import * as React from 'react'; import { ColorPicker, ChoiceGroup, IChoiceGroupOption, Toggle, getColorFromString, IColor, IColorPickerStyles, IColorPickerProps, updateA, } from '@fluentui/react/lib/index'; import { mergeStyleSets } from '@fluentui/react/lib/Styling'; const white = getColorFromString('#ffffff')!; export const ColorPickerBasicExample: React.FunctionComponent = () => { const [color, setColor] = React.useState(white); const [showPreview, setShowPreview] = React.useState(true); const [alphaType, setAlphaType] = React.useState('alpha'); const updateColor = React.useCallback((ev: any, colorObj: IColor) => setColor(colorObj), []); const onShowPreviewClick = React.useCallback((ev: any, checked?: boolean) => setShowPreview(!!checked), []); const onAlphaTypeChange = React.useCallback( (ev: any, option: IChoiceGroupOption = alphaOptions[0]) => { if (option.key === 'none') { // If hiding the alpha slider, remove transparency from the color setColor(updateA(color, 100)); } setAlphaType(option.key as IColorPickerProps['alphaType']); }, [color], ); return (
); }; const alphaOptions: IChoiceGroupOption[] = [ { key: 'alpha', text: 'Alpha' }, { key: 'transparency', text: 'Transparency' }, { key: 'none', text: 'None' }, ]; const classNames = mergeStyleSets({ wrapper: { display: 'flex' }, column2: { marginLeft: 10 }, }); const colorPickerStyles: Partial = { panel: { padding: 12 }, root: { maxWidth: 352, minWidth: 352, }, colorRectangle: { height: 268 }, };