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,cAAc,WAAW,CAAA,GAAA,iBAAS,EAAE,aAAa,WAAW;QAAC;KAAU;IACxG,IAAI,UAAC,MAAM,EAAC,GAAG,CAAA,GAAA,gBAAQ;IACvB,IAAI,MAAM,CAAA,GAAA,iBAAS,EAAE;IACrB,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,MAAM,MAAM,QAAQ,CAAC;QACzB,IAAI,GAAG,CAAC,KAAK;QACb,OAAO;YACL,IAAI,MAAM,CAAC;QACb;IACF,GAAG;QAAC;QAAO;KAAI;IAEf,IAAI,OAAO,CAAC;QACV,IAAI,OAAO,MAAM,YACf,OAAO,CAAC,cAAgB,EAAE;gBAAC,GAAG,WAAW;uBAAE;YAAK;QAElD,OAAO;IACT;IAEA,qBACE,gCAAC,CAAA,GAAA,wCAAU;QACR,GAAG,KAAK;QACT,yCAAyC;QACzC,QAAQ,MAAM,MAAM;QACpB,KAAK;QACL,IAAI,MAAM,QAAQ,CAAC;QACnB,WAAW,MAAM,YAAY,CAAC;QAC9B,WAAW,KAAK,MAAM,SAAS,IAAI;QACnC,OAAO,KAAK,MAAM,KAAK;OACtB,CAAA,GAAA,yCAAiB,EAAE,KAAK,MAAM,QAAQ,GAAG,CAAA,yBACxC,gCAAC,CAAA,GAAA,yCAAiB,EAAE,QAAQ;YAAC,OAAO;uBAAC;YAAK;WACvC;AAKX","sources":["packages/react-aria-components/src/ColorSwatchPicker.tsx"],"sourcesContent":["import {AriaLabelingProps, GlobalDOMAttributes, HoverEvents, PressEvents, ValueBase} from '@react-types/shared';\nimport {\n  ClassNameOrFunction,\n  composeRenderProps,\n  ContextValue,\n  RenderProps,\n  StyleRenderProps,\n  useContextProps\n} from './utils';\nimport {Color} from 'react-stately/Color';\nimport {ColorSwatchContext} from './ColorSwatch';\nimport {filterDOMProps} from 'react-aria/filterDOMProps';\nimport intlMessages from '../intl/*.json';\nimport {ListBox, ListBoxItem, ListBoxItemRenderProps, ListBoxRenderProps} from './ListBox';\n// @ts-ignore\nimport {parseColor} from 'react-stately/Color';\nimport React, {createContext, ForwardedRef, forwardRef, ReactNode, useContext, useEffect, useMemo} from 'react';\nimport {useColorPickerState} from 'react-stately/useColorPickerState';\nimport {useLocale} from 'react-aria/I18nProvider';\nimport {useLocalizedStringFormatter} from 'react-aria/useLocalizedStringFormatter';\n\nexport interface ColorSwatchPickerRenderProps extends Omit<ListBoxRenderProps, 'isDropTarget'> {}\nexport interface ColorSwatchPickerProps extends ValueBase<string | Color, Color>, AriaLabelingProps, StyleRenderProps<ColorSwatchPickerRenderProps>, GlobalDOMAttributes<HTMLDivElement> {\n  /**\n   * The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state.\n   * @default 'react-aria-ColorSwatchPicker'\n   */\n  className?: ClassNameOrFunction<ColorSwatchPickerRenderProps>,\n  /** The children of the ColorSwatchPicker. */\n  children?: ReactNode,\n  /**\n   * Whether the items are arranged in a stack or grid.\n   * @default 'grid'\n   */\n  layout?: 'grid' | 'stack'\n}\n\nexport const ColorSwatchPickerContext = createContext<ContextValue<ColorSwatchPickerProps, HTMLDivElement>>(null);\nconst ColorMapContext = createContext<Map<string, Color> | null>(null);\n\n/**\n * A ColorSwatchPicker displays a list of color swatches and allows a user to select one of them.\n */\nexport const ColorSwatchPicker = forwardRef(function ColorSwatchPicker(props: ColorSwatchPickerProps, ref: ForwardedRef<HTMLDivElement>) {\n  [props, ref] = useContextProps(props, ref, ColorSwatchPickerContext);\n  let state = useColorPickerState(props);\n  let colorMap = useMemo(() => new Map(), []);\n  let formatter = useLocalizedStringFormatter(intlMessages, 'react-aria-components');\n\n  return (\n    <ListBox\n      {...filterDOMProps(props, {labelable: true})}\n      ref={ref}\n      className={props.className || 'react-aria-ColorSwatchPicker'}\n      style={props.style}\n      aria-label={props['aria-label'] || (!props['aria-labelledby'] ? formatter.format('colorSwatchPicker') : undefined)}\n      layout={props.layout || 'grid'}\n      selectionMode=\"single\"\n      selectedKeys={[state.color.toString('hexa')]}\n      onSelectionChange={(keys) => {\n        // single select, 'all' cannot occur. appease typescript.\n        if (keys !== 'all') {\n          state.setColor(colorMap.get([...keys][0]));\n        }\n      }}\n      disallowEmptySelection>\n      <ColorMapContext.Provider value={colorMap}>\n        {props.children}\n      </ColorMapContext.Provider>\n    </ListBox>\n  );\n});\n\nexport interface ColorSwatchPickerItemRenderProps extends Omit<ListBoxItemRenderProps, 'selectionMode' | 'selectionBehavior'> {\n  /** The color of the swatch. */\n  color: Color\n}\n\nexport interface ColorSwatchPickerItemProps extends RenderProps<ColorSwatchPickerItemRenderProps>, HoverEvents, PressEvents, Omit<GlobalDOMAttributes<HTMLDivElement>, 'onClick'> {\n  /**\n   * The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state.\n   * @default 'react-aria-ColorSwatchPickerItem'\n   */\n  className?: ClassNameOrFunction<ColorSwatchPickerItemRenderProps>,\n  /** The color of the swatch. */\n  color: string | Color,\n  /** Whether the color swatch is disabled. */\n  isDisabled?: boolean\n}\n\nexport const ColorSwatchPickerItem = forwardRef(function ColorSwatchPickerItem(props: ColorSwatchPickerItemProps, ref: ForwardedRef<HTMLDivElement>) {\n  let propColor = props.color || '#0000';\n  let color = useMemo(() => typeof propColor === 'string' ? parseColor(propColor) : propColor, [propColor]);\n  let {locale} = useLocale();\n  let map = useContext(ColorMapContext)!;\n  useEffect(() => {\n    let key = color.toString('hexa');\n    map.set(key, color);\n    return () => {\n      map.delete(key);\n    };\n  }, [color, map]);\n\n  let wrap = (v) => {\n    if (typeof v === 'function') {\n      return (renderProps) => v({...renderProps, color});\n    }\n    return v;\n  };\n\n  return (\n    <ListBoxItem\n      {...props}\n      // ColorSwatchPickerItem is never a link.\n      render={props.render as any}\n      ref={ref}\n      id={color.toString('hexa')}\n      textValue={color.getColorName(locale)}\n      className={wrap(props.className || 'react-aria-ColorSwatchPickerItem')}\n      style={wrap(props.style)}>\n      {composeRenderProps(wrap(props.children), children => (\n        <ColorSwatchContext.Provider value={{color}}>\n          {children}\n        </ColorSwatchContext.Provider>\n      ))}\n    </ListBoxItem>\n  );\n});\n"],"names":[],"version":3,"file":"ColorSwatchPicker.mjs.map"}