@tristan2828/ui-foundation 4.82.0 → 4.84.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 +1 -1
- package/conventions/docs/add-an-entity.md +4 -4
- package/conventions/docs/cell-patterns.md +111 -50
- package/conventions/docs/design-language.md +75 -30
- package/conventions/docs/entity-plan-template.md +3 -3
- package/dist/components/app/data-table.d.ts +36 -8
- package/dist/components/app/data-table.js +142 -90
- package/dist/components/app/freshness.d.ts +14 -0
- package/dist/components/app/freshness.js +25 -0
- package/dist/components/app/list-header.d.ts +44 -0
- package/dist/components/app/list-header.js +27 -0
- package/dist/components/app/needs-you.d.ts +19 -0
- package/dist/components/app/needs-you.js +30 -0
- package/dist/components/app/part-empty.d.ts +20 -0
- package/dist/components/app/part-empty.js +17 -0
- package/dist/components/app/timeline.d.ts +25 -0
- package/dist/components/app/timeline.js +31 -0
- package/dist/components/app/value-list.d.ts +14 -0
- package/dist/components/app/value-list.js +13 -0
- package/dist/components/app/widget-card.d.ts +9 -1
- package/dist/components/app/widget-card.js +3 -2
- package/dist/hooks/use-table-url-state.d.ts +19 -1
- package/dist/hooks/use-table-url-state.js +31 -3
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/lib/freshness.d.ts +6 -0
- package/dist/lib/freshness.js +37 -0
- package/package.json +1 -1
- package/styles/theme.css +6 -0
|
@@ -22,6 +22,7 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel
|
|
|
22
22
|
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from '../ui/empty.js';
|
|
23
23
|
import { Sheet, SheetContent, SheetHeader, SheetTitle } from '../ui/sheet.js';
|
|
24
24
|
import { Skeleton } from '../ui/skeleton.js';
|
|
25
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip.js';
|
|
25
26
|
import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
|
|
26
27
|
import { EditInPlaceContext } from './edit-in-place.js';
|
|
27
28
|
import { EditInPlaceStore } from './edit-in-place-store.js';
|
|
@@ -94,6 +95,40 @@ function GroupMenu({ groupings, value, onValueChange, }) {
|
|
|
94
95
|
const current = groupings.find((grouping) => grouping.id === value);
|
|
95
96
|
return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { render: _jsx(Button, { variant: "outline", size: "sm", "data-slot": "data-table-group-menu" }), children: [_jsx(ListTreeIcon, { "aria-hidden": "true" }), current ? `Group: ${current.label}` : 'Group'] }), _jsx(DropdownMenuContent, { align: "end", className: "w-48", children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Group by" }), _jsxs(DropdownMenuRadioGroup, { value: current?.id ?? NO_GROUPING, onValueChange: (next) => onValueChange(next === NO_GROUPING ? '' : String(next)), children: [_jsx(DropdownMenuRadioItem, { value: NO_GROUPING, closeOnClick: true, children: "None" }), groupings.map((grouping) => (_jsx(DropdownMenuRadioItem, { value: grouping.id, closeOnClick: true, children: grouping.label }, grouping.id)))] })] }) })] }));
|
|
96
97
|
}
|
|
98
|
+
// The rows-per-page menu in the pagination bar (`pageSizes`): a radio list
|
|
99
|
+
// that closes on a pick. The button says the size in words of its own
|
|
100
|
+
// ("50 rows", as the list page standard drew it), and the menu says
|
|
101
|
+
// what it is.
|
|
102
|
+
function PageSizeMenu({ pageSizes, value, onValueChange, }) {
|
|
103
|
+
return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { render: _jsx(Button, { variant: "outline", size: "sm", "data-slot": "data-table-page-size", "aria-label": `${value} rows per page` }), children: [value, " rows", _jsx(ChevronDownIcon, { "aria-hidden": "true" })] }), _jsx(DropdownMenuContent, { align: "end", className: "w-40", children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Rows per page" }), _jsx(DropdownMenuRadioGroup, { value: String(value), onValueChange: (next) => onValueChange(Number(next)), children: pageSizes.map((size) => (_jsx(DropdownMenuRadioItem, { value: String(size), closeOnClick: true, children: size }, size))) })] }) })] }));
|
|
104
|
+
}
|
|
105
|
+
// A cell's text cut to one line (`meta.clip`). Only when it is cut does it
|
|
106
|
+
// take a tab stop and a tooltip with the whole text, on hover and on focus;
|
|
107
|
+
// re-measured on every render (the text may change) and on every resize.
|
|
108
|
+
function ClippedText({ maxWidth, children }) {
|
|
109
|
+
const ref = useRef(null);
|
|
110
|
+
const [fullText, setFullText] = useState(null);
|
|
111
|
+
const measure = () => {
|
|
112
|
+
const element = ref.current;
|
|
113
|
+
if (!element)
|
|
114
|
+
return;
|
|
115
|
+
const isCut = element.scrollWidth > element.clientWidth + 0.5;
|
|
116
|
+
setFullText(isCut ? element.textContent?.trim() || null : null);
|
|
117
|
+
};
|
|
118
|
+
useLayoutEffect(measure);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
const element = ref.current;
|
|
121
|
+
if (!element)
|
|
122
|
+
return;
|
|
123
|
+
const observer = new ResizeObserver(() => measure());
|
|
124
|
+
observer.observe(element);
|
|
125
|
+
return () => observer.disconnect();
|
|
126
|
+
}, []);
|
|
127
|
+
return (_jsxs(Tooltip, { disabled: fullText === null, children: [_jsx(TooltipTrigger, { render: _jsx("span", { ref: ref, "data-slot": "data-table-clip", className: CLIP_CLASS,
|
|
128
|
+
// Never more than 60% of the table's area, so on a phone the
|
|
129
|
+
// cut column leaves the name and the rest room.
|
|
130
|
+
style: { maxWidth: `min(${maxWidth}, 60cqw)` }, tabIndex: fullText === null ? undefined : 0 }), children: children }), _jsx(TooltipContent, { className: "max-w-sm break-words whitespace-normal", children: fullText })] }));
|
|
131
|
+
}
|
|
97
132
|
// Whether the detail panel (`detailPanel`) fits beside the table, or opens
|
|
98
133
|
// as a bottom sheet. Wide on the server and wherever matchMedia is missing
|
|
99
134
|
// (a test's DOM), so markup never depends on it.
|
|
@@ -121,44 +156,49 @@ function TableSkeleton({ columnCount }) {
|
|
|
121
156
|
// The pinned cell gets an opaque background, not `bg-inherit`: the zebra
|
|
122
157
|
// stripe (table.tsx) is a *translucent* color, so inheriting it would let
|
|
123
158
|
// the columns scrolling behind show through at 40% opacity — exactly the
|
|
124
|
-
// bleed-through a solid background avoids.
|
|
125
|
-
// pre-mixed onto the page (--table-stripe), so the stripe
|
|
126
|
-
// row's width (issue #92); `:where()` keeps that rule's
|
|
127
|
-
// background's, so the
|
|
128
|
-
const PINNED_CELL_CLASS = 'z-10 bg-background
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// an inset shadow rather than a border, so nothing reflows.
|
|
132
|
-
const PINNED_COLUMN_CLASS = `sticky left-0 border-r ${PINNED_CELL_CLASS} group-hover/row:bg-accent ` +
|
|
133
|
-
'group-hover/row:shadow-[inset_3px_0_0_0_var(--primary)]';
|
|
134
|
-
// The right-edge mirror, opaque for the same reason, but with no hover
|
|
135
|
-
// highlight (issue #103): it holds the row's actions, which name nothing,
|
|
136
|
-
// so lighting it too read as a second selected thing. Only the first
|
|
137
|
-
// column marks the hovered row.
|
|
159
|
+
// bleed-through a solid background avoids. With `striped`, on an even row
|
|
160
|
+
// it's the stripe pre-mixed onto the page (--table-stripe), so the stripe
|
|
161
|
+
// runs the whole row's width (issue #92); `:where()` keeps that rule's
|
|
162
|
+
// specificity at the background's, so the row's hover below still wins.
|
|
163
|
+
const PINNED_CELL_CLASS = 'z-10 bg-background';
|
|
164
|
+
const PINNED_STRIPED_CELL_CLASS = '[:where(tbody>tr:nth-child(even))>&]:bg-(--table-stripe)';
|
|
165
|
+
const PINNED_COLUMN_CLASS = `sticky left-0 border-r ${PINNED_CELL_CLASS}`;
|
|
138
166
|
const PINNED_LAST_COLUMN_CLASS = `sticky right-0 border-l ${PINNED_CELL_CLASS}`;
|
|
139
167
|
// The totals row's label, pinned with the first column (`totals`): the
|
|
140
168
|
// same opaque cell, with no hover, since the row isn't one to pick.
|
|
141
|
-
const PINNED_TOTALS_LABEL_CLASS =
|
|
169
|
+
const PINNED_TOTALS_LABEL_CLASS = PINNED_COLUMN_CLASS;
|
|
170
|
+
// `striped` off (the default, 4.83): table.tsx's zebra taken back off the
|
|
171
|
+
// body (tailwind-merge drops its even-row tint for this one), so rows are
|
|
172
|
+
// told apart by the line under each.
|
|
173
|
+
const UNSTRIPED_BODY_CLASS = '[&_tr:nth-child(even)]:bg-transparent';
|
|
174
|
+
// A body row under the pointer (4.83): every cell, pinned ones included,
|
|
175
|
+
// in --table-hover (solid, so a pinned cell can wear it), with a bar in
|
|
176
|
+
// --primary on the first cell, so it reads without colour too; an inset
|
|
177
|
+
// shadow rather than a border, so nothing reflows. On a cell, not the row,
|
|
178
|
+
// so it covers a stripe and a pinned cell's opaque background alike
|
|
179
|
+
// (`.row:hover > td` outranks both). Muted text on it takes the darker grey
|
|
180
|
+
// a highlighted row's does (theme.css --table-hover). table.tsx's own row
|
|
181
|
+
// hover comes off: it would sit under the cells' tint anyway. A row that
|
|
182
|
+
// opens a record adds the hand cursor (SELECTABLE_ROW_CLASS); one edited in
|
|
183
|
+
// place keeps the arrow. A highlighted or picked row keeps its own look.
|
|
184
|
+
const HOVER_ROW_CLASS = 'hover:bg-transparent hover:[--muted-foreground:var(--table-highlight-muted-foreground)] ' +
|
|
185
|
+
'hover:[&>td]:bg-(--table-hover) hover:[&>td:first-child]:shadow-[inset_3px_0_0_0_var(--primary)]';
|
|
186
|
+
// Its bar and a focused row's ring, both on the first cell's shadow.
|
|
187
|
+
const HOVER_FOCUSED_ROW_CLASS = 'focus-visible:hover:[&>td:first-child]:shadow-[inset_3px_0_0_0_var(--primary),inset_0_2px_0_0_var(--ring),inset_0_-2px_0_0_var(--ring)]';
|
|
188
|
+
// A column's `meta.clip`: one line, cut at `meta.maxWidth` with an ellipsis.
|
|
189
|
+
const DEFAULT_CLIP_WIDTH = '24rem';
|
|
190
|
+
const CLIP_CLASS = 'block truncate rounded-sm outline-none focus-visible:ring-3 focus-visible:ring-ring/50';
|
|
142
191
|
// A pinned first column's content, capped below md at 45% of the table's
|
|
143
192
|
// scroll area (`cqw`: the container is an inline-size query container)
|
|
144
193
|
// and wrapping, so a long title can't widen the column past the screen
|
|
145
194
|
// and leave every other column scrolling underneath it (issue #91).
|
|
146
195
|
// Wider screens are unchanged: the column sizes to its content.
|
|
147
196
|
const PINNED_FIRST_CONTENT_CLASS = 'max-md:max-w-[45cqw] max-md:whitespace-normal max-md:break-words';
|
|
148
|
-
// Hover highlights the pinned cell, not the whole row. A row-level hover
|
|
149
|
-
// cannot be made consistent against the zebra stripe: `tr:nth-child(even)`
|
|
150
|
-
// is specificity (0,2,1) and `tr:hover` is (0,2,0), so the stripe wins and
|
|
151
|
-
// even rows stay unlit — odd rows highlight, even rows don't.
|
|
152
|
-
// `hover:bg-transparent` drops table.tsx's own `hover:bg-muted/50` via
|
|
153
|
-
// tailwind-merge so no row hover is attempted at all. The pinned cell is
|
|
154
|
-
// the better target anyway: it names the row, it sits on an opaque
|
|
155
|
-
// background so it reads identically on striped and unstriped rows, and it
|
|
156
|
-
// stays on screen when the table is scrolled right.
|
|
157
|
-
const ROW_GROUP_CLASS = 'group/row hover:bg-transparent';
|
|
158
197
|
// `highlightRow`: the wash on every cell, so it covers the zebra stripe
|
|
159
198
|
// (on the row) and the pinned cells' opaque backgrounds (on the cell, and
|
|
160
|
-
// one class weaker than this)
|
|
161
|
-
//
|
|
199
|
+
// one class weaker than this); hover leaves it as it is, so "next up" never
|
|
200
|
+
// reads as the pointer's row. A bar in info-text on the first cell, as
|
|
201
|
+
// hover's is in --primary, so it reads without colour too.
|
|
162
202
|
// Inside, muted text takes the darker grey the wash needs (theme.css).
|
|
163
203
|
const HIGHLIGHTED_ROW_CLASS = '[--muted-foreground:var(--table-highlight-muted-foreground)] [&>td]:bg-(--table-highlight) ' +
|
|
164
204
|
'[&>td:first-child]:shadow-[inset_3px_0_0_0_var(--info-text)]';
|
|
@@ -225,12 +265,13 @@ const WITH_DETAIL_OPEN_CLASS = 'grid-cols-[minmax(0,1fr)_minmax(18rem,26rem)]';
|
|
|
225
265
|
const DETAIL_ASIDE_CLASS = 'sticky top-4 flex max-h-[calc(100dvh-2rem)] min-w-0 flex-col gap-3 overflow-y-auto rounded-lg border ' +
|
|
226
266
|
'border-border bg-card p-4 text-card-foreground';
|
|
227
267
|
const EMPTY_KEYS = new Set();
|
|
228
|
-
// `width="content"`:
|
|
229
|
-
// need (`w-fit` over the table's own `w-full`), at least
|
|
230
|
-
// width it last had loaded while it shows another state
|
|
231
|
-
// (--data-table-last-width),
|
|
232
|
-
|
|
233
|
-
|
|
268
|
+
// `width="content"`: the table and its pagination (not the toolbar) as wide
|
|
269
|
+
// as the columns need (`w-fit` over the table's own `w-full`), at least
|
|
270
|
+
// 36rem, or the width it last had loaded while it shows another state
|
|
271
|
+
// (--data-table-last-width), and never wider than the area: `min()` keeps
|
|
272
|
+
// the minimum from pushing past a phone's width, since a min-width
|
|
273
|
+
// outranks a max-width.
|
|
274
|
+
const CONTENT_WIDTH_CLASS = 'w-fit max-w-full min-w-[min(100%,max(--spacing(144),var(--data-table-last-width,0px)))]';
|
|
234
275
|
// A second horizontal scrollbar, stuck to the viewport's bottom edge. The
|
|
235
276
|
// real one sits directly under the last row, which on a full page is
|
|
236
277
|
// off-screen until you have already scrolled past every row. Only rendered
|
|
@@ -320,7 +361,7 @@ function useStickyHeadings(containerRef, enabled) {
|
|
|
320
361
|
}, [containerRef, enabled]);
|
|
321
362
|
return { scrollsSideways, headHeight };
|
|
322
363
|
}
|
|
323
|
-
export function DataTable({ columns, data, total, page, pageSize, onPageChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = '
|
|
364
|
+
export function DataTable({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = 'content', striped = false, groupBy, groupSummary, stickyGroupHeadings = false, stickyTop = '0px', header: showHeader = true, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel = 'Details', }) {
|
|
324
365
|
// The switch's own state, for a table that doesn't pass `layout`.
|
|
325
366
|
const [ownLayout, setOwnLayout] = useState('table');
|
|
326
367
|
const requestedLayout = layoutProp ?? ownLayout;
|
|
@@ -429,16 +470,19 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
|
|
|
429
470
|
const isSuccessView = !error && !isLoading && !isPastLastPage && !isEmpty;
|
|
430
471
|
// `width="content"`: the width the table last had loaded, kept while it
|
|
431
472
|
// shows another state.
|
|
473
|
+
// A card layout's grid takes the whole width whatever `width` says.
|
|
474
|
+
const fitsColumns = width === 'content' && !cardLayout;
|
|
432
475
|
const root = useRef(null);
|
|
476
|
+
const body = useRef(null);
|
|
433
477
|
const [lastWidth, setLastWidth] = useState(null);
|
|
434
478
|
useLayoutEffect(() => {
|
|
435
|
-
const element =
|
|
436
|
-
if (
|
|
479
|
+
const element = body.current;
|
|
480
|
+
if (!fitsColumns || !isSuccessView || !element)
|
|
437
481
|
return;
|
|
438
482
|
const observer = new ResizeObserver(() => setLastWidth(Math.round(element.getBoundingClientRect().width)));
|
|
439
483
|
observer.observe(element);
|
|
440
484
|
return () => observer.disconnect();
|
|
441
|
-
}, [
|
|
485
|
+
}, [fitsColumns, isSuccessView]);
|
|
442
486
|
const containerRef = useRef(null);
|
|
443
487
|
const { barRef, isOverflowing, scrollWidth } = useBottomScrollbar(containerRef, Boolean(pinFirstColumn) && isSuccessView && !cardLayout);
|
|
444
488
|
const rows = table.getRowModel().rows;
|
|
@@ -577,68 +621,76 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
|
|
|
577
621
|
// One body row, the same in a plain table and a grouped one.
|
|
578
622
|
const renderRow = (row, key = row.id) => {
|
|
579
623
|
const isSelected = Boolean(detailPanel) && key === selectedKey;
|
|
580
|
-
|
|
624
|
+
const isHighlighted = Boolean(highlightRow?.(row.original));
|
|
625
|
+
const hovers = !isHighlighted && !isSelected;
|
|
626
|
+
return (_jsx(TableRow, { "data-highlighted": isHighlighted || undefined, ...(rowsOpen
|
|
581
627
|
? {
|
|
582
628
|
'data-row-key': key,
|
|
583
629
|
...(detailPanel ? { 'data-selected': isSelected || undefined, 'aria-selected': isSelected } : {}),
|
|
584
630
|
tabIndex: key === tabStopKey ? 0 : -1,
|
|
585
631
|
onClickCapture: (event) => onRowClick(event, { key, rowId: row.id }),
|
|
586
632
|
}
|
|
587
|
-
: {}), className: cn(
|
|
633
|
+
: {}), className: cn('hover:bg-transparent', hovers && HOVER_ROW_CLASS, isHighlighted && HIGHLIGHTED_ROW_CLASS, rowsOpen && SELECTABLE_ROW_CLASS, rowsOpen && hovers && HOVER_FOCUSED_ROW_CLASS, isSelected && SELECTED_ROW_CLASS), children: row.getVisibleCells().map((cell, index) => {
|
|
634
|
+
const meta = cell.column.columnDef.meta;
|
|
635
|
+
const value = flexRender(cell.column.columnDef.cell, cell.getContext());
|
|
636
|
+
const shown = meta?.clip ? (_jsx(ClippedText, { maxWidth: meta.maxWidth ?? DEFAULT_CLIP_WIDTH, children: value })) : meta?.maxWidth ? (_jsx("div", { className: "whitespace-normal break-words", style: { maxWidth: meta.maxWidth }, children: value })) : (value);
|
|
637
|
+
const isPinnedFirst = pinFirstColumn && index === 0;
|
|
638
|
+
const isPinnedLast = pinLastColumn && index === row.getVisibleCells().length - 1;
|
|
639
|
+
return (_jsx(TableCell, { className: cn(isPinnedFirst && PINNED_COLUMN_CLASS, isPinnedLast && PINNED_LAST_COLUMN_CLASS, (isPinnedFirst || isPinnedLast) && striped && PINNED_STRIPED_CELL_CLASS, alignClass(meta?.align)), children: isPinnedFirst ? _jsx("div", { className: PINNED_FIRST_CONTENT_CLASS, children: shown }) : shown }, cell.id));
|
|
640
|
+
}) }, key));
|
|
588
641
|
};
|
|
589
|
-
const content = (_jsxs("div", { ref: root, className:
|
|
590
|
-
? { '--data-table-last-width': `${lastWidth}px` }
|
|
591
|
-
: undefined, children: [layouts?.length || groupings?.length ? (_jsxs("div", { className: "flex flex-wrap items-end gap-x-4 gap-y-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: toolbar }), groupings?.length ? (_jsxs("div", { className: "flex items-center gap-2", children: [activeGrouping && (_jsx(Button, { variant: "ghost", size: "sm", "data-slot": "data-table-fold-all", disabled: !runs?.length, onClick: foldAll, children: allFolded ? 'Unfold all' : 'Fold all' })), _jsx(GroupMenu, { groupings: groupings, value: activeGrouping?.id ?? '', onValueChange: setGrouping })] })) : null, layouts?.length ? (_jsx(LayoutSwitch, { options: [
|
|
642
|
+
const content = (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-layout": layouts?.length ? currentLayout : undefined, children: [layouts?.length || groupings?.length ? (_jsxs("div", { className: "flex flex-wrap items-end gap-x-4 gap-y-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: toolbar }), groupings?.length ? (_jsxs("div", { className: "flex items-center gap-2", children: [activeGrouping && (_jsx(Button, { variant: "ghost", size: "sm", "data-slot": "data-table-fold-all", disabled: !runs?.length, onClick: foldAll, children: allFolded ? 'Unfold all' : 'Fold all' })), _jsx(GroupMenu, { groupings: groupings, value: activeGrouping?.id ?? '', onValueChange: setGrouping })] })) : null, layouts?.length ? (_jsx(LayoutSwitch, { options: [
|
|
592
643
|
{ id: 'table', label: tableLayout?.label ?? 'Table', icon: tableLayout?.icon ?? TableIcon },
|
|
593
644
|
...layouts,
|
|
594
|
-
], value: currentLayout, onValueChange: setLayout })) : null] })) : (toolbar),
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
645
|
+
], value: currentLayout, onValueChange: setLayout })) : null] })) : (toolbar), _jsx("div", { ref: body, "data-slot": "data-table-body", className: cn('flex flex-col gap-4', fitsColumns && CONTENT_WIDTH_CLASS), style: fitsColumns && !isSuccessView && lastWidth !== null
|
|
646
|
+
? { '--data-table-last-width': `${lastWidth}px` }
|
|
647
|
+
: undefined, children: error ? (_jsx(ErrorState, { error: error, onRetry: onRetry })) : isLoading || isPastLastPage ? (cardLayout ? (_jsx(CardsSkeleton, { layout: cardLayout })) : (_jsx(TableSkeleton, { columnCount: table.getVisibleLeafColumns().length }))) : isEmpty ? (_jsxs(Empty, { "data-state": "empty", children: [_jsxs(EmptyHeader, { children: [_jsx(EmptyTitle, { children: emptyTitle }), emptyDescription && _jsx(EmptyDescription, { children: emptyDescription })] }), emptyAction] })) : (_jsxs(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: selectedRow && detailPanel && isWide ? (_jsxs("aside", { "aria-label": detailLabel, "data-slot": "data-table-detail", className: DETAIL_ASIDE_CLASS, onKeyDown: (event) => {
|
|
648
|
+
const target = event.target;
|
|
649
|
+
if (event.key !== 'Escape' || event.defaultPrevented || target.closest(TYPING_SELECTOR))
|
|
650
|
+
return;
|
|
651
|
+
event.preventDefault();
|
|
652
|
+
closeDetail();
|
|
653
|
+
}, children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("h2", { className: "type-label text-muted-foreground", children: detailLabel }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Close", onClick: closeDetail, children: _jsx(XIcon, { "aria-hidden": "true" }) })] }), detailPanel(selectedRow.original)] })) : null, children: [cardLayout ? (_jsx(Cards, { layout: cardLayout, runs: runs, rows: rows, folded: folded, onToggleFold: toggleFold, groupSummary: groupSummary, groupIcons: groupIcons, onCardClick: onCardClick })) : (_jsxs(Table, { "data-state": "success", containerRef: containerRef, onKeyDown: rowsOpen ? onListKeyDown : undefined, className: cn(stickyGroups && STICKY_FOCUS_CLASS), containerStyle: stickyGroups
|
|
654
|
+
? {
|
|
655
|
+
'--data-table-head-height': `${headHeight}px`,
|
|
656
|
+
'--data-table-sticky-top': stickyTop,
|
|
657
|
+
'--data-table-pin-top': scrollsSideways ? '0px' : stickyTop,
|
|
658
|
+
}
|
|
659
|
+
: undefined,
|
|
660
|
+
// With the sticky bar below as the visible scrollbar, hide the
|
|
661
|
+
// container's own. It stays overflow-x-auto and fully
|
|
662
|
+
// scrollable (wheel, trackpad, drag, and the sync effect); it
|
|
663
|
+
// just no longer draws a bar directly under the last row.
|
|
664
|
+
containerClassName: cn(
|
|
665
|
+
// A size container has no width of its own to give, so
|
|
666
|
+
// `width="content"` couldn't fit the table: there the
|
|
667
|
+
// pinned column's `cqw` measures the table's area
|
|
668
|
+
// (`@container/data-table`) instead.
|
|
669
|
+
pinFirstColumn && width !== 'content' && '@container', pinFirstColumn && '[scrollbar-width:none] [&::-webkit-scrollbar]:hidden', stickyGroups && (scrollsSideways ? STICKY_OWN_SCROLL_CLASS : STICKY_PAGE_SCROLL_CLASS)), children: [_jsx(TableHeader, { className: cn((!showHeader || stickyGroups) && '[&_tr]:border-0'), children: table.getHeaderGroups().map((headerGroup) => (_jsx(TableRow, { children: headerGroup.headers.map((header, index) => {
|
|
670
|
+
const canSort = header.column.getCanSort();
|
|
671
|
+
const sortDirection = header.column.getIsSorted();
|
|
672
|
+
// Hidden, a header is its name only: a sort button no
|
|
673
|
+
// one can see would still take focus.
|
|
674
|
+
const content = header.isPlaceholder ? null : canSort && showHeader ? (_jsxs("button", { type: "button", className: cn('flex items-center gap-1 text-foreground', header.column.columnDef.meta?.align === 'center' && 'w-full justify-center',
|
|
675
|
+
// The arrow on the label's left, so the label's
|
|
676
|
+
// right edge lines up with the numbers under it.
|
|
677
|
+
header.column.columnDef.meta?.align === 'right' && 'ml-auto flex-row-reverse'), onClick: header.column.getToggleSortingHandler(), children: [flexRender(header.column.columnDef.header, header.getContext()), sortDirection === 'asc' ? (_jsx(ArrowUpIcon, { className: "size-3.5 text-muted-foreground" })) : sortDirection === 'desc' ? (_jsx(ArrowDownIcon, { className: "size-3.5 text-muted-foreground" })) : (_jsx(ArrowUpDownIcon, { className: "size-3.5 text-muted-foreground/50" }))] })) : (flexRender(header.column.columnDef.header, header.getContext()));
|
|
678
|
+
return (_jsx(TableHead, { className: cn(!showHeader && HIDDEN_HEAD_CLASS, pinFirstColumn && index === 0 && PINNED_COLUMN_CLASS, pinLastColumn &&
|
|
679
|
+
index === headerGroup.headers.length - 1 &&
|
|
680
|
+
PINNED_LAST_COLUMN_CLASS, stickyGroups && showHeader && STICKY_HEAD_CELL_CLASS, alignClass(header.column.columnDef.meta?.align)), "aria-sort": !canSort
|
|
681
|
+
? undefined
|
|
682
|
+
: sortDirection === 'asc'
|
|
683
|
+
? 'ascending'
|
|
684
|
+
: sortDirection === 'desc'
|
|
685
|
+
? 'descending'
|
|
686
|
+
: 'none', children: !showHeader ? (_jsx("span", { className: "sr-only", children: content })) : pinFirstColumn && index === 0 ? (_jsx("div", { className: PINNED_FIRST_CONTENT_CLASS, children: content })) : (content) }, header.id));
|
|
687
|
+
}) }, headerGroup.id))) }), runs ? (runs.map((run, runIndex) => {
|
|
688
|
+
const isFolded = folded.has(run.key);
|
|
689
|
+
return (_jsxs(TableBody, { "data-slot": "table-group", "data-folded": isFolded || undefined, className: cn(!striped && UNSTRIPED_BODY_CLASS), children: [_jsx(TableRow, { "data-slot": "table-group-heading", className: cn('hover:bg-transparent has-aria-expanded:bg-transparent', stickyGroups && 'border-b-0'), children: _jsx(TableHead, { scope: "rowgroup", colSpan: visibleColumnCount, className: cn(GROUP_HEADING_CLASS, stickyGroups && STICKY_GROUP_HEADING_CLASS), children: _jsxs("span", { className: "sticky left-(--table-cell-px) inline-flex items-baseline gap-2", children: [_jsx(GroupLabel, { run: run, icon: groupIcons?.get(run.key), isFolded: isFolded, onToggle: () => toggleFold(run.key) }), groupSummary && (_jsx("span", { className: "type-caption text-muted-foreground tabular-nums", children: groupSummary(run.rows.map((row) => row.original), { key: run.key, label: run.label }) }))] }) }) }), _jsx("tr", { hidden: true, "aria-hidden": "true", "data-slot": "table-group-stripe-offset" }), !isFolded && run.rows.map((row) => renderRow(row, placeKey(run.key, row.id)))] }, `${runIndex}:${run.key}`));
|
|
690
|
+
})) : (_jsx(TableBody, { className: cn(!striped && UNSTRIPED_BODY_CLASS), children: rows.map((row) => renderRow(row)) })), totals && (_jsx(TableFooter, { className: TOTALS_FOOTER_CLASS, children: _jsx(TableRow, { "data-slot": "table-totals", className: "hover:bg-transparent", children: visibleLeafColumns.map((column, index) => {
|
|
691
|
+
const className = cn(pinFirstColumn && index === 0 && PINNED_TOTALS_LABEL_CLASS, pinLastColumn && index === visibleColumnCount - 1 && PINNED_LAST_COLUMN_CLASS, alignClass(column.columnDef.meta?.align));
|
|
692
|
+
return index === 0 ? (_jsx(TableHead, { scope: "row", className: cn(TOTALS_LABEL_CLASS, className), children: pinFirstColumn ? (_jsx("div", { className: PINNED_FIRST_CONTENT_CLASS, children: totals.label })) : (totals.label) }, column.id)) : (_jsx(TableCell, { className: className, children: totals.cells?.[column.id] }, column.id));
|
|
693
|
+
}) }) }))] })), pinFirstColumn && isOverflowing && !cardLayout && (_jsx("div", { ref: barRef, "aria-hidden": "true", tabIndex: -1, "data-slot": "bottom-scrollbar", className: "sticky bottom-0 z-20 h-4 overflow-x-auto border-t border-border bg-background", children: _jsx("div", { style: { width: scrollWidth, height: 1 } }) })), _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", "data-slot": "data-table-pagination", children: [_jsxs("p", { className: "type-body text-muted-foreground", children: [total === 0 ? 0 : (page - 1) * pageSize + 1, '–', Math.min(page * pageSize, total), " of ", total] }), _jsxs("div", { className: "flex items-center gap-2", children: [pageSizes && pageSizes.length > 1 && onPageSizeChange ? (_jsx(PageSizeMenu, { pageSizes: pageSizes, value: pageSize, onValueChange: onPageSizeChange })) : null, _jsx(Button, { variant: "outline", size: "icon-sm", "aria-label": "Previous page", disabled: page <= 1, onClick: () => onPageChange(page - 1), children: _jsx(ChevronLeftIcon, {}) }), _jsxs("span", { className: "type-body text-muted-foreground", children: ["Page ", page, " of ", pageCount] }), _jsx(Button, { variant: "outline", size: "icon-sm", "aria-label": "Next page", disabled: page >= pageCount, onClick: () => onPageChange(page + 1), children: _jsx(ChevronRightIcon, {}) })] })] })] })) })] }));
|
|
642
694
|
return (_jsxs(EditInPlaceContext.Provider, { value: store, children: [editing && _jsx(LeaveGuard, { store: store }), width === 'content' ? _jsx("div", { className: "@container/data-table", children: content }) : content, detailPanel && (_jsx(Sheet, { open: Boolean(selectedRow) && !isWide && isSuccessView && !cardLayout, onOpenChange: (open) => {
|
|
643
695
|
if (!open)
|
|
644
696
|
setSelection(null);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type FreshnessProps = {
|
|
2
|
+
/** When it was entered or checked; null or '' when it never was. */
|
|
3
|
+
at: Date | string | null | undefined;
|
|
4
|
+
/** The moment it goes stale. Left out, the line is never in the warning tone. */
|
|
5
|
+
staleAfter?: Date | string;
|
|
6
|
+
/** What happened, before the date: "Balances entered", "Prices checked". */
|
|
7
|
+
label: string;
|
|
8
|
+
/** What the line says when `at` is empty. Defaults to "<label>: never". */
|
|
9
|
+
neverText?: string;
|
|
10
|
+
/** The clock, for stories and tests. Defaults to now. */
|
|
11
|
+
now?: Date;
|
|
12
|
+
className?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function Freshness({ at, staleAfter, label, neverText, now, className }: FreshnessProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// How fresh a number is (overview standard O3): one quiet line under it,
|
|
3
|
+
// "Balances entered Aug 2", in the caption type and the muted tone. Once
|
|
4
|
+
// `staleAfter` has passed it turns to the warning tone and gains a
|
|
5
|
+
// warning icon, so an out-of-date balance never looks current; the line
|
|
6
|
+
// still says when, and a screen reader hears ", out of date".
|
|
7
|
+
//
|
|
8
|
+
// Used in a part's tile and detail and in a WidgetCard's body. The date is
|
|
9
|
+
// a plain day ('YYYY-MM-DD', as the wire writes it, shown without the
|
|
10
|
+
// time zone shifting it) or an instant (a Date, or an ISO timestamp).
|
|
11
|
+
// `staleAfter` is the moment it goes stale, so the app owns the rule
|
|
12
|
+
// (entered + 90 days): this only says whether it has passed. `now` is for
|
|
13
|
+
// stories and tests.
|
|
14
|
+
import { TriangleAlertIcon } from 'lucide-react';
|
|
15
|
+
import { cn } from 'cn';
|
|
16
|
+
import { isStale, showDate } from '../../lib/freshness.js';
|
|
17
|
+
export function Freshness({ at, staleAfter, label, neverText, now = new Date(), className }) {
|
|
18
|
+
const entered = at ? showDate(at, now) : '';
|
|
19
|
+
if (!entered) {
|
|
20
|
+
return (_jsx("span", { "data-slot": "freshness", "data-state": "never", className: cn('type-caption text-muted-foreground', className), children: neverText ?? `${label}: never` }));
|
|
21
|
+
}
|
|
22
|
+
const stale = isStale(staleAfter, now);
|
|
23
|
+
const iso = at instanceof Date ? at.toISOString() : String(at);
|
|
24
|
+
return (_jsxs("span", { "data-slot": "freshness", "data-state": stale ? 'stale' : 'fresh', className: cn('inline-flex items-center gap-1 type-caption', stale ? 'text-warning-text' : 'text-muted-foreground', className), children: [stale && _jsx(TriangleAlertIcon, { "aria-hidden": "true", className: "size-3 shrink-0" }), _jsxs("span", { children: [label, " ", _jsx("time", { dateTime: iso, children: entered }), stale && _jsx("span", { className: "sr-only", children: ", out of date" })] })] }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type To } from 'react-router';
|
|
2
|
+
import type { IconComponent } from './icon-component.js';
|
|
3
|
+
export type ListHeaderLink = {
|
|
4
|
+
label: string;
|
|
5
|
+
to: To;
|
|
6
|
+
icon?: IconComponent;
|
|
7
|
+
};
|
|
8
|
+
export type ListHeaderAction = {
|
|
9
|
+
label: string;
|
|
10
|
+
onSelect: () => void;
|
|
11
|
+
icon?: IconComponent;
|
|
12
|
+
};
|
|
13
|
+
export type ListHeaderProps = {
|
|
14
|
+
/** The list's name: the page's h1. */
|
|
15
|
+
title: string;
|
|
16
|
+
/** How many records there are, beside the title in the muted tone. Left out while loading. */
|
|
17
|
+
count?: number;
|
|
18
|
+
/** Related screens (Board, Change log). One stays a button; two or more fold into ⋯. */
|
|
19
|
+
links?: readonly ListHeaderLink[];
|
|
20
|
+
/** The New button: a link to the new-record page, or a function that opens its dialog. */
|
|
21
|
+
newAction?: {
|
|
22
|
+
label: string;
|
|
23
|
+
to: To;
|
|
24
|
+
onClick?: never;
|
|
25
|
+
} | {
|
|
26
|
+
label: string;
|
|
27
|
+
onClick: () => void;
|
|
28
|
+
to?: never;
|
|
29
|
+
};
|
|
30
|
+
/** The page's other actions (Export, Import), in ⋯ after the folded links. */
|
|
31
|
+
more?: readonly ListHeaderAction[];
|
|
32
|
+
/**
|
|
33
|
+
* Soft-deleted records, for a list that has them: "Show deleted" in ⋯,
|
|
34
|
+
* and the notice while it is on. `noun` completes "Showing deleted
|
|
35
|
+
* <noun>" (default "records").
|
|
36
|
+
*/
|
|
37
|
+
deleted?: {
|
|
38
|
+
shown: boolean;
|
|
39
|
+
onShownChange: (shown: boolean) => void;
|
|
40
|
+
noun?: string;
|
|
41
|
+
};
|
|
42
|
+
className?: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function ListHeader({ title, count, links, newAction, more, deleted, className }: ListHeaderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A list page's header (list standard L12): the title with its count,
|
|
3
|
+
// the New button alone beside it, and everything else behind one ⋯ menu.
|
|
4
|
+
// The related screens (Board, Change log) stay out as buttons while
|
|
5
|
+
// there's one; two or more fold into the menu with the page's other
|
|
6
|
+
// extras, so the row is the same on a list with no siblings and one with
|
|
7
|
+
// four. "Show deleted" is the menu's last item, and while it's on a notice
|
|
8
|
+
// says so with "Back to the list", so the ⋯ menu and the notice are one
|
|
9
|
+
// component and a list can't show deleted records without saying so.
|
|
10
|
+
//
|
|
11
|
+
// Holds no state: the app keeps `shown` (usually a URL filter). `links`
|
|
12
|
+
// are routes, `more` are the app's own actions. The ⋯ button has an
|
|
13
|
+
// accessible name and is left out when the menu would be empty.
|
|
14
|
+
import { EllipsisIcon, PlusIcon, Trash2Icon } from 'lucide-react';
|
|
15
|
+
import { Link } from 'react-router';
|
|
16
|
+
import { cn } from 'cn';
|
|
17
|
+
import { Notice } from './notice.js';
|
|
18
|
+
import { Button } from '../ui/button.js';
|
|
19
|
+
import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
|
|
20
|
+
export function ListHeader({ title, count, links = [], newAction, more = [], deleted, className }) {
|
|
21
|
+
// One link is a button of its own; two or more go in the menu.
|
|
22
|
+
const outLink = links.length === 1 ? links[0] : undefined;
|
|
23
|
+
const menuLinks = links.length > 1 ? links : [];
|
|
24
|
+
const hasMenu = menuLinks.length > 0 || more.length > 0 || deleted !== undefined;
|
|
25
|
+
return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more" }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", children: [menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show deleted"] }))] })] })), newAction &&
|
|
26
|
+
(newAction.to !== undefined ? (_jsxs(Button, { size: "sm", nativeButton: false, render: _jsx(Link, { to: newAction.to }), children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })) : (_jsxs(Button, { size: "sm", onClick: newAction.onClick, children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })))] })] }), _jsx("div", { role: "status", "data-slot": "list-header-notice", className: "not-empty:mt-3", children: deleted?.shown && (_jsxs(Notice, { tone: "info", icon: Trash2Icon, action: _jsx(Button, { size: "sm", variant: "outline", onClick: () => deleted.onShownChange(false), children: "Back to the list" }), children: ["Showing deleted ", deleted.noun ?? 'records', "."] })) })] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type To } from 'react-router';
|
|
2
|
+
export type NeedsYouTone = 'warning' | 'destructive';
|
|
3
|
+
export type NeedsYouItem = {
|
|
4
|
+
/** What waits: a short sentence ("1 document is overdue"). The whole line is the link. */
|
|
5
|
+
text: string;
|
|
6
|
+
/** Where to fix it. */
|
|
7
|
+
to: To;
|
|
8
|
+
/** `warning` (the default), or `destructive` for what's overdue. */
|
|
9
|
+
tone?: NeedsYouTone;
|
|
10
|
+
};
|
|
11
|
+
export type NeedsYouProps = {
|
|
12
|
+
items: readonly NeedsYouItem[];
|
|
13
|
+
/** The heading. Defaults to "Needs you". */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** The heading's level: 2 under the page's h1 (the default). */
|
|
16
|
+
headingLevel?: 2 | 3 | 4;
|
|
17
|
+
className?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function NeedsYou({ items, title, headingLevel, className }: NeedsYouProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// What waits on you (overview standard O2): one list at the top of an
|
|
3
|
+
// overview, in the warning tone, each line a link to where it's fixed
|
|
4
|
+
// ("Balances are three months old", "2 deals at their target"). It
|
|
5
|
+
// collects what each part already says about itself, so the page's first
|
|
6
|
+
// answer is "what do I do", not a scan of every tile.
|
|
7
|
+
//
|
|
8
|
+
// Nothing at all when `items` is empty: no heading, no empty box. A
|
|
9
|
+
// region named by its heading, so it is in the page's outline and a
|
|
10
|
+
// screen reader can jump to it. The wash is the tone at 10% (20% in dark)
|
|
11
|
+
// with foreground text and the `*-text` icon, as a Notice draws it; a
|
|
12
|
+
// line may take another tone (`destructive` for an overdue one).
|
|
13
|
+
import { ChevronRightIcon, CircleAlertIcon, TriangleAlertIcon } from 'lucide-react';
|
|
14
|
+
import { useId } from 'react';
|
|
15
|
+
import { Link } from 'react-router';
|
|
16
|
+
import { cn } from 'cn';
|
|
17
|
+
const LINE = {
|
|
18
|
+
warning: { icon: 'text-warning-text', Icon: TriangleAlertIcon },
|
|
19
|
+
destructive: { icon: 'text-destructive-text', Icon: CircleAlertIcon },
|
|
20
|
+
};
|
|
21
|
+
export function NeedsYou({ items, title = 'Needs you', headingLevel = 2, className }) {
|
|
22
|
+
const headingId = useId();
|
|
23
|
+
if (items.length === 0)
|
|
24
|
+
return null;
|
|
25
|
+
const Heading = `h${headingLevel}`;
|
|
26
|
+
return (_jsxs("section", { "aria-labelledby": headingId, "data-slot": "needs-you", className: cn('flex flex-col gap-1 rounded-lg border border-warning-text/30 bg-warning/10 px-4 py-3 text-foreground dark:bg-warning/20', className), children: [_jsx(Heading, { id: headingId, className: "type-label font-semibold text-foreground", children: title }), _jsx("ul", { className: "flex flex-col", children: items.map((item, index) => {
|
|
27
|
+
const { icon, Icon } = LINE[item.tone ?? 'warning'];
|
|
28
|
+
return (_jsx("li", { "data-tone": item.tone ?? 'warning', children: _jsxs(Link, { to: item.to, className: "group/line -mx-1 flex min-h-8 items-center gap-2 rounded-sm px-1 py-1 type-body text-foreground outline-none focus-visible:ring-3 focus-visible:ring-ring/50 max-sm:min-h-11", children: [_jsx(Icon, { "aria-hidden": "true", className: cn('size-4 shrink-0', icon) }), _jsx("span", { className: "min-w-0 flex-1 underline-offset-4 group-hover/line:underline", children: item.text }), _jsx(ChevronRightIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-muted-foreground" })] }) }, `${index}-${item.text}`));
|
|
29
|
+
}) })] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type To } from 'react-router';
|
|
2
|
+
export type PartEmptyAction = {
|
|
3
|
+
label: string;
|
|
4
|
+
to: To;
|
|
5
|
+
onClick?: never;
|
|
6
|
+
} | {
|
|
7
|
+
label: string;
|
|
8
|
+
onClick: () => void;
|
|
9
|
+
to?: never;
|
|
10
|
+
};
|
|
11
|
+
export type PartEmptyState = {
|
|
12
|
+
/** What it says. Defaults to "Nothing here yet". */
|
|
13
|
+
text?: string;
|
|
14
|
+
/** The one way to start: a link to where the first one is added, or a button that opens it. */
|
|
15
|
+
action?: PartEmptyAction;
|
|
16
|
+
};
|
|
17
|
+
export type PartEmptyProps = PartEmptyState & {
|
|
18
|
+
className?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function PartEmpty({ text, action, className }: PartEmptyProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A part with nothing in it yet (overview standard O5): the card stays,
|
|
3
|
+
// with "Nothing here yet" and one way to start ("Add the first line"), as
|
|
4
|
+
// an empty list does. The foundation's Empty at card size: no big
|
|
5
|
+
// illustration, a dashed border, the message and one outline button.
|
|
6
|
+
//
|
|
7
|
+
// `WidgetCard`'s `empty` prop draws this in its body in place of the
|
|
8
|
+
// plain `emptyMessage` line; an overview part uses the same component for
|
|
9
|
+
// its own `empty`. The button is a link (`to`) or a plain button
|
|
10
|
+
// (`onClick`).
|
|
11
|
+
import { Link } from 'react-router';
|
|
12
|
+
import { cn } from 'cn';
|
|
13
|
+
import { Button } from '../ui/button.js';
|
|
14
|
+
import { Empty, EmptyContent, EmptyDescription, EmptyHeader } from '../ui/empty.js';
|
|
15
|
+
export function PartEmpty({ text = 'Nothing here yet', action, className }) {
|
|
16
|
+
return (_jsxs(Empty, { "data-slot": "part-empty", "data-state": "empty", className: cn('gap-3 border p-4', className), children: [_jsx(EmptyHeader, { children: _jsx(EmptyDescription, { children: text }) }), action && (_jsx(EmptyContent, { children: action.to !== undefined ? (_jsx(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: action.to }), children: action.label })) : (_jsx(Button, { size: "sm", variant: "outline", onClick: action.onClick, children: action.label })) }))] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export type TimelineItem = {
|
|
3
|
+
/** Unique in the list; a stored id when there is one. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** The date as shown ("Nov 2", "Nov 2, 2025"): short, one line. */
|
|
6
|
+
date: string;
|
|
7
|
+
/** The date for machines ('2026-11-02'), on the <time> element. */
|
|
8
|
+
dateTime?: string;
|
|
9
|
+
/** What sort of entry: "Visit", "Call", "Note". A muted line under the body. */
|
|
10
|
+
kind?: string;
|
|
11
|
+
body: ReactNode;
|
|
12
|
+
/** The entry's own control, at its end (an edit button, a ⋯ menu). */
|
|
13
|
+
edit?: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
export type TimelineProps = {
|
|
16
|
+
items: readonly TimelineItem[];
|
|
17
|
+
/** How many show before "Show all N". Defaults to 5. */
|
|
18
|
+
initial?: number;
|
|
19
|
+
/** The list's name for screen readers ("Changes"). */
|
|
20
|
+
label: string;
|
|
21
|
+
/** What an empty timeline says. Defaults to "Nothing yet". */
|
|
22
|
+
emptyText?: string;
|
|
23
|
+
className?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function Timeline({ items, initial, label, emptyText, className }: TimelineProps): import("react").JSX.Element;
|