diff --git a/packages/react-components/react-swatch-picker/stories/package.json b/packages/react-components/react-swatch-picker/stories/package.json index 7c09755b0a660..c53f16491d747 100644 --- a/packages/react-components/react-swatch-picker/stories/package.json +++ b/packages/react-components/react-swatch-picker/stories/package.json @@ -4,6 +4,7 @@ "private": true, "devDependencies": { "@fluentui/react-components": "*", + "@fluentui/react-color-picker-preview": "*", "@fluentui/react-storybook-addon": "*", "@fluentui/react-storybook-addon-export-to-sandbox": "*", "@fluentui/scripts-storybook": "*", diff --git a/packages/react-components/react-swatch-picker/stories/src/SwatchPicker/EmptySwatch.stories.tsx b/packages/react-components/react-swatch-picker/stories/src/SwatchPicker/EmptySwatch.stories.tsx index 7f35cdfe660c6..bd8cb9d89e27c 100644 --- a/packages/react-components/react-swatch-picker/stories/src/SwatchPicker/EmptySwatch.stories.tsx +++ b/packages/react-components/react-swatch-picker/stories/src/SwatchPicker/EmptySwatch.stories.tsx @@ -1,9 +1,33 @@ import * as React from 'react'; -import { makeStyles, Button, Label, SwatchPicker, EmptySwatch, ColorSwatch } from '@fluentui/react-components'; +import { tinycolor } from '@ctrl/tinycolor'; +import { + makeStyles, + Button, + SwatchPicker, + EmptySwatch, + ColorSwatch, + Popover, + PopoverTrigger, + PopoverSurface, + Tooltip, +} from '@fluentui/react-components'; import type { SwatchPickerOnSelectEventHandler } from '@fluentui/react-components'; +import { + ColorPicker, + ColorSlider, + AlphaSlider, + ColorPickerProps, + ColorArea, +} from '@fluentui/react-color-picker-preview'; const useStyles = makeStyles({ example: { + width: '300px', + display: 'flex', + flexDirection: 'column', + gap: '10px', + }, + selectedColor: { width: '100px', height: '100px', border: '1px solid #ccc', @@ -15,10 +39,27 @@ const useStyles = makeStyles({ button: { marginRight: '8px', }, - input: { + previewColor: { + margin: '10px 0', + width: '50px', + height: '50px', + borderRadius: '4px', + border: '1px solid #ccc', + }, + previewButton: { + minWidth: '50px', + height: '50px', display: 'block', margin: '10px 0', }, + rowWrapper: { + display: 'flex', + gap: '10px', + }, + sliders: { + display: 'flex', + flexDirection: 'column', + }, }); const ITEMS_LIMIT = 8; @@ -30,24 +71,33 @@ const defaultItems = [ { color: '#00B053', value: '00B053', 'aria-label': 'green' }, ]; +const DEFAULT_COLOR_HSV = tinycolor('#2be700').toHsv(); + export const EmptySwatchExample = () => { const styles = useStyles(); const [selectedValue, setSelectedValue] = React.useState('00B053'); const [selectedColor, setSelectedColor] = React.useState('#00B053'); + const [popoverOpen, setPopoverOpen] = React.useState(false); + const [previewColor, setPreviewColor] = React.useState(DEFAULT_COLOR_HSV); + const [color, setColor] = React.useState(DEFAULT_COLOR_HSV); - const inputRef = React.useRef(null); const colorFocusTargetRef = React.useRef(null); const [colorFocusTarget, setColorFocusTarget] = React.useState(null); const [items, setItems] = React.useState>(defaultItems); const emptyItems = new Array(ITEMS_LIMIT - items.length).fill(null); + const handleChange: ColorPickerProps['onColorChange'] = (_, data) => { + setPreviewColor({ ...data.color, a: data.color.a ?? 1 }); + }; + const handleSelect: SwatchPickerOnSelectEventHandler = (_, data) => { setSelectedValue(data.selectedValue); setSelectedColor(data.selectedSwatch); }; + const handleAddColor = () => { - const newColor = inputRef.current?.value as string; + const newColor = tinycolor(color).toRgbString(); // "value" should be unique as it's used as a key and for selection const newValue = `custom-${newColor} [${items.length - ITEMS_LIMIT}]`; @@ -80,10 +130,47 @@ export const EmptySwatchExample = () => { ))} +

Selected swatch

+
+ setPopoverOpen(data.open)}> + + + + +
+ + -
- -