// // Copyright 2026 DXOS.org // // @import-as-namespace import React, { type HTMLAttributes, type KeyboardEvent, type MouseEvent } from 'react'; import { useTranslation } from 'react-i18next'; import { useComposedRefs } from '@dxos/react-hooks'; import { mx } from '@dxos/ui-theme'; import { type ChromaticPalette, type MessageValence, type NeutralPalette } from '@dxos/ui-types'; import { translationKey } from '#translations'; import { recipes } from '../../recipes.ts'; import { composable, composableProps } from '../../util/slots.ts'; import * as Icon from '../Icon/Icon.tsx'; export type TagHue = NeutralPalette | ChromaticPalette | MessageValence; export type TagProps = HTMLAttributes & { /** Maps to ui-theme's `--color--surface`/`-fg` tokens; valences use the same hues as the current `Tag`. */ hue?: TagHue; /** * Adds a trailing × delete trigger (Ark TagsInput's "delete trigger") inside the pill; a clickable tag also calls it * on Backspace or Delete. */ onDelete?: () => void; /** Overrides the delete trigger's translated `tag.delete.label` ("Remove "). */ deleteLabel?: string; }; /** Keys that delete a focused clickable tag, as in a tags input. */ const DELETE_KEYS = ['Backspace', 'Delete']; /** * A small pill one inset shorter than a control, so it sits inside a control or a block row. With neither `onClick` * nor `onDelete` it is a plain span. With `onClick` alone the root is a ` ) : ( {children} ); } const label = deleteLabel ?? t('tag.delete.label', { label: typeof children === 'string' ? children : '' }).trim(); return ( {onClick ? ( ) : ( children )} ); }, ); Tag.displayName = 'Tag';