@@ -27,6 +27,11 @@ export enum ChromeInputType {
27
27
28
28
export interface ChromeProps extends Omit < GithubProps , 'colors' > {
29
29
inputType ?: ChromeInputType ;
30
+ showEditableInput ?: boolean ;
31
+ showEyeDropper ?: boolean ;
32
+ showColorPreview ?: boolean ;
33
+ showHue ?: boolean ;
34
+ showAlpha ?: boolean ;
30
35
}
31
36
32
37
const Chrome = React . forwardRef < HTMLDivElement , ChromeProps > ( ( props , ref ) => {
@@ -35,6 +40,11 @@ const Chrome = React.forwardRef<HTMLDivElement, ChromeProps>((props, ref) => {
35
40
className,
36
41
style,
37
42
color,
43
+ showEditableInput = true ,
44
+ showEyeDropper = true ,
45
+ showColorPreview = true ,
46
+ showHue = true ,
47
+ showAlpha = true ,
38
48
inputType = ChromeInputType . RGBA ,
39
49
rectProps = { } ,
40
50
onChange,
@@ -78,6 +88,10 @@ const Chrome = React.forwardRef<HTMLDivElement, ChromeProps>((props, ref) => {
78
88
handleChange ( { ...result } ) ;
79
89
} ;
80
90
const styleSize = { height : 14 , width : 14 } ;
91
+ const pointerProps = {
92
+ style : { ...styleSize } ,
93
+ fillProps : { style : styleSize } ,
94
+ } ;
81
95
return (
82
96
< Github
83
97
ref = { ref }
@@ -97,90 +111,92 @@ const Chrome = React.forwardRef<HTMLDivElement, ChromeProps>((props, ref) => {
97
111
} }
98
112
/>
99
113
< div style = { { padding : 15 , display : 'flex' , alignItems : 'center' , gap : 10 } } >
100
- { isSupportEyeDropper && < EyeDropper onPickColor = { handleClickColor } /> }
101
- < Alpha
102
- width = { 28 }
103
- height = { 28 }
104
- hsva = { hsva }
105
- radius = { 2 }
106
- style = { {
107
- borderRadius : '50%' ,
108
- } }
109
- bgProps = { { style : { background : 'transparent' } } }
110
- innerProps = { {
111
- style : alphaStyle ,
112
- } }
113
- pointer = { ( ) => < Fragment /> }
114
- />
115
- < div style = { { flex : 1 } } >
116
- < Hue
117
- hue = { hsva . h }
118
- style = { { width : '100%' , height : 12 } }
119
- pointerProps = { {
120
- style : { ...styleSize } ,
121
- fillProps : { style : styleSize } ,
122
- } }
123
- bgProps = { {
124
- style : { borderRadius : 2 } ,
125
- } }
126
- onChange = { ( newHue ) => {
127
- handleChange ( { ...hsva , ...newHue } ) ;
128
- } }
129
- />
114
+ { isSupportEyeDropper && showEyeDropper && < EyeDropper onPickColor = { handleClickColor } /> }
115
+ { showColorPreview && (
130
116
< Alpha
117
+ width = { 28 }
118
+ height = { 28 }
131
119
hsva = { hsva }
132
- style = { { marginTop : 6 , height : 12 } }
133
- pointerProps = { {
134
- style : { ...styleSize } ,
135
- fillProps : { style : styleSize } ,
120
+ radius = { 2 }
121
+ style = { {
122
+ borderRadius : '50%' ,
136
123
} }
137
- bgProps = { {
138
- style : { borderRadius : 2 } ,
139
- } }
140
- onChange = { ( newAlpha ) => {
141
- handleChange ( { ...hsva , ...newAlpha } ) ;
124
+ bgProps = { { style : { background : 'transparent' } } }
125
+ innerProps = { {
126
+ style : alphaStyle ,
142
127
} }
128
+ pointer = { ( ) => < Fragment /> }
143
129
/>
144
- </ div >
145
- </ div >
146
- < div style = { { display : 'flex' , alignItems : 'flex-start' , padding : '0 15px 15px 15px' , userSelect : 'none' } } >
130
+ ) }
147
131
< div style = { { flex : 1 } } >
148
- { type == ChromeInputType . RGBA && (
149
- < EditableInputRGBA
150
- hsva = { hsva }
151
- rProps = { { labelStyle, inputStyle } }
152
- gProps = { { labelStyle, inputStyle } }
153
- bProps = { { labelStyle, inputStyle } }
154
- aProps = { { labelStyle, inputStyle } }
155
- onChange = { ( reColor ) => handleChange ( reColor . hsva ) }
156
- />
157
- ) }
158
- { type === ChromeInputType . HEXA && (
159
- < EditableInput
160
- label = "HEX"
161
- labelStyle = { labelStyle }
162
- inputStyle = { inputStyle }
163
- value = { hsva . a > 0 && hsva . a < 1 ? hsvaToHexa ( hsva ) . toLocaleUpperCase ( ) : hsvaToHex ( hsva ) . toLocaleUpperCase ( ) }
164
- onChange = { ( _ , value ) => {
165
- if ( typeof value === 'string' ) {
166
- handleChange ( hexToHsva ( / ^ # / . test ( value ) ? value : `#${ value } ` ) ) ;
167
- }
132
+ { showHue == true && (
133
+ < Hue
134
+ hue = { hsva . h }
135
+ style = { { width : '100%' , height : 12 } }
136
+ pointerProps = { pointerProps }
137
+ bgProps = { {
138
+ style : { borderRadius : 2 } ,
139
+ } }
140
+ onChange = { ( newHue ) => {
141
+ handleChange ( { ...hsva , ...newHue } ) ;
168
142
} }
169
143
/>
170
144
) }
171
- { type === ChromeInputType . HSLA && (
172
- < EditableInputHSLA
145
+ { showAlpha == true && (
146
+ < Alpha
173
147
hsva = { hsva }
174
- hProps = { { labelStyle, inputStyle } }
175
- sProps = { { labelStyle, inputStyle } }
176
- lProps = { { labelStyle, inputStyle } }
177
- aProps = { { labelStyle, inputStyle } }
178
- onChange = { ( reColor ) => handleChange ( reColor . hsva ) }
148
+ style = { { marginTop : 6 , height : 12 } }
149
+ pointerProps = { pointerProps }
150
+ bgProps = { {
151
+ style : { borderRadius : 2 } ,
152
+ } }
153
+ onChange = { ( newAlpha ) => {
154
+ handleChange ( { ...hsva , ...newAlpha } ) ;
155
+ } }
179
156
/>
180
157
) }
181
158
</ div >
182
- < Arrow onClick = { handleClick } />
183
159
</ div >
160
+ { showEditableInput && (
161
+ < div style = { { display : 'flex' , alignItems : 'flex-start' , padding : '0 15px 15px 15px' , userSelect : 'none' } } >
162
+ < div style = { { flex : 1 } } >
163
+ { type == ChromeInputType . RGBA && (
164
+ < EditableInputRGBA
165
+ hsva = { hsva }
166
+ rProps = { { labelStyle, inputStyle } }
167
+ gProps = { { labelStyle, inputStyle } }
168
+ bProps = { { labelStyle, inputStyle } }
169
+ aProps = { { labelStyle, inputStyle } }
170
+ onChange = { ( reColor ) => handleChange ( reColor . hsva ) }
171
+ />
172
+ ) }
173
+ { type === ChromeInputType . HEXA && (
174
+ < EditableInput
175
+ label = "HEX"
176
+ labelStyle = { labelStyle }
177
+ inputStyle = { inputStyle }
178
+ value = { hsva . a > 0 && hsva . a < 1 ? hsvaToHexa ( hsva ) . toLocaleUpperCase ( ) : hsvaToHex ( hsva ) . toLocaleUpperCase ( ) }
179
+ onChange = { ( _ , value ) => {
180
+ if ( typeof value === 'string' ) {
181
+ handleChange ( hexToHsva ( / ^ # / . test ( value ) ? value : `#${ value } ` ) ) ;
182
+ }
183
+ } }
184
+ />
185
+ ) }
186
+ { type === ChromeInputType . HSLA && (
187
+ < EditableInputHSLA
188
+ hsva = { hsva }
189
+ hProps = { { labelStyle, inputStyle } }
190
+ sProps = { { labelStyle, inputStyle } }
191
+ lProps = { { labelStyle, inputStyle } }
192
+ aProps = { { labelStyle, inputStyle } }
193
+ onChange = { ( reColor ) => handleChange ( reColor . hsva ) }
194
+ />
195
+ ) }
196
+ </ div >
197
+ < Arrow onClick = { handleClick } />
198
+ </ div >
199
+ ) }
184
200
</ Fragment >
185
201
}
186
202
rectRender = { ( ) => < Fragment /> }
0 commit comments