{"version":3,"file":"ColorPickerInput.mjs","sources":["../../../admin/src/components/ColorPickerInput.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n  Button,\n  Box,\n  Field,\n  Flex,\n  Popover,\n  Typography,\n  useComposedRefs,\n} from '@strapi/design-system';\nimport { CaretDown } from '@strapi/icons';\nimport { type InputProps, useField } from '@strapi/strapi/admin';\nimport { HexColorPicker } from 'react-colorful';\nimport { useIntl } from 'react-intl';\nimport { styled } from 'styled-components';\n\nimport { getTrad } from '../utils/getTrad';\n\nconst ColorPreview = styled.div`\n  border-radius: 50%;\n  width: 20px;\n  height: 20px;\n  margin-right: 10px;\n  background-color: ${(props) => props.color};\n  border: 1px solid rgba(0, 0, 0, 0.1);\n`;\n\nconst ColorPicker = styled(HexColorPicker)`\n  && {\n    width: 100%;\n    aspect-ratio: 1.5;\n  }\n\n  .react-colorful__pointer {\n    width: ${({ theme }) => theme.spaces[3]};\n    height: ${({ theme }) => theme.spaces[3]};\n  }\n\n  .react-colorful__saturation {\n    border-radius: ${({ theme }) => theme.spaces[1]};\n    border-bottom: none;\n  }\n\n  .react-colorful__hue {\n    border-radius: 10px;\n    height: ${({ theme }) => theme.spaces[3]};\n    margin-top: ${({ theme }) => theme.spaces[2]};\n  }\n`;\n\nconst ColorPickerToggle = styled(Button)`\n  & > span {\n    display: flex;\n    justify-content: space-between;\n    align-items: center;\n    width: 100%;\n  }\n\n  svg {\n    width: ${({ theme }) => theme.spaces[2]};\n    height: ${({ theme }) => theme.spaces[2]};\n  }\n\n  svg > path {\n    fill: ${({ theme }) => theme.colors.neutral500};\n    justify-self: flex-end;\n  }\n`;\n\nconst ColorPickerPopover = styled(Popover.Content)`\n  padding: ${({ theme }) => theme.spaces[2]};\n  min-height: 270px;\n`;\n\ntype ColorPickerInputProps = InputProps & {\n  labelAction?: React.ReactNode;\n};\n\nexport const ColorPickerInput = React.forwardRef<HTMLButtonElement, ColorPickerInputProps>(\n  ({ hint, disabled, labelAction, label, name, required, ...props }, forwardedRef) => {\n    const [showColorPicker, setShowColorPicker] = React.useState(false);\n    const colorPickerButtonRef = React.useRef<HTMLButtonElement>(null!);\n    const { formatMessage } = useIntl();\n    const field = useField<string>(name);\n\n    /**\n     * The color that will show in the field. We can't presume to show black or something\n     *   if no value is currently set (as `null` really corresponds to no color, not\n     *   black), so default to empty string if nothing else is available. */\n    const color = field.value ?? props.placeholder ?? '';\n    const hasColor = field.value !== undefined && field.value !== null && field.value !== '';\n\n    const composedRefs = useComposedRefs(forwardedRef, colorPickerButtonRef);\n\n    return (\n      <Field.Root name={name} id={name} error={field.error} hint={hint} required={required}>\n        <Flex direction=\"column\" alignItems=\"stretch\" gap={1}>\n          <Field.Label action={labelAction}>{label}</Field.Label>\n          <Popover.Root onOpenChange={setShowColorPicker}>\n            <Popover.Trigger>\n              <ColorPickerToggle\n                ref={composedRefs}\n                aria-label={formatMessage({\n                  id: getTrad('color-picker.toggle.aria-label'),\n                  defaultMessage: 'Color picker toggle',\n                })}\n                aria-controls=\"color-picker-value\"\n                aria-haspopup=\"dialog\"\n                aria-expanded={showColorPicker}\n                aria-disabled={disabled}\n                disabled={disabled}\n                variant=\"tertiary\"\n                size=\"L\"\n              >\n                <Flex>\n                  <ColorPreview color={color} />\n                  <Typography\n                    style={{ textTransform: 'uppercase' }}\n                    textColor={hasColor === true ? undefined : 'neutral500'}\n                    variant=\"omega\"\n                  >\n                    {color}\n                  </Typography>\n                </Flex>\n                <CaretDown aria-hidden />\n              </ColorPickerToggle>\n            </Popover.Trigger>\n            <ColorPickerPopover sideOffset={4}>\n              <ColorPicker color={color} onChange={(hexValue) => field.onChange(name, hexValue)} />\n              <Flex paddingTop={3} paddingLeft={4} justifyContent=\"flex-end\">\n                <Box paddingRight={2}>\n                  <Typography variant=\"omega\" tag=\"label\" textColor=\"neutral600\">\n                    {formatMessage({\n                      id: getTrad('color-picker.input.format'),\n                      defaultMessage: 'HEX',\n                    })}\n                  </Typography>\n                </Box>\n                <Field.Root>\n                  <Field.Input\n                    aria-label={formatMessage({\n                      id: getTrad('color-picker.input.aria-label'),\n                      defaultMessage: 'Color picker input',\n                    })}\n                    style={{ textTransform: 'uppercase' }}\n                    name={name}\n                    // No default value. If nothing is selected, the input will be empty.\n                    defaultValue={field.value ?? ''}\n                    // Here we default to #000000 as the placeholder, because, absent a\n                    //   user defined placeholder, we want to indicate the desired format.\n                    placeholder=\"#000000\"\n                    onChange={field.onChange}\n                    {...props}\n                  />\n                </Field.Root>\n              </Flex>\n            </ColorPickerPopover>\n          </Popover.Root>\n          <Field.Hint />\n          <Field.Error />\n        </Flex>\n      </Field.Root>\n    );\n  }\n);\n"],"names":["ColorPreview","styled","div","props","color","ColorPicker","HexColorPicker","theme","spaces","ColorPickerToggle","Button","colors","neutral500","ColorPickerPopover","Popover","Content","ColorPickerInput","React","forwardRef","hint","disabled","labelAction","label","name","required","forwardedRef","showColorPicker","setShowColorPicker","useState","colorPickerButtonRef","useRef","formatMessage","useIntl","field","useField","value","placeholder","hasColor","undefined","composedRefs","useComposedRefs","_jsx","Field","Root","id","error","_jsxs","Flex","direction","alignItems","gap","Label","action","onOpenChange","Trigger","ref","aria-label","getTrad","defaultMessage","aria-controls","aria-haspopup","aria-expanded","aria-disabled","variant","size","Typography","style","textTransform","textColor","CaretDown","aria-hidden","sideOffset","onChange","hexValue","paddingTop","paddingLeft","justifyContent","Box","paddingRight","tag","Input","defaultValue","Hint","Error"],"mappings":";;;;;;;;;;AAmBA,MAAMA,YAAAA,GAAeC,MAAAA,CAAOC,GAAG;;;;;AAKX,oBAAA,EAAE,CAACC,KAAAA,GAAUA,KAAAA,CAAMC,KAAK,CAAC;;AAE7C,CAAC;AAED,MAAMC,WAAAA,GAAcJ,MAAAA,CAAOK,cAAAA,CAAe;;;;;;;WAO/B,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAAA,CAAMC,MAAM,CAAC,CAAA,CAAE,CAAC;YAChC,EAAE,CAAC,EAAED,KAAK,EAAE,GAAKA,KAAAA,CAA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