rift-ds 1.30.0 → 1.32.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 +6 -4
- package/behaviors/chat-card.css +4 -1
- package/behaviors/deferComponent.d.ts +43 -0
- package/behaviors/deferComponent.js +35 -0
- package/behaviors/locale.d.ts +7 -0
- package/behaviors/locale.js +5 -0
- package/behaviors/shell.css +33 -0
- package/bin/rift-ds.mjs +35 -9
- package/bin/templates/blocks/app/planner/PlannerGrid.tsx +58 -0
- package/bin/templates/blocks/app/planner/Requests.tsx +42 -0
- package/bin/templates/blocks/app/planner/page.module.css +17 -0
- package/bin/templates/blocks/app/planner/page.tsx +32 -0
- package/bin/templates/blocks/components/blocks/AppShell.module.css +10 -1
- package/bin/templates/blocks/registry.json +14 -0
- package/bin/templates/chat/app/api/chat/route.actions.ts +108 -0
- package/bin/templates/chat/components/chat/ChatMount.actions.tsx +55 -0
- package/bin/templates/chat/components/chat/ChatMount.tsx +14 -1
- package/bin/templates/chat/components/chat/proposals/ProposalCard.tsx +81 -0
- package/bin/templates/chat/components/chat/proposals/actions.ts +60 -0
- package/bin/templates/chat/components/chat/proposals/confirmation.ts +9 -0
- package/bin/templates/chat/components/chat/proposals/renderers.tsx +9 -0
- package/chat/ChatLauncher.d.ts +13 -2
- package/chat/ChatLauncher.js +52 -29
- package/chat/ChatProvider.d.ts +19 -2
- package/chat/ChatProvider.js +26 -3
- package/chat/ChatWidget.css +23 -4
- package/chat/ChatWidget.d.ts +2 -1
- package/chat/ChatWidget.js +23 -21
- package/chat/actions.d.ts +52 -6
- package/chat/actions.js +53 -5
- package/chat/contextSchema.d.ts +76 -0
- package/chat/contextSchema.js +58 -0
- package/chat/deferredChatWidget.d.ts +10 -0
- package/chat/deferredChatWidget.js +10 -0
- package/chat/index.d.ts +3 -2
- package/chat/index.js +7 -1
- package/chat/registry.json.d.ts +4 -3
- package/chat/registry.json.js +1 -1
- package/chat/server.d.ts +18 -2
- package/chat/server.js +10 -1
- package/chat/suggestions.d.ts +7 -0
- package/chat/suggestions.js +13 -1
- package/chat/types.d.ts +23 -0
- package/chat/useChat.d.ts +2 -2
- package/chat/useChat.js +15 -1
- package/components/Accordion/Accordion.css +8 -0
- package/components/AgentPlan/AgentPlan.css +8 -0
- package/components/AgentRail/AgentRail.css +3 -3
- package/components/AiButton/AiButton.css +19 -0
- package/components/AiButton/AiButton.d.ts +10 -1
- package/components/AiButton/AiButton.js +6 -1
- package/components/AppSidebar/AppSidebar.css +12 -0
- package/components/ArtifactPanel/ArtifactPanel.js +5 -5
- package/components/Attachment/AttachmentViewer.js +7 -7
- package/components/BentoTile/BentoTile.css +1 -1
- package/components/BentoTile/BentoTile.js +5 -5
- package/components/Button/Button.css +28 -1
- package/components/Button/Button.d.ts +7 -2
- package/components/Button/Button.js +7 -3
- package/components/ButtonGroup/ButtonGroup.css +10 -1
- package/components/Chart/RadarChart.js +24 -10
- package/components/ChatHeader/ChatHeader.d.ts +1 -1
- package/components/ChatThread/ChatThread.css +1 -1
- package/components/Chip/Chip.css +26 -0
- package/components/CircularButton/CircularButton.d.ts +16 -96
- package/components/CircularButton/CircularButton.js +11 -94
- package/components/Combobox/Combobox.css +12 -0
- package/components/CommandPalette/CommandPalette.css +1 -1
- package/components/CommandPalette/CommandPalette.js +3 -3
- package/components/CommandPaletteTrigger/CommandPaletteTrigger.css +9 -0
- package/components/CommandPaletteTrigger/CommandPaletteTrigger.d.ts +10 -2
- package/components/CommandPaletteTrigger/CommandPaletteTrigger.js +7 -2
- package/components/Composer/Composer.css +3 -3
- package/components/Composer/Composer.js +9 -9
- package/components/ContextMenu/ContextMenu.css +24 -0
- package/components/DataTable/DataTable.css +19 -4
- package/components/DataTable/DataTable.d.ts +14 -2
- package/components/DataTable/DataTable.js +28 -17
- package/components/DataTable/periodColumns.d.ts +37 -0
- package/components/DataTable/periodColumns.js +48 -0
- package/components/DateInput/DateInput.css +20 -0
- package/components/DatePicker/DatePicker.css +22 -6
- package/components/DatePicker/DatePicker.d.ts +2 -1
- package/components/DatePicker/DatePicker.js +2 -2
- package/components/DateRangePicker/DateRangePicker.js +2 -2
- package/components/DecisionRow/DecisionRow.css +46 -0
- package/components/DecisionRow/DecisionRow.d.ts +62 -0
- package/components/DecisionRow/DecisionRow.js +93 -0
- package/components/DescriptionList/DescriptionListCopy.d.ts +1 -1
- package/components/DescriptionList/DescriptionListCopy.js +3 -3
- package/components/Dialog/Dialog.css +1 -1
- package/components/Dialog/Dialog.js +3 -3
- package/components/DocumentChip/DocumentChip.css +12 -0
- package/components/DocumentViewer/DocumentViewer.js +10 -10
- package/components/Drawer/Drawer.css +1 -1
- package/components/Drawer/Drawer.js +3 -3
- package/components/Dropdown/Dropdown.css +30 -0
- package/components/DropdownMenu/DropdownMenu.css +24 -0
- package/components/EventCalendar/EventCalendar.css +54 -0
- package/components/EventCalendar/EventCalendar.d.ts +27 -5
- package/components/EventCalendar/EventCalendar.js +50 -15
- package/components/FileInput/FileInput.css +9 -0
- package/components/FilterBar/FilterBar.css +12 -0
- package/components/FunnelChart/FunnelChart.js +33 -22
- package/components/Globe/Globe.css +7 -0
- package/components/Globe/Globe.js +1 -1
- package/components/{CircularButton/CircularButton.css → IconButton/IconButton.css} +91 -81
- package/components/IconButton/IconButton.d.ts +108 -0
- package/components/IconButton/IconButton.js +101 -0
- package/components/Input/Input.css +53 -0
- package/components/Input/Input.js +3 -3
- package/components/MaskedInput/MaskedInput.js +3 -3
- package/components/ModelPicker/ModelPicker.css +12 -1
- package/components/NavList/NavList.css +1 -1
- package/components/Pagination/Pagination.css +1 -1
- package/components/QuestionCard/QuestionCard.js +3 -3
- package/components/RadioButton/RadioButton.css +14 -12
- package/components/RichDropdown/RichDropdown.css +7 -0
- package/components/SegmentedControl/SegmentedControl.css +16 -5
- package/components/SegmentedControl/SegmentedControl.js +7 -4
- package/components/SiteHeader/SiteHeader.css +12 -5
- package/components/SiteHeader/SiteHeader.js +3 -3
- package/components/SourceTrail/SourceTrail.css +8 -0
- package/components/SplitButton/SplitButton.css +14 -14
- package/components/SplitButton/SplitButton.js +3 -3
- package/components/Table/Table.css +7 -0
- package/components/Table/Table.js +1 -1
- package/components/TableToolbar/TableToolbar.css +2 -2
- package/components/TableToolbar/TableToolbar.js +36 -37
- package/components/Tabs/Tabs.css +21 -3
- package/components/ThreadPanel/ThreadPanel.css +8 -0
- package/components/ThreadTabs/ThreadTabs.css +7 -0
- package/components/TimePicker/TimePicker.css +12 -0
- package/components/Timeline/Timeline.css +8 -0
- package/components/ToolCall/ToolCall.css +8 -0
- package/components/Tooltip/Tooltip.js +3 -2
- package/components/Widget/Widget.css +2 -0
- package/components/WorldMap/WorldMap.css +15 -0
- package/components/WorldMap/WorldMap.js +61 -6
- package/components/registry.d.ts +3 -1
- package/components/registry.json +39 -13
- package/components/registry.json.d.ts +39 -13
- package/components/registry.json.js +1 -1
- package/index.d.ts +2 -0
- package/index.js +8 -0
- package/package.json +6 -2
- package/tokens/presets/blueprint.css +9 -0
- package/tokens/presets/bubblegum.css +9 -0
- package/tokens/presets/contrast.css +3 -3
- package/tokens/presets/coral.css +3 -3
- package/tokens/presets/ember.css +9 -0
- package/tokens/presets/getaway.css +9 -0
- package/tokens/presets/gold.css +3 -3
- package/tokens/presets/mono.css +3 -3
- package/tokens/presets/pink.css +3 -3
- package/tokens/presets/plum.css +3 -3
- package/tokens/presets/signal.css +9 -0
- package/tokens/presets/smoke.css +9 -0
- package/tokens/presets/velvet.css +9 -0
- package/tokens/presets/violet.css +3 -3
- package/tokens/presets/volt.css +9 -0
- package/tokens/presets/warm.css +3 -3
|
@@ -425,6 +425,18 @@ type DataTableOwnProps<R extends DataTableRow = DataTableRow> = {
|
|
|
425
425
|
expandMode?: 'multiple' | 'single';
|
|
426
426
|
/** Fires with the table's setup as a view whenever any part of it changes, so a host can keep the reader's last view. */
|
|
427
427
|
onViewChange?: (view: DataTableView) => void;
|
|
428
|
+
/**
|
|
429
|
+
* The whole setup in one value (sorts, filters, search, grouping, hidden and
|
|
430
|
+
* ordered columns, pins, widths, density, page size), for controlled use:
|
|
431
|
+
* whenever it changes the table shows it, so one piece of state outside the
|
|
432
|
+
* table, a chat's card or a saved link, can set every part at once. A part it
|
|
433
|
+
* leaves out falls back to the table's opening setup. Pair with
|
|
434
|
+
* `onViewChange`, and hand back what it reports, so the reader's own changes
|
|
435
|
+
* stay.
|
|
436
|
+
*/
|
|
437
|
+
view?: DataTableView;
|
|
438
|
+
/** The setup to start with, for uncontrolled use: the table's first render, the server's HTML too, is already this view. */
|
|
439
|
+
defaultView?: DataTableView;
|
|
428
440
|
/** The column keys the rows are grouped by, for controlled use; this milestone draws the first. Pair with `onGroupingChange`. */
|
|
429
441
|
grouping?: string[];
|
|
430
442
|
/** The grouping to start with, for uncontrolled use. */
|
|
@@ -606,7 +618,7 @@ type DataTableOwnProps<R extends DataTableRow = DataTableRow> = {
|
|
|
606
618
|
};
|
|
607
619
|
export interface DataTableProps<R extends DataTableRow = DataTableRow> extends DataTableOwnProps<R>, Omit<React.ComponentPropsWithRef<'div'>, keyof DataTableOwnProps<R>> {
|
|
608
620
|
}
|
|
609
|
-
export declare function DataTable<R extends DataTableRow = DataTableRow>({ columns: columnsProp, rows: rowsProp, pageSize: pageSizeProp, defaultPageSize, onPageSizeChange, pageSizeOptions, page: pageProp, defaultPage, onPageChange, pageSizeLabel, phoneLayout, selectable, selectedIds, defaultSelectedIds, onSelectionChange, sort, defaultSort, onSortChange, sorts: sortsProp, defaultSorts, onSortsChange, multiSort, onViewChange, virtualize, onLoadMore, hasMore, renderDetail, expandedIds: expandedProp, defaultExpandedIds, onExpandedIdsChange, expandMode, grouping: groupingProp, defaultGrouping, onGroupingChange, totalsRow, totals: totalsProp, defaultTotals, onTotalsChange, linkComponent, rowHref, onRowClick, searchable, searchPlaceholder, toolbar, size: sizeProp, defaultSize, onSizeChange, filters: filtersProp, defaultFilters, onFiltersChange, search: searchProp, defaultSearch, onSearchChange, filterLabels: filterLabelsProp, striped, caption, emptyState, selectAllLabel, selectRowLabel, sortLabel, sortRankLabel, sortAnnouncement, pageAnnouncement, resultsLabel, selectedLabel, paginationLabels, emptyStateLabels, resizableColumns, reorderableColumns, columnMenu, reorderableRows, stickyHeader, maxHeight, navigation, columnWidths, defaultColumnWidths, onColumnWidthsChange, columnOrder, defaultColumnOrder, onColumnOrderChange, columnPinning, defaultColumnPinning, onColumnPinningChange, hiddenColumns, defaultHiddenColumns, onHiddenColumnsChange, rowOrder, defaultRowOrder, onRowOrderChange, columnLabels, columnDividers, cellText, rowActions, rowActionsVisibility, editMode, onCellEdit, onRowEdit, manual, rowCount: rowCountProp, loading, error, onRetry, loadLabels, locale: localeProp, className, ref, ...rest }: DataTableProps<R>): React.JSX.Element;
|
|
621
|
+
export declare function DataTable<R extends DataTableRow = DataTableRow>({ columns: columnsProp, rows: rowsProp, pageSize: pageSizeProp, defaultPageSize, onPageSizeChange, pageSizeOptions, page: pageProp, defaultPage, onPageChange, pageSizeLabel, phoneLayout, selectable, selectedIds, defaultSelectedIds, onSelectionChange, sort, defaultSort, onSortChange, sorts: sortsProp, defaultSorts, onSortsChange, multiSort, onViewChange, view: viewProp, defaultView, virtualize, onLoadMore, hasMore, renderDetail, expandedIds: expandedProp, defaultExpandedIds, onExpandedIdsChange, expandMode, grouping: groupingProp, defaultGrouping, onGroupingChange, totalsRow, totals: totalsProp, defaultTotals, onTotalsChange, linkComponent, rowHref, onRowClick, searchable, searchPlaceholder, toolbar, size: sizeProp, defaultSize, onSizeChange, filters: filtersProp, defaultFilters, onFiltersChange, search: searchProp, defaultSearch, onSearchChange, filterLabels: filterLabelsProp, striped, caption, emptyState, selectAllLabel, selectRowLabel, sortLabel, sortRankLabel, sortAnnouncement, pageAnnouncement, resultsLabel, selectedLabel, paginationLabels, emptyStateLabels, resizableColumns, reorderableColumns, columnMenu, reorderableRows, stickyHeader, maxHeight, navigation, columnWidths, defaultColumnWidths, onColumnWidthsChange, columnOrder, defaultColumnOrder, onColumnOrderChange, columnPinning, defaultColumnPinning, onColumnPinningChange, hiddenColumns, defaultHiddenColumns, onHiddenColumnsChange, rowOrder, defaultRowOrder, onRowOrderChange, columnLabels, columnDividers, cellText, rowActions, rowActionsVisibility, editMode, onCellEdit, onRowEdit, manual, rowCount: rowCountProp, loading, error, onRetry, loadLabels, locale: localeProp, className, ref, ...rest }: DataTableProps<R>): React.JSX.Element;
|
|
610
622
|
/**
|
|
611
623
|
* A stored view made safe for a table's columns as they are now: columns
|
|
612
624
|
* that no longer exist drop out of every part of it, a filter whose
|
|
@@ -616,4 +628,4 @@ export declare function DataTable<R extends DataTableRow = DataTableRow>({ colum
|
|
|
616
628
|
* read from storage before showing it anywhere else.
|
|
617
629
|
*/
|
|
618
630
|
export declare function reconcileDataTableView<R extends DataTableRow = DataTableRow>(view: DataTableView, columns: DataTableColumn<R>[]): DataTableView;
|
|
619
|
-
export {};
|
|
631
|
+
export { periodColumns, periodsOf, totalOf, type PeriodColumnsOptions, type PeriodUnit, type Period } from './periodColumns';
|
|
@@ -4,7 +4,7 @@ import React, { useMemo, useState, useEffect, useRef, useId, useLayoutEffect, us
|
|
|
4
4
|
import { useTable, tableFeatures, columnVisibilityFeature, columnPinningFeature, columnOrderingFeature, rowSelectionFeature, globalFilteringFeature, columnFilteringFeature, rowSortingFeature, createFilteredRowModel, createSortedRowModel } from "@tanstack/react-table";
|
|
5
5
|
import { DropdownMenu } from "../DropdownMenu/DropdownMenu.js";
|
|
6
6
|
import { Dropdown } from "../Dropdown/Dropdown.js";
|
|
7
|
-
import {
|
|
7
|
+
import { IconButton } from "../IconButton/IconButton.js";
|
|
8
8
|
import { Button } from "../Button/Button.js";
|
|
9
9
|
import { Spinner } from "../Spinner/Spinner.js";
|
|
10
10
|
import { VirtualRows } from "./VirtualRows.js";
|
|
@@ -191,6 +191,8 @@ function DataTable({
|
|
|
191
191
|
onSortsChange,
|
|
192
192
|
multiSort = false,
|
|
193
193
|
onViewChange,
|
|
194
|
+
view: viewProp,
|
|
195
|
+
defaultView,
|
|
194
196
|
virtualize = "auto",
|
|
195
197
|
onLoadMore,
|
|
196
198
|
hasMore = false,
|
|
@@ -293,7 +295,7 @@ function DataTable({
|
|
|
293
295
|
const locale = useLocale(localeProp);
|
|
294
296
|
const collator = useMemo(() => textCollator(locale), [locale]);
|
|
295
297
|
const compareValues = useMemo(() => valueComparator(collator), [collator]);
|
|
296
|
-
const [startingView] = useState(() => slotStartingView(toolbar));
|
|
298
|
+
const [startingView] = useState(() => viewProp ?? defaultView ?? slotStartingView(toolbar));
|
|
297
299
|
const startsWith = (key, controlled) => controlled === void 0 && startingView?.[key] !== void 0;
|
|
298
300
|
const [size, setSize] = useControllable(
|
|
299
301
|
sizeProp,
|
|
@@ -1133,6 +1135,13 @@ function DataTable({
|
|
|
1133
1135
|
if (next.pageSize !== void 0) setPageSize(next.pageSize);
|
|
1134
1136
|
setPage(1);
|
|
1135
1137
|
};
|
|
1138
|
+
const viewPropKey = viewProp ? viewKey(fullView(viewProp)) : null;
|
|
1139
|
+
const appliedViewKey = useRef(viewPropKey);
|
|
1140
|
+
useEffect(() => {
|
|
1141
|
+
if (!viewProp || viewPropKey === appliedViewKey.current) return;
|
|
1142
|
+
appliedViewKey.current = viewPropKey;
|
|
1143
|
+
if (viewPropKey !== currentKey) applyView(viewProp);
|
|
1144
|
+
}, [viewPropKey]);
|
|
1136
1145
|
const viewCallback = useRef(onViewChange);
|
|
1137
1146
|
useEffect(() => {
|
|
1138
1147
|
viewCallback.current = onViewChange;
|
|
@@ -1474,8 +1483,10 @@ function DataTable({
|
|
|
1474
1483
|
return String(result.value);
|
|
1475
1484
|
};
|
|
1476
1485
|
const groupTotal = (col, groupRows) => {
|
|
1477
|
-
if (!col.aggregate) return null;
|
|
1478
1486
|
const values = groupRows.map((row) => row.values[col.key]);
|
|
1487
|
+
const picked = totalsState[col.key];
|
|
1488
|
+
if (picked && picked !== "none") return resultText(col, calculate(picked, values));
|
|
1489
|
+
if (!col.aggregate) return null;
|
|
1479
1490
|
if (typeof col.aggregate === "function") return col.aggregate(values, groupRows);
|
|
1480
1491
|
return resultText(col, calculate(col.aggregate, values));
|
|
1481
1492
|
};
|
|
@@ -1752,13 +1763,13 @@ function DataTable({
|
|
|
1752
1763
|
onOpenChange: (open) => setMenuKey(open ? key : null),
|
|
1753
1764
|
items: menuItems(key),
|
|
1754
1765
|
trigger: /* @__PURE__ */ jsx(
|
|
1755
|
-
|
|
1766
|
+
IconButton,
|
|
1756
1767
|
{
|
|
1757
1768
|
icon: "more_horiz",
|
|
1758
1769
|
variant: "tertiary",
|
|
1759
1770
|
size: "compact",
|
|
1760
1771
|
tooltip: false,
|
|
1761
|
-
|
|
1772
|
+
label: labels.menu(text),
|
|
1762
1773
|
tabIndex: innerTab
|
|
1763
1774
|
}
|
|
1764
1775
|
)
|
|
@@ -2151,13 +2162,13 @@ function DataTable({
|
|
|
2151
2162
|
}
|
|
2152
2163
|
),
|
|
2153
2164
|
editMode === "cell" && editable && !isLive(col) && !editingHere && /* @__PURE__ */ jsx(
|
|
2154
|
-
|
|
2165
|
+
IconButton,
|
|
2155
2166
|
{
|
|
2156
2167
|
className: `${baseClass}__edit-hint${alignsEnd(col.align) ? ` ${baseClass}__edit-hint--start` : ""}`,
|
|
2157
2168
|
icon: "edit",
|
|
2158
2169
|
variant: "tertiary",
|
|
2159
2170
|
size: "compact",
|
|
2160
|
-
|
|
2171
|
+
label: labels.editCell(headerText(col), name),
|
|
2161
2172
|
tooltip: false,
|
|
2162
2173
|
tabIndex: -1,
|
|
2163
2174
|
onClick: () => startEdit(row.id, key)
|
|
@@ -2212,13 +2223,13 @@ function DataTable({
|
|
|
2212
2223
|
children: /* @__PURE__ */ jsxs("div", { className: `ds-table__cell-content ${baseClass}__actions-row`, children: [
|
|
2213
2224
|
editMode === "row" && editing?.row === row.id ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2214
2225
|
/* @__PURE__ */ jsx(
|
|
2215
|
-
|
|
2226
|
+
IconButton,
|
|
2216
2227
|
{
|
|
2217
2228
|
className: `${baseClass}__save`,
|
|
2218
2229
|
icon: "check",
|
|
2219
2230
|
variant: "tertiary",
|
|
2220
2231
|
size: "compact",
|
|
2221
|
-
|
|
2232
|
+
label: labels.saveRow(name),
|
|
2222
2233
|
tooltip: labels.saveRow(name),
|
|
2223
2234
|
tooltipPosition: "start",
|
|
2224
2235
|
onClick: () => commitEdit("stay"),
|
|
@@ -2226,13 +2237,13 @@ function DataTable({
|
|
|
2226
2237
|
}
|
|
2227
2238
|
),
|
|
2228
2239
|
/* @__PURE__ */ jsx(
|
|
2229
|
-
|
|
2240
|
+
IconButton,
|
|
2230
2241
|
{
|
|
2231
2242
|
className: `${baseClass}__cancel`,
|
|
2232
2243
|
icon: "close",
|
|
2233
2244
|
variant: "tertiary",
|
|
2234
2245
|
size: "compact",
|
|
2235
|
-
|
|
2246
|
+
label: labels.cancelRow(name),
|
|
2236
2247
|
tooltip: labels.cancelRow(name),
|
|
2237
2248
|
tooltipPosition: "start",
|
|
2238
2249
|
onClick: cancelEdit,
|
|
@@ -2240,13 +2251,13 @@ function DataTable({
|
|
|
2240
2251
|
}
|
|
2241
2252
|
)
|
|
2242
2253
|
] }) : editMode === "row" && visibleKeys.some((k) => canEdit(byKey.get(k), row) && !isLive(byKey.get(k))) && /* @__PURE__ */ jsx(
|
|
2243
|
-
|
|
2254
|
+
IconButton,
|
|
2244
2255
|
{
|
|
2245
2256
|
className: `${baseClass}__inline-action`,
|
|
2246
2257
|
icon: "edit",
|
|
2247
2258
|
variant: "tertiary",
|
|
2248
2259
|
size: "compact",
|
|
2249
|
-
|
|
2260
|
+
label: labels.editRow(name),
|
|
2250
2261
|
tooltip: labels.editRow(name),
|
|
2251
2262
|
tooltipPosition: "start",
|
|
2252
2263
|
disabled: editing !== null,
|
|
@@ -2255,13 +2266,13 @@ function DataTable({
|
|
|
2255
2266
|
}
|
|
2256
2267
|
),
|
|
2257
2268
|
!(editMode === "row" && editing?.row === row.id) && actionsFor(row).filter((action) => action.inline).map((action) => /* @__PURE__ */ jsx(
|
|
2258
|
-
|
|
2269
|
+
IconButton,
|
|
2259
2270
|
{
|
|
2260
2271
|
className: `${baseClass}__inline-action`,
|
|
2261
2272
|
icon: action.icon ?? "bolt",
|
|
2262
2273
|
variant: "tertiary",
|
|
2263
2274
|
size: "compact",
|
|
2264
|
-
|
|
2275
|
+
label: action.label,
|
|
2265
2276
|
tooltip: action.label,
|
|
2266
2277
|
tooltipPosition: "start",
|
|
2267
2278
|
disabled: action.disabled,
|
|
@@ -2283,13 +2294,13 @@ function DataTable({
|
|
|
2283
2294
|
onClick: action.onSelect
|
|
2284
2295
|
})),
|
|
2285
2296
|
trigger: /* @__PURE__ */ jsx(
|
|
2286
|
-
|
|
2297
|
+
IconButton,
|
|
2287
2298
|
{
|
|
2288
2299
|
icon: "more_horiz",
|
|
2289
2300
|
variant: "tertiary",
|
|
2290
2301
|
size: "compact",
|
|
2291
2302
|
tooltip: false,
|
|
2292
|
-
|
|
2303
|
+
label: labels.moreActions(name),
|
|
2293
2304
|
tabIndex: innerTab
|
|
2294
2305
|
}
|
|
2295
2306
|
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DataTableColumn, DataTableRow, DataTableValue } from './DataTable';
|
|
2
|
+
/** The length of one period column. */
|
|
3
|
+
export type PeriodUnit = 'day' | 'week' | 'month';
|
|
4
|
+
export interface PeriodColumnsOptions<R extends DataTableRow = DataTableRow> {
|
|
5
|
+
/** The first period's date, as `YYYY-MM-DD`. A week starts on this day; a month column is the month this day falls in. */
|
|
6
|
+
start: string;
|
|
7
|
+
/** How many periods, one column each. */
|
|
8
|
+
count: number;
|
|
9
|
+
/** How long each period is. */
|
|
10
|
+
unit: PeriodUnit;
|
|
11
|
+
/** The locale the headers are written in. */
|
|
12
|
+
locale?: string;
|
|
13
|
+
/** Prepended to each period's date to make its column key: `"d:2026-03-02"`. Defaults to `""`. */
|
|
14
|
+
keyPrefix?: string;
|
|
15
|
+
/** The header for a period, given its first day and its unit. Defaults to the weekday and day ("Mon 2") for a day, the first day ("Mar 2") for a week, and the month ("Mar") for a month, in `locale`. */
|
|
16
|
+
header?: (date: Date, unit: PeriodUnit) => string;
|
|
17
|
+
/** What every period column shares (its type, alignment, editability, aggregate), laid under the key and header. */
|
|
18
|
+
column?: Omit<DataTableColumn<R>, 'key' | 'header'>;
|
|
19
|
+
}
|
|
20
|
+
/** One period: its column key and its first day, as `YYYY-MM-DD`. */
|
|
21
|
+
export interface Period {
|
|
22
|
+
key: string;
|
|
23
|
+
date: string;
|
|
24
|
+
}
|
|
25
|
+
/** The periods a run covers, first first: each one's column key and first day. Dates are calendar dates, never moved by a time zone. */
|
|
26
|
+
export declare function periodsOf({ start, count, unit, keyPrefix }: Pick<PeriodColumnsOptions, 'start' | 'count' | 'unit' | 'keyPrefix'>): Period[];
|
|
27
|
+
/**
|
|
28
|
+
* Columns for a run of periods: one per day, week or month, for a table whose
|
|
29
|
+
* rows are measured across time (hours by day, a budget by month, stock by
|
|
30
|
+
* week). Each column's key is its first day, so a row's values are keyed the
|
|
31
|
+
* same way, and every column takes what `column` shares, so the run is
|
|
32
|
+
* edited, aggregated and aligned as one. Pair it with a computed total column
|
|
33
|
+
* (`totalOf`) and the totals row for the sums across and down.
|
|
34
|
+
*/
|
|
35
|
+
export declare function periodColumns<R extends DataTableRow = DataTableRow>({ locale, header, column, ...run }: PeriodColumnsOptions<R>): DataTableColumn<R>[];
|
|
36
|
+
/** A computed column's `compute`: the sum of the number values under these keys, for a total across a row. A value that is not a number counts as nothing. */
|
|
37
|
+
export declare const totalOf: (keys: readonly string[]) => (values: Record<string, DataTableValue>) => number;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DEFAULT_LOCALE } from "../../behaviors/locale.js";
|
|
2
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
3
|
+
const isoOf = (date) => `${date.getUTCFullYear()}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())}`;
|
|
4
|
+
function parse(start) {
|
|
5
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(start);
|
|
6
|
+
if (!match) throw new Error(`periodColumns: start must be YYYY-MM-DD, got ${JSON.stringify(start)}.`);
|
|
7
|
+
return new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3])));
|
|
8
|
+
}
|
|
9
|
+
function step(date, unit, n) {
|
|
10
|
+
if (unit === "month") return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + n, 1));
|
|
11
|
+
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() + n * (unit === "week" ? 7 : 1)));
|
|
12
|
+
}
|
|
13
|
+
function periodsOf({ start, count, unit, keyPrefix = "" }) {
|
|
14
|
+
const first = unit === "month" ? step(parse(start), "month", 0) : parse(start);
|
|
15
|
+
return Array.from({ length: Math.max(0, Math.floor(count)) }, (_, i) => {
|
|
16
|
+
const date = isoOf(step(first, unit, i));
|
|
17
|
+
return { key: `${keyPrefix}${date}`, date };
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function defaultHeader(locale) {
|
|
21
|
+
const day = new Intl.DateTimeFormat(locale, { weekday: "short", day: "numeric", timeZone: "UTC" });
|
|
22
|
+
const week = new Intl.DateTimeFormat(locale, { month: "short", day: "numeric", timeZone: "UTC" });
|
|
23
|
+
const month = new Intl.DateTimeFormat(locale, { month: "short", timeZone: "UTC" });
|
|
24
|
+
return (date, unit) => (unit === "day" ? day : unit === "week" ? week : month).format(date);
|
|
25
|
+
}
|
|
26
|
+
function periodColumns({
|
|
27
|
+
locale = DEFAULT_LOCALE,
|
|
28
|
+
header,
|
|
29
|
+
column,
|
|
30
|
+
...run
|
|
31
|
+
}) {
|
|
32
|
+
const write = header ?? defaultHeader(locale);
|
|
33
|
+
const first = run.unit === "month" ? null : parse(run.start);
|
|
34
|
+
return periodsOf(run).map(({ key, date }, i) => ({
|
|
35
|
+
...column,
|
|
36
|
+
key,
|
|
37
|
+
header: write(first ? step(first, run.unit, i) : parse(date), run.unit)
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
const totalOf = (keys) => (values) => keys.reduce((sum, key) => {
|
|
41
|
+
const value = values[key];
|
|
42
|
+
return typeof value === "number" && Number.isFinite(value) ? sum + value : sum;
|
|
43
|
+
}, 0);
|
|
44
|
+
export {
|
|
45
|
+
periodColumns,
|
|
46
|
+
periodsOf,
|
|
47
|
+
totalOf
|
|
48
|
+
};
|
|
@@ -131,3 +131,23 @@
|
|
|
131
131
|
.ds-date-input--disabled .ds-date-input__icon {
|
|
132
132
|
color: var(--color-input-text-disabled);
|
|
133
133
|
}
|
|
134
|
+
|
|
135
|
+
/* Icon side padding, Button's rule (design.md): a glyph's box carries its
|
|
136
|
+
own side bearing, so a side that holds one takes the step below the text
|
|
137
|
+
side. The calendar glyph moves in one step and the text keeps its
|
|
138
|
+
distance from it (16 → 12, compact 12 → 8). */
|
|
139
|
+
.ds-date-input__icon {
|
|
140
|
+
inset-inline-start: var(--padding-300);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.ds-date-input__field {
|
|
144
|
+
padding-inline-start: calc(var(--padding-300) + 24px + var(--gap-200)); /* 12px + 24px icon + 8px gap */
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.ds-date-input--compact .ds-date-input__icon {
|
|
148
|
+
inset-inline-start: var(--padding-200);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.ds-date-input--compact .ds-date-input__field {
|
|
152
|
+
padding-inline-start: calc(var(--padding-200) + 20px + var(--gap-200)); /* 8px + 20px icon + 8px gap */
|
|
153
|
+
}
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
border-radius: var(--radius-300); /* 12px */
|
|
13
13
|
background-color: var(--color-input-bg-primary);
|
|
14
14
|
user-select: none;
|
|
15
|
+
/* Never wider than its container: in a column narrower than seven full
|
|
16
|
+
days, the days shrink with it (below) rather than running off it. */
|
|
17
|
+
max-width: 100%;
|
|
18
|
+
box-sizing: border-box;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
/* ============================================
|
|
@@ -76,7 +80,7 @@
|
|
|
76
80
|
|
|
77
81
|
.ds-date-picker__grid {
|
|
78
82
|
display: grid;
|
|
79
|
-
grid-template-columns: repeat(7, 1fr);
|
|
83
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
80
84
|
gap: var(--gap-050); /* 2px */
|
|
81
85
|
}
|
|
82
86
|
|
|
@@ -90,7 +94,7 @@
|
|
|
90
94
|
.ds-date-picker__row {
|
|
91
95
|
display: grid;
|
|
92
96
|
grid-column: 1 / -1;
|
|
93
|
-
grid-template-columns: repeat(7, 1fr);
|
|
97
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
94
98
|
grid-template-columns: subgrid;
|
|
95
99
|
column-gap: var(--gap-050); /* 2px, the grid's own gap */
|
|
96
100
|
}
|
|
@@ -119,8 +123,12 @@
|
|
|
119
123
|
display: flex;
|
|
120
124
|
align-items: center;
|
|
121
125
|
justify-content: center;
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
/* The full 36px day, shrinking square with its column when the picker is
|
|
127
|
+
squeezed, so seven days always fit and never overlap. */
|
|
128
|
+
margin-inline: auto;
|
|
129
|
+
width: 100%;
|
|
130
|
+
max-width: 36px;
|
|
131
|
+
aspect-ratio: 1;
|
|
124
132
|
padding: 0;
|
|
125
133
|
border: none;
|
|
126
134
|
border-radius: var(--radius-pill);
|
|
@@ -198,11 +206,19 @@
|
|
|
198
206
|
}
|
|
199
207
|
|
|
200
208
|
.ds-date-picker--compact .ds-date-picker__cell {
|
|
201
|
-
width: 28px;
|
|
202
|
-
height: 28px;
|
|
209
|
+
max-width: 28px;
|
|
203
210
|
font-size: var(--font-caption-size);
|
|
204
211
|
}
|
|
205
212
|
|
|
213
|
+
/* On a phone the picker gives up some of its own padding before its days
|
|
214
|
+
give up size, so a squeezed picker keeps each day at least a 24px
|
|
215
|
+
target. */
|
|
216
|
+
@media (max-width: 480px) {
|
|
217
|
+
.ds-date-picker {
|
|
218
|
+
padding: var(--padding-300);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
206
222
|
/* ============================================
|
|
207
223
|
DISABLED STATE
|
|
208
224
|
============================================ */
|
|
@@ -32,7 +32,8 @@ type DatePickerOwnProps = {
|
|
|
32
32
|
/**
|
|
33
33
|
* The visible weekday column headers: seven entries, Sunday first, laid
|
|
34
34
|
* out from `weekStartsOn`. Defaults to the two-letter abbreviations ("Su"
|
|
35
|
-
* to "Sa") in English and the short weekday names in `locale` otherwise
|
|
35
|
+
* to "Sa") in English and the short weekday names in `locale` otherwise,
|
|
36
|
+
* or its narrow names where the short ones are whole words (Arabic); a
|
|
36
37
|
* list of any other length falls back to the default.
|
|
37
38
|
*/
|
|
38
39
|
weekdayLabels?: string[];
|
|
@@ -4,7 +4,7 @@ import React, { useMemo, useState, useRef, useEffect } from "react";
|
|
|
4
4
|
import "./DatePicker.css";
|
|
5
5
|
import "../../fonts/material-symbols.css";
|
|
6
6
|
import { useLocale } from "../../behaviors/LocaleProvider.js";
|
|
7
|
-
import { weekStartOf, rotateWeek, isEnglish, weekdayNamesIn } from "../../behaviors/locale.js";
|
|
7
|
+
import { weekStartOf, rotateWeek, isEnglish, weekdayHeadersIn, weekdayNamesIn } from "../../behaviors/locale.js";
|
|
8
8
|
import { MonthGrid } from "./MonthGrid.js";
|
|
9
9
|
import { parseDate, monthLabelIn, dayLabelIn, weekdaysOr, EN_DAYS, formatDate, visuallyHidden, isSameDay, keyMove } from "./calendar.js";
|
|
10
10
|
const DatePicker = React.forwardRef(
|
|
@@ -36,7 +36,7 @@ const DatePicker = React.forwardRef(
|
|
|
36
36
|
const monthLabel = useMemo(() => monthLabelProp ?? monthLabelIn(locale), [monthLabelProp, locale]);
|
|
37
37
|
const dayLabel = useMemo(() => dayLabelProp ?? dayLabelIn(locale), [dayLabelProp, locale]);
|
|
38
38
|
const weekdays = rotateWeek(
|
|
39
|
-
weekdaysOr(weekdayLabels, isEnglish(locale) ? EN_DAYS :
|
|
39
|
+
weekdaysOr(weekdayLabels, isEnglish(locale) ? EN_DAYS : weekdayHeadersIn(locale)),
|
|
40
40
|
weekStart
|
|
41
41
|
);
|
|
42
42
|
const weekdayFullNames = rotateWeek(
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useMemo, useRef, useEffect } from "react";
|
|
4
4
|
import { useLocale } from "../../behaviors/LocaleProvider.js";
|
|
5
|
-
import { weekStartOf, rotateWeek, isEnglish, weekdayNamesIn } from "../../behaviors/locale.js";
|
|
5
|
+
import { weekStartOf, rotateWeek, isEnglish, weekdayHeadersIn, weekdayNamesIn } from "../../behaviors/locale.js";
|
|
6
6
|
import { MonthGrid } from "../DatePicker/MonthGrid.js";
|
|
7
7
|
import { parseDate, monthLabelIn, fullDateIn, weekdaysOr, EN_DAYS, formatDate, isSameDay, visuallyHidden, addMonths, keyMove, daysBetween } from "../DatePicker/calendar.js";
|
|
8
8
|
import { Chip } from "../Chip/Chip.js";
|
|
@@ -54,7 +54,7 @@ function DateRangePicker({
|
|
|
54
54
|
const monthLabel = useMemo(() => monthLabelProp ?? monthLabelIn(locale), [monthLabelProp, locale]);
|
|
55
55
|
const fullDate = useMemo(() => fullDateIn(locale), [locale]);
|
|
56
56
|
const weekdays = rotateWeek(
|
|
57
|
-
weekdaysOr(weekdayLabels, isEnglish(locale) ? EN_DAYS :
|
|
57
|
+
weekdaysOr(weekdayLabels, isEnglish(locale) ? EN_DAYS : weekdayHeadersIn(locale)),
|
|
58
58
|
weekStart
|
|
59
59
|
);
|
|
60
60
|
const weekdayFullNames = rotateWeek(weekdaysOr(weekdayNames, weekdayNamesIn(locale, "long")), weekStart);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* ============================================
|
|
2
|
+
DECISION ROW
|
|
3
|
+
WidgetRow with a decision's lifecycle: the row's own layout, faces and
|
|
4
|
+
gaps are WidgetRow's (Widget.css), so a decision sits in a Widget beside
|
|
5
|
+
plain rows with nothing restated here. This file only adds the root and
|
|
6
|
+
the focus ring the row takes when it settles with nowhere else for focus
|
|
7
|
+
to go.
|
|
8
|
+
============================================ */
|
|
9
|
+
|
|
10
|
+
/* Base */
|
|
11
|
+
|
|
12
|
+
.ds-decision-row {
|
|
13
|
+
display: block;
|
|
14
|
+
min-width: 0;
|
|
15
|
+
border-radius: var(--radius-300);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* States */
|
|
19
|
+
|
|
20
|
+
/* A settled row with no Undo holds focus itself after the reader's press,
|
|
21
|
+
so the ring is the row's, in the focus colour every control uses. */
|
|
22
|
+
.ds-decision-row:focus-visible {
|
|
23
|
+
outline: 2px solid var(--color-action-primary-bg);
|
|
24
|
+
outline-offset: 2px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* The settled mark sits in the actions slot as one item. */
|
|
28
|
+
.ds-decision-row__outcome {
|
|
29
|
+
display: inline-flex;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Narrow rows: the title keeps a floor, stated on the icon scale, and the
|
|
33
|
+
decision wraps to its own line under it, set to the row's end, rather
|
|
34
|
+
than squeezing the title to nothing and running off the edge. */
|
|
35
|
+
.ds-decision-row .ds-widget-row {
|
|
36
|
+
flex-wrap: wrap;
|
|
37
|
+
row-gap: var(--gap-200);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.ds-decision-row .ds-widget-row__main {
|
|
41
|
+
flex-basis: calc(var(--icon-size-1200) * 3);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.ds-decision-row .ds-widget-row__actions {
|
|
45
|
+
margin-inline-start: auto;
|
|
46
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/** Where a decision stands: waiting on the reader, or settled one way or the other. */
|
|
3
|
+
export type DecisionRowStatus = 'pending' | 'accepted' | 'declined';
|
|
4
|
+
/** Props owned by DecisionRow itself; everything else falls through to the row's root `<div>`. */
|
|
5
|
+
type DecisionRowOwnProps = {
|
|
6
|
+
/** What is waiting on a decision: who asked and for what. Collides with the native `title` tooltip attribute on purpose: the row shows it. */
|
|
7
|
+
title: string;
|
|
8
|
+
/** A quiet second line: the dates, the amount, the reason given. */
|
|
9
|
+
description?: string;
|
|
10
|
+
/** A leading mark: an Avatar, a StatusDot, an icon. Decorative unless the element names itself. */
|
|
11
|
+
leading?: React.ReactNode;
|
|
12
|
+
/** A trailing fact before the decision: when it was asked, how long it has waited. */
|
|
13
|
+
meta?: React.ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Where the decision stands, for controlled use. Pair with `onStatusChange`. Unset, the row keeps its own, starting at `defaultStatus`.
|
|
16
|
+
* @default "pending"
|
|
17
|
+
*/
|
|
18
|
+
status?: DecisionRowStatus;
|
|
19
|
+
/** Where it stands to begin with, for uncontrolled use. */
|
|
20
|
+
defaultStatus?: DecisionRowStatus;
|
|
21
|
+
/** Fires with the new status when the reader accepts, declines or undoes. */
|
|
22
|
+
onStatusChange?: (status: DecisionRowStatus) => void;
|
|
23
|
+
/** Fires when the reader accepts. */
|
|
24
|
+
onAccept?: () => void;
|
|
25
|
+
/** Fires when the reader declines. */
|
|
26
|
+
onDecline?: () => void;
|
|
27
|
+
/** Offers Undo on a settled row, which returns it to pending and fires this. Leave it unset where a decision cannot be reversed. */
|
|
28
|
+
onUndo?: () => void;
|
|
29
|
+
/** The accept button's colour: `destructive` for a decision whose yes takes something away (remove a member, delete a draft), as ActionCard's `tone` does for a change. */
|
|
30
|
+
tone?: 'default' | 'destructive';
|
|
31
|
+
/** The accept button's words. */
|
|
32
|
+
acceptLabel?: string;
|
|
33
|
+
/** The decline button's words. */
|
|
34
|
+
declineLabel?: string;
|
|
35
|
+
/** The settled mark's words once accepted. */
|
|
36
|
+
acceptedLabel?: string;
|
|
37
|
+
/** The settled mark's words once declined. */
|
|
38
|
+
declinedLabel?: string;
|
|
39
|
+
/** The undo button's words. */
|
|
40
|
+
undoLabel?: string;
|
|
41
|
+
/** What is announced when the row settles, given its title and the settled mark's words: "Accepted: Room booking". */
|
|
42
|
+
settledAnnouncement?: (title: string, outcome: string) => string;
|
|
43
|
+
/** Additional CSS classes */
|
|
44
|
+
className?: string;
|
|
45
|
+
/** A ref onto the row's root `<div>`. */
|
|
46
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
47
|
+
};
|
|
48
|
+
export interface DecisionRowProps extends DecisionRowOwnProps, Omit<React.HTMLAttributes<HTMLDivElement>, keyof DecisionRowOwnProps> {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* DecisionRow: one item waiting on a yes or a no, as a row in a list. While
|
|
52
|
+
* it is pending it offers two buttons in the host's words (Approve and Deny,
|
|
53
|
+
* Accept and Decline, Keep and Discard); once decided it settles to a mark
|
|
54
|
+
* saying which, with Undo while the host can reverse it. It is WidgetRow with
|
|
55
|
+
* that lifecycle, so it sits in a Widget beside plain rows.
|
|
56
|
+
*
|
|
57
|
+
* The buttons leave the row when it settles, so focus moves with them, to
|
|
58
|
+
* Undo when there is one and to the row otherwise, and the outcome is
|
|
59
|
+
* announced, so a keyboard or screen-reader user is never left on nothing.
|
|
60
|
+
*/
|
|
61
|
+
export declare function DecisionRow({ title, description, leading, meta, status: statusProp, defaultStatus, onStatusChange, onAccept, onDecline, onUndo, tone, acceptLabel, declineLabel, acceptedLabel, declinedLabel, undoLabel, settledAnnouncement, className, ref, ...rest }: DecisionRowProps): React.JSX.Element;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useRef, useEffect } from "react";
|
|
4
|
+
import { Badge } from "../Badge/Badge.js";
|
|
5
|
+
import { Button } from "../Button/Button.js";
|
|
6
|
+
import { WidgetRow } from "../Widget/Widget.js";
|
|
7
|
+
import "../../behaviors/visually-hidden.css";
|
|
8
|
+
import "./DecisionRow.css";
|
|
9
|
+
function DecisionRow({
|
|
10
|
+
title,
|
|
11
|
+
description,
|
|
12
|
+
leading,
|
|
13
|
+
meta,
|
|
14
|
+
status: statusProp,
|
|
15
|
+
defaultStatus = "pending",
|
|
16
|
+
onStatusChange,
|
|
17
|
+
onAccept,
|
|
18
|
+
onDecline,
|
|
19
|
+
onUndo,
|
|
20
|
+
tone = "default",
|
|
21
|
+
acceptLabel = "Accept",
|
|
22
|
+
declineLabel = "Decline",
|
|
23
|
+
acceptedLabel = "Accepted",
|
|
24
|
+
declinedLabel = "Declined",
|
|
25
|
+
undoLabel = "Undo",
|
|
26
|
+
settledAnnouncement = (rowTitle, outcome) => `${outcome}: ${rowTitle}`,
|
|
27
|
+
className = "",
|
|
28
|
+
ref,
|
|
29
|
+
...rest
|
|
30
|
+
}) {
|
|
31
|
+
const baseClass = "ds-decision-row";
|
|
32
|
+
const [ownStatus, setOwnStatus] = useState(defaultStatus);
|
|
33
|
+
const status = statusProp ?? ownStatus;
|
|
34
|
+
const rootRef = useRef(null);
|
|
35
|
+
const movedByPress = useRef(false);
|
|
36
|
+
const setRef = (node) => {
|
|
37
|
+
rootRef.current = node;
|
|
38
|
+
if (typeof ref === "function") ref(node);
|
|
39
|
+
else if (ref) ref.current = node;
|
|
40
|
+
};
|
|
41
|
+
const decide = (next) => {
|
|
42
|
+
movedByPress.current = true;
|
|
43
|
+
if (statusProp === void 0) setOwnStatus(next);
|
|
44
|
+
onStatusChange?.(next);
|
|
45
|
+
if (next === "accepted") onAccept?.();
|
|
46
|
+
else if (next === "declined") onDecline?.();
|
|
47
|
+
else onUndo?.();
|
|
48
|
+
};
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!movedByPress.current) return;
|
|
51
|
+
movedByPress.current = false;
|
|
52
|
+
const root = rootRef.current;
|
|
53
|
+
if (!root) return;
|
|
54
|
+
const target = status === "pending" ? root.querySelector(`.${baseClass}__accept`) : root.querySelector(`.${baseClass}__undo`) ?? root;
|
|
55
|
+
target?.focus();
|
|
56
|
+
}, [status]);
|
|
57
|
+
const settled = status !== "pending";
|
|
58
|
+
const outcome = status === "accepted" ? acceptedLabel : declinedLabel;
|
|
59
|
+
const actions = settled ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
60
|
+
/* @__PURE__ */ jsx("span", { className: `${baseClass}__outcome`, "aria-hidden": "true", children: /* @__PURE__ */ jsx(Badge, { variant: status === "accepted" ? "positive" : "neutral", label: outcome }) }),
|
|
61
|
+
onUndo && /* @__PURE__ */ jsx(Button, { className: `${baseClass}__undo`, variant: "tertiary", size: "compact", iconLeft: "undo", label: undoLabel, onClick: () => decide("pending") })
|
|
62
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
63
|
+
/* @__PURE__ */ jsx(
|
|
64
|
+
Button,
|
|
65
|
+
{
|
|
66
|
+
className: `${baseClass}__accept`,
|
|
67
|
+
variant: "secondary",
|
|
68
|
+
tone,
|
|
69
|
+
size: "compact",
|
|
70
|
+
label: acceptLabel,
|
|
71
|
+
onClick: () => decide("accepted")
|
|
72
|
+
}
|
|
73
|
+
),
|
|
74
|
+
/* @__PURE__ */ jsx(Button, { variant: "tertiary", tone: "neutral", size: "compact", label: declineLabel, onClick: () => decide("declined") })
|
|
75
|
+
] });
|
|
76
|
+
return /* @__PURE__ */ jsxs(
|
|
77
|
+
"div",
|
|
78
|
+
{
|
|
79
|
+
...rest,
|
|
80
|
+
ref: setRef,
|
|
81
|
+
tabIndex: settled && !onUndo ? -1 : rest.tabIndex,
|
|
82
|
+
className: [baseClass, settled ? `${baseClass}--settled` : "", className].filter(Boolean).join(" "),
|
|
83
|
+
"data-status": status,
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ jsx(WidgetRow, { title, description, leading, meta, actions }),
|
|
86
|
+
/* @__PURE__ */ jsx("span", { className: "ds-visually-hidden", role: "status", children: settled ? settledAnnouncement(title, outcome) : "" })
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
DecisionRow
|
|
93
|
+
};
|
|
@@ -12,7 +12,7 @@ export interface DescriptionListCopyProps {
|
|
|
12
12
|
/**
|
|
13
13
|
* The copy button beside a description list value. Internal: DescriptionList
|
|
14
14
|
* renders it for a `copyable` item, so the list itself stays
|
|
15
|
-
* server-renderable. A compact tertiary
|
|
15
|
+
* server-renderable. A compact tertiary IconButton whose glyph and name
|
|
16
16
|
* turn to "Copied" for a moment after a press.
|
|
17
17
|
*/
|
|
18
18
|
export declare function DescriptionListCopy({ value, label, copiedLabel, onCopied }: DescriptionListCopyProps): import("react").JSX.Element;
|