{"version":3,"file":"chunk-Tag.mjs","names":["Icon.Icon"],"sources":["../../src/components/Tag/Tag.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport React, { type HTMLAttributes, type KeyboardEvent, type MouseEvent } from 'react';\nimport { useTranslation } from 'react-i18next';\n\nimport { useComposedRefs } from '@dxos/react-hooks';\nimport { mx } from '@dxos/ui-theme';\nimport { type ChromaticPalette, type MessageValence, type NeutralPalette } from '@dxos/ui-types';\n\nimport { translationKey } from '#translations';\n\nimport { recipes } from '../../recipes.ts';\nimport { composable, composableProps } from '../../util/slots.ts';\nimport * as Icon from '../Icon/Icon.tsx';\n\nexport type TagHue = NeutralPalette | ChromaticPalette | MessageValence;\n\nexport type TagVariant = 'fill' | 'outline';\n\nexport type TagProps = HTMLAttributes<HTMLElement> & {\n  /** Maps to ui-theme's `--color-<hue>-surface`/`-fg` tokens; valences use the same hues as the current `Tag`. */\n  hue?: TagHue;\n  /** `outline` draws the hue as a ring and text on no fill. */\n  variant?: TagVariant;\n  /**\n   * Adds a trailing × delete trigger (Ark TagsInput's \"delete trigger\") inside the pill; a clickable tag also calls it\n   * on Backspace or Delete.\n   */\n  onDelete?: () => void;\n  /** Overrides the delete trigger's translated `tag.delete.label` (\"Remove <text>\"). */\n  deleteLabel?: string;\n};\n\n/** Keys that delete a focused clickable tag, as in a tags input. */\nconst DELETE_KEYS = ['Backspace', 'Delete'];\n\n/**\n * A small pill one inset shorter than a control, so it sits inside a control or a block row. With neither `onClick`\n * nor `onDelete` it is a plain span. With `onClick` alone the root is a `<button>`. With `onDelete` the root is a span\n * holding the text (inside a `<button>` part `trigger` when `onClick` is also set) and a sibling `<button>` part\n * `delete-trigger`, so a button never nests inside another.\n */\nexport const Tag = composable<HTMLElement, TagProps>(\n  (\n    { hue = 'neutral', variant = 'fill', onClick, onKeyDown, onDelete, deleteLabel, children, ...props },\n    forwardedRef,\n  ) => {\n    const { t } = useTranslation(translationKey);\n    const ref = useComposedRefs<HTMLElement>(forwardedRef);\n    const { className, ...rest } = composableProps(props, { classNames: recipes.tag() });\n    const handleKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n      onKeyDown?.(event);\n      if (onDelete && !event.defaultPrevented && DELETE_KEYS.includes(event.key)) {\n        event.preventDefault();\n        onDelete();\n      }\n    };\n\n    if (!onDelete) {\n      return onClick ? (\n        <button\n          type='button'\n          {...rest}\n          onClick={onClick}\n          onKeyDown={onKeyDown}\n          data-hue={hue}\n          data-variant={variant}\n          data-scope='tag'\n          data-part='root'\n          data-clickable=''\n          className={mx(className, recipes.tagClickable())}\n          ref={ref}\n        >\n          {children}\n        </button>\n      ) : (\n        <span\n          {...rest}\n          onKeyDown={onKeyDown}\n          data-hue={hue}\n          data-variant={variant}\n          data-scope='tag'\n          data-part='root'\n          className={className}\n          ref={ref}\n        >\n          {children}\n        </span>\n      );\n    }\n\n    const label = deleteLabel ?? t('tag.delete.label', { label: typeof children === 'string' ? children : '' }).trim();\n    return (\n      <span\n        {...rest}\n        onKeyDown={onKeyDown}\n        data-hue={hue}\n        data-variant={variant}\n        data-scope='tag'\n        data-part='root'\n        className={className}\n        ref={ref}\n      >\n        {onClick ? (\n          <button\n            type='button'\n            onClick={onClick}\n            onKeyDown={handleKeyDown}\n            data-scope='tag'\n            data-part='trigger'\n            className={recipes.tagTrigger()}\n          >\n            {children}\n          </button>\n        ) : (\n          children\n        )}\n        <button\n          type='button'\n          aria-label={label}\n          onClick={(event: MouseEvent<HTMLButtonElement>) => {\n            // A tag inside a clickable row or card must not activate it too.\n            event.stopPropagation();\n            onDelete();\n          }}\n          data-scope='tag'\n          data-part='delete-trigger'\n          className={recipes.tagDeleteTrigger()}\n        >\n          <Icon.Icon icon='ph--x--regular' />\n        </button>\n      </span>\n    );\n  },\n);\n\nTag.displayName = 'Tag';\n"],"mappings":";;;;;;;;;;;;;AAsCA,IAAM,cAAc,CAAC,aAAa,QAAQ;;;;;;;AAQ1C,IAAa,MAAM,YAEf,EAA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