-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(react-color-picker): updated the spec and the migration #33918
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,24 +74,22 @@ import { | |
ColorArea, | ||
ColorSliderProps, | ||
AlphaSlider, | ||
HueSlider, | ||
ColorSlider, | ||
ColorPickerOnSelectEventHandler, | ||
} from '@fluentui/react-color-picker-preview'; | ||
|
||
export const Default = () => { | ||
const [selectedColor, setSelectedColor] = React.useState('rgba(0, 255, 170, 1)'); | ||
const handleChange: ColorPickerProps['onChange'] = (_, data) => { | ||
setSelectedColor(data.selectedColorHex); | ||
}; | ||
const [selectedColor, setSelectedColor] = React.useState({ h: 109, s: 1, v: 0.9, a: 1 }); | ||
const handleChange: ColorPickerProps['onChange'] = (_, data) => setSelectedColor(data.selectedColorHex); | ||
|
||
return ( | ||
<> | ||
<ColorPicker color={selectedColor} onChange={handleChange}> | ||
<ColorArea /> | ||
<AlphaSlider /> | ||
<HueSlider /> | ||
<ColorSlider /> | ||
</ColorPicker> | ||
<div style={{ backgroundColor: `${selectedColor}` }} /> | ||
<div style={{ backgroundColor: tinycolor(color).toRgbString() }} /> | ||
</> | ||
); | ||
}; | ||
|
@@ -132,51 +130,18 @@ For custom sizes users might want to customize it via CSS. | |
|
||
### ColorPicker | ||
|
||
| Property | Values | Default | Purpose | | ||
| ---------- | ------------------- | --------- | -------------------------------------- | | ||
| color | `HSV` | | Sets color value in HSV format | | ||
| onChange | `function` | undefined | Callback called when color is selected | | ||
| shape | `square`, `rounded` | `rounded` | Sets shape | | ||
| step | `number` | 1 | Step for arrow navigation | | ||
| customStep | `number` | 3 | Fast navigation | | ||
Comment on lines
-140
to
-141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are supported by default. And |
||
| Property | Values | Default | Purpose | | ||
| ------------- | ------------------- | --------- | -------------------------------------- | | ||
| color | `HSV` | | Sets color value in HSV format | | ||
| onColorChange | `function` | undefined | Callback called when color is selected | | ||
| shape | `square`, `rounded` | `rounded` | Sets shape | | ||
|
||
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. | ||
|
||
`onChange` event returns data which contains a new color. | ||
|
||
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. | ||
|
||
```tsx | ||
import { ColorPicker } from '@fluentui/react-color-picker-preview'; | ||
|
||
const COLOR = { h: 0, s: 1, v: 1 }; | ||
|
||
export const Default = () => { | ||
const [selectedColor, setSelectedColor] = React.useState(COLOR); | ||
const handleChange: ColorPickerOnSelectEventHandler = (_, data) => { | ||
setSelectedColor({ ...data.color, a: data.color.a ?? 1 }); | ||
}; | ||
|
||
return ( | ||
<> | ||
<ColorPicker color={color} onColorChange={handleChange}> | ||
<ColorSlider /> | ||
<AlphaSlider /> | ||
<ColorArea /> | ||
</ColorPicker> | ||
<InputHexField color={color} onChange={handleChange} /> | ||
<InputRgbField color={color} onChange={handleChange} /> | ||
<ColorSwatch color={color}> | ||
<div style={{ backgroundColor: `${selectedColor}` }} /> | ||
</> | ||
); | ||
}; | ||
``` | ||
Comment on lines
-147
to
-174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the examples of inputs are in the storybook now |
||
`onColorChange` event returns data which contains a new color. | ||
|
||
 | ||
|
||
Validation of color fields will be in `utils`. Validation should not allow entering incorrect values to the input fields. | ||
|
||
For color manipulation and conversion [tinycolor](https://www.npmjs.com/package/@ctrl/tinycolor) library will be used. | ||
|
||
| Slots | Values | Default | Description | | ||
|
@@ -188,7 +153,7 @@ For color manipulation and conversion [tinycolor](https://www.npmjs.com/package/ | |
| Property | Values | Default | Purpose | | ||
| ------------ | ------------------- | --------- | --------------------------------------- | | ||
| color | `HSV` | | Sets color value in HSV format | | ||
| defauleColor | `HSV` | | Sets color for uncontrollable ColorArea | | ||
| defaultColor | `HSV` | | Sets color for uncontrollable ColorArea | | ||
| onChange | `function` | undefined | Callback called when color is selected | | ||
| shape | `square`, `rounded` | `rounded` | Sets shape | | ||
|
||
|
@@ -201,13 +166,14 @@ For color manipulation and conversion [tinycolor](https://www.npmjs.com/package/ | |
|
||
### ColorSlider | ||
|
||
| Property | Values | Default | Purpose | | ||
| ------------ | ------------------------ | ------------ | ----------------------------------------- | | ||
| color | `HSV` | | Sets color value in HSV format | | ||
| defauleColor | `HSV` | | Sets color for uncontrollable ColorSlider | | ||
| onChange | `function` | undefined | Callback called when color is selected | | ||
| orient | `horizontal`, `vertical` | `horizontal` | Orientation of a slider | | ||
| shape | `square`, `rounded` | `rounded` | Sets shape | | ||
| Property | Values | Default | Purpose | | ||
| ------------ | ---------------------------- | --------- | ----------------------------------------- | | ||
| channel | `hue`, `saturation`, `value` | `hue` | Sets color channel | | ||
| color | `HSV` | | Sets color value in HSV format | | ||
| defaultColor | `HSV` | | Sets color for uncontrollable ColorSlider | | ||
| onChange | `function` | undefined | Callback called when color is selected | | ||
| shape | `square`, `rounded` | `rounded` | Sets shape | | ||
| vertical | `boolean` | `false` | Orientation of a slider | | ||
|
||
| Slots | Values | Default | Description | | ||
| ------ | ------- | ------- | ---------------------------------------------------------------- | | ||
|
@@ -218,7 +184,10 @@ For color manipulation and conversion [tinycolor](https://www.npmjs.com/package/ | |
|
||
### AlphaSlider | ||
|
||
AlphaSlider has the same props and slots as ColorSlider. | ||
AlphaSlider has the same props and slots as ColorSlider except `transparent` prop. | ||
| Property | Values | Default | Purpose | | ||
| ------------ | ---------------------------- | --------- | ----------------------------------------- | | ||
| transparent | `boolean` | `false` | The `transparency` property determines how the alpha channel is interpreted | | ||
|
||
## Structure | ||
|
||
|
@@ -309,11 +278,12 @@ States: | |
|
||
In a `horizontal` orientation top/right arrows move to the right, bottom/left arrows move to the left. | ||
|
||
| Key | Result | | ||
| -------------------- | -------------------------------------------------------------- | | ||
| Arrows | Color thumb is focused. Color is selected | | ||
| `Home/End/PgUp/PgDn` | Can be used another configuration for the step to move faster. | | ||
| `Tab` | Navigation between color sliders and Color Area | | ||
| Key | Result | | ||
| ----------- | ----------------------------------------------- | | ||
| Arrows | Color thumb is focused. Color is selected | | ||
| `PgUp/PgDn` | Can be used for faster navigation | | ||
| `Home/End` | Navigates to the beginning or end of a Slider | | ||
| `Tab` | Navigation between color sliders and Color Area | | ||
|
||
##### Color/Alpha Slider | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕵🏾♀️ visual regressions to review in the fluentuiv9 Visual Regression Report
Avatar Converged 2 screenshots