Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
de4e1a91
Commit
de4e1a91
authored
Jan 08, 2019
by
Dominik Prokop
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored withPoper HOC to PopperController using render prop
parent
8e8b759b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
41 deletions
+42
-41
public/app/core/components/Tooltip/Popper.tsx
+6
-11
public/app/core/components/Tooltip/PopperController.tsx
+36
-30
No files found.
public/app/core/components/Tooltip/Popper.tsx
View file @
de4e1a91
import
React
,
{
PureComponent
}
from
'react'
;
import
*
as
PopperJS
from
'popper.js'
;
import
{
Manager
,
Popper
as
ReactPopper
}
from
'react-popper'
;
import
Portal
from
'app/core/components/Portal/Portal'
;
import
{
Manager
,
Popper
as
ReactPopper
,
Reference
}
from
'react-popper'
;
import
Transition
from
'react-transition-group/Transition'
;
const
defaultTransitionStyles
=
{
...
...
@@ -18,29 +19,23 @@ const transitionStyles = {
interface
Props
{
renderContent
:
(
content
:
any
)
=>
any
;
show
:
boolean
;
placement
?:
any
;
placement
?:
PopperJS
.
Placement
;
content
:
string
|
((
props
:
any
)
=>
JSX
.
Element
);
refClassName
?:
string
;
referenceElement
:
PopperJS
.
ReferenceObject
;
}
class
Popper
extends
PureComponent
<
Props
>
{
render
()
{
const
{
children
,
renderContent
,
show
,
placement
,
refClassName
}
=
this
.
props
;
const
{
renderContent
,
show
,
placement
}
=
this
.
props
;
const
{
content
}
=
this
.
props
;
return
(
<
Manager
>
<
Reference
>
{
({
ref
})
=>
(
<
div
className=
{
`popper_ref ${refClassName || ''}`
}
ref=
{
ref
}
>
{
children
}
</
div
>
)
}
</
Reference
>
<
Transition
in=
{
show
}
timeout=
{
100
}
mountOnEnter=
{
true
}
unmountOnExit=
{
true
}
>
{
transitionState
=>
(
<
Portal
>
<
ReactPopper
placement=
{
placement
}
>
<
ReactPopper
placement=
{
placement
}
referenceElement=
{
this
.
props
.
referenceElement
}
>
{
({
ref
,
style
,
placement
,
arrowProps
})
=>
{
return
(
<
div
...
...
public/app/core/components/Tooltip/
withPopp
er.tsx
→
public/app/core/components/Tooltip/
PopperControll
er.tsx
View file @
de4e1a91
import
React
from
'react'
;
import
*
as
PopperJS
from
'popper.js'
;
type
PopperContent
=
string
|
(()
=>
JSX
.
Element
);
export
interface
UsingPopperProps
{
showPopper
:
(
prevState
:
object
)
=>
void
;
hidePopper
:
(
prevState
:
object
)
=>
void
;
renderContent
:
(
content
:
any
)
=>
any
;
show
?:
boolean
;
placement
?:
PopperJS
.
Placement
;
content
:
PopperContent
;
children
:
JSX
.
Element
;
renderContent
?:
(
content
:
PopperContent
)
=>
JSX
.
Element
;
}
type
PopperControllerRenderProp
=
(
showPopper
:
()
=>
void
,
hidePopper
:
()
=>
void
,
popperProps
:
{
show
:
boolean
;
placement
?:
string
;
placement
:
PopperJS
.
Placement
;
content
:
string
|
((
props
:
any
)
=>
JSX
.
Element
);
className
?:
string
;
refClassName
?:
string
;
}
renderContent
:
(
content
:
any
)
=>
any
;
}
)
=>
JSX
.
Element
;
interface
Props
{
placement
?:
string
;
placement
?:
PopperJS
.
Placement
;
content
:
PopperContent
;
className
?:
string
;
refClassName
?:
string
;
content
:
string
|
((
props
:
any
)
=>
JSX
.
Element
);
children
:
PopperControllerRenderProp
;
}
interface
State
{
placement
:
string
;
placement
:
PopperJS
.
Placement
;
show
:
boolean
;
}
export
default
function
withPopper
(
WrappedComponent
)
{
return
class
extends
React
.
Component
<
Props
,
State
>
{
constructor
(
props
)
{
class
PopperController
extends
React
.
Component
<
Props
,
State
>
{
constructor
(
props
:
Props
)
{
super
(
props
);
this
.
setState
=
this
.
setState
.
bind
(
this
);
this
.
state
=
{
placement
:
this
.
props
.
placement
||
'auto'
,
show
:
false
,
};
}
componentWillReceiveProps
(
next
Props
)
{
componentWillReceiveProps
(
nextProps
:
Props
)
{
if
(
nextProps
.
placement
&&
nextProps
.
placement
!==
this
.
state
.
placement
)
{
this
.
setState
(
prevState
=>
{
return
{
...
...
@@ -59,7 +69,7 @@ export default function withPopper(WrappedComponent) {
}));
};
renderContent
(
c
ontent
)
{
renderContent
(
content
:
PopperC
ontent
)
{
if
(
typeof
content
===
'function'
)
{
// If it's a function we assume it's a React component
const
ReactComponent
=
content
;
...
...
@@ -69,20 +79,16 @@ export default function withPopper(WrappedComponent) {
}
render
()
{
const
{
children
,
content
}
=
this
.
props
;
const
{
show
,
placement
}
=
this
.
state
;
const
className
=
this
.
props
.
className
||
''
;
return
(
<
WrappedComponent
{
...
this
.
props
}
showPopper=
{
this
.
showPopper
}
hidePopper=
{
this
.
hidePopper
}
renderContent=
{
this
.
renderContent
}
show=
{
show
}
placement=
{
placement
}
className=
{
className
}
/>
);
return
children
(
this
.
showPopper
,
this
.
hidePopper
,
{
show
,
placement
,
content
,
renderContent
:
this
.
renderContent
,
});
}
};
}
export
default
PopperController
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment