@surfaces-ui/components 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +48 -2
- package/dist/appComponents.d.ts +86 -0
- package/dist/appComponents.js +555 -0
- package/dist/appComponents.js.map +1 -0
- package/dist/chart/BulletGraph.d.ts +44 -0
- package/dist/chart/BulletGraph.js +40 -0
- package/dist/chart/BulletGraph.js.map +1 -0
- package/dist/chart/Chart.d.ts +177 -0
- package/dist/chart/Chart.js +279 -0
- package/dist/chart/Chart.js.map +1 -0
- package/dist/chart/Sparkline.d.ts +35 -0
- package/dist/chart/Sparkline.js +37 -0
- package/dist/chart/Sparkline.js.map +1 -0
- package/dist/chart/advice.d.ts +28 -0
- package/dist/chart/advice.js +39 -0
- package/dist/chart/advice.js.map +1 -0
- package/dist/chart/option.d.ts +90 -0
- package/dist/chart/option.js +252 -0
- package/dist/chart/option.js.map +1 -0
- package/dist/controls/Combobox.d.ts +39 -0
- package/dist/controls/Combobox.js +75 -0
- package/dist/controls/Combobox.js.map +1 -0
- package/dist/controls/ConfirmDialog.d.ts +35 -0
- package/dist/controls/ConfirmDialog.js +84 -0
- package/dist/controls/ConfirmDialog.js.map +1 -0
- package/dist/controls/ItemControls.d.ts +115 -0
- package/dist/controls/ItemControls.js +109 -0
- package/dist/controls/ItemControls.js.map +1 -0
- package/dist/controls/Popover.d.ts +31 -0
- package/dist/controls/Popover.js +114 -0
- package/dist/controls/Popover.js.map +1 -0
- package/dist/controls/ResizeHandle.d.ts +48 -0
- package/dist/controls/ResizeHandle.js +91 -0
- package/dist/controls/ResizeHandle.js.map +1 -0
- package/dist/controls/SegmentedControl.d.ts +27 -0
- package/dist/controls/SegmentedControl.js +17 -0
- package/dist/controls/SegmentedControl.js.map +1 -0
- package/dist/controls/StatusBadge.d.ts +17 -0
- package/dist/controls/StatusBadge.js +10 -0
- package/dist/controls/StatusBadge.js.map +1 -0
- package/dist/controls/context.d.ts +17 -0
- package/dist/controls/context.js +2 -0
- package/dist/controls/context.js.map +1 -0
- package/dist/controls/placement.d.ts +43 -0
- package/dist/controls/placement.js +19 -0
- package/dist/controls/placement.js.map +1 -0
- package/dist/controls/resize.d.ts +23 -0
- package/dist/controls/resize.js +49 -0
- package/dist/controls/resize.js.map +1 -0
- package/dist/data/DataSourceProvider.d.ts +11 -0
- package/dist/data/DataSourceProvider.js +21 -0
- package/dist/data/DataSourceProvider.js.map +1 -0
- package/dist/data/export.d.ts +33 -0
- package/dist/data/export.js +77 -0
- package/dist/data/export.js.map +1 -0
- package/dist/data/format.d.ts +44 -0
- package/dist/data/format.js +127 -0
- package/dist/data/format.js.map +1 -0
- package/dist/data/messages.d.ts +13 -0
- package/dist/data/messages.js +2 -0
- package/dist/data/messages.js.map +1 -0
- package/dist/data/useRowWindow.d.ts +70 -0
- package/dist/data/useRowWindow.js +175 -0
- package/dist/data/useRowWindow.js.map +1 -0
- package/dist/discovery/AskData.d.ts +22 -0
- package/dist/discovery/AskData.js +48 -0
- package/dist/discovery/AskData.js.map +1 -0
- package/dist/discovery/ContextBuilder.d.ts +49 -0
- package/dist/discovery/ContextBuilder.js +167 -0
- package/dist/discovery/ContextBuilder.js.map +1 -0
- package/dist/discovery/DataSearch.d.ts +27 -0
- package/dist/discovery/DataSearch.js +73 -0
- package/dist/discovery/DataSearch.js.map +1 -0
- package/dist/discovery/ObjectDetail.d.ts +38 -0
- package/dist/discovery/ObjectDetail.js +129 -0
- package/dist/discovery/ObjectDetail.js.map +1 -0
- package/dist/discovery/RelationshipGraph.d.ts +19 -0
- package/dist/discovery/RelationshipGraph.js +64 -0
- package/dist/discovery/RelationshipGraph.js.map +1 -0
- package/dist/discovery/shared.d.ts +38 -0
- package/dist/discovery/shared.js +64 -0
- package/dist/discovery/shared.js.map +1 -0
- package/dist/editor/SqlEditor.d.ts +41 -0
- package/dist/editor/SqlEditor.js +181 -0
- package/dist/editor/SqlEditor.js.map +1 -0
- package/dist/explore/Explorer.d.ts +110 -0
- package/dist/explore/Explorer.js +471 -0
- package/dist/explore/Explorer.js.map +1 -0
- package/dist/explore/ModelLineage.d.ts +22 -0
- package/dist/explore/ModelLineage.js +70 -0
- package/dist/explore/ModelLineage.js.map +1 -0
- package/dist/explore/ReportBuilder.d.ts +39 -0
- package/dist/explore/ReportBuilder.js +98 -0
- package/dist/explore/ReportBuilder.js.map +1 -0
- package/dist/explore/SemanticModelEditor.d.ts +60 -0
- package/dist/explore/SemanticModelEditor.js +220 -0
- package/dist/explore/SemanticModelEditor.js.map +1 -0
- package/dist/explore/SemanticRows.d.ts +42 -0
- package/dist/explore/SemanticRows.js +117 -0
- package/dist/explore/SemanticRows.js.map +1 -0
- package/dist/explore/SemanticsProvider.d.ts +31 -0
- package/dist/explore/SemanticsProvider.js +72 -0
- package/dist/explore/SemanticsProvider.js.map +1 -0
- package/dist/explore/model.d.ts +151 -0
- package/dist/explore/model.js +344 -0
- package/dist/explore/model.js.map +1 -0
- package/dist/explore/report.d.ts +60 -0
- package/dist/explore/report.js +92 -0
- package/dist/explore/report.js.map +1 -0
- package/dist/explore/semantic-proposal.d.ts +44 -0
- package/dist/explore/semantic-proposal.js +67 -0
- package/dist/explore/semantic-proposal.js.map +1 -0
- package/dist/explore/semantic.d.ts +44 -0
- package/dist/explore/semantic.js +154 -0
- package/dist/explore/semantic.js.map +1 -0
- package/dist/files/FileBrowser.d.ts +42 -0
- package/dist/files/FileBrowser.js +314 -0
- package/dist/files/FileBrowser.js.map +1 -0
- package/dist/files/files.d.ts +65 -0
- package/dist/files/files.js +165 -0
- package/dist/files/files.js.map +1 -0
- package/dist/filter/FilterBar.d.ts +49 -0
- package/dist/filter/FilterBar.js +153 -0
- package/dist/filter/FilterBar.js.map +1 -0
- package/dist/filter/QueryFilters.d.ts +25 -0
- package/dist/filter/QueryFilters.js +58 -0
- package/dist/filter/QueryFilters.js.map +1 -0
- package/dist/form/Form.d.ts +76 -0
- package/dist/form/Form.js +131 -0
- package/dist/form/Form.js.map +1 -0
- package/dist/graph/NodeGraph.d.ts +30 -0
- package/dist/graph/NodeGraph.js +86 -0
- package/dist/graph/NodeGraph.js.map +1 -0
- package/dist/graph/model.d.ts +68 -0
- package/dist/graph/model.js +122 -0
- package/dist/graph/model.js.map +1 -0
- package/dist/grid/DataGrid.d.ts +98 -0
- package/dist/grid/DataGrid.js +399 -0
- package/dist/grid/DataGrid.js.map +1 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -0
- package/dist/locale/SurfacesText.d.ts +17 -0
- package/dist/locale/SurfacesText.js +17 -0
- package/dist/locale/SurfacesText.js.map +1 -0
- package/dist/locale/locale.d.ts +305 -0
- package/dist/locale/locale.js +359 -0
- package/dist/locale/locale.js.map +1 -0
- package/dist/menu/ContextMenu.d.ts +31 -0
- package/dist/menu/ContextMenu.js +95 -0
- package/dist/menu/ContextMenu.js.map +1 -0
- package/dist/metric/Metric.d.ts +33 -0
- package/dist/metric/Metric.js +63 -0
- package/dist/metric/Metric.js.map +1 -0
- package/dist/metric/useMeasure.d.ts +23 -0
- package/dist/metric/useMeasure.js +43 -0
- package/dist/metric/useMeasure.js.map +1 -0
- package/dist/model/ModelDiagram.d.ts +142 -0
- package/dist/model/ModelDiagram.js +699 -0
- package/dist/model/ModelDiagram.js.map +1 -0
- package/dist/panzoom/usePanZoom.d.ts +117 -0
- package/dist/panzoom/usePanZoom.js +313 -0
- package/dist/panzoom/usePanZoom.js.map +1 -0
- package/dist/pipeline/DatasetReview.d.ts +48 -0
- package/dist/pipeline/DatasetReview.js +157 -0
- package/dist/pipeline/DatasetReview.js.map +1 -0
- package/dist/pipeline/IngestWizard.d.ts +51 -0
- package/dist/pipeline/IngestWizard.js +79 -0
- package/dist/pipeline/IngestWizard.js.map +1 -0
- package/dist/pipeline/Pipeline.d.ts +171 -0
- package/dist/pipeline/Pipeline.js +203 -0
- package/dist/pipeline/Pipeline.js.map +1 -0
- package/dist/pipeline/PipelineView.d.ts +63 -0
- package/dist/pipeline/PipelineView.js +239 -0
- package/dist/pipeline/PipelineView.js.map +1 -0
- package/dist/pivot/PivotTable.d.ts +94 -0
- package/dist/pivot/PivotTable.js +171 -0
- package/dist/pivot/PivotTable.js.map +1 -0
- package/dist/plan/QueryPlan.d.ts +29 -0
- package/dist/plan/QueryPlan.js +79 -0
- package/dist/plan/QueryPlan.js.map +1 -0
- package/dist/result/QueryResult.d.ts +51 -0
- package/dist/result/QueryResult.js +255 -0
- package/dist/result/QueryResult.js.map +1 -0
- package/dist/review/ActionReceipt.d.ts +52 -0
- package/dist/review/ActionReceipt.js +32 -0
- package/dist/review/ActionReceipt.js.map +1 -0
- package/dist/review/PiiReview.d.ts +37 -0
- package/dist/review/PiiReview.js +29 -0
- package/dist/review/PiiReview.js.map +1 -0
- package/dist/review/PlanReview.d.ts +42 -0
- package/dist/review/PlanReview.js +37 -0
- package/dist/review/PlanReview.js.map +1 -0
- package/dist/review/StepFlow.d.ts +25 -0
- package/dist/review/StepFlow.js +21 -0
- package/dist/review/StepFlow.js.map +1 -0
- package/dist/review/pii.d.ts +21 -0
- package/dist/review/pii.js +67 -0
- package/dist/review/pii.js.map +1 -0
- package/dist/rows/RowList.d.ts +41 -0
- package/dist/rows/RowList.js +71 -0
- package/dist/rows/RowList.js.map +1 -0
- package/dist/schema/ObjectBrowser.d.ts +78 -0
- package/dist/schema/ObjectBrowser.js +467 -0
- package/dist/schema/ObjectBrowser.js.map +1 -0
- package/dist/schema/ObjectInfo.d.ts +25 -0
- package/dist/schema/ObjectInfo.js +69 -0
- package/dist/schema/ObjectInfo.js.map +1 -0
- package/dist/schema/SchemaExplorer.d.ts +32 -0
- package/dist/schema/SchemaExplorer.js +175 -0
- package/dist/schema/SchemaExplorer.js.map +1 -0
- package/dist/schema/refs.d.ts +32 -0
- package/dist/schema/refs.js +65 -0
- package/dist/schema/refs.js.map +1 -0
- package/dist/site/Site.d.ts +191 -0
- package/dist/site/Site.js +138 -0
- package/dist/site/Site.js.map +1 -0
- package/dist/source/ConnectionBuilder.d.ts +54 -0
- package/dist/source/ConnectionBuilder.js +115 -0
- package/dist/source/ConnectionBuilder.js.map +1 -0
- package/dist/source/SourceList.d.ts +17 -0
- package/dist/source/SourceList.js +71 -0
- package/dist/source/SourceList.js.map +1 -0
- package/dist/styles.css +9882 -0
- package/dist/styles.layer.css +9886 -0
- package/dist/table/DataTable.d.ts +72 -0
- package/dist/table/DataTable.js +68 -0
- package/dist/table/DataTable.js.map +1 -0
- package/dist/table/Pagination.d.ts +20 -0
- package/dist/table/Pagination.js +16 -0
- package/dist/table/Pagination.js.map +1 -0
- package/dist/table/SelectionBar.d.ts +43 -0
- package/dist/table/SelectionBar.js +18 -0
- package/dist/table/SelectionBar.js.map +1 -0
- package/dist/text/Markdown.d.ts +71 -0
- package/dist/text/Markdown.js +187 -0
- package/dist/text/Markdown.js.map +1 -0
- package/dist/text/highlight.d.ts +23 -0
- package/dist/text/highlight.js +196 -0
- package/dist/text/highlight.js.map +1 -0
- package/dist/theme/ThemePicker.d.ts +16 -0
- package/dist/theme/ThemePicker.js +49 -0
- package/dist/theme/ThemePicker.js.map +1 -0
- package/dist/theme/ThemeProvider.d.ts +43 -0
- package/dist/theme/ThemeProvider.js +107 -0
- package/dist/theme/ThemeProvider.js.map +1 -0
- package/dist/workspace/NavBar.d.ts +23 -0
- package/dist/workspace/NavBar.js +171 -0
- package/dist/workspace/NavBar.js.map +1 -0
- package/dist/workspace/SideNav.d.ts +61 -0
- package/dist/workspace/SideNav.js +149 -0
- package/dist/workspace/SideNav.js.map +1 -0
- package/dist/workspace/Workspace.d.ts +50 -0
- package/dist/workspace/Workspace.js +243 -0
- package/dist/workspace/Workspace.js.map +1 -0
- package/dist/workspace/icons.d.ts +34 -0
- package/dist/workspace/icons.js +37 -0
- package/dist/workspace/icons.js.map +1 -0
- package/dist/workspace/layout.d.ts +74 -0
- package/dist/workspace/layout.js +276 -0
- package/dist/workspace/layout.js.map +1 -0
- package/package.json +85 -3
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { label as text } from "../locale/locale.js";
|
|
4
|
+
/**
|
|
5
|
+
* Asks a person to confirm one action before it runs, as a modal dialog: the page behind cannot be used, focus starts
|
|
6
|
+
* inside it and returns where it was, and Escape cancels. Name the button for the action. For something that can be
|
|
7
|
+
* undone, prefer doing it and offering Undo (`ActionReceipt`). `useConfirm` asks from code and waits for the answer.
|
|
8
|
+
*/
|
|
9
|
+
export function ConfirmDialog({ open, title, body, confirmLabel, cancelLabel, danger, onConfirm, onCancel, className }) {
|
|
10
|
+
const dialog = useRef(null);
|
|
11
|
+
const cancel = useRef(null);
|
|
12
|
+
const confirm = useRef(null);
|
|
13
|
+
const titleId = useId();
|
|
14
|
+
const bodyId = useId();
|
|
15
|
+
const answered = useRef(false);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const element = dialog.current;
|
|
18
|
+
if (!element)
|
|
19
|
+
return;
|
|
20
|
+
if (open && !element.open) {
|
|
21
|
+
answered.current = false;
|
|
22
|
+
const back = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
23
|
+
// A browser without modal dialogs (and jsdom) still shows it, without making the page behind inert.
|
|
24
|
+
if (typeof element.showModal === "function")
|
|
25
|
+
element.showModal();
|
|
26
|
+
else
|
|
27
|
+
element.setAttribute("open", "");
|
|
28
|
+
(danger ? cancel : confirm).current?.focus();
|
|
29
|
+
return () => {
|
|
30
|
+
if (element.open)
|
|
31
|
+
element.close?.();
|
|
32
|
+
element.removeAttribute("open");
|
|
33
|
+
back?.focus();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}, [open, danger]);
|
|
38
|
+
const answer = (yes) => {
|
|
39
|
+
if (answered.current)
|
|
40
|
+
return;
|
|
41
|
+
answered.current = true;
|
|
42
|
+
if (yes)
|
|
43
|
+
onConfirm();
|
|
44
|
+
else
|
|
45
|
+
onCancel();
|
|
46
|
+
};
|
|
47
|
+
if (!open)
|
|
48
|
+
return null;
|
|
49
|
+
return (_jsxs("dialog", { ref: dialog, className: ["sf-confirm", className].filter(Boolean).join(" "), "aria-labelledby": titleId, "aria-describedby": body ? bodyId : undefined, onCancel: (event) => {
|
|
50
|
+
// Escape: answer as Cancel, and let React close it.
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
answer(false);
|
|
53
|
+
}, onMouseDown: (event) => {
|
|
54
|
+
// A press on the backdrop lands on the dialog itself, outside its box.
|
|
55
|
+
if (event.target === dialog.current) {
|
|
56
|
+
const box = dialog.current.getBoundingClientRect();
|
|
57
|
+
const inside = event.clientX >= box.left && event.clientX <= box.right && event.clientY >= box.top && event.clientY <= box.bottom;
|
|
58
|
+
if (!inside)
|
|
59
|
+
answer(false);
|
|
60
|
+
}
|
|
61
|
+
}, children: [_jsx("h2", { id: titleId, className: "sf-confirm-title", children: title }), body && (_jsx("div", { id: bodyId, className: "sf-confirm-body", children: body })), _jsxs("div", { className: "sf-confirm-actions", children: [_jsx("button", { ref: cancel, type: "button", className: "sf-button", onClick: () => answer(false), children: cancelLabel ?? text("confirm.cancel") }), _jsx("button", { ref: confirm, type: "button", className: "sf-button", "data-variant": danger ? "danger" : "primary", onClick: () => answer(true), children: confirmLabel ?? text("confirm.confirm") })] })] }));
|
|
62
|
+
}
|
|
63
|
+
/** Asks for confirmation from an event handler: `if (await confirm({ title, body, confirmLabel, danger })) run()`. */
|
|
64
|
+
export function useConfirm() {
|
|
65
|
+
const [request, setRequest] = useState();
|
|
66
|
+
const pending = useRef(undefined);
|
|
67
|
+
const settle = useCallback((yes) => {
|
|
68
|
+
const resolve = pending.current;
|
|
69
|
+
pending.current = undefined;
|
|
70
|
+
setRequest(undefined);
|
|
71
|
+
resolve?.(yes);
|
|
72
|
+
}, []);
|
|
73
|
+
useEffect(() => () => pending.current?.(false), []);
|
|
74
|
+
const confirm = useCallback((next) => {
|
|
75
|
+
pending.current?.(false);
|
|
76
|
+
setRequest(next);
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
pending.current = resolve;
|
|
79
|
+
});
|
|
80
|
+
}, []);
|
|
81
|
+
const element = request ? _jsx(ConfirmDialog, { ...request, open: true, onConfirm: () => settle(true), onCancel: () => settle(false) }) : null;
|
|
82
|
+
return { confirm, element };
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=ConfirmDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfirmDialog.js","sourceRoot":"","sources":["../../src/controls/ConfirmDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxF,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAqBpD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAsB;IACxI,MAAM,MAAM,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,KAAK,EAAE,CAAC;IACxB,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE/B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,IAAI,IAAI,IAAI,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AAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["import { type ReactNode, useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport { label as text } from \"../locale/locale.js\";\n\nexport interface ConfirmDialogProps {\n /** Whether the dialog is showing. */\n open: boolean;\n /** The question, as a heading: \"Turn off 5 accounts?\" */\n title: string;\n /** What will happen, and what cannot be undone. */\n body?: ReactNode;\n /** The button that goes ahead, named for what it does: \"Turn off\", not \"OK\". Defaults to \"Confirm\". */\n confirmLabel?: string;\n /** Defaults to \"Cancel\". */\n cancelLabel?: string;\n /** For something that takes away or cannot be undone: the button is marked, and Cancel has focus first. */\n danger?: boolean;\n onConfirm(): void;\n /** Cancel, Escape, or a press outside the dialog. */\n onCancel(): void;\n className?: string;\n}\n\n/**\n * Asks a person to confirm one action before it runs, as a modal dialog: the page behind cannot be used, focus starts\n * inside it and returns where it was, and Escape cancels. Name the button for the action. For something that can be\n * undone, prefer doing it and offering Undo (`ActionReceipt`). `useConfirm` asks from code and waits for the answer.\n */\nexport function ConfirmDialog({ open, title, body, confirmLabel, cancelLabel, danger, onConfirm, onCancel, className }: ConfirmDialogProps) {\n const dialog = useRef<HTMLDialogElement>(null);\n const cancel = useRef<HTMLButtonElement>(null);\n const confirm = useRef<HTMLButtonElement>(null);\n const titleId = useId();\n const bodyId = useId();\n const answered = useRef(false);\n\n useEffect(() => {\n const element = dialog.current;\n if (!element) return;\n if (open && !element.open) {\n answered.current = false;\n const back = document.activeElement instanceof HTMLElement ? document.activeElement : null;\n // A browser without modal dialogs (and jsdom) still shows it, without making the page behind inert.\n if (typeof element.showModal === \"function\") element.showModal();\n else element.setAttribute(\"open\", \"\");\n (danger ? cancel : confirm).current?.focus();\n return () => {\n if (element.open) element.close?.();\n element.removeAttribute(\"open\");\n back?.focus();\n };\n }\n return undefined;\n }, [open, danger]);\n\n const answer = (yes: boolean) => {\n if (answered.current) return;\n answered.current = true;\n if (yes) onConfirm();\n else onCancel();\n };\n\n if (!open) return null;\n return (\n <dialog\n ref={dialog}\n className={[\"sf-confirm\", className].filter(Boolean).join(\" \")}\n aria-labelledby={titleId}\n aria-describedby={body ? bodyId : undefined}\n onCancel={(event) => {\n // Escape: answer as Cancel, and let React close it.\n event.preventDefault();\n answer(false);\n }}\n onMouseDown={(event) => {\n // A press on the backdrop lands on the dialog itself, outside its box.\n if (event.target === dialog.current) {\n const box = dialog.current.getBoundingClientRect();\n const inside = event.clientX >= box.left && event.clientX <= box.right && event.clientY >= box.top && event.clientY <= box.bottom;\n if (!inside) answer(false);\n }\n }}\n >\n <h2 id={titleId} className=\"sf-confirm-title\">\n {title}\n </h2>\n {body && (\n <div id={bodyId} className=\"sf-confirm-body\">\n {body}\n </div>\n )}\n <div className=\"sf-confirm-actions\">\n <button ref={cancel} type=\"button\" className=\"sf-button\" onClick={() => answer(false)}>\n {cancelLabel ?? text(\"confirm.cancel\")}\n </button>\n <button ref={confirm} type=\"button\" className=\"sf-button\" data-variant={danger ? \"danger\" : \"primary\"} onClick={() => answer(true)}>\n {confirmLabel ?? text(\"confirm.confirm\")}\n </button>\n </div>\n </dialog>\n );\n}\n\n/** What `useConfirm`'s `confirm` asks. */\nexport type ConfirmRequest = Omit<ConfirmDialogProps, \"open\" | \"onConfirm\" | \"onCancel\">;\n\nexport interface Confirm {\n /** Shows the dialog and resolves true if the person goes ahead, false if not. Asking again while one is open answers the first with false. */\n confirm(request: ConfirmRequest): Promise<boolean>;\n /** Render this once, anywhere in the component. */\n element: ReactNode;\n}\n\n/** Asks for confirmation from an event handler: `if (await confirm({ title, body, confirmLabel, danger })) run()`. */\nexport function useConfirm(): Confirm {\n const [request, setRequest] = useState<ConfirmRequest>();\n const pending = useRef<(yes: boolean) => void>(undefined);\n const settle = useCallback((yes: boolean) => {\n const resolve = pending.current;\n pending.current = undefined;\n setRequest(undefined);\n resolve?.(yes);\n }, []);\n useEffect(() => () => pending.current?.(false), []);\n const confirm = useCallback((next: ConfirmRequest) => {\n pending.current?.(false);\n setRequest(next);\n return new Promise<boolean>((resolve) => {\n pending.current = resolve;\n });\n }, []);\n const element = request ? <ConfirmDialog {...request} open onConfirm={() => settle(true)} onCancel={() => settle(false)} /> : null;\n return { confirm, element };\n}\n"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
declare const PATHS: {
|
|
3
|
+
readonly edit: "M4 20h4L19 9l-4-4L4 16z M14 6l4 4";
|
|
4
|
+
readonly chart: "M4 4v16h16 M8 16v-5 M12 16V8 M16 16v-9";
|
|
5
|
+
readonly table: "M3 5h18v14H3z M3 10h18 M3 15h18 M9 5v14";
|
|
6
|
+
readonly wider: "M3 12h18 M7 8l-4 4 4 4 M17 8l4 4-4 4";
|
|
7
|
+
readonly narrower: "M3 12h6 M21 12h-6 M5 8l4 4-4 4 M19 8l-4 4 4 4";
|
|
8
|
+
readonly earlier: "M19 12H5 M11 6l-6 6 6 6";
|
|
9
|
+
readonly later: "M5 12h14 M13 6l6 6-6 6";
|
|
10
|
+
readonly up: "M12 19V5 M6 11l6-6 6 6";
|
|
11
|
+
readonly down: "M12 5v14 M6 13l6 6 6-6";
|
|
12
|
+
readonly duplicate: "M8 8h11v11H8z M5 16V5h11";
|
|
13
|
+
readonly remove: "M5 7h14 M10 7V4h4v3 M7 7l1 13h8l1-13 M10 11v6 M14 11v6";
|
|
14
|
+
readonly add: "M12 5v14 M5 12h14";
|
|
15
|
+
readonly close: "M6 6l12 12 M18 6L6 18";
|
|
16
|
+
readonly menu: "M4 7h16 M4 12h16 M4 17h16";
|
|
17
|
+
readonly fold: "M4 4v16 M20 12H9 M14 7l-5 5 5 5";
|
|
18
|
+
readonly unfold: "M20 4v16 M4 12h11 M10 7l5 5-5 5";
|
|
19
|
+
readonly confirm: "M5 12l5 5 9-10";
|
|
20
|
+
readonly power: "M12 3v8 M7 6.5a7 7 0 1 0 10 0";
|
|
21
|
+
readonly "sign-out": "M10 4H5v16h5 M15 8l4 4-4 4 M19 12H9";
|
|
22
|
+
readonly more: "M4.8 12a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0 M10.8 12a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0 M16.8 12a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0";
|
|
23
|
+
};
|
|
24
|
+
/** The drawings the shared controls use. One set, so the same action looks the same wherever it appears. */
|
|
25
|
+
export type ControlIconName = keyof typeof PATHS;
|
|
26
|
+
export declare const CONTROL_ICONS: ControlIconName[];
|
|
27
|
+
export declare function ControlIcon({ icon }: {
|
|
28
|
+
icon: ControlIconName | ReactNode;
|
|
29
|
+
}): import("react").JSX.Element;
|
|
30
|
+
/** One control on an item: an icon, and its name for assistive technology and the tooltip. */
|
|
31
|
+
export interface ItemControl {
|
|
32
|
+
/** What it does, as a word: "edit", "remove". Put on the button as `data-control`. */
|
|
33
|
+
id: string;
|
|
34
|
+
/** The button's full name, said by a screen reader and shown at once on hover and focus: "Remove Refund rate by category". */
|
|
35
|
+
label: string;
|
|
36
|
+
icon: ControlIconName | ReactNode;
|
|
37
|
+
onSelect(): void;
|
|
38
|
+
/** Shown but cannot be used: the first item cannot move earlier. It can still be focused, so its name can be read. */
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
/** For a control that removes or destroys. Marked by more than colour: it comes last, after a gap. */
|
|
41
|
+
danger?: boolean;
|
|
42
|
+
/** For a control that switches something on and off. */
|
|
43
|
+
pressed?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Stays visible when the rest are quiet: for the one action a person
|
|
46
|
+
* must be able to find without pointing at the item first (a report's
|
|
47
|
+
* "Add to report"). Use it sparingly, and not on a control that cannot
|
|
48
|
+
* be used right now.
|
|
49
|
+
*/
|
|
50
|
+
pinned?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface ItemControlsProps {
|
|
53
|
+
/** Names the group: "Refund rate by category controls". */
|
|
54
|
+
label: string;
|
|
55
|
+
controls: ItemControl[];
|
|
56
|
+
/**
|
|
57
|
+
* "hover" (the default) shows the controls when the pointer is over the
|
|
58
|
+
* item they belong to, or focus is inside it; give that item the class
|
|
59
|
+
* `sf-controls-host`. On a touch screen, which has no hover, they are
|
|
60
|
+
* always shown. "always" keeps them shown.
|
|
61
|
+
*/
|
|
62
|
+
show?: "hover" | "always";
|
|
63
|
+
/**
|
|
64
|
+
* Whether an outer layer of controls can hide these (see `CONTROLS_QUIET`).
|
|
65
|
+
* True by default; the outer layer's own controls pass false.
|
|
66
|
+
*/
|
|
67
|
+
quietable?: boolean;
|
|
68
|
+
className?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Put this class on a region to hide the item controls inside it, so that
|
|
72
|
+
* two layers of controls are never on screen at once: an editor that frames
|
|
73
|
+
* each component with its own controls (move, remove, resize) quiets the
|
|
74
|
+
* controls of what it frames while it is arranging.
|
|
75
|
+
*/
|
|
76
|
+
export declare const CONTROLS_QUIET = "sf-controls-quiet";
|
|
77
|
+
/** Put this class on the item a set of hover controls belongs to. */
|
|
78
|
+
export declare const CONTROLS_HOST = "sf-controls-host";
|
|
79
|
+
/**
|
|
80
|
+
* The controls of one item (a tile, a card, a framed component) as a row of
|
|
81
|
+
* icons: quiet until the item is pointed at or focused, each named at once
|
|
82
|
+
* in a tooltip, and one stop in the tab order with the arrow keys moving
|
|
83
|
+
* between them. Every part of the library that lets a person change, move,
|
|
84
|
+
* resize or remove an item uses this, with `standardControls` for the
|
|
85
|
+
* actions they share, so the same action has the same icon, name and place
|
|
86
|
+
* everywhere.
|
|
87
|
+
*/
|
|
88
|
+
export declare function ItemControls({ label, controls, show, quietable, className }: ItemControlsProps): import("react").JSX.Element | null;
|
|
89
|
+
/** What an item can have done to it. A handler left out leaves the control out; `false` shows it greyed, for an action that makes no sense right now. */
|
|
90
|
+
export interface StandardActions {
|
|
91
|
+
edit?: (() => void) | false;
|
|
92
|
+
/** Switch between a chart and a table. `now` is what is showing. */
|
|
93
|
+
view?: {
|
|
94
|
+
now: "chart" | "table";
|
|
95
|
+
toggle(): void;
|
|
96
|
+
};
|
|
97
|
+
wider?: (() => void) | false;
|
|
98
|
+
narrower?: (() => void) | false;
|
|
99
|
+
/** Earlier and later in reading order, for items laid out across. */
|
|
100
|
+
earlier?: (() => void) | false;
|
|
101
|
+
later?: (() => void) | false;
|
|
102
|
+
/** Up and down, for items stacked. */
|
|
103
|
+
up?: (() => void) | false;
|
|
104
|
+
down?: (() => void) | false;
|
|
105
|
+
duplicate?: (() => void) | false;
|
|
106
|
+
remove?: (() => void) | false;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The controls an item shares with every other kind of item, in one order
|
|
110
|
+
* and with one wording: change, chart or table, wider, narrower, move,
|
|
111
|
+
* duplicate, remove. `name` is what the item is called ("Refund rate by
|
|
112
|
+
* category", "Chart revenue"), and goes into each control's name.
|
|
113
|
+
*/
|
|
114
|
+
export declare function standardControls(name: string, actions: StandardActions): ItemControl[];
|
|
115
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
const PATHS = {
|
|
4
|
+
edit: "M4 20h4L19 9l-4-4L4 16z M14 6l4 4",
|
|
5
|
+
chart: "M4 4v16h16 M8 16v-5 M12 16V8 M16 16v-9",
|
|
6
|
+
table: "M3 5h18v14H3z M3 10h18 M3 15h18 M9 5v14",
|
|
7
|
+
wider: "M3 12h18 M7 8l-4 4 4 4 M17 8l4 4-4 4",
|
|
8
|
+
narrower: "M3 12h6 M21 12h-6 M5 8l4 4-4 4 M19 8l-4 4 4 4",
|
|
9
|
+
earlier: "M19 12H5 M11 6l-6 6 6 6",
|
|
10
|
+
later: "M5 12h14 M13 6l6 6-6 6",
|
|
11
|
+
up: "M12 19V5 M6 11l6-6 6 6",
|
|
12
|
+
down: "M12 5v14 M6 13l6 6 6-6",
|
|
13
|
+
duplicate: "M8 8h11v11H8z M5 16V5h11",
|
|
14
|
+
remove: "M5 7h14 M10 7V4h4v3 M7 7l1 13h8l1-13 M10 11v6 M14 11v6",
|
|
15
|
+
add: "M12 5v14 M5 12h14",
|
|
16
|
+
close: "M6 6l12 12 M18 6L6 18",
|
|
17
|
+
menu: "M4 7h16 M4 12h16 M4 17h16",
|
|
18
|
+
fold: "M4 4v16 M20 12H9 M14 7l-5 5 5 5",
|
|
19
|
+
unfold: "M20 4v16 M4 12h11 M10 7l5 5-5 5",
|
|
20
|
+
confirm: "M5 12l5 5 9-10",
|
|
21
|
+
power: "M12 3v8 M7 6.5a7 7 0 1 0 10 0",
|
|
22
|
+
"sign-out": "M10 4H5v16h5 M15 8l4 4-4 4 M19 12H9",
|
|
23
|
+
more: "M4.8 12a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0 M10.8 12a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0 M16.8 12a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0",
|
|
24
|
+
};
|
|
25
|
+
export const CONTROL_ICONS = Object.keys(PATHS);
|
|
26
|
+
export function ControlIcon({ icon }) {
|
|
27
|
+
if (typeof icon === "string" && icon in PATHS) {
|
|
28
|
+
return (_jsx("svg", { className: "sf-item-control-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: PATHS[icon] }) }));
|
|
29
|
+
}
|
|
30
|
+
return _jsx("span", { className: "sf-item-control-icon", children: icon });
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Put this class on a region to hide the item controls inside it, so that
|
|
34
|
+
* two layers of controls are never on screen at once: an editor that frames
|
|
35
|
+
* each component with its own controls (move, remove, resize) quiets the
|
|
36
|
+
* controls of what it frames while it is arranging.
|
|
37
|
+
*/
|
|
38
|
+
export const CONTROLS_QUIET = "sf-controls-quiet";
|
|
39
|
+
/** Put this class on the item a set of hover controls belongs to. */
|
|
40
|
+
export const CONTROLS_HOST = "sf-controls-host";
|
|
41
|
+
/**
|
|
42
|
+
* The controls of one item (a tile, a card, a framed component) as a row of
|
|
43
|
+
* icons: quiet until the item is pointed at or focused, each named at once
|
|
44
|
+
* in a tooltip, and one stop in the tab order with the arrow keys moving
|
|
45
|
+
* between them. Every part of the library that lets a person change, move,
|
|
46
|
+
* resize or remove an item uses this, with `standardControls` for the
|
|
47
|
+
* actions they share, so the same action has the same icon, name and place
|
|
48
|
+
* everywhere.
|
|
49
|
+
*/
|
|
50
|
+
export function ItemControls({ label, controls, show = "hover", quietable = true, className }) {
|
|
51
|
+
const bar = useRef(null);
|
|
52
|
+
const [current, setCurrent] = useState(0);
|
|
53
|
+
const [tip, setTip] = useState();
|
|
54
|
+
const at = Math.min(current, Math.max(0, controls.length - 1));
|
|
55
|
+
const focus = (index) => {
|
|
56
|
+
const next = (index + controls.length) % controls.length;
|
|
57
|
+
setCurrent(next);
|
|
58
|
+
bar.current?.querySelectorAll("button")[next]?.focus();
|
|
59
|
+
};
|
|
60
|
+
const onKeyDown = (event) => {
|
|
61
|
+
if (event.key === "ArrowRight" || event.key === "ArrowDown")
|
|
62
|
+
focus(at + 1);
|
|
63
|
+
else if (event.key === "ArrowLeft" || event.key === "ArrowUp")
|
|
64
|
+
focus(at - 1);
|
|
65
|
+
else if (event.key === "Home")
|
|
66
|
+
focus(0);
|
|
67
|
+
else if (event.key === "End")
|
|
68
|
+
focus(controls.length - 1);
|
|
69
|
+
else if (event.key === "Escape" && tip !== undefined)
|
|
70
|
+
setTip(undefined);
|
|
71
|
+
else
|
|
72
|
+
return;
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
event.stopPropagation();
|
|
75
|
+
};
|
|
76
|
+
if (controls.length === 0)
|
|
77
|
+
return null;
|
|
78
|
+
return (_jsx("div", { ref: bar, className: ["sf-item-controls", className].filter(Boolean).join(" "), role: "toolbar", "aria-label": label, "data-show": show, "data-quietable": quietable || undefined, onKeyDown: onKeyDown, children: controls.map((control, index) => (_jsxs("button", { type: "button", className: "sf-item-control", "data-control": control.id, "data-danger": control.danger || undefined, "data-pinned": (control.pinned && !control.disabled) || undefined, "aria-label": control.label, "aria-pressed": control.pressed, "aria-disabled": control.disabled || undefined, tabIndex: index === at ? 0 : -1, onClick: () => !control.disabled && control.onSelect(), onFocus: () => {
|
|
79
|
+
setCurrent(index);
|
|
80
|
+
setTip(index);
|
|
81
|
+
}, onBlur: () => setTip((now) => (now === index ? undefined : now)), onPointerEnter: () => setTip(index), onPointerLeave: () => setTip((now) => (now === index ? undefined : now)), children: [_jsx(ControlIcon, { icon: control.icon }), tip === index && (_jsxs("span", { className: "sf-item-tip", "aria-hidden": "true", children: [control.label, control.disabled ? " (not available here)" : ""] }))] }, control.id))) }));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The controls an item shares with every other kind of item, in one order
|
|
85
|
+
* and with one wording: change, chart or table, wider, narrower, move,
|
|
86
|
+
* duplicate, remove. `name` is what the item is called ("Refund rate by
|
|
87
|
+
* category", "Chart revenue"), and goes into each control's name.
|
|
88
|
+
*/
|
|
89
|
+
export function standardControls(name, actions) {
|
|
90
|
+
const out = [];
|
|
91
|
+
const add = (id, label, icon, handler, extra = {}) => {
|
|
92
|
+
if (handler === undefined)
|
|
93
|
+
return;
|
|
94
|
+
out.push({ id, label, icon, onSelect: handler || (() => undefined), ...(handler === false ? { disabled: true } : {}), ...extra });
|
|
95
|
+
};
|
|
96
|
+
add("edit", `Change ${name}`, "edit", actions.edit);
|
|
97
|
+
if (actions.view)
|
|
98
|
+
add("view", actions.view.now === "chart" ? `Show ${name} as a table` : `Show ${name} as a chart`, actions.view.now === "chart" ? "table" : "chart", actions.view.toggle);
|
|
99
|
+
add("wider", `Make ${name} wider`, "wider", actions.wider);
|
|
100
|
+
add("narrower", `Make ${name} narrower`, "narrower", actions.narrower);
|
|
101
|
+
add("earlier", `Move ${name} earlier`, "earlier", actions.earlier);
|
|
102
|
+
add("later", `Move ${name} later`, "later", actions.later);
|
|
103
|
+
add("up", `Move ${name} up`, "up", actions.up);
|
|
104
|
+
add("down", `Move ${name} down`, "down", actions.down);
|
|
105
|
+
add("duplicate", `Duplicate ${name}`, "duplicate", actions.duplicate);
|
|
106
|
+
add("remove", `Remove ${name}`, "remove", actions.remove, { danger: true });
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=ItemControls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemControls.js","sourceRoot":"","sources":["../../src/controls/ItemControls.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsC,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7E,MAAM,KAAK,GAAG;IACZ,IAAI,EAAE,mCAAmC;IACzC,KAAK,EAAE,wCAAwC;IAC/C,KAAK,EAAE,yCAAyC;IAChD,KAAK,EAAE,sCAAsC;IAC7C,QAAQ,EAAE,+CAA+C;IACzD,OAAO,EAAE,yBAAyB;IAClC,KAAK,EAAE,wBAAwB;IAC/B,EAAE,EAAE,wBAAwB;IAC5B,IAAI,EAAE,wBAAwB;IAC9B,SAAS,EAAE,0BAA0B;IACrC,MAAM,EAAE,wDAAwD;IAChE,GAAG,EAAE,mBAAmB;IACxB,KAAK,EAAE,uBAAuB;IAC9B,IAAI,EAAE,2BAA2B;IACjC,IAAI,EAAE,iCAAiC;IACvC,MAAM,EAAE,iCAAiC;IACzC,OAAO,EAAE,gBAAgB;IACzB,KAAK,EAAE,+BAA+B;IACtC,UAAU,EAAE,qCAAqC;IACjD,IAAI,EAAE,mJAAmJ;CACjJ,CAAC;AAIX,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAsB,CAAC;AAErE,MAAM,UAAU,WAAW,CAAC,EAAE,IAAI,EAAyC;IACzE,IAAI,OAAO,IAAI,K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E,GAAG,CAAC,SAAS,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACnE,GAAG,CAAC,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3D,GAAG,CAAC,IAAI,EAAE,QAAQ,IAAI,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/C,GAAG,CAAC,MAAM,EAAE,QAAQ,IAAI,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,GAAG,CAAC,WAAW,EAAE,aAAa,IAAI,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACtE,GAAG,CAAC,QAAQ,EAAE,UAAU,IAAI,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5E,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { type KeyboardEvent, type ReactNode, useRef, useState } from \"react\";\n\nconst PATHS = {\n edit: \"M4 20h4L19 9l-4-4L4 16z M14 6l4 4\",\n chart: \"M4 4v16h16 M8 16v-5 M12 16V8 M16 16v-9\",\n table: \"M3 5h18v14H3z M3 10h18 M3 15h18 M9 5v14\",\n wider: \"M3 12h18 M7 8l-4 4 4 4 M17 8l4 4-4 4\",\n narrower: \"M3 12h6 M21 12h-6 M5 8l4 4-4 4 M19 8l-4 4 4 4\",\n earlier: \"M19 12H5 M11 6l-6 6 6 6\",\n later: \"M5 12h14 M13 6l6 6-6 6\",\n up: \"M12 19V5 M6 11l6-6 6 6\",\n down: \"M12 5v14 M6 13l6 6 6-6\",\n duplicate: \"M8 8h11v11H8z M5 16V5h11\",\n remove: \"M5 7h14 M10 7V4h4v3 M7 7l1 13h8l1-13 M10 11v6 M14 11v6\",\n add: \"M12 5v14 M5 12h14\",\n close: \"M6 6l12 12 M18 6L6 18\",\n menu: \"M4 7h16 M4 12h16 M4 17h16\",\n fold: \"M4 4v16 M20 12H9 M14 7l-5 5 5 5\",\n unfold: \"M20 4v16 M4 12h11 M10 7l5 5-5 5\",\n confirm: \"M5 12l5 5 9-10\",\n power: \"M12 3v8 M7 6.5a7 7 0 1 0 10 0\",\n \"sign-out\": \"M10 4H5v16h5 M15 8l4 4-4 4 M19 12H9\",\n more: \"M4.8 12a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0 M10.8 12a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0 M16.8 12a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0\",\n} as const;\n\n/** The drawings the shared controls use. One set, so the same action looks the same wherever it appears. */\nexport type ControlIconName = keyof typeof PATHS;\nexport const CONTROL_ICONS = Object.keys(PATHS) as ControlIconName[];\n\nexport function ControlIcon({ icon }: { icon: ControlIconName | ReactNode }) {\n if (typeof icon === \"string\" && icon in PATHS) {\n return (\n <svg className=\"sf-item-control-icon\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" focusable=\"false\">\n <path d={PATHS[icon as ControlIconName]} />\n </svg>\n );\n }\n return <span className=\"sf-item-control-icon\">{icon}</span>;\n}\n\n/** One control on an item: an icon, and its name for assistive technology and the tooltip. */\nexport interface ItemControl {\n /** What it does, as a word: \"edit\", \"remove\". Put on the button as `data-control`. */\n id: string;\n /** The button's full name, said by a screen reader and shown at once on hover and focus: \"Remove Refund rate by category\". */\n label: string;\n icon: ControlIconName | ReactNode;\n onSelect(): void;\n /** Shown but cannot be used: the first item cannot move earlier. It can still be focused, so its name can be read. */\n disabled?: boolean;\n /** For a control that removes or destroys. Marked by more than colour: it comes last, after a gap. */\n danger?: boolean;\n /** For a control that switches something on and off. */\n pressed?: boolean;\n /**\n * Stays visible when the rest are quiet: for the one action a person\n * must be able to find without pointing at the item first (a report's\n * \"Add to report\"). Use it sparingly, and not on a control that cannot\n * be used right now.\n */\n pinned?: boolean;\n}\n\nexport interface ItemControlsProps {\n /** Names the group: \"Refund rate by category controls\". */\n label: string;\n controls: ItemControl[];\n /**\n * \"hover\" (the default) shows the controls when the pointer is over the\n * item they belong to, or focus is inside it; give that item the class\n * `sf-controls-host`. On a touch screen, which has no hover, they are\n * always shown. \"always\" keeps them shown.\n */\n show?: \"hover\" | \"always\";\n /**\n * Whether an outer layer of controls can hide these (see `CONTROLS_QUIET`).\n * True by default; the outer layer's own controls pass false.\n */\n quietable?: boolean;\n className?: string;\n}\n\n/**\n * Put this class on a region to hide the item controls inside it, so that\n * two layers of controls are never on screen at once: an editor that frames\n * each component with its own controls (move, remove, resize) quiets the\n * controls of what it frames while it is arranging.\n */\nexport const CONTROLS_QUIET = \"sf-controls-quiet\";\n/** Put this class on the item a set of hover controls belongs to. */\nexport const CONTROLS_HOST = \"sf-controls-host\";\n\n/**\n * The controls of one item (a tile, a card, a framed component) as a row of\n * icons: quiet until the item is pointed at or focused, each named at once\n * in a tooltip, and one stop in the tab order with the arrow keys moving\n * between them. Every part of the library that lets a person change, move,\n * resize or remove an item uses this, with `standardControls` for the\n * actions they share, so the same action has the same icon, name and place\n * everywhere.\n */\nexport function ItemControls({ label, controls, show = \"hover\", quietable = true, className }: ItemControlsProps) {\n const bar = useRef<HTMLDivElement>(null);\n const [current, setCurrent] = useState(0);\n const [tip, setTip] = useState<number | undefined>();\n const at = Math.min(current, Math.max(0, controls.length - 1));\n\n const focus = (index: number) => {\n const next = (index + controls.length) % controls.length;\n setCurrent(next);\n bar.current?.querySelectorAll<HTMLButtonElement>(\"button\")[next]?.focus();\n };\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key === \"ArrowRight\" || event.key === \"ArrowDown\") focus(at + 1);\n else if (event.key === \"ArrowLeft\" || event.key === \"ArrowUp\") focus(at - 1);\n else if (event.key === \"Home\") focus(0);\n else if (event.key === \"End\") focus(controls.length - 1);\n else if (event.key === \"Escape\" && tip !== undefined) setTip(undefined);\n else return;\n event.preventDefault();\n event.stopPropagation();\n };\n\n if (controls.length === 0) return null;\n return (\n <div ref={bar} className={[\"sf-item-controls\", className].filter(Boolean).join(\" \")} role=\"toolbar\" aria-label={label} data-show={show} data-quietable={quietable || undefined} onKeyDown={onKeyDown}>\n {controls.map((control, index) => (\n <button\n key={control.id}\n type=\"button\"\n className=\"sf-item-control\"\n data-control={control.id}\n data-danger={control.danger || undefined}\n data-pinned={(control.pinned && !control.disabled) || undefined}\n aria-label={control.label}\n aria-pressed={control.pressed}\n // Not `disabled`, which would take it out of reach of the keyboard and leave its name unread.\n aria-disabled={control.disabled || undefined}\n tabIndex={index === at ? 0 : -1}\n onClick={() => !control.disabled && control.onSelect()}\n onFocus={() => {\n setCurrent(index);\n setTip(index);\n }}\n onBlur={() => setTip((now) => (now === index ? undefined : now))}\n onPointerEnter={() => setTip(index)}\n onPointerLeave={() => setTip((now) => (now === index ? undefined : now))}\n >\n <ControlIcon icon={control.icon} />\n {/* The button carries its name for assistive technology; this is the same words for the eye, shown at once. */}\n {tip === index && (\n <span className=\"sf-item-tip\" aria-hidden=\"true\">\n {control.label}\n {control.disabled ? \" (not available here)\" : \"\"}\n </span>\n )}\n </button>\n ))}\n </div>\n );\n}\n\n/** What an item can have done to it. A handler left out leaves the control out; `false` shows it greyed, for an action that makes no sense right now. */\nexport interface StandardActions {\n edit?: (() => void) | false;\n /** Switch between a chart and a table. `now` is what is showing. */\n view?: { now: \"chart\" | \"table\"; toggle(): void };\n wider?: (() => void) | false;\n narrower?: (() => void) | false;\n /** Earlier and later in reading order, for items laid out across. */\n earlier?: (() => void) | false;\n later?: (() => void) | false;\n /** Up and down, for items stacked. */\n up?: (() => void) | false;\n down?: (() => void) | false;\n duplicate?: (() => void) | false;\n remove?: (() => void) | false;\n}\n\n/**\n * The controls an item shares with every other kind of item, in one order\n * and with one wording: change, chart or table, wider, narrower, move,\n * duplicate, remove. `name` is what the item is called (\"Refund rate by\n * category\", \"Chart revenue\"), and goes into each control's name.\n */\nexport function standardControls(name: string, actions: StandardActions): ItemControl[] {\n const out: ItemControl[] = [];\n const add = (id: string, label: string, icon: ControlIconName, handler: (() => void) | false | undefined, extra: Partial<ItemControl> = {}) => {\n if (handler === undefined) return;\n out.push({ id, label, icon, onSelect: handler || (() => undefined), ...(handler === false ? { disabled: true } : {}), ...extra });\n };\n add(\"edit\", `Change ${name}`, \"edit\", actions.edit);\n if (actions.view) add(\"view\", actions.view.now === \"chart\" ? `Show ${name} as a table` : `Show ${name} as a chart`, actions.view.now === \"chart\" ? \"table\" : \"chart\", actions.view.toggle);\n add(\"wider\", `Make ${name} wider`, \"wider\", actions.wider);\n add(\"narrower\", `Make ${name} narrower`, \"narrower\", actions.narrower);\n add(\"earlier\", `Move ${name} earlier`, \"earlier\", actions.earlier);\n add(\"later\", `Move ${name} later`, \"later\", actions.later);\n add(\"up\", `Move ${name} up`, \"up\", actions.up);\n add(\"down\", `Move ${name} down`, \"down\", actions.down);\n add(\"duplicate\", `Duplicate ${name}`, \"duplicate\", actions.duplicate);\n add(\"remove\", `Remove ${name}`, \"remove\", actions.remove, { danger: true });\n return out;\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface PopoverProps {
|
|
3
|
+
/** What the button says, and the panel's name for assistive technology: "View". */
|
|
4
|
+
label: string;
|
|
5
|
+
/** A few words after the label on the button saying what is set now: "Fit · 100% · Real data". Part of the button's name. */
|
|
6
|
+
summary?: ReactNode;
|
|
7
|
+
/** The panel's contents: selects, a `SegmentedControl`, check boxes. Anything a person can Tab through. */
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
/** Line the panel up with the button's start edge (the default) or its end edge. It moves along to stay inside the window either way. */
|
|
10
|
+
align?: "start" | "end";
|
|
11
|
+
/** Open, when the host holds it. Leave out to let the popover hold it. */
|
|
12
|
+
open?: boolean;
|
|
13
|
+
/** Open at first, when the popover holds it. */
|
|
14
|
+
defaultOpen?: boolean;
|
|
15
|
+
/** Every change asked for: the button, Escape, a press or focus outside. */
|
|
16
|
+
onOpenChange?(open: boolean): void;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
/** On the outer box, which holds the button and the panel. */
|
|
19
|
+
className?: string;
|
|
20
|
+
/** On the panel. */
|
|
21
|
+
panelClassName?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A button that shows a small panel of controls beneath it: a view's settings, a few filters. It is a non-modal
|
|
25
|
+
* dialog opened by a disclosure button: the button says whether it is open (`aria-expanded`) and which panel it
|
|
26
|
+
* opens (`aria-controls`); opening moves focus to the panel's first control; Tab moves through the panel and on
|
|
27
|
+
* to the page after the button, which closes it; Escape closes it and puts focus back on the button; a press or
|
|
28
|
+
* focus anywhere else closes it. For a list of actions use `useContextMenu`; for a decision that must be answered
|
|
29
|
+
* first, `ConfirmDialog`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function Popover(props: PopoverProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { placePanel } from "./placement.js";
|
|
4
|
+
const FOCUSABLE = 'a[href], button:not(:disabled), input:not(:disabled):not([type="hidden"]), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])';
|
|
5
|
+
/** Whether the panel is in the top layer now; false where the browser has no popovers. */
|
|
6
|
+
function shown(element) {
|
|
7
|
+
try {
|
|
8
|
+
return element.matches(":popover-open");
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A button that shows a small panel of controls beneath it: a view's settings, a few filters. It is a non-modal
|
|
16
|
+
* dialog opened by a disclosure button: the button says whether it is open (`aria-expanded`) and which panel it
|
|
17
|
+
* opens (`aria-controls`); opening moves focus to the panel's first control; Tab moves through the panel and on
|
|
18
|
+
* to the page after the button, which closes it; Escape closes it and puts focus back on the button; a press or
|
|
19
|
+
* focus anywhere else closes it. For a list of actions use `useContextMenu`; for a decision that must be answered
|
|
20
|
+
* first, `ConfirmDialog`.
|
|
21
|
+
*/
|
|
22
|
+
export function Popover(props) {
|
|
23
|
+
const { label, summary, children, align = "start", open: held, defaultOpen = false, onOpenChange, disabled, className, panelClassName } = props;
|
|
24
|
+
const id = useId();
|
|
25
|
+
const panelId = `${id}-panel`;
|
|
26
|
+
const [own, setOwn] = useState(defaultOpen);
|
|
27
|
+
const open = held ?? own;
|
|
28
|
+
const box = useRef(null);
|
|
29
|
+
const button = useRef(null);
|
|
30
|
+
const panel = useRef(null);
|
|
31
|
+
// Opening moves focus into the panel; being open when first drawn does not take focus from the page.
|
|
32
|
+
const wasOpen = useRef(open);
|
|
33
|
+
const change = useCallback((next) => {
|
|
34
|
+
if (held === undefined)
|
|
35
|
+
setOwn(next);
|
|
36
|
+
onOpenChange?.(next);
|
|
37
|
+
}, [held, onOpenChange]);
|
|
38
|
+
const place = useCallback(() => {
|
|
39
|
+
const element = panel.current;
|
|
40
|
+
const trigger = button.current;
|
|
41
|
+
if (!element || !trigger)
|
|
42
|
+
return;
|
|
43
|
+
const style = getComputedStyle(element);
|
|
44
|
+
// The panel's margin is the gap to the button and the least room kept from the window's edge.
|
|
45
|
+
const gap = Number.parseFloat(style.marginTop) || 0;
|
|
46
|
+
const at = placePanel({
|
|
47
|
+
trigger: trigger.getBoundingClientRect(),
|
|
48
|
+
// Its whole height, as if no room had been taken away yet: what it scrolls, plus its edges.
|
|
49
|
+
panel: { width: element.offsetWidth, height: element.scrollHeight + element.offsetHeight - element.clientHeight },
|
|
50
|
+
viewport: { width: document.documentElement.clientWidth || window.innerWidth, height: document.documentElement.clientHeight || window.innerHeight },
|
|
51
|
+
gap,
|
|
52
|
+
align,
|
|
53
|
+
rtl: getComputedStyle(trigger).direction === "rtl",
|
|
54
|
+
});
|
|
55
|
+
// A fixed box is placed by its margin edge, so the margin is taken off again.
|
|
56
|
+
element.style.left = `${at.left - gap}px`;
|
|
57
|
+
element.style.top = `${at.top - gap}px`;
|
|
58
|
+
element.style.maxHeight = `${at.maxHeight}px`;
|
|
59
|
+
element.dataset.side = at.side;
|
|
60
|
+
}, [align]);
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
const element = panel.current;
|
|
63
|
+
if (!element)
|
|
64
|
+
return;
|
|
65
|
+
if (open) {
|
|
66
|
+
if (typeof element.showPopover === "function" && !shown(element)) {
|
|
67
|
+
element.setAttribute("popover", "manual");
|
|
68
|
+
element.showPopover();
|
|
69
|
+
}
|
|
70
|
+
place();
|
|
71
|
+
if (!wasOpen.current)
|
|
72
|
+
(element.querySelector(FOCUSABLE) ?? element).focus();
|
|
73
|
+
}
|
|
74
|
+
else if (typeof element.hidePopover === "function" && shown(element)) {
|
|
75
|
+
element.hidePopover();
|
|
76
|
+
}
|
|
77
|
+
wasOpen.current = open;
|
|
78
|
+
});
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!open)
|
|
81
|
+
return;
|
|
82
|
+
const inside = (target) => target instanceof Node && !!box.current?.contains(target);
|
|
83
|
+
const away = (event) => {
|
|
84
|
+
if (!inside(event.target))
|
|
85
|
+
change(false);
|
|
86
|
+
};
|
|
87
|
+
// Scrolling the page moves the button, so the panel follows; scrolling the panel itself moves nothing.
|
|
88
|
+
const scrolled = (event) => {
|
|
89
|
+
if (!(event.target instanceof Node && panel.current?.contains(event.target)))
|
|
90
|
+
place();
|
|
91
|
+
};
|
|
92
|
+
document.addEventListener("pointerdown", away, true);
|
|
93
|
+
document.addEventListener("focusin", away, true);
|
|
94
|
+
window.addEventListener("resize", place);
|
|
95
|
+
window.addEventListener("scroll", scrolled, true);
|
|
96
|
+
return () => {
|
|
97
|
+
document.removeEventListener("pointerdown", away, true);
|
|
98
|
+
document.removeEventListener("focusin", away, true);
|
|
99
|
+
window.removeEventListener("resize", place);
|
|
100
|
+
window.removeEventListener("scroll", scrolled, true);
|
|
101
|
+
};
|
|
102
|
+
}, [open, change, place]);
|
|
103
|
+
const onKeyDown = (event) => {
|
|
104
|
+
// A control inside that used Escape itself (a combobox closing its list) keeps it.
|
|
105
|
+
if (event.key !== "Escape" || !open || event.defaultPrevented)
|
|
106
|
+
return;
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
event.stopPropagation();
|
|
109
|
+
change(false);
|
|
110
|
+
button.current?.focus();
|
|
111
|
+
};
|
|
112
|
+
return (_jsxs("div", { ref: box, className: ["sf-popover", className].filter(Boolean).join(" "), onKeyDown: onKeyDown, children: [_jsxs("button", { ref: button, type: "button", className: "sf-button sf-popover-button", "aria-expanded": open, "aria-controls": panelId, "aria-haspopup": "dialog", disabled: disabled, onClick: () => change(!open), children: [_jsx("span", { className: "sf-popover-label", children: label }), summary !== undefined && summary !== null && summary !== "" && _jsx("span", { className: "sf-popover-summary", children: summary }), _jsx("span", { className: "sf-popover-caret", "aria-hidden": "true" })] }), _jsx("div", { ref: panel, id: panelId, role: "dialog", "aria-label": label, tabIndex: -1, className: ["sf-popover-panel", panelClassName].filter(Boolean).join(" "), hidden: !open, children: children })] }));
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=Popover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Popover.js","sourceRoot":"","sources":["../../src/controls/Popover.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsC,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7H,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAwB5C,MAAM,SAAS,GAAG,4JAA4J,CAAC;AAK/K,0FAA0F;AAC1F,SAA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E,GAAG,EAAE,MAAM,EACX,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,6BAA6B,mBACxB,IAAI,mBACJ,OAAO,mBACR,QAAQ,EACtB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,aAE5B,eAAM,SAAS,EAAC,kBAAkB,YAAE,KAAK,GAAQ,EAChD,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,EAAE,IAAI,eAAM,SAAS,EAAC,oBAAoB,YAAE,OAAO,GAAQ,EACrH,eAAM,SAAS,EAAC,kBAAkB,iBAAa,MAAM,GAAG,IACjD,EACT,cAAK,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAC,QAAQ,gBAAa,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,YAClK,QAAQ,GACL,IACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { type KeyboardEvent, type ReactNode, useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport { placePanel } from \"./placement.js\";\n\nexport interface PopoverProps {\n /** What the button says, and the panel's name for assistive technology: \"View\". */\n label: string;\n /** A few words after the label on the button saying what is set now: \"Fit · 100% · Real data\". Part of the button's name. */\n summary?: ReactNode;\n /** The panel's contents: selects, a `SegmentedControl`, check boxes. Anything a person can Tab through. */\n children: ReactNode;\n /** Line the panel up with the button's start edge (the default) or its end edge. It moves along to stay inside the window either way. */\n align?: \"start\" | \"end\";\n /** Open, when the host holds it. Leave out to let the popover hold it. */\n open?: boolean;\n /** Open at first, when the popover holds it. */\n defaultOpen?: boolean;\n /** Every change asked for: the button, Escape, a press or focus outside. */\n onOpenChange?(open: boolean): void;\n disabled?: boolean;\n /** On the outer box, which holds the button and the panel. */\n className?: string;\n /** On the panel. */\n panelClassName?: string;\n}\n\nconst FOCUSABLE = 'a[href], button:not(:disabled), input:not(:disabled):not([type=\"hidden\"]), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])';\n\n/** The top layer, where the browser has it, so no clipping, transform or filter on an ancestor can move or cut the panel. */\ntype PopoverElement = HTMLElement & { showPopover?(): void; hidePopover?(): void };\n\n/** Whether the panel is in the top layer now; false where the browser has no popovers. */\nfunction shown(element: PopoverElement): boolean {\n try {\n return element.matches(\":popover-open\");\n } catch {\n return false;\n }\n}\n\n/**\n * A button that shows a small panel of controls beneath it: a view's settings, a few filters. It is a non-modal\n * dialog opened by a disclosure button: the button says whether it is open (`aria-expanded`) and which panel it\n * opens (`aria-controls`); opening moves focus to the panel's first control; Tab moves through the panel and on\n * to the page after the button, which closes it; Escape closes it and puts focus back on the button; a press or\n * focus anywhere else closes it. For a list of actions use `useContextMenu`; for a decision that must be answered\n * first, `ConfirmDialog`.\n */\nexport function Popover(props: PopoverProps) {\n const { label, summary, children, align = \"start\", open: held, defaultOpen = false, onOpenChange, disabled, className, panelClassName } = props;\n const id = useId();\n const panelId = `${id}-panel`;\n const [own, setOwn] = useState(defaultOpen);\n const open = held ?? own;\n const box = useRef<HTMLDivElement>(null);\n const button = useRef<HTMLButtonElement>(null);\n const panel = useRef<HTMLDivElement>(null);\n // Opening moves focus into the panel; being open when first drawn does not take focus from the page.\n const wasOpen = useRef(open);\n\n const change = useCallback(\n (next: boolean) => {\n if (held === undefined) setOwn(next);\n onOpenChange?.(next);\n },\n [held, onOpenChange],\n );\n\n const place = useCallback(() => {\n const element = panel.current;\n const trigger = button.current;\n if (!element || !trigger) return;\n const style = getComputedStyle(element);\n // The panel's margin is the gap to the button and the least room kept from the window's edge.\n const gap = Number.parseFloat(style.marginTop) || 0;\n const at = placePanel({\n trigger: trigger.getBoundingClientRect(),\n // Its whole height, as if no room had been taken away yet: what it scrolls, plus its edges.\n panel: { width: element.offsetWidth, height: element.scrollHeight + element.offsetHeight - element.clientHeight },\n viewport: { width: document.documentElement.clientWidth || window.innerWidth, height: document.documentElement.clientHeight || window.innerHeight },\n gap,\n align,\n rtl: getComputedStyle(trigger).direction === \"rtl\",\n });\n // A fixed box is placed by its margin edge, so the margin is taken off again.\n element.style.left = `${at.left - gap}px`;\n element.style.top = `${at.top - gap}px`;\n element.style.maxHeight = `${at.maxHeight}px`;\n element.dataset.side = at.side;\n }, [align]);\n\n useLayoutEffect(() => {\n const element = panel.current as PopoverElement | null;\n if (!element) return;\n if (open) {\n if (typeof element.showPopover === \"function\" && !shown(element)) {\n element.setAttribute(\"popover\", \"manual\");\n element.showPopover();\n }\n place();\n if (!wasOpen.current) (element.querySelector<HTMLElement>(FOCUSABLE) ?? element).focus();\n } else if (typeof element.hidePopover === \"function\" && shown(element)) {\n element.hidePopover();\n }\n wasOpen.current = open;\n });\n\n useEffect(() => {\n if (!open) return;\n const inside = (target: EventTarget | null) => target instanceof Node && !!box.current?.contains(target);\n const away = (event: Event) => {\n if (!inside(event.target)) change(false);\n };\n // Scrolling the page moves the button, so the panel follows; scrolling the panel itself moves nothing.\n const scrolled = (event: Event) => {\n if (!(event.target instanceof Node && panel.current?.contains(event.target))) place();\n };\n document.addEventListener(\"pointerdown\", away, true);\n document.addEventListener(\"focusin\", away, true);\n window.addEventListener(\"resize\", place);\n window.addEventListener(\"scroll\", scrolled, true);\n return () => {\n document.removeEventListener(\"pointerdown\", away, true);\n document.removeEventListener(\"focusin\", away, true);\n window.removeEventListener(\"resize\", place);\n window.removeEventListener(\"scroll\", scrolled, true);\n };\n }, [open, change, place]);\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n // A control inside that used Escape itself (a combobox closing its list) keeps it.\n if (event.key !== \"Escape\" || !open || event.defaultPrevented) return;\n event.preventDefault();\n event.stopPropagation();\n change(false);\n button.current?.focus();\n };\n\n return (\n <div ref={box} className={[\"sf-popover\", className].filter(Boolean).join(\" \")} onKeyDown={onKeyDown}>\n <button\n ref={button}\n type=\"button\"\n className=\"sf-button sf-popover-button\"\n aria-expanded={open}\n aria-controls={panelId}\n aria-haspopup=\"dialog\"\n disabled={disabled}\n onClick={() => change(!open)}\n >\n <span className=\"sf-popover-label\">{label}</span>\n {summary !== undefined && summary !== null && summary !== \"\" && <span className=\"sf-popover-summary\">{summary}</span>}\n <span className=\"sf-popover-caret\" aria-hidden=\"true\" />\n </button>\n <div ref={panel} id={panelId} role=\"dialog\" aria-label={label} tabIndex={-1} className={[\"sf-popover-panel\", panelClassName].filter(Boolean).join(\" \")} hidden={!open}>\n {children}\n </div>\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ResizeEdge } from "./resize.js";
|
|
2
|
+
export interface ResizeHandleProps {
|
|
3
|
+
/** Which edge of its parent it sits on: "right" sizes a width (dragged left and right), "left" a width that grows leftwards (a panel docked on the right), "bottom" a height (dragged up and down). The parent must be positioned. */
|
|
4
|
+
edge: ResizeEdge;
|
|
5
|
+
/** The size it stands for, in any unit (pixels, a share, a percentage). Undefined when no size is set yet: a drag then starts from `startFrom`. */
|
|
6
|
+
value: number | undefined;
|
|
7
|
+
min?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
/** Values land on multiples of this while dragging and by key (10 rounds to ten pixels). */
|
|
10
|
+
snap?: number;
|
|
11
|
+
/** How far an arrow key moves it; Shift moves five steps. Defaults to a twentieth of the range, or 10. */
|
|
12
|
+
step?: number;
|
|
13
|
+
/** How many pixels on screen one unit of value is: 1 for pixels, a container's width for a share of it. Read when a drag starts. Defaults to 1. */
|
|
14
|
+
unitPixels?: number | ((handle: HTMLElement) => number);
|
|
15
|
+
/** Where a drag or key starts when `value` is undefined, such as the height drawn now. */
|
|
16
|
+
startFrom?(handle: HTMLElement): number;
|
|
17
|
+
/** Each new value while it is dragged, and after each key. Draw the new size here. */
|
|
18
|
+
onChange?(value: number): void;
|
|
19
|
+
/** When a drag is released or cancelled (Escape, a lost pointer, or the handle going away mid-drag), and after each key: where to keep the size. `committed` is false for a cancelled drag, whose value is where it started. */
|
|
20
|
+
onChangeEnd?(value: number, end: {
|
|
21
|
+
committed: boolean;
|
|
22
|
+
via: "pointer" | "keyboard";
|
|
23
|
+
}): void;
|
|
24
|
+
/** Enter or a double click: back to the size it had before anyone changed it. Without it, Enter does nothing. */
|
|
25
|
+
onReset?(): void;
|
|
26
|
+
/** What it resizes, for assistive technology: "Resize the map and the list". */
|
|
27
|
+
label: string;
|
|
28
|
+
/** The value in words, when a number alone does not say it ("40% and 60%"). */
|
|
29
|
+
valueText?: string;
|
|
30
|
+
/** Shown all the time, rather than when its parent is pointed at or it has focus. */
|
|
31
|
+
always?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether Tab stops on it (default true). False leaves it to the pointer and to focus given in code: an editor with
|
|
34
|
+
* a handle on every element keeps Tab to one stop each, and offers the handles of the one selected.
|
|
35
|
+
*/
|
|
36
|
+
tabbable?: boolean;
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A handle on the right, left or bottom edge of something, dragged to change its
|
|
41
|
+
* width or height: the one Arrange draws under a component and between a
|
|
42
|
+
* Grid's columns, for any app to place. A focusable `separator` with its
|
|
43
|
+
* value, least and most; dragged with pointer events so a mouse, a pen and a
|
|
44
|
+
* finger all work; moved by the arrow keys (Shift for bigger steps), Home and
|
|
45
|
+
* End; and put back by Enter or a double click. It holds no size of its own:
|
|
46
|
+
* the host keeps `value` and draws the change.
|
|
47
|
+
*/
|
|
48
|
+
export declare function ResizeHandle(props: ResizeHandleProps): import("react").JSX.Element;
|