@eifi1/ui-kit 0.10.0 → 0.11.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/README.md +20 -16
- package/dist/components/alert-banner.d.ts +26 -1
- package/dist/components/alert-banner.js +10 -7
- package/dist/components/alert-banner.js.map +1 -1
- package/dist/components/amount-input.d.ts +2 -0
- package/dist/components/bulk-action-bar.d.ts +51 -5
- package/dist/components/bulk-action-bar.js +88 -41
- package/dist/components/bulk-action-bar.js.map +1 -1
- package/dist/components/button-group.d.ts +58 -3
- package/dist/components/button-group.js +56 -5
- package/dist/components/button-group.js.map +1 -1
- package/dist/components/calculator.d.ts +2 -0
- package/dist/components/calendar-heatmap.d.ts +124 -0
- package/dist/components/calendar-heatmap.js +295 -0
- package/dist/components/calendar-heatmap.js.map +1 -0
- package/dist/components/choice-card.d.ts +34 -2
- package/dist/components/choice-card.js +49 -0
- package/dist/components/choice-card.js.map +1 -1
- package/dist/components/copy-button.d.ts +1 -0
- package/dist/components/data-table.js +2 -0
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/field.d.ts +43 -0
- package/dist/components/field.js +52 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/file-button.d.ts +1 -0
- package/dist/components/file-dropzone.d.ts +1 -0
- package/dist/components/floating-panel.d.ts +147 -4
- package/dist/components/floating-panel.js +188 -28
- package/dist/components/floating-panel.js.map +1 -1
- package/dist/components/list.d.ts +14 -1
- package/dist/components/list.js +7 -1
- package/dist/components/list.js.map +1 -1
- package/dist/components/menu-item.d.ts +11 -1
- package/dist/components/menu-item.js +6 -1
- package/dist/components/menu-item.js.map +1 -1
- package/dist/components/mini-calendar.d.ts +70 -5
- package/dist/components/mini-calendar.js +166 -62
- package/dist/components/mini-calendar.js.map +1 -1
- package/dist/components/nav-pills.d.ts +66 -0
- package/dist/components/nav-pills.js +65 -0
- package/dist/components/nav-pills.js.map +1 -0
- package/dist/components/number-field.d.ts +2 -0
- package/dist/components/number-input.d.ts +2 -0
- package/dist/components/numpad-sheet.d.ts +2 -0
- package/dist/components/progress-bar.d.ts +31 -2
- package/dist/components/progress-bar.js +73 -7
- package/dist/components/progress-bar.js.map +1 -1
- package/dist/components/series-chart.d.ts +16 -0
- package/dist/components/series-chart.js +4 -1
- package/dist/components/series-chart.js.map +1 -1
- package/dist/components/settings-fields.d.ts +1 -0
- package/dist/components/status-dot.d.ts +6 -2
- package/dist/components/status-dot.js +6 -1
- package/dist/components/status-dot.js.map +1 -1
- package/dist/components/table.d.ts +40 -8
- package/dist/components/table.js +41 -7
- package/dist/components/table.js.map +1 -1
- package/dist/components/text.d.ts +8 -1
- package/dist/components/text.js +1 -0
- package/dist/components/text.js.map +1 -1
- package/dist/components/time-input.d.ts +1 -0
- package/dist/components/toggle-group.d.ts +15 -0
- package/dist/components/toggle-group.js +23 -3
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/tooltip.d.ts +11 -3
- package/dist/components/tooltip.js +2 -0
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/ui.d.ts +55 -4
- package/dist/components/ui.js +84 -7
- package/dist/components/ui.js.map +1 -1
- package/dist/components/user-avatar.d.ts +25 -3
- package/dist/components/user-avatar.js +32 -3
- package/dist/components/user-avatar.js.map +1 -1
- package/dist/hooks/use-file-drop.d.ts +1 -0
- package/dist/i18n/defaults.d.ts +2 -0
- package/dist/i18n/defaults.js +2 -0
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +3 -0
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/de-CH-informal.d.ts +2 -0
- package/dist/i18n/locales/de-CH.d.ts +2 -0
- package/dist/i18n/locales/de-informal.d.ts +2 -0
- package/dist/i18n/locales/de.d.ts +2 -0
- package/dist/i18n/locales/de.js +9 -1
- package/dist/i18n/locales/de.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +2 -0
- package/dist/i18n/locales/es.js +9 -1
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +2 -0
- package/dist/i18n/locales/fr.js +9 -1
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +2 -0
- package/dist/i18n/locales/hu.js +9 -1
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +2 -0
- package/dist/i18n/locales/it.js +9 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +2 -0
- package/dist/i18n/locales/zh.js +9 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/index.d.ts +14 -10
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/clipping.d.ts +21 -5
- package/dist/lib/clipping.js +3 -0
- package/dist/lib/clipping.js.map +1 -1
- package/dist/lib/dates.d.ts +17 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/rhf/form.d.ts +1 -0
- package/dist/rhf/use-rhf-wizard-step.d.ts +22 -0
- package/dist/rhf/use-rhf-wizard-step.js +38 -0
- package/dist/rhf/use-rhf-wizard-step.js.map +1 -0
- package/dist/rhf.d.ts +2 -0
- package/dist/rhf.js +1 -0
- package/dist/rhf.js.map +1 -1
- package/dist/shell/topbar-action-menu.d.ts +73 -3
- package/dist/shell/topbar-action-menu.js +100 -27
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell.d.ts +2 -1
- package/dist/wizard/stepper-nav.d.ts +1 -0
- package/dist/wizard/wizard-context.d.ts +7 -1
- package/dist/wizard/wizard-context.js +4 -0
- package/dist/wizard/wizard-context.js.map +1 -1
- package/dist/wizard.d.ts +2 -1
- package/package.json +1 -1
- package/src/components/alert-banner.tsx +36 -7
- package/src/components/bulk-action-bar.tsx +163 -57
- package/src/components/button-group.tsx +124 -4
- package/src/components/calendar-heatmap.tsx +504 -0
- package/src/components/choice-card.tsx +97 -1
- package/src/components/data-table.tsx +7 -0
- package/src/components/field.tsx +137 -0
- package/src/components/floating-panel.tsx +366 -15
- package/src/components/list.tsx +28 -2
- package/src/components/menu-item.tsx +22 -1
- package/src/components/mini-calendar.tsx +245 -54
- package/src/components/nav-pills.tsx +145 -0
- package/src/components/progress-bar.tsx +129 -11
- package/src/components/series-chart.tsx +21 -0
- package/src/components/status-dot.tsx +10 -2
- package/src/components/table.tsx +85 -11
- package/src/components/text.tsx +9 -1
- package/src/components/toggle-group.tsx +48 -3
- package/src/components/tooltip.tsx +17 -3
- package/src/components/ui.tsx +149 -11
- package/src/components/user-avatar.tsx +57 -3
- package/src/i18n/defaults.ts +2 -0
- package/src/i18n/kit-labels.tsx +2 -0
- package/src/i18n/locales/de.ts +9 -0
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/hu.ts +9 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/zh.ts +9 -0
- package/src/index.ts +5 -0
- package/src/lib/clipping.ts +22 -4
- package/src/lib/dates.ts +37 -0
- package/src/rhf/use-rhf-wizard-step.ts +113 -0
- package/src/rhf.ts +2 -0
- package/src/shell/topbar-action-menu.tsx +239 -49
- package/src/wizard/wizard-context.tsx +9 -0
|
@@ -11,6 +11,21 @@ type TableDensity = "comfortable" | "compact" | "none";
|
|
|
11
11
|
* figures for room. */
|
|
12
12
|
type TableLayout = "auto" | "fixed";
|
|
13
13
|
type TableAlign = "start" | "center" | "end";
|
|
14
|
+
/**
|
|
15
|
+
* Vertical alignment of a cell's content (0.11.0). The defaults stay as they were — a
|
|
16
|
+
* head cell sits on the `bottom` (a wrapped heading ends on the line above the
|
|
17
|
+
* figures), a body cell at the `top` (a wrapped note starts level with its row). A
|
|
18
|
+
* table whose cells are INPUTS wants `middle`: keksdose's VAT summary
|
|
19
|
+
* (invoices/vat-summary.tsx) sets fields beside derived read-out figures in one row,
|
|
20
|
+
* and a figure at the top of its cell sat above the middle of the field next to it —
|
|
21
|
+
* so it writes `<tr className="align-middle">` over raw `<th>`/`<td>`, because the
|
|
22
|
+
* kit's cells each stated `align-top` and a class on the row could not reach them.
|
|
23
|
+
*/
|
|
24
|
+
type TableVAlign = "top" | "middle" | "bottom";
|
|
25
|
+
/** The head cell's type size: `xs` (the head's default) or `sm` (the body's). */
|
|
26
|
+
type TableHeaderCellSize = "xs" | "sm";
|
|
27
|
+
/** The header cell's weight. Default `medium`. */
|
|
28
|
+
type TableHeaderCellWeight = "normal" | "medium" | "semibold";
|
|
14
29
|
/**
|
|
15
30
|
* The alignment a figure column wants: end-aligned (so the units line up under each
|
|
16
31
|
* other in either reading direction) with tabular digits (so they line up at all).
|
|
@@ -80,26 +95,43 @@ type TableFootProps = ComponentPropsWithoutRef<"tfoot">;
|
|
|
80
95
|
/** The totals row. Not in the brief, but every ledger view has one and a `<tfoot>`
|
|
81
96
|
* is what tells a reader it is a total rather than one more row. */
|
|
82
97
|
declare function TableFoot({ className, ...rest }: TableFootProps): react.JSX.Element;
|
|
83
|
-
|
|
84
|
-
|
|
98
|
+
/** The deprecated HTML `valign` attribute is replaced by a class-backed one. */
|
|
99
|
+
interface TableRowProps extends ComponentPropsWithoutRef<"tr"> {
|
|
100
|
+
/** Vertical alignment for every cell of the row that does not set its own. See
|
|
101
|
+
* {@link TableVAlign}. Left out, each cell keeps its default. */
|
|
102
|
+
valign?: TableVAlign;
|
|
103
|
+
}
|
|
104
|
+
declare function TableRow({ valign, className, ...rest }: TableRowProps): react.JSX.Element;
|
|
85
105
|
interface CellAlignProps {
|
|
86
106
|
/** Shorthand for a figure column: end-aligned, tabular digits. */
|
|
87
107
|
numeric?: boolean;
|
|
88
108
|
/** Logical alignment. Default `start` (`end` when `numeric`). */
|
|
89
109
|
align?: TableAlign;
|
|
110
|
+
/** Vertical alignment. Default: the row's `valign`, else `bottom` for a head cell and
|
|
111
|
+
* `top` for a body cell. See {@link TableVAlign}. */
|
|
112
|
+
valign?: TableVAlign;
|
|
90
113
|
}
|
|
91
|
-
/** The deprecated HTML `align`
|
|
92
|
-
interface TableHeaderCellProps extends Omit<ComponentPropsWithoutRef<"th">, "align">, CellAlignProps {
|
|
114
|
+
/** The deprecated HTML `align` and `valign` attributes are replaced by class-backed ones. */
|
|
115
|
+
interface TableHeaderCellProps extends Omit<ComponentPropsWithoutRef<"th">, "align" | "valign">, CellAlignProps {
|
|
116
|
+
/**
|
|
117
|
+
* Type size. Left out: `xs` in the head, the table's own size in the body — as
|
|
118
|
+
* before. keksdose's VAT summary heads its columns at the body size and normal weight
|
|
119
|
+
* (vat-summary.tsx:158–168, `font-normal` on each `<th>`), a quiet header over a
|
|
120
|
+
* small table of figures, and could not say so without overriding classes.
|
|
121
|
+
*/
|
|
122
|
+
size?: TableHeaderCellSize;
|
|
123
|
+
/** Default `medium`. `normal` for the quiet header above; see {@link size}. */
|
|
124
|
+
weight?: TableHeaderCellWeight;
|
|
93
125
|
}
|
|
94
126
|
/**
|
|
95
127
|
* A `<th>`. `scope` defaults to `col` in the head and `row` in the body — a header
|
|
96
128
|
* cell in a body row is the row's label ("Net rent" in a key-value table), and a
|
|
97
129
|
* reader needs the scope to read it with each cell beside it.
|
|
98
130
|
*/
|
|
99
|
-
declare function TableHeaderCell({ numeric, align, scope, className, ...rest }: TableHeaderCellProps): react.JSX.Element;
|
|
100
|
-
interface TableCellProps extends Omit<ComponentPropsWithoutRef<"td">, "align">, CellAlignProps {
|
|
131
|
+
declare function TableHeaderCell({ numeric, align, valign, size, weight, scope, className, ...rest }: TableHeaderCellProps): react.JSX.Element;
|
|
132
|
+
interface TableCellProps extends Omit<ComponentPropsWithoutRef<"td">, "align" | "valign">, CellAlignProps {
|
|
101
133
|
}
|
|
102
|
-
declare function TableCell({ numeric, align, className, ...rest }: TableCellProps): react.JSX.Element;
|
|
134
|
+
declare function TableCell({ numeric, align, valign, className, ...rest }: TableCellProps): react.JSX.Element;
|
|
103
135
|
type TableCaptionProps = ComponentPropsWithoutRef<"caption">;
|
|
104
136
|
/**
|
|
105
137
|
* The table's title. Beneath the table by default (`caption-bottom`, the shadcn
|
|
@@ -113,4 +145,4 @@ type TableCaptionProps = ComponentPropsWithoutRef<"caption">;
|
|
|
113
145
|
*/
|
|
114
146
|
declare function TableCaption({ className, id, ...rest }: TableCaptionProps): react.JSX.Element;
|
|
115
147
|
|
|
116
|
-
export { NUMERIC_CELL_CLASS, Table, type TableAlign, TableBody, type TableBodyProps, TableCaption, type TableCaptionProps, TableCell, type TableCellProps, type TableDensity, TableEmpty, type TableEmptyProps, TableFoot, type TableFootProps, TableHead, type TableHeadProps, TableHeaderCell, type TableHeaderCellProps, type TableLayout, type TableProps, TableRow, type TableRowProps };
|
|
148
|
+
export { NUMERIC_CELL_CLASS, Table, type TableAlign, TableBody, type TableBodyProps, TableCaption, type TableCaptionProps, TableCell, type TableCellProps, type TableDensity, TableEmpty, type TableEmptyProps, TableFoot, type TableFootProps, TableHead, type TableHeadProps, TableHeaderCell, type TableHeaderCellProps, type TableHeaderCellSize, type TableHeaderCellWeight, type TableLayout, type TableProps, TableRow, type TableRowProps, type TableVAlign };
|
package/dist/components/table.js
CHANGED
|
@@ -12,6 +12,21 @@ const TableContext = createContext({
|
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
const SectionContext = createContext("body");
|
|
15
|
+
const RowVAlignContext = createContext(void 0);
|
|
16
|
+
const VALIGN = {
|
|
17
|
+
top: "align-top",
|
|
18
|
+
middle: "align-middle",
|
|
19
|
+
bottom: "align-bottom"
|
|
20
|
+
};
|
|
21
|
+
const HEADER_SIZE = {
|
|
22
|
+
xs: "text-xs",
|
|
23
|
+
sm: "text-sm"
|
|
24
|
+
};
|
|
25
|
+
const HEADER_WEIGHT = {
|
|
26
|
+
normal: "font-normal",
|
|
27
|
+
medium: "font-medium",
|
|
28
|
+
semibold: "font-semibold"
|
|
29
|
+
};
|
|
15
30
|
const CELL_PAD = {
|
|
16
31
|
comfortable: "px-3 py-2",
|
|
17
32
|
compact: "px-2 py-1",
|
|
@@ -59,6 +74,7 @@ function Table({
|
|
|
59
74
|
...overflowing ? regionName : null,
|
|
60
75
|
tabIndex: overflowing ? 0 : void 0,
|
|
61
76
|
"data-overflowing": overflowing || void 0,
|
|
77
|
+
"data-clips": "",
|
|
62
78
|
className: cn(
|
|
63
79
|
// `relative`: the containing block for an `sr-only` caption.
|
|
64
80
|
"relative w-full overflow-x-auto",
|
|
@@ -126,11 +142,11 @@ function TableEmpty({ children, colSpan, cellClassName, className, ...rest }) {
|
|
|
126
142
|
function TableFoot({ className, ...rest }) {
|
|
127
143
|
return /* @__PURE__ */ jsx(SectionContext.Provider, { value: "foot", children: /* @__PURE__ */ jsx("tfoot", { ...rest, className: cn("border-t border-[var(--border-strong)] font-medium", className) }) });
|
|
128
144
|
}
|
|
129
|
-
function TableRow({ className, ...rest }) {
|
|
145
|
+
function TableRow({ valign, className, ...rest }) {
|
|
130
146
|
const { zebra, hover } = useContext(TableContext);
|
|
131
147
|
const section = useContext(SectionContext);
|
|
132
148
|
const body = section === "body";
|
|
133
|
-
|
|
149
|
+
const row = /* @__PURE__ */ jsx(
|
|
134
150
|
"tr",
|
|
135
151
|
{
|
|
136
152
|
...rest,
|
|
@@ -138,14 +154,29 @@ function TableRow({ className, ...rest }) {
|
|
|
138
154
|
body && "border-b border-[var(--border)]",
|
|
139
155
|
body && zebra && "even:bg-[var(--bg-surface-2)]",
|
|
140
156
|
body && hover && "transition-colors hover:bg-[var(--bg-hover)]",
|
|
157
|
+
// On the row as well, for a raw `<td>` of the caller's, which inherits it.
|
|
158
|
+
valign && VALIGN[valign],
|
|
141
159
|
className
|
|
142
160
|
)
|
|
143
161
|
}
|
|
144
162
|
);
|
|
163
|
+
return valign ? /* @__PURE__ */ jsx(RowVAlignContext.Provider, { value: valign, children: row }) : row;
|
|
145
164
|
}
|
|
146
|
-
function TableHeaderCell({
|
|
165
|
+
function TableHeaderCell({
|
|
166
|
+
numeric = false,
|
|
167
|
+
align,
|
|
168
|
+
valign,
|
|
169
|
+
size,
|
|
170
|
+
weight = "medium",
|
|
171
|
+
scope,
|
|
172
|
+
className,
|
|
173
|
+
...rest
|
|
174
|
+
}) {
|
|
147
175
|
const { density } = useContext(TableContext);
|
|
148
176
|
const section = useContext(SectionContext);
|
|
177
|
+
const rowVAlign = useContext(RowVAlignContext);
|
|
178
|
+
const head = section === "head";
|
|
179
|
+
const textSize = size ?? (head ? "xs" : void 0);
|
|
149
180
|
return /* @__PURE__ */ jsx(
|
|
150
181
|
"th",
|
|
151
182
|
{
|
|
@@ -155,22 +186,25 @@ function TableHeaderCell({ numeric = false, align, scope, className, ...rest })
|
|
|
155
186
|
CELL_PAD[density],
|
|
156
187
|
ALIGN[align ?? (numeric ? "end" : "start")],
|
|
157
188
|
numeric && "tabular-nums",
|
|
158
|
-
"
|
|
159
|
-
|
|
189
|
+
VALIGN[valign ?? rowVAlign ?? (head ? "bottom" : "top")],
|
|
190
|
+
HEADER_WEIGHT[weight],
|
|
191
|
+
head ? "text-[var(--text-muted)]" : "text-[var(--text-secondary)]",
|
|
192
|
+
textSize && HEADER_SIZE[textSize],
|
|
160
193
|
className
|
|
161
194
|
)
|
|
162
195
|
}
|
|
163
196
|
);
|
|
164
197
|
}
|
|
165
|
-
function TableCell({ numeric = false, align, className, ...rest }) {
|
|
198
|
+
function TableCell({ numeric = false, align, valign, className, ...rest }) {
|
|
166
199
|
const { density } = useContext(TableContext);
|
|
200
|
+
const rowVAlign = useContext(RowVAlignContext);
|
|
167
201
|
return /* @__PURE__ */ jsx(
|
|
168
202
|
"td",
|
|
169
203
|
{
|
|
170
204
|
...rest,
|
|
171
205
|
className: cn(
|
|
172
206
|
CELL_PAD[density],
|
|
173
|
-
"
|
|
207
|
+
VALIGN[valign ?? rowVAlign ?? "top"],
|
|
174
208
|
ALIGN[align ?? (numeric ? "end" : "start")],
|
|
175
209
|
numeric && "tabular-nums whitespace-nowrap",
|
|
176
210
|
className
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/table.tsx"],"sourcesContent":["import { Children, createContext, useContext, useId, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { THIN_SCROLLBAR_CLASS, useScrollOverflow } from \"./scroll-area\";\n\n/** `none` (0.10.0): no cell padding at all — keksdose's VAT summary, a table set\n * inside a card's own padding whose columns are spaced by hand (`pl-2` on exactly the\n * columns that need it). Type stays at the body size, as `comfortable`. */\nexport type TableDensity = \"comfortable\" | \"compact\" | \"none\";\n/** CSS `table-layout`. `auto` (the browser default) sizes columns to their content;\n * `fixed` takes widths from the first row and ignores the rest — keksdose's VAT\n * summary switches to it while editing so two inputs stop bidding against the\n * figures for room. */\nexport type TableLayout = \"auto\" | \"fixed\";\nexport type TableAlign = \"start\" | \"center\" | \"end\";\n\ninterface TableContextValue {\n density: TableDensity;\n zebra: boolean;\n hover: boolean;\n captionId: string;\n registerCaption: () => () => void;\n}\n\nconst TableContext = createContext<TableContextValue>({\n density: \"comfortable\",\n zebra: false,\n hover: false,\n captionId: \"\",\n registerCaption: () => () => {},\n});\n\n/** Which section a row sits in — zebra and hover apply to body rows only. */\nconst SectionContext = createContext<\"head\" | \"body\" | \"foot\">(\"body\");\n\nconst CELL_PAD: Record<TableDensity, string> = {\n comfortable: \"px-3 py-2\",\n compact: \"px-2 py-1\",\n none: \"p-0\",\n};\n\nconst ALIGN: Record<TableAlign, string> = {\n start: \"text-start\",\n center: \"text-center\",\n end: \"text-end\",\n};\n\n/**\n * The alignment a figure column wants: end-aligned (so the units line up under each\n * other in either reading direction) with tabular digits (so they line up at all).\n * Exported for a cell the kit did not render — a DataTable column, a `<td>` of the\n * app's own.\n */\nexport const NUMERIC_CELL_CLASS = \"text-end tabular-nums\";\n\nexport interface TableProps extends ComponentPropsWithoutRef<\"table\"> {\n /** `compact` for a dense detail view (a ledger, a spec sheet). */\n density?: TableDensity;\n /** Tint every other body row. */\n zebra?: boolean;\n /** Tint the body row under the pointer. Off by default: a static table whose rows\n * light up promises a click that does nothing. */\n hover?: boolean;\n /** Classes for the overflow wrapper around the `<table>` (a max-height, a border). */\n wrapperClassName?: string;\n /** See {@link TableLayout}. Unset leaves the browser's `auto` and adds no class. */\n layout?: TableLayout;\n}\n\n/**\n * A plain, static HTML table in the kit's tokens — for the detail views that need\n * rows and columns and none of {@link DataTable}'s sorting, filtering or paging.\n *\n * kastlan renders about twenty of these on shadcn's Table parts; the part names here\n * are the same idea (`TableHead` is the `<thead>`, `TableHeaderCell` the `<th>`), so\n * the move is a rename rather than a rewrite.\n *\n * The table sits in an overflow-x wrapper, because a table cannot shrink below its\n * content and on a phone it would otherwise widen the page. While it overflows that\n * wrapper becomes a tab stop and a `role=\"region\"` named by the `TableCaption` (or the\n * table's own `aria-label`), so a keyboard user can scroll it and a reader can say\n * what it is — the same contract as {@link ScrollArea}.\n *\n * Alignment is logical throughout (`text-start` / `text-end`), so a right-to-left\n * page gets its first column on the right without a class changing.\n */\nexport function Table({\n density = \"comfortable\",\n zebra = false,\n hover = false,\n wrapperClassName,\n layout,\n className,\n \"aria-label\": ariaLabel,\n ...rest\n}: TableProps) {\n const captionId = useId();\n const [captions, setCaptions] = useState(0);\n const wrapper = useRef<HTMLDivElement | null>(null);\n const overflowing = useScrollOverflow(wrapper);\n\n const ctx = useMemo<TableContextValue>(\n () => ({\n density,\n zebra,\n hover,\n captionId,\n registerCaption: () => {\n setCaptions((n) => n + 1);\n return () => setCaptions((n) => n - 1);\n },\n }),\n [density, zebra, hover, captionId],\n );\n\n const regionName = captions > 0 ? { \"aria-labelledby\": captionId } : ariaLabel ? { \"aria-label\": ariaLabel } : null;\n\n return (\n <TableContext.Provider value={ctx}>\n <div\n ref={wrapper}\n // Only a region when it scrolls AND has a name: a landmark for every short\n // table on a page would bury the real ones.\n role={overflowing && regionName ? \"region\" : undefined}\n {...(overflowing ? regionName : null)}\n tabIndex={overflowing ? 0 : undefined}\n data-overflowing={overflowing || undefined}\n className={cn(\n // `relative`: the containing block for an `sr-only` caption.\n \"relative w-full overflow-x-auto\",\n THIN_SCROLLBAR_CLASS,\n \"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-[var(--brand)]\",\n wrapperClassName,\n )}\n >\n <table\n {...rest}\n aria-label={ariaLabel}\n className={cn(\n \"w-full caption-bottom border-collapse text-sm text-[var(--text-primary)]\",\n density === \"compact\" && \"text-xs\",\n layout === \"fixed\" && \"table-fixed\",\n layout === \"auto\" && \"table-auto\",\n className,\n )}\n />\n </div>\n </TableContext.Provider>\n );\n}\n\nexport type TableHeadProps = ComponentPropsWithoutRef<\"thead\">;\n\nexport function TableHead({ className, ...rest }: TableHeadProps) {\n return (\n <SectionContext.Provider value=\"head\">\n <thead {...rest} className={cn(\"border-b border-[var(--border)]\", className)} />\n </SectionContext.Provider>\n );\n}\n\nexport interface TableBodyProps extends ComponentPropsWithoutRef<\"tbody\"> {\n /**\n * Shown as ONE full-width row (a {@link TableEmpty}) when the body has no rows —\n * `children` that render nothing: an empty `.map`, a `false`, `null`. kastlan hand-\n * writes that row with a counted `colSpan` in unit-values-editor, the meeting agenda\n * and invitations tabs, the journal-entry and invoice detail pages, and a column\n * added later leaves every one of those counts one short.\n */\n empty?: ReactNode;\n}\n\nexport function TableBody({ className, empty, children, ...rest }: TableBodyProps) {\n // `toArray` drops null/undefined/booleans and flattens arrays, so `[[], false]` —\n // an empty map beside a conditional row that is off — is no rows.\n const hasRows = Children.toArray(children).length > 0;\n return (\n <SectionContext.Provider value=\"body\">\n <tbody {...rest} className={cn(\"[&>tr:last-child]:border-b-0\", className)}>\n {hasRows || empty === undefined || empty === null || empty === false ? (\n children\n ) : (\n <TableEmpty>{empty}</TableEmpty>\n )}\n </tbody>\n </SectionContext.Provider>\n );\n}\n\nexport interface TableEmptyProps extends Omit<ComponentPropsWithoutRef<\"tr\">, \"children\"> {\n children: ReactNode;\n /** Columns to span. Default: MEASURED — the widest row of the table it renders in,\n * counted after mount, so the row stays full width when a column is added. */\n colSpan?: number;\n /** Classes for the `<td>`. */\n cellClassName?: string;\n}\n\n/**\n * The \"nothing here\" row: one cell across every column, centred, muted. What\n * {@link TableBodyProps.empty} renders, and usable on its own for a body whose rows\n * are not its direct children.\n */\nexport function TableEmpty({ children, colSpan, cellClassName, className, ...rest }: TableEmptyProps) {\n const { density } = useContext(TableContext);\n const cell = useRef<HTMLTableCellElement | null>(null);\n const [measured, setMeasured] = useState(1);\n // Every render, deliberately: a column can appear in the head without anything this\n // row depends on changing. It cannot loop — setting the same count is a bail-out.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(() => {\n if (colSpan !== undefined) return;\n const row = cell.current?.parentElement;\n const table = cell.current?.closest(\"table\");\n if (!row || !table) return;\n let widest = 1;\n for (const r of Array.from(table.rows)) {\n if (r === row) continue;\n let n = 0;\n for (const c of Array.from(r.cells)) n += c.colSpan || 1;\n widest = Math.max(widest, n);\n }\n setMeasured(widest);\n });\n return (\n <tr {...rest} data-table-empty=\"\" className={className}>\n <td\n ref={cell}\n colSpan={colSpan ?? measured}\n className={cn(\n // `none` keeps the message off the edges regardless: it is text, not a figure.\n density === \"none\" ? \"py-2\" : CELL_PAD[density],\n \"text-center text-[var(--text-muted)]\",\n cellClassName,\n )}\n >\n {children}\n </td>\n </tr>\n );\n}\n\nexport type TableFootProps = ComponentPropsWithoutRef<\"tfoot\">;\n\n/** The totals row. Not in the brief, but every ledger view has one and a `<tfoot>`\n * is what tells a reader it is a total rather than one more row. */\nexport function TableFoot({ className, ...rest }: TableFootProps) {\n return (\n <SectionContext.Provider value=\"foot\">\n <tfoot {...rest} className={cn(\"border-t border-[var(--border-strong)] font-medium\", className)} />\n </SectionContext.Provider>\n );\n}\n\nexport type TableRowProps = ComponentPropsWithoutRef<\"tr\">;\n\nexport function TableRow({ className, ...rest }: TableRowProps) {\n const { zebra, hover } = useContext(TableContext);\n const section = useContext(SectionContext);\n const body = section === \"body\";\n return (\n <tr\n {...rest}\n className={cn(\n body && \"border-b border-[var(--border)]\",\n body && zebra && \"even:bg-[var(--bg-surface-2)]\",\n body && hover && \"transition-colors hover:bg-[var(--bg-hover)]\",\n className,\n )}\n />\n );\n}\n\ninterface CellAlignProps {\n /** Shorthand for a figure column: end-aligned, tabular digits. */\n numeric?: boolean;\n /** Logical alignment. Default `start` (`end` when `numeric`). */\n align?: TableAlign;\n}\n\n/** The deprecated HTML `align` attribute is replaced by a logical one. */\nexport interface TableHeaderCellProps extends Omit<ComponentPropsWithoutRef<\"th\">, \"align\">, CellAlignProps {}\n\n/**\n * A `<th>`. `scope` defaults to `col` in the head and `row` in the body — a header\n * cell in a body row is the row's label (\"Net rent\" in a key-value table), and a\n * reader needs the scope to read it with each cell beside it.\n */\nexport function TableHeaderCell({ numeric = false, align, scope, className, ...rest }: TableHeaderCellProps) {\n const { density } = useContext(TableContext);\n const section = useContext(SectionContext);\n return (\n <th\n {...rest}\n scope={scope ?? (section === \"head\" ? \"col\" : \"row\")}\n className={cn(\n CELL_PAD[density],\n ALIGN[align ?? (numeric ? \"end\" : \"start\")],\n numeric && \"tabular-nums\",\n \"align-bottom font-medium\",\n section === \"head\" ? \"text-xs text-[var(--text-muted)]\" : \"align-top text-[var(--text-secondary)]\",\n className,\n )}\n />\n );\n}\n\nexport interface TableCellProps extends Omit<ComponentPropsWithoutRef<\"td\">, \"align\">, CellAlignProps {}\n\nexport function TableCell({ numeric = false, align, className, ...rest }: TableCellProps) {\n const { density } = useContext(TableContext);\n return (\n <td\n {...rest}\n className={cn(\n CELL_PAD[density],\n \"align-top\",\n ALIGN[align ?? (numeric ? \"end\" : \"start\")],\n numeric && \"tabular-nums whitespace-nowrap\",\n className,\n )}\n />\n );\n}\n\nexport type TableCaptionProps = ComponentPropsWithoutRef<\"caption\">;\n\n/**\n * The table's title. Beneath the table by default (`caption-bottom`, the shadcn\n * convention kastlan's views already follow); `className=\"caption-top\"` moves it.\n * `className=\"sr-only\"` keeps it for readers only — the wrapper is `relative`, so\n * the hidden caption stays inside it.\n *\n * It also names the scroll region when the table overflows: it registers itself\n * with the {@link Table} so the wrapper points at an id that exists, and never at\n * one that does not.\n */\nexport function TableCaption({ className, id, ...rest }: TableCaptionProps) {\n const { captionId, registerCaption } = useContext(TableContext);\n useLayoutEffect(() => (id ? undefined : registerCaption()), [id, registerCaption]);\n return (\n <caption\n {...rest}\n id={id ?? captionId}\n className={cn(\"mt-2 text-start text-sm text-[var(--text-muted)]\", className)}\n />\n );\n}\n"],"mappings":";AAuIQ;AAvIR,SAAS,UAAU,eAAe,YAAY,OAAO,iBAAiB,SAAS,QAAQ,gBAAgB;AAEvG,SAAS,UAAU;AACnB,SAAS,sBAAsB,yBAAyB;AAqBxD,MAAM,eAAe,cAAiC;AAAA,EACpD,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP,WAAW;AAAA,EACX,iBAAiB,MAAM,MAAM;AAAA,EAAC;AAChC,CAAC;AAGD,MAAM,iBAAiB,cAAwC,MAAM;AAErE,MAAM,WAAyC;AAAA,EAC7C,aAAa;AAAA,EACb,SAAS;AAAA,EACT,MAAM;AACR;AAEA,MAAM,QAAoC;AAAA,EACxC,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AACP;AAQO,MAAM,qBAAqB;AAiC3B,SAAS,MAAM;AAAA,EACpB,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,GAAG;AACL,GAAe;AACb,QAAM,YAAY,MAAM;AACxB,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,CAAC;AAC1C,QAAM,UAAU,OAA8B,IAAI;AAClD,QAAM,cAAc,kBAAkB,OAAO;AAE7C,QAAM,MAAM;AAAA,IACV,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,iBAAiB,MAAM;AACrB,oBAAY,CAAC,MAAM,IAAI,CAAC;AACxB,eAAO,MAAM,YAAY,CAAC,MAAM,IAA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,SAAS;AAAA,QACjB,QAAQ,SAAS;AAAA,QACjB;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;AAiBO,SAAS,gBAAgB,EAAE,UAAU,OAAO,OAAO,OAAO,WAAW,GAAG,KAAK,GAAyB;AAC3G,QAAM,EAAE,QAAQ,IAAI,WAAW,YAAY;AAC3C,QAAM,UAAU,WAAW,cAAc;AACzC,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,OAAO,UAAU,YAAY,SAAS,QAAQ;AAAA,MAC9C,WAAW;AAAA,QACT,SAAS,OAAO;AAAA,QAChB,MAAM,UAAU,UAAU,QAAQ,QAAQ;AAAA,QAC1C,WAAW;AAAA,QACX;AAAA,QACA,YAAY,SAAS,qCAAqC;AAAA,QAC1D;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;AAIO,SAAS,UAAU,EAAE,UAAU,OAAO,OAAO,WAAW,GAAG,KAAK,GAAmB;AACxF,QAAM,EAAE,QAAQ,IAAI,WAAW,YAAY;AAC3C,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,WAAW;AAAA,QACT,SAAS,OAAO;AAAA,QAChB;AAAA,QACA,MAAM,UAAU,UAAU,QAAQ,QAAQ;AAAA,QAC1C,WAAW;AAAA,QACX;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;AAcO,SAAS,aAAa,EAAE,WAAW,IAAI,GAAG,KAAK,GAAsB;AAC1E,QAAM,EAAE,WAAW,gBAAgB,IAAI,WAAW,YAAY;AAC9D,kBAAgB,MAAO,KAAK,SAAY,gBAAgB,GAAI,CAAC,IAAI,eAAe,CAAC;AACjF,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,IAAI,MAAM;AAAA,MACV,WAAW,GAAG,oDAAoD,SAAS;AAAA;AAAA,EAC7E;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/table.tsx"],"sourcesContent":["import { Children, createContext, useContext, useId, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { THIN_SCROLLBAR_CLASS, useScrollOverflow } from \"./scroll-area\";\n\n/** `none` (0.10.0): no cell padding at all — keksdose's VAT summary, a table set\n * inside a card's own padding whose columns are spaced by hand (`pl-2` on exactly the\n * columns that need it). Type stays at the body size, as `comfortable`. */\nexport type TableDensity = \"comfortable\" | \"compact\" | \"none\";\n/** CSS `table-layout`. `auto` (the browser default) sizes columns to their content;\n * `fixed` takes widths from the first row and ignores the rest — keksdose's VAT\n * summary switches to it while editing so two inputs stop bidding against the\n * figures for room. */\nexport type TableLayout = \"auto\" | \"fixed\";\nexport type TableAlign = \"start\" | \"center\" | \"end\";\n/**\n * Vertical alignment of a cell's content (0.11.0). The defaults stay as they were — a\n * head cell sits on the `bottom` (a wrapped heading ends on the line above the\n * figures), a body cell at the `top` (a wrapped note starts level with its row). A\n * table whose cells are INPUTS wants `middle`: keksdose's VAT summary\n * (invoices/vat-summary.tsx) sets fields beside derived read-out figures in one row,\n * and a figure at the top of its cell sat above the middle of the field next to it —\n * so it writes `<tr className=\"align-middle\">` over raw `<th>`/`<td>`, because the\n * kit's cells each stated `align-top` and a class on the row could not reach them.\n */\nexport type TableVAlign = \"top\" | \"middle\" | \"bottom\";\n/** The head cell's type size: `xs` (the head's default) or `sm` (the body's). */\nexport type TableHeaderCellSize = \"xs\" | \"sm\";\n/** The header cell's weight. Default `medium`. */\nexport type TableHeaderCellWeight = \"normal\" | \"medium\" | \"semibold\";\n\ninterface TableContextValue {\n density: TableDensity;\n zebra: boolean;\n hover: boolean;\n captionId: string;\n registerCaption: () => () => void;\n}\n\nconst TableContext = createContext<TableContextValue>({\n density: \"comfortable\",\n zebra: false,\n hover: false,\n captionId: \"\",\n registerCaption: () => () => {},\n});\n\n/** Which section a row sits in — zebra and hover apply to body rows only. */\nconst SectionContext = createContext<\"head\" | \"body\" | \"foot\">(\"body\");\n\n/** A {@link TableRow}'s `valign`, which its cells take unless they set their own. It\n * cannot be left to CSS inheritance: every cell states its own default alignment,\n * and a class on the cell beats one on the row. */\nconst RowVAlignContext = createContext<TableVAlign | undefined>(undefined);\n\nconst VALIGN: Record<TableVAlign, string> = {\n top: \"align-top\",\n middle: \"align-middle\",\n bottom: \"align-bottom\",\n};\n\nconst HEADER_SIZE: Record<TableHeaderCellSize, string> = {\n xs: \"text-xs\",\n sm: \"text-sm\",\n};\n\nconst HEADER_WEIGHT: Record<TableHeaderCellWeight, string> = {\n normal: \"font-normal\",\n medium: \"font-medium\",\n semibold: \"font-semibold\",\n};\n\nconst CELL_PAD: Record<TableDensity, string> = {\n comfortable: \"px-3 py-2\",\n compact: \"px-2 py-1\",\n none: \"p-0\",\n};\n\nconst ALIGN: Record<TableAlign, string> = {\n start: \"text-start\",\n center: \"text-center\",\n end: \"text-end\",\n};\n\n/**\n * The alignment a figure column wants: end-aligned (so the units line up under each\n * other in either reading direction) with tabular digits (so they line up at all).\n * Exported for a cell the kit did not render — a DataTable column, a `<td>` of the\n * app's own.\n */\nexport const NUMERIC_CELL_CLASS = \"text-end tabular-nums\";\n\nexport interface TableProps extends ComponentPropsWithoutRef<\"table\"> {\n /** `compact` for a dense detail view (a ledger, a spec sheet). */\n density?: TableDensity;\n /** Tint every other body row. */\n zebra?: boolean;\n /** Tint the body row under the pointer. Off by default: a static table whose rows\n * light up promises a click that does nothing. */\n hover?: boolean;\n /** Classes for the overflow wrapper around the `<table>` (a max-height, a border). */\n wrapperClassName?: string;\n /** See {@link TableLayout}. Unset leaves the browser's `auto` and adds no class. */\n layout?: TableLayout;\n}\n\n/**\n * A plain, static HTML table in the kit's tokens — for the detail views that need\n * rows and columns and none of {@link DataTable}'s sorting, filtering or paging.\n *\n * kastlan renders about twenty of these on shadcn's Table parts; the part names here\n * are the same idea (`TableHead` is the `<thead>`, `TableHeaderCell` the `<th>`), so\n * the move is a rename rather than a rewrite.\n *\n * The table sits in an overflow-x wrapper, because a table cannot shrink below its\n * content and on a phone it would otherwise widen the page. While it overflows that\n * wrapper becomes a tab stop and a `role=\"region\"` named by the `TableCaption` (or the\n * table's own `aria-label`), so a keyboard user can scroll it and a reader can say\n * what it is — the same contract as {@link ScrollArea}.\n *\n * Alignment is logical throughout (`text-start` / `text-end`), so a right-to-left\n * page gets its first column on the right without a class changing.\n */\nexport function Table({\n density = \"comfortable\",\n zebra = false,\n hover = false,\n wrapperClassName,\n layout,\n className,\n \"aria-label\": ariaLabel,\n ...rest\n}: TableProps) {\n const captionId = useId();\n const [captions, setCaptions] = useState(0);\n const wrapper = useRef<HTMLDivElement | null>(null);\n const overflowing = useScrollOverflow(wrapper);\n\n const ctx = useMemo<TableContextValue>(\n () => ({\n density,\n zebra,\n hover,\n captionId,\n registerCaption: () => {\n setCaptions((n) => n + 1);\n return () => setCaptions((n) => n - 1);\n },\n }),\n [density, zebra, hover, captionId],\n );\n\n const regionName = captions > 0 ? { \"aria-labelledby\": captionId } : ariaLabel ? { \"aria-label\": ariaLabel } : null;\n\n return (\n <TableContext.Provider value={ctx}>\n <div\n ref={wrapper}\n // Only a region when it scrolls AND has a name: a landmark for every short\n // table on a page would bury the real ones.\n role={overflowing && regionName ? \"region\" : undefined}\n {...(overflowing ? regionName : null)}\n tabIndex={overflowing ? 0 : undefined}\n data-overflowing={overflowing || undefined}\n data-clips=\"\"\n className={cn(\n // `relative`: the containing block for an `sr-only` caption.\n \"relative w-full overflow-x-auto\",\n THIN_SCROLLBAR_CLASS,\n \"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-[var(--brand)]\",\n wrapperClassName,\n )}\n >\n <table\n {...rest}\n aria-label={ariaLabel}\n className={cn(\n \"w-full caption-bottom border-collapse text-sm text-[var(--text-primary)]\",\n density === \"compact\" && \"text-xs\",\n layout === \"fixed\" && \"table-fixed\",\n layout === \"auto\" && \"table-auto\",\n className,\n )}\n />\n </div>\n </TableContext.Provider>\n );\n}\n\nexport type TableHeadProps = ComponentPropsWithoutRef<\"thead\">;\n\nexport function TableHead({ className, ...rest }: TableHeadProps) {\n return (\n <SectionContext.Provider value=\"head\">\n <thead {...rest} className={cn(\"border-b border-[var(--border)]\", className)} />\n </SectionContext.Provider>\n );\n}\n\nexport interface TableBodyProps extends ComponentPropsWithoutRef<\"tbody\"> {\n /**\n * Shown as ONE full-width row (a {@link TableEmpty}) when the body has no rows —\n * `children` that render nothing: an empty `.map`, a `false`, `null`. kastlan hand-\n * writes that row with a counted `colSpan` in unit-values-editor, the meeting agenda\n * and invitations tabs, the journal-entry and invoice detail pages, and a column\n * added later leaves every one of those counts one short.\n */\n empty?: ReactNode;\n}\n\nexport function TableBody({ className, empty, children, ...rest }: TableBodyProps) {\n // `toArray` drops null/undefined/booleans and flattens arrays, so `[[], false]` —\n // an empty map beside a conditional row that is off — is no rows.\n const hasRows = Children.toArray(children).length > 0;\n return (\n <SectionContext.Provider value=\"body\">\n <tbody {...rest} className={cn(\"[&>tr:last-child]:border-b-0\", className)}>\n {hasRows || empty === undefined || empty === null || empty === false ? (\n children\n ) : (\n <TableEmpty>{empty}</TableEmpty>\n )}\n </tbody>\n </SectionContext.Provider>\n );\n}\n\nexport interface TableEmptyProps extends Omit<ComponentPropsWithoutRef<\"tr\">, \"children\"> {\n children: ReactNode;\n /** Columns to span. Default: MEASURED — the widest row of the table it renders in,\n * counted after mount, so the row stays full width when a column is added. */\n colSpan?: number;\n /** Classes for the `<td>`. */\n cellClassName?: string;\n}\n\n/**\n * The \"nothing here\" row: one cell across every column, centred, muted. What\n * {@link TableBodyProps.empty} renders, and usable on its own for a body whose rows\n * are not its direct children.\n */\nexport function TableEmpty({ children, colSpan, cellClassName, className, ...rest }: TableEmptyProps) {\n const { density } = useContext(TableContext);\n const cell = useRef<HTMLTableCellElement | null>(null);\n const [measured, setMeasured] = useState(1);\n // Every render, deliberately: a column can appear in the head without anything this\n // row depends on changing. It cannot loop — setting the same count is a bail-out.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(() => {\n if (colSpan !== undefined) return;\n const row = cell.current?.parentElement;\n const table = cell.current?.closest(\"table\");\n if (!row || !table) return;\n let widest = 1;\n for (const r of Array.from(table.rows)) {\n if (r === row) continue;\n let n = 0;\n for (const c of Array.from(r.cells)) n += c.colSpan || 1;\n widest = Math.max(widest, n);\n }\n setMeasured(widest);\n });\n return (\n <tr {...rest} data-table-empty=\"\" className={className}>\n <td\n ref={cell}\n colSpan={colSpan ?? measured}\n className={cn(\n // `none` keeps the message off the edges regardless: it is text, not a figure.\n density === \"none\" ? \"py-2\" : CELL_PAD[density],\n \"text-center text-[var(--text-muted)]\",\n cellClassName,\n )}\n >\n {children}\n </td>\n </tr>\n );\n}\n\nexport type TableFootProps = ComponentPropsWithoutRef<\"tfoot\">;\n\n/** The totals row. Not in the brief, but every ledger view has one and a `<tfoot>`\n * is what tells a reader it is a total rather than one more row. */\nexport function TableFoot({ className, ...rest }: TableFootProps) {\n return (\n <SectionContext.Provider value=\"foot\">\n <tfoot {...rest} className={cn(\"border-t border-[var(--border-strong)] font-medium\", className)} />\n </SectionContext.Provider>\n );\n}\n\n/** The deprecated HTML `valign` attribute is replaced by a class-backed one. */\nexport interface TableRowProps extends ComponentPropsWithoutRef<\"tr\"> {\n /** Vertical alignment for every cell of the row that does not set its own. See\n * {@link TableVAlign}. Left out, each cell keeps its default. */\n valign?: TableVAlign;\n}\n\nexport function TableRow({ valign, className, ...rest }: TableRowProps) {\n const { zebra, hover } = useContext(TableContext);\n const section = useContext(SectionContext);\n const body = section === \"body\";\n const row = (\n <tr\n {...rest}\n className={cn(\n body && \"border-b border-[var(--border)]\",\n body && zebra && \"even:bg-[var(--bg-surface-2)]\",\n body && hover && \"transition-colors hover:bg-[var(--bg-hover)]\",\n // On the row as well, for a raw `<td>` of the caller's, which inherits it.\n valign && VALIGN[valign],\n className,\n )}\n />\n );\n return valign ? <RowVAlignContext.Provider value={valign}>{row}</RowVAlignContext.Provider> : row;\n}\n\ninterface CellAlignProps {\n /** Shorthand for a figure column: end-aligned, tabular digits. */\n numeric?: boolean;\n /** Logical alignment. Default `start` (`end` when `numeric`). */\n align?: TableAlign;\n /** Vertical alignment. Default: the row's `valign`, else `bottom` for a head cell and\n * `top` for a body cell. See {@link TableVAlign}. */\n valign?: TableVAlign;\n}\n\n/** The deprecated HTML `align` and `valign` attributes are replaced by class-backed ones. */\nexport interface TableHeaderCellProps extends Omit<ComponentPropsWithoutRef<\"th\">, \"align\" | \"valign\">, CellAlignProps {\n /**\n * Type size. Left out: `xs` in the head, the table's own size in the body — as\n * before. keksdose's VAT summary heads its columns at the body size and normal weight\n * (vat-summary.tsx:158–168, `font-normal` on each `<th>`), a quiet header over a\n * small table of figures, and could not say so without overriding classes.\n */\n size?: TableHeaderCellSize;\n /** Default `medium`. `normal` for the quiet header above; see {@link size}. */\n weight?: TableHeaderCellWeight;\n}\n\n/**\n * A `<th>`. `scope` defaults to `col` in the head and `row` in the body — a header\n * cell in a body row is the row's label (\"Net rent\" in a key-value table), and a\n * reader needs the scope to read it with each cell beside it.\n */\nexport function TableHeaderCell({\n numeric = false,\n align,\n valign,\n size,\n weight = \"medium\",\n scope,\n className,\n ...rest\n}: TableHeaderCellProps) {\n const { density } = useContext(TableContext);\n const section = useContext(SectionContext);\n const rowVAlign = useContext(RowVAlignContext);\n const head = section === \"head\";\n const textSize = size ?? (head ? \"xs\" : undefined);\n return (\n <th\n {...rest}\n scope={scope ?? (section === \"head\" ? \"col\" : \"row\")}\n className={cn(\n CELL_PAD[density],\n ALIGN[align ?? (numeric ? \"end\" : \"start\")],\n numeric && \"tabular-nums\",\n VALIGN[valign ?? rowVAlign ?? (head ? \"bottom\" : \"top\")],\n HEADER_WEIGHT[weight],\n head ? \"text-[var(--text-muted)]\" : \"text-[var(--text-secondary)]\",\n textSize && HEADER_SIZE[textSize],\n className,\n )}\n />\n );\n}\n\nexport interface TableCellProps extends Omit<ComponentPropsWithoutRef<\"td\">, \"align\" | \"valign\">, CellAlignProps {}\n\nexport function TableCell({ numeric = false, align, valign, className, ...rest }: TableCellProps) {\n const { density } = useContext(TableContext);\n const rowVAlign = useContext(RowVAlignContext);\n return (\n <td\n {...rest}\n className={cn(\n CELL_PAD[density],\n VALIGN[valign ?? rowVAlign ?? \"top\"],\n ALIGN[align ?? (numeric ? \"end\" : \"start\")],\n numeric && \"tabular-nums whitespace-nowrap\",\n className,\n )}\n />\n );\n}\n\nexport type TableCaptionProps = ComponentPropsWithoutRef<\"caption\">;\n\n/**\n * The table's title. Beneath the table by default (`caption-bottom`, the shadcn\n * convention kastlan's views already follow); `className=\"caption-top\"` moves it.\n * `className=\"sr-only\"` keeps it for readers only — the wrapper is `relative`, so\n * the hidden caption stays inside it.\n *\n * It also names the scroll region when the table overflows: it registers itself\n * with the {@link Table} so the wrapper points at an id that exists, and never at\n * one that does not.\n */\nexport function TableCaption({ className, id, ...rest }: TableCaptionProps) {\n const { captionId, registerCaption } = useContext(TableContext);\n useLayoutEffect(() => (id ? undefined : registerCaption()), [id, registerCaption]);\n return (\n <caption\n {...rest}\n id={id ?? captionId}\n className={cn(\"mt-2 text-start text-sm text-[var(--text-muted)]\", className)}\n />\n );\n}\n"],"mappings":";AA6KQ;AA7KR,SAAS,UAAU,eAAe,YAAY,OAAO,iBAAiB,SAAS,QAAQ,gBAAgB;AAEvG,SAAS,UAAU;AACnB,SAAS,sBAAsB,yBAAyB;AAoCxD,MAAM,eAAe,cAAiC;AAAA,EACpD,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP,WAAW;AAAA,EACX,iBAAiB,MAAM,MAAM;AAAA,EAAC;AAChC,CAAC;AAGD,MAAM,iBAAiB,cAAwC,MAAM;AAKrE,MAAM,mBAAmB,cAAuC,MAAS;AAEzE,MAAM,SAAsC;AAAA,EAC1C,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,QAAQ;AACV;AAEA,MAAM,cAAmD;AAAA,EACvD,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,MA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,OAAO,OAAO;AACxC,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,OAAO,UAAU,YAAY,SAAS,QAAQ;AAAA,MAC9C,WAAW;AAAA,QACT,SAAS,OAAO;AAAA,QAChB,MAAM,UAAU,UAAU,QAAQ,QAAQ;AAAA,QAC1C,WAAW;AAAA,QACX,OAAO,UAAU,cAAc,OAAO,WAAW,MAAM;AAAA,QACvD,cAAc,MAAM;AAAA,QACpB,OAAO,6BAA6B;AAAA,QACpC,YAAY,YAAY,QAAQ;AAAA,QAChC;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;AAIO,SAAS,UAAU,EAAE,UAAU,OAAO,OAAO,QAAQ,WAAW,GAAG,KAAK,GAAmB;AAChG,QAAM,EAAE,QAAQ,IAAI,WAAW,YAAY;AAC3C,QAAM,YAAY,WAAW,gBAAgB;AAC7C,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,WAAW;AAAA,QACT,SAAS,OAAO;AAAA,QAChB,OAAO,UAAU,aAAa,KAAK;AAAA,QACnC,MAAM,UAAU,UAAU,QAAQ,QAAQ;AAAA,QAC1C,WAAW;AAAA,QACX;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;AAcO,SAAS,aAAa,EAAE,WAAW,IAAI,GAAG,KAAK,GAAsB;AAC1E,QAAM,EAAE,WAAW,gBAAgB,IAAI,WAAW,YAAY;AAC9D,kBAAgB,MAAO,KAAK,SAAY,gBAAgB,GAAI,CAAC,IAAI,eAAe,CAAC;AACjF,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,IAAI,MAAM;AAAA,MACV,WAAW,GAAG,oDAAoD,SAAS;AAAA;AAAA,EAC7E;AAEJ;","names":[]}
|
|
@@ -7,8 +7,15 @@ import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
|
7
7
|
* (control-page.tsx:119/123/127) draw. Two sizes because the label sits either inside a
|
|
8
8
|
* dense panel (a legend, a menu) or above a block of page content, and one size looked
|
|
9
9
|
* wrong in the other place.
|
|
10
|
+
*
|
|
11
|
+
* `md` (0.11.0) is 11px, the rung between them: keksdose's budget-summary card labels
|
|
12
|
+
* its figures ("Assigned", "Activity", "Upcoming", "Available" —
|
|
13
|
+
* budget-summary-card:258/264/286/297) and its support thread its day divider and a message's meta line
|
|
14
|
+
* (support-thread:153/223) at `text-[11px]` by hand — 10px read as a footnote under a
|
|
15
|
+
* figure that size, 12px competed with it. Named `md` rather than slotted in order
|
|
16
|
+
* because `sm` was already the default and renaming it would move every caller.
|
|
10
17
|
*/
|
|
11
|
-
type SectionLabelSize = "xs" | "sm";
|
|
18
|
+
type SectionLabelSize = "xs" | "md" | "sm";
|
|
12
19
|
/**
|
|
13
20
|
* The small, uppercase, tracked, muted label — as a class string, per size.
|
|
14
21
|
*
|
package/dist/components/text.js
CHANGED
|
@@ -3,6 +3,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { cn } from "../lib/cn.js";
|
|
4
4
|
const SECTION_LABEL_CLASS = {
|
|
5
5
|
xs: "text-[10px] font-semibold uppercase tracking-wide text-[var(--text-muted)]",
|
|
6
|
+
md: "text-[11px] font-semibold uppercase tracking-wide text-[var(--text-muted)]",
|
|
6
7
|
sm: "text-xs font-semibold uppercase tracking-wide text-[var(--text-muted)]"
|
|
7
8
|
};
|
|
8
9
|
function SectionLabel({ as = "h3", size = "sm", className, children, ...rest }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/text.tsx"],"sourcesContent":["import type { ComponentPropsWithoutRef, ElementType, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\n\n/* ── SectionLabel ─────────────────────────────────────────────────────────── */\n\n/**\n * `xs` is 10px — the size `LegendGroup`'s title and the top-bar menus' heading row draw;\n * `sm` (default) is 12px — the size `StatTile`'s label and lenkbank's section headings\n * (control-page.tsx:119/123/127) draw. Two sizes because the label sits either inside a\n * dense panel (a legend, a menu) or above a block of page content, and one size looked\n * wrong in the other place.\n */\nexport type SectionLabelSize = \"xs\" | \"sm\";\n\n/**\n * The small, uppercase, tracked, muted label — as a class string, per size.\n *\n * Exported because `LegendGroup` and `StatTile` already draw it inline, and a class a\n * caller has to position itself (a `<th>`, a `<legend>`, a menu `<li>`) is better\n * reached as a string than wrapped in a component that only takes a `className`. The\n * uppercase is CSS, so a screen reader reads the text as written: write it in normal\n * case.\n */\nexport const SECTION_LABEL_CLASS: Record<SectionLabelSize, string> = {\n xs: \"text-[10px] font-semibold uppercase tracking-wide text-[var(--text-muted)]\",\n sm: \"text-xs font-semibold uppercase tracking-wide text-[var(--text-muted)]\",\n};\n\ntype SectionLabelElement = \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\" | \"p\" | \"span\" | \"div\" | \"legend\";\n\nexport interface SectionLabelProps extends ComponentPropsWithoutRef<\"h3\"> {\n /**\n * The element — which is the heading LEVEL, and so is the caller's to pick: the kit\n * cannot know where in the outline the label sits. Default `h3`, which is what\n * lenkbank's control page writes under its `h2` card title. Pass `span` or `p` for a\n * label that is not a heading at all (a legend group's title).\n */\n as?: SectionLabelElement;\n size?: SectionLabelSize;\n children: ReactNode;\n}\n\n/**\n * A section's small uppercase label. lenkbank spells\n * `text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400`\n * on every `<h3>` of its control page and more; keksdose's budget switcher writes the\n * 10px version on a menu row. One component, the token colour, and the level chosen\n * where the outline is known.\n */\nexport function SectionLabel({ as = \"h3\", size = \"sm\", className, children, ...rest }: SectionLabelProps) {\n const Tag = as as ElementType;\n return (\n <Tag {...rest} className={cn(SECTION_LABEL_CLASS[size], className)}>\n {children}\n </Tag>\n );\n}\n\n/* ── Caption ──────────────────────────────────────────────────────────────── */\n\n/**\n * The caption type as a class string: 11px, snug, muted. lenkbank's `CAPTION`\n * (shared/ui/caption.ts:23) — written out 31 times before it was a constant — as a\n * token colour rather than `slate-500 dark:slate-400`, so it follows the palette.\n * Exported for the same reason lenkbank's is a string: every caller positions it\n * differently (`mt-1`, `self-end pb-2`, `border-t`), and what must be one thing is the\n * type, not the box.\n */\nexport const CAPTION_CLASS = \"text-[11px] leading-snug text-[var(--text-muted)]\";\n\nexport interface CaptionProps extends ComponentPropsWithoutRef<\"p\"> {\n /** Default `p`; `span` for a caption inside a line of other content. */\n as?: \"p\" | \"span\" | \"div\";\n children: ReactNode;\n}\n\n/**\n * The small grey sentence under a field, a table or a button — prose ABOUT the thing\n * above it. Not `FieldHint`, which hides behind a field label's \"?\" so a paragraph does\n * not make one field taller than its neighbour (lenkbank feedback #27).\n */\nexport function Caption({ as = \"p\", className, children, ...rest }: CaptionProps) {\n const Tag = as as ElementType;\n return (\n <Tag {...rest} className={cn(CAPTION_CLASS, className)}>\n {children}\n </Tag>\n );\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../src/components/text.tsx"],"sourcesContent":["import type { ComponentPropsWithoutRef, ElementType, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\n\n/* ── SectionLabel ─────────────────────────────────────────────────────────── */\n\n/**\n * `xs` is 10px — the size `LegendGroup`'s title and the top-bar menus' heading row draw;\n * `sm` (default) is 12px — the size `StatTile`'s label and lenkbank's section headings\n * (control-page.tsx:119/123/127) draw. Two sizes because the label sits either inside a\n * dense panel (a legend, a menu) or above a block of page content, and one size looked\n * wrong in the other place.\n *\n * `md` (0.11.0) is 11px, the rung between them: keksdose's budget-summary card labels\n * its figures (\"Assigned\", \"Activity\", \"Upcoming\", \"Available\" —\n * budget-summary-card:258/264/286/297) and its support thread its day divider and a message's meta line\n * (support-thread:153/223) at `text-[11px]` by hand — 10px read as a footnote under a\n * figure that size, 12px competed with it. Named `md` rather than slotted in order\n * because `sm` was already the default and renaming it would move every caller.\n */\nexport type SectionLabelSize = \"xs\" | \"md\" | \"sm\";\n\n/**\n * The small, uppercase, tracked, muted label — as a class string, per size.\n *\n * Exported because `LegendGroup` and `StatTile` already draw it inline, and a class a\n * caller has to position itself (a `<th>`, a `<legend>`, a menu `<li>`) is better\n * reached as a string than wrapped in a component that only takes a `className`. The\n * uppercase is CSS, so a screen reader reads the text as written: write it in normal\n * case.\n */\nexport const SECTION_LABEL_CLASS: Record<SectionLabelSize, string> = {\n xs: \"text-[10px] font-semibold uppercase tracking-wide text-[var(--text-muted)]\",\n md: \"text-[11px] font-semibold uppercase tracking-wide text-[var(--text-muted)]\",\n sm: \"text-xs font-semibold uppercase tracking-wide text-[var(--text-muted)]\",\n};\n\ntype SectionLabelElement = \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\" | \"p\" | \"span\" | \"div\" | \"legend\";\n\nexport interface SectionLabelProps extends ComponentPropsWithoutRef<\"h3\"> {\n /**\n * The element — which is the heading LEVEL, and so is the caller's to pick: the kit\n * cannot know where in the outline the label sits. Default `h3`, which is what\n * lenkbank's control page writes under its `h2` card title. Pass `span` or `p` for a\n * label that is not a heading at all (a legend group's title).\n */\n as?: SectionLabelElement;\n size?: SectionLabelSize;\n children: ReactNode;\n}\n\n/**\n * A section's small uppercase label. lenkbank spells\n * `text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400`\n * on every `<h3>` of its control page and more; keksdose's budget switcher writes the\n * 10px version on a menu row. One component, the token colour, and the level chosen\n * where the outline is known.\n */\nexport function SectionLabel({ as = \"h3\", size = \"sm\", className, children, ...rest }: SectionLabelProps) {\n const Tag = as as ElementType;\n return (\n <Tag {...rest} className={cn(SECTION_LABEL_CLASS[size], className)}>\n {children}\n </Tag>\n );\n}\n\n/* ── Caption ──────────────────────────────────────────────────────────────── */\n\n/**\n * The caption type as a class string: 11px, snug, muted. lenkbank's `CAPTION`\n * (shared/ui/caption.ts:23) — written out 31 times before it was a constant — as a\n * token colour rather than `slate-500 dark:slate-400`, so it follows the palette.\n * Exported for the same reason lenkbank's is a string: every caller positions it\n * differently (`mt-1`, `self-end pb-2`, `border-t`), and what must be one thing is the\n * type, not the box.\n */\nexport const CAPTION_CLASS = \"text-[11px] leading-snug text-[var(--text-muted)]\";\n\nexport interface CaptionProps extends ComponentPropsWithoutRef<\"p\"> {\n /** Default `p`; `span` for a caption inside a line of other content. */\n as?: \"p\" | \"span\" | \"div\";\n children: ReactNode;\n}\n\n/**\n * The small grey sentence under a field, a table or a button — prose ABOUT the thing\n * above it. Not `FieldHint`, which hides behind a field label's \"?\" so a paragraph does\n * not make one field taller than its neighbour (lenkbank feedback #27).\n */\nexport function Caption({ as = \"p\", className, children, ...rest }: CaptionProps) {\n const Tag = as as ElementType;\n return (\n <Tag {...rest} className={cn(CAPTION_CLASS, className)}>\n {children}\n </Tag>\n );\n}\n"],"mappings":";AA4DI;AA3DJ,SAAS,UAAU;AA6BZ,MAAM,sBAAwD;AAAA,EACnE,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAuBO,SAAS,aAAa,EAAE,KAAK,MAAM,OAAO,MAAM,WAAW,UAAU,GAAG,KAAK,GAAsB;AACxG,QAAM,MAAM;AACZ,SACE,oBAAC,OAAK,GAAG,MAAM,WAAW,GAAG,oBAAoB,IAAI,GAAG,SAAS,GAC9D,UACH;AAEJ;AAYO,MAAM,gBAAgB;AAatB,SAAS,QAAQ,EAAE,KAAK,KAAK,WAAW,UAAU,GAAG,KAAK,GAAiB;AAChF,QAAM,MAAM;AACZ,SACE,oBAAC,OAAK,GAAG,MAAM,WAAW,GAAG,eAAe,SAAS,GAClD,UACH;AAEJ;","names":[]}
|
|
@@ -69,11 +69,24 @@ interface ToggleGroupBaseProps<T extends string> extends Omit<ComponentPropsWith
|
|
|
69
69
|
* {@link Select}'s `error` does. Only with `label`. */
|
|
70
70
|
error?: ReactNode;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* A line under the group saying what the CHOSEN option means — lenkbank's ToggleField
|
|
74
|
+
* `hint` (features/gear/common.tsx:97): not help behind a "?" but a caption, and one
|
|
75
|
+
* that changes as the choice does. Pass a function of the value for that; it is
|
|
76
|
+
* attached with `aria-describedby`, and a function caption is also a polite live
|
|
77
|
+
* region, because a description is read when the group is entered and not again when
|
|
78
|
+
* an arrow key changes the choice underneath it.
|
|
79
|
+
*
|
|
80
|
+
* In muted 11px text under the field (or the bare group), above an `error`.
|
|
81
|
+
*/
|
|
82
|
+
type ToggleGroupCaption<V> = ReactNode | ((value: V) => ReactNode);
|
|
72
83
|
/** The group as it has always been: one option is always the answer. */
|
|
73
84
|
interface ToggleGroupRequiredProps<T extends string> extends ToggleGroupBaseProps<T> {
|
|
74
85
|
allowEmpty?: false;
|
|
75
86
|
value: T;
|
|
76
87
|
onChange: (value: T) => void;
|
|
88
|
+
/** See {@link ToggleGroupCaption}. */
|
|
89
|
+
caption?: ToggleGroupCaption<T>;
|
|
77
90
|
}
|
|
78
91
|
/**
|
|
79
92
|
* A group that can be emptied: clicking the active option clears it, and `onChange`
|
|
@@ -89,6 +102,8 @@ interface ToggleGroupClearableProps<T extends string> extends ToggleGroupBasePro
|
|
|
89
102
|
allowEmpty: true;
|
|
90
103
|
value: T | null;
|
|
91
104
|
onChange: (value: T | null) => void;
|
|
105
|
+
/** See {@link ToggleGroupCaption}. `null` while nothing is chosen. */
|
|
106
|
+
caption?: ToggleGroupCaption<T | null>;
|
|
92
107
|
}
|
|
93
108
|
/** `allowEmpty` picks the shape, so `onChange` is typed `(T) => void` unless the group
|
|
94
109
|
* can actually emit `null` — no existing caller has a `null` to handle. */
|
|
@@ -23,7 +23,11 @@ function ToggleGroup(props) {
|
|
|
23
23
|
const errorId = useId();
|
|
24
24
|
const field = label !== void 0 && label !== null && label !== false && label !== "";
|
|
25
25
|
const hasError = field && error !== void 0 && error !== null && error !== false && error !== "";
|
|
26
|
-
const { allowEmpty: _allowEmpty, onChange: _onChange, ...rest } = restWithMode;
|
|
26
|
+
const { allowEmpty: _allowEmpty, onChange: _onChange, caption, ...rest } = restWithMode;
|
|
27
|
+
const captionId = useId();
|
|
28
|
+
const captionIsLive = typeof caption === "function";
|
|
29
|
+
const captionNode = captionIsLive ? caption(value) : caption;
|
|
30
|
+
const hasCaption = captionNode !== void 0 && captionNode !== null && captionNode !== false && captionNode !== "";
|
|
27
31
|
const choose = (next) => {
|
|
28
32
|
if (props.allowEmpty) props.onChange(next === value ? null : next);
|
|
29
33
|
else props.onChange(next);
|
|
@@ -54,7 +58,7 @@ function ToggleGroup(props) {
|
|
|
54
58
|
"aria-label": ariaLabelAttr ?? ariaLabel,
|
|
55
59
|
"aria-labelledby": field && ariaLabelAttr === void 0 && ariaLabel === void 0 ? labelId : rest["aria-labelledby"],
|
|
56
60
|
"aria-invalid": hasError || rest["aria-invalid"] || void 0,
|
|
57
|
-
"aria-describedby":
|
|
61
|
+
"aria-describedby": [rest["aria-describedby"], hasCaption && captionId, hasError && errorId].filter(Boolean).join(" ") || void 0,
|
|
58
62
|
"aria-disabled": disabled || void 0,
|
|
59
63
|
className: cn(
|
|
60
64
|
// `gap-0.5` — the same 2px as the container's own padding, so EVERY segment
|
|
@@ -135,7 +139,22 @@ function ToggleGroup(props) {
|
|
|
135
139
|
})
|
|
136
140
|
}
|
|
137
141
|
);
|
|
138
|
-
|
|
142
|
+
const captionEl = hasCaption || captionIsLive ? /* @__PURE__ */ jsx(
|
|
143
|
+
"p",
|
|
144
|
+
{
|
|
145
|
+
id: captionId,
|
|
146
|
+
"aria-live": captionIsLive ? "polite" : void 0,
|
|
147
|
+
className: cn("text-[11px] leading-snug text-[var(--text-muted)]", hasCaption && "mt-1"),
|
|
148
|
+
children: hasCaption ? captionNode : null
|
|
149
|
+
}
|
|
150
|
+
) : null;
|
|
151
|
+
if (!field) {
|
|
152
|
+
if (!captionEl) return group;
|
|
153
|
+
return /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
154
|
+
group,
|
|
155
|
+
captionEl
|
|
156
|
+
] });
|
|
157
|
+
}
|
|
139
158
|
return (
|
|
140
159
|
// `h-full` + `flex-1`: the chrome fills a grid or stretched flex row, which is what
|
|
141
160
|
// levels it with a select beside it whatever the browser makes of the select.
|
|
@@ -160,6 +179,7 @@ function ToggleGroup(props) {
|
|
|
160
179
|
)
|
|
161
180
|
}
|
|
162
181
|
),
|
|
182
|
+
captionEl,
|
|
163
183
|
hasError && /* @__PURE__ */ jsx("p", { id: errorId, className: "mt-1 text-[11px] leading-tight text-[var(--danger)]", children: error })
|
|
164
184
|
] })
|
|
165
185
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/toggle-group.tsx"],"sourcesContent":["import { useId } from \"react\";\nimport type { ComponentPropsWithoutRef, KeyboardEvent, ReactElement, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { horizontalStep } from \"../lib/direction\";\nimport { FIELD_INVALID, FloatingField } from \"./ui\";\n\nexport interface ToggleOption<T extends string> {\n value: T;\n label: string;\n className?: string;\n}\n\n/**\n * `onChange` is the group's own — the chosen VALUE, not a DOM event — so the div's\n * `onChange` is omitted rather than shadowed: leaving both in scope would give the\n * prop two incompatible meanings depending on which overload TypeScript picked.\n *\n * `children` is omitted too: this renders its `options` and nothing else, so a `children` the type\n * accepted and the component ignored would be a prop that silently does nothing —\n * worse than one that does not compile.\n */\nexport interface ToggleGroupBaseProps<T extends string>\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\" | \"children\"> {\n options: ToggleOption<T>[];\n className?: string;\n /** Applied to every option button (e.g. to tune height/rounding to match\n * adjacent fields). Per-option `className` still wins over this. */\n optionClassName?: string;\n /**\n * @deprecated Pass `aria-label` instead — the DOM spelling, which every other\n * control in this kit now answers to. Kept working because three applications ship\n * this one today; it names the group only when `aria-label` is absent.\n */\n ariaLabel?: string;\n /**\n * Show, refuse the change (Keksdose live #288: a payment dated in the future has no\n * state to set).\n *\n * Whatever `value` says stays pressed and keeps its own fill rather than going grey\n * with the rest — a reader who cannot see WHICH option is chosen has been told less\n * than before it was disabled. A caller with nothing to show passes no value, and\n * the group renders dimmed with nothing pressed, which is the shape Keksdose's\n * status picker uses for a row whose status does not exist yet.\n *\n * On the whole GROUP, not per option: a segmented control where some segments are\n * live and others are not is a menu with holes in it, and no caller here wants one.\n */\n disabled?: boolean;\n /**\n * `sm`: 12px options with `px-2 py-1` — the compact group keksdose's rule editor\n * (rule-editor:204) writes as `optionClassName=\"px-2 py-1 text-xs\"` beside a small\n * caption. `md` (default) is the size every other group has.\n */\n size?: \"sm\" | \"md\";\n /**\n * Stand in a form row as a FIELD: with a label the group wears the field's chrome —\n * border, surface, the top strip with a small static label in it, a labelled\n * {@link Select}'s height — so beside an Input or a Select it reads as one of them\n * rather than as a control with a caption over it. lenkbank builds exactly this by\n * hand as `ToggleField` (features/gear/common.tsx:97, feedback #69), and its notes\n * are why the chrome STRETCHES to its row as well as matching the select's padding:\n * a native select's height is the browser's, so a toggle a few pixels short of it\n * is levelled up by the row rather than by arithmetic.\n *\n * The label names the group (`aria-labelledby`), so `aria-label` is not needed. With\n * a label, `className` styles the field's wrapper — as on {@link Select} — and the\n * group's own box is dropped: two nested borders read as a control in a control.\n */\n label?: ReactNode;\n /** A {@link FieldHint} on the label line, as on a labelled {@link Select}. Only with\n * `label`. */\n hint?: ReactNode;\n /** The message under the field when it is wrong: paints the field's border with\n * `--danger`, marks the group `aria-invalid` and describes it with the message, as\n * {@link Select}'s `error` does. Only with `label`. */\n error?: ReactNode;\n}\n\n/** The group as it has always been: one option is always the answer. */\nexport interface ToggleGroupRequiredProps<T extends string> extends ToggleGroupBaseProps<T> {\n allowEmpty?: false;\n value: T;\n onChange: (value: T) => void;\n}\n\n/**\n * A group that can be emptied: clicking the active option clears it, and `onChange`\n * receives `null` (Keksdose's support-panel filters, where \"no filter\" is reached by\n * clicking the filter that is on).\n *\n * The options become TOGGLE BUTTONS (`aria-pressed`, in a `role=\"group\"`) rather than\n * radios. A radio cannot be unchecked by activating it — no screen reader user expects\n * a second press on \"Open, radio, checked\" to leave nothing checked, and nothing would\n * tell them it had. \"Open, toggle button, pressed\" says exactly what a press will do.\n */\nexport interface ToggleGroupClearableProps<T extends string> extends ToggleGroupBaseProps<T> {\n allowEmpty: true;\n value: T | null;\n onChange: (value: T | null) => void;\n}\n\n/** `allowEmpty` picks the shape, so `onChange` is typed `(T) => void` unless the group\n * can actually emit `null` — no existing caller has a `null` to handle. */\nexport type ToggleGroupProps<T extends string> =\n | ToggleGroupRequiredProps<T>\n | ToggleGroupClearableProps<T>;\n\n/**\n * Overloaded rather than typed by the union alone (keksdose, \"Gaps found adopting\n * 0.6.0\" #7). Inferring `T` through a union of prop shapes let TypeScript settle on\n * `string`, so `<ToggleGroup allowEmpty value={filter} onChange={setFilter} />` over a\n * `useState<Status | null>` did not compile unless the caller spelled\n * `<ToggleGroup<Status>>`. One signature per mode lets each infer `T` from its own\n * `value`/`onChange`/`options`; the third keeps a caller that forwards a\n * {@link ToggleGroupProps} union (a wrapper component) compiling.\n */\nexport function ToggleGroup<T extends string>(props: ToggleGroupClearableProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupRequiredProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupProps<T>): ReactElement {\n const {\n value,\n options,\n className,\n optionClassName,\n ariaLabel,\n disabled = false,\n size = \"md\",\n label,\n hint,\n error,\n \"aria-label\": ariaLabelAttr,\n ...restWithMode\n } = props;\n const labelId = useId();\n const errorId = useId();\n const field = label !== undefined && label !== null && label !== false && label !== \"\";\n const hasError = field && error !== undefined && error !== null && error !== false && error !== \"\";\n // Taken off the rest so neither reaches the DOM; `props` keeps them paired, which is\n // what lets the `onChange` below be called with `null` only in the mode that allows it.\n const { allowEmpty: _allowEmpty, onChange: _onChange, ...rest } = restWithMode;\n const choose = (next: T) => {\n if (props.allowEmpty) props.onChange(next === value ? null : next);\n else props.onChange(next);\n };\n const clearable = props.allowEmpty === true;\n // A radio group is ONE tab stop (the checked radio, else the first) and arrows move\n // the choice — the pattern `role=\"radiogroup\"` promises a screen-reader user. Before\n // 0.7.0 each segment was its own tab stop with no arrow keys. The clearable mode is a\n // row of toggle buttons, where separate tab stops are the pattern.\n const tabStop = options.some((o) => o.value === value) ? value : options[0]?.value;\n const onRadioKey = (e: KeyboardEvent<HTMLButtonElement>, index: number) => {\n const last = options.length - 1;\n let next: number | null = null;\n const step = horizontalStep(e.key, e.currentTarget);\n if (step !== 0) next = index + step;\n else if (e.key === \"ArrowDown\") next = index + 1;\n else if (e.key === \"ArrowUp\") next = index - 1;\n else if (e.key === \"Home\") next = 0;\n else if (e.key === \"End\") next = last;\n if (next === null) return;\n e.preventDefault();\n next = next < 0 ? last : next > last ? 0 : next;\n const buttons = e.currentTarget.parentElement?.querySelectorAll<HTMLButtonElement>(\":scope > button\");\n buttons?.[next]?.focus();\n choose(options[next].value);\n };\n const group = (\n <div\n // The audit's named example of a closed prop list (§\"Public API design\"): the\n // tour locates a step by CSS SELECTOR, so a component that drops every attribute\n // it was not expecting cannot be spotlighted at all — and Keksdose's rule editor\n // carries a comment explaining that it wraps this group in a bare <div> for\n // exactly that reason.\n //\n // `...rest` first, then the attributes the group cannot do without: a caller\n // hanging an anchor or a test id on the group must not be able to overwrite the\n // radiogroup role or the disabled state by accident. `className` is destructured\n // out entirely and merged through `cn`, so it is never in here.\n {...rest}\n role={clearable ? \"group\" : \"radiogroup\"}\n // The DOM spelling wins; `ariaLabel` is the fallback for the call sites that\n // have not moved yet.\n aria-label={ariaLabelAttr ?? ariaLabel}\n aria-labelledby={field && ariaLabelAttr === undefined && ariaLabel === undefined ? labelId : rest[\"aria-labelledby\"]}\n aria-invalid={hasError || rest[\"aria-invalid\"] || undefined}\n aria-describedby={\n hasError ? (rest[\"aria-describedby\"] ? `${rest[\"aria-describedby\"]} ${errorId}` : errorId) : rest[\"aria-describedby\"]\n }\n // `aria-disabled` on the group as well as `disabled` on each button: a radio\n // group is what the user is being refused, and a screen reader announcing\n // three separately-disabled radios does not say that.\n aria-disabled={disabled || undefined}\n className={cn(\n // `gap-0.5` — the same 2px as the container's own padding, so EVERY segment\n // sits in a uniform 2px moat and no two fills ever touch. Flush segments were\n // Keksdose live #268's rework: the pressed segment wears a saturated fill and\n // an unpressed neighbour wears a pale hover fill, and with a shared edge the\n // two rectangles read as one smeared shape — *\"the boundary of the selected\n // option and hovering next to it overlays the boundary of the selected\n // button\"*. A gap is what makes each segment its own chip; it cannot be\n // undone by a caller's per-option colour, which a hover-only fix could.\n //\n // (The hover fill is the DESKTOP half of that report: Tailwind v4 wraps every\n // `hover:` in `@media (hover: hover)`, so a phone never paints it. The half a\n // phone does see is the focus ring — see the segment's own note below.)\n \"inline-flex w-full gap-0.5 rounded-md border border-[var(--border-strong)] bg-[var(--bg-surface)] p-0.5 shadow-sm\",\n // The whole group fades, the way every other disabled control in this\n // package does; `cursor-not-allowed` is on the buttons, which is what a\n // pointer is actually over.\n disabled && \"opacity-60\",\n // Inside the field's chrome the group is only a row of segments: no border, no\n // surface, no padding of its own, and the field (not the group) is what dims.\n field && \"border-0 bg-transparent p-0 shadow-none opacity-100\",\n !field && className,\n )}\n >\n {options.map((opt, index) => {\n const active = opt.value === value;\n return (\n <button\n key={opt.value}\n type=\"button\"\n role={clearable ? undefined : \"radio\"}\n aria-checked={clearable ? undefined : active}\n aria-pressed={clearable ? active : undefined}\n disabled={disabled}\n tabIndex={clearable ? undefined : opt.value === tabStop ? 0 : -1}\n onKeyDown={clearable ? undefined : (e) => onRadioKey(e, index)}\n onClick={() => choose(opt.value)}\n className={cn(\n // `truncate` (which carries whitespace-nowrap) rather than letting a\n // label wrap: a segmented control sizes its whole row to the tallest\n // option, so one two-word option — Keksdose feedback #147's \"Where I\n // am\" — silently doubles the height of every segment beside it.\n //\n // `basis-auto` is what keeps that ellipsis a LAST resort rather than\n // the normal state (Keksdose dev#475). With flex-1's `basis-0`, a\n // shrink-to-fit group (`w-auto`) still resolves to the sum of the\n // labels' widths — and then splits it EQUALLY, so the short option\n // got 66px it did not need and \"Where I am\" got 66 of the 81 it did:\n // truncated at 1778px of free screen. Basing each segment on its own\n // content and sharing only the LEFTOVER space keeps a full-width\n // group's segments near-equal and an auto-width group's exact.\n //\n // `focus-visible` + `ring-inset`, not `focus` + an outset ring. A ring\n // is a box-shadow that spreads OUTWARD, so on a flush group it painted\n // 2px of ring over both neighbours and over the container's own border\n // — and on a phone it appeared on every TAP, because a tap focuses the\n // button. That is the other half of what live #268's rework saw\n // overlaying the selected segment's boundary. Inset keeps the ring\n // inside the segment it belongs to; focus-visible keeps it for the\n // keyboard, which is the only input that needs it.\n \"min-w-0 flex-1 basis-auto truncate rounded px-3 py-1.5 text-sm font-medium transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--border-strong)]\",\n size === \"sm\" && \"px-2 py-1 text-xs\",\n // In a field: no vertical padding and a 20px line — a `text-sm` line, the\n // same line a labelled Select holds under its label strip — so the field's\n // own `pt-4 pb-1` decides the height, as it does for the select.\n field && \"py-0 leading-5\",\n active\n ? \"bg-[var(--bg-inverse)] text-[var(--text-inverse)]\"\n : \"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]\",\n // No hover fill on a group that cannot be changed — a segment that\n // lights up under the pointer is an offer, and there is none here.\n disabled && \"cursor-not-allowed hover:bg-transparent dark:hover:bg-transparent\",\n optionClassName,\n opt.className,\n )}\n >\n {opt.label}\n </button>\n );\n })}\n </div>\n );\n if (!field) return group;\n return (\n // `h-full` + `flex-1`: the chrome fills a grid or stretched flex row, which is what\n // levels it with a select beside it whatever the browser makes of the select.\n <div className={cn(\"flex h-full flex-col\", className)}>\n <FloatingField\n className=\"flex flex-1 flex-col\"\n label={<span id={labelId}>{label}</span>}\n staticLabel\n hint={hint}\n >\n <div\n className={cn(\n \"flex flex-1 flex-col justify-center rounded-md border border-[var(--border)] bg-[var(--bg-surface)] px-1 pt-4 pb-1 shadow-sm\",\n disabled && \"bg-[var(--bg-surface-2)] opacity-60\",\n hasError && FIELD_INVALID,\n )}\n >\n {group}\n </div>\n </FloatingField>\n {hasError && (\n <p id={errorId} className=\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A;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAuBT;AAAA,cACA,SAAS,QAAQ;AAAA;AAAA;AAAA;AAAA,cAIjB,SAAS;AAAA,cACT,SACI,sDACA;AAAA;AAAA;AAAA,cAGJ,YAAY;AAAA,cACZ;AAAA,cACA,IAAI;AAAA,YACN;AAAA,YAEC,cAAI;AAAA;AAAA,UAhDA,IAAI;AAAA,QAiDX;AAAA,MAEJ,CAAC;AAAA;AAAA,EACH;AAEF,MAAI,CAAC,MAAO,QAAO;AACnB;AAAA;AAAA;AAAA,IAGE,qBAAC,SAAI,WAAW,GAAG,wBAAwB,SAAS,GAClD;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV,OAAO,oBAAC,UAAK,IAAI,SAAU,iBAAM;AAAA,UACjC,aAAW;AAAA,UACX;AAAA,UAEA;AAAA,YAAC;AAAA;AAAA,cACC,WAAW;AAAA,gBACT;AAAA,gBACA,YAAY;AAAA,gBACZ,YAAY;AAAA,cACd;AAAA,cAEC;AAAA;AAAA,UACH;AAAA;AAAA,MACF;AAAA,MACC,YACC,oBAAC,OAAE,IAAI,SAAS,WAAU,uDACvB,iBACH;AAAA,OAEJ;AAAA;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/toggle-group.tsx"],"sourcesContent":["import { useId } from \"react\";\nimport type { ComponentPropsWithoutRef, KeyboardEvent, ReactElement, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { horizontalStep } from \"../lib/direction\";\nimport { FIELD_INVALID, FloatingField } from \"./ui\";\n\nexport interface ToggleOption<T extends string> {\n value: T;\n label: string;\n className?: string;\n}\n\n/**\n * `onChange` is the group's own — the chosen VALUE, not a DOM event — so the div's\n * `onChange` is omitted rather than shadowed: leaving both in scope would give the\n * prop two incompatible meanings depending on which overload TypeScript picked.\n *\n * `children` is omitted too: this renders its `options` and nothing else, so a `children` the type\n * accepted and the component ignored would be a prop that silently does nothing —\n * worse than one that does not compile.\n */\nexport interface ToggleGroupBaseProps<T extends string>\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\" | \"children\"> {\n options: ToggleOption<T>[];\n className?: string;\n /** Applied to every option button (e.g. to tune height/rounding to match\n * adjacent fields). Per-option `className` still wins over this. */\n optionClassName?: string;\n /**\n * @deprecated Pass `aria-label` instead — the DOM spelling, which every other\n * control in this kit now answers to. Kept working because three applications ship\n * this one today; it names the group only when `aria-label` is absent.\n */\n ariaLabel?: string;\n /**\n * Show, refuse the change (Keksdose live #288: a payment dated in the future has no\n * state to set).\n *\n * Whatever `value` says stays pressed and keeps its own fill rather than going grey\n * with the rest — a reader who cannot see WHICH option is chosen has been told less\n * than before it was disabled. A caller with nothing to show passes no value, and\n * the group renders dimmed with nothing pressed, which is the shape Keksdose's\n * status picker uses for a row whose status does not exist yet.\n *\n * On the whole GROUP, not per option: a segmented control where some segments are\n * live and others are not is a menu with holes in it, and no caller here wants one.\n */\n disabled?: boolean;\n /**\n * `sm`: 12px options with `px-2 py-1` — the compact group keksdose's rule editor\n * (rule-editor:204) writes as `optionClassName=\"px-2 py-1 text-xs\"` beside a small\n * caption. `md` (default) is the size every other group has.\n */\n size?: \"sm\" | \"md\";\n /**\n * Stand in a form row as a FIELD: with a label the group wears the field's chrome —\n * border, surface, the top strip with a small static label in it, a labelled\n * {@link Select}'s height — so beside an Input or a Select it reads as one of them\n * rather than as a control with a caption over it. lenkbank builds exactly this by\n * hand as `ToggleField` (features/gear/common.tsx:97, feedback #69), and its notes\n * are why the chrome STRETCHES to its row as well as matching the select's padding:\n * a native select's height is the browser's, so a toggle a few pixels short of it\n * is levelled up by the row rather than by arithmetic.\n *\n * The label names the group (`aria-labelledby`), so `aria-label` is not needed. With\n * a label, `className` styles the field's wrapper — as on {@link Select} — and the\n * group's own box is dropped: two nested borders read as a control in a control.\n */\n label?: ReactNode;\n /** A {@link FieldHint} on the label line, as on a labelled {@link Select}. Only with\n * `label`. */\n hint?: ReactNode;\n /** The message under the field when it is wrong: paints the field's border with\n * `--danger`, marks the group `aria-invalid` and describes it with the message, as\n * {@link Select}'s `error` does. Only with `label`. */\n error?: ReactNode;\n}\n\n/**\n * A line under the group saying what the CHOSEN option means — lenkbank's ToggleField\n * `hint` (features/gear/common.tsx:97): not help behind a \"?\" but a caption, and one\n * that changes as the choice does. Pass a function of the value for that; it is\n * attached with `aria-describedby`, and a function caption is also a polite live\n * region, because a description is read when the group is entered and not again when\n * an arrow key changes the choice underneath it.\n *\n * In muted 11px text under the field (or the bare group), above an `error`.\n */\ntype ToggleGroupCaption<V> = ReactNode | ((value: V) => ReactNode);\n\n/** The group as it has always been: one option is always the answer. */\nexport interface ToggleGroupRequiredProps<T extends string> extends ToggleGroupBaseProps<T> {\n allowEmpty?: false;\n value: T;\n onChange: (value: T) => void;\n /** See {@link ToggleGroupCaption}. */\n caption?: ToggleGroupCaption<T>;\n}\n\n/**\n * A group that can be emptied: clicking the active option clears it, and `onChange`\n * receives `null` (Keksdose's support-panel filters, where \"no filter\" is reached by\n * clicking the filter that is on).\n *\n * The options become TOGGLE BUTTONS (`aria-pressed`, in a `role=\"group\"`) rather than\n * radios. A radio cannot be unchecked by activating it — no screen reader user expects\n * a second press on \"Open, radio, checked\" to leave nothing checked, and nothing would\n * tell them it had. \"Open, toggle button, pressed\" says exactly what a press will do.\n */\nexport interface ToggleGroupClearableProps<T extends string> extends ToggleGroupBaseProps<T> {\n allowEmpty: true;\n value: T | null;\n onChange: (value: T | null) => void;\n /** See {@link ToggleGroupCaption}. `null` while nothing is chosen. */\n caption?: ToggleGroupCaption<T | null>;\n}\n\n/** `allowEmpty` picks the shape, so `onChange` is typed `(T) => void` unless the group\n * can actually emit `null` — no existing caller has a `null` to handle. */\nexport type ToggleGroupProps<T extends string> =\n | ToggleGroupRequiredProps<T>\n | ToggleGroupClearableProps<T>;\n\n/**\n * Overloaded rather than typed by the union alone (keksdose, \"Gaps found adopting\n * 0.6.0\" #7). Inferring `T` through a union of prop shapes let TypeScript settle on\n * `string`, so `<ToggleGroup allowEmpty value={filter} onChange={setFilter} />` over a\n * `useState<Status | null>` did not compile unless the caller spelled\n * `<ToggleGroup<Status>>`. One signature per mode lets each infer `T` from its own\n * `value`/`onChange`/`options`; the third keeps a caller that forwards a\n * {@link ToggleGroupProps} union (a wrapper component) compiling.\n */\nexport function ToggleGroup<T extends string>(props: ToggleGroupClearableProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupRequiredProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupProps<T>): ReactElement {\n const {\n value,\n options,\n className,\n optionClassName,\n ariaLabel,\n disabled = false,\n size = \"md\",\n label,\n hint,\n error,\n \"aria-label\": ariaLabelAttr,\n ...restWithMode\n } = props;\n const labelId = useId();\n const errorId = useId();\n const field = label !== undefined && label !== null && label !== false && label !== \"\";\n const hasError = field && error !== undefined && error !== null && error !== false && error !== \"\";\n // Taken off the rest so neither reaches the DOM; `props` keeps them paired, which is\n // what lets the `onChange` below be called with `null` only in the mode that allows it.\n const { allowEmpty: _allowEmpty, onChange: _onChange, caption, ...rest } = restWithMode;\n const captionId = useId();\n const captionIsLive = typeof caption === \"function\";\n const captionNode = captionIsLive ? (caption as (v: T | null) => ReactNode)(value) : caption;\n const hasCaption = captionNode !== undefined && captionNode !== null && captionNode !== false && captionNode !== \"\";\n const choose = (next: T) => {\n if (props.allowEmpty) props.onChange(next === value ? null : next);\n else props.onChange(next);\n };\n const clearable = props.allowEmpty === true;\n // A radio group is ONE tab stop (the checked radio, else the first) and arrows move\n // the choice — the pattern `role=\"radiogroup\"` promises a screen-reader user. Before\n // 0.7.0 each segment was its own tab stop with no arrow keys. The clearable mode is a\n // row of toggle buttons, where separate tab stops are the pattern.\n const tabStop = options.some((o) => o.value === value) ? value : options[0]?.value;\n const onRadioKey = (e: KeyboardEvent<HTMLButtonElement>, index: number) => {\n const last = options.length - 1;\n let next: number | null = null;\n const step = horizontalStep(e.key, e.currentTarget);\n if (step !== 0) next = index + step;\n else if (e.key === \"ArrowDown\") next = index + 1;\n else if (e.key === \"ArrowUp\") next = index - 1;\n else if (e.key === \"Home\") next = 0;\n else if (e.key === \"End\") next = last;\n if (next === null) return;\n e.preventDefault();\n next = next < 0 ? last : next > last ? 0 : next;\n const buttons = e.currentTarget.parentElement?.querySelectorAll<HTMLButtonElement>(\":scope > button\");\n buttons?.[next]?.focus();\n choose(options[next].value);\n };\n const group = (\n <div\n // The audit's named example of a closed prop list (§\"Public API design\"): the\n // tour locates a step by CSS SELECTOR, so a component that drops every attribute\n // it was not expecting cannot be spotlighted at all — and Keksdose's rule editor\n // carries a comment explaining that it wraps this group in a bare <div> for\n // exactly that reason.\n //\n // `...rest` first, then the attributes the group cannot do without: a caller\n // hanging an anchor or a test id on the group must not be able to overwrite the\n // radiogroup role or the disabled state by accident. `className` is destructured\n // out entirely and merged through `cn`, so it is never in here.\n {...rest}\n role={clearable ? \"group\" : \"radiogroup\"}\n // The DOM spelling wins; `ariaLabel` is the fallback for the call sites that\n // have not moved yet.\n aria-label={ariaLabelAttr ?? ariaLabel}\n aria-labelledby={field && ariaLabelAttr === undefined && ariaLabel === undefined ? labelId : rest[\"aria-labelledby\"]}\n aria-invalid={hasError || rest[\"aria-invalid\"] || undefined}\n aria-describedby={\n [rest[\"aria-describedby\"], hasCaption && captionId, hasError && errorId].filter(Boolean).join(\" \") || undefined\n }\n // `aria-disabled` on the group as well as `disabled` on each button: a radio\n // group is what the user is being refused, and a screen reader announcing\n // three separately-disabled radios does not say that.\n aria-disabled={disabled || undefined}\n className={cn(\n // `gap-0.5` — the same 2px as the container's own padding, so EVERY segment\n // sits in a uniform 2px moat and no two fills ever touch. Flush segments were\n // Keksdose live #268's rework: the pressed segment wears a saturated fill and\n // an unpressed neighbour wears a pale hover fill, and with a shared edge the\n // two rectangles read as one smeared shape — *\"the boundary of the selected\n // option and hovering next to it overlays the boundary of the selected\n // button\"*. A gap is what makes each segment its own chip; it cannot be\n // undone by a caller's per-option colour, which a hover-only fix could.\n //\n // (The hover fill is the DESKTOP half of that report: Tailwind v4 wraps every\n // `hover:` in `@media (hover: hover)`, so a phone never paints it. The half a\n // phone does see is the focus ring — see the segment's own note below.)\n \"inline-flex w-full gap-0.5 rounded-md border border-[var(--border-strong)] bg-[var(--bg-surface)] p-0.5 shadow-sm\",\n // The whole group fades, the way every other disabled control in this\n // package does; `cursor-not-allowed` is on the buttons, which is what a\n // pointer is actually over.\n disabled && \"opacity-60\",\n // Inside the field's chrome the group is only a row of segments: no border, no\n // surface, no padding of its own, and the field (not the group) is what dims.\n field && \"border-0 bg-transparent p-0 shadow-none opacity-100\",\n !field && className,\n )}\n >\n {options.map((opt, index) => {\n const active = opt.value === value;\n return (\n <button\n key={opt.value}\n type=\"button\"\n role={clearable ? undefined : \"radio\"}\n aria-checked={clearable ? undefined : active}\n aria-pressed={clearable ? active : undefined}\n disabled={disabled}\n tabIndex={clearable ? undefined : opt.value === tabStop ? 0 : -1}\n onKeyDown={clearable ? undefined : (e) => onRadioKey(e, index)}\n onClick={() => choose(opt.value)}\n className={cn(\n // `truncate` (which carries whitespace-nowrap) rather than letting a\n // label wrap: a segmented control sizes its whole row to the tallest\n // option, so one two-word option — Keksdose feedback #147's \"Where I\n // am\" — silently doubles the height of every segment beside it.\n //\n // `basis-auto` is what keeps that ellipsis a LAST resort rather than\n // the normal state (Keksdose dev#475). With flex-1's `basis-0`, a\n // shrink-to-fit group (`w-auto`) still resolves to the sum of the\n // labels' widths — and then splits it EQUALLY, so the short option\n // got 66px it did not need and \"Where I am\" got 66 of the 81 it did:\n // truncated at 1778px of free screen. Basing each segment on its own\n // content and sharing only the LEFTOVER space keeps a full-width\n // group's segments near-equal and an auto-width group's exact.\n //\n // `focus-visible` + `ring-inset`, not `focus` + an outset ring. A ring\n // is a box-shadow that spreads OUTWARD, so on a flush group it painted\n // 2px of ring over both neighbours and over the container's own border\n // — and on a phone it appeared on every TAP, because a tap focuses the\n // button. That is the other half of what live #268's rework saw\n // overlaying the selected segment's boundary. Inset keeps the ring\n // inside the segment it belongs to; focus-visible keeps it for the\n // keyboard, which is the only input that needs it.\n \"min-w-0 flex-1 basis-auto truncate rounded px-3 py-1.5 text-sm font-medium transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--border-strong)]\",\n size === \"sm\" && \"px-2 py-1 text-xs\",\n // In a field: no vertical padding and a 20px line — a `text-sm` line, the\n // same line a labelled Select holds under its label strip — so the field's\n // own `pt-4 pb-1` decides the height, as it does for the select.\n field && \"py-0 leading-5\",\n active\n ? \"bg-[var(--bg-inverse)] text-[var(--text-inverse)]\"\n : \"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]\",\n // No hover fill on a group that cannot be changed — a segment that\n // lights up under the pointer is an offer, and there is none here.\n disabled && \"cursor-not-allowed hover:bg-transparent dark:hover:bg-transparent\",\n optionClassName,\n opt.className,\n )}\n >\n {opt.label}\n </button>\n );\n })}\n </div>\n );\n // Rendered whenever the caption is — `aria-live` must be on the element BEFORE its\n // text changes, or the change is not announced — but empty (no height, no margin)\n // when there is nothing to say, so a function caption that returns null for some\n // options leaves no gap. Empty rather than `hidden`: some readers do not announce\n // text that appears inside an element coming back from `display: none`.\n const captionEl =\n hasCaption || captionIsLive ? (\n <p\n id={captionId}\n aria-live={captionIsLive ? \"polite\" : undefined}\n className={cn(\"text-[11px] leading-snug text-[var(--text-muted)]\", hasCaption && \"mt-1\")}\n >\n {hasCaption ? captionNode : null}\n </p>\n ) : null;\n if (!field) {\n if (!captionEl) return group;\n // The group keeps its `className`, as without a caption; the wrapper only stacks.\n return (\n <div className=\"min-w-0\">\n {group}\n {captionEl}\n </div>\n );\n }\n return (\n // `h-full` + `flex-1`: the chrome fills a grid or stretched flex row, which is what\n // levels it with a select beside it whatever the browser makes of the select.\n <div className={cn(\"flex h-full flex-col\", className)}>\n <FloatingField\n className=\"flex flex-1 flex-col\"\n label={<span id={labelId}>{label}</span>}\n staticLabel\n hint={hint}\n >\n <div\n className={cn(\n \"flex flex-1 flex-col justify-center rounded-md border border-[var(--border)] bg-[var(--bg-surface)] px-1 pt-4 pb-1 shadow-sm\",\n disabled && \"bg-[var(--bg-surface-2)] opacity-60\",\n hasError && FIELD_INVALID,\n )}\n >\n {group}\n </div>\n </FloatingField>\n {captionEl}\n {hasError && (\n <p id={errorId} className=\"mt-1 text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </p>\n )}\n </div>\n );\n}\n"],"mappings":";AAgPU,cA0EJ,YA1EI;AAhPV,SAAS,aAAa;AAEtB,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAC/B,SAAS,eAAe,qBAAqB;AAmItC,SAAS,YAA8B,OAA0C;AACtF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,UAAU,MAAM;AACtB,QAAM,UAAU,MAAM;AACtB,QAAM,QAAQ,UAAU,UAAa,UAAU,QAAQ,UAAU,SAAS,UAAU;AACpF,QAAM,WAAW,SAAS,UAAU,UAAa,UAAU,QAAQ,UAAU,SAAS,UAAU;AAGhG,QAAM,EAAE,YAAY,aAAa,UAAU,WAAW,SAAS,GAAG,KAAK,IAAI;AAC3E,QAAM,YAAY,MAAM;AACxB,QAAM,gBAAgB,OAAO,YAAY;AACzC,QAAM,cAAc,gBAAiB,QAAuC,KAAK,IAAI;AACrF,QAAM,aAAa,gBAAgB,UAAa,gBAAgB,QAAQ,gBAAgB,SAAS,gBAAgB;AACjH,QAAM,SAAS,CAAC,SAAY;AAC1B,QAAI,MAAM,WAAY,OAAM,SAAS,SAAS,QA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AAA,IAGE,qBAAC,SAAI,WAAW,GAAG,wBAAwB,SAAS,GAClD;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV,OAAO,oBAAC,UAAK,IAAI,SAAU,iBAAM;AAAA,UACjC,aAAW;AAAA,UACX;AAAA,UAEA;AAAA,YAAC;AAAA;AAAA,cACC,WAAW;AAAA,gBACT;AAAA,gBACA,YAAY;AAAA,gBACZ,YAAY;AAAA,cACd;AAAA,cAEC;AAAA;AAAA,UACH;AAAA;AAAA,MACF;AAAA,MACC;AAAA,MACA,YACC,oBAAC,OAAE,IAAI,SAAS,WAAU,uDACvB,iBACH;AAAA,OAEJ;AAAA;AAEJ;","names":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
3
3
|
import { AnchorRect } from '../hooks/use-anchored-rect.js';
|
|
4
|
+
export { CLIPS_ATTRIBUTE } from '../lib/clipping.js';
|
|
4
5
|
|
|
5
6
|
/** Where the bubble sits. `start` / `end` follow the reading direction — `end` is the
|
|
6
7
|
* right in LTR and the left in RTL — and are what a layout that mirrors should ask
|
|
@@ -25,8 +26,8 @@ interface TooltipProps extends ComponentPropsWithoutRef<"span"> {
|
|
|
25
26
|
/**
|
|
26
27
|
* Where the bubble lives. Left out (the default since 0.10.0), the tooltip decides for
|
|
27
28
|
* itself: the bubble stays next to the trigger unless an ancestor clips or scrolls
|
|
28
|
-
* (`overflow` other than `visible
|
|
29
|
-
* scroll container" below. `true` always portals, `false` never does; both are exactly
|
|
29
|
+
* (`overflow` other than `visible`, or the {@link CLIPS_ATTRIBUTE} marker), in which
|
|
30
|
+
* case it is portalled — see "Inside a scroll container" below. `true` always portals, `false` never does; both are exactly
|
|
30
31
|
* what they were before the default existed.
|
|
31
32
|
*/
|
|
32
33
|
portal?: boolean;
|
|
@@ -89,7 +90,14 @@ interface TooltipProps extends ComponentPropsWithoutRef<"span"> {
|
|
|
89
90
|
* being one: every tooltip in a table, a drawer or a scrolling card had to remember it,
|
|
90
91
|
* and the ones that forgot were only found by someone scrolling sideways. So with
|
|
91
92
|
* `portal` left out, the tooltip looks for a clipping ancestor itself — any element
|
|
92
|
-
* between it and `<body>` whose computed `overflow-x` / `overflow-y` is not `visible
|
|
93
|
+
* between it and `<body>` whose computed `overflow-x` / `overflow-y` is not `visible`,
|
|
94
|
+
* or that carries {@link CLIPS_ATTRIBUTE} (`data-clips`). The marker is what makes the
|
|
95
|
+
* answer the same under test: jsdom computes no Tailwind, so there every scroller
|
|
96
|
+
* reads `visible` and a table-cell tooltip used to stay in place — its always-mounted
|
|
97
|
+
* bubble then repeated the label in the cell's accessible name and `textContent`
|
|
98
|
+
* ("CheckingChecking"), and apps pinned `portal` to stop it. The kit's own scrollers
|
|
99
|
+
* are marked, so a tooltip in a DataTable or Table cell portals in jsdom exactly as it
|
|
100
|
+
* does in the browser.
|
|
93
101
|
* It looks at MOUNT, not only on open: dev#488's phantom scroll is caused by a bubble
|
|
94
102
|
* nobody opened, so a check that waited for the hover would find the damage already
|
|
95
103
|
* done. It looks again on every open, for a container that started scrolling after
|
|
@@ -14,6 +14,7 @@ import { useEscapeKey } from "../hooks/use-dismiss.js";
|
|
|
14
14
|
import { useAnchoredRect } from "../hooks/use-anchored-rect.js";
|
|
15
15
|
import { dirOf } from "../lib/direction.js";
|
|
16
16
|
import { hasClippingAncestor } from "../lib/clipping.js";
|
|
17
|
+
import { CLIPS_ATTRIBUTE } from "../lib/clipping.js";
|
|
17
18
|
function physicalSide(side, dir) {
|
|
18
19
|
if (side === "start") return dir === "rtl" ? "right" : "left";
|
|
19
20
|
if (side === "end") return dir === "rtl" ? "left" : "right";
|
|
@@ -277,6 +278,7 @@ function PortalBubble({
|
|
|
277
278
|
);
|
|
278
279
|
}
|
|
279
280
|
export {
|
|
281
|
+
CLIPS_ATTRIBUTE,
|
|
280
282
|
Tooltip,
|
|
281
283
|
placeTooltip
|
|
282
284
|
};
|