{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-action-set",
  "type": "registry:ui",
  "title": "react-tw/action-set.tsx",
  "description": "The row the buttons sit in (ActionSet, the side panel and tearsheet footers): Carbon's full-bleed buttons touch; Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [],
  "registryDependencies": [
    "@kanok-ui/core-action-set",
    "@kanok-ui/tw-button",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/action-set.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/action-set.tsx",
      "content": "import { useEffect, type ComponentProps, type ReactNode } from 'react';\nimport { actionSetProblems, actionWidth, sortActions, willStack, type ActionSetSize } from '../core/action-set.ts';\nimport { Button, type ButtonKind, type ButtonProps } from './button.tsx';\nimport { cn } from './lib/utils.ts';\n\n/** One action of an ActionSet (Carbon React `actions`): a Button's props plus its label. */\nexport interface ActionSetAction extends Omit<ButtonProps, 'children' | 'kind' | 'size'> {\n    label: ReactNode;\n    /** Carbon's `danger--ghost` is our `danger-ghost`. */\n    kind?: ButtonKind | 'danger--ghost';\n}\n\n// literal classes, so Tailwind sees every one; --ui-actions-button-flex lets a design keep the buttons their own width\nconst WIDTH: Record<string, string> = {\n    '0 0 100%': 'flex-[var(--ui-actions-button-flex,0_0_100%)]',\n    '0 1 50%': 'flex-[var(--ui-actions-button-flex,0_1_50%)]',\n    '0 1 25%': 'flex-[var(--ui-actions-button-flex,0_1_25%)] max-w-[232px]',\n    '1 1 75%': 'flex-[var(--ui-actions-button-flex,1_1_75%)]',\n    '1 1 50%': 'flex-[var(--ui-actions-button-flex,1_1_50%)]',\n    '1 1 25%': 'flex-[var(--ui-actions-button-flex,1_1_25%)]',\n};\n\n/**\n * The row the buttons sit in (ActionSet, the side panel and tearsheet footers): Carbon's full-bleed buttons touch;\n * --ui-actions-gap / -padding let a design space ordinary buttons at the end.\n */\nexport const actionRowClasses = 'gap-[var(--ui-actions-gap,normal)] p-[var(--ui-actions-padding,0px)]';\n\n/** A stacked set: a column, primary on top (--ui-actions-stacked-*: a design can keep a wrapping row of ordinary buttons). */\nexport const stackedClasses = '[flex-direction:var(--ui-actions-stacked-direction,column-reverse)] [flex-wrap:var(--ui-actions-stacked-wrap,nowrap)]';\n\nconst kindOf = (kind: ActionSetAction['kind']): ButtonKind => (kind === 'danger--ghost' ? 'danger-ghost' : (kind ?? 'primary'));\n\n/**\n * The buttons of a set in Carbon's order and widths, for ActionSet and the side panel / tearsheet footers. Warns on the\n * console when they break Carbon's rules (Carbon for IBM Products' `ActionSet` logs \"Invalid prop `actions` supplied to\n * `ActionSet`: …\"), once per change of the problems.\n */\nexport function ActionButtons({ actions, size, stacking }: Readonly<{ actions: readonly ActionSetAction[]; size: ActionSetSize; stacking: boolean }>) {\n    const problems = actionSetProblems(\n        actions.map((action) => action.kind),\n        size,\n    ).join(', and ');\n    useEffect(() => {\n        if (problems) console.warn(`ActionSet: ${problems}.`);\n    }, [problems]);\n    // in Carbon's row order (ghost … primary) also when stacked: the column runs bottom-up (primary on top), as the\n    // <ui-action-set> slot does, so the Tab order and a design's row (--ui-actions-stacked-direction) match it\n    return sortActions(actions, false).map(({ label, kind, className, ...button }, index) => {\n        const own = kindOf(kind);\n        const ghost = own === 'ghost' || own === 'danger-ghost';\n        return (\n            <Button\n                key={typeof label === 'string' ? label : index}\n                {...button}\n                kind={own}\n                className={cn(\n                    // Carbon: the text 16px from the top; --ui-actions-button-align / -padding-top let a design centre it\n                    'm-0 [--ui-button-align:var(--ui-actions-button-align,flex-start)] pt-[var(--ui-actions-button-padding-top,var(--ui-space-md))]',\n                    stacking ? 'w-[var(--ui-actions-stacked-width,100%)] flex-none' : WIDTH[actionWidth(own, actions.length, size, false).flex],\n                    ghost && !stacking && 'ps-4',\n                    // 1px button-separator between neighbours (stacked: above each lower one), not next to the focused one; the\n                    // button set's setting (Kanok: none)\n                    stacking\n                        ? '[&:not(:last-child):not(:focus-within)]:shadow-[0_-1px_0_0_var(--ui-button-set-separator,var(--ui-button-separator))]'\n                        : '[&:not(:first-child):not(:focus-within)]:shadow-[-1px_0_0_0_var(--ui-button-set-separator,var(--ui-button-separator))]',\n                    className,\n                )}\n            >\n                {label}\n            </Button>\n        );\n    });\n}\n\nexport interface ActionSetProps extends Omit<ComponentProps<'div'>, 'children'> {\n    /** Up to four actions; shown in Carbon's order (ghost … primary; primary on top when stacked). */\n    actions: readonly ActionSetAction[];\n    /** The set's size (a side panel's size; xs counts as sm): how the buttons share the row, or stack. */\n    size?: ActionSetSize;\n    /** 48px buttons instead of 64px. */\n    condensed?: boolean;\n    /** Keep the buttons in a row even where Carbon would stack them. */\n    disableStacking?: boolean;\n}\n\n/**\n * Carbon for IBM Products `ActionSet` as React + Tailwind, the look of `<ui-action-set>`: the action buttons at the\n * foot of a side panel or tearsheet — 64px expressive buttons with their text at the top (48px `condensed`), 1px\n * separators, sorted (ghost … primary) and sized by `size` and their number; small sets, and medium ones with three,\n * stack them with the primary on top.\n */\nexport function ActionSet({ actions, size = 'md', condensed = false, disableStacking = false, className, ...rest }: Readonly<ActionSetProps>) {\n    const stacking = !disableStacking && willStack(size, actions.length);\n    return (\n        <div {...rest} className={cn('flex justify-end bg-surface-1', actionRowClasses, stacking && stackedClasses, condensed ? '[--ui-field-height-lg:48px]' : '[--ui-field-height-lg:64px]', className)}>\n            <ActionButtons actions={actions} size={size} stacking={stacking} />\n        </div>\n    );\n}\n"
    }
  ]
}
