@@ -10,11 +10,12 @@ import {
10
10
rgba ,
11
11
hsv2rgb ,
12
12
} from '@swiftcarrot/color-fns' ;
13
- import { rgba2hex } from './utils' ;
13
+ import { rgba2hex , parseColor , onlyUnique } from './utils' ;
14
+ import ColorSquare from './color-square'
14
15
15
16
const KEY_ENTER = 13 ;
16
17
17
- const ColorPicker = ( { color, onChange, disabled } ) => {
18
+ const ColorPicker = ( { color, onChange, disabled, recommendedColors } ) => {
18
19
const { r, g, b, a, h, s, v } = color ;
19
20
20
21
function changeColor ( color ) {
@@ -70,6 +71,20 @@ const ColorPicker = ({ color, onChange, disabled }) => {
70
71
71
72
return (
72
73
< div css = { styles . picker } onClick = { handleClick } >
74
+
75
+ { ! ! recommendedColors . length && (
76
+ < div css = { styles . recommendedColors } >
77
+ { onlyUnique ( recommendedColors ) . 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
+
73
88
< div css = { styles . selector } style = { { backgroundColor : hueBackground } } >
74
89
< div css = { styles . gradientWhite } />
75
90
< div css = { styles . gradientDark } />
@@ -153,9 +168,7 @@ const ColorPicker = ({ color, onChange, disabled }) => {
153
168
disabled = { disabled }
154
169
/>
155
170
</ div >
156
- < div
157
- style = { { backgroundColor : rgbaBackground , width : 30 , height : 30 } }
158
- />
171
+ < ColorSquare color = { rgbaBackground } />
159
172
</ div >
160
173
161
174
< div css = { styles . inputs } >
@@ -219,7 +232,8 @@ const ColorPicker = ({ color, onChange, disabled }) => {
219
232
220
233
ColorPicker . defaultProps = {
221
234
initialValue : '#5e72e4' ,
222
- disabled : false
235
+ disabled : false ,
236
+ recommendedColors : [ ]
223
237
} ;
224
238
225
239
const styles = {
@@ -278,6 +292,16 @@ const styles = {
278
292
marginTop : 4 ,
279
293
} ,
280
294
} ,
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
+ }
281
305
} ;
282
306
283
307
export default ColorPicker ;
0 commit comments