{"version":3,"file":"chunk-Button.mjs","names":["Fieldset.useFieldsetDisabled","Icon.Icon","Tooltip.Root","Tooltip.Trigger","Tooltip.Content"],"sources":["../../src/components/Button/Button.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport React, { type ButtonHTMLAttributes, type ReactNode } from 'react';\n\nimport { type ChromaticPalette, type ClassNameValue, type MessageValence, type NeutralPalette } from '@dxos/ui-types';\n\nimport { recipes } from '../../recipes.ts';\nimport { type Size } from '../../sizes.ts';\nimport { composable, composableProps } from '../../util/slots.ts';\nimport * as Fieldset from '../Fieldset/Fieldset.tsx';\nimport * as Icon from '../Icon/Icon.tsx';\nimport { useToolbarItem } from '../Toolbar/toolbar-context.ts';\nimport * as Tooltip from '../Tooltip/Tooltip.tsx';\n\n/** The current Button's variants; `primary` marks the one action a surface leads with (e.g. a form's Save). */\nexport type ButtonVariant = 'default' | 'primary' | 'ghost' | 'outline' | 'destructive' | 'valence';\n\nexport type ButtonValence = MessageValence;\n\n/** Tag's palette (`TagHue`), repeated here since Tag builds on nothing of Button's. */\nexport type ButtonHue = NeutralPalette | ChromaticPalette | MessageValence;\n\nexport type ButtonVariantProps = {\n  variant?: ButtonVariant;\n  /** Colour of the `valence` variant; without it the button adopts an enclosing valence surface's, else neutral. */\n  valence?: ButtonValence;\n  /** Fills the button with a Tag's hue (`--color-<hue>-surface`/`-fg`), in place of the variant's fill. */\n  hue?: ButtonHue;\n  /**\n   * Dense inline padding (one control inset), e.g. for a run of pager buttons. An icon-only button loses its square,\n   * narrowing to its icon plus an inset either side, and compact icon-only buttons in an Input adornment abut (a\n   * stepper's − and +).\n   */\n  compact?: boolean;\n  /** A trailing caret marking a button that opens a menu. */\n  caretDown?: boolean;\n  /** `start` packs icon and label at the start (a full-width menu-like button) instead of centring them. */\n  align?: 'center' | 'start';\n  /** Spins the leading icon, as a busy indicator. */\n  spin?: boolean;\n  /** Sizes just this button (`data-size` scopes `theme/size.css`'s metrics to it), whatever its enclosing scope. */\n  size?: Size;\n  /** The icons at this size's scale instead of the button's. */\n  iconSize?: Size;\n  /** Classes for the leading icon (e.g. a state colour), where the button's own colour would not reach it. */\n  iconClassNames?: ClassNameValue;\n};\n\n/** Content is a label (or children) with optional leading/trailing icons, or a lone icon named by its label. */\nexport type ButtonContentProps =\n  | {\n      /** Leading icon. */\n      icon?: string;\n      /** Trailing icon (e.g. a caret). */\n      iconEnd?: string;\n      /** Visible text; `children` take precedence. */\n      label?: string;\n      iconOnly?: false;\n      showTooltip?: never;\n      tooltipSide?: never;\n      children?: ReactNode;\n    }\n  | {\n      icon: string;\n      /** Required: names the button (`aria-label`) and shows in a Tooltip. */\n      label: string;\n      /** A control-sized square inset in a block-sized cell (follow-up 19), showing only the icon. */\n      iconOnly: true;\n      /** Opt out of the label Tooltip, e.g. when the caller wraps the button in its own `Tooltip.Trigger`. */\n      showTooltip?: boolean;\n      /** Side of the trigger the label Tooltip opens on; below by default. */\n      tooltipSide?: Tooltip.Side;\n      iconEnd?: never;\n      children?: never;\n    };\n\nexport type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'aria-label' | 'title'> &\n  ButtonVariantProps &\n  ButtonContentProps;\n\n// `button` by default: the browser's `submit` would post an enclosing form on every click.\nexport const Button = composable<HTMLButtonElement, ButtonProps>(\n  (\n    {\n      type = 'button',\n      variant = 'default',\n      valence,\n      hue,\n      compact,\n      caretDown,\n      align,\n      spin,\n      size,\n      iconSize,\n      iconClassNames,\n      id,\n      onFocus,\n      icon,\n      iconEnd,\n      label,\n      iconOnly,\n      showTooltip = true,\n      tooltipSide,\n      children,\n      ...buttonProps\n    },\n    forwardedRef,\n  ) => {\n    const disabled = Fieldset.useFieldsetDisabled(buttonProps.disabled);\n    const toolbarItem = useToolbarItem(disabled);\n    const { className, ...attributes } = composableProps(buttonProps, { classNames: recipes.button() });\n    const button = (\n      <button\n        {...attributes}\n        disabled={disabled}\n        {...toolbarItem}\n        id={id}\n        onFocus={(event) => {\n          onFocus?.(event);\n          toolbarItem?.onFocus();\n        }}\n        type={type}\n        aria-label={iconOnly ? label : undefined}\n        data-scope='button'\n        data-part='root'\n        data-square={iconOnly ? '' : undefined}\n        data-size={size}\n        data-variant={variant}\n        data-valence={variant === 'valence' ? valence : undefined}\n        data-hue={hue}\n        data-compact={compact ? '' : undefined}\n        data-caret={caretDown ? '' : undefined}\n        data-align={align === 'start' ? align : undefined}\n        className={className}\n        ref={forwardedRef}\n      >\n        {icon && <Icon.Icon icon={icon} spin={spin} size={iconSize} classNames={iconClassNames} />}\n        {/* Icon-only children stand in for the icon (e.g. a swatch), so they keep the square's padding. */}\n        {iconOnly ? !icon && children : (children ?? label)}\n        {iconEnd && <Icon.Icon icon={iconEnd} size={iconSize} />}\n        {caretDown && <Icon.Icon icon='ph--caret-down--bold' />}\n      </button>\n    );\n\n    if (!iconOnly || !showTooltip) {\n      return button;\n    }\n\n    return (\n      // An `asChild` parent (e.g. `Popover.Trigger`) may own the id, so the tooltip looks its trigger up by it.\n      <Tooltip.Root\n        ids={id ? { trigger: id } : undefined}\n        positioning={tooltipSide ? { placement: tooltipSide } : undefined}\n      >\n        <Tooltip.Trigger asChild>{button}</Tooltip.Trigger>\n        <Tooltip.Content>{label}</Tooltip.Content>\n      </Tooltip.Root>\n    );\n  },\n);\n\nButton.displayName = 'Button';\n"],"mappings":";;;;;;;;;AAmFA,IAAa,SAAS,YAElB,EACE,OAAO,UACP,UAAU,WACV,SACA,KACA,SACA,WACA,OACA,MACA,MACA,UACA,gBACA,IACA,SACA,MACA,SACA,OACA,UACA,cAAc,MACd,aACA,UACA,GAAG,eAEL,iBACG;CACH,MAAM,WAAWA,oBAA6B,YAAY,QAAQ;CAClE,MAAM,cAAc,eAAe,QAAQ;CAC3C,MAAM,EAAE,WAAW,GAAG,eAAe,gBAAgB,aAAa,EAAE,YAAY,QAAQ,OAAO,EAAE,CAAC;CAClG,MAAM,SACJ,qBAAC,UAAD;EACE,GAAI;EACM;EACV,GAAI;EACA;E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