@stackone/malachite 2.88.3 → 2.89.1
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/Button.js +35 -33
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Table/Table.js +557 -560
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/Table/TablePagination.js +100 -181
- package/dist/components/Table/TablePagination.js.map +1 -1
- package/dist/components/Table/paginationPlacement.js +15 -0
- package/dist/components/Table/paginationPlacement.js.map +1 -0
- package/dist/components/Table/useFillHeight.js +53 -0
- package/dist/components/Table/useFillHeight.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartLegend.js +5 -16
- package/dist/components/TimeBarChart/TimeBarChartLegend.js.map +1 -1
- package/dist/components/TimeBarChart/TimeBarChartSwatch.js +21 -0
- package/dist/components/TimeBarChart/TimeBarChartSwatch.js.map +1 -0
- package/dist/components/UserIdentity.js +19 -0
- package/dist/components/UserIdentity.js.map +1 -0
- package/dist/index.d.ts +25 -1
- package/dist/index.js +482 -478
- package/dist/index.js.map +1 -1
- package/dist/tailwind.css.js +1 -1
- package/package.json +1 -1
package/COMPONENTS.md
CHANGED
|
@@ -99,7 +99,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
99
99
|
|
|
100
100
|
## Buttons & actions
|
|
101
101
|
|
|
102
|
-
- **`Button`** — Primary button. Variants: `filled`, `outline`, `surface` (outline's geometry on a ground of its own, for a control sitting on a tinted surface), `assistant` (the violet the assistant is named in — provenance, not a severity: it says who is being asked, not that anything is wrong), `destructive`, `success`, `warning`, `error`, `ghost`, `row-outline` (`ghost` until the `Surface.Row` whose `trailing` slot it sits in is hovered or holds focus, or its menu is open, then `outline`; always `outline` on a touch screen — a row control that stays quiet until its row is in play, in CSS alone), `quiet` (text only in the accent colour, for a secondary action such as Reset beside a primary one — accent, not success, because it is something to press rather than a status), `muted` (a recessed grey with secondary text, for a control whose subject is switched off, such as an account set to Not allowed; it stays clickable), `no-style`. Supports `flush` (pulls a borderless button out by its padding so its label lines up with the text around it), `iconOnly`, `loading`, `tooltip`. `leading` puts something that is not an icon, such as an avatar, before the label at its own size; `contentAlign="start"` starts the label at the leading edge and pins an end `icon` to the far edge, which with `flexGrow` makes a full-width switcher trigger — a project pill whose width comes from its container (e.g. a box `SIDEBAR_POPOVER_WIDTH_PX` wide, so it lines up with the `Sidebar.Panel` it opens). _Key props:_ `variant`, `size`, `icon`, `iconPosition`, `leading`, `contentAlign` (`center` | `start`), `flexGrow` (fills the container), `width` (`auto` | `wide` — a 120px floor for a panel's or dialog's primary action), `iconOnly`, `loading`, `disabled`, `fill`, `tooltip`.
|
|
102
|
+
- **`Button`** — Primary button. Variants: `filled`, `outline`, `surface` (outline's geometry on a ground of its own, for a control sitting on a tinted surface), `assistant` (the violet the assistant is named in — provenance, not a severity: it says who is being asked, not that anything is wrong), `destructive`, `success`, `warning`, `error`, `ghost`, `row-outline` (`ghost` until the `Surface.Row` whose `trailing` slot it sits in is hovered or holds focus, or its menu is open, then `outline`; always `outline` on a touch screen — a row control that stays quiet until its row is in play, in CSS alone), `quiet` (text only in the accent colour, for a secondary action such as Reset beside a primary one — accent, not success, because it is something to press rather than a status), `muted` (a recessed grey with secondary text, for a control whose subject is switched off, such as an account set to Not allowed; it stays clickable), `no-style`. Supports `flush` (pulls a borderless button out by its padding so its label lines up with the text around it), `iconOnly`, `loading`, `tooltip`. `leading` puts something that is not an icon, such as an avatar, before the label at its own size; `contentAlign="start"` starts the label at the leading edge and pins an end `icon` to the far edge, which with `flexGrow` makes a full-width switcher trigger — a project pill whose width comes from its container (e.g. a box `SIDEBAR_POPOVER_WIDTH_PX` wide, so it lines up with the `Sidebar.Panel` it opens). `type` is `button` unless set, so a Button in a form submits it only as `type="submit"`. _Key props:_ `variant`, `size`, `icon`, `iconPosition`, `leading`, `contentAlign` (`center` | `start`), `flexGrow` (fills the container), `width` (`auto` | `wide` — a 120px floor for a panel's or dialog's primary action), `iconOnly`, `loading`, `disabled`, `fill`, `tooltip`.
|
|
103
103
|
- **`SplitButton`** — One pill made of a primary action and a trailing menu trigger, sharing `Button`'s chrome: for an action with a default and a choice behind it, such as authorizing on every connected app or on one. The two segments are two real buttons, each with its own hover, active and keyboard focus, separated by a translucent seam that reads on every variant's ground; `disabled` and `loading` take both out together. The trigger shows a chevron pointing down while closed and up while `menuOpen`, which also sets `aria-expanded`, and is named by `menuLabel` since it shows no text. `trailing` sits after the label at its own size, for an `AvatarGroup` of what the action reaches. To open a `Popover` from the trigger, pass `menuTrigger`: it hands the segment to the Popover as its `trigger`, so the main segment stays a plain action rather than toggling the menu too. The menu itself is composed by the consumer from `Popover` and `Surface.Row`. _Key props:_ `variant` (every `Button` variant, default `filled`), `size` (default `medium`), `children`, `leading`, `trailing`, `onClick`, `type`, `loading`, `disabled`, `flexGrow`, `menuLabel`, `menuOpen`, `onMenuClick`, `menuIcon`, `menuHasPopup`, `menuRef`, `menuTrigger` (`(segment) => node`), `ref`, `className`, `style`.
|
|
104
104
|
- **`CloseButton`** — The bare X that dismisses a screen, panel or wizard: secondary at rest, primary on hover and keyboard focus, with no box or background at either. Use it instead of a `ghost` `Button` (which draws a hover box) or `no-style` (which has no disabled look). `surface="inverse"` is for a panel that stays dark in every theme, such as `SplitScreenLayout`’s, and reads the `closeButton` theme tokens. `loading` swaps the X for a spinner and sets `aria-busy`. Disabled and loading both use `aria-disabled` rather than `disabled`, so they ignore clicks but stay focusable and can still trigger a `Tooltip` explaining why. Named "Close" unless `aria-label` says otherwise. _Key props:_ `onClick`, `aria-label`, `size` (`small` 24px | `medium` 32px, 12px glyph), `surface` (`default` | `inverse`), `disabled`, `loading`.
|
|
105
105
|
- **`AccessPills`** — Three toggle pills, R / W / D, saying which effects an account grants (Read, Write, Delete) — on a linked-account row and in the header above the rows. Each pill is a button with `aria-pressed`, named in full by its state (`Write: some actions off`), and a tooltip on hover and focus spells that name out, since a letter alone is cryptic. On paints the effect’s tint (Read in `Tag`’s primary, Write in warning, Delete in error, the colours the dashboard already gives these effects), `"mixed"` (some, not all, of its actions on) an empty pill with a dashed border, off a neutral one. The colours come from the theme and there is no colour prop. It reports only which pill was pressed through `onToggle`: any cascade between effects (Read off turning Write and Delete off, say) and what pressing a mixed pill means belong to the caller. A pill in `disabled` stays focusable with `aria-disabled`, ignores clicks and keys, and its tooltip shows `disabledReason` instead, which is also its accessible description. `size="dense"` draws 24×20 pills in place of 26×24, for a narrow screen. _Key props:_ `value` (`{ read, write, delete }`, each `true` | `false` | `"mixed"`), `onToggle(effect)`, `disabled` (per effect), `disabledReason` (per effect, or one string), `size` (`default` | `dense`), `aria-label`, `aria-labelledby`.
|
|
@@ -112,11 +112,13 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
112
112
|
|
|
113
113
|
- **`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`.
|
|
114
114
|
- **`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`.
|
|
115
|
-
- **`
|
|
115
|
+
- **`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 always matches the bars, the legend and the tooltip, and follows the theme with them. Decorative: the label beside it does the naming. _Key props:_ `tone` (`TimeBarChartTone`).
|
|
116
|
+
- **`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).
|
|
116
117
|
- **`Statistic`** — Displays a statistic value with a label; primary/secondary sizes. _Key props:_ `StatisticValueSize`.
|
|
117
118
|
- **`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"`.
|
|
118
119
|
- **`ZoomableImage`** — An image shown inline as a button that enlarges it, for a screenshot too detailed to read at its inline size. The thumbnail is shown at its own width up to the width of its container, never stretched, and stops at 240px tall, cropping a tall image to its top. The enlarged image sits on the scrim with no card, as large as the window allows at its own aspect ratio, up to its natural size, and a click anywhere or ESC closes it. The thumbnail is named `Enlarge image: <alt>` and the dialog is named by `title`, or by `alt` when `title` is missing or empty, so `alt` must be non-empty. `onError` reports a thumbnail that failed to load, so the caller can leave it out rather than show a broken image. The thumbnail loads lazily, so for one below the fold that report comes once it nears the viewport, not on render. _Key props:_ `src`, `alt`, `title`, `onError`.
|
|
119
120
|
- **`AvatarGroup`** — A horizontal stack of overlapping `Avatar`s, first on top, for a "these apps" cluster beside a label or in a button. The gap between tiles is cut out of the tile beneath rather than painted, so it shows whatever ground the group sits on. Past `max` the rest fold into a `+N` tile. One image to assistive tech, named by its items joined with ", " unless `aria-label` says otherwise. _Key props:_ `items` (`{src?, name, fallback?}[]`), `size` (px, default 24), `shape` (`square` | `circle`), `max` (default 4), `overlap` (fraction of `size`, 0 to 0.5, default 0.3), `aria-label`, `className`, `style`.
|
|
121
|
+
- **`UserIdentity`** — A person as a list or table shows them: their `Avatar`, their name, and their email beneath in secondary text. Without a name the email takes the first line and there is no second line; without either the line reads `-`. Both lines keep to one line and ellipsise in a narrow cell. The avatar is hidden from assistive tech, as the text already names the person. _Key props:_ `name`, `email`, `src`, `size` (`small` | `medium`).
|
|
120
122
|
- **`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`.
|
|
121
123
|
- **`ConnectionHeader`** — Two tilted logo tiles (from → to) showing a connection between apps. _Key props:_ `from`, `to` (`ConnectionEndpoint`: `icon`, `label`, `background`).
|
|
122
124
|
- **`CodeBlock`** — Syntax-styled code block. _Key props:_ `code`.
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { jsx as t, jsxs as m, Fragment as p } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { ButtonSpinner as
|
|
4
|
-
import
|
|
2
|
+
import { forwardRef as X, useRef as d, useMemo as Y, useLayoutEffect as Z } from "react";
|
|
3
|
+
import { ButtonSpinner as P } from "./ButtonSpinner.js";
|
|
4
|
+
import z from "./Tooltip.js";
|
|
5
5
|
import { getDeepActiveNode as _ } from "./activeElement.js";
|
|
6
|
-
import { getIconOnlySizeClasses as
|
|
7
|
-
import { getSizeClasses as
|
|
8
|
-
import { composeRefs as
|
|
9
|
-
import { resolveRel as
|
|
10
|
-
const
|
|
6
|
+
import { getIconOnlySizeClasses as ee, getIconSizeClass as te } from "./buttonSizing.js";
|
|
7
|
+
import { getSizeClasses as re, getVariantClasses as se, getIconGapClass as H, getRadiusClass as ne, getDefaultRadiusClass as le } from "./buttonStyles.js";
|
|
8
|
+
import { composeRefs as ae } from "./composeRefs.js";
|
|
9
|
+
import { resolveRel as ce } from "./linkRel.js";
|
|
10
|
+
const oe = "-mx-[calc(var(--btn-px)+1px)]", ie = "-mx-[var(--btn-px)]", ue = (l) => {
|
|
11
11
|
try {
|
|
12
12
|
return l.matches(":focus-visible");
|
|
13
13
|
} catch {
|
|
14
14
|
return !0;
|
|
15
15
|
}
|
|
16
|
-
}, fe =
|
|
16
|
+
}, fe = X(
|
|
17
17
|
({
|
|
18
18
|
variant: l,
|
|
19
19
|
size: r = "large",
|
|
@@ -27,9 +27,9 @@ const ce = "-mx-[calc(var(--btn-px)+1px)]", oe = "-mx-[var(--btn-px)]", ie = (l)
|
|
|
27
27
|
flexGrow: x = !1,
|
|
28
28
|
width: V = "auto",
|
|
29
29
|
fill: q = !1,
|
|
30
|
-
tooltip:
|
|
30
|
+
tooltip: b,
|
|
31
31
|
tooltipPlacement: G = "top",
|
|
32
|
-
iconOnly:
|
|
32
|
+
iconOnly: g = !1,
|
|
33
33
|
flush: W = !1,
|
|
34
34
|
children: s,
|
|
35
35
|
className: J = "",
|
|
@@ -38,14 +38,15 @@ const ce = "-mx-[calc(var(--btn-px)+1px)]", oe = "-mx-[var(--btn-px)]", ie = (l)
|
|
|
38
38
|
rel: K,
|
|
39
39
|
onBlur: h,
|
|
40
40
|
onFocus: C,
|
|
41
|
+
type: O = "button",
|
|
41
42
|
...k
|
|
42
43
|
}, A) => {
|
|
43
|
-
const R = d(null), L =
|
|
44
|
-
() =>
|
|
44
|
+
const R = d(null), L = Y(
|
|
45
|
+
() => ae(A, R),
|
|
45
46
|
[A]
|
|
46
47
|
), o = d(!1), N = d(!1), S = d(0);
|
|
47
|
-
|
|
48
|
-
var
|
|
48
|
+
Z(() => {
|
|
49
|
+
var f;
|
|
49
50
|
if (a) {
|
|
50
51
|
N.current = o.current;
|
|
51
52
|
return;
|
|
@@ -54,27 +55,27 @@ const ce = "-mx-[calc(var(--btn-px)+1px)]", oe = "-mx-[var(--btn-px)]", ie = (l)
|
|
|
54
55
|
return;
|
|
55
56
|
N.current = !1;
|
|
56
57
|
const e = _();
|
|
57
|
-
(!e || e === document.body) && ((
|
|
58
|
+
(!e || e === document.body) && ((f = R.current) == null || f.focus({ preventScroll: !0 }), _() === R.current && (o.current = !0));
|
|
58
59
|
}, [a]);
|
|
59
60
|
const B = (e) => {
|
|
60
|
-
S.current += 1, o.current =
|
|
61
|
+
S.current += 1, o.current = ue(e.currentTarget), C == null || C(e);
|
|
61
62
|
}, F = (e) => {
|
|
62
|
-
const
|
|
63
|
+
const f = S.current;
|
|
63
64
|
queueMicrotask(() => {
|
|
64
|
-
S.current ===
|
|
65
|
+
S.current === f && (o.current = !1);
|
|
65
66
|
}), h == null || h(e);
|
|
66
|
-
},
|
|
67
|
+
}, Q = v ? ne(v) : le(r, g), n = T || a, M = U === "start", D = [
|
|
67
68
|
M ? "flex items-center justify-start text-left" : "flex items-center justify-center",
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
g ? `p-0 ${ee(r)}` : re(r),
|
|
70
|
+
se(l, Q),
|
|
70
71
|
x ? "w-full" : "",
|
|
71
72
|
V === "wide" ? "min-w-[120px]" : "",
|
|
72
73
|
q ? "max-w-full" : "",
|
|
73
74
|
n ? "cursor-not-allowed" : "",
|
|
74
|
-
|
|
75
|
-
W && !
|
|
75
|
+
b && n ? "pointer-events-none" : "",
|
|
76
|
+
W && !g ? l === "no-style" ? ie : oe : "",
|
|
76
77
|
J
|
|
77
|
-
].filter(Boolean).join(" "), i = M ? /* @__PURE__ */ t("span", { className: "flex min-w-0 flex-1 items-center", children: s }) : s,
|
|
78
|
+
].filter(Boolean).join(" "), i = M ? /* @__PURE__ */ t("span", { className: "flex min-w-0 flex-1 items-center", children: s }) : s, u = y ? /* @__PURE__ */ t(
|
|
78
79
|
"span",
|
|
79
80
|
{
|
|
80
81
|
className: s ? "btn-leading inline-flex shrink-0 items-center me-2" : "btn-leading inline-flex shrink-0 items-center",
|
|
@@ -83,13 +84,13 @@ const ce = "-mx-[calc(var(--btn-px)+1px)]", oe = "-mx-[var(--btn-px)]", ie = (l)
|
|
|
83
84
|
) : null, E = () => {
|
|
84
85
|
if (a)
|
|
85
86
|
return /* @__PURE__ */ m(p, { children: [
|
|
86
|
-
|
|
87
|
-
/* @__PURE__ */ t(
|
|
87
|
+
u,
|
|
88
|
+
/* @__PURE__ */ t(P, {}),
|
|
88
89
|
i
|
|
89
90
|
] });
|
|
90
|
-
const e = `inline-flex items-center shrink-0 ${
|
|
91
|
+
const e = `inline-flex items-center shrink-0 ${te(r)}`;
|
|
91
92
|
return c && w === "start" ? /* @__PURE__ */ m(p, { children: [
|
|
92
|
-
|
|
93
|
+
u,
|
|
93
94
|
/* @__PURE__ */ t(
|
|
94
95
|
"span",
|
|
95
96
|
{
|
|
@@ -99,7 +100,7 @@ const ce = "-mx-[calc(var(--btn-px)+1px)]", oe = "-mx-[var(--btn-px)]", ie = (l)
|
|
|
99
100
|
),
|
|
100
101
|
i
|
|
101
102
|
] }) : c && w === "end" ? /* @__PURE__ */ m(p, { children: [
|
|
102
|
-
|
|
103
|
+
u,
|
|
103
104
|
i,
|
|
104
105
|
/* @__PURE__ */ t(
|
|
105
106
|
"span",
|
|
@@ -109,7 +110,7 @@ const ce = "-mx-[calc(var(--btn-px)+1px)]", oe = "-mx-[var(--btn-px)]", ie = (l)
|
|
|
109
110
|
}
|
|
110
111
|
)
|
|
111
112
|
] }) : /* @__PURE__ */ m(p, { children: [
|
|
112
|
-
|
|
113
|
+
u,
|
|
113
114
|
i
|
|
114
115
|
] });
|
|
115
116
|
}, $ = I && !n ? /* @__PURE__ */ t(
|
|
@@ -118,7 +119,7 @@ const ce = "-mx-[calc(var(--btn-px)+1px)]", oe = "-mx-[var(--btn-px)]", ie = (l)
|
|
|
118
119
|
ref: L,
|
|
119
120
|
href: I,
|
|
120
121
|
target: j,
|
|
121
|
-
rel:
|
|
122
|
+
rel: ce(K, j),
|
|
122
123
|
className: D,
|
|
123
124
|
onFocus: B,
|
|
124
125
|
onBlur: F,
|
|
@@ -129,6 +130,7 @@ const ce = "-mx-[calc(var(--btn-px)+1px)]", oe = "-mx-[var(--btn-px)]", ie = (l)
|
|
|
129
130
|
"button",
|
|
130
131
|
{
|
|
131
132
|
ref: L,
|
|
133
|
+
type: O,
|
|
132
134
|
disabled: n,
|
|
133
135
|
className: D,
|
|
134
136
|
onFocus: B,
|
|
@@ -137,7 +139,7 @@ const ce = "-mx-[calc(var(--btn-px)+1px)]", oe = "-mx-[var(--btn-px)]", ie = (l)
|
|
|
137
139
|
children: E()
|
|
138
140
|
}
|
|
139
141
|
);
|
|
140
|
-
return
|
|
142
|
+
return b ? /* @__PURE__ */ t(z, { text: b, placement: G, fill: x, children: n ? /* @__PURE__ */ t("span", { className: `inline-flex cursor-not-allowed${x ? " w-full" : ""}`, children: $ }) : $ }) : $;
|
|
141
143
|
}
|
|
142
144
|
);
|
|
143
145
|
fe.displayName = "Button";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sources":["../../src/components/Button.tsx"],"sourcesContent":["import React, { forwardRef, useLayoutEffect, useMemo, useRef } from 'react';\nimport ButtonSpinner from './ButtonSpinner';\nimport Tooltip from './Tooltip';\nimport { getDeepActiveNode } from './activeElement';\nimport { getIconOnlySizeClasses, getIconSizeClass } from './buttonSizing';\nimport {\n getDefaultRadiusClass,\n getIconGapClass,\n getRadiusClass,\n getSizeClasses,\n getVariantClasses,\n} from './buttonStyles';\nimport { composeRefs } from './composeRefs';\nimport { resolveRel } from './linkRel';\n\n// Button variant types matching the old component\nexport type ButtonVariant =\n | 'filled'\n | 'outline'\n /**\n * `outline`'s geometry on a ground of its own. For a button sitting on a tinted or\n * patterned surface, where `outline`'s transparent background lets that surface through\n * and the control stops reading as a button.\n */\n | 'surface'\n /**\n * The violet the assistant is named in elsewhere — for a control that hands work to it, or\n * acts on what it produced. Provenance, not a severity: it says who is being asked, not\n * that anything is wrong.\n */\n | 'assistant'\n | 'destructive'\n | 'success'\n | 'warning'\n | 'error'\n | 'ghost'\n /** `ghost` until its `Surface.Row` is hovered or focused, or its menu opens. For `trailing` only. */\n | 'row-outline'\n /** Text only, in the accent colour, for a secondary action beside a primary one. */\n | 'quiet'\n /**\n * A recessed grey with secondary text, for a control whose subject is switched off, such as\n * an account set to Not allowed. It stays clickable: `disabled` is for a control that is not.\n */\n | 'muted'\n | 'no-style';\n\nexport type ButtonSize = 'xsmall' | 'small' | 'medium' | 'large';\n\nexport type ButtonRadius = 'md' | 'lg' | 'xl';\n\ninterface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n variant: ButtonVariant;\n size?: ButtonSize;\n radius?: ButtonRadius;\n loading?: boolean;\n disabled?: boolean;\n icon?: React.ReactNode;\n iconPosition?: 'start' | 'end';\n /** Before the label at its own size, never squeezed (an avatar); pairs with an end `icon`. */\n leading?: React.ReactNode;\n /** `start` aligns the label to the leading edge and pins an end `icon` to the far edge. */\n contentAlign?: 'center' | 'start';\n /** Fills the container's width. */\n flexGrow?: boolean;\n /** `wide` holds a 120px floor for a primary action. */\n width?: 'auto' | 'wide';\n fill?: boolean;\n tooltip?: string;\n tooltipPlacement?: 'top' | 'bottom' | 'left' | 'right';\n iconOnly?: boolean;\n /** Pulls a borderless button out by its own padding, so its label lines up with the text around it. */\n flush?: boolean;\n children?: React.ReactNode;\n onClick?: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement>;\n /** Renders the button as a real anchor, so a link action is never an <a> nested in a <button>. */\n href?: string;\n target?: React.HTMLAttributeAnchorTarget;\n rel?: string;\n}\n\n// The 1px is the transparent border, which `no-style` drops.\nconst FLUSH_MARGIN = '-mx-[calc(var(--btn-px)+1px)]';\nconst FLUSH_MARGIN_BORDERLESS = '-mx-[var(--btn-px)]';\n\n// Only keyboard focus is handed back: a mouse user never asked for focus to stay there.\nconst isFocusVisible = (element: Element) => {\n try {\n return element.matches(':focus-visible');\n } catch {\n return true;\n }\n};\n\nexport const Button = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProps>(\n (\n {\n variant,\n size = 'large',\n radius,\n loading = false,\n disabled = false,\n icon,\n iconPosition = 'start',\n leading,\n contentAlign = 'center',\n flexGrow = false,\n width = 'auto',\n fill = false,\n tooltip,\n tooltipPlacement = 'top',\n iconOnly = false,\n flush = false,\n children,\n className = '',\n href,\n target,\n rel,\n onBlur,\n onFocus,\n ...props\n },\n ref,\n ) => {\n const elementRef = useRef<HTMLElement | null>(null);\n // Memoised: a fresh callback ref each render would detach and re-attach the consumer's.\n const composedRef = useMemo(\n () => composeRefs(ref as React.Ref<HTMLElement>, elementRef),\n [ref],\n );\n // Loading disables the button, or swaps the element (a tooltip wrapper, a link), and\n // either drops a keyboard user's focus to <body>. It is handed back when loading ends.\n const keyboardFocus = useRef(false);\n const refocusAfterLoading = useRef(false);\n // Counts focus events, so a blur's deferred clear can tell focus came back meanwhile.\n const focusCount = useRef(0);\n\n // A layout effect, so it reads `keyboardFocus` at commit: the blur that commit causes\n // only clears it from a microtask, after this has run.\n useLayoutEffect(() => {\n if (loading) {\n refocusAfterLoading.current = keyboardFocus.current;\n return;\n }\n if (!refocusAfterLoading.current) {\n return;\n }\n refocusAfterLoading.current = false;\n const active = getDeepActiveNode();\n if (!active || active === document.body) {\n elementRef.current?.focus({ preventScroll: true });\n // Scripted focus from <body> need not match :focus-visible, yet it is still the\n // keyboard user's: the next send must hand it back too.\n if (getDeepActiveNode() === elementRef.current) {\n keyboardFocus.current = true;\n }\n }\n }, [loading]);\n\n const handleFocus = (event: React.FocusEvent<HTMLElement>) => {\n focusCount.current += 1;\n keyboardFocus.current = isFocusVisible(event.currentTarget);\n onFocus?.(event as React.FocusEvent<HTMLButtonElement>);\n };\n\n const handleBlur = (event: React.FocusEvent<HTMLElement>) => {\n // A focus trap can put focus straight back within this task; that focus wins.\n const blurredAfter = focusCount.current;\n queueMicrotask(() => {\n if (focusCount.current === blurredAfter) {\n keyboardFocus.current = false;\n }\n });\n onBlur?.(event as React.FocusEvent<HTMLButtonElement>);\n };\n\n const radiusClass = radius ? getRadiusClass(radius) : getDefaultRadiusClass(size, iconOnly);\n const isInactive = disabled || loading;\n const alignStart = contentAlign === 'start';\n const baseClasses = [\n alignStart\n ? 'flex items-center justify-start text-left'\n : 'flex items-center justify-center',\n iconOnly ? `p-0 ${getIconOnlySizeClasses(size)}` : getSizeClasses(size),\n getVariantClasses(variant, radiusClass),\n flexGrow ? 'w-full' : '',\n width === 'wide' ? 'min-w-[120px]' : '',\n fill ? 'max-w-full' : '',\n isInactive ? 'cursor-not-allowed' : '',\n tooltip && isInactive ? 'pointer-events-none' : '',\n flush && !iconOnly\n ? variant === 'no-style'\n ? FLUSH_MARGIN_BORDERLESS\n : FLUSH_MARGIN\n : '',\n className,\n ]\n .filter(Boolean)\n .join(' ');\n\n const label = alignStart ? (\n <span className=\"flex min-w-0 flex-1 items-center\">{children}</span>\n ) : (\n children\n );\n\n const leadingSlot = leading ? (\n <span\n className={\n children\n ? 'btn-leading inline-flex shrink-0 items-center me-2'\n : 'btn-leading inline-flex shrink-0 items-center'\n }\n >\n {leading}\n </span>\n ) : null;\n\n const renderContent = () => {\n if (loading) {\n return (\n <>\n {leadingSlot}\n <ButtonSpinner />\n {label}\n </>\n );\n }\n\n const iconWrapperClasses = `inline-flex items-center shrink-0 ${getIconSizeClass(size)}`;\n\n if (icon && iconPosition === 'start') {\n return (\n <>\n {leadingSlot}\n <span\n className={`${iconWrapperClasses}${children ? ` ${getIconGapClass(size, 'start')}` : ''}`}\n >\n {icon}\n </span>\n {label}\n </>\n );\n }\n\n if (icon && iconPosition === 'end') {\n return (\n <>\n {leadingSlot}\n {label}\n <span\n className={`${iconWrapperClasses}${children ? ` ${getIconGapClass(size, 'end')}` : ''}`}\n >\n {icon}\n </span>\n </>\n );\n }\n\n return (\n <>\n {leadingSlot}\n {label}\n </>\n );\n };\n\n // An anchor cannot be disabled, so an inactive link still renders as a <button>.\n const button =\n href && !isInactive ? (\n <a\n ref={composedRef}\n href={href}\n target={target}\n rel={resolveRel(rel, target)}\n className={baseClasses}\n onFocus={handleFocus}\n onBlur={handleBlur}\n {...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>)}\n >\n {renderContent()}\n </a>\n ) : (\n <button\n ref={composedRef}\n disabled={isInactive}\n className={baseClasses}\n onFocus={handleFocus}\n onBlur={handleBlur}\n {...props}\n >\n {renderContent()}\n </button>\n );\n\n if (tooltip) {\n const trigger = isInactive ? (\n <span className={`inline-flex cursor-not-allowed${flexGrow ? ' w-full' : ''}`}>\n {button}\n </span>\n ) : (\n button\n );\n return (\n <Tooltip text={tooltip} placement={tooltipPlacement} fill={flexGrow}>\n {trigger}\n </Tooltip>\n );\n }\n\n return button;\n },\n);\n\nButton.displayName = 'Button';\n\nexport default Button;\n"],"names":["FLUSH_MARGIN","FLUSH_MARGIN_BORDERLESS","isFocusVisible","element","Button","forwardRef","variant","size","radius","loading","disabled","icon","iconPosition","leading","contentAlign","flexGrow","width","fill","tooltip","tooltipPlacement","iconOnly","flush","children","className","href","target","rel","onBlur","onFocus","props","ref","elementRef","useRef","composedRef","useMemo","composeRefs","keyboardFocus","refocusAfterLoading","focusCount","useLayoutEffect","active","getDeepActiveNode","_a","handleFocus","event","handleBlur","blurredAfter","radiusClass","getRadiusClass","getDefaultRadiusClass","isInactive","alignStart","baseClasses","getIconOnlySizeClasses","getSizeClasses","getVariantClasses","label","jsx","leadingSlot","renderContent","jsxs","Fragment","ButtonSpinner","iconWrapperClasses","getIconSizeClass","getIconGapClass","button","resolveRel","Tooltip"],"mappings":";;;;;;;;;AAkFA,MAAMA,KAAe,iCACfC,KAA0B,uBAG1BC,KAAiB,CAACC,MAAqB;AACzC,MAAI;AACA,WAAOA,EAAQ,QAAQ,gBAAgB;AAAA,EAC3C,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ,GAEaC,KAASC;AAAA,EAClB,CACI;AAAA,IACI,SAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,QAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,UAAAC,IAAW;AAAA,IACX,MAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,SAAAC;AAAA,IACA,cAAAC,IAAe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C;AAAA,MAAA,GACL,IAIJ7C,KAAQC,MAAiB,QAErB,gBAAAgD,EAAAC,GAAA,EACK,UAAA;AAAA,QAAAH;AAAA,QACAF;AAAA,QACD,gBAAAC;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,WAAW,GAAGM,CAAkB,GAAGzC,IAAW,IAAI2C,EAAgB1D,GAAM,KAAK,CAAC,KAAK,EAAE;AAAA,YAEpF,UAAAI;AAAA,UAAA;AAAA,QAAA;AAAA,MACL,GACJ,IAKJ,gBAAAiD,EAAAC,GAAA,EACK,UAAA;AAAA,QAAAH;AAAA,QACAF;AAAA,MAAA,GACL;AAAA,IAER,GAGMU,IACF1C,KAAQ,CAAC0B,IACL,gBAAAO;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,KAAKxB;AAAA,QACL,MAAAT;AAAA,QACA,QAAAC;AAAA,QACA,KAAK0C,GAAWzC,GAAKD,CAAM;AAAA,QAC3B,WAAW2B;AAAA,QACX,SAAST;AAAA,QACT,QAAQE;AAAA,QACP,GAAIhB;AAAA,QAEJ,UAAA8B,EAAA;AAAA,MAAc;AAAA,IAAA,IAGnB,gBAAAF;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,KAAKxB;AAAA,QACL,UAAUiB;AAAA,QACV,WAAWE;AAAA,QACX,SAAST;AAAA,QACT,QAAQE;AAAA,QACP,GAAGhB;AAAA,QAEH,UAAA8B,EAAA;AAAA,MAAc;AAAA,IAAA;AAI3B,WAAIzC,IASI,gBAAAuC,EAACW,KAAQ,MAAMlD,GAAS,WAAWC,GAAkB,MAAMJ,GACtD,UATOmC,IACZ,gBAAAO,EAAC,QAAA,EAAK,WAAW,iCAAiC1C,IAAW,YAAY,EAAE,IACtE,UAAAmD,EAAA,CACL,IAEAA,EAIK,CACL,IAIDA;AAAA,EACX;AACJ;AAEA9D,GAAO,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Button.js","sources":["../../src/components/Button.tsx"],"sourcesContent":["import React, { forwardRef, useLayoutEffect, useMemo, useRef } from 'react';\nimport ButtonSpinner from './ButtonSpinner';\nimport Tooltip from './Tooltip';\nimport { getDeepActiveNode } from './activeElement';\nimport { getIconOnlySizeClasses, getIconSizeClass } from './buttonSizing';\nimport {\n getDefaultRadiusClass,\n getIconGapClass,\n getRadiusClass,\n getSizeClasses,\n getVariantClasses,\n} from './buttonStyles';\nimport { composeRefs } from './composeRefs';\nimport { resolveRel } from './linkRel';\n\n// Button variant types matching the old component\nexport type ButtonVariant =\n | 'filled'\n | 'outline'\n /**\n * `outline`'s geometry on a ground of its own. For a button sitting on a tinted or\n * patterned surface, where `outline`'s transparent background lets that surface through\n * and the control stops reading as a button.\n */\n | 'surface'\n /**\n * The violet the assistant is named in elsewhere — for a control that hands work to it, or\n * acts on what it produced. Provenance, not a severity: it says who is being asked, not\n * that anything is wrong.\n */\n | 'assistant'\n | 'destructive'\n | 'success'\n | 'warning'\n | 'error'\n | 'ghost'\n /** `ghost` until its `Surface.Row` is hovered or focused, or its menu opens. For `trailing` only. */\n | 'row-outline'\n /** Text only, in the accent colour, for a secondary action beside a primary one. */\n | 'quiet'\n /**\n * A recessed grey with secondary text, for a control whose subject is switched off, such as\n * an account set to Not allowed. It stays clickable: `disabled` is for a control that is not.\n */\n | 'muted'\n | 'no-style';\n\nexport type ButtonSize = 'xsmall' | 'small' | 'medium' | 'large';\n\nexport type ButtonRadius = 'md' | 'lg' | 'xl';\n\ninterface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n variant: ButtonVariant;\n size?: ButtonSize;\n radius?: ButtonRadius;\n loading?: boolean;\n disabled?: boolean;\n icon?: React.ReactNode;\n iconPosition?: 'start' | 'end';\n /** Before the label at its own size, never squeezed (an avatar); pairs with an end `icon`. */\n leading?: React.ReactNode;\n /** `start` aligns the label to the leading edge and pins an end `icon` to the far edge. */\n contentAlign?: 'center' | 'start';\n /** Fills the container's width. */\n flexGrow?: boolean;\n /** `wide` holds a 120px floor for a primary action. */\n width?: 'auto' | 'wide';\n fill?: boolean;\n tooltip?: string;\n tooltipPlacement?: 'top' | 'bottom' | 'left' | 'right';\n iconOnly?: boolean;\n /** Pulls a borderless button out by its own padding, so its label lines up with the text around it. */\n flush?: boolean;\n children?: React.ReactNode;\n onClick?: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement>;\n /** Renders the button as a real anchor, so a link action is never an <a> nested in a <button>. */\n href?: string;\n target?: React.HTMLAttributeAnchorTarget;\n rel?: string;\n}\n\n// The 1px is the transparent border, which `no-style` drops.\nconst FLUSH_MARGIN = '-mx-[calc(var(--btn-px)+1px)]';\nconst FLUSH_MARGIN_BORDERLESS = '-mx-[var(--btn-px)]';\n\n// Only keyboard focus is handed back: a mouse user never asked for focus to stay there.\nconst isFocusVisible = (element: Element) => {\n try {\n return element.matches(':focus-visible');\n } catch {\n return true;\n }\n};\n\nexport const Button = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProps>(\n (\n {\n variant,\n size = 'large',\n radius,\n loading = false,\n disabled = false,\n icon,\n iconPosition = 'start',\n leading,\n contentAlign = 'center',\n flexGrow = false,\n width = 'auto',\n fill = false,\n tooltip,\n tooltipPlacement = 'top',\n iconOnly = false,\n flush = false,\n children,\n className = '',\n href,\n target,\n rel,\n onBlur,\n onFocus,\n type = 'button',\n ...props\n },\n ref,\n ) => {\n const elementRef = useRef<HTMLElement | null>(null);\n // Memoised: a fresh callback ref each render would detach and re-attach the consumer's.\n const composedRef = useMemo(\n () => composeRefs(ref as React.Ref<HTMLElement>, elementRef),\n [ref],\n );\n // Loading disables the button, or swaps the element (a tooltip wrapper, a link), and\n // either drops a keyboard user's focus to <body>. It is handed back when loading ends.\n const keyboardFocus = useRef(false);\n const refocusAfterLoading = useRef(false);\n // Counts focus events, so a blur's deferred clear can tell focus came back meanwhile.\n const focusCount = useRef(0);\n\n // A layout effect, so it reads `keyboardFocus` at commit: the blur that commit causes\n // only clears it from a microtask, after this has run.\n useLayoutEffect(() => {\n if (loading) {\n refocusAfterLoading.current = keyboardFocus.current;\n return;\n }\n if (!refocusAfterLoading.current) {\n return;\n }\n refocusAfterLoading.current = false;\n const active = getDeepActiveNode();\n if (!active || active === document.body) {\n elementRef.current?.focus({ preventScroll: true });\n // Scripted focus from <body> need not match :focus-visible, yet it is still the\n // keyboard user's: the next send must hand it back too.\n if (getDeepActiveNode() === elementRef.current) {\n keyboardFocus.current = true;\n }\n }\n }, [loading]);\n\n const handleFocus = (event: React.FocusEvent<HTMLElement>) => {\n focusCount.current += 1;\n keyboardFocus.current = isFocusVisible(event.currentTarget);\n onFocus?.(event as React.FocusEvent<HTMLButtonElement>);\n };\n\n const handleBlur = (event: React.FocusEvent<HTMLElement>) => {\n // A focus trap can put focus straight back within this task; that focus wins.\n const blurredAfter = focusCount.current;\n queueMicrotask(() => {\n if (focusCount.current === blurredAfter) {\n keyboardFocus.current = false;\n }\n });\n onBlur?.(event as React.FocusEvent<HTMLButtonElement>);\n };\n\n const radiusClass = radius ? getRadiusClass(radius) : getDefaultRadiusClass(size, iconOnly);\n const isInactive = disabled || loading;\n const alignStart = contentAlign === 'start';\n const baseClasses = [\n alignStart\n ? 'flex items-center justify-start text-left'\n : 'flex items-center justify-center',\n iconOnly ? `p-0 ${getIconOnlySizeClasses(size)}` : getSizeClasses(size),\n getVariantClasses(variant, radiusClass),\n flexGrow ? 'w-full' : '',\n width === 'wide' ? 'min-w-[120px]' : '',\n fill ? 'max-w-full' : '',\n isInactive ? 'cursor-not-allowed' : '',\n tooltip && isInactive ? 'pointer-events-none' : '',\n flush && !iconOnly\n ? variant === 'no-style'\n ? FLUSH_MARGIN_BORDERLESS\n : FLUSH_MARGIN\n : '',\n className,\n ]\n .filter(Boolean)\n .join(' ');\n\n const label = alignStart ? (\n <span className=\"flex min-w-0 flex-1 items-center\">{children}</span>\n ) : (\n children\n );\n\n const leadingSlot = leading ? (\n <span\n className={\n children\n ? 'btn-leading inline-flex shrink-0 items-center me-2'\n : 'btn-leading inline-flex shrink-0 items-center'\n }\n >\n {leading}\n </span>\n ) : null;\n\n const renderContent = () => {\n if (loading) {\n return (\n <>\n {leadingSlot}\n <ButtonSpinner />\n {label}\n </>\n );\n }\n\n const iconWrapperClasses = `inline-flex items-center shrink-0 ${getIconSizeClass(size)}`;\n\n if (icon && iconPosition === 'start') {\n return (\n <>\n {leadingSlot}\n <span\n className={`${iconWrapperClasses}${children ? ` ${getIconGapClass(size, 'start')}` : ''}`}\n >\n {icon}\n </span>\n {label}\n </>\n );\n }\n\n if (icon && iconPosition === 'end') {\n return (\n <>\n {leadingSlot}\n {label}\n <span\n className={`${iconWrapperClasses}${children ? ` ${getIconGapClass(size, 'end')}` : ''}`}\n >\n {icon}\n </span>\n </>\n );\n }\n\n return (\n <>\n {leadingSlot}\n {label}\n </>\n );\n };\n\n // An anchor cannot be disabled, so an inactive link still renders as a <button>.\n const button =\n href && !isInactive ? (\n <a\n ref={composedRef}\n href={href}\n target={target}\n rel={resolveRel(rel, target)}\n className={baseClasses}\n onFocus={handleFocus}\n onBlur={handleBlur}\n {...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>)}\n >\n {renderContent()}\n </a>\n ) : (\n <button\n ref={composedRef}\n // Not the browser's `submit`: an untyped Button in a form would otherwise be its\n // default button, so Enter in any field pressed it.\n type={type}\n disabled={isInactive}\n className={baseClasses}\n onFocus={handleFocus}\n onBlur={handleBlur}\n {...props}\n >\n {renderContent()}\n </button>\n );\n\n if (tooltip) {\n const trigger = isInactive ? (\n <span className={`inline-flex cursor-not-allowed${flexGrow ? ' w-full' : ''}`}>\n {button}\n </span>\n ) : (\n button\n );\n return (\n <Tooltip text={tooltip} placement={tooltipPlacement} fill={flexGrow}>\n {trigger}\n </Tooltip>\n );\n }\n\n return button;\n },\n);\n\nButton.displayName = 'Button';\n\nexport default Button;\n"],"names":["FLUSH_MARGIN","FLUSH_MARGIN_BORDERLESS","isFocusVisible","element","Button","forwardRef","variant","size","radius","loading","disabled","icon","iconPosition","leading","contentAlign","flexGrow","width","fill","tooltip","tooltipPlacement","iconOnly","flush","children","className","href","target","rel","onBlur","onFocus","type","props","ref","elementRef","useRef","composedRef","useMemo","composeRefs","keyboardFocus","refocusAfterLoading","focusCount","useLayoutEffect","active","getDeepActiveNode","_a","handleFocus","event","handleBlur","blurredAfter","radiusClass","getRadiusClass","getDefaultRadiusClass","isInactive","alignStart","baseClasses","getIconOnlySizeClasses","getSizeClasses","getVariantClasses","label","jsx","leadingSlot","renderContent","jsxs","Fragment","ButtonSpinner","iconWrapperClasses","getIconSizeClass","getIconGapClass","button","resolveRel","Tooltip"],"mappings":";;;;;;;;;AAkFA,MAAMA,KAAe,iCACfC,KAA0B,uBAG1BC,KAAiB,CAACC,MAAqB;AACzC,MAAI;AACA,WAAOA,EAAQ,QAAQ,gBAAgB;AAAA,EAC3C,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ,GAEaC,KAASC;AAAA,EAClB,CACI;AAAA,IACI,SAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,QAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,UAAAC,IAAW;AAAA,IACX,MAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,SAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,UAAAC,IAAW;AAAA,IACX,OAAAC,IAAQ;AAAA,IACR,MAAAC,IAAO;AAAA,IACP,SAAAC;AAAA,IACA,kBAAAC,IAAmB;AAAA,IACnB,UAAAC,IAAW;AAAA,IACX,OAAAC,IAAQ;AAAA,IACR,UAAAC;AAAA,IACA,WAAAC,IAAY;AAAA,IACZ,MAAAC;AAAA,IACA,QAAAC;AAAA,IACA,KAAAC;AAAA,IACA,QAAAC;AAAA,IACA,SAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,GAAGC;AAAA,EAAA,GAEPC,MACC;AACD,UAAMC,IAAaC,EAA2B,IAAI,GAE5CC,IAAcC;AAAA,MAChB,MAAMC,GAAYL,GAA+BC,CAAU;AAAA,MAC3D,CAACD,CAAG;AAAA,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