@@ -10,11 +10,12 @@ import {
1010 rgba ,
1111 hsv2rgb ,
1212} from '@swiftcarrot/color-fns' ;
13- import { rgba2hex } from './utils' ;
13+ import { rgba2hex , parseColor , onlyUnique } from './utils' ;
14+ import ColorSquare from './color-square'
1415
1516const KEY_ENTER = 13 ;
1617
17- const ColorPicker = ( { color, onChange, disabled } ) => {
18+ const ColorPicker = ( { color, onChange, disabled, recommendedColors } ) => {
1819 const { r, g, b, a, h, s, v } = color ;
1920
2021 function changeColor ( color ) {
@@ -70,6 +71,20 @@ const ColorPicker = ({ color, onChange, disabled }) => {
7071
7172 return (
7273 < div css = { styles . picker } onClick = { handleClick } >
74+
75+ { ! ! recommendedColors . length && (
76+ < div css = { styles . recommendedColors } >
77+ { recommendedColors . filter ( onlyUnique ) . map ( ( recommendedColor ) => (
78+ < ColorSquare
79+ key = { recommendedColor }
80+ color = { recommendedColor }
81+ onClick = { ( ) => ! disabled && onChange ( parseColor ( recommendedColor ) ) }
82+ disabled = { disabled }
83+ />
84+ ) ) }
85+ </ div >
86+ ) }
87+
7388 < div css = { styles . selector } style = { { backgroundColor : hueBackground } } >
7489 < div css = { styles . gradientWhite } />
7590 < div css = { styles . gradientDark } />
@@ -153,9 +168,7 @@ const ColorPicker = ({ color, onChange, disabled }) => {
153168 disabled = { disabled }
154169 />
155170 </ div >
156- < div
157- style = { { backgroundColor : rgbaBackground , width : 30 , height : 30 } }
158- />
171+ < ColorSquare color = { rgbaBackground } />
159172 </ div >
160173
161174 < div css = { styles . inputs } >
@@ -219,7 +232,8 @@ const ColorPicker = ({ color, onChange, disabled }) => {
219232
220233ColorPicker . defaultProps = {
221234 initialValue : '#5e72e4' ,
222- disabled : false
235+ disabled : false ,
236+ recommendedColors : [ ]
223237} ;
224238
225239const styles = {
@@ -278,6 +292,16 @@ const styles = {
278292 marginTop : 4 ,
279293 } ,
280294 } ,
295+
296+ recommendedColors : {
297+ width : '100%' ,
298+ display : 'flex' ,
299+ flexWrap : 'wrap' ,
300+ alignItems : 'center' ,
301+ paddingBottom : 10 ,
302+ marginBottom : 10 ,
303+ borderBottom : '1px solid #e9e9e9'
304+ }
281305} ;
282306
283307export default ColorPicker ;
0 commit comments