@sharadox/graphical-user-interface-web-library 0.2.0-layout.15 → 0.2.0-navigation.27

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.
Files changed (124) hide show
  1. package/README.md +12 -0
  2. package/distribution/code-boxes/index.d.ts +11 -0
  3. package/distribution/code-boxes/index.d.ts.map +1 -0
  4. package/distribution/code-boxes/index.js +64 -0
  5. package/distribution/code-boxes/index.js.map +1 -0
  6. package/distribution/code-boxes/index.module.css +1 -0
  7. package/distribution/code-boxes/index.module.scss +28 -0
  8. package/distribution/code-boxes/type.d.ts +17 -0
  9. package/distribution/code-boxes/type.d.ts.map +1 -0
  10. package/distribution/code-boxes/type.js +2 -0
  11. package/distribution/code-boxes/type.js.map +1 -0
  12. package/distribution/combobox/index.d.ts +18 -0
  13. package/distribution/combobox/index.d.ts.map +1 -0
  14. package/distribution/combobox/index.js +105 -0
  15. package/distribution/combobox/index.js.map +1 -0
  16. package/distribution/combobox/index.module.css +1 -0
  17. package/distribution/combobox/index.module.scss +25 -0
  18. package/distribution/combobox/type.d.ts +8 -0
  19. package/distribution/combobox/type.d.ts.map +1 -0
  20. package/distribution/combobox/type.js +2 -0
  21. package/distribution/combobox/type.js.map +1 -0
  22. package/distribution/copy-button/index.d.ts +10 -0
  23. package/distribution/copy-button/index.d.ts.map +1 -0
  24. package/distribution/copy-button/index.js +26 -0
  25. package/distribution/copy-button/index.js.map +1 -0
  26. package/distribution/copy-button/type.d.ts +11 -0
  27. package/distribution/copy-button/type.d.ts.map +1 -0
  28. package/distribution/copy-button/type.js +2 -0
  29. package/distribution/copy-button/type.js.map +1 -0
  30. package/distribution/dialog/index.d.ts +12 -0
  31. package/distribution/dialog/index.d.ts.map +1 -0
  32. package/distribution/dialog/index.js +56 -0
  33. package/distribution/dialog/index.js.map +1 -0
  34. package/distribution/dialog/index.module.css +1 -0
  35. package/distribution/dialog/index.module.scss +59 -0
  36. package/distribution/dialog/type.d.ts +11 -0
  37. package/distribution/dialog/type.d.ts.map +1 -0
  38. package/distribution/dialog/type.js +2 -0
  39. package/distribution/dialog/type.js.map +1 -0
  40. package/distribution/field/index.d.ts +1 -1
  41. package/distribution/field/index.d.ts.map +1 -1
  42. package/distribution/field/index.js +2 -2
  43. package/distribution/field/index.js.map +1 -1
  44. package/distribution/listbox/index.d.ts +11 -0
  45. package/distribution/listbox/index.d.ts.map +1 -0
  46. package/distribution/listbox/index.js +21 -0
  47. package/distribution/listbox/index.js.map +1 -0
  48. package/distribution/listbox/index.module.css +1 -0
  49. package/distribution/listbox/index.module.scss +38 -0
  50. package/distribution/listbox/type.d.ts +22 -0
  51. package/distribution/listbox/type.d.ts.map +1 -0
  52. package/distribution/listbox/type.js +2 -0
  53. package/distribution/listbox/type.js.map +1 -0
  54. package/distribution/navigation/index.d.ts +13 -0
  55. package/distribution/navigation/index.d.ts.map +1 -0
  56. package/distribution/navigation/index.js +27 -0
  57. package/distribution/navigation/index.js.map +1 -0
  58. package/distribution/navigation/index.module.css +1 -0
  59. package/distribution/navigation/index.module.scss +64 -0
  60. package/distribution/navigation/type.d.ts +24 -0
  61. package/distribution/navigation/type.d.ts.map +1 -0
  62. package/distribution/navigation/type.js +2 -0
  63. package/distribution/navigation/type.js.map +1 -0
  64. package/distribution/notification/index.d.ts +19 -0
  65. package/distribution/notification/index.d.ts.map +1 -0
  66. package/distribution/notification/index.js +48 -0
  67. package/distribution/notification/index.js.map +1 -0
  68. package/distribution/notification/index.module.css +1 -0
  69. package/distribution/notification/index.module.scss +35 -0
  70. package/distribution/notification/type.d.ts +23 -0
  71. package/distribution/notification/type.d.ts.map +1 -0
  72. package/distribution/notification/type.js +2 -0
  73. package/distribution/notification/type.js.map +1 -0
  74. package/distribution/number-field/index.d.ts +10 -0
  75. package/distribution/number-field/index.d.ts.map +1 -0
  76. package/distribution/number-field/index.js +46 -0
  77. package/distribution/number-field/index.js.map +1 -0
  78. package/distribution/number-field/index.module.css +1 -0
  79. package/distribution/number-field/index.module.scss +29 -0
  80. package/distribution/number-field/type.d.ts +29 -0
  81. package/distribution/number-field/type.d.ts.map +1 -0
  82. package/distribution/number-field/type.js +2 -0
  83. package/distribution/number-field/type.js.map +1 -0
  84. package/distribution/select/index.d.ts +13 -0
  85. package/distribution/select/index.d.ts.map +1 -0
  86. package/distribution/select/index.js +102 -0
  87. package/distribution/select/index.js.map +1 -0
  88. package/distribution/select/index.module.css +1 -0
  89. package/distribution/select/index.module.scss +42 -0
  90. package/distribution/select/type.d.ts +25 -0
  91. package/distribution/select/type.d.ts.map +1 -0
  92. package/distribution/select/type.js +2 -0
  93. package/distribution/select/type.js.map +1 -0
  94. package/distribution/skeleton/index.d.ts +11 -0
  95. package/distribution/skeleton/index.d.ts.map +1 -0
  96. package/distribution/skeleton/index.js +20 -0
  97. package/distribution/skeleton/index.js.map +1 -0
  98. package/distribution/skeleton/index.module.css +1 -0
  99. package/distribution/skeleton/index.module.scss +96 -0
  100. package/distribution/skeleton/type.d.ts +16 -0
  101. package/distribution/skeleton/type.d.ts.map +1 -0
  102. package/distribution/skeleton/type.js +2 -0
  103. package/distribution/skeleton/type.js.map +1 -0
  104. package/distribution/skeleton-value/index.d.ts +10 -0
  105. package/distribution/skeleton-value/index.d.ts.map +1 -0
  106. package/distribution/skeleton-value/index.js +15 -0
  107. package/distribution/skeleton-value/index.js.map +1 -0
  108. package/distribution/skeleton-value/index.module.css +1 -0
  109. package/distribution/skeleton-value/index.module.scss +35 -0
  110. package/distribution/skeleton-value/type.d.ts +9 -0
  111. package/distribution/skeleton-value/type.d.ts.map +1 -0
  112. package/distribution/skeleton-value/type.js +2 -0
  113. package/distribution/skeleton-value/type.js.map +1 -0
  114. package/distribution/tip/index.d.ts +10 -0
  115. package/distribution/tip/index.d.ts.map +1 -0
  116. package/distribution/tip/index.js +22 -0
  117. package/distribution/tip/index.js.map +1 -0
  118. package/distribution/tip/index.module.css +1 -0
  119. package/distribution/tip/index.module.scss +24 -0
  120. package/distribution/tip/type.d.ts +7 -0
  121. package/distribution/tip/type.d.ts.map +1 -0
  122. package/distribution/tip/type.js +2 -0
  123. package/distribution/tip/type.js.map +1 -0
  124. package/package.json +3 -2
package/README.md CHANGED
@@ -101,6 +101,18 @@ everything below it: on the page, in one part of it, or on one piece.
101
101
  | `…/separator` | `Separator({ orientation?, color?, line? })` | A horizontal (or vertical) line in the line style |
102
102
  | `…/badge` | `Badge(box)` | A short label in running text: small, filled, brand |
103
103
  | `…/avatar` | `Avatar({ name, src?, size?, color?, corner? })`, `initials(name)` | A picture, or the initials when there is none; round |
104
+ | `…/listbox` | `Listbox({ id, labelledBy, options, chosen, active, onActive, onChoose, empty? })` | The list a select or combobox opens: a glass panel, the chosen one checked |
105
+ | `…/select` | `Select({ label, options, value?, defaultValue?, onChange?, name?, placeholder? })` | A select drawn by the interface, with a native select's keyboard |
106
+ | `…/combobox` | `Combobox({ label, options, … , empty? })`, `matches(label, typed)` | A text field that filters its options as you type |
107
+ | `…/number-field` | `NumberField({ label, value?, min?, max?, step?, decreaseLabel, increaseLabel })` | A number between a minus and a plus section |
108
+ | `…/dialog` | `Dialog({ open, onClose, title, closeLabel, children })` | A modal in the middle of the screen that leaves the way it came |
109
+ | `…/tip` | `Tip({ text, label })` | A question mark showing a tip on hover, focus or tap |
110
+ | `…/notification` | `NotificationProvider({ label, dismissLabel, duration? })`, `useNotification()` | Notifications at the top right, in their tone's color, hiding themselves |
111
+ | `…/skeleton` | `Skeleton({ label, shape?, lines?, rows?, height? })` | Shimmering shapes like what is loading |
112
+ | `…/skeleton-value` | `SkeletonValue({ label?, width?, circle? })` | A shimmering shape for one value |
113
+ | `…/copy-button` | `CopyButton({ value, label, copiedLabel, onCopied? })` | Copies a value and says so for two seconds |
114
+ | `…/code-boxes` | `CodeBoxes({ label, digitLabel, ofLabel, name?, length?, onComplete? })` | One field box per digit of a one-time code |
115
+ | `…/navigation` | `Navigation({ brand, label, links, actions?, menuLabel, closeLabel, collapse? })` | The sticky bar, and a phone menu below `collapse` (960) |
104
116
 
105
117
  ### Box
106
118
 
@@ -0,0 +1,11 @@
1
+ import type { CodeBoxesProperties } from "@sharadox/graphical-user-interface-web-library/code-boxes/type";
2
+ /**
3
+ * A one-time code typed into one box per digit: each digit moves on to the next box, Backspace or Delete clears the
4
+ * box it is on (on an empty box, Backspace clears the one before), the arrows move back and forth, and pasting the code (or the phone filling it in from a message) fills every box at once. The whole
5
+ * code is in one hidden field for forms. Each box is a large outlined field box (the error color when invalid); `onComplete` fires once every box has its digit.
6
+ *
7
+ * @example
8
+ * <CodeBoxes label="Code" digitLabel="digit" ofLabel="of" onComplete={submit} autoFocus />
9
+ */
10
+ export declare function CodeBoxes({ label, digitLabel, ofLabel, name, length, onComplete, invalid, disabled, describedBy, autoFocus, }: CodeBoxesProperties): import("react").JSX.Element;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/code-boxes/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gEAAgE,CAAC;AAE1G;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,UAAU,EACV,OAAO,EACP,IAAI,EACJ,MAAU,EACV,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,SAAS,GACV,EAAE,mBAAmB,+BAgFrB"}
@@ -0,0 +1,64 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useRef, useState } from "react";
4
+ import { Box } from "@sharadox/graphical-user-interface-web-library/box";
5
+ import styles from "./index.module.css";
6
+ /**
7
+ * A one-time code typed into one box per digit: each digit moves on to the next box, Backspace or Delete clears the
8
+ * box it is on (on an empty box, Backspace clears the one before), the arrows move back and forth, and pasting the code (or the phone filling it in from a message) fills every box at once. The whole
9
+ * code is in one hidden field for forms. Each box is a large outlined field box (the error color when invalid); `onComplete` fires once every box has its digit.
10
+ *
11
+ * @example
12
+ * <CodeBoxes label="Code" digitLabel="digit" ofLabel="of" onComplete={submit} autoFocus />
13
+ */
14
+ export function CodeBoxes({ label, digitLabel, ofLabel, name, length = 6, onComplete, invalid, disabled, describedBy, autoFocus, }) {
15
+ const [digits, setDigits] = useState(() => Array.from({ length }, () => ""));
16
+ const boxes = useRef([]);
17
+ const focus = (index) => boxes.current[Math.max(0, Math.min(length - 1, index))]?.focus();
18
+ /** Puts `typed` digits from box `from` on, then moves to the next empty box. */
19
+ const fill = (from, typed) => {
20
+ const next = [...digits];
21
+ let at = from;
22
+ for (const digit of typed.replace(/\D/g, "").slice(0, length - from))
23
+ next[at++] = digit;
24
+ setDigits(next);
25
+ focus(at);
26
+ const code = next.join("");
27
+ if (code.length === length)
28
+ onComplete?.(code);
29
+ };
30
+ const change = (index, value) => {
31
+ const typed = value.replace(/\D/g, "");
32
+ if (!typed)
33
+ return;
34
+ // One new digit typed over an old one: keep the new one (the last typed).
35
+ fill(index, typed.length === 2 && digits[index] ? typed.slice(-1) : typed);
36
+ };
37
+ /** Empties box `index`. */
38
+ const clear = (index) => setDigits(digits.map((digit, at) => (at === index ? "" : digit)));
39
+ const keyDown = (index, event) => {
40
+ if ((event.key === "Backspace" || event.key === "Delete") && digits[index]) {
41
+ // A filled box: clear it, wherever it is, and stay on it.
42
+ event.preventDefault();
43
+ clear(index);
44
+ }
45
+ else if (event.key === "Backspace") {
46
+ // An empty box: clear the one before and go back to it.
47
+ event.preventDefault();
48
+ clear(Math.max(0, index - 1));
49
+ focus(index - 1);
50
+ }
51
+ else if (event.key === "ArrowLeft")
52
+ focus(index - 1);
53
+ else if (event.key === "ArrowRight")
54
+ focus(index + 1);
55
+ };
56
+ const paste = (index, event) => {
57
+ event.preventDefault();
58
+ fill(index, event.clipboardData.getData("text"));
59
+ };
60
+ return (_jsxs("div", { role: "group", "aria-label": label, className: styles.boxes, children: [name && _jsx("input", { type: "hidden", name: name, value: digits.join("") }), digits.map((digit, index) => (_jsx(Box, { field: true, variant: "outlined", color: invalid ? "error" : "middleground", size: "large", state: disabled ? "disabled" : "enabled", className: styles.cell, children: _jsx("input", { ref: (element) => {
61
+ boxes.current[index] = element;
62
+ }, className: styles.box, value: digit, onChange: (event) => change(index, event.target.value), onKeyDown: (event) => keyDown(index, event), onPaste: (event) => paste(index, event), onFocus: (event) => event.target.select(), inputMode: "numeric", autoComplete: index === 0 ? "one-time-code" : "off", "aria-label": `${label}, ${digitLabel} ${index + 1} ${ofLabel} ${length}`, "aria-invalid": invalid || undefined, "aria-describedby": describedBy, disabled: disabled, autoFocus: autoFocus && index === 0 }) }, index)))] }));
63
+ }
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/code-boxes/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,MAAM,EAAE,QAAQ,EAA2C,MAAM,OAAO,CAAC;AAClF,OAAO,EAAE,GAAG,EAAE,MAAM,oDAAoD,CAAC;AACzE,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAGzC;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,EACxB,KAAK,EACL,UAAU,EACV,OAAO,EACP,IAAI,EACJ,MAAM,GAAG,CAAC,EACV,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,SAAS,GACW;IACpB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAW,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACvF,MAAM,KAAK,GAAG,MAAM,CAA8B,EAAE,CAAC,CAAC;IACtD,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG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,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ :where(.boxes){display:flex;gap:var(--scale-8);inline-size:100%}.cell{flex:1 1 0;min-inline-size:0}:where(.box){box-sizing:border-box;inline-size:100%;min-inline-size:0;min-block-size:var(--section-minimum-size);margin:0;padding:0;border:0;outline:0;background:rgba(0,0,0,0);color:var(--current-hover-color);font:inherit;font-size:var(--scale-24);font-variant-numeric:tabular-nums;text-align:center}
@@ -0,0 +1,28 @@
1
+ // The boxes share the width, each at least as tall as a large field, the digits centered and large.
2
+ :where(.boxes) {
3
+ display: flex;
4
+ gap: var(--scale-8);
5
+ inline-size: 100%;
6
+ }
7
+
8
+ .cell {
9
+ flex: 1 1 0;
10
+ min-inline-size: 0;
11
+ }
12
+
13
+ :where(.box) {
14
+ box-sizing: border-box;
15
+ inline-size: 100%;
16
+ min-inline-size: 0;
17
+ min-block-size: var(--section-minimum-size);
18
+ margin: 0;
19
+ padding: 0;
20
+ border: 0;
21
+ outline: 0;
22
+ background: transparent;
23
+ color: var(--current-hover-color);
24
+ font: inherit;
25
+ font-size: var(--scale-24);
26
+ font-variant-numeric: tabular-nums;
27
+ text-align: center;
28
+ }
@@ -0,0 +1,17 @@
1
+ export interface CodeBoxesProperties {
2
+ /** The group's name ("Code"); each box reads "Code, digit 3 of 6". */
3
+ label: string;
4
+ /** "digit" and "of", in the reader's language. */
5
+ digitLabel: string;
6
+ ofLabel: string;
7
+ /** The hidden field's name, for forms. */
8
+ name?: string;
9
+ length?: number;
10
+ /** Once every box has its digit. */
11
+ onComplete?: (code: string) => void;
12
+ invalid?: boolean;
13
+ disabled?: boolean;
14
+ describedBy?: string;
15
+ autoFocus?: boolean;
16
+ }
17
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/code-boxes/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/code-boxes/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import type { ComboboxProperties } from "@sharadox/graphical-user-interface-web-library/combobox/type";
2
+ /**
3
+ * Whether an option's words contain what was typed, ignoring case and accents.
4
+ *
5
+ * @example
6
+ * matches("Loulé", "loule"); // true
7
+ */
8
+ export declare function matches(label: string, typed: string): boolean;
9
+ /**
10
+ * A combobox: a text field that filters its options as you type (ignoring case and accents) and opens a `Listbox`
11
+ * of the ones that match. The arrows, Home and End move, Enter chooses, Escape closes and puts back the chosen
12
+ * option's words, and a click outside closes. With a `name`, the chosen value goes in a hidden field for forms.
13
+ *
14
+ * @example
15
+ * <Combobox label="City" name="city" options={cities} empty="No city found." />
16
+ */
17
+ export declare function Combobox(properties: ComboboxProperties): import("react").JSX.Element;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/combobox/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8DAA8D,CAAC;AAUvG;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,kBAAkB,+BAqItD"}
@@ -0,0 +1,105 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { Icon } from "@sharadox/icon-web-library/icon";
5
+ import { Box } from "@sharadox/graphical-user-interface-web-library/box";
6
+ import { Field } from "@sharadox/graphical-user-interface-web-library/field";
7
+ import { Listbox } from "@sharadox/graphical-user-interface-web-library/listbox";
8
+ import styles from "./index.module.css";
9
+ /** Lower case without accents, so "Loulé" is found by "loule". */
10
+ const plain = (text) => text
11
+ .normalize("NFD")
12
+ .replace(/\p{Diacritic}/gu, "")
13
+ .toLowerCase();
14
+ /**
15
+ * Whether an option's words contain what was typed, ignoring case and accents.
16
+ *
17
+ * @example
18
+ * matches("Loulé", "loule"); // true
19
+ */
20
+ export function matches(label, typed) {
21
+ return plain(label).includes(plain(typed));
22
+ }
23
+ /**
24
+ * A combobox: a text field that filters its options as you type (ignoring case and accents) and opens a `Listbox`
25
+ * of the ones that match. The arrows, Home and End move, Enter chooses, Escape closes and puts back the chosen
26
+ * option's words, and a click outside closes. With a `name`, the chosen value goes in a hidden field for forms.
27
+ *
28
+ * @example
29
+ * <Combobox label="City" name="city" options={cities} empty="No city found." />
30
+ */
31
+ export function Combobox(properties) {
32
+ const { label, hideLabel, hint, error, options, value, defaultValue, onChange, name, placeholder, empty, disabled, state, id, className, color, ...look } = properties;
33
+ const [own, setOwn] = useState(defaultValue ?? "");
34
+ const chosen = value ?? own;
35
+ const words = (chosenValue) => options.find((option) => option.value === chosenValue)?.label ?? "";
36
+ const [typed, setTyped] = useState(() => words(chosen));
37
+ const [open, setOpen] = useState(false);
38
+ const [active, setActive] = useState(0);
39
+ const root = useRef(null);
40
+ // Until something new is typed, every option shows; then only those that match.
41
+ const shown = typed === words(chosen) ? options : options.filter((option) => matches(option.label, typed));
42
+ const show = () => {
43
+ if (disabled)
44
+ return;
45
+ setActive(0);
46
+ setOpen(true);
47
+ };
48
+ const close = () => {
49
+ setOpen(false);
50
+ setTyped(words(chosen));
51
+ };
52
+ const choose = (index) => {
53
+ const option = shown[index];
54
+ if (value === undefined)
55
+ setOwn(option.value);
56
+ onChange?.(option.value);
57
+ setTyped(option.label);
58
+ setOpen(false);
59
+ };
60
+ useEffect(() => {
61
+ if (!open)
62
+ return;
63
+ const outside = (event) => {
64
+ if (!root.current.contains(event.target))
65
+ close();
66
+ };
67
+ document.addEventListener("pointerdown", outside);
68
+ return () => document.removeEventListener("pointerdown", outside);
69
+ });
70
+ const keyDown = (event) => {
71
+ const { key } = event;
72
+ if (!open) {
73
+ if (key === "ArrowDown" || key === "ArrowUp") {
74
+ event.preventDefault();
75
+ show();
76
+ }
77
+ return;
78
+ }
79
+ const moves = {
80
+ ArrowDown: Math.min(shown.length - 1, active + 1),
81
+ ArrowUp: Math.max(0, active - 1),
82
+ Home: 0,
83
+ End: shown.length - 1,
84
+ };
85
+ if (key in moves) {
86
+ event.preventDefault();
87
+ setActive(moves[key]);
88
+ }
89
+ else if (key === "Enter") {
90
+ event.preventDefault();
91
+ if (shown.length > 0)
92
+ choose(active);
93
+ }
94
+ else if (key === "Escape") {
95
+ event.preventDefault();
96
+ close();
97
+ }
98
+ };
99
+ return (_jsx(Field, { label: label, hideLabel: hideLabel, hint: hint, error: error, id: id, className: className, children: (control) => (_jsxs("div", { ref: root, className: styles.anchor, children: [name && _jsx("input", { type: "hidden", name: name, value: chosen }), _jsx(Box, { field: true, variant: "outlined", color: color ?? (error === undefined ? "middleground" : "error"), state: state ?? (disabled ? "disabled" : "enabled"), suffix: _jsx(Icon, { name: "chevron-down" }), ...look, children: _jsx("input", { ...control, type: "text", role: "combobox", autoComplete: "off", "aria-autocomplete": "list", "aria-expanded": open, "aria-controls": `${control.id}-list`, "aria-activedescendant": open && shown.length > 0 ? `${control.id}-list-${active}` : undefined, placeholder: placeholder, value: typed, disabled: disabled, onFocus: show, onChange: (event) => {
100
+ setTyped(event.target.value);
101
+ setActive(0);
102
+ setOpen(true);
103
+ }, onKeyDown: keyDown, className: styles.input }) }), open && (_jsx(Listbox, { id: `${control.id}-list`, labelledBy: `${control.id}-label`, options: shown, chosen: chosen, active: active, onActive: setActive, onChoose: choose, empty: empty }))] })) }));
104
+ }
105
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/combobox/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAsB,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,oDAAoD,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,sDAAsD,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AAEjF,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAEzC,kEAAkE;AAClE,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAC7B,IAAI;KACD,SAAS,CAAC,KAAK,CAAC;KAChB,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;KAC9B,WAAW,EAAE,CAAC;AAEnB;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,KAAa;IAClD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,UAA8B;IACrD,MAAM,EACJ,KAAK,EACL,SAAS,EACT,IAAI,EACJ,KAAK,EACL,OAAO,EACP,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,IA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CAAC,CAAC,SAAS,CAAC,EACnD,MAAM,EAAE,KAAC,IAAI,IAAC,IAAI,EAAC,cAAc,GAAG,KAChC,IAAI,YAER,mBACM,OAAO,EACX,IAAI,EAAC,MAAM,EACX,IAAI,EAAC,UAAU,EACf,YAAY,EAAC,KAAK,uBACA,MAAM,mBACT,IAAI,mBACJ,GAAG,OAAO,CAAC,EAAE,OAAO,2BACZ,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,EAC5F,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,IAAI,EACb,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;4BAClB,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;4BAC7B,SAAS,CAAC,CAAC,CAAC,CAAC;4BACb,OAAO,CAAC,IAAI,CAAC,CAAC;wBAChB,CAAC,EACD,SAAS,EAAE,OAAO,EAClB,SAAS,EAAE,MAAM,CAAC,KAAK,GACvB,GACE,EACL,IAAI,IAAI,CACP,KAAC,OAAO,IACN,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,OAAO,EACxB,UAAU,EAAE,GAAG,OAAO,CAAC,EAAE,QAAQ,EACjC,OAAO,EAAE,KAAK,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,KAAK,GACZ,CACH,IACG,CACP,GACK,CACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ :where(.anchor){position:relative;display:flex;flex-direction:column}:where(.input){box-sizing:border-box;inline-size:100%;min-inline-size:0;min-block-size:var(--section-minimum-size);margin:0;padding:0;border:0;outline:0;background:rgba(0,0,0,0);color:inherit;font:inherit;text-align:start}:where(.input)::placeholder{color:inherit;opacity:.6}
@@ -0,0 +1,25 @@
1
+ :where(.anchor) {
2
+ position: relative;
3
+ display: flex;
4
+ flex-direction: column;
5
+ }
6
+
7
+ :where(.input) {
8
+ box-sizing: border-box;
9
+ inline-size: 100%;
10
+ min-inline-size: 0;
11
+ min-block-size: var(--section-minimum-size);
12
+ margin: 0;
13
+ padding: 0;
14
+ border: 0;
15
+ outline: 0;
16
+ background: transparent;
17
+ color: inherit;
18
+ font: inherit;
19
+ text-align: start;
20
+
21
+ &::placeholder {
22
+ color: inherit;
23
+ opacity: 0.6;
24
+ }
25
+ }
@@ -0,0 +1,8 @@
1
+ import type { SelectProperties } from "@sharadox/graphical-user-interface-web-library/select/type";
2
+ export interface ComboboxProperties extends Omit<SelectProperties, "placeholder"> {
3
+ /** Shown in the empty input. */
4
+ placeholder?: string;
5
+ /** Shown in the list when nothing matches what was typed. */
6
+ empty?: React.ReactNode;
7
+ }
8
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/combobox/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAC;AAEnG,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,aAAa,CAAC;IAC/E,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/combobox/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { CopyButtonProperties } from "@sharadox/graphical-user-interface-web-library/copy-button/type";
2
+ /**
3
+ * Copies a value to the clipboard (a key, a set of recovery codes) and says so for two seconds, with a tick: an
4
+ * outlined middleground button.
5
+ *
6
+ * @example
7
+ * <CopyButton value={secret} label="Copy" copiedLabel="Copied." />
8
+ */
9
+ export declare function CopyButton({ value, label, copiedLabel, onCopied }: CopyButtonProperties): import("react").JSX.Element;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/copy-button/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iEAAiE,CAAC;AAE5G;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,oBAAoB,+BAsBvF"}
@@ -0,0 +1,26 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useState } from "react";
4
+ import { Button } from "@sharadox/graphical-user-interface-web-library/button";
5
+ /**
6
+ * Copies a value to the clipboard (a key, a set of recovery codes) and says so for two seconds, with a tick: an
7
+ * outlined middleground button.
8
+ *
9
+ * @example
10
+ * <CopyButton value={secret} label="Copy" copiedLabel="Copied." />
11
+ */
12
+ export function CopyButton({ value, label, copiedLabel, onCopied }) {
13
+ const [copied, setCopied] = useState(false);
14
+ useEffect(() => {
15
+ if (!copied)
16
+ return;
17
+ const timer = setTimeout(() => setCopied(false), 2000);
18
+ return () => clearTimeout(timer);
19
+ }, [copied]);
20
+ return (_jsx(Button, { variant: "outlined", color: "middleground", size: "small", icon: copied ? "check" : "copy", onClick: async () => {
21
+ await navigator.clipboard.writeText(value);
22
+ setCopied(true);
23
+ onCopied?.();
24
+ }, children: _jsx("span", { "aria-live": "polite", children: copied ? copiedLabel : label }) }));
25
+ }
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/copy-button/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,uDAAuD,CAAC;AAG/E;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAwB;IACtF,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;QACvD,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IACb,OAAO,CACL,KAAC,MAAM,IACL,OAAO,EAAC,UAAU,EAClB,KAAK,EAAC,cAAc,EACpB,IAAI,EAAC,OAAO,EACZ,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAC/B,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAC3C,SAAS,CAAC,IAAI,CAAC,CAAC;YAChB,QAAQ,EAAE,EAAE,CAAC;QACf,CAAC,YAED,4BAAgB,QAAQ,YAAE,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,GAAQ,GACvD,CACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ export interface CopyButtonProperties {
2
+ /** What is copied. */
3
+ value: string;
4
+ /** The button's words ("Copy", "Copy all"). */
5
+ label: string;
6
+ /** Said for 2 seconds once copied ("Copied."). */
7
+ copiedLabel: string;
8
+ /** After copying (to show a notification). */
9
+ onCopied?: () => void;
10
+ }
11
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/copy-button/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,sBAAsB;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/copy-button/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import type { DialogProperties } from "@sharadox/graphical-user-interface-web-library/dialog/type";
2
+ /**
3
+ * A pop-up in the middle of the screen (the browser's own modal dialog: focus stays inside, the page behind is
4
+ * inert), named by its title, closed by Escape, its close button or a click on the backdrop. It leaves the way it
5
+ * came: the opening animation runs backwards before it closes, no longer modal meanwhile, so the page behind works
6
+ * at once.
7
+ *
8
+ * @example
9
+ * <Dialog open={asking} onClose={() => setAsking(false)} title="Check Your Email" closeLabel="Close">…</Dialog>
10
+ */
11
+ export declare function Dialog({ open, onClose, title, closeLabel, children }: DialogProperties): import("react").JSX.Element;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/dialog/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAC;AAMnG;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,gBAAgB,+BA8DtF"}
@@ -0,0 +1,56 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useRef, useState } from "react";
4
+ import { Box } from "@sharadox/graphical-user-interface-web-library/box";
5
+ import { Button } from "@sharadox/graphical-user-interface-web-library/button";
6
+ import styles from "./index.module.css";
7
+ /** The longest a leaving animation may take before the dialog closes anyway (reduced motion runs none). */
8
+ const LEAVING_MILLISECONDS = 300;
9
+ /**
10
+ * A pop-up in the middle of the screen (the browser's own modal dialog: focus stays inside, the page behind is
11
+ * inert), named by its title, closed by Escape, its close button or a click on the backdrop. It leaves the way it
12
+ * came: the opening animation runs backwards before it closes, no longer modal meanwhile, so the page behind works
13
+ * at once.
14
+ *
15
+ * @example
16
+ * <Dialog open={asking} onClose={() => setAsking(false)} title="Check Your Email" closeLabel="Close">…</Dialog>
17
+ */
18
+ export function Dialog({ open, onClose, title, closeLabel, children }) {
19
+ const dialog = useRef(null);
20
+ const titleId = useId();
21
+ // Leaving: closed by the parent but still on screen while its animation runs backwards.
22
+ const [leaving, setLeaving] = useState(false);
23
+ const [wasOpen, setWasOpen] = useState(open);
24
+ if (open !== wasOpen) {
25
+ setWasOpen(open);
26
+ setLeaving(!open);
27
+ }
28
+ const finish = () => {
29
+ dialog.current.close();
30
+ setLeaving(false);
31
+ };
32
+ useEffect(() => {
33
+ const element = dialog.current;
34
+ if (open && !element.open)
35
+ element.showModal();
36
+ if (!leaving)
37
+ return;
38
+ // Leaving, it stops being modal at once, so the page behind works straight away; it stays on screen only for
39
+ // its animation.
40
+ element.close();
41
+ element.show();
42
+ const timer = setTimeout(finish, LEAVING_MILLISECONDS);
43
+ return () => clearTimeout(timer);
44
+ }, [open, leaving]);
45
+ return (_jsx("dialog", { ref: dialog, className: styles.dialog, "aria-labelledby": titleId, "data-closing": leaving ? "" : undefined, onAnimationEnd: (event) => {
46
+ if (event.target === dialog.current && leaving)
47
+ finish();
48
+ }, onCancel: (event) => {
49
+ event.preventDefault();
50
+ onClose();
51
+ }, onClick: (event) => {
52
+ if (event.target === dialog.current)
53
+ onClose();
54
+ }, children: (open || leaving) && (_jsxs(Box, { direction: "top-to-bottom", align: "stretch", textAlign: "start", gap: 16, padding: 24, children: [_jsxs(Box, { justify: "space-between", align: "start", gap: 16, children: [_jsx("h2", { id: titleId, className: styles.title, children: title }), _jsx(Button, { square: true, variant: "transparent", color: "middleground", icon: "close", "aria-label": closeLabel, onClick: onClose })] }), children] })) }));
55
+ }
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/dialog/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,oDAAoD,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,uDAAuD,CAAC;AAE/E,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAEzC,2GAA2G;AAC3G,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAoB;IACrF,MAAM,MAAM,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,KAAK,EAAE,CAAC;IACxB,wFAAwF;IACxF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,MAAM,MAAM,GAAG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AAC,KAAK,EAAC,SAAS,EAAC,SAAS,EAAC,OAAO,EAAC,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,aACnF,MAAC,GAAG,IAAC,OAAO,EAAC,eAAe,EAAC,KAAK,EAAC,OAAO,EAAC,GAAG,EAAE,EAAE,aAChD,aAAI,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,YACrC,KAAK,GACH,EACL,KAAC,MAAM,IACL,MAAM,QACN,OAAO,EAAC,aAAa,EACrB,KAAK,EAAC,cAAc,EACpB,IAAI,EAAC,OAAO,gBACA,UAAU,EACtB,OAAO,EAAE,OAAO,GAChB,IACE,EACL,QAAQ,IACL,CACP,GACM,CACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ :where(.dialog){position:fixed;inset:0;box-sizing:border-box;inline-size:min(440px,100vw - 2*var(--scale-16));block-size:fit-content;max-block-size:calc(100dvh - 2*var(--scale-16));margin:auto;padding:0;overflow:auto;border:var(--line-thickness) var(--line-style) var(--foreground-border-color);border-radius:var(--corner-radius);background:var(--background-color);box-shadow:0 var(--scale-24) var(--scale-64) rgba(0,0,0,.25);color:var(--foreground-color);font-family:var(--font-family);scrollbar-width:thin}:where(.dialog)::backdrop{background:rgba(0,0,0,.5);-webkit-backdrop-filter:blur(var(--scale-4));backdrop-filter:blur(var(--scale-4));animation:fade var(--duration) var(--easing)}:where(.dialog)[open]{animation:rise var(--duration) var(--easing)}:where(.dialog)[data-closing]{animation:rise var(--duration) var(--easing) reverse forwards}:where(.dialog)[data-closing]::backdrop{animation:fade var(--duration) var(--easing) reverse forwards}:where(.title){margin:0;font-size:var(--scale-24);font-weight:600;line-height:1.2}@keyframes rise{from{opacity:0;transform:translateY(var(--scale-16)) scale(0.98)}}@keyframes fade{from{opacity:0}}
@@ -0,0 +1,59 @@
1
+ // Always in the middle of the screen, whatever a site resets margins and positions to.
2
+ :where(.dialog) {
3
+ position: fixed;
4
+ inset: 0;
5
+ box-sizing: border-box;
6
+ inline-size: min(440px, calc(100vw - 2 * var(--scale-16)));
7
+ block-size: fit-content;
8
+ max-block-size: calc(100dvh - 2 * var(--scale-16));
9
+ margin: auto;
10
+ padding: 0;
11
+ overflow: auto;
12
+ border: var(--line-thickness) var(--line-style) var(--foreground-border-color);
13
+ border-radius: var(--corner-radius);
14
+ background: var(--background-color);
15
+ box-shadow: 0 var(--scale-24) var(--scale-64) rgb(0 0 0 / 25%);
16
+ color: var(--foreground-color);
17
+ font-family: var(--font-family);
18
+ scrollbar-width: thin;
19
+
20
+ &::backdrop {
21
+ background: rgb(0 0 0 / 50%);
22
+ -webkit-backdrop-filter: blur(var(--scale-4));
23
+ backdrop-filter: blur(var(--scale-4));
24
+ animation: fade var(--duration) var(--easing);
25
+ }
26
+
27
+ &[open] {
28
+ animation: rise var(--duration) var(--easing);
29
+ }
30
+
31
+ // Leaving: the same movement, backwards.
32
+ &[data-closing] {
33
+ animation: rise var(--duration) var(--easing) reverse forwards;
34
+ }
35
+
36
+ &[data-closing]::backdrop {
37
+ animation: fade var(--duration) var(--easing) reverse forwards;
38
+ }
39
+ }
40
+
41
+ :where(.title) {
42
+ margin: 0;
43
+ font-size: var(--scale-24);
44
+ font-weight: 600;
45
+ line-height: 1.2;
46
+ }
47
+
48
+ @keyframes rise {
49
+ from {
50
+ opacity: 0;
51
+ transform: translateY(var(--scale-16)) scale(0.98);
52
+ }
53
+ }
54
+
55
+ @keyframes fade {
56
+ from {
57
+ opacity: 0;
58
+ }
59
+ }
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from "react";
2
+ export interface DialogProperties {
3
+ open: boolean;
4
+ /** Escape, the close button or a click on the backdrop. */
5
+ onClose: () => void;
6
+ title: string;
7
+ /** The close button's name ("Close"). */
8
+ closeLabel: string;
9
+ children: ReactNode;
10
+ }
11
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/dialog/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,2DAA2D;IAC3D,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/dialog/type.ts"],"names":[],"mappings":""}
@@ -2,7 +2,7 @@ import type { FieldProperties } from "@sharadox/graphical-user-interface-web-lib
2
2
  /**
3
3
  * A form control with its label above it and its hint and error under it, all linked for assistive technology: the
4
4
  * label names the control, the hint and error describe it, and an error marks it invalid. The control is drawn by
5
- * `children`, which receives the attributes to spread on it.
5
+ * `children`, which receives the attributes to spread on it. The label's id is the control's plus `-label`.
6
6
  *
7
7
  * @example
8
8
  * <Field label="Email" hint="We never share it." error={error}>{(control) => <input {...control} type="email" />}</Field>