@stackone/malachite 2.99.1 → 2.100.0
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 +4 -2
- package/dist/components/ChoiceGroup.js +1 -1
- package/dist/components/ChoiceGroup.js.map +1 -1
- package/dist/components/CodePreview.js +142 -0
- package/dist/components/CodePreview.js.map +1 -0
- 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/components/LinkCard.js +83 -0
- package/dist/components/LinkCard.js.map +1 -0
- package/dist/components/Timeline.js +65 -31
- package/dist/components/Timeline.js.map +1 -1
- package/dist/index.d.ts +54 -1
- package/dist/index.js +480 -476
- package/dist/index.js.map +1 -1
- package/dist/tailwind.css.js +1 -1
- package/dist/theme.js +1 -1
- package/dist/theme.js.map +1 -1
- package/package.json +1 -1
package/COMPONENTS.md
CHANGED
|
@@ -12,6 +12,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
12
12
|
- **`SurfaceExpandableRow`** — A row that opens to reveal a body (used as `Surface.ExpandableRow`), for a line that carries its own controls. Not `Accordion`, which puts its header inside the toggle button, so a header holding a dropdown or a second button would be invalid: here the row surface takes the click and a cell opts out by wrapping its controls in `ExpandableRow.Controls`, while the arrow stays a real button so the keyboard reaches it. That opt-out is explicit rather than sniffing the event target for an interactive ancestor, because a control rendering into a shadow root retargets the event to its host. `sticky` pins the row while its body scrolls, offset by `stickyTopOffset` for whatever is already pinned above it; it only pins while open, since a closed row has nothing to scroll past. _Key props:_ `header`, `children`, `expanded`, `onToggle`, `sticky`, `stickyTopOffset`, `divider`, `tone`, `aria-label`, `className`, `style`.
|
|
13
13
|
- **`DisclosureArrow`** — The expand/collapse triangle disclosure UI shares (`Accordion`, `Surface.ExpandableRow`). Owns its colour states so they never drift between usages: `text-primary` when expanded, `text-placeholder` otherwise, and dark on hover inside a `group` ancestor — put `group` on the clickable header or row so that hover state activates. _Key props:_ `expanded`, `size`, `className`.
|
|
14
14
|
- **`Card`** — Generic content card. `title` heads it, with dimmed `subtitle` text beside it and `extra` actions at the right of the title row. `variant="framed"` draws the detached `Table`’s frame instead: the title row sits on a grey frame and the children in a bordered section inside it, so a card above a table, such as a chart over a log list, reads as part of the same set. `dimmed`, `border`, `size`, `glassFooter` and `headerConfig` do not apply to a framed card. _Key props:_ `variant` (`CardVariant`: `default` | `framed`), `title`, `subtitle`, `extra`, `padding`, `footer`.
|
|
15
|
+
- **`LinkCard`** — A compact card that opens more about one thing elsewhere on the screen, such as another tab of a side panel: an optional icon, a title coloured by `tone`, a one-line description cut with an ellipsis, optional `trailing` content such as a level scale, and an accent “Open →”. The whole card is one button, or an anchor with `href` (an unsafe scheme such as `javascript:` is dropped); with neither `onClick` nor a safe `href` it is a static card without the action. Tone is colour alone, so the title has to say the outcome. For a resource in a new tab use `ResourceCard`; for a row in a list use `Surface.Row`. _Key props:_ `title`, `description`, `tone` (`LinkCardTone`: `neutral` | `success` | `warning` | `error`), `icon`, `trailing` (both decorative; `trailing` sits inside the control, so never interactive), `actionLabel` (default `Open`), `onClick`, `href`, `className`.
|
|
15
16
|
- **`ResourceCard`** — A card pointing at a resource elsewhere, such as an SDK’s documentation: a muted icon tile, a title, a description clamped to two lines and a link that opens in a new tab. `ResourceCard.Header` is the icon, title and description on their own, all phrasing content, so a section that opens on them, such as an `Accordion` header, can use it inside its button. _Key props:_ `icon`, `title`, `description`, `href`, `linkLabel` (default `Documentation`), `titleAs` (`h3` | `h4`), `className`. `ResourceCard.Header`: `icon`, `title`, `description`; phrasing content only, so its title is never a heading.
|
|
16
17
|
- **`SelectableCard`** — A card that is one option in a radio group — eyebrow, optional status tag, title, description, a count label and a top-right action slot. Use inside a `CardStrip`. Selection is controlled by the consumer: pass `selected`, which drives both the visual treatment and `aria-checked`. A selected card meets the sheet below the way a browser tab meets its toolbar — its bottom corners flare outward onto the strip’s rule — so its outline is one SVG path rather than borders, which would split into two lines at the tangent. `variant` picks the palette: `profile` (green), `library` (neutral) or `editing` (amber, for a profile with unsaved changes). `actions` stands in the card’s top-right corner, on the eyebrow row, and renders outside the control so a menu or icon button inside it stays clickable and keeps its own tab stop. Nothing else marks that corner: the flared outline, the tint and the green eyebrow already say which card is selected, so a radio there would only repeat them. `onDismiss` adds an x after `actions`, tinted like the eyebrow so it reads as part of the card — for discarding a draft card; `dismissDisabledReason` disables it and explains why in its tooltip. `isDefault` marks the card as the account default with a pin beside the title, named for assistive tech and tooltipped for everyone else — it belongs with the name it qualifies rather than among the actions, which read as things to press. `address` puts a one-line chip above the count for a copyable address such as a server URL: its `label` is cut short with an ellipsis, and its full `value` shows in a tooltip and is copied on click, without selecting the card. It takes the place of `description`, since the card has room for one or the other. For a row-shaped selectable use `Surface.Row` instead. _Key props:_ `value`, `title`, `titleIcon`, `isDefault`, `variant` (`profile` | `library` | `editing`), `eyebrow`, `status` (`label`, `type`, `tooltip`), `description`, `address` (`label`, `value`), `countLabel`, `actions`, `onDismiss` (`dismissLabel`, `dismissDisabledReason`), `selected`, `loading` (`loadingLabel`, `loadingHint`), `disabled`, `dimmed`, `onSelect`, `tabIndex`, `aria-label`, `className`, `style`.
|
|
17
18
|
- **`CardStrip`** — Horizontally scrolling radio group of cards, with edge arrows that appear only when the content overflows, an edge fade, scroll-snap and arrow-key navigation matching `SegmentedControl`. Owns interaction only: it finds its options by looking for `role="radio"` descendants carrying `data-value`, so any such child works (`SelectableCard` emits both). Pass a non-selectable terminal tile as `CardStrip.AddTile` — it sits inside the group but outside the radio set, and must be a direct child or it scrolls with the cards. Use `leading` to pin a card that should not scroll away; the strip tells the cards which slot they are in, so a pinned `SelectableCard` drops the left rule the scrolling ones draw. A strip too narrow to show a card beside `leading` scrolls it with the cards rather than squeezing them, so the selected card always has its full width. Set `bleed` when the strip sits in a `PageLayout`: the strip stretches past the horizontal padding of the layout so its bottom rule runs the full width of the page card, while the cards stay aligned to the gutter. With no cards at all the strip degenerates to its pinned slots alone — no trough, no scroller and no arrows — with the add tile standing beside `leading` and taking `primary` emphasis automatically, since adding the first card is the only thing on offer. _Key props:_ `value`, `tone` (`profile` | `library` | `editing` — read off the selected card unless set), `onChange`, `children`, `leading`, `arrows`, `fadeEdges`, `snap`, `bleed`, `scrollSelectedIntoView`, `aria-label`, `aria-labelledby`, `className`, `style`. `CardStrip.AddTile`: `label`, `icon`, `onClick`, `disabled`, `emphasis` (`primary` | `secondary` — left to the strip unless set: `primary` while there are no cards, `secondary` once there are), `className`.
|
|
@@ -23,7 +24,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
23
24
|
- **`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
25
|
- **`Padded`** — Padding wrapper applying consistent design-system spacing.
|
|
25
26
|
- **`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`.
|
|
27
|
+
- **`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
28
|
- **`OverflowRow`** — Horizontal row that collapses items that do not fit into an overflow affordance.
|
|
28
29
|
- **`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
30
|
- **`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.
|
|
@@ -117,7 +118,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
117
118
|
- **`LevelMeter`** — Rising bars, shortest first, that picture how much of a scale is on — an access level in a level menu or on a level chip. Each step is `on` (a solid accent-green bar), `partial` (a green outline over a faint tint, for a step only some of whose actions are on) or `off` (an empty grey outline); every step keeps 3:1 against the surface, and colours come from the theme. Styled inline so it still draws inside an `ActionMenu`, which portals outside the shadow root and its stylesheet. Beside text that already names the level it is decorative and hidden from assistive tech; give it a `label` only when it stands alone and it reads as an image of that name. As an `ActionMenu` item `icon` or a `Button` `icon`, leave `label` off: the icon joins the item name, and the text already says the level. _Key props:_ `steps` (`LevelMeterStep[]`: `on` | `partial` | `off`), `label`, `className`.
|
|
118
119
|
- **`TimeBarChart`** — Counts per time bucket as stacked bars on a UTC axis, the request-volume chart above a log list. Every bucket in `range` takes a slot whether or not it has data, so gaps read as gaps; a zone-less time string is read as UTC. Hover or arrow-key through buckets for a tooltip listing every series and the total; `highlightTime` shades the bucket holding a time from elsewhere on the page, such as the hovered log row. With `onRangeSelect`, dragging across bars reports the whole buckets covered, `end` exclusive so it goes straight back in as `range`, and whether the selection takes in the last bucket. `loading` dims bars already drawn rather than replacing them, and shows a spinner only when there is nothing to dim. Series colours follow the theme’s status tokens by `tone`, and failures always stack above successes whatever order `series` comes in, so position separates them where colour alone might not; a legend names them unless `legend={false}`. A visually hidden table carries the same numbers for screen readers. _Key props:_ `series` (`{ key, label, tone }[]`, stacked by tone with `error` on top; `TimeBarChartTone`: `success` | `error` | `neutral`), `buckets` (`{ start, values }[]`), `interval` (`{ unit, step }`; `TimeBarChartUnit`: `minute` | `hour` | `day` | `week` | `month`), `range` (`end` exclusive, as a selection reports it; at most 2,000 buckets, the newest kept), `TimeBarChartSize` (`small` | `medium` | `large`), `loading`, `error`, `errorTitle`, `errorSubTitle`, `valueLabel`, `legend`, `highlightTime`, `onRangeSelect`, `aria-label`, `aria-labelledby`, `className`, `style`.
|
|
119
120
|
- **`TimeBarChartSwatch`** — The mark a `TimeBarChart` draws a series in, by its `tone`, for naming the series somewhere other than the chart's legend, such as a count beside the chart standing in for it. It matches the legend and the tooltip, and the bars draw the same colour at 40%; it follows the theme with them. Decorative: the label beside it does the naming. _Key props:_ `tone` (`TimeBarChartTone`).
|
|
120
|
-
- **`Timeline`** — A vertical sequence of steps as an ordered list (`Timeline.Item`): a dot on a connecting line, a title, its timing at the right and a free-form body below, such as what happened to one API call. The dot is painted by `tone` from the theme’s text tokens (`neutral` is secondary text, the rest their status colours), or replaced by a decorative `marker` such as the caller’s logo. `stopped` puts an error badge (`stoppedLabel`, default "Stopped here") after the title of the step a flow ended on and paints its dot `error` unless a `tone` is set; the line ends at the last item. For steps a person works through (complete, open, locked) use `StepList`. _Key props:_ `aria-label`, `aria-labelledby`; on `Timeline.Item`: `title`, `time`, `tone` (`TimelineTone`: `neutral` | `info` | `success` | `warning` | `error`), `marker` (fills the 24px circle in place of the ringed dot), `stopped`, `stoppedLabel
|
|
121
|
+
- **`Timeline`** — A vertical sequence of steps as an ordered list (`Timeline.Item`): a dot on a connecting line, a title, its timing at the right and a free-form body below, such as what happened to one API call. The dot is painted by `tone` from the theme’s text tokens (`neutral` is secondary text, the rest their status colours), or replaced by a decorative `marker` such as the caller’s logo. `stopped` puts an error badge (`stoppedLabel`, default "Stopped here") after the title of the step a flow ended on and paints its dot `error` unless a `tone` is set; the line ends at the last item. `meta` puts facts about a step in one wrapping row under its title, such as `calls` 2 and `status` 200, each label secondary and its value in the mono face, 18px apart, as a `dl`. `skipped` marks a step that never ran with a grey chevron in place of the dot; the title has to say so. For steps a person works through (complete, open, locked) use `StepList`. _Key props:_ `aria-label`, `aria-labelledby`; on `Timeline.Item`: `title`, `time`, `tone` (`TimelineTone`: `neutral` | `info` | `success` | `warning` | `error`), `marker` (fills the 24px circle in place of the ringed dot), `skipped`, `stopped`, `stoppedLabel`, `meta` (`TimelineMetaEntry[]`: `label`, `value`).
|
|
121
122
|
- **`Table`** — Data table with columns, sizing, pagination and row selection. `column.align` places a column's header as well as its cells. What lands on the aligned edge is the last thing in the header row rather than the title: the sort caret on a sortable column, the info icon on one carrying `info` without a sorter. `headerVariant` picks the header layout, and only `inline` lines header and body up exactly, because both are cells of one `<table>`. `detached` builds them from flex rows, where a sortable header cell is 32px narrower than a non-sortable one — its padding sits on the inner button rather than on the flex item — so its header cells sit 15–17px off their column at any alignment; reach for `inline` where exact alignment matters. Sorting is internal, so the array passed as `data` is not the order rendered once a column is sorted: `onVisibleOrderChange` reports the rows in render order — the whole of `data`, compared by `rowKey` so an equal order never re-fires — for a consumer stepping a master-detail view the way the user sees it. On the detached header, `title`, `subtitle` and `extra` add a title row on the frame above the column headers, the row a `framed` `Card` draws, and it docks with them under `stickyHeaderTop` (with `showHeader={false}` nothing docks and it scrolls with the rows). The inline header has no frame, so it draws none of the three and warns in development. _Key props:_ `TableColumns` (incl. `align`), `TableSize`, `TableType`, `TableRowSelection`, `TablePaginationPosition` (`pagination.position`, in antd naming: a pager on each edge named, aligned as named, 16px from the rows; bottom right by default), `headerVariant`, `title`, `subtitle`, `extra`, `onVisibleOrderChange`, `scrollHeight` (a height, or `"fill"` for the room left in its scroller once the content above and below it fits, so the page itself never scrolls).
|
|
122
123
|
- **`Statistic`** — Displays a statistic value with a label; primary/secondary sizes. _Key props:_ `StatisticValueSize`.
|
|
123
124
|
- **`Avatar`** — Logo/initial avatar. Renders the image when available, otherwise a coloured tile with the first letter of `name`, or with `fallback="placeholder"` the generic "no logo available" tile. Encapsulates the fallback colour. _Key props:_ `src`, `name`, `size`, `shape="square" | "circle"`, `fallback="initial" | "placeholder"`.
|
|
@@ -127,6 +128,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
127
128
|
- **`AppLogo`** — A connector's mark, optionally with its name and version tag. Builds on `Avatar`, so a missing or broken logo falls back to the generic "no logo available" placeholder, a neutral grey tile with a darker square, the same mark stackone-logos.com serves. The gap tightens below 18px so the mark and label still read as one unit. _Key props:_ `src`, `name`, `showName`, `size`, `nameSize`, `nameWeight`, `version`, `truncate`, `className`.
|
|
128
129
|
- **`ConnectionHeader`** — Two tilted logo tiles (from → to) showing a connection between apps. _Key props:_ `from`, `to` (`ConnectionEndpoint`: `icon`, `label`, `background`).
|
|
129
130
|
- **`CodeBlock`** — Syntax-styled code block, a JSON tree, or a diff. A `json` tree folds by depth with `collapsed`; `collapseLargerThan` also starts any nested array or object with more entries than the limit collapsed at any depth, so a large payload mounts a row per node rather than per item; a node over the limit gets a keyboard toggle named by its path and size, and a folded one says how many entries it holds. _Key props:_ `code`, `json`, `language` (`yaml` | `cedar`), `collapsed`, `collapseLargerThan`, `diff`, `showLineNumbers`, `wrapLines`, `enableCopy`, `height`, `aria-label`, `aria-labelledby`.
|
|
131
|
+
- **`CodePreview`** — A framed payload, such as the raw request or response under a step of a trace: a header naming it with mono `meta` at the right, its first `previewLines` lines (5 by default) with line numbers, and a full-width “Show All N Lines” toggle for the rest that becomes “Show Less”; the toggle carries `aria-expanded`, is described by the title, says how many flagged lines the fold hides, and only appears when there is more to show. The body is a focusable region named by the title, so a keyboard can scroll it. An empty `code` says so. The body scrolls past 360px, folded or open; past `maxRenderedLines` (2,000 by default) the expanded body stops mounting lines and says how many it left out. `highlightLines` flags 1-based lines with the error tint, a rule down their start edge and a visually hidden “Flagged:” for assistive tech; say why nearby. Plain text, no syntax colouring or JSON tree: for those use `CodeBlock`. _Key props:_ `title`, `meta`, `code`, `previewLines`, `highlightLines`, `showLineNumbers` (default `true`), `maxRenderedLines`, `className`.
|
|
130
132
|
- **`Stepper`** — Progress dots/segments for a multi-step flow; optionally clickable. `groups` takes a long flow in labelled sections: the active step’s group opens into one bar per step across the full width and every other group folds to a short bar. Folded bars keep a fixed width and the open group shares what is left, so allow about 20px per other group and 12px per step in the open group. With `onChange` each folded bar is a button named after its group. _Key props:_ `steps` or `groups` (`{ label, steps }[]`), `active`, `onChange`.
|
|
131
133
|
- **`Swatch`** — Colour swatch preview.
|
|
132
134
|
|
|
@@ -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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A,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,CA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,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;"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { jsxs as l, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { useState as A, useId as N, useMemo as v } from "react";
|
|
3
|
+
import L from "./CustomIcons/CaretDownIcon.js";
|
|
4
|
+
import c from "./Typography/Text.js";
|
|
5
|
+
import { rowsWrapperStyle as M } from "./codeBlockStyles.js";
|
|
6
|
+
import { FOCUS_RING_INSET as E } from "./focusRing.js";
|
|
7
|
+
import { isRenderableNode as O } from "./renderableNode.js";
|
|
8
|
+
const w = 5, I = 2e3, T = 360, F = "var(--malachite-card-border,rgb(232,232,232))", S = "var(--malachite-card-subtle-divider,rgb(241,241,241))", W = (e) => e === "" ? [] : e.replace(/\r?\n$/, "").split(/\r\n|\r|\n/), $ = (e, o) => !Number.isNaN(e) && e >= 1 ? Math.floor(e) : o, j = (e) => e ? "flex border-0 border-s-[3px] border-solid border-[var(--malachite-error-background,rgb(197,63,63))] bg-[var(--malachite-alert-error-background,rgba(197,63,63,0.08))]" : "flex border-0 border-s-[3px] border-solid border-transparent", H = (e, o, s) => {
|
|
9
|
+
if (e)
|
|
10
|
+
return "Show Less";
|
|
11
|
+
const m = s > 0 ? ` · ${s} flagged` : "";
|
|
12
|
+
return `Show All ${o} Lines${m}`;
|
|
13
|
+
}, q = ({
|
|
14
|
+
title: e,
|
|
15
|
+
meta: o,
|
|
16
|
+
code: s,
|
|
17
|
+
previewLines: m = w,
|
|
18
|
+
highlightLines: f = [],
|
|
19
|
+
showLineNumbers: i = !0,
|
|
20
|
+
maxRenderedLines: D = I,
|
|
21
|
+
className: _ = ""
|
|
22
|
+
}) => {
|
|
23
|
+
const [d, k] = A(!1), h = N(), u = N(), a = v(() => W(s), [s]), p = v(
|
|
24
|
+
() => new Set(
|
|
25
|
+
f.filter(
|
|
26
|
+
(t) => Number.isInteger(t) && t >= 1 && t <= a.length
|
|
27
|
+
)
|
|
28
|
+
),
|
|
29
|
+
[f, a.length]
|
|
30
|
+
), x = $(m, w), y = a.length > x, b = d || !y, g = Math.min(
|
|
31
|
+
b ? a.length : x,
|
|
32
|
+
$(D, I)
|
|
33
|
+
), C = a.slice(0, g), R = [...p].filter((t) => t > x).length, z = `max(40px, calc(${String(a.length).length}ch + 14px))`;
|
|
34
|
+
return /* @__PURE__ */ l(
|
|
35
|
+
"div",
|
|
36
|
+
{
|
|
37
|
+
className: `overflow-hidden rounded-[var(--malachite-radius-10,10px)] border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] ${_}`,
|
|
38
|
+
style: { borderColor: F },
|
|
39
|
+
children: [
|
|
40
|
+
/* @__PURE__ */ l(
|
|
41
|
+
"div",
|
|
42
|
+
{
|
|
43
|
+
className: "flex items-center justify-between gap-[12px] border-0 border-b border-solid bg-[var(--malachite-card-sunken-background,rgb(250,250,250))] px-[12px] py-[7px] leading-[14px]",
|
|
44
|
+
style: { borderColor: S },
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ r("span", { id: h, className: "flex min-w-0", children: /* @__PURE__ */ r(c, { size: "xsmall", color: "secondary", fontWeight: "semi-bold", children: e }) }),
|
|
47
|
+
O(o) && /* @__PURE__ */ r(
|
|
48
|
+
c,
|
|
49
|
+
{
|
|
50
|
+
size: "xsmall",
|
|
51
|
+
color: "secondary",
|
|
52
|
+
font: "mono",
|
|
53
|
+
wrap: !1,
|
|
54
|
+
className: "truncate",
|
|
55
|
+
children: o
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
),
|
|
61
|
+
a.length === 0 ? /* @__PURE__ */ r(c, { as: "p", size: "xsmall", color: "secondary", className: "m-0 px-[12px] py-[8px]", children: "Empty" }) : (
|
|
62
|
+
// Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.
|
|
63
|
+
/* @__PURE__ */ r(
|
|
64
|
+
"pre",
|
|
65
|
+
{
|
|
66
|
+
id: u,
|
|
67
|
+
role: "region",
|
|
68
|
+
"aria-labelledby": h,
|
|
69
|
+
tabIndex: 0,
|
|
70
|
+
className: `m-0 overflow-auto font-mono text-[length:var(--malachite-font-size-xsmall,11px)] ${i ? "py-[6px] leading-[14px]" : "py-[10px] leading-[1.65]"} text-[var(--malachite-text-primary,rgb(10,10,10))] ${E}`,
|
|
71
|
+
style: { maxHeight: T },
|
|
72
|
+
children: /* @__PURE__ */ l("span", { className: "block", style: M(!1), children: [
|
|
73
|
+
C.map((t, n) => (
|
|
74
|
+
// A line's position is its identity: its text can repeat.
|
|
75
|
+
/* @__PURE__ */ l(
|
|
76
|
+
"span",
|
|
77
|
+
{
|
|
78
|
+
"data-flagged": p.has(n + 1) || void 0,
|
|
79
|
+
className: j(p.has(n + 1)),
|
|
80
|
+
children: [
|
|
81
|
+
i && /* @__PURE__ */ r(
|
|
82
|
+
"span",
|
|
83
|
+
{
|
|
84
|
+
"aria-hidden": "true",
|
|
85
|
+
className: "flex-none select-none pe-[10px] text-end text-[var(--malachite-text-dimmed,rgb(161,161,161))]",
|
|
86
|
+
style: { width: z },
|
|
87
|
+
children: n + 1
|
|
88
|
+
}
|
|
89
|
+
),
|
|
90
|
+
/* @__PURE__ */ l(
|
|
91
|
+
"span",
|
|
92
|
+
{
|
|
93
|
+
className: `min-w-0 whitespace-pre ${i ? "" : "px-[11px]"}`,
|
|
94
|
+
children: [
|
|
95
|
+
p.has(n + 1) && /* @__PURE__ */ r("span", { className: "sr-only select-none", children: "Flagged: " }),
|
|
96
|
+
t || " "
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
n
|
|
103
|
+
)
|
|
104
|
+
)),
|
|
105
|
+
!b && !i && /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "block select-none px-[14px]", children: "…" })
|
|
106
|
+
] })
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
),
|
|
110
|
+
b && g < a.length && /* @__PURE__ */ r(c, { as: "p", size: "xsmall", color: "secondary", className: "m-0 px-[12px] pb-[8px]", children: `Showing the first ${g.toLocaleString()} of ${a.length.toLocaleString()} lines.` }),
|
|
111
|
+
y && /* @__PURE__ */ l(
|
|
112
|
+
"button",
|
|
113
|
+
{
|
|
114
|
+
type: "button",
|
|
115
|
+
"aria-expanded": d,
|
|
116
|
+
"aria-controls": u,
|
|
117
|
+
"aria-describedby": h,
|
|
118
|
+
onClick: () => k((t) => !t),
|
|
119
|
+
className: `m-0 flex w-full cursor-pointer appearance-none items-center gap-[5px] border-0 border-t border-solid bg-transparent px-[12px] py-[7px] text-start font-[inherit] text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${E}`,
|
|
120
|
+
style: { borderColor: S },
|
|
121
|
+
children: [
|
|
122
|
+
/* @__PURE__ */ r(c, { size: "xsmall", fontWeight: "semi-bold", color: "inherit", children: H(d, a.length, R) }),
|
|
123
|
+
/* @__PURE__ */ r("span", { "aria-hidden": "true", className: "flex", children: /* @__PURE__ */ r(
|
|
124
|
+
L,
|
|
125
|
+
{
|
|
126
|
+
size: 12,
|
|
127
|
+
className: "transition-transform",
|
|
128
|
+
style: { transform: d ? "rotate(180deg)" : void 0 }
|
|
129
|
+
}
|
|
130
|
+
) })
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
export {
|
|
139
|
+
q as CodePreview,
|
|
140
|
+
q as default
|
|
141
|
+
};
|
|
142
|
+
//# sourceMappingURL=CodePreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodePreview.js","sources":["../../src/components/CodePreview.tsx"],"sourcesContent":["import type React from 'react';\nimport { useId, useMemo, useState } from 'react';\nimport CaretDownIcon from './CustomIcons/CaretDownIcon';\nimport Text from './Typography/Text';\nimport { rowsWrapperStyle } from './codeBlockStyles';\nimport { FOCUS_RING_INSET } from './focusRing';\nimport { isRenderableNode } from './renderableNode';\n\nexport interface CodePreviewProps {\n /** Names the payload in the header and its body and toggle for assistive tech, e.g. `Request`. */\n title: string;\n /** At the right of the header in the mono face, e.g. `POST · acc_8f2…`. */\n meta?: React.ReactNode;\n code: string;\n /** How many lines show until the reader asks for all of them. `Infinity` shows them all. */\n previewLines?: number;\n /** 1-based line numbers to flag, such as the fields a scanner caught. Colour alone, so say why nearby. */\n highlightLines?: readonly number[];\n showLineNumbers?: boolean;\n /** The most lines the expanded body mounts; past it a note says how many are not shown. */\n maxRenderedLines?: number;\n className?: string;\n}\n\nconst DEFAULT_PREVIEW_LINES = 5;\nconst DEFAULT_MAX_RENDERED_LINES = 2000;\n\n// Past this the body scrolls, folded or open, so a long preview never crowds out what is around it.\nconst MAX_BODY_HEIGHT = 360;\n\nconst BORDER = 'var(--malachite-card-border,rgb(232,232,232))';\nconst DIVIDER = 'var(--malachite-card-subtle-divider,rgb(241,241,241))';\n\n// Any line ending, and no empty last line for a trailing newline.\nconst linesOf = (code: string): string[] =>\n code === '' ? [] : code.replace(/\\r?\\n$/, '').split(/\\r\\n|\\r|\\n/);\n\nconst countOf = (value: number, fallback: number): number =>\n !Number.isNaN(value) && value >= 1 ? Math.floor(value) : fallback;\n\nconst lineClasses = (flagged: boolean): string =>\n flagged\n ? 'flex border-0 border-s-[3px] border-solid border-[var(--malachite-error-background,rgb(197,63,63))] bg-[var(--malachite-alert-error-background,rgba(197,63,63,0.08))]'\n : 'flex border-0 border-s-[3px] border-solid border-transparent';\n\nconst toggleLabel = (expanded: boolean, total: number, hiddenFlags: number): string => {\n if (expanded) {\n return 'Show Less';\n }\n const flags = hiddenFlags > 0 ? ` · ${hiddenFlags} flagged` : '';\n return `Show All ${total} Lines${flags}`;\n};\n\n/**\n * A framed payload: a header naming it, its first lines, and a toggle for the rest. For the raw\n * request or response under a step of a trace, where the whole body would crowd out the steps.\n */\nconst CodePreview: React.FC<CodePreviewProps> = ({\n title,\n meta,\n code,\n previewLines = DEFAULT_PREVIEW_LINES,\n highlightLines = [],\n showLineNumbers = true,\n maxRenderedLines = DEFAULT_MAX_RENDERED_LINES,\n className = '',\n}) => {\n const [expanded, setExpanded] = useState(false);\n const titleId = useId();\n const bodyId = useId();\n const lines = useMemo(() => linesOf(code), [code]);\n const flagged = useMemo(\n () =>\n new Set(\n highlightLines.filter(\n (line) => Number.isInteger(line) && line >= 1 && line <= lines.length,\n ),\n ),\n [highlightLines, lines.length],\n );\n const limit = countOf(previewLines, DEFAULT_PREVIEW_LINES);\n const foldable = lines.length > limit;\n const open = expanded || !foldable;\n const rendered = Math.min(\n open ? lines.length : limit,\n countOf(maxRenderedLines, DEFAULT_MAX_RENDERED_LINES),\n );\n const shown = lines.slice(0, rendered);\n const hiddenFlags = [...flagged].filter((line) => line > limit).length;\n // 40px as designed, wider only when the last line's number would crowd the code.\n const gutter = `max(40px, calc(${String(lines.length).length}ch + 14px))`;\n return (\n <div\n className={`overflow-hidden rounded-[var(--malachite-radius-10,10px)] border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] ${className}`}\n style={{ borderColor: BORDER }}\n >\n <div\n className=\"flex items-center justify-between gap-[12px] border-0 border-b border-solid bg-[var(--malachite-card-sunken-background,rgb(250,250,250))] px-[12px] py-[7px] leading-[14px]\"\n style={{ borderColor: DIVIDER }}\n >\n <span id={titleId} className=\"flex min-w-0\">\n <Text size=\"xsmall\" color=\"secondary\" fontWeight=\"semi-bold\">\n {title}\n </Text>\n </span>\n {isRenderableNode(meta) && (\n <Text\n size=\"xsmall\"\n color=\"secondary\"\n font=\"mono\"\n wrap={false}\n className=\"truncate\"\n >\n {meta}\n </Text>\n )}\n </div>\n {lines.length === 0 ? (\n <Text as=\"p\" size=\"xsmall\" color=\"secondary\" className=\"m-0 px-[12px] py-[8px]\">\n Empty\n </Text>\n ) : (\n // Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.\n <pre\n id={bodyId}\n role=\"region\"\n aria-labelledby={titleId}\n tabIndex={0}\n // Numbered rows sit tight like an editor's; a bare payload keeps code spacing, as designed.\n className={`m-0 overflow-auto font-mono text-[length:var(--malachite-font-size-xsmall,11px)] ${showLineNumbers ? 'py-[6px] leading-[14px]' : 'py-[10px] leading-[1.65]'} text-[var(--malachite-text-primary,rgb(10,10,10))] ${FOCUS_RING_INSET}`}\n style={{ maxHeight: MAX_BODY_HEIGHT }}\n >\n <span className=\"block\" style={rowsWrapperStyle(false)}>\n {shown.map((line, index) => (\n // A line's position is its identity: its text can repeat.\n <span\n key={index}\n data-flagged={flagged.has(index + 1) || undefined}\n className={lineClasses(flagged.has(index + 1))}\n >\n {showLineNumbers && (\n <span\n aria-hidden=\"true\"\n className=\"flex-none select-none pe-[10px] text-end text-[var(--malachite-text-dimmed,rgb(161,161,161))]\"\n style={{ width: gutter }}\n >\n {index + 1}\n </span>\n )}\n <span\n className={`min-w-0 whitespace-pre ${showLineNumbers ? '' : 'px-[11px]'}`}\n >\n {flagged.has(index + 1) && (\n <span className=\"sr-only select-none\">Flagged: </span>\n )}\n {line || ' '}\n </span>\n </span>\n ))}\n {!open && !showLineNumbers && (\n <span aria-hidden=\"true\" className=\"block select-none px-[14px]\">\n …\n </span>\n )}\n </span>\n </pre>\n )}\n {open && rendered < lines.length && (\n <Text as=\"p\" size=\"xsmall\" color=\"secondary\" className=\"m-0 px-[12px] pb-[8px]\">\n {`Showing the first ${rendered.toLocaleString()} of ${lines.length.toLocaleString()} lines.`}\n </Text>\n )}\n {foldable && (\n <button\n type=\"button\"\n aria-expanded={expanded}\n aria-controls={bodyId}\n aria-describedby={titleId}\n onClick={() => setExpanded((isOpen) => !isOpen)}\n className={`m-0 flex w-full cursor-pointer appearance-none items-center gap-[5px] border-0 border-t border-solid bg-transparent px-[12px] py-[7px] text-start font-[inherit] text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${FOCUS_RING_INSET}`}\n style={{ borderColor: DIVIDER }}\n >\n <Text size=\"xsmall\" fontWeight=\"semi-bold\" color=\"inherit\">\n {toggleLabel(expanded, lines.length, hiddenFlags)}\n </Text>\n <span aria-hidden=\"true\" className=\"flex\">\n <CaretDownIcon\n size={12}\n className=\"transition-transform\"\n style={{ transform: expanded ? 'rotate(180deg)' : undefined }}\n />\n </span>\n </button>\n )}\n </div>\n );\n};\n\nexport default CodePreview;\nexport { CodePreview };\n"],"names":["DEFAULT_PREVIEW_LINES","DEFAULT_MAX_RENDERED_LINES","MAX_BODY_HEIGHT","BORDER","DIVIDER","linesOf","code","countOf","value","fallback","lineClasses","flagged","toggleLabel","expanded","total","hiddenFlags","flags","CodePreview","title","meta","previewLines","highlightLines","showLineNumbers","maxRenderedLines","className","setExpanded","useState","titleId","useId","bodyId","lines","useMemo","line","limit","foldable","open","rendered","shown","gutter","jsxs","jsx","Text","isRenderableNode","FOCUS_RING_INSET","rowsWrapperStyle","index","isOpen","CaretDownIcon"],"mappings":";;;;;;;AAwBA,MAAMA,IAAwB,GACxBC,IAA6B,KAG7BC,IAAkB,KAElBC,IAAS,iDACTC,IAAU,yDAGVC,IAAU,CAACC,MACbA,MAAS,KAAK,CAAA,IAAKA,EAAK,QAAQ,UAAU,EAAE,EAAE,MAAM,YAAY,GAE9DC,IAAU,CAACC,GAAeC,MAC5B,CAAC,OAAO,MAAMD,CAAK,KAAKA,KAAS,IAAI,KAAK,MAAMA,CAAK,IAAIC,GAEvDC,IAAc,CAACC,MACjBA,IACM,0KACA,gEAEJC,IAAc,CAACC,GAAmBC,GAAeC,MAAgC;AACnF,MAAIF;AACA,WAAO;AAEX,QAAMG,IAAQD,IAAc,IAAI,MAAMA,CAAW,aAAa;AAC9D,SAAO,YAAYD,CAAK,SAASE,CAAK;AAC1C,GAMMC,IAA0C,CAAC;AAAA,EAC7C,OAA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mB,OAAA;AAAA,gBAAU;AAAA,cAAA,EAChE,CACJ;AAAA,YAAA;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;"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { jsxs as l, Fragment as g, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import v from "./CustomIcons/ForwardArrowIcon.js";
|
|
3
|
+
import $ from "./Typography/EllipsisText.js";
|
|
4
|
+
import m from "./Typography/Text.js";
|
|
5
|
+
import { devWarning as N } from "./devWarning.js";
|
|
6
|
+
import { FOCUS_RING as y } from "./focusRing.js";
|
|
7
|
+
import { isRenderableNode as p } from "./renderableNode.js";
|
|
8
|
+
import { safeHref as C } from "./safeHref.js";
|
|
9
|
+
const L = {
|
|
10
|
+
neutral: "primary",
|
|
11
|
+
success: "success",
|
|
12
|
+
warning: "warning",
|
|
13
|
+
error: "error"
|
|
14
|
+
}, s = "flex w-full items-center gap-[12px] rounded-[var(--malachite-radius-10,10px)] border border-solid border-[var(--malachite-card-border,rgb(232,232,232))] bg-[var(--malachite-card-background,rgb(255,255,255))] px-[12px] py-[10px] text-start text-[var(--malachite-text-primary,rgb(10,10,10))] no-underline", h = `cursor-pointer transition-colors hover:border-[var(--malachite-secondary-border-hover,rgb(186,186,186))] hover:bg-[var(--malachite-buttonlist-hover-background,rgb(245,245,245))] ${y}`, O = ({
|
|
15
|
+
title: f,
|
|
16
|
+
description: t,
|
|
17
|
+
tone: x = "neutral",
|
|
18
|
+
icon: c,
|
|
19
|
+
trailing: d,
|
|
20
|
+
actionLabel: u = "Open",
|
|
21
|
+
onClick: r,
|
|
22
|
+
href: a,
|
|
23
|
+
className: o = ""
|
|
24
|
+
}) => {
|
|
25
|
+
const n = C(a);
|
|
26
|
+
a && !n && N(
|
|
27
|
+
`LinkCard.href:${a}`,
|
|
28
|
+
`LinkCard dropped the unsafe href "${a}"; without an onClick it is a static card.`
|
|
29
|
+
);
|
|
30
|
+
const b = !!(n || r), i = /* @__PURE__ */ l(g, { children: [
|
|
31
|
+
p(c) && /* @__PURE__ */ e("span", { "aria-hidden": "true", className: "flex flex-none items-center", children: c }),
|
|
32
|
+
/* @__PURE__ */ l("span", { className: "flex min-w-0 flex-1 flex-col gap-[1px] leading-[15px]", children: [
|
|
33
|
+
/* @__PURE__ */ e(
|
|
34
|
+
m,
|
|
35
|
+
{
|
|
36
|
+
size: "small",
|
|
37
|
+
fontWeight: "bold",
|
|
38
|
+
color: L[x],
|
|
39
|
+
className: "leading-[17px]",
|
|
40
|
+
children: f
|
|
41
|
+
}
|
|
42
|
+
),
|
|
43
|
+
t && /* @__PURE__ */ e(
|
|
44
|
+
$,
|
|
45
|
+
{
|
|
46
|
+
size: "xsmall",
|
|
47
|
+
color: "secondary",
|
|
48
|
+
tooltip: t,
|
|
49
|
+
tooltipWhenTruncated: !0,
|
|
50
|
+
inline: !0,
|
|
51
|
+
children: t
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
] }),
|
|
55
|
+
p(d) && /* @__PURE__ */ e("span", { "aria-hidden": "true", className: "flex flex-none items-center", children: d }),
|
|
56
|
+
b && /* @__PURE__ */ l("span", { className: "flex flex-none items-center gap-[3px] text-[var(--malachite-accent-foreground,rgb(2,122,66))]", children: [
|
|
57
|
+
/* @__PURE__ */ e(m, { size: "xsmall", fontWeight: "semi-bold", color: "inherit", wrap: !1, children: u }),
|
|
58
|
+
/* @__PURE__ */ e("span", { "aria-hidden": "true", className: "flex", children: /* @__PURE__ */ e(v, { size: 12 }) })
|
|
59
|
+
] })
|
|
60
|
+
] });
|
|
61
|
+
return n ? /* @__PURE__ */ e(
|
|
62
|
+
"a",
|
|
63
|
+
{
|
|
64
|
+
href: n,
|
|
65
|
+
onClick: r,
|
|
66
|
+
className: `${s} ${h} ${o}`,
|
|
67
|
+
children: i
|
|
68
|
+
}
|
|
69
|
+
) : r ? /* @__PURE__ */ e(
|
|
70
|
+
"button",
|
|
71
|
+
{
|
|
72
|
+
type: "button",
|
|
73
|
+
onClick: r,
|
|
74
|
+
className: `m-0 appearance-none font-[inherit] ${s} ${h} ${o}`,
|
|
75
|
+
children: i
|
|
76
|
+
}
|
|
77
|
+
) : /* @__PURE__ */ e("div", { className: `${s} ${o}`, children: i });
|
|
78
|
+
};
|
|
79
|
+
export {
|
|
80
|
+
O as LinkCard,
|
|
81
|
+
O as default
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=LinkCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkCard.js","sources":["../../src/components/LinkCard.tsx"],"sourcesContent":["import type React from 'react';\nimport ForwardArrowIcon from './CustomIcons/ForwardArrowIcon';\nimport EllipsisText from './Typography/EllipsisText';\nimport Text from './Typography/Text';\nimport { devWarning } from './devWarning';\nimport { FOCUS_RING } from './focusRing';\nimport { isRenderableNode } from './renderableNode';\nimport { safeHref } from './safeHref';\n\nexport type LinkCardTone = 'neutral' | 'success' | 'warning' | 'error';\n\nexport interface LinkCardProps {\n title: string;\n /** One line under the title; truncated text shows in full on hover. */\n description?: string;\n /** Colours the title. */\n tone?: LinkCardTone;\n /** Decorative, before the title. Coloured paths need `data-malachite-shape`. */\n icon?: React.ReactNode;\n /** Decorative content before the action, e.g. a level scale. Must not be interactive. */\n trailing?: React.ReactNode;\n actionLabel?: string;\n onClick?: (event: React.MouseEvent<HTMLElement>) => void;\n /** Renders a link instead of a button; unsafe schemes are dropped. */\n href?: string;\n className?: string;\n}\n\nconst TITLE_COLOR = {\n neutral: 'primary',\n success: 'success',\n warning: 'warning',\n error: 'error',\n} as const;\n\nconst CARD_CLASSES =\n 'flex w-full items-center gap-[12px] rounded-[var(--malachite-radius-10,10px)] border border-solid border-[var(--malachite-card-border,rgb(232,232,232))] bg-[var(--malachite-card-background,rgb(255,255,255))] px-[12px] py-[10px] text-start text-[var(--malachite-text-primary,rgb(10,10,10))] no-underline';\n\nconst INTERACTIVE_CLASSES = `cursor-pointer transition-colors hover:border-[var(--malachite-secondary-border-hover,rgb(186,186,186))] hover:bg-[var(--malachite-buttonlist-hover-background,rgb(245,245,245))] ${FOCUS_RING}`;\n\n/** A compact card that opens more detail elsewhere, such as another tab of a panel. */\nconst LinkCard: React.FC<LinkCardProps> = ({\n title,\n description,\n tone = 'neutral',\n icon,\n trailing,\n actionLabel = 'Open',\n onClick,\n href: rawHref,\n className = '',\n}) => {\n const href = safeHref(rawHref);\n if (rawHref && !href) {\n devWarning(\n `LinkCard.href:${rawHref}`,\n `LinkCard dropped the unsafe href \"${rawHref}\"; without an onClick it is a static card.`,\n );\n }\n const interactive = Boolean(href || onClick);\n const body = (\n <>\n {isRenderableNode(icon) && (\n <span aria-hidden=\"true\" className=\"flex flex-none items-center\">\n {icon}\n </span>\n )}\n <span className=\"flex min-w-0 flex-1 flex-col gap-[1px] leading-[15px]\">\n <Text\n size=\"small\"\n fontWeight=\"bold\"\n color={TITLE_COLOR[tone]}\n className=\"leading-[17px]\"\n >\n {title}\n </Text>\n {description && (\n <EllipsisText\n size=\"xsmall\"\n color=\"secondary\"\n tooltip={description}\n tooltipWhenTruncated\n inline\n >\n {description}\n </EllipsisText>\n )}\n </span>\n {isRenderableNode(trailing) && (\n <span aria-hidden=\"true\" className=\"flex flex-none items-center\">\n {trailing}\n </span>\n )}\n {interactive && (\n <span className=\"flex flex-none items-center gap-[3px] text-[var(--malachite-accent-foreground,rgb(2,122,66))]\">\n <Text size=\"xsmall\" fontWeight=\"semi-bold\" color=\"inherit\" wrap={false}>\n {actionLabel}\n </Text>\n <span aria-hidden=\"true\" className=\"flex\">\n <ForwardArrowIcon size={12} />\n </span>\n </span>\n )}\n </>\n );\n if (href) {\n return (\n <a\n href={href}\n onClick={onClick}\n className={`${CARD_CLASSES} ${INTERACTIVE_CLASSES} ${className}`}\n >\n {body}\n </a>\n );\n }\n if (onClick) {\n return (\n <button\n type=\"button\"\n onClick={onClick}\n className={`m-0 appearance-none font-[inherit] ${CARD_CLASSES} ${INTERACTIVE_CLASSES} ${className}`}\n >\n {body}\n </button>\n );\n }\n return <div className={`${CARD_CLASSES} ${className}`}>{body}</div>;\n};\n\nexport default LinkCard;\nexport { LinkCard };\n"],"names":["TITLE_COLOR","CARD_CLASSES","INTERACTIVE_CLASSES","FOCUS_RING","LinkCard","title","description","tone","icon","trailing","actionLabel","onClick","rawHref","className","href","safeHref","devWarning","interactive","body","jsxs","Fragment","isRenderableNode","jsx","Text","EllipsisText","ForwardArrowIcon"],"mappings":";;;;;;;;AA4BA,MAAMA,IAAc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