@@ -74,24 +74,22 @@ import {
74
74
ColorArea ,
75
75
ColorSliderProps ,
76
76
AlphaSlider ,
77
- HueSlider ,
77
+ ColorSlider ,
78
78
ColorPickerOnSelectEventHandler ,
79
79
} from ' @fluentui/react-color-picker-preview' ;
80
80
81
81
export const Default = () => {
82
- const [selectedColor , setSelectedColor ] = React .useState (' rgba(0, 255, 170, 1)' );
83
- const handleChange: ColorPickerProps ['onChange '] = (_ , data ) => {
84
- setSelectedColor (data .selectedColorHex );
85
- };
82
+ const [selectedColor , setSelectedColor ] = React .useState ({ h: 109 , s: 1 , v: 0.9 , a: 1 });
83
+ const handleChange: ColorPickerProps ['onChange '] = (_ , data ) => setSelectedColor (data .selectedColorHex );
86
84
87
85
return (
88
86
<>
89
87
< ColorPicker color= {selectedColor} onChange= {handleChange}>
90
88
< ColorArea / >
91
89
< AlphaSlider / >
92
- < HueSlider / >
90
+ < ColorSlider / >
93
91
< / ColorPicker>
94
- < div style= {{ backgroundColor: ` ${ selectedColor } ` }} / >
92
+ < div style= {{ backgroundColor: tinycolor (color). toRgbString () }} / >
95
93
< / >
96
94
);
97
95
};
@@ -132,51 +130,18 @@ For custom sizes users might want to customize it via CSS.
132
130
133
131
### ColorPicker
134
132
135
- | Property | Values | Default | Purpose |
136
- | ---------- | ------------------- | --------- | -------------------------------------- |
137
- | color | ` HSV ` | | Sets color value in HSV format |
138
- | onChange | ` function ` | undefined | Callback called when color is selected |
139
- | shape | ` square ` , ` rounded ` | ` rounded ` | Sets shape |
140
- | step | ` number ` | 1 | Step for arrow navigation |
141
- | customStep | ` number ` | 3 | Fast navigation |
133
+ | Property | Values | Default | Purpose |
134
+ | ------------- | ------------------- | --------- | -------------------------------------- |
135
+ | color | ` HSV ` | | Sets color value in HSV format |
136
+ | onColorChange | ` function ` | undefined | Callback called when color is selected |
137
+ | shape | ` square ` , ` rounded ` | ` rounded ` | Sets shape |
142
138
143
139
Color has an ` HSV ` type because the correct functioning of the component requires coordinates. In some parts of the ColorArea, the color is the same, and therefore it should be calculated using coordinates. Color manipulations will be done on the user end in the desired format.
144
140
145
- ` onChange ` event returns data which contains a new color.
146
-
147
- Input fields with color values will be in ` renderUtils ` . It will contain default ColorPicker which has all colors represented and a preview swatch. This functionality is similar to V8.
148
-
149
- ``` tsx
150
- import { ColorPicker } from ' @fluentui/react-color-picker-preview' ;
151
-
152
- const COLOR = { h: 0 , s: 1 , v: 1 };
153
-
154
- export const Default = () => {
155
- const [selectedColor, setSelectedColor] = React .useState (COLOR );
156
- const handleChange: ColorPickerOnSelectEventHandler = (_ , data ) => {
157
- setSelectedColor ({ ... data .color , a: data .color .a ?? 1 });
158
- };
159
-
160
- return (
161
- <>
162
- <ColorPicker color = { color } onColorChange = { handleChange } >
163
- <ColorSlider />
164
- <AlphaSlider />
165
- <ColorArea />
166
- </ColorPicker >
167
- <InputHexField color = { color } onChange = { handleChange } />
168
- <InputRgbField color = { color } onChange = { handleChange } />
169
- <ColorSwatch color = { color } >
170
- <div style = { { backgroundColor: ` ${selectedColor } ` }} />
171
- </>
172
- );
173
- };
174
- ```
141
+ ` onColorChange ` event returns data which contains a new color.
175
142
176
143
![ ColorPicker] ( ./assets/color-picker-layout.jpg )
177
144
178
- Validation of color fields will be in `utils`. Validation should not allow entering incorrect values to the input fields.
179
-
180
145
For color manipulation and conversion [ tinycolor] ( https://www.npmjs.com/package/@ctrl/tinycolor ) library will be used.
181
146
182
147
| Slots | Values | Default | Description |
@@ -188,7 +153,7 @@ For color manipulation and conversion [tinycolor](https://www.npmjs.com/package/
188
153
| Property | Values | Default | Purpose |
189
154
| ------------ | ------------------- | --------- | --------------------------------------- |
190
155
| color | ` HSV ` | | Sets color value in HSV format |
191
- | defauleColor | `HSV` | | Sets color for uncontrollable ColorArea |
156
+ | defaultColor | ` HSV ` | | Sets color for uncontrollable ColorArea |
192
157
| onChange | ` function ` | undefined | Callback called when color is selected |
193
158
| shape | ` square ` , ` rounded ` | ` rounded ` | Sets shape |
194
159
@@ -201,13 +166,14 @@ For color manipulation and conversion [tinycolor](https://www.npmjs.com/package/
201
166
202
167
### ColorSlider
203
168
204
- | Property | Values | Default | Purpose |
205
- | ------------ | ------------------------ | ------------ | ----------------------------------------- |
206
- | color | `HSV` | | Sets color value in HSV format |
207
- | defauleColor | `HSV` | | Sets color for uncontrollable ColorSlider |
208
- | onChange | `function` | undefined | Callback called when color is selected |
209
- | orient | `horizontal`, `vertical` | `horizontal` | Orientation of a slider |
210
- | shape | `square`, `rounded` | `rounded` | Sets shape |
169
+ | Property | Values | Default | Purpose |
170
+ | ------------ | ---------------------------- | --------- | ----------------------------------------- |
171
+ | channel | ` hue ` , ` saturation ` , ` value ` | ` hue ` | Sets color channel |
172
+ | color | ` HSV ` | | Sets color value in HSV format |
173
+ | defaultColor | ` HSV ` | | Sets color for uncontrollable ColorSlider |
174
+ | onChange | ` function ` | undefined | Callback called when color is selected |
175
+ | shape | ` square ` , ` rounded ` | ` rounded ` | Sets shape |
176
+ | vertical | ` boolean ` | ` false ` | Orientation of a slider |
211
177
212
178
| Slots | Values | Default | Description |
213
179
| ------ | ------- | ------- | ---------------------------------------------------------------- |
@@ -218,7 +184,10 @@ For color manipulation and conversion [tinycolor](https://www.npmjs.com/package/
218
184
219
185
### AlphaSlider
220
186
221
- AlphaSlider has the same props and slots as ColorSlider.
187
+ AlphaSlider has the same props and slots as ColorSlider except ` transparent ` prop.
188
+ | Property | Values | Default | Purpose |
189
+ | ------------ | ---------------------------- | --------- | ----------------------------------------- |
190
+ | transparent | ` boolean ` | ` false ` | The ` transparency ` property determines how the alpha channel is interpreted |
222
191
223
192
## Structure
224
193
@@ -309,11 +278,12 @@ States:
309
278
310
279
In a ` horizontal ` orientation top/right arrows move to the right, bottom/left arrows move to the left.
311
280
312
- | Key | Result |
313
- | -------------------- | -------------------------------------------------------------- |
314
- | Arrows | Color thumb is focused. Color is selected |
315
- | `Home/End/PgUp/PgDn` | Can be used another configuration for the step to move faster. |
316
- | `Tab` | Navigation between color sliders and Color Area |
281
+ | Key | Result |
282
+ | ----------- | ----------------------------------------------- |
283
+ | Arrows | Color thumb is focused. Color is selected |
284
+ | ` PgUp/PgDn ` | Can be used for faster navigation |
285
+ | ` Home/End ` | Navigates to the beginning or end of a Slider |
286
+ | ` Tab ` | Navigation between color sliders and Color Area |
317
287
318
288
##### Color/Alpha Slider
319
289
0 commit comments