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
96285c4f
Commit
96285c4f
authored
Mar 12, 2019
by
Andrej Ocenas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use render props pattern in color picker
parent
4a2905de
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
14 deletions
+32
-14
packages/grafana-ui/src/components/ColorPicker/ColorPicker.story.tsx
+10
-1
packages/grafana-ui/src/components/ColorPicker/ColorPicker.tsx
+14
-7
packages/grafana-ui/src/components/ColorPicker/ColorPickerPopover.tsx
+1
-1
packages/grafana-ui/src/components/ColorPicker/ColorPickerTrigger.tsx
+2
-2
public/app/plugins/panel/graph/Legend/LegendSeriesItem.tsx
+5
-3
No files found.
packages/grafana-ui/src/components/ColorPicker/ColorPicker.story.tsx
View file @
96285c4f
...
...
@@ -50,7 +50,16 @@ ColorPickerStories.add('Series color picker', () => {
color=
{
selectedColor
}
onChange=
{
color
=>
updateSelectedColor
(
color
)
}
>
<
div
style=
{
{
color
:
selectedColor
,
cursor
:
'pointer'
}
}
>
Open color picker
</
div
>
{
({
ref
,
showColorPicker
,
hideColorPicker
})
=>
(
<
div
ref=
{
ref
}
onMouseLeave=
{
hideColorPicker
}
onClick=
{
showColorPicker
}
style=
{
{
color
:
selectedColor
,
cursor
:
'pointer'
}
}
>
Open color picker
</
div
>
)
}
</
SeriesColorPicker
>
);
}
}
...
...
packages/grafana-ui/src/components/ColorPicker/ColorPicker.tsx
View file @
96285c4f
import
React
,
{
Component
,
createRef
}
from
'react'
;
import
{
omit
}
from
'lodash'
;
import
{
PopperController
}
from
'../Tooltip/PopperController'
;
import
{
Popper
}
from
'../Tooltip/Popper'
;
import
{
ColorPickerPopover
,
ColorPickerProps
,
ColorPickerChangeHandler
}
from
'./ColorPickerPopover'
;
...
...
@@ -8,13 +9,19 @@ import { SeriesColorPickerPopover } from './SeriesColorPickerPopover';
import
{
withTheme
}
from
'../../themes/ThemeContext'
;
import
{
ColorPickerTrigger
}
from
'./ColorPickerTrigger'
;
type
ColorPickerTriggerRenderer
=
(
props
:
{
ref
:
React
.
RefObject
<
any
>
;
showColorPicker
:
()
=>
void
;
hideColorPicker
:
()
=>
void
;
})
=>
React
.
ReactNode
;
export
const
colorPickerFactory
=
<
T
extends
ColorPickerProps
>
(
popover: React.ComponentType
<
T
>
,
displayName = 'ColorPicker'
) =
>
{
return
class
ColorPicker
extends
Component
<
T
,
any
>
{
return
class
ColorPicker
extends
Component
<
T
&
{
children
?:
ColorPickerTriggerRenderer
}
,
any
>
{
static
displayName
=
displayName
;
pickerTriggerRef
=
createRef
<
HTMLDivElement
>
();
pickerTriggerRef
=
createRef
<
any
>
();
onColorChange
=
(
color
:
string
)
=>
{
const
{
onColorChange
,
onChange
}
=
this
.
props
;
...
...
@@ -24,11 +31,11 @@ export const colorPickerFactory = <T extends ColorPickerProps>(
};
render
()
{
const
{
theme
,
children
}
=
this
.
props
;
const
popoverElement
=
React
.
createElement
(
popover
,
{
...
this
.
props
,
...
omit
(
this
.
props
,
'children'
)
,
onChange
:
this
.
onColorChange
,
});
const
{
theme
,
children
}
=
this
.
props
;
return
(
<
PopperController
content=
{
popoverElement
}
hideAfter=
{
300
}
>
...
...
@@ -46,10 +53,10 @@ export const colorPickerFactory = <T extends ColorPickerProps>(
)
}
{
children
?
(
React
.
cloneElement
(
children
as
JSX
.
Element
,
{
(
children
as
ColorPickerTriggerRenderer
)(
{
ref
:
this
.
pickerTriggerRef
,
onClick
:
showPopper
,
onMouseLeave
:
hidePopper
,
showColorPicker
:
showPopper
,
hideColorPicker
:
hidePopper
,
})
)
:
(
<
ColorPickerTrigger
...
...
packages/grafana-ui/src/components/ColorPicker/ColorPickerPopover.tsx
View file @
96285c4f
...
...
@@ -17,8 +17,8 @@ export interface ColorPickerProps extends Themeable {
*/
onColorChange
?:
ColorPickerChangeHandler
;
enableNamedColors
?:
boolean
;
children
?:
JSX
.
Element
;
}
export
interface
Props
<
T
>
extends
ColorPickerProps
,
PopperContentProps
{
customPickers
?:
T
;
}
...
...
packages/grafana-ui/src/components/ColorPicker/ColorPickerTrigger.tsx
View file @
96285c4f
import
React
,
{
forwardRef
,
Ref
}
from
'react'
;
import
React
,
{
forwardRef
}
from
'react'
;
interface
ColorPickerTriggerProps
{
onClick
:
()
=>
void
;
...
...
@@ -8,7 +8,7 @@ interface ColorPickerTriggerProps {
export
const
ColorPickerTrigger
=
forwardRef
(
function
ColorPickerTrigger
(
props
:
ColorPickerTriggerProps
,
ref
:
Ref
<
HTMLDivElement
>
ref
:
Re
act
.
Re
f
<
HTMLDivElement
>
)
{
return
(
<
div
...
...
public/app/plugins/panel/graph/Legend/LegendSeriesItem.tsx
View file @
96285c4f
...
...
@@ -174,9 +174,11 @@ class LegendSeriesIcon extends PureComponent<LegendSeriesIconProps, LegendSeries
onToggleAxis=
{
this
.
props
.
onToggleAxis
}
enableNamedColors
>
<
span
className=
"graph-legend-icon"
>
<
SeriesIcon
color=
{
this
.
props
.
color
}
/>
</
span
>
{
({
ref
,
showColorPicker
,
hideColorPicker
})
=>
(
<
span
ref=
{
ref
}
onClick=
{
showColorPicker
}
onMouseLeave=
{
hideColorPicker
}
className=
"graph-legend-icon"
>
<
SeriesIcon
color=
{
this
.
props
.
color
}
/>
</
span
>
)
}
</
SeriesColorPicker
>
);
}
...
...
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