@stackone/malachite 2.99.1 → 2.99.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMPONENTS.md +1 -1
- package/dist/components/ChoiceGroup.js +1 -1
- package/dist/components/ChoiceGroup.js.map +1 -1
- package/dist/components/CornerBadge.js +14 -14
- package/dist/components/CornerBadge.js.map +1 -1
- package/dist/components/Divider.js +20 -17
- package/dist/components/Divider.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/COMPONENTS.md
CHANGED
|
@@ -23,7 +23,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
23
23
|
- **`Flex`** — Flexbox layout helper with semantic direction/align/justify/gap props. _Key props:_ `FlexDirection`, `FlexAlign`, `FlexJustify`, `FlexGapSize`. `as` (`div` | `span`, the latter for content inside a clickable `Surface.Row`)
|
|
24
24
|
- **`Padded`** — Padding wrapper applying consistent design-system spacing.
|
|
25
25
|
- **`Spacer`** — Empty element that adds fixed spacing between siblings.
|
|
26
|
-
- **`Divider`** — Separator; supports a dashed line style. Horizontal by default and spanning its container; `orientation="vertical"` draws a rule between inline controls (e.g. groups in a toolbar) and holds its width in a tight flex row. `length` sizes it along its own axis on a fixed scale, and it never shrinks below 1px. _Key props:_ `orientation="horizontal" | "vertical"`, `length` (`small` | `medium` | `large`), `lineStyle="solid" | "dashed"`, `DividerVariant`, `SpacingSize`, `PaddingSize`.
|
|
26
|
+
- **`Divider`** — Separator; supports a dashed line style. Horizontal by default and spanning its container; `orientation="vertical"` draws a rule between inline controls (e.g. groups in a toolbar) and holds its width in a tight flex row. `length` sizes it along its own axis on a fixed scale, and it never shrinks below 1px. `DividerVariant.Muted` is the lighter rule between parts of one card, such as above a card’s footer. _Key props:_ `orientation="horizontal" | "vertical"`, `length` (`small` | `medium` | `large`), `lineStyle="solid" | "dashed"`, `DividerVariant`, `SpacingSize`, `PaddingSize`.
|
|
27
27
|
- **`OverflowRow`** — Horizontal row that collapses items that do not fit into an overflow affordance.
|
|
28
28
|
- **`ActionBar`** — A row of actions that collapses into a single `ActionMenu` once its container drops below `collapseBelow`. Measures the nearest genuinely-wider ancestor rather than itself, since the row shrinks to its own content. `dividerBefore` renders a vertical rule in the row and a divider in the collapsed menu, so both forms group the actions the same way. _Key props:_ `buttons` (`label`, `onClick`, `icon`, `variant`, `size`, `radius`, `tooltip`, `disabled`, `dividerBefore`), `collapseBelow`, `menuLabel`, `className`.
|
|
29
29
|
- **`Popover`** — An anchored, non-modal panel for arbitrary content — a workspace switcher, an org flyout. The panel renders in its own shadow root, so malachite components inside it are styled, and joins the top layer like the other overlays. It prefers its `placement` and flips to the opposite side when there is no room, clamping along the other axis. Click-opened panels take focus and hand it back to the trigger on close; `openOn="hover"` also opens on focus and stays open while the pointer or focus is in the panel. A nested Popover counts as inside its parent for outside-press and hover dismissal, and Escape closes the topmost only. A click panel also closes when focus moves somewhere outside it and its trigger, and on close it hands focus back to the trigger only if focus would otherwise fall to the page. _Key props:_ `trigger`, `children`, `open`, `defaultOpen`, `onOpenChange`, `placement` (`bottom-start` | `bottom-end` | `top-start` | `top-end` | `top-center` | `right-start` | `right-end` | `left-start`), `openOn` (`click` | `hover`), `width` (`content` | `trigger`), `padding` (`none` | `small` | `medium`), `anchorRef` (position against another element, e.g. the section a trigger row sits in), `offset` (`small` 8px | `medium` 12px | `large` 14px), `elevation` (`default` | `raised`), `initialFocus` (a ref, or a function read when the panel is shown, for what takes focus in place of the first focusable; it is read again as the panel's content changes, so focus follows content that mounts late or a focused element that is removed, but never leaves an element the user moved to; `initialFocusRef` is its deprecated form, read on open only), `openOnArrowKey` (a click panel also opens, focus inside, on the arrow key its placement points at — ArrowDown for a `bottom-*` placement; a text field trigger keeps its arrow keys), `role` (`dialog` | `menu` | `listbox`; `menu` brings no roving focus of its own), `aria-label` or `aria-labelledby` (one is required), `className`. The panel is capped to the viewport width, and only overlays opened from inside it (menus, dropdowns, modals) count as inside for outside-press dismissal. A side placement stays level with its anchor and scrolls within the room below, sliding up only when under 160px is left. Parts for the panel body: `Popover.Header` (`title`, `action`, `divider` — `false` drops the rule and sits it 4px over the list, as its label), `Popover.Action` (`icon`, `aria-label`, `onClick`, `href` (a link that opens in a new tab on Cmd/Ctrl-click or a middle click; a plain click runs `onClick` when one is given), `disabled`, `tooltip`), `Popover.List` (a scrolling list; `scrollToSelected` scrolls the list, never the page, to its selected row, one marked `aria-current`, `aria-selected` or a checked radio, each time the popover is shown, once that row mounts), `Popover.Section` (a bordered section), `Popover.Empty` (an empty-state line), `Popover.Search` (pads a `Search` above the list without a second rule), `Popover.Note` (a footnote section in small secondary text) and `Popover.Status` (`message`, `tone` (`default` | `error`), `action` (`label`, `onClick`, `pending`), `focusable`): one `status` live region for the panel's life, announcing each message it is given and staying mounted, visually hidden, while there is none, so clear `message` rather than unmounting it. Errors announce through the same region. `focusable` with a ref makes it an `initialFocus` target; resolve to it only while it has a message, since an empty one is invisible. Reach for `Status` when the message changes while the panel is open or carries an action (loading, failed, sign-in needed), and `Empty` for a static line in a list that simply has nothing in it.
|
|
@@ -93,7 +93,7 @@ function Q({
|
|
|
93
93
|
}
|
|
94
94
|
),
|
|
95
95
|
a && /* @__PURE__ */ o(h, { size: b }),
|
|
96
|
-
!a && x(e.mark) && /* @__PURE__ */ o(h, { size: b, tone: "
|
|
96
|
+
!a && x(e.mark) && /* @__PURE__ */ o(h, { size: b, tone: "success", children: e.mark })
|
|
97
97
|
]
|
|
98
98
|
}
|
|
99
99
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChoiceGroup.js","sources":["../../src/components/ChoiceGroup.tsx"],"sourcesContent":["import type React from 'react';\nimport { useRef } from 'react';\nimport CornerBadge, { type CornerBadgeSize } from './CornerBadge';\nimport Tooltip from './Tooltip';\nimport Text from './Typography/Text';\nimport { FOCUS_RING } from './focusRing';\nimport { inertWhen } from './inert';\nimport { isRenderableNode } from './renderableNode';\nimport { nextRovingIndex, rovingTabStop } from './rovingKeys';\nimport { isCut } from './truncatedLines';\n\nexport type ChoiceGroupMode = 'radio' | 'toggle';\n\nexport type ChoiceGroupSize = 'small' | 'medium';\n\nexport type ChoiceGroupColumns = 1 | 2 | 3 | 4 | 5 | 6;\n\nexport interface ChoiceGroupOption<T extends string = string> {\n value: T;\n label: string;\n /** Before the label in a `medium` tile, such as a client's logo. Decorative. */\n icon?: React.ReactNode;\n /** A neutral corner mark while the option is not chosen, such as a star on a recommended one. */\n mark?: React.ReactNode;\n /** Names the option when its label alone says too little, e.g. \"1 year, recommended\". */\n 'aria-label'?: string;\n disabled?: boolean;\n}\n\nexport interface ChoiceGroupCustom {\n /**\n * A control that holds a choice of its own, such as a custom date picker. It fills the cell, and\n * the tick covers its top-right corner while chosen, so keep that corner clear.\n */\n control: React.ReactNode;\n /** Names the cell, a group announced as focus enters it: \"<label>, chosen\" while chosen. */\n label: string;\n /** Ticks the control's cell, as a chosen tile is ticked. */\n chosen: boolean;\n}\n\ninterface ChoiceGroupBaseProps<T extends string = string> {\n options: ChoiceGroupOption<T>[];\n /** The chosen option; one not in `options`, or none, leaves every tile unchosen. */\n value: T | undefined;\n onChange: (value: T) => void;\n /** `small` centres a label in a compact tile; `medium` leads with `icon`. */\n size?: ChoiceGroupSize;\n /** Columns across the grid, counting the `custom` cell. */\n columns?: ChoiceGroupColumns;\n disabled?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n}\n\n/**\n * `radio` is one choice among many: a single tab stop, moved with the arrow keys, Home and End,\n * and a press on the chosen tile changes nothing. `toggle` is a row of pressed buttons, each its\n * own tab stop, that reports every press, the chosen tile's too. Only a toggle group takes\n * `custom`, a last cell for a choice the tiles can't hold, such as a custom date: a radiogroup\n * may hold nothing but radios.\n */\nexport type ChoiceGroupProps<T extends string = string> = ChoiceGroupBaseProps<T> &\n ({ mode?: 'radio'; custom?: never } | { mode: 'toggle'; custom?: ChoiceGroupCustom });\n\nconst TILE_CLASSES =\n 'relative flex h-full w-full min-w-0 items-center gap-[10px] rounded-[var(--malachite-radius-lg,8px)] border-[1.5px] border-solid text-left font-[inherit] text-[var(--malachite-text-primary,rgb(23,23,23))] transition-[border-color,background-color] duration-150 cursor-pointer disabled:pointer-events-none disabled:opacity-50';\n\nconst SIZE_CLASSES: Record<ChoiceGroupSize, string> = {\n small: 'justify-center px-[8px] py-[6px]',\n medium: 'justify-start px-[12px] py-[10px]',\n};\n\nconst STATE_CLASSES = {\n // The tint is mixed from the accent, as NavItem's is, so a rebrand repaints it with the border.\n chosen: 'border-[var(--malachite-accent-background,rgb(0,175,102))] bg-[var(--malachite-accent-background-glass,rgba(0,175,102,0.08))] supports-[color:color-mix(in_srgb,red,red)]:bg-[color-mix(in_srgb,var(--malachite-accent-background,rgb(0,175,102))_12%,var(--malachite-card-background,rgb(255,255,255)))]',\n unchosen:\n 'border-[var(--malachite-card-border,rgb(232,232,232))] bg-[var(--malachite-card-background,rgb(255,255,255))] enabled:hover:border-[var(--malachite-control-border-hover,rgb(187,187,187))]',\n};\n\n// The compact tile carries the larger mark: it has more room above its centred label.\nconst BADGE_SIZES: Record<ChoiceGroupSize, CornerBadgeSize> = { small: 'medium', medium: 'small' };\n\n/**\n * A grid of tiles to choose one option from: the chosen tile takes the accent border, tint and a\n * corner tick. `mode` sets the semantics; see `ChoiceGroupProps['mode']`. The tick overhangs the\n * tile's top-right corner by a third of its size, so leave that room above and after the group.\n */\nfunction ChoiceGroup<T extends string = string>({\n options,\n value,\n onChange,\n mode = 'radio',\n size = 'medium',\n columns = 4,\n custom,\n disabled = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}: ChoiceGroupProps<T>): React.ReactElement {\n const tiles = useRef<(HTMLButtonElement | null)[]>([]);\n const labels = useRef<(HTMLSpanElement | null)[]>([]);\n\n const enabled = options.map((option) => !disabled && !option.disabled);\n const chosenIndex = options.findIndex((option) => option.value === value);\n const tabStop = rovingTabStop(chosenIndex, enabled);\n const isRadio = mode === 'radio';\n const badgeSize = BADGE_SIZES[size];\n\n const choose = (index: number) => {\n // A radio tile already chosen stays chosen; a toggle reports the press, to retry with.\n if (!isRadio || index !== chosenIndex) {\n onChange(options[index].value);\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent, index: number) => {\n const target = nextRovingIndex(event, index, enabled);\n if (target === undefined) {\n return;\n }\n event.preventDefault();\n choose(target);\n tiles.current[target]?.focus();\n };\n\n return (\n <div\n role={isRadio ? 'radiogroup' : 'group'}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-disabled={disabled || undefined}\n className={`grid gap-[8px] ${className}`}\n style={{ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))` }}\n >\n {options.map((option, index) => {\n const chosen = index === chosenIndex;\n return (\n // Around the button, so keyboard focus opens it as well as a hover.\n <Tooltip\n key={option.value}\n text={option.label}\n // Measured as it opens, not on mount: only a label cut short needs it.\n shouldShow={() => isCut(labels.current[index])}\n describesTrigger={false}\n // `fill` only: `isShrinkable` would clip the tick that overhangs the tile.\n fill\n >\n <button\n ref={(element) => {\n tiles.current[index] = element;\n }}\n type=\"button\"\n role={isRadio ? 'radio' : undefined}\n aria-checked={isRadio ? chosen : undefined}\n aria-pressed={isRadio ? undefined : chosen}\n aria-label={option['aria-label']}\n tabIndex={isRadio ? (index === tabStop ? 0 : -1) : undefined}\n disabled={!enabled[index]}\n className={`${TILE_CLASSES} ${SIZE_CLASSES[size]} ${chosen ? STATE_CLASSES.chosen : STATE_CLASSES.unchosen} ${FOCUS_RING}`}\n onClick={() => choose(index)}\n onKeyDown={isRadio ? (event) => handleKeyDown(event, index) : undefined}\n >\n {size === 'medium' && isRenderableNode(option.icon) && (\n <span\n aria-hidden=\"true\"\n className=\"inline-flex size-[22px] shrink-0 items-center justify-center\"\n >\n {option.icon}\n </span>\n )}\n <span\n ref={(element) => {\n labels.current[index] = element;\n }}\n className=\"min-w-0 overflow-hidden text-ellipsis whitespace-nowrap\"\n >\n <Text size=\"small\" fontWeight=\"semi-bold\" wrap={false}>\n {option.label}\n </Text>\n </span>\n {chosen && <CornerBadge size={badgeSize} />}\n {!chosen && isRenderableNode(option.mark) && (\n <CornerBadge size={badgeSize} tone=\"neutral\">\n {option.mark}\n </CornerBadge>\n )}\n </button>\n </Tooltip>\n );\n })}\n {custom && (\n // Announced as focus enters it; inert and dimmed with the group.\n <div\n role=\"group\"\n aria-label={custom.chosen ? `${custom.label}, chosen` : custom.label}\n className={`flex min-w-0 items-center ${disabled ? 'opacity-50' : ''}`}\n {...inertWhen(disabled)}\n >\n {/* The tick pins to the control's corner, not the taller cell's. */}\n <div className=\"relative w-full\">\n {custom.control}\n {custom.chosen && <CornerBadge size={badgeSize} />}\n </div>\n </div>\n )}\n </div>\n );\n}\n\nexport default ChoiceGroup;\nexport { ChoiceGroup };\n"],"names":["TILE_CLASSES","SIZE_CLASSES","STATE_CLASSES","BADGE_SIZES","ChoiceGroup","options","value","onChange","mode","size","columns","custom","disabled","ariaLabel","ariaLabelledBy","className","tiles","useRef","labels","enabled","option","chosenIndex","tabStop","rovingTabStop","isRadio","badgeSize","choose","index","handleKeyDown","event","target","nextRovingIndex","_a","jsxs","chosen","jsx","Tooltip","isCut","element","FOCUS_RING","isRenderableNode","Text","CornerBadge","inertWhen"],"mappings":";;;;;;;;;;AAkEA,MAAMA,IACF,wUAEEC,IAAgD;AAAA,EAClD,OAAO;AAAA,EACP,QAAQ;AACZ,GAEMC,IAAgB;AAAA;AAAA,EAElB,QAAQ;AAAA,EACR,UACI;AACR,GAGMC,IAAwD,EAAE,OAAO,UAAU,QAAQ,QAAA;AAOzF,SAASC,EAAuC;AAAA,EAC5C,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,MAAAC,IAAO;AAAA,EACP,SAAAC,IAAU;AAAA,EACV,QAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,cAAcC;AAAA,EACd,m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oBAAA;AAAA,kBAAA;AAAA,gBAAA;AAAA,cAER;AAAA,cA/CKL,EAAO;AAAA,YAAA;AAAA;AAAA,QAkDxB,CAAC;AAAA,QACAT;AAAA,QAEG,gBAAAwB;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,MAAK;AAAA,YACL,cAAYxB,EAAO,SAAS,GAAGA,EAAO,KAAK,aAAaA,EAAO;AAAA,YAC/D,WAAW,6BAA6BC,IAAW,eAAe,EAAE;AAAA,YACnE,GAAG+B,EAAU/B,CAAQ;AAAA,YAGtB,UAAA,gBAAAqB,EAAC,OAAA,EAAI,WAAU,mBACV,UAAA;AAAA,cAAAtB,EAAO;AAAA,cACPA,EAAO,UAAU,gBAAAwB,EAACO,GAAA,EAAY,MAAMjB,EAAA,CAAW;AAAA,YAAA,EAAA,CACpD;AAAA,UAAA;AAAA,QAAA;AAAA,MACJ;AAAA,IAAA;AAAA,EAAA;AAIhB;"}
|
|
1
|
+
{"version":3,"file":"ChoiceGroup.js","sources":["../../src/components/ChoiceGroup.tsx"],"sourcesContent":["import type React from 'react';\nimport { useRef } from 'react';\nimport CornerBadge, { type CornerBadgeSize } from './CornerBadge';\nimport Tooltip from './Tooltip';\nimport Text from './Typography/Text';\nimport { FOCUS_RING } from './focusRing';\nimport { inertWhen } from './inert';\nimport { isRenderableNode } from './renderableNode';\nimport { nextRovingIndex, rovingTabStop } from './rovingKeys';\nimport { isCut } from './truncatedLines';\n\nexport type ChoiceGroupMode = 'radio' | 'toggle';\n\nexport type ChoiceGroupSize = 'small' | 'medium';\n\nexport type ChoiceGroupColumns = 1 | 2 | 3 | 4 | 5 | 6;\n\nexport interface ChoiceGroupOption<T extends string = string> {\n value: T;\n label: string;\n /** Before the label in a `medium` tile, such as a client's logo. Decorative. */\n icon?: React.ReactNode;\n /** A green corner mark, deeper than the tick, while the option is not chosen, such as a star on a recommended one. */\n mark?: React.ReactNode;\n /** Names the option when its label alone says too little, e.g. \"1 year, recommended\". */\n 'aria-label'?: string;\n disabled?: boolean;\n}\n\nexport interface ChoiceGroupCustom {\n /**\n * A control that holds a choice of its own, such as a custom date picker. It fills the cell, and\n * the tick covers its top-right corner while chosen, so keep that corner clear.\n */\n control: React.ReactNode;\n /** Names the cell, a group announced as focus enters it: \"<label>, chosen\" while chosen. */\n label: string;\n /** Ticks the control's cell, as a chosen tile is ticked. */\n chosen: boolean;\n}\n\ninterface ChoiceGroupBaseProps<T extends string = string> {\n options: ChoiceGroupOption<T>[];\n /** The chosen option; one not in `options`, or none, leaves every tile unchosen. */\n value: T | undefined;\n onChange: (value: T) => void;\n /** `small` centres a label in a compact tile; `medium` leads with `icon`. */\n size?: ChoiceGroupSize;\n /** Columns across the grid, counting the `custom` cell. */\n columns?: ChoiceGroupColumns;\n disabled?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n}\n\n/**\n * `radio` is one choice among many: a single tab stop, moved with the arrow keys, Home and End,\n * and a press on the chosen tile changes nothing. `toggle` is a row of pressed buttons, each its\n * own tab stop, that reports every press, the chosen tile's too. Only a toggle group takes\n * `custom`, a last cell for a choice the tiles can't hold, such as a custom date: a radiogroup\n * may hold nothing but radios.\n */\nexport type ChoiceGroupProps<T extends string = string> = ChoiceGroupBaseProps<T> &\n ({ mode?: 'radio'; custom?: never } | { mode: 'toggle'; custom?: ChoiceGroupCustom });\n\nconst TILE_CLASSES =\n 'relative flex h-full w-full min-w-0 items-center gap-[10px] rounded-[var(--malachite-radius-lg,8px)] border-[1.5px] border-solid text-left font-[inherit] text-[var(--malachite-text-primary,rgb(23,23,23))] transition-[border-color,background-color] duration-150 cursor-pointer disabled:pointer-events-none disabled:opacity-50';\n\nconst SIZE_CLASSES: Record<ChoiceGroupSize, string> = {\n small: 'justify-center px-[8px] py-[6px]',\n medium: 'justify-start px-[12px] py-[10px]',\n};\n\nconst STATE_CLASSES = {\n // The tint is mixed from the accent, as NavItem's is, so a rebrand repaints it with the border.\n chosen: 'border-[var(--malachite-accent-background,rgb(0,175,102))] bg-[var(--malachite-accent-background-glass,rgba(0,175,102,0.08))] supports-[color:color-mix(in_srgb,red,red)]:bg-[color-mix(in_srgb,var(--malachite-accent-background,rgb(0,175,102))_12%,var(--malachite-card-background,rgb(255,255,255)))]',\n unchosen:\n 'border-[var(--malachite-card-border,rgb(232,232,232))] bg-[var(--malachite-card-background,rgb(255,255,255))] enabled:hover:border-[var(--malachite-control-border-hover,rgb(187,187,187))]',\n};\n\n// The compact tile carries the larger mark: it has more room above its centred label.\nconst BADGE_SIZES: Record<ChoiceGroupSize, CornerBadgeSize> = { small: 'medium', medium: 'small' };\n\n/**\n * A grid of tiles to choose one option from: the chosen tile takes the accent border, tint and a\n * corner tick. `mode` sets the semantics; see `ChoiceGroupProps['mode']`. The tick overhangs the\n * tile's top-right corner by a third of its size, so leave that room above and after the group.\n */\nfunction ChoiceGroup<T extends string = string>({\n options,\n value,\n onChange,\n mode = 'radio',\n size = 'medium',\n columns = 4,\n custom,\n disabled = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}: ChoiceGroupProps<T>): React.ReactElement {\n const tiles = useRef<(HTMLButtonElement | null)[]>([]);\n const labels = useRef<(HTMLSpanElement | null)[]>([]);\n\n const enabled = options.map((option) => !disabled && !option.disabled);\n const chosenIndex = options.findIndex((option) => option.value === value);\n const tabStop = rovingTabStop(chosenIndex, enabled);\n const isRadio = mode === 'radio';\n const badgeSize = BADGE_SIZES[size];\n\n const choose = (index: number) => {\n // A radio tile already chosen stays chosen; a toggle reports the press, to retry with.\n if (!isRadio || index !== chosenIndex) {\n onChange(options[index].value);\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent, index: number) => {\n const target = nextRovingIndex(event, index, enabled);\n if (target === undefined) {\n return;\n }\n event.preventDefault();\n choose(target);\n tiles.current[target]?.focus();\n };\n\n return (\n <div\n role={isRadio ? 'radiogroup' : 'group'}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-disabled={disabled || undefined}\n className={`grid gap-[8px] ${className}`}\n style={{ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))` }}\n >\n {options.map((option, index) => {\n const chosen = index === chosenIndex;\n return (\n // Around the button, so keyboard focus opens it as well as a hover.\n <Tooltip\n key={option.value}\n text={option.label}\n // Measured as it opens, not on mount: only a label cut short needs it.\n shouldShow={() => isCut(labels.current[index])}\n describesTrigger={false}\n // `fill` only: `isShrinkable` would clip the tick that overhangs the tile.\n fill\n >\n <button\n ref={(element) => {\n tiles.current[index] = element;\n }}\n type=\"button\"\n role={isRadio ? 'radio' : undefined}\n aria-checked={isRadio ? chosen : undefined}\n aria-pressed={isRadio ? undefined : chosen}\n aria-label={option['aria-label']}\n tabIndex={isRadio ? (index === tabStop ? 0 : -1) : undefined}\n disabled={!enabled[index]}\n className={`${TILE_CLASSES} ${SIZE_CLASSES[size]} ${chosen ? STATE_CLASSES.chosen : STATE_CLASSES.unchosen} ${FOCUS_RING}`}\n onClick={() => choose(index)}\n onKeyDown={isRadio ? (event) => handleKeyDown(event, index) : undefined}\n >\n {size === 'medium' && isRenderableNode(option.icon) && (\n <span\n aria-hidden=\"true\"\n className=\"inline-flex size-[22px] shrink-0 items-center justify-center\"\n >\n {option.icon}\n </span>\n )}\n <span\n ref={(element) => {\n labels.current[index] = element;\n }}\n className=\"min-w-0 overflow-hidden text-ellipsis whitespace-nowrap\"\n >\n <Text size=\"small\" fontWeight=\"semi-bold\" wrap={false}>\n {option.label}\n </Text>\n </span>\n {chosen && <CornerBadge size={badgeSize} />}\n {!chosen && isRenderableNode(option.mark) && (\n <CornerBadge size={badgeSize} tone=\"success\">\n {option.mark}\n </CornerBadge>\n )}\n </button>\n </Tooltip>\n );\n })}\n {custom && (\n // Announced as focus enters it; inert and dimmed with the group.\n <div\n role=\"group\"\n aria-label={custom.chosen ? `${custom.label}, chosen` : custom.label}\n className={`flex min-w-0 items-center ${disabled ? 'opacity-50' : ''}`}\n {...inertWhen(disabled)}\n >\n {/* The tick pins to the control's corner, not the taller cell's. */}\n <div className=\"relative w-full\">\n {custom.control}\n {custom.chosen && <CornerBadge size={badgeSize} />}\n </div>\n </div>\n )}\n </div>\n );\n}\n\nexport default ChoiceGroup;\nexport { ChoiceGroup };\n"],"names":["TILE_CLASSES","SIZE_CLASSES","STATE_CLASSES","BADGE_SIZES","ChoiceGroup","options","value","onChange","mode","size","columns","custom","disabled","ariaLabel","ariaLabelledBy","className","tiles","useRef","labels","enabled","option","chosenIndex","tabStop","rovingTabStop","isRadio","badgeSize","choose","index","handleKeyDown","event","target","nextRovingIndex","_a","jsxs","chosen","jsx","Tooltip","isCut","element","FOCUS_RING","isRenderableNode","Text","CornerBadge","inertWhen"],"mappings":";;;;;;;;;;AAkEA,MAAMA,IACF,wUAEEC,IAAgD;AAAA,EAClD,OAAO;AAAA,EACP,QAAQ;AACZ,GAEMC,IAAgB;AAAA;AAAA,EAElB,QAAQ;AAAA,EACR,UACI;AACR,GAGMC,IAAwD,EAAE,OAAO,UAAU,QAAQ,QAAA;AAOzF,SAASC,EAAuC;AAAA,EAC5C,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,MAAAC,IAAO;AAAA,EACP,SAAAC,IAAU;AAAA,EACV,QAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,cAAcC;AAAA,EACd,mBAAmBC;AAAA,EACnB,WAAAC,IAAY;AAChB,GAA4C;AACxC,QAAMC,IAAQC,EAAqC,EAAE,GAC/CC,IAASD,EAAmC,EAAE,GAE9CE,IAAUd,EAAQ,IAAI,CAACe,MAAW,CAACR,KAAY,CAACQ,EAAO,QAAQ,GAC/DC,IAAchB,EAAQ,UAAU,CAACe,MAAWA,EAAO,UAAUd,CAAK,GAClEgB,IAAUC,EAAcF,GAAaF,CAAO,GAC5CK,IAAUhB,MAAS,SACnBiB,IAAYtB,EAAYM,CAAI,GAE5BiB,IAAS,CAACC,MAAkB;AAE9B,KAAI,CAACH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BACV,UAAA;AAAA,cAAAtB,EAAO;AAAA,cACPA,EAAO,UAAU,gBAAAwB,EAACO,GAAA,EAAY,MAAMjB,EAAA,CAAW;AAAA,YAAA,EAAA,CACpD;AAAA,UAAA;AAAA,QAAA;AAAA,MACJ;AAAA,IAAA;AAAA,EAAA;AAIhB;"}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { ICON_BADGE_FILL as
|
|
4
|
-
const
|
|
1
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import s from "./CustomIcons/CheckmarkIcon.js";
|
|
3
|
+
import { ICON_BADGE_FILL as d } from "./iconBadgeVariants.js";
|
|
4
|
+
const i = {
|
|
5
5
|
small: { box: 18, glyph: 9 },
|
|
6
6
|
medium: { box: 22, glyph: 10 }
|
|
7
|
-
},
|
|
7
|
+
}, l = {
|
|
8
8
|
accent: "bg-[var(--malachite-accent-background,rgb(0,175,102))] text-white",
|
|
9
|
-
|
|
9
|
+
success: "text-[var(--malachite-card-background,rgb(255,255,255))]"
|
|
10
10
|
}, g = ({
|
|
11
|
-
children:
|
|
12
|
-
size:
|
|
11
|
+
children: t,
|
|
12
|
+
size: c = "medium",
|
|
13
13
|
tone: r = "accent",
|
|
14
|
-
className:
|
|
14
|
+
className: a = ""
|
|
15
15
|
}) => {
|
|
16
|
-
const { box: e, glyph:
|
|
17
|
-
return /* @__PURE__ */
|
|
16
|
+
const { box: e, glyph: n } = i[c];
|
|
17
|
+
return /* @__PURE__ */ o(
|
|
18
18
|
"span",
|
|
19
19
|
{
|
|
20
20
|
"aria-hidden": "true",
|
|
21
|
-
className: `pointer-events-none absolute box-border flex items-center justify-center rounded-full border-2 border-solid border-[var(--malachite-card-background,rgb(255,255,255))] ${
|
|
21
|
+
className: `pointer-events-none absolute box-border flex items-center justify-center rounded-full border-2 border-solid border-[var(--malachite-card-background,rgb(255,255,255))] ${l[r]} ${a}`,
|
|
22
22
|
style: {
|
|
23
23
|
width: e,
|
|
24
24
|
height: e,
|
|
25
25
|
top: -e / 3,
|
|
26
26
|
insetInlineEnd: -e / 3,
|
|
27
|
-
backgroundColor: r === "
|
|
27
|
+
backgroundColor: r === "success" ? d.success : void 0
|
|
28
28
|
},
|
|
29
|
-
children:
|
|
29
|
+
children: t ?? /* @__PURE__ */ o(s, { size: n })
|
|
30
30
|
}
|
|
31
31
|
);
|
|
32
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CornerBadge.js","sources":["../../src/components/CornerBadge.tsx"],"sourcesContent":["import type React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport { ICON_BADGE_FILL } from './iconBadgeVariants';\n\nexport type CornerBadgeSize = 'small' | 'medium';\n\nexport type CornerBadgeTone = 'accent' | '
|
|
1
|
+
{"version":3,"file":"CornerBadge.js","sources":["../../src/components/CornerBadge.tsx"],"sourcesContent":["import type React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport { ICON_BADGE_FILL } from './iconBadgeVariants';\n\nexport type CornerBadgeSize = 'small' | 'medium';\n\nexport type CornerBadgeTone = 'accent' | 'success';\n\nexport interface CornerBadgeProps {\n /** The mark inside; a tick when omitted. An svg painting with `currentColor`. */\n children?: React.ReactNode;\n size?: CornerBadgeSize;\n /**\n * `accent` marks a choice; `success` notes something good about the option, such as that it\n * is recommended, in IconBadge's success fill: a deeper green than the accent's tick.\n */\n tone?: CornerBadgeTone;\n className?: string;\n}\n\nconst SIZES: Record<CornerBadgeSize, { box: number; glyph: number }> = {\n small: { box: 18, glyph: 9 },\n medium: { box: 22, glyph: 10 },\n};\n\n// The accent tick is white on the fill in both themes, as Checkbox draws its tick; the success\n// mark is IconBadge's, the card colour on its fill.\nconst TONE_CLASSES: Record<CornerBadgeTone, string> = {\n accent: 'bg-[var(--malachite-accent-background,rgb(0,175,102))] text-white',\n success: 'text-[var(--malachite-card-background,rgb(255,255,255))]',\n};\n\n/**\n * A round mark pinned over the top-right corner of its parent, such as the accent tick on a chosen\n * tile. The parent must be positioned, and the badge comes after what it overlaps so it paints\n * on top. Decorative and click-through: the parent's own state says what it marks.\n */\nconst CornerBadge: React.FC<CornerBadgeProps> = ({\n children,\n size = 'medium',\n tone = 'accent',\n className = '',\n}) => {\n const { box, glyph } = SIZES[size];\n return (\n <span\n aria-hidden=\"true\"\n className={`pointer-events-none absolute box-border flex items-center justify-center rounded-full border-2 border-solid border-[var(--malachite-card-background,rgb(255,255,255))] ${TONE_CLASSES[tone]} ${className}`}\n style={{\n width: box,\n height: box,\n top: -box / 3,\n insetInlineEnd: -box / 3,\n backgroundColor: tone === 'success' ? ICON_BADGE_FILL.success : undefined,\n }}\n >\n {children ?? <CheckmarkIcon size={glyph} />}\n </span>\n );\n};\n\nexport default CornerBadge;\nexport { CornerBadge };\n"],"names":["SIZES","TONE_CLASSES","CornerBadge","children","size","tone","className","box","glyph","jsx","ICON_BADGE_FILL","CheckmarkIcon"],"mappings":";;;AAoBA,MAAMA,IAAiE;AAAA,EACnE,OAAO,EAAE,KAAK,IAAI,OAAO,EAAA;AAAA,EACzB,QAAQ,EAAE,KAAK,IAAI,OAAO,GAAA;AAC9B,GAIMC,IAAgD;AAAA,EAClD,QAAQ;AAAA,EACR,SAAS;AACb,GAOMC,IAA0C,CAAC;AAAA,EAC7C,UAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,MAAAC,IAAO;AAAA,EACP,WAAAC,IAAY;AAChB,MAAM;AACF,QAAM,EAAE,KAAAC,GAAK,OAAAC,MAAUR,EAAMI,CAAI;AACjC,SACI,gBAAAK;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,eAAY;AAAA,MACZ,WAAW,0KAA0KR,EAAaI,CAAI,CAAC,IAAIC,CAAS;AAAA,MACpN,OAAO;AAAA,QACH,OAAOC;AAAA,QACP,QAAQA;AAAA,QACR,KAAK,CAACA,IAAM;AAAA,QACZ,gBAAgB,CAACA,IAAM;AAAA,QACvB,iBAAiBF,MAAS,YAAYK,EAAgB,UAAU;AAAA,MAAA;AAAA,MAGnE,UAAAP,KAAY,gBAAAM,EAACE,GAAA,EAAc,MAAMH,EAAA,CAAO;AAAA,IAAA;AAAA,EAAA;AAGrD;"}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { DividerVariant as i, PaddingSize as
|
|
3
|
-
const
|
|
1
|
+
import { jsx as x } from "react/jsx-runtime";
|
|
2
|
+
import { DividerVariant as i, PaddingSize as a, SpacingSize as t } from "./dividerTypes.js";
|
|
3
|
+
const S = { small: 16, medium: 24, large: 32 }, h = (e) => e ? `${f(e)}px` : void 0, b = (e) => e ? `${k(e)}px` : void 0, f = (e) => {
|
|
4
4
|
switch (e) {
|
|
5
|
-
case
|
|
5
|
+
case t.XSmall:
|
|
6
6
|
return 8;
|
|
7
|
-
case
|
|
7
|
+
case t.Small:
|
|
8
8
|
return 12;
|
|
9
|
-
case
|
|
9
|
+
case t.Medium:
|
|
10
10
|
return 24;
|
|
11
|
-
case
|
|
11
|
+
case t.Large:
|
|
12
12
|
return 36;
|
|
13
13
|
}
|
|
14
14
|
}, k = (e) => {
|
|
15
15
|
switch (e) {
|
|
16
|
-
case
|
|
16
|
+
case a.XSmall:
|
|
17
17
|
return 1;
|
|
18
|
-
case
|
|
18
|
+
case a.Small:
|
|
19
19
|
return 2;
|
|
20
|
-
case
|
|
20
|
+
case a.Medium:
|
|
21
21
|
return 4;
|
|
22
|
-
case
|
|
22
|
+
case a.Large:
|
|
23
23
|
return 8;
|
|
24
24
|
}
|
|
25
25
|
}, $ = ({
|
|
@@ -28,19 +28,22 @@ const v = { small: 16, medium: 24, large: 32 }, h = (e) => e ? `${f(e)}px` : voi
|
|
|
28
28
|
margin: n,
|
|
29
29
|
padding: d,
|
|
30
30
|
className: g = "",
|
|
31
|
-
variant:
|
|
31
|
+
variant: c = i.Default,
|
|
32
32
|
lineStyle: p = "solid",
|
|
33
|
-
grow:
|
|
33
|
+
grow: s = !1
|
|
34
34
|
}) => {
|
|
35
|
-
const l =
|
|
35
|
+
const l = c === i.Default ? "var(--malachite-card-border)" : c === i.Muted ? (
|
|
36
|
+
// The theme's lighter rule, between parts of one card; no theme sets a border-muted.
|
|
37
|
+
"var(--malachite-card-subtle-divider, var(--malachite-card-border))"
|
|
38
|
+
) : "var(--malachite-border-strong)", r = e === "vertical", m = r ? "to bottom" : "to right", u = o ? `${S[o]}px` : "100%", v = {
|
|
36
39
|
height: r ? u : "1px",
|
|
37
40
|
width: r ? "1px" : u,
|
|
38
41
|
margin: n ? h(n) : void 0,
|
|
39
42
|
padding: d ? b(d) : void 0,
|
|
40
43
|
// Longhands, never the `flex` shorthand: it resets `flex-shrink` and a 1px rule that
|
|
41
44
|
// may shrink disappears between wider siblings.
|
|
42
|
-
flexGrow:
|
|
43
|
-
flexBasis:
|
|
45
|
+
flexGrow: s ? 1 : void 0,
|
|
46
|
+
flexBasis: s ? "0%" : void 0,
|
|
44
47
|
flexShrink: 0,
|
|
45
48
|
border: "none",
|
|
46
49
|
...p === "dashed" ? {
|
|
@@ -50,7 +53,7 @@ const v = { small: 16, medium: 24, large: 32 }, h = (e) => e ? `${f(e)}px` : voi
|
|
|
50
53
|
backgroundRepeat: "no-repeat"
|
|
51
54
|
} : { backgroundColor: l }
|
|
52
55
|
};
|
|
53
|
-
return /* @__PURE__ */
|
|
56
|
+
return /* @__PURE__ */ x("div", { className: g, style: v });
|
|
54
57
|
};
|
|
55
58
|
export {
|
|
56
59
|
$ as Divider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Divider.js","sources":["../../src/components/Divider.tsx"],"sourcesContent":["import React from 'react';\nimport { DividerVariant, PaddingSize, SpacingSize } from './dividerTypes';\n\nexport type DividerLineStyle = 'solid' | 'dashed';\n\nexport type DividerOrientation = 'horizontal' | 'vertical';\n\n/** Fixed lengths a rule between inline controls can take. Left unset it spans its container. */\nexport type DividerLength = 'small' | 'medium' | 'large';\n\nconst LENGTH_PX: Record<DividerLength, number> = { small: 16, medium: 24, large: 32 };\n\ninterface DividerProps {\n /** `vertical` draws a 1px rule between inline controls, e.g. groups in a toolbar. */\n orientation?: DividerOrientation;\n /** Length along the rule's own axis — height when vertical, width when horizontal.\n * Unset spans the container. */\n length?: DividerLength;\n margin?: SpacingSize;\n padding?: PaddingSize;\n className?: string;\n variant?: DividerVariant;\n lineStyle?: DividerLineStyle;\n grow?: boolean;\n}\n\n/**\n * A 1px divider using the theme's card border. Horizontal and full-width by default;\n * `orientation=\"vertical\"` draws a rule between inline controls instead.\n */\n\nconst getSpacingValue = (spacing?: SpacingSize): string | undefined => {\n return spacing ? `${getSpacingSize(spacing)}px` : undefined;\n};\n\nconst getPaddingValue = (padding?: PaddingSize): string | undefined => {\n return padding ? `${getPaddingSize(padding)}px` : undefined;\n};\n\nconst getSpacingSize = (size: SpacingSize): number => {\n switch (size) {\n case SpacingSize.XSmall:\n return 8;\n case SpacingSize.Small:\n return 12;\n case SpacingSize.Medium:\n return 24;\n case SpacingSize.Large:\n return 36;\n }\n};\n\nconst getPaddingSize = (size: PaddingSize): number => {\n switch (size) {\n case PaddingSize.XSmall:\n return 1;\n case PaddingSize.Small:\n return 2;\n case PaddingSize.Medium:\n return 4;\n case PaddingSize.Large:\n return 8;\n }\n};\n\nconst Divider: React.FC<DividerProps> = ({\n orientation = 'horizontal',\n length,\n margin,\n padding,\n className = '',\n variant = DividerVariant.Default,\n lineStyle = 'solid',\n grow = false,\n}) => {\n const lineColor =\n variant === DividerVariant.Default\n ? 'var(--malachite-card-border)'\n : variant === DividerVariant.Muted\n ? 'var(--malachite-border
|
|
1
|
+
{"version":3,"file":"Divider.js","sources":["../../src/components/Divider.tsx"],"sourcesContent":["import React from 'react';\nimport { DividerVariant, PaddingSize, SpacingSize } from './dividerTypes';\n\nexport type DividerLineStyle = 'solid' | 'dashed';\n\nexport type DividerOrientation = 'horizontal' | 'vertical';\n\n/** Fixed lengths a rule between inline controls can take. Left unset it spans its container. */\nexport type DividerLength = 'small' | 'medium' | 'large';\n\nconst LENGTH_PX: Record<DividerLength, number> = { small: 16, medium: 24, large: 32 };\n\ninterface DividerProps {\n /** `vertical` draws a 1px rule between inline controls, e.g. groups in a toolbar. */\n orientation?: DividerOrientation;\n /** Length along the rule's own axis — height when vertical, width when horizontal.\n * Unset spans the container. */\n length?: DividerLength;\n margin?: SpacingSize;\n padding?: PaddingSize;\n className?: string;\n variant?: DividerVariant;\n lineStyle?: DividerLineStyle;\n grow?: boolean;\n}\n\n/**\n * A 1px divider using the theme's card border, or the lighter rule between parts of one card\n * with `variant={DividerVariant.Muted}`. Horizontal and full-width by default;\n * `orientation=\"vertical\"` draws a rule between inline controls instead.\n */\n\nconst getSpacingValue = (spacing?: SpacingSize): string | undefined => {\n return spacing ? `${getSpacingSize(spacing)}px` : undefined;\n};\n\nconst getPaddingValue = (padding?: PaddingSize): string | undefined => {\n return padding ? `${getPaddingSize(padding)}px` : undefined;\n};\n\nconst getSpacingSize = (size: SpacingSize): number => {\n switch (size) {\n case SpacingSize.XSmall:\n return 8;\n case SpacingSize.Small:\n return 12;\n case SpacingSize.Medium:\n return 24;\n case SpacingSize.Large:\n return 36;\n }\n};\n\nconst getPaddingSize = (size: PaddingSize): number => {\n switch (size) {\n case PaddingSize.XSmall:\n return 1;\n case PaddingSize.Small:\n return 2;\n case PaddingSize.Medium:\n return 4;\n case PaddingSize.Large:\n return 8;\n }\n};\n\nconst Divider: React.FC<DividerProps> = ({\n orientation = 'horizontal',\n length,\n margin,\n padding,\n className = '',\n variant = DividerVariant.Default,\n lineStyle = 'solid',\n grow = false,\n}) => {\n const lineColor =\n variant === DividerVariant.Default\n ? 'var(--malachite-card-border)'\n : variant === DividerVariant.Muted\n ? // The theme's lighter rule, between parts of one card; no theme sets a border-muted.\n 'var(--malachite-card-subtle-divider, var(--malachite-card-border))'\n : 'var(--malachite-border-strong)';\n\n const isVertical = orientation === 'vertical';\n const dashDirection = isVertical ? 'to bottom' : 'to right';\n const span = length ? `${LENGTH_PX[length]}px` : '100%';\n\n const dividerStyles: React.CSSProperties = {\n height: isVertical ? span : '1px',\n width: isVertical ? '1px' : span,\n margin: margin ? getSpacingValue(margin) : undefined,\n padding: padding ? getPaddingValue(padding) : undefined,\n // Longhands, never the `flex` shorthand: it resets `flex-shrink` and a 1px rule that\n // may shrink disappears between wider siblings.\n flexGrow: grow ? 1 : undefined,\n flexBasis: grow ? '0%' : undefined,\n flexShrink: 0,\n border: 'none',\n ...(lineStyle === 'dashed'\n ? {\n backgroundColor: 'transparent',\n backgroundImage: `repeating-linear-gradient(${dashDirection}, ${lineColor} 0 5px, transparent 5px 11px)`,\n backgroundSize: isVertical ? '1px 100%' : '100% 1px',\n backgroundRepeat: 'no-repeat',\n }\n : { backgroundColor: lineColor }),\n };\n\n return <div className={className} style={dividerStyles} />;\n};\n\nexport default Divider;\nexport { Divider };\n"],"names":["LENGTH_PX","getSpacingValue","spacing","getSpacingSize","getPaddingValue","padding","getPaddingSize","size","SpacingSize","PaddingSize","Divider","orientation","length","margin","className","variant","DividerVariant","lineStyle","grow","lineColor","isVertical","dashDirection","span","dividerStyles","jsx"],"mappings":";;AAUA,MAAMA,IAA2C,EAAE,OAAO,IAAI,QAAQ,IAAI,OAAO,GAAA,GAsB3EC,IAAkB,CAACC,MACdA,IAAU,GAAGC,EAAeD,CAAO,CAAC,OAAO,QAGhDE,IAAkB,CAACC,MACdA,IAAU,GAAGC,EAAeD,CAAO,CAAC,OAAO,QAGhDF,IAAiB,CAACI,MAA8B;AAClD,UAAQA,GAAA;AAAA,IACJ,KAAKC,EAAY;AACb,aAAO;AAAA,IACX,KAAKA,EAAY;AACb,aAAO;AAAA,IACX,KAAKA,EAAY;AACb,aAAO;AAAA,IACX,KAAKA,EAAY;AACb,aAAO;AAAA,EAAA;AAEnB,GAEMF,IAAiB,CAACC,MAA8B;AAClD,UAAQA,GAAA;AAAA,IACJ,KAAKE,EAAY;AACb,aAAO;AAAA,IACX,KAAKA,EAAY;AACb,aAAO;AAAA,IACX,KAAKA,EAAY;AACb,aAAO;AAAA,IACX,KAAKA,EAAY;AACb,aAAO;AAAA,EAAA;AAEnB,GAEMC,IAAkC,CAAC;AAAA,EACrC,aAAAC,IAAc;AAAA,EACd,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAR;AAAA,EACA,WAAAS,IAAY;AAAA,EACZ,SAAAC,IAAUC,EAAe;AAAA,EACzB,WAAAC,IAAY;AAAA,EACZ,MAAAC,IAAO;AACX,MAAM;AACF,QAAMC,IACFJ,MAAYC,EAAe,UACrB,iCACAD,MAAYC,EAAe;AAAA;AAAA,IAEzB;AAAA,MACA,kCAENI,IAAaT,MAAgB,YAC7BU,IAAgBD,IAAa,cAAc,YAC3CE,IAAOV,IAAS,GAAGZ,EAAUY,CAAM,CAAC,OAAO,QAE3CW,IAAqC;AAAA,IACvC,QAAQH,IAAaE,IAAO;AAAA,IAC5B,OAAOF,IAAa,QAAQE;AAAA,IAC5B,QAAQT,IAASZ,EAAgBY,CAAM,IAAI;AAAA,IAC3C,SAASR,IAAUD,EAAgBC,CAAO,IAAI;AAAA;AAAA;AAAA,IAG9C,UAAUa,IAAO,IAAI;AAAA,IACrB,WAAWA,IAAO,OAAO;AAAA,IACzB,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,GAAID,MAAc,WACZ;AAAA,MACI,iBAAiB;AAAA,MACjB,iBAAiB,6BAA6BI,CAAa,KAAKF,CAAS;AAAA,MACzE,gBAAgBC,IAAa,aAAa;AAAA,MAC1C,kBAAkB;AAAA,IAAA,IAEtB,EAAE,iBAAiBD,EAAA;AAAA,EAAU;AAGvC,SAAO,gBAAAK,EAAC,OAAA,EAAI,WAAAV,GAAsB,OAAOS,EAAA,CAAe;AAC5D;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1106,7 +1106,7 @@ export declare interface ChoiceGroupOption<T extends string = string> {
|
|
|
1106
1106
|
label: string;
|
|
1107
1107
|
/** Before the label in a `medium` tile, such as a client's logo. Decorative. */
|
|
1108
1108
|
icon?: default_2.ReactNode;
|
|
1109
|
-
/** A
|
|
1109
|
+
/** A green corner mark, deeper than the tick, while the option is not chosen, such as a star on a recommended one. */
|
|
1110
1110
|
mark?: default_2.ReactNode;
|
|
1111
1111
|
/** Names the option when its label alone says too little, e.g. "1 year, recommended". */
|
|
1112
1112
|
'aria-label'?: string;
|
package/package.json
CHANGED