{"version":3,"file":"SelectionChip.mjs","sources":["../../../src/components/SelectionChip/SelectionChip.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport React, { forwardRef } from 'react';\n\nimport type {\n  ForwardedRefComponent,\n  IconOrContent,\n} from '../../util/utility-types';\n\nimport { hasSlotContent, IconSlot } from '../Icon';\nimport Text from '../Text';\n\nimport styles from './SelectionChip.module.css';\n\nexport type SelectionChipProps = {\n  // Component API\n  /**\n   * CSS properties defined for the HTML element. Includes the component's CSS Custom Properties:\n   *\n   * - `--selection-chip__bg`\n   * - `--selection-chip__border`\n   * - `--selection-chip__fg`\n   */\n  style?: SelectionChipCSSProperties;\n  // Design API\n  /**\n   * Whether the chip is disabled or not\n   */\n  isDisabled?: boolean;\n  /**\n   * Text used in the chip to give it a description\n   */\n  label: string;\n  /**\n   * Content that precedes the label. Pass an EDS icon name to render a decorative\n   * icon, or a node to render it as-is.\n   */\n  leadingContent?: IconOrContent;\n  /**\n   * Chip types (correspond to the equivalent input types)\n   */\n  type?: 'checkbox' | 'radio';\n} & Pick<\n  React.InputHTMLAttributes<HTMLInputElement>,\n  'id' | 'name' | 'className' | 'checked' | 'defaultChecked' | 'onChange'\n>;\n\nexport interface SelectionChipCSSProperties extends React.CSSProperties {\n  /**\n   * Custom property to customize the background color of this component (e.g., background color)\n   */\n  '--selection-chip__bg'?: string;\n\n  /**\n   * Custom property to customize the border color of this component\n   */\n  '--selection-chip__border'?: string;\n\n  /**\n   * Custom property to customize the foreground color of this component (e.g., text, icon, etc.)\n   */\n  '--selection-chip__fg'?: string;\n}\n\ntype SelectionChipRefProps = ForwardedRefComponent<\n  HTMLInputElement,\n  SelectionChipProps\n>;\n\n/**\n * ## Usage\n *\n * A selection chip is an interactive chip that can be selected, deselected, or toggled. Use it to represent user controls or selections outside the context of a form, in place of a checkbox group, radio button group, or toggle. Common uses include filtering content and selecting multiple items.\n *\n * ### Best Practices\n *\n * * **Enable quick selection**: When you want users to choose from a limited set of related, easily digestible options, such as selecting filters or tags in search and content filtering.\n * * **Show multi-select options**: When users need the option to select multiple items at once, especially when toggling on/off multiple states or filters.\n * * **Enhance readability in tight spaces**: Selection chips help maintain readability while maximizing available screen space, especially on mobile.\n * * **Improve visual clarity**: When you need to show clear boundaries around items. Chips with subtle visual indicators like icons or colors can also convey context.\n * * **Replace dropdowns or radio buttons**: When dropdowns or radio buttons are too clunky or take up too much space.\n *\n * ## Interaction\n *\n * Unless used as a toggle, chips should always be presented as a group.\n *\n * Selection chips don't have built-in error handling. To show that something went wrong with a selection, pair the chips with an `InlineNotification` or `FieldNote` component to display the error message.\n *\n * ## Content & Accessibility\n *\n * ### Do's\n *\n * * Keep labels to 1-2 words.\n * * Represent one piece of info per chip. This could be a discrete thing, a grouping, category, etc.\n */\nexport const SelectionChip: SelectionChipRefProps = forwardRef(\n  (\n    {\n      checked,\n      className,\n      defaultChecked,\n      id,\n      isDisabled,\n      label,\n      leadingContent,\n      name,\n      onChange,\n      type = 'checkbox',\n      ...other\n    },\n    ref,\n  ) => {\n    const componentClassName = clsx(\n      styles['selection-chip'],\n      hasSlotContent(leadingContent) &&\n        styles['selection-chip--has-leading-content'],\n      isDisabled && styles['selection-chip--disabled'],\n      className,\n    );\n\n    const generatedIdVar = React.useId();\n    const idVar = id || generatedIdVar;\n\n    return (\n      <label\n        className={componentClassName}\n        htmlFor={idVar}\n        inert={isDisabled}\n        {...other}\n      >\n        <input\n          checked={checked}\n          className={styles['selection-chip__input']}\n          defaultChecked={defaultChecked}\n          disabled={isDisabled}\n          id={idVar}\n          name={name}\n          onChange={onChange}\n          ref={ref}\n          type={type}\n        />\n        <div className={styles['selection-chip__body']}>\n          {hasSlotContent(leadingContent) && (\n            <IconSlot content={leadingContent} />\n          )}\n          <Text\n            as=\"span\"\n            className={styles['selection-chip__label']}\n            preset=\"label-lg\"\n          >\n            {label}\n          </Text>\n        </div>\n      </label>\n    );\n  },\n);\n\nSelectionChip.displayName = 'SelectionChip';\n"],"names":["React"],"mappings":";;;;;;;;AAoE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