@robert-stackflow/oneui 0.6.39 → 0.6.41

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 (60) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +347 -329
  3. package/components/AccountItem.module.css +103 -103
  4. package/components/AppShell.module.css +223 -223
  5. package/components/Badge.module.css +30 -30
  6. package/components/BarChart.module.css +35 -35
  7. package/components/Breadcrumb.module.css +97 -97
  8. package/components/Button.module.css +120 -120
  9. package/components/Card.d.ts +2 -1
  10. package/components/Card.js +3 -1
  11. package/components/Card.module.css +6 -1
  12. package/components/Checkbox.module.css +95 -95
  13. package/components/Control.module.css +86 -86
  14. package/components/DataTable.module.css +75 -75
  15. package/components/Descriptions.module.css +4 -3
  16. package/components/Form.d.ts +5 -1
  17. package/components/Form.js +5 -1
  18. package/components/FormField.js +1 -0
  19. package/components/FormField.module.css +11 -3
  20. package/components/HierarchyPicker.module.css +185 -185
  21. package/components/IconButton.module.css +6 -10
  22. package/components/Indicator.module.css +83 -83
  23. package/components/Layout.module.css +82 -82
  24. package/components/Markdown.module.css +227 -227
  25. package/components/NativeForm.d.ts +10 -0
  26. package/components/NativeForm.js +155 -0
  27. package/components/NavBar.module.css +130 -130
  28. package/components/Popover.js +12 -5
  29. package/components/Progress.module.css +33 -33
  30. package/components/RadioGroup.module.css +87 -87
  31. package/components/RangeSlider.module.css +141 -141
  32. package/components/ResizablePanel.module.css +101 -101
  33. package/components/ResourceCard.module.css +98 -98
  34. package/components/Section.d.ts +7 -4
  35. package/components/Section.js +24 -8
  36. package/components/Section.module.css +24 -5
  37. package/components/SettingRow.js +1 -1
  38. package/components/SettingRow.module.css +8 -6
  39. package/components/SettingsLayout.module.css +3 -2
  40. package/components/Slider.module.css +19 -19
  41. package/components/SplitButton.d.ts +14 -3
  42. package/components/SplitButton.js +76 -40
  43. package/components/SplitButton.module.css +34 -8
  44. package/components/Steps.module.css +176 -176
  45. package/components/Tab.module.css +148 -148
  46. package/components/ThemePicker.module.css +178 -178
  47. package/components/TimeColumns.module.css +47 -47
  48. package/components/Timeline.module.css +202 -202
  49. package/components/TreeTable.module.css +57 -57
  50. package/components/UptimeChart.module.css +15 -15
  51. package/components/field.d.ts +1 -1
  52. package/components/field.js +2 -1
  53. package/components/form-validation.d.ts +4 -0
  54. package/components/form-validation.js +22 -0
  55. package/components/index.d.ts +5 -3
  56. package/components/index.js +9 -3
  57. package/package.json +1 -1
  58. package/styles/base.css +9 -0
  59. package/styles/blue.css +270 -270
  60. package/styles/minimal.css +2 -2
@@ -0,0 +1,155 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import {
4
+ useRef,
5
+ useImperativeHandle,
6
+ useState
7
+ } from "react";
8
+ import { FormLayoutContext } from "./FormLayout.js";
9
+ import {
10
+ FormValidationContext,
11
+ formControls,
12
+ validateForm
13
+ } from "./form-validation.js";
14
+ import { FormErrorSummary } from "./FormErrorSummary.js";
15
+ import { useUIConfig } from "./UIProvider.js";
16
+ function NativeForm({
17
+ children,
18
+ layout = "stacked",
19
+ labelWidth,
20
+ validationMode = "submit",
21
+ ref,
22
+ onSubmit,
23
+ onSubmitError,
24
+ onReset,
25
+ onInvalidCapture,
26
+ onInput,
27
+ onChange,
28
+ onBlurCapture,
29
+ ...props
30
+ }) {
31
+ const [errors, setErrors] = useState({}), [submitError, setSubmitError] = useState(""), [pending, setPending] = useState(false);
32
+ const formRef = useRef(null), attempted = useRef(false), locked = useRef(false), touched = useRef(/* @__PURE__ */ new Set());
33
+ const { locale } = useUIConfig();
34
+ useImperativeHandle(ref, () => formRef.current);
35
+ const fieldKey = (field) => field.id || field.name;
36
+ const message = (field) => {
37
+ if (!field.willValidate || field.validity.valid) return "";
38
+ if (field.validity.customError) return field.validationMessage;
39
+ const en = locale.startsWith("en"), tw = /tw|hant/i.test(locale);
40
+ if (field.validity.valueMissing)
41
+ return en ? "This field is required." : tw ? "\u8ACB\u586B\u5BEB\u6B64\u6B04\u4F4D\u3002" : "\u8BF7\u586B\u5199\u6B64\u5B57\u6BB5\u3002";
42
+ if (field.validity.typeMismatch || field.validity.patternMismatch)
43
+ return en ? "Enter a value in the required format." : tw ? "\u8ACB\u8F38\u5165\u6B63\u78BA\u683C\u5F0F\u3002" : "\u8BF7\u8F93\u5165\u6B63\u786E\u683C\u5F0F\u3002";
44
+ return field.validationMessage;
45
+ };
46
+ const update = (target, blur = false) => {
47
+ if (!(target instanceof HTMLInputElement || target instanceof HTMLSelectElement || target instanceof HTMLTextAreaElement))
48
+ return;
49
+ const key = fieldKey(target);
50
+ if (!key) return;
51
+ if (blur) touched.current.add(key);
52
+ if (attempted.current || validationMode === "change" || touched.current.has(key)) {
53
+ const error = message(target);
54
+ setErrors((old) => {
55
+ const next = { ...old };
56
+ if (error) next[key] = error;
57
+ else delete next[key];
58
+ return next;
59
+ });
60
+ }
61
+ };
62
+ const submit = async (event) => {
63
+ const form = event.currentTarget;
64
+ event.preventDefault();
65
+ if (locked.current || props["aria-busy"] === true || props["aria-busy"] === "true")
66
+ return;
67
+ attempted.current = true;
68
+ setSubmitError("");
69
+ const next = {};
70
+ for (const field of formControls(form)) {
71
+ const error = message(field);
72
+ if (error && fieldKey(field)) next[fieldKey(field)] = error;
73
+ }
74
+ setErrors(next);
75
+ if (!validateForm(form)) return;
76
+ locked.current = true;
77
+ try {
78
+ const result = onSubmit?.(event);
79
+ if (result && typeof result.then === "function") {
80
+ setPending(true);
81
+ await result;
82
+ }
83
+ } catch (error) {
84
+ setSubmitError(
85
+ locale.startsWith("en") ? "Could not submit. Please try again." : /tw|hant/i.test(locale) ? "\u63D0\u4EA4\u5931\u6557\uFF0C\u8ACB\u91CD\u8A66\u3002" : "\u63D0\u4EA4\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002"
86
+ );
87
+ onSubmitError?.(error);
88
+ } finally {
89
+ locked.current = false;
90
+ setPending(false);
91
+ }
92
+ };
93
+ const unmatched = Object.fromEntries(
94
+ Object.entries(errors).filter(
95
+ ([id]) => !formRef.current?.ownerDocument.getElementById(id)?.closest("[data-field-id]")
96
+ )
97
+ );
98
+ return /* @__PURE__ */ jsx(FormLayoutContext, { value: { layout, labelWidth }, children: /* @__PURE__ */ jsx(FormValidationContext, { value: errors, children: /* @__PURE__ */ jsxs(
99
+ "form",
100
+ {
101
+ ...props,
102
+ noValidate: true,
103
+ ref: formRef,
104
+ "aria-busy": pending || props["aria-busy"] || void 0,
105
+ onSubmit: submit,
106
+ onReset: (event) => {
107
+ onReset?.(event);
108
+ if (!event.defaultPrevented) {
109
+ attempted.current = false;
110
+ touched.current.clear();
111
+ setErrors({});
112
+ setSubmitError("");
113
+ }
114
+ },
115
+ onInvalidCapture: (event) => {
116
+ event.preventDefault();
117
+ onInvalidCapture?.(event);
118
+ const field = event.target;
119
+ const key = fieldKey(field);
120
+ if (key) {
121
+ touched.current.add(key);
122
+ setErrors((old) => ({ ...old, [key]: message(field) }));
123
+ }
124
+ },
125
+ onInput: (event) => {
126
+ onInput?.(event);
127
+ const target = event.target;
128
+ queueMicrotask(() => update(target));
129
+ },
130
+ onChange: (event) => {
131
+ onChange?.(event);
132
+ const target = event.target;
133
+ queueMicrotask(() => update(target));
134
+ },
135
+ onBlurCapture: (event) => {
136
+ onBlurCapture?.(event);
137
+ if (validationMode === "blur") update(event.target, true);
138
+ },
139
+ children: [
140
+ children,
141
+ (Object.keys(unmatched).length > 0 || submitError) && /* @__PURE__ */ jsx(
142
+ FormErrorSummary,
143
+ {
144
+ submitError,
145
+ errors: unmatched,
146
+ onFocus: (id) => formControls(formRef.current).find((field) => fieldKey(field) === id)?.focus()
147
+ }
148
+ )
149
+ ]
150
+ }
151
+ ) }) });
152
+ }
153
+ export {
154
+ NativeForm
155
+ };
@@ -1,130 +1,130 @@
1
- .bar {
2
- display: flex;
3
- align-items: center;
4
- gap: 24px;
5
- min-width: 0;
6
- min-height: 68px;
7
- padding: 12px 24px;
8
- color: var(--fg);
9
- background: var(--surface);
10
- border-bottom: 1px solid var(--line);
11
- }
12
- .brand {
13
- display: inline-flex;
14
- align-items: center;
15
- gap: 10px;
16
- flex-shrink: 0;
17
- color: var(--fg);
18
- text-decoration: none;
19
- font-weight: 600;
20
- }
21
- .brand > svg {
22
- width: 24px;
23
- height: 24px;
24
- color: var(--accent-ink, var(--accent));
25
- }
26
- .links {
27
- display: flex;
28
- align-items: center;
29
- justify-content: flex-end;
30
- gap: 6px;
31
- min-width: 0;
32
- margin-left: auto;
33
- }
34
- .link,
35
- .menuItem {
36
- display: flex;
37
- align-items: center;
38
- justify-content: flex-start;
39
- gap: 9px;
40
- min-height: 38px;
41
- padding: 8px 13px;
42
- border: 0;
43
- border-radius: 9px;
44
- background: transparent;
45
- color: var(--muted);
46
- font: inherit;
47
- font-size: 13px;
48
- line-height: 1.5;
49
- text-decoration: none;
50
- white-space: nowrap;
51
- cursor: pointer;
52
- transition:
53
- color var(--motion-hover),
54
- background var(--motion-hover);
55
- }
56
- .link > svg,
57
- .menuItem > svg {
58
- flex-shrink: 0;
59
- width: 17px;
60
- height: 17px;
61
- }
62
- .link:hover:not(:disabled):not([aria-disabled]),
63
- .menuItem:hover:not([aria-disabled]) {
64
- color: var(--fg);
65
- background: var(--hover);
66
- }
67
- .link[aria-current],
68
- .link[data-selected],
69
- .menuItem[aria-current] {
70
- color: var(--navigation-active-color, var(--fg));
71
- background: var(--selected);
72
- }
73
- .link:disabled,
74
- .link[aria-disabled],
75
- .menuItem[aria-disabled] {
76
- opacity: 0.45;
77
- cursor: not-allowed;
78
- }
79
- .link:focus-visible,
80
- .menuItem:focus-visible,
81
- .brand:focus-visible {
82
- outline: 2px solid var(--accent-ink, var(--accent));
83
- outline-offset: -2px;
84
- }
85
- .chevron {
86
- transition: transform var(--motion-chevron) var(--ease);
87
- }
88
- .link[aria-expanded="true"] .chevron {
89
- transform: rotate(180deg);
90
- }
91
- .menuItem {
92
- min-width: 0;
93
- width: 100%;
94
- }
95
- .menuItem > span {
96
- overflow: hidden;
97
- text-overflow: ellipsis;
98
- }
99
- .actions {
100
- display: flex;
101
- align-items: center;
102
- gap: 8px;
103
- flex-shrink: 0;
104
- }
105
- .mobileToggle {
106
- display: none;
107
- }
108
- @media (max-width: 720px) {
109
- .bar {
110
- min-height: 60px;
111
- padding: 10px 16px;
112
- gap: 12px;
113
- }
114
- .links {
115
- display: none;
116
- }
117
- .actions {
118
- margin-left: auto;
119
- }
120
- .mobileToggle {
121
- display: inline-flex;
122
- }
123
- }
124
- @media (prefers-reduced-motion: reduce) {
125
- .link,
126
- .menuItem,
127
- .chevron {
128
- transition: none;
129
- }
130
- }
1
+ .bar {
2
+ display: flex;
3
+ align-items: center;
4
+ gap: 24px;
5
+ min-width: 0;
6
+ min-height: 68px;
7
+ padding: 12px 24px;
8
+ color: var(--fg);
9
+ background: var(--surface);
10
+ border-bottom: 1px solid var(--line);
11
+ }
12
+ .brand {
13
+ display: inline-flex;
14
+ align-items: center;
15
+ gap: 10px;
16
+ flex-shrink: 0;
17
+ color: var(--fg);
18
+ text-decoration: none;
19
+ font-weight: 600;
20
+ }
21
+ .brand > svg {
22
+ width: 24px;
23
+ height: 24px;
24
+ color: var(--accent-ink, var(--accent));
25
+ }
26
+ .links {
27
+ display: flex;
28
+ align-items: center;
29
+ justify-content: flex-end;
30
+ gap: 6px;
31
+ min-width: 0;
32
+ margin-left: auto;
33
+ }
34
+ .link,
35
+ .menuItem {
36
+ display: flex;
37
+ align-items: center;
38
+ justify-content: flex-start;
39
+ gap: 9px;
40
+ min-height: 38px;
41
+ padding: 8px 13px;
42
+ border: 0;
43
+ border-radius: 9px;
44
+ background: transparent;
45
+ color: var(--muted);
46
+ font: inherit;
47
+ font-size: 13px;
48
+ line-height: 1.5;
49
+ text-decoration: none;
50
+ white-space: nowrap;
51
+ cursor: pointer;
52
+ transition:
53
+ color var(--motion-hover),
54
+ background var(--motion-hover);
55
+ }
56
+ .link > svg,
57
+ .menuItem > svg {
58
+ flex-shrink: 0;
59
+ width: 17px;
60
+ height: 17px;
61
+ }
62
+ .link:hover:not(:disabled):not([aria-disabled]),
63
+ .menuItem:hover:not([aria-disabled]) {
64
+ color: var(--fg);
65
+ background: var(--hover);
66
+ }
67
+ .link[aria-current],
68
+ .link[data-selected],
69
+ .menuItem[aria-current] {
70
+ color: var(--navigation-active-color, var(--fg));
71
+ background: var(--selected);
72
+ }
73
+ .link:disabled,
74
+ .link[aria-disabled],
75
+ .menuItem[aria-disabled] {
76
+ opacity: 0.45;
77
+ cursor: not-allowed;
78
+ }
79
+ .link:focus-visible,
80
+ .menuItem:focus-visible,
81
+ .brand:focus-visible {
82
+ outline: 2px solid var(--accent-ink, var(--accent));
83
+ outline-offset: -2px;
84
+ }
85
+ .chevron {
86
+ transition: transform var(--motion-chevron) var(--ease);
87
+ }
88
+ .link[aria-expanded="true"] .chevron {
89
+ transform: rotate(180deg);
90
+ }
91
+ .menuItem {
92
+ min-width: 0;
93
+ width: 100%;
94
+ }
95
+ .menuItem > span {
96
+ overflow: hidden;
97
+ text-overflow: ellipsis;
98
+ }
99
+ .actions {
100
+ display: flex;
101
+ align-items: center;
102
+ gap: 8px;
103
+ flex-shrink: 0;
104
+ }
105
+ .mobileToggle {
106
+ display: none;
107
+ }
108
+ @media (max-width: 720px) {
109
+ .bar {
110
+ min-height: 60px;
111
+ padding: 10px 16px;
112
+ gap: 12px;
113
+ }
114
+ .links {
115
+ display: none;
116
+ }
117
+ .actions {
118
+ margin-left: auto;
119
+ }
120
+ .mobileToggle {
121
+ display: inline-flex;
122
+ }
123
+ }
124
+ @media (prefers-reduced-motion: reduce) {
125
+ .link,
126
+ .menuItem,
127
+ .chevron {
128
+ transition: none;
129
+ }
130
+ }
@@ -14,7 +14,11 @@ import {
14
14
  cancelMotion
15
15
  } from "./motion.js";
16
16
  import s from "./Popover.module.css";
17
- import { useSurfacePortal } from "./surfacePortal.js";
17
+ import {
18
+ SurfacePortalContext,
19
+ useSurfaceHost,
20
+ useSurfacePortal
21
+ } from "./surfacePortal.js";
18
22
  function Popover({
19
23
  open: requestedOpen,
20
24
  onClose,
@@ -39,7 +43,8 @@ function Popover({
39
43
  }) {
40
44
  const root = usePortalRoot();
41
45
  const owner = useSurfacePortal(), portalHost = portalContainer || owner?.host || root, open = requestedOpen && owner?.active !== false;
42
- const ref = useRef(null), close = useRef(onClose);
46
+ const { ref, host, setRef } = useSurfaceHost();
47
+ const close = useRef(onClose);
43
48
  close.current = onClose;
44
49
  const opened = useRef(open);
45
50
  opened.current = open;
@@ -165,6 +170,8 @@ function Popover({
165
170
  };
166
171
  const key = (event) => {
167
172
  if (event.key === "Escape") {
173
+ if (surface.querySelector("[popover]:popover-open:not([inert])"))
174
+ return;
168
175
  event.preventDefault();
169
176
  event.stopPropagation();
170
177
  close.current();
@@ -208,7 +215,7 @@ function Popover({
208
215
  /* @__PURE__ */ jsx(
209
216
  "div",
210
217
  {
211
- ref,
218
+ ref: setRef,
212
219
  id,
213
220
  popover: "manual",
214
221
  role,
@@ -216,10 +223,10 @@ function Popover({
216
223
  "aria-describedby": descriptionId,
217
224
  onKeyDown,
218
225
  className: `${s.popover} ${scrollable ? "" : s.contained} ${arrow ? s.withArrow : ""} ${className}`,
219
- children: /* @__PURE__ */ jsx(FieldContext, { value: null, children: arrow ? /* @__PURE__ */ jsxs(Fragment, { children: [
226
+ children: /* @__PURE__ */ jsx(SurfacePortalContext, { value: { host, active: open }, children: /* @__PURE__ */ jsx(FieldContext, { value: null, children: arrow ? /* @__PURE__ */ jsxs(Fragment, { children: [
220
227
  /* @__PURE__ */ jsx("span", { className: s.arrow, "data-popover-arrow": true, "aria-hidden": "true" }),
221
228
  /* @__PURE__ */ jsx("div", { className: `${s.body} ${scrollable ? "" : s.bodyContained}`, children })
222
- ] }) : children })
229
+ ] }) : children }) })
223
230
  }
224
231
  ),
225
232
  portalHost
@@ -1,33 +1,33 @@
1
- .progress {
2
- height: 5px;
3
- width: 100%;
4
- background: var(--line);
5
- border-radius: 10px;
6
- overflow: hidden;
7
- }
8
- .progress span {
9
- display: block;
10
- height: 100%;
11
- background: var(--accent-ink, var(--accent));
12
- border-radius: inherit;
13
- transition: width var(--motion-panel) var(--ease);
14
- }
15
-
16
- .progress[data-indeterminate="true"] > span {
17
- width: 35%;
18
- animation: progress-travel 1.25s ease-in-out infinite;
19
- }
20
- .progress[data-tone="success"] > span {
21
- background: var(--success);
22
- }
23
- .progress[data-tone="error"] > span {
24
- background: var(--danger);
25
- }
26
- @keyframes progress-travel {
27
- from {
28
- transform: translateX(-100%);
29
- }
30
- to {
31
- transform: translateX(290%);
32
- }
33
- }
1
+ .progress {
2
+ height: 5px;
3
+ width: 100%;
4
+ background: var(--line);
5
+ border-radius: 10px;
6
+ overflow: hidden;
7
+ }
8
+ .progress span {
9
+ display: block;
10
+ height: 100%;
11
+ background: var(--accent-ink, var(--accent));
12
+ border-radius: inherit;
13
+ transition: width var(--motion-panel) var(--ease);
14
+ }
15
+
16
+ .progress[data-indeterminate="true"] > span {
17
+ width: 35%;
18
+ animation: progress-travel 1.25s ease-in-out infinite;
19
+ }
20
+ .progress[data-tone="success"] > span {
21
+ background: var(--success);
22
+ }
23
+ .progress[data-tone="error"] > span {
24
+ background: var(--danger);
25
+ }
26
+ @keyframes progress-travel {
27
+ from {
28
+ transform: translateX(-100%);
29
+ }
30
+ to {
31
+ transform: translateX(290%);
32
+ }
33
+ }