@stackone/malachite 2.113.0 → 2.115.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 -3
- package/dist/components/Breadcrumbs.js +69 -53
- package/dist/components/Breadcrumbs.js.map +1 -1
- package/dist/components/Confetti.js +46 -45
- package/dist/components/Confetti.js.map +1 -1
- package/dist/components/LoadingScreen.js +133 -0
- package/dist/components/LoadingScreen.js.map +1 -0
- package/dist/components/PageLayout/index.js.map +1 -1
- package/dist/components/PageLayout/regularLayout.js +92 -83
- package/dist/components/PageLayout/regularLayout.js.map +1 -1
- package/dist/components/confettiPhysics.js +57 -0
- package/dist/components/confettiPhysics.js.map +1 -0
- package/dist/components/stackOneWordmarkPaths.js +10 -0
- package/dist/components/stackOneWordmarkPaths.js.map +1 -0
- package/dist/index.d.ts +22 -3
- package/dist/index.js +318 -316
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/COMPONENTS.md
CHANGED
|
@@ -17,7 +17,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
17
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`.
|
|
18
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`.
|
|
19
19
|
- **`SplitScreenLayout`** — Two-pane full-screen layout (content + preview/aside) with an optional dismiss button.
|
|
20
|
-
- **`PageLayout`** — Standard page chrome: a bordered card holding a breadcrumb bar, an optional alert strip, and a header block (subtitle, title + suffix, description) above the page body. Used as `PageLayout.Regular`; `PageLayout.Empty` is the chrome-only variant for pre-auth and error screens, with `headerActions` and `background` slots. Actions are declared as data (`buttons`) rather than children, and any that do not fit collapse into an overflow `ActionMenu` via `OverflowRow`. A client-side-routed app must pass `renderLink` so crumbs and the back button go through its router instead of reloading the document. Both layouts render a `main` landmark, demoted via `role` when the app owns its own. Deliberately not a `Surface` — the page card is 16px and carries no shadow. _Key props:_ `PageLayout.Regular`: `breadcrumbLinks`, `breadcrumbActions`, `renderLink`, `title`, `titleSuffix`, `subtitle`, `description`, `buttons`, `loading`, `centered`, `noPadding`, `contentGap` (`small` | `medium` | `large` | `xlarge`, default `small`), `alert`, `role`, `aria-label`, `aria-labelledby`, `className`, `style`. `PageLayout.Empty`: `title`, `centered`, `uniformPadding`, `headerActions`, `background`, `role`, `aria-label`, `aria-labelledby`, `className`, `style`.
|
|
20
|
+
- **`PageLayout`** — Standard page chrome: a bordered card holding a breadcrumb bar, an optional alert strip, and a header block (subtitle, title + suffix, description) above the page body. Used as `PageLayout.Regular`; `PageLayout.Empty` is the chrome-only variant for pre-auth and error screens, with `headerActions` and `background` slots. Actions are declared as data (`buttons`) rather than children, and any that do not fit collapse into an overflow `ActionMenu` via `OverflowRow`. A client-side-routed app must pass `renderLink` so crumbs and the back button go through its router instead of reloading the document. Both layouts render a `main` landmark, demoted via `role` when the app owns its own. Deliberately not a `Surface` — the page card is 16px and carries no shadow. _Key props:_ `PageLayout.Regular`: `breadcrumbLinks`, `breadcrumbActions`, `renderLink`, `title`, `titleSuffix`, `subtitle`, `description`, `buttons`, `loading`, `centered`, `noPadding`, `contentGap` (`small` | `medium` | `large` | `xlarge`, default `small`), `contentWidth` (`narrow`: caps and centres the header and body column for a single-column form), `alert`, `role`, `aria-label`, `aria-labelledby`, `className`, `style`. `PageLayout.Empty`: `title`, `centered`, `uniformPadding`, `headerActions`, `background`, `role`, `aria-label`, `aria-labelledby`, `className`, `style`.
|
|
21
21
|
- **`WizardLayout`** — Full-screen wizard scaffold: top bar (back button, right-aligned stepper, trailing slot), pinned `header` slot, centered scrolling content column, and a pinned footer (above sticky body content). `footerGlass` gives the footer a frosted translucent + backdrop-blur treatment. `banner` pins a page-wide notice under the top bar, above `header` and outside the content column, so a warning about the whole page is not squeezed to the column's width — pair it with `Alert layout="banner"`. `topBarSize="large"` draws a 60px top bar with 28px insets (52px and 16px below 640px). `footerAlign="content"` holds the footer to the content column, inside its gutter, so a full-width action lines up with the list above it. `reserveBack={false}` drops the square held for a hidden back button, so `leading` sits at the same inset as `trailing`; the default keeps it so `leading` does not move as the wizard steps. _Key props:_ `showBack`, `onBack`, `reserveBack`, `topBarSize` (`default` | `large`), `footerAlign` (`full` | `content`), `leading`, `stepper`, `trailing`, `banner`, `header`, `footer`, `footerGlass`, `center`, `contentWidth`, `minWidth`.
|
|
22
22
|
- **`PageActions`** — A page's action buttons, collapsing into an overflow menu as the row narrows. `PageLayout.Regular` renders these from its `buttons` prop; import it directly when a page builds its own header block (e.g. one that scrolls the title away) so the collapse, the dividers and the href handling come with it rather than being hand-rolled. _Key props:_ `buttons` (`PageAction[]`).
|
|
23
23
|
- **`Toolbar`** — Flat, opaque horizontal bar for a sub-header / filter row (e.g. a Search). Owns its chrome — an opaque ground (`card-background`, or the sunken page ground with `surface="page"` for a bar above a card), so it can pin over scrolling content, plus an optional bottom `divider` — so consumers don’t hand-roll background/border tokens. Its `TOOLBAR_FILTER_WIDTH_PX` / `TOOLBAR_FILTER_MIN_WIDTH_PX` / `TOOLBAR_FILL_BASIS_PX` / `TOOLBAR_FILL_MIN_WIDTH_PX` are exported so a control outside the bar can line up with one inside it without re-typing the number. `sticky` pins it to the top of its scroll container; any other positioning is left to the consumer, as is the gutter when `padding="none"` — use that when the bar must sit flush with the content it pins over. `layout="filters"` makes it own the layout too, which consumers were each re-deriving and getting wrong the same way: a `flex: 1` search with no floor collapses to nothing on a narrow viewport, and a row that cannot wrap runs off the page. Compose it as `Toolbar.Fill` for the search and `Toolbar.Item` per filter, as flat siblings; `grow={false}` stops a slot growing past its basis, for a row that already spaces its children, though it can still shrink toward its `minWidth`. The row packs greedily from its basis widths and each line's spare space is shared out by grow factor, which is deliberately lopsided: the search outweighs the filters a hundred to one, so a shared line leaves them at their 200px while a filter left alone on a wrapped line grows into the whole width instead of stranding beside a gap. A filter drops to the next line once its full 200px basis will not fit, and the filters sharing a line then compress toward a 160px floor. A search and a filter are laid out differently rather than uniformly, because a search field's useful width is "as much as you can spare" where a filter's is the width of a value. _Key props:_ `divider`, `padding` (`none` | `compact` | `default`), `layout` (`plain` | `filters`), `surface` (`card` | `page` — `page` paints the sunken page ground, for a bar that sits above a card rather than inside it), `sticky` (pins it to the top of its scroll container above the rows under it), `className`, `style`. `Fill`: `minWidth`. `Item`: `width`, `minWidth`, `grow`.
|
|
@@ -47,12 +47,13 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
47
47
|
- **`UsageCard`** — A small metered card: a title (optionally a link via `titleLink`, drawn with a trailing arrow), a right-aligned `detail` such as "700/1,000", and a body, usually a `Progress`. Used by `Sidebar.Usage`, and fine on its own, e.g. on a billing page. _Key props:_ `title`, `titleLink`, `detail`, `children`, `aria-label` (required; names the group), `busy` (sets `aria-busy` only).
|
|
48
48
|
- **`Progress`** — Progress bar.
|
|
49
49
|
- **`LoadingBar`** — Indeterminate full-width loading line; the variant colour sweeps across a pale track for work of unknown duration. Toggle `active` rather than unmounting, so the reserved height prevents layout shift. _Key props:_ `active`, `LoadingBarVariant` (`default` | `warning` | `error`), `LoadingBarSize` (`small` | `medium` | `large`), `aria-label`, `aria-labelledby`, `className`, `style`.
|
|
50
|
+
- **`LoadingScreen`** — The whole viewport while an app has nothing to show yet: the StackOne wordmark over a bar scanning back and forth, on the sunken page background, in either theme. It matches the screen unified-cloud paints before its bundle loads, so a page handing over to it, or from it, reads as one wait (an IdP page a sign-out passes through, say). Fixed to the viewport; render it as the page, not inside a card. Reduced motion stops the scan at full width. For loading inside a page use `LoadingBar` or `Skeleton`. _Key props:_ `aria-label` (default "Loading"), `aria-labelledby`, `className`.
|
|
50
51
|
- **`ToastProvider`** — Transient top-centre toasts for the outcome of an action. Wrap the app once in `ToastProvider` and call `useToast().show({ message, variant })` anywhere beneath it. Corners match a medium button. Each toast auto-dismisses, pauses while hovered and dismisses on click; at most three show at once. Toasts are announced through always-mounted live regions (`status` for success, `alert` for error), and the pills themselves are hidden from assistive tech and never take focus, so they cannot fight a dialog's focus trap. The host mounts on the first toast and joins the top layer, so toasts paint above elevated side panels. _Key props:_ `ToastProvider`: `children`, `duration` (ms, default 3000). `useToast()` → `show({ message, variant })`, `ToastVariant` (`success` | `error`, default `success`).
|
|
51
52
|
- **`Spinner`** — Loading spinner.
|
|
52
53
|
- **`Skeleton`** — Loading placeholders. Includes `Skeleton.Avatar` and `Skeleton.Input`. The shimmer stops under `prefers-reduced-motion`, leaving the plain placeholder.
|
|
53
54
|
- **`Tooltip`** — Hover/focus tooltip; also works on disabled controls (see CLAUDE.md). It describes its trigger once shown, so `describesTrigger={false}` where the same sentence is already on screen and referenced — otherwise a screen reader reads it twice. _Key props:_ `text`, `placement`, `delay`, `maxWidth`, `shouldShow`, `triggerAs`, `describesTrigger`, `isShrinkable`, `fill`, `wrapChildren`, `suppressed` (holds the tooltip back, e.g. while the popup its trigger opens is up), `showOnFocus` (false where script can move focus onto the trigger, e.g. an option a panel focuses on open), `focusableTrigger` (makes a trigger that cannot take focus — text, a static `Tag` — a tab stop, so the tooltip is not mouse-only; not for focusable children).
|
|
54
55
|
- **`TruncatedTooltip`** — Shows a tooltip only when its text is truncated.
|
|
55
|
-
- **`Confetti`** — Celebratory confetti burst for success moments. _Key props:_ `
|
|
56
|
+
- **`Confetti`** — Celebratory confetti burst for success moments: two cannons at the bottom corners throw the pieces up, then they flutter down, tumbling, and fade, on one canvas over the viewport. Fires once on mount; re-mount it (a changing `key`) to replay. Theme colours by default, green-led. Skipped entirely under `prefers-reduced-motion`. _Key props:_ `count` (default 150), `colors` (picked at random; list one twice to weight it), `className`.
|
|
56
57
|
- **`ConfirmationDialog`** — Asks the customer to confirm one consequential action — a preset over `Modal`, not a second dialog implementation. `variant` picks a whole coherent set at once (badge fill, tray tint, caption colour, badge icon and confirm-button variant), so `destructive` cannot end up with a non-destructive confirm button; `destructive` also renders as `role="alertdialog"`, and `description` is wired to the dialog through `aria-describedby`, so the consequence is announced and not just the title. `confirmPhrase` gates the confirm action on typing that exact phrase, for a consequence severe enough that one click should not be able to cause it — the typed value and the phrase are both trimmed, since copying a name picks up a trailing space and a saved name can carry padding that never renders, except that a phrase of only whitespace is matched exactly as given, so an empty field cannot confirm it; the match stays case-sensitive, and the field clears each time the dialog opens, being a per-decision gate rather than a value. Neither a destructive dialog nor one carrying a `confirmPhrase` dismisses on a scrim click, and `loading` suppresses the pointer routes — the scrim and the close button — as well as disabling the buttons. It never suppresses ESC: that is the only guaranteed keyboard exit from a focus trap, so it always reaches `onClose` and whether to abort is left to the caller. ESC reaches it whenever it is the topmost overlay, so it can be opened over a panel. `confirmDisabled` holds only the confirm action back, for a consequence still being worked out (a check the callout reports on, so pair it with a callout saying why); cancel and every dismissal route stay live. `callout` renders an `Alert` in a full-width band at the top of the body — it scrolls with the body rather than being pinned under the header, and with no `description`, `children` or `confirmPhrase` there is no body, so the band sits directly on the footer — and its `type` is chosen independently of `variant` — the frames pair a green badge with an amber callout. `titleAdornment` names the entity beside the title, `badgeIcon` overrides the variant’s glyph for an action-specific one, and `tip` is the `{ label?, message }` caption on the tray beneath the card, which `Modal` renders and describes. `children` is where extra body content goes. `onConfirm` does not close the dialog, so the caller can hold it open on `loading` while the request is in flight. `confirmPhraseLabel` also takes `{ prefix, suffix }`, which renders the phrase itself as a copyable token between the two — the gate is case-sensitive and space-exact inside the phrase, so a customer who has identified the right entity should not be locked out by a glyph they cannot tell apart. The copy control sits outside the element that names the field, so “Copy…” never lands in the field’s accessible name; `confirmPhraseCopyLabel` names it and `onPhraseCopied` reports a completed write with the phrase it copied. A rejected write says so in the field rather than failing silently, and the control is disabled where the Clipboard API is unavailable. A near miss is named rather than left to a disabled button: typing the phrase with the wrong case or the wrong spacing says which, once the whole phrase is there, and that message is the field’s `aria-describedby`. _Key props:_ `open`, `onClose`, `onConfirm`, `title`, `description`, `titleAdornment`, `badgeIcon`, `variant` (`default` | `warning` | `destructive` | `success`), `callout`, `confirmPhrase`, `confirmPhraseLabel`, `confirmPhraseCopyLabel`, `confirmPhrasePlaceholder`, `onPhraseCopied`, `confirmLabel`, `cancelLabel`, `loading`, `confirmDisabled`, `tip`, `size`, `aria-label`, `aria-labelledby`.
|
|
57
58
|
|
|
58
59
|
## Forms & inputs
|
|
@@ -90,7 +91,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
90
91
|
- **`PreviewTree`** — Nested, indented tree for previewing hierarchical structure.
|
|
91
92
|
- **`PreviewTreeRow`** — A single labelled row within a PreviewTree. _Key props:_ `label`.
|
|
92
93
|
- **`Tabs`** — Tabbed navigation switching between content panels. ArrowLeft and ArrowRight on a focused tab move focus to the next enabled tab, wrapping at the ends, and Home and End to the first and last; Enter, Space or a click opens it, or `activation="automatic"` opens the tab an arrow reaches. ArrowUp, ArrowDown and any key with Alt, Ctrl or Cmd held are left to the page. `trailing` puts content on the same row, settled against its end — a count, a scope picker, the state the tabs are showing — inside the rule this component already draws. Without it a consumer had to redraw that rule to carry it past the tabs, and the tab list, which cannot wrap, would not yield any width to what sat beside it. The tabs hold their width and the trailing content gives ground; the `tablist` role stays on the tabs alone, so the extra content is not announced as one. Give an item `content` and each tab gets a `tabpanel` below the strip, wired with `aria-controls` and `aria-labelledby`: a panel mounts the first time its tab opens and then stays mounted, hidden, so a search, a filter or a scroll position survives a round trip and its data is not fetched again. `destroyInactivePanels` unmounts a panel when its tab is left instead. Panels have no overflow of their own, so a sticky toolbar inside one still pins to the page. Leave `content` off every item and the strip is all it renders. _Key props:_ `TabItem[]` (`key`, `label`, `count` (a `NumberTag` after the label), `disabled`, `content`), `activeKey`, `onChange`, `trailing`, `destroyInactivePanels`, `activation` (`manual` | `automatic`), `className`, `style`.
|
|
93
|
-
- **`Breadcrumbs`** — Breadcrumb trail with caret separators, an optional back button (shown only when there is more than one crumb AND the parent — the second-to-last — carries a `url` to target) and a right-aligned `actions` row. A lone crumb marked `isRoot` switches to title mode: plain emphasised text, no trail chrome, but the `actions` row still renders. Renders as a `nav`/`ol` with `aria-current="page"` on the last crumb. Pass `renderLink` to route crumbs through the app's own router instead of a plain `<a>`. Used by `PageLayout`, but standalone too. _Key props:_ `links[]` (`name`, `url`, `isRoot`), `actions[]`, `renderLink`, `className`, `style`.
|
|
94
|
+
- **`Breadcrumbs`** — Breadcrumb trail with caret separators, an optional back button (shown only when there is more than one crumb AND the parent — the second-to-last — carries a `url` to target) and a right-aligned `actions` row. A lone crumb marked `isRoot` switches to title mode: plain emphasised text, no trail chrome, but the `actions` row still renders; `titleElement` renders it as a heading, which `PageLayout.Regular` asks for (`h1`) when no `title` heading is showing. Renders as a `nav`/`ol` with `aria-current="page"` on the last crumb. Pass `renderLink` to route crumbs through the app's own router instead of a plain `<a>`. Used by `PageLayout`, but standalone too. _Key props:_ `links[]` (`name`, `url`, `isRoot`), `actions[]`, `renderLink`, `titleElement`, `className`, `style`.
|
|
94
95
|
- **`ActionMenu`** — Dropdown menu of actions (kebab/overflow style). The trigger is an icon-only `Button` by default, so `size` draws exactly the square a `Button` of that size draws beside it: `xsmall` is Figma's 20px "Button Element - Square (X-Small)", `small` the 28px rung above it. Both squares are fixed rather than read off the `controlHeights` tokens, so re-theming those does not resize the trigger. A supplied `triggerIcon` is held to the tier's glyph size — 11px at `xsmall`, 16px at `small`. At 20px the `xsmall` trigger meets WCAG 2.5.8 through the *Spacing* exception rather than the 24px minimum, so keep at least 4px between adjacent triggers. `showLabel` draws `label` beside the icon instead of leaving it to the accessible name — for a menu that is the point of its corner rather than an overflow for a row that already says what it acts on — and `variant` puts the trigger on any `Button` variant, so a menu handing work to the assistant can wear the assistant ground rather than the overflow-kebab outline. An item's `icon` leads its label: every caller's names the action itself — copy, open, delete — and an icon that is part of an item's identity belongs where the eye starts rather than right-aligned, where it reads as a status column. The menu is Figma's `Dropdown Component - Options List`: a fixed sized to its widest item between a 180px floor and the 280px Figma draws, by default under the trigger's right edge, 14px below it, flipping above or clamping sideways when the viewport has no room, rounding at the library's 12px and padding wider (8px) than the menu a `Dropdown` opens. Items read in the primary text colour, or the secondary one with `tone="muted"` (e.g. a sidebar's menus); destructive ones in red; `danger: 'hover'` keeps an item in its normal colour and turns it destructive (red text on a light red ground) only on hover or keyboard focus, for an action like signing out. A ceiling rather than a flat width: taken literally it gave a menu of four short verbs 130px of air and made every kebab in an app the same width whatever it held. `minWidth` only raises it above that ceiling, so it is the one way to go past 280px, and a label too long for the box truncates rather than wrapping. _Key props:_ `ActionMenuItem[]`, `size`, `label`, `triggerIcon`, `minWidth`, `showLabel`, `variant`, `tone` (`default` | `muted`), `trigger` (your own control in place of the kebab, cloned with the menu's ref and aria state), `highlightChoices`, `placement` (`bottom-end` default | `bottom-start` | `right-start` | `top-start` | `top-center`), `offset` (`small` 8px | `medium` 12px | `large` 14px; applies to every placement; without it the default `bottom-end` keeps the options menu's 14px and the others use 8px). An item's `tag` (e.g. an "Early access" `Tag`) follows its label in a lazily loaded shadow host of its own, since the menu renders into `document.body`, and joins its accessible name; `current: true` marks the item for the page the user is on (`aria-current="page"` and the selected row paint; a `danger` item keeps its red text). An item with an `href` is a link: Cmd/Ctrl-click or a middle click opens it in a new tab and closes the menu, while a plain click runs `onClick` in its place when one is given (so a router can navigate in-app); Enter and Space both activate it. `target: '_blank'` opens it in a new tab, adds `noopener noreferrer` and tells screen readers it opens a new tab. An item with `checked` is one of a set of choices: a `menuitemradio` with `aria-checked` and a trailing check while true; picking it still runs `onClick` and closes. Give the choices of one set the same `group` and, where they sit next to each other, they share a `role="group"` named by it, so a screen reader can tell where the set ends; choices with the same `group` split by another item form separate groups. `description` adds a quieter second line under the label, announced as the item's description rather than its name. `intent` colours the label and icon: `warning` (amber) for undoing choices already made, `accent` (green) for a way forward; a disabled item drops it, and `danger` or `current` wins over it. `highlightChoices` styles the menu as a picker: the checked choice of each `group` sits on a light green row (a Dropdown selected option's ground) with a green check (a danger, intent, disabled or current choice keeps its own colours), and a text row whose label is a set's `group` name sits a notch smaller, as its heading. An item with `type: 'text'` is context rather than an action (an account's email above its actions): secondary text the arrow keys skip. Opened from the keyboard, focus lands on the first item, or on the checked choice in a menu of choices; Up/Down/Home/End move through enabled items, Tab closes the menu and moves on as usual; Escape or a picked item returns focus to the trigger.
|
|
95
96
|
- **`NavItem`** — A row in an app's side navigation. Idle rows read secondary and take the list hover; the `active` row wears the accent tint and sets `aria-current="page"` on a link. `collapsed` shrinks it to a 36px icon tile whose label becomes the accessible name and a right-hand tooltip, with any `badge` pinned to the tile's corner. `variant="subitem"` indents a child row behind a dot instead of an icon; `disclosure` makes a group header button with `aria-expanded` and a rotating chevron, and `hasActiveChild` colours its text while a child is current. Renders an `<a>` with `href`, the element passed with `asChild` (a router `Link`), or a `<button>`, and forwards its ref and extra attributes so it can be a `Popover` or `ActionMenu` trigger. `disabled` keeps the row a tab stop with `aria-disabled`, drops its hover and pointer, and ignores clicks, Enter and Space; a `Popover` or `ActionMenu` it triggers stays shut on press, hover, focus and arrow keys, while other keys still reach a passed `onKeyDown` so arrow navigation through a list keeps working; a disabled `href` row renders as a button so it cannot be followed. `disabledReason` explains it in a right-hand tooltip on hover and focus and is the row's accessible description from the first focus. Not with `asChild`, whose child would still navigate. _Key props:_ `label`, `icon`, `active`, `hasActiveChild`, `collapsed`, `variant` (`item` | `subitem`), `danger`, `trailing`, `badge`, `disclosure` (`expanded` | `collapsed`), `tooltip`, `accessibleLabel` (overrides the accessible name; collapsed it defaults to the tooltip text plus `badgeLabel`), `href`, `target`, `rel`, `onClick`, `asChild` + `children`, `className`, `size` (`medium` | `small`, the tighter row for lists inside a popover), `tag` (beside the label, e.g. early access), `badgeLabel` (read in place of the badge and added to the collapsed name), `disabled`, `disabledReason`. A passed `aria-expanded` (e.g. from a `Popover`) wins over `disclosure`, and a button row forwards a passed `aria-current`.
|
|
96
97
|
- **`Sidebar`** — An app's left navigation shell, pinned to the viewport's left edge: 260px wide, 60px `collapsed`, on the sunken page background. Composed from `Sidebar.Header` (a 56px band for `Sidebar.Switcher`, the logo + workspace + parent trigger), `Sidebar.Body` (the part that scrolls), `Sidebar.Notices`, `Sidebar.Search`, `Sidebar.Section` (rows of `NavItem`s at the gutter), `Sidebar.Group` + `Sidebar.GroupItems` (a disclosure header and its sub-items), `Sidebar.Divider`, `Sidebar.Usage` (a `UsageCard` placed at the sidebar's gutter) and `Sidebar.Footer` holding `Sidebar.Account`. Popovers opened from it (with `padding="none"`) wrap their body in `Sidebar.Panel`, sized so the popover comes to `SIDEBAR_POPOVER_WIDTH_PX`, and build it from the `Popover` parts. `onToggleCollapse` adds the edge toggle, shown in CSS while the pointer is over the sidebar or a keyboard focus is inside it, and always on a touch screen, which has no hover to reveal it. A workspace, organization or account name cut off in the expanded sidebar shows in full on hover. Notices, the divider and the usage card hide while collapsed. Render it inside `<MalachiteContext layer="sidebar">`, or the page paints over the edge toggle. On a viewport narrower than `SIDEBAR_OVERLAY_BREAKPOINT_PX` (768px) pass `overlay`, collapse it on entering overlay mode, and keep the page at the collapsed offset. Collapsed, it is the plain rail and takes no focus. Expanded from that rail, it floats over the page as a modal drawer, behind a scrim, with Escape, a focus trap and scroll lock, and a click on the scrim or Escape collapses it through `onToggleCollapse`. Expanded on mount or across the breakpoint it stays a plain sidebar, so it never takes focus from the page, and expanded under an open dialog it becomes the drawer once that dialog closes. _Key props:_ `collapsed`, `onToggleCollapse`, `overlay`, `expandLabel`, `collapseLabel`, `aria-label`; `Sidebar.Switcher`: `logo`, `title`, `subtitle`, `titleTooltip`/`subtitleTooltip` (shown when the name is cut off, the name by default; pass a node to wrap it, e.g. to keep it out of session recordings) + button attributes; `Sidebar.Account`: `avatar` or `initials` (a small chip when there is no photo), `name`, `tooltip` (on the collapsed rail, and expanded when the name is cut off; `name` by default; pass a node to wrap it) + button attributes; `Sidebar.Usage`: the `UsageCard` props; `Sidebar.Notices`: `aria-label` (required); `Sidebar.Panel`: `width` (`SIDEBAR_POPOVER_WIDTH_PX` by default). `useSidebarCollapsed()` reads the state from inside; `SIDEBAR_WIDTH_PX` gives the page its offset beside the sidebar; `SIDEBAR_TOOLTIP_DELAY_S` is the 0.2s delay its name and rail tooltips use, for tooltips a consumer adds inside it.
|
|
@@ -1,106 +1,122 @@
|
|
|
1
|
-
import { jsxs as u, jsx as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { jsxs as u, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import N from "react";
|
|
3
|
+
import { Button as B } from "./Button.js";
|
|
4
|
+
import S from "./CustomIcons/ArrowLeftIcon.js";
|
|
5
|
+
import _ from "./CustomIcons/CaretRightIcon.js";
|
|
6
|
+
import $ from "./Typography/Text.js";
|
|
7
|
+
import { hasBackButton as y } from "./breadcrumbsNav.js";
|
|
7
8
|
import { FOCUS_RING as x } from "./focusRing.js";
|
|
8
|
-
import { isSafeHref as
|
|
9
|
-
const
|
|
9
|
+
import { isSafeHref as E, safeHref as A } from "./safeHref.js";
|
|
10
|
+
const R = `no-underline rounded-xs cursor-pointer transition-colors duration-200 ease-in-out hover:text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${x}`, C = `flex h-6 w-6 shrink-0 items-center justify-center rounded-[var(--malachite-radius-10,10px)] no-underline bg-[var(--malachite-number-tag-background,rgba(0,0,0,0.08))] text-[var(--malachite-text-primary,rgb(10,10,10))] transition-colors duration-200 ease-in-out hover:bg-[var(--malachite-number-tag-emphasis-background,rgba(0,0,0,0.15))] ${x}`, p = (e, r) => E(e.href) ? r ? r(e) : /* @__PURE__ */ n("a", { ...e }) : e.children, v = { margin: 0 }, I = {
|
|
11
|
+
...v,
|
|
12
|
+
fontSize: "inherit",
|
|
13
|
+
fontWeight: "inherit"
|
|
14
|
+
}, f = (e, r, a) => typeof e == "string" ? /* @__PURE__ */ n(
|
|
15
|
+
$,
|
|
16
|
+
{
|
|
17
|
+
as: a,
|
|
18
|
+
size: "medium",
|
|
19
|
+
fontWeight: "semi-bold",
|
|
20
|
+
color: r,
|
|
21
|
+
style: a ? v : void 0,
|
|
22
|
+
children: e
|
|
23
|
+
}
|
|
24
|
+
) : a ? N.createElement(a, { style: I }, e) : e, T = ({
|
|
10
25
|
label: e,
|
|
11
26
|
onClick: r,
|
|
12
|
-
disabled:
|
|
13
|
-
variant:
|
|
14
|
-
icon:
|
|
15
|
-
href:
|
|
16
|
-
target:
|
|
17
|
-
tooltip:
|
|
18
|
-
tooltipPlacement:
|
|
19
|
-
},
|
|
20
|
-
const
|
|
21
|
-
return /* @__PURE__ */
|
|
22
|
-
|
|
27
|
+
disabled: a,
|
|
28
|
+
variant: c,
|
|
29
|
+
icon: s,
|
|
30
|
+
href: d,
|
|
31
|
+
target: h,
|
|
32
|
+
tooltip: i,
|
|
33
|
+
tooltipPlacement: m
|
|
34
|
+
}, l) => {
|
|
35
|
+
const t = A(d);
|
|
36
|
+
return /* @__PURE__ */ n(
|
|
37
|
+
B,
|
|
23
38
|
{
|
|
24
39
|
size: "small",
|
|
25
|
-
variant:
|
|
26
|
-
disabled:
|
|
27
|
-
icon:
|
|
28
|
-
tooltip:
|
|
29
|
-
tooltipPlacement:
|
|
30
|
-
href:
|
|
31
|
-
target:
|
|
32
|
-
onClick:
|
|
40
|
+
variant: c ?? "outline",
|
|
41
|
+
disabled: a,
|
|
42
|
+
icon: s,
|
|
43
|
+
tooltip: i,
|
|
44
|
+
tooltipPlacement: m,
|
|
45
|
+
href: t,
|
|
46
|
+
target: t ? h ?? "_blank" : void 0,
|
|
47
|
+
onClick: t ? void 0 : r,
|
|
33
48
|
children: e
|
|
34
49
|
},
|
|
35
|
-
`${
|
|
50
|
+
`${l}-${e}`
|
|
36
51
|
);
|
|
37
|
-
},
|
|
52
|
+
}, K = ({
|
|
38
53
|
links: e,
|
|
39
54
|
actions: r,
|
|
40
|
-
renderLink:
|
|
55
|
+
renderLink: a,
|
|
56
|
+
titleElement: c,
|
|
41
57
|
className: s = "",
|
|
42
58
|
style: d
|
|
43
59
|
}) => {
|
|
44
60
|
if (e.length === 0 && !(r != null && r.length))
|
|
45
61
|
return null;
|
|
46
|
-
const h = e.length === 1 && !!e[0].isRoot,
|
|
62
|
+
const h = e.length === 1 && !!e[0].isRoot, i = y(e) ? e[e.length - 2] : void 0, m = i == null ? void 0 : i.name, l = !!(r != null && r.length);
|
|
47
63
|
return /* @__PURE__ */ u(
|
|
48
64
|
"div",
|
|
49
65
|
{
|
|
50
|
-
className: `flex items-center ${
|
|
66
|
+
className: `flex items-center ${l ? "justify-between" : ""} ${s}`,
|
|
51
67
|
style: d,
|
|
52
68
|
children: [
|
|
53
|
-
h ? f(e[0].name, "primary") : /* @__PURE__ */ u("div", { className: "flex items-center gap-4", children: [
|
|
54
|
-
(
|
|
69
|
+
h ? f(e[0].name, "primary", c) : /* @__PURE__ */ u("div", { className: "flex items-center gap-4", children: [
|
|
70
|
+
(i == null ? void 0 : i.url) && p(
|
|
55
71
|
{
|
|
56
|
-
href:
|
|
57
|
-
"aria-label": typeof
|
|
72
|
+
href: i.url,
|
|
73
|
+
"aria-label": typeof m == "string" ? `Back to ${m}` : "Go back",
|
|
58
74
|
className: C,
|
|
59
|
-
children: /* @__PURE__ */
|
|
75
|
+
children: /* @__PURE__ */ n(S, { size: 12 })
|
|
60
76
|
},
|
|
61
|
-
|
|
77
|
+
a
|
|
62
78
|
),
|
|
63
|
-
e.length > 0 && /* @__PURE__ */
|
|
64
|
-
const o =
|
|
79
|
+
e.length > 0 && /* @__PURE__ */ n("nav", { "aria-label": "Breadcrumb", children: /* @__PURE__ */ n("ol", { className: "flex flex-wrap items-center gap-2 m-0 p-0 list-none", children: e.map((t, g) => {
|
|
80
|
+
const o = g === e.length - 1, b = o ? "primary" : "muted";
|
|
65
81
|
return /* @__PURE__ */ u(
|
|
66
82
|
"li",
|
|
67
83
|
{
|
|
68
84
|
className: "flex items-center gap-2",
|
|
69
|
-
"aria-current": o && !
|
|
85
|
+
"aria-current": o && !t.url ? "page" : void 0,
|
|
70
86
|
children: [
|
|
71
|
-
|
|
87
|
+
t.url ? p(
|
|
72
88
|
{
|
|
73
|
-
href:
|
|
89
|
+
href: t.url,
|
|
74
90
|
"aria-current": o ? "page" : void 0,
|
|
75
|
-
className: `${
|
|
91
|
+
className: `${R} ${o ? "text-[var(--malachite-text-primary,rgb(10,10,10))]" : "text-[var(--malachite-text-muted,rgb(76,75,75))]"}`,
|
|
76
92
|
children: f(
|
|
77
|
-
|
|
93
|
+
t.name,
|
|
78
94
|
"inherit"
|
|
79
95
|
)
|
|
80
96
|
},
|
|
81
|
-
|
|
82
|
-
) : f(
|
|
83
|
-
!o && /* @__PURE__ */
|
|
97
|
+
a
|
|
98
|
+
) : f(t.name, b),
|
|
99
|
+
!o && /* @__PURE__ */ n(
|
|
84
100
|
"span",
|
|
85
101
|
{
|
|
86
102
|
"aria-hidden": "true",
|
|
87
103
|
className: "flex items-center text-[var(--malachite-text-dimmed,rgb(161,161,161))]",
|
|
88
|
-
children: /* @__PURE__ */
|
|
104
|
+
children: /* @__PURE__ */ n(_, { size: 13 })
|
|
89
105
|
}
|
|
90
106
|
)
|
|
91
107
|
]
|
|
92
108
|
},
|
|
93
|
-
`${
|
|
109
|
+
`${t.url ?? ""}-${g}`
|
|
94
110
|
);
|
|
95
111
|
}) }) })
|
|
96
112
|
] }),
|
|
97
|
-
|
|
113
|
+
l && /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: r == null ? void 0 : r.map(T) })
|
|
98
114
|
]
|
|
99
115
|
}
|
|
100
116
|
);
|
|
101
117
|
};
|
|
102
118
|
export {
|
|
103
|
-
|
|
104
|
-
|
|
119
|
+
K as Breadcrumbs,
|
|
120
|
+
K as default
|
|
105
121
|
};
|
|
106
122
|
//# sourceMappingURL=Breadcrumbs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Breadcrumbs.js","sources":["../../src/components/Breadcrumbs.tsx"],"sourcesContent":["import React from 'react';\nimport Button from './Button';\nimport ArrowLeftIcon from './CustomIcons/ArrowLeftIcon';\nimport CaretRightIcon from './CustomIcons/CaretRightIcon';\nimport type { BreadcrumbLink, PageAction, RenderLink } from './PageLayout/types';\nimport Text, { type TextColor } from './Typography/Text';\nimport { hasBackButton } from './breadcrumbsNav';\nimport { FOCUS_RING } from './focusRing';\nimport { isSafeHref, safeHref } from './safeHref';\n\nexport interface BreadcrumbsProps {\n links: BreadcrumbLink[];\n actions?: PageAction[];\n renderLink?: RenderLink;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst CRUMB_LINK_CLASSES = `no-underline rounded-xs cursor-pointer transition-colors duration-200 ease-in-out hover:text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${FOCUS_RING}`;\n\nconst BACK_BUTTON_CLASSES = `flex h-6 w-6 shrink-0 items-center justify-center rounded-[var(--malachite-radius-10,10px)] no-underline bg-[var(--malachite-number-tag-background,rgba(0,0,0,0.08))] text-[var(--malachite-text-primary,rgb(10,10,10))] transition-colors duration-200 ease-in-out hover:bg-[var(--malachite-number-tag-emphasis-background,rgba(0,0,0,0.15))] ${FOCUS_RING}`;\n\ntype LinkProps = Parameters<RenderLink>[0];\n\nconst renderCrumbLink = (props: LinkProps, renderLink?: RenderLink): React.ReactNode => {\n // An unsafe url degrades to plain text rather than a link that could run a script.\n if (!isSafeHref(props.href)) {\n return props.children;\n }\n return renderLink ? renderLink(props) : <a {...props} />;\n};\n\nconst renderCrumbName = (name: React.ReactNode, color: TextColor): React.ReactNode =>\n typeof name === 'string' ? (\n <Text size=\"medium\" fontWeight=\"semi-bold\" color={color}>\n {name}\n </Text>\n ) : (\n name\n );\n\nconst renderAction = (\n {\n label,\n onClick,\n disabled,\n variant,\n icon,\n href,\n target,\n tooltip,\n tooltipPlacement,\n }: PageAction,\n index: number,\n) => {\n const safe = safeHref(href);\n return (\n <Button\n key={`${index}-${label}`}\n size=\"small\"\n variant={variant ?? 'outline'}\n disabled={disabled}\n icon={icon}\n tooltip={tooltip}\n tooltipPlacement={tooltipPlacement}\n href={safe}\n target={safe ? (target ?? '_blank') : undefined}\n onClick={safe ? undefined : onClick}\n >\n {label}\n </Button>\n );\n};\n\nconst Breadcrumbs: React.FC<BreadcrumbsProps> = ({\n links,\n actions,\n renderLink,\n className = '',\n style,\n}) => {\n // PageLayout mounts this unconditionally, so returning markup would leave an empty\n // navigation landmark on every page without crumbs.\n if (links.length === 0 && !actions?.length) {\n return null;\n }\n\n const isTitle = links.length === 1 && Boolean(links[0].isRoot);\n const parentCrumb = hasBackButton(links) ? links[links.length - 2] : undefined;\n const parentName = parentCrumb?.name;\n const hasActions = Boolean(actions?.length);\n\n return (\n <div\n className={`flex items-center ${hasActions ? 'justify-between' : ''} ${className}`}\n style={style}\n >\n {isTitle ? (\n renderCrumbName(links[0].name, 'primary')\n ) : (\n <div className=\"flex items-center gap-4\">\n {parentCrumb?.url &&\n renderCrumbLink(\n {\n href: parentCrumb.url,\n 'aria-label':\n typeof parentName === 'string'\n ? `Back to ${parentName}`\n : 'Go back',\n className: BACK_BUTTON_CLASSES,\n children: <ArrowLeftIcon size={12} />,\n },\n renderLink,\n )}\n {links.length > 0 && (\n <nav aria-label=\"Breadcrumb\">\n <ol className=\"flex flex-wrap items-center gap-2 m-0 p-0 list-none\">\n {links.map((link, index) => {\n const isLast = index === links.length - 1;\n const color: TextColor = isLast ? 'primary' : 'muted';\n\n return (\n <li\n key={`${link.url ?? ''}-${index}`}\n className=\"flex items-center gap-2\"\n aria-current={isLast && !link.url ? 'page' : undefined}\n >\n {link.url\n ? renderCrumbLink(\n {\n href: link.url,\n 'aria-current': isLast\n ? 'page'\n : undefined,\n className: `${CRUMB_LINK_CLASSES} ${\n isLast\n ? 'text-[var(--malachite-text-primary,rgb(10,10,10))]'\n : 'text-[var(--malachite-text-muted,rgb(76,75,75))]'\n }`,\n children: renderCrumbName(\n link.name,\n 'inherit',\n ),\n },\n renderLink,\n )\n : renderCrumbName(link.name, color)}\n {!isLast && (\n <span\n aria-hidden=\"true\"\n className=\"flex items-center text-[var(--malachite-text-dimmed,rgb(161,161,161))]\"\n >\n <CaretRightIcon size={13} />\n </span>\n )}\n </li>\n );\n })}\n </ol>\n </nav>\n )}\n </div>\n )}\n {hasActions && (\n <div className=\"flex items-center gap-2\">{actions?.map(renderAction)}</div>\n )}\n </div>\n );\n};\n\nexport { Breadcrumbs };\nexport default Breadcrumbs;\n"],"names":["CRUMB_LINK_CLASSES","FOCUS_RING","BACK_BUTTON_CLASSES","renderCrumbLink","props","renderLink","isSafeHref","jsx","renderCrumbName","name","color","Text","renderAction","label","onClick","disabled","variant","icon","href","target","tooltip","tooltipPlacement","index","safe","safeHref","Button","Breadcrumbs","links","actions","className","style","isTitle","parentCrumb","hasBackButton","parentName","hasActions","jsxs","ArrowLeftIcon","link","isLast","CaretRightIcon"],"mappings":";;;;;;;;AAkBA,MAAMA,IAAqB,mJAAmJC,CAAU,IAElLC,IAAsB,mVAAmVD,CAAU,IAInXE,IAAkB,CAACC,GAAkBC,MAElCC,EAAWF,EAAM,IAAI,IAGnBC,IAAaA,EAAWD,CAAK,IAAI,gBAAAG,EAAC,KAAA,EAAG,GAAGH,GAAO,IAF3CA,EAAM,UAKfI,IAAkB,CAACC,GAAuBC,MAC5C,OAAOD,KAAS,WACZ,gBAAAF,EAACI,GAAA,EAAK,MAAK,UAAS,YAAW,aAAY,OAAAD,GACtC,aACL,IAEAD,GAGFG,IAAe,CACjB;AAAA,EACI,OAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UA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UAAAP,KAAA,gBAAAA,EAAS,IAAIhB,GAAY,CAAE;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIrF;"}
|
|
1
|
+
{"version":3,"file":"Breadcrumbs.js","sources":["../../src/components/Breadcrumbs.tsx"],"sourcesContent":["import React from 'react';\nimport Button from './Button';\nimport ArrowLeftIcon from './CustomIcons/ArrowLeftIcon';\nimport CaretRightIcon from './CustomIcons/CaretRightIcon';\nimport type { BreadcrumbLink, PageAction, RenderLink } from './PageLayout/types';\nimport Text, { type TextColor, type TextElement } from './Typography/Text';\nimport { hasBackButton } from './breadcrumbsNav';\nimport { FOCUS_RING } from './focusRing';\nimport { isSafeHref, safeHref } from './safeHref';\n\nexport interface BreadcrumbsProps {\n links: BreadcrumbLink[];\n actions?: PageAction[];\n renderLink?: RenderLink;\n /** The element a lone root crumb renders as, e.g. `h1` when it titles the page. */\n titleElement?: TextElement;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst CRUMB_LINK_CLASSES = `no-underline rounded-xs cursor-pointer transition-colors duration-200 ease-in-out hover:text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${FOCUS_RING}`;\n\nconst BACK_BUTTON_CLASSES = `flex h-6 w-6 shrink-0 items-center justify-center rounded-[var(--malachite-radius-10,10px)] no-underline bg-[var(--malachite-number-tag-background,rgba(0,0,0,0.08))] text-[var(--malachite-text-primary,rgb(10,10,10))] transition-colors duration-200 ease-in-out hover:bg-[var(--malachite-number-tag-emphasis-background,rgba(0,0,0,0.15))] ${FOCUS_RING}`;\n\ntype LinkProps = Parameters<RenderLink>[0];\n\nconst renderCrumbLink = (props: LinkProps, renderLink?: RenderLink): React.ReactNode => {\n // An unsafe url degrades to plain text rather than a link that could run a script.\n if (!isSafeHref(props.href)) {\n return props.children;\n }\n return renderLink ? renderLink(props) : <a {...props} />;\n};\n\nconst HEADING_RESET: React.CSSProperties = { margin: 0 };\n\nconst NODE_HEADING_RESET: React.CSSProperties = {\n ...HEADING_RESET,\n fontSize: 'inherit',\n fontWeight: 'inherit',\n};\n\nconst renderCrumbName = (\n name: React.ReactNode,\n color: TextColor,\n as?: TextElement,\n): React.ReactNode => {\n if (typeof name === 'string') {\n return (\n <Text\n as={as}\n size=\"medium\"\n fontWeight=\"semi-bold\"\n color={color}\n style={as ? HEADING_RESET : undefined}\n >\n {name}\n </Text>\n );\n }\n return as ? React.createElement(as, { style: NODE_HEADING_RESET }, name) : name;\n};\n\nconst renderAction = (\n {\n label,\n onClick,\n disabled,\n variant,\n icon,\n href,\n target,\n tooltip,\n tooltipPlacement,\n }: PageAction,\n index: number,\n) => {\n const safe = safeHref(href);\n return (\n <Button\n key={`${index}-${label}`}\n size=\"small\"\n variant={variant ?? 'outline'}\n disabled={disabled}\n icon={icon}\n tooltip={tooltip}\n tooltipPlacement={tooltipPlacement}\n href={safe}\n target={safe ? (target ?? '_blank') : undefined}\n onClick={safe ? undefined : onClick}\n >\n {label}\n </Button>\n );\n};\n\nconst Breadcrumbs: React.FC<BreadcrumbsProps> = ({\n links,\n actions,\n renderLink,\n titleElement,\n className = '',\n style,\n}) => {\n // PageLayout mounts this unconditionally, so returning markup would leave an empty\n // navigation landmark on every page without crumbs.\n if (links.length === 0 && !actions?.length) {\n return null;\n }\n\n const isTitle = links.length === 1 && Boolean(links[0].isRoot);\n const parentCrumb = hasBackButton(links) ? links[links.length - 2] : undefined;\n const parentName = parentCrumb?.name;\n const hasActions = Boolean(actions?.length);\n\n return (\n <div\n className={`flex items-center ${hasActions ? 'justify-between' : ''} ${className}`}\n style={style}\n >\n {isTitle ? (\n renderCrumbName(links[0].name, 'primary', titleElement)\n ) : (\n <div className=\"flex items-center gap-4\">\n {parentCrumb?.url &&\n renderCrumbLink(\n {\n href: parentCrumb.url,\n 'aria-label':\n typeof parentName === 'string'\n ? `Back to ${parentName}`\n : 'Go back',\n className: BACK_BUTTON_CLASSES,\n children: <ArrowLeftIcon size={12} />,\n },\n renderLink,\n )}\n {links.length > 0 && (\n <nav aria-label=\"Breadcrumb\">\n <ol className=\"flex flex-wrap items-center gap-2 m-0 p-0 list-none\">\n {links.map((link, index) => {\n const isLast = index === links.length - 1;\n const color: TextColor = isLast ? 'primary' : 'muted';\n\n return (\n <li\n key={`${link.url ?? ''}-${index}`}\n className=\"flex items-center gap-2\"\n aria-current={isLast && !link.url ? 'page' : undefined}\n >\n {link.url\n ? renderCrumbLink(\n {\n href: link.url,\n 'aria-current': isLast\n ? 'page'\n : undefined,\n className: `${CRUMB_LINK_CLASSES} ${\n isLast\n ? 'text-[var(--malachite-text-primary,rgb(10,10,10))]'\n : 'text-[var(--malachite-text-muted,rgb(76,75,75))]'\n }`,\n children: renderCrumbName(\n link.name,\n 'inherit',\n ),\n },\n renderLink,\n )\n : renderCrumbName(link.name, color)}\n {!isLast && (\n <span\n aria-hidden=\"true\"\n className=\"flex items-center text-[var(--malachite-text-dimmed,rgb(161,161,161))]\"\n >\n <CaretRightIcon size={13} />\n </span>\n )}\n </li>\n );\n })}\n </ol>\n </nav>\n )}\n </div>\n )}\n {hasActions && (\n <div className=\"flex items-center gap-2\">{actions?.map(renderAction)}</div>\n )}\n </div>\n );\n};\n\nexport { Breadcrumbs };\nexport default Breadcrumbs;\n"],"names":["CRUMB_LINK_CLASSES","FOCUS_RING","BACK_BUTTON_CLASSES","renderCrumbLink","props","renderLink","isSafeHref","jsx","HEADING_RESET","NODE_HEADING_RESET","renderCrumbName","name","color","as","Text","React","renderAction","label","onClick","disabled","variant","icon","href","target","tooltip","tooltipPlacement","index","safe","safeHref","Button","Breadcrumbs","links","actions","titleElement","className","style","isTitle","parentCrumb","hasBackButton","parentName","hasActions","jsxs","ArrowLeftIcon","link","isLast","CaretRightIcon"],"mappings":";;;;;;;;;AAoBA,MAAMA,IAAqB,mJAAmJC,CAAU,IAElLC,IAAsB,mVAAmVD,CAAU,IAInXE,IAAkB,CAACC,GAAkBC,MAElCC,EAAWF,EAAM,IAAI,IAGnBC,IAAaA,EAAWD,CAAK,IAAI,gBAAAG,EAAC,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,IAC5B4C,IACM,uDACA,kDACV;AAAA,sBACA,UAAUlC;AAAA,wBACNiC,EAAK;AAAA,wBACL;AAAA,sBAAA;AAAA,oBACJ;AAAA,oBAEJtC;AAAA,kBAAA,IAEJK,EAAgBiC,EAAK,MAAM/B,CAAK;AAAA,kBACrC,CAACgC,KACE,gBAAArC;AAAA,oBAAC;AAAA,oBAAA;AAAA,sBACG,eAAY;AAAA,sBACZ,WAAU;AAAA,sBAEV,UAAA,gBAAAA,EAACsC,GAAA,EAAe,MAAM,GAAA,CAAI;AAAA,oBAAA;AAAA,kBAAA;AAAA,gBAC9B;AAAA,cAAA;AAAA,cA9BC,GAAGF,EAAK,OAAO,EAAE,IAAIjB,CAAK;AAAA,YAAA;AAAA,UAkC3C,CAAC,GACL,EAAA,CACJ;AAAA,QAAA,GAER;AAAA,QAEHc,uBACI,OAAA,EAAI,WAAU,2BAA2B,UAAAR,KAAA,gBAAAA,EAAS,IAAIhB,GAAY,CAAE;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIrF;"}
|
|
@@ -1,56 +1,57 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"var(--malachite-
|
|
6
|
-
"var(--malachite-
|
|
7
|
-
"var(--malachite-
|
|
8
|
-
"var(--malachite-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { jsxs as O, jsx as C } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as m, useEffect as S } from "react";
|
|
3
|
+
import { createPieces as F, stepPiece as _, isFinished as k, isLaunched as T, wobbleOf as j, opacityOf as L } from "./confettiPhysics.js";
|
|
4
|
+
const P = [
|
|
5
|
+
"var(--malachite-accent-background, rgb(0, 175, 102))",
|
|
6
|
+
"var(--malachite-accent-background, rgb(0, 175, 102))",
|
|
7
|
+
"var(--malachite-accent-foreground, rgb(2, 122, 66))",
|
|
8
|
+
"var(--malachite-tag-primary-foreground, rgb(37, 130, 234))",
|
|
9
|
+
"var(--malachite-tag-assistant-foreground, rgb(110, 86, 207))"
|
|
10
|
+
], M = "\0", D = 0.72, K = 1 / 30, N = () => typeof window > "u" || typeof window.matchMedia != "function" ? !0 : window.matchMedia("(prefers-reduced-motion: reduce)").matches, q = (o, u) => u.map((i) => {
|
|
11
|
+
o.style.color = i;
|
|
12
|
+
const r = getComputedStyle(o).color || i, a = r.match(/rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/), s = a ? `rgb(${a.slice(1, 4).map((l) => Math.round(Number(l) * D)).join(", ")})` : r;
|
|
13
|
+
return { front: r, back: s };
|
|
14
|
+
}), H = ({
|
|
15
|
+
count: o = 150,
|
|
16
|
+
colors: u = P,
|
|
17
|
+
className: i = ""
|
|
13
18
|
}) => {
|
|
14
|
-
const
|
|
15
|
-
return
|
|
16
|
-
const a =
|
|
17
|
-
if (!
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
],
|
|
32
|
-
{
|
|
33
|
-
duration: 2600 + e * 17 % 1600,
|
|
34
|
-
delay: e * 11 % 500,
|
|
35
|
-
easing: "cubic-bezier(0.2, 0.6, 0.4, 1)",
|
|
36
|
-
fill: "forwards"
|
|
37
|
-
}
|
|
38
|
-
), t;
|
|
39
|
-
});
|
|
40
|
-
return () => {
|
|
41
|
-
for (const c of m) c.remove();
|
|
19
|
+
const r = m(null), a = m(null), s = m(null), l = u.join(M);
|
|
20
|
+
return S(() => {
|
|
21
|
+
const g = r.current, n = a.current, p = s.current;
|
|
22
|
+
if (!g || !n || !p || N()) return;
|
|
23
|
+
const e = n.getContext("2d");
|
|
24
|
+
if (!e) return;
|
|
25
|
+
const w = q(p, l.split(M)), b = g.getBoundingClientRect(), d = { width: b.width, height: b.height }, h = window.devicePixelRatio || 1;
|
|
26
|
+
n.width = Math.round(d.width * h), n.height = Math.round(d.height * h);
|
|
27
|
+
const f = F(o, w.length, d), c = { frame: 0, last: performance.now() }, v = (R) => {
|
|
28
|
+
const E = Math.min((R - c.last) / 1e3, K);
|
|
29
|
+
c.last = R, e.setTransform(1, 0, 0, 1, 0, 0), e.clearRect(0, 0, n.width, n.height);
|
|
30
|
+
const y = f.filter((t) => (_(t, E), !k(t, d)));
|
|
31
|
+
for (const t of y.filter(T)) {
|
|
32
|
+
const A = Math.cos(t.tilt), x = w[t.colorIndex];
|
|
33
|
+
e.setTransform(h, 0, 0, h, 0, 0), e.translate(t.x + j(t), t.y), e.rotate(t.rotation), e.scale(1, A), e.globalAlpha = L(t), e.fillStyle = A >= 0 ? x.front : x.back, e.fillRect(-t.width / 2, -t.height / 2, t.width, t.height);
|
|
34
|
+
}
|
|
35
|
+
f.splice(0, f.length, ...y), f.length > 0 && (c.frame = requestAnimationFrame(v));
|
|
42
36
|
};
|
|
43
|
-
|
|
37
|
+
return c.frame = requestAnimationFrame(v), () => {
|
|
38
|
+
cancelAnimationFrame(c.frame), e.setTransform(1, 0, 0, 1, 0, 0), e.clearRect(0, 0, n.width, n.height);
|
|
39
|
+
};
|
|
40
|
+
}, [o, l]), /* @__PURE__ */ O(
|
|
44
41
|
"div",
|
|
45
42
|
{
|
|
46
|
-
ref:
|
|
43
|
+
ref: r,
|
|
47
44
|
"aria-hidden": !0,
|
|
48
|
-
className: `pointer-events-none fixed inset-0 overflow-hidden z-50 ${
|
|
45
|
+
className: `pointer-events-none fixed inset-0 overflow-hidden z-50 ${i}`,
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ C("canvas", { ref: a, style: { width: "100%", height: "100%", display: "block" } }),
|
|
48
|
+
/* @__PURE__ */ C("span", { ref: s, style: { display: "none" } })
|
|
49
|
+
]
|
|
49
50
|
}
|
|
50
51
|
);
|
|
51
52
|
};
|
|
52
53
|
export {
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
H as Confetti,
|
|
55
|
+
H as default
|
|
55
56
|
};
|
|
56
57
|
//# sourceMappingURL=Confetti.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Confetti.js","sources":["../../src/components/Confetti.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\n\n// Theme tokens
|
|
1
|
+
{"version":3,"file":"Confetti.js","sources":["../../src/components/Confetti.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport {\n type ConfettiViewport,\n createPieces,\n isFinished,\n isLaunched,\n opacityOf,\n stepPiece,\n wobbleOf,\n} from './confettiPhysics';\n\n// Theme tokens, resolved in the component's own subtree so they follow light and dark. Green\n// leads (listed twice), with the brand's blue and purple; no status colours, which would read\n// as a warning in the middle of a celebration.\nconst DEFAULT_COLORS = [\n 'var(--malachite-accent-background, rgb(0, 175, 102))',\n 'var(--malachite-accent-background, rgb(0, 175, 102))',\n 'var(--malachite-accent-foreground, rgb(2, 122, 66))',\n 'var(--malachite-tag-primary-foreground, rgb(37, 130, 234))',\n 'var(--malachite-tag-assistant-foreground, rgb(110, 86, 207))',\n];\n\n/** Joins the palette into a content key; NUL cannot occur in a CSS colour value. */\nconst COLORS_KEY_SEPARATOR = '\\u0000';\n\n// The face turned away from the viewer is drawn this much darker, so a tumbling piece flashes.\nconst BACK_FACE_SHADE = 0.72;\n// A frame after a stall (a background tab) is stepped as this much time at most, so pieces do\n// not teleport.\nconst MAX_FRAME_SECONDS = 1 / 30;\n\n/**\n * `window.matchMedia` is absent under SSR and in older test environments. When it cannot\n * be consulted, assume reduced motion — skipping a decorative burst is the safe default.\n */\nconst prefersReducedMotion = (): boolean => {\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {\n return true;\n }\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n};\n\ninterface ResolvedColor {\n front: string;\n back: string;\n}\n\n// A canvas cannot read `var()`, so each colour is resolved through a probe in this subtree,\n// where the theme's custom properties apply.\nconst resolveColors = (probe: HTMLElement, palette: string[]): ResolvedColor[] =>\n palette.map((color) => {\n probe.style.color = color;\n const front = getComputedStyle(probe).color || color;\n const channels = front.match(/rgba?\\(\\s*([\\d.]+)[\\s,]+([\\d.]+)[\\s,]+([\\d.]+)/);\n const back = channels\n ? `rgb(${channels\n .slice(1, 4)\n .map((channel) => Math.round(Number(channel) * BACK_FACE_SHADE))\n .join(', ')})`\n : front;\n return { front, back };\n });\n\nexport interface ConfettiProps {\n /** Number of confetti pieces, split between the two cannons. */\n count?: number;\n /** Colors picked at random across the pieces; list one twice to weight it. */\n colors?: string[];\n className?: string;\n}\n\n// A burst from two cannons at the bottom corners, drawn on one canvas: the pieces are thrown up\n// against gravity and air drag, then flutter down, tumbling, and fade. Fires once on mount and\n// skips entirely under prefers-reduced-motion; it is aria-hidden decoration carrying nothing.\nconst Confetti: React.FC<ConfettiProps> = ({\n count = 150,\n colors = DEFAULT_COLORS,\n className = '',\n}) => {\n const ref = useRef<HTMLDivElement>(null);\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const probeRef = useRef<HTMLSpanElement>(null);\n\n // Keyed on the palette's contents, not the array's identity: an inline\n // `colors={['red', 'blue']}` is a new array every render and would re-fire the burst.\n const colorsKey = colors.join(COLORS_KEY_SEPARATOR);\n\n useEffect(() => {\n const container = ref.current;\n const canvas = canvasRef.current;\n const probe = probeRef.current;\n if (!container || !canvas || !probe || prefersReducedMotion()) return;\n const context = canvas.getContext('2d');\n if (!context) return;\n\n const palette = resolveColors(probe, colorsKey.split(COLORS_KEY_SEPARATOR));\n const bounds = container.getBoundingClientRect();\n const viewport: ConfettiViewport = { width: bounds.width, height: bounds.height };\n const pixelRatio = window.devicePixelRatio || 1;\n canvas.width = Math.round(viewport.width * pixelRatio);\n canvas.height = Math.round(viewport.height * pixelRatio);\n\n const pieces = createPieces(count, palette.length, viewport);\n const state = { frame: 0, last: performance.now() };\n\n const draw = (now: number): void => {\n const seconds = Math.min((now - state.last) / 1000, MAX_FRAME_SECONDS);\n state.last = now;\n context.setTransform(1, 0, 0, 1, 0, 0);\n context.clearRect(0, 0, canvas.width, canvas.height);\n\n const live = pieces.filter((piece) => {\n stepPiece(piece, seconds);\n return !isFinished(piece, viewport);\n });\n for (const piece of live.filter(isLaunched)) {\n const turn = Math.cos(piece.tilt);\n const color = palette[piece.colorIndex];\n context.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);\n context.translate(piece.x + wobbleOf(piece), piece.y);\n context.rotate(piece.rotation);\n context.scale(1, turn);\n context.globalAlpha = opacityOf(piece);\n context.fillStyle = turn >= 0 ? color.front : color.back;\n context.fillRect(-piece.width / 2, -piece.height / 2, piece.width, piece.height);\n }\n\n pieces.splice(0, pieces.length, ...live);\n if (pieces.length > 0) {\n state.frame = requestAnimationFrame(draw);\n }\n };\n state.frame = requestAnimationFrame(draw);\n\n return () => {\n cancelAnimationFrame(state.frame);\n context.setTransform(1, 0, 0, 1, 0, 0);\n context.clearRect(0, 0, canvas.width, canvas.height);\n };\n }, [count, colorsKey]);\n\n return (\n <div\n ref={ref}\n aria-hidden\n className={`pointer-events-none fixed inset-0 overflow-hidden z-50 ${className}`}\n >\n <canvas ref={canvasRef} style={{ width: '100%', height: '100%', display: 'block' }} />\n <span ref={probeRef} style={{ display: 'none' }} />\n </div>\n );\n};\n\nexport default Confetti;\nexport { Confetti };\n"],"names":["DEFAULT_COLORS","COLORS_KEY_SEPARATOR","BACK_FACE_SHADE","MAX_FRAME_SECONDS","prefersReducedMotion","resolveColors","probe","palette","color","front","channels","back","channel","Confetti","count","colors","className","ref","useRef","canvasRef","probeRef","colorsKey","useEffect","container","canvas","context","bounds","viewport","pixelRatio","pieces","createPieces","state","draw","now","seconds","live","piece","stepPiece","isFinished","isLaunched","turn","wobbleOf","opacityOf","jsxs","jsx"],"mappings":";;;AAcA,MAAMA,IAAiB;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,GA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