@adea-ai/ui 0.85.0 → 0.88.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/dist/NOTICE +34 -0
- package/dist/components/composites/action-button/action-button.d.ts.map +1 -1
- package/dist/components/composites/action-button/action-button.js +2 -2
- package/dist/components/composites/action-button/action-button.js.map +1 -1
- package/dist/components/composites/list-row/list-row.d.ts +6 -3
- package/dist/components/composites/list-row/list-row.d.ts.map +1 -1
- package/dist/components/composites/list-row/list-row.js +69 -7
- package/dist/components/composites/list-row/list-row.js.map +1 -1
- package/dist/components/composites/settings/settings.d.ts +9 -11
- package/dist/components/composites/settings/settings.d.ts.map +1 -1
- package/dist/components/composites/settings/settings.js +48 -33
- package/dist/components/composites/settings/settings.js.map +1 -1
- package/dist/components/conversation/message-composer.js +1 -1
- package/dist/components/conversation/scroll-follow.d.ts.map +1 -1
- package/dist/components/conversation/scroll-follow.js +95 -15
- package/dist/components/conversation/scroll-follow.js.map +1 -1
- package/dist/components/layout/app-shell/index.d.ts +1 -0
- package/dist/components/layout/app-shell/index.d.ts.map +1 -1
- package/dist/components/layout/app-shell/index.js +2 -1
- package/dist/components/layout/app-shell/skip-link.d.ts +11 -0
- package/dist/components/layout/app-shell/skip-link.d.ts.map +1 -0
- package/dist/components/layout/app-shell/skip-link.js +44 -0
- package/dist/components/layout/app-shell/skip-link.js.map +1 -0
- package/dist/components/layout/floating-preview/floating-preview.d.ts +12 -0
- package/dist/components/layout/floating-preview/floating-preview.d.ts.map +1 -0
- package/dist/components/layout/floating-preview/floating-preview.js +283 -0
- package/dist/components/layout/floating-preview/floating-preview.js.map +1 -0
- package/dist/components/layout/floating-preview/index.d.ts +3 -0
- package/dist/components/layout/floating-preview/index.d.ts.map +1 -0
- package/dist/components/layout/floating-preview/index.js +3 -0
- package/dist/components/layout/floating-preview/model.d.ts +74 -0
- package/dist/components/layout/floating-preview/model.d.ts.map +1 -0
- package/dist/components/layout/floating-preview/model.js +146 -0
- package/dist/components/layout/floating-preview/model.js.map +1 -0
- package/dist/components/layout/sidebar-nav/index.d.ts +1 -1
- package/dist/components/layout/sidebar-nav/index.d.ts.map +1 -1
- package/dist/components/layout/sidebar-nav/sidebar-nav.d.ts +18 -2
- package/dist/components/layout/sidebar-nav/sidebar-nav.d.ts.map +1 -1
- package/dist/components/layout/sidebar-nav/sidebar-nav.js +42 -11
- package/dist/components/layout/sidebar-nav/sidebar-nav.js.map +1 -1
- package/dist/components/theme/index.d.ts +1 -0
- package/dist/components/theme/index.d.ts.map +1 -1
- package/dist/components/theme/index.js +2 -1
- package/dist/components/theme/theme-mode-toggle.d.ts +10 -0
- package/dist/components/theme/theme-mode-toggle.d.ts.map +1 -0
- package/dist/components/theme/theme-mode-toggle.js +82 -0
- package/dist/components/theme/theme-mode-toggle.js.map +1 -0
- package/dist/components/ui/checkbox/checkbox.d.ts +2 -0
- package/dist/components/ui/checkbox/checkbox.d.ts.map +1 -1
- package/dist/components/ui/checkbox/checkbox.js +24 -3
- package/dist/components/ui/checkbox/checkbox.js.map +1 -1
- package/dist/components/ui/combobox/combobox.d.ts.map +1 -1
- package/dist/components/ui/combobox/combobox.js +41 -4
- package/dist/components/ui/combobox/combobox.js.map +1 -1
- package/dist/components/ui/combobox/index.d.ts +1 -0
- package/dist/components/ui/combobox/index.d.ts.map +1 -1
- package/dist/components/ui/combobox/index.js +2 -1
- package/dist/components/ui/combobox/value-combobox.d.ts +19 -0
- package/dist/components/ui/combobox/value-combobox.d.ts.map +1 -0
- package/dist/components/ui/combobox/value-combobox.js +42 -0
- package/dist/components/ui/combobox/value-combobox.js.map +1 -0
- package/dist/components/ui/empty/empty-state.d.ts +15 -0
- package/dist/components/ui/empty/empty-state.d.ts.map +1 -0
- package/dist/components/ui/empty/empty-state.js +96 -0
- package/dist/components/ui/empty/empty-state.js.map +1 -0
- package/dist/components/ui/empty/index.d.ts +1 -0
- package/dist/components/ui/empty/index.d.ts.map +1 -1
- package/dist/components/ui/empty/index.js +2 -1
- package/dist/components/ui/entity-icon/entity-icon.d.ts +4 -1
- package/dist/components/ui/entity-icon/entity-icon.d.ts.map +1 -1
- package/dist/components/ui/entity-icon/entity-icon.js +37 -13
- package/dist/components/ui/entity-icon/entity-icon.js.map +1 -1
- package/dist/components/ui/field/field.d.ts +36 -13
- package/dist/components/ui/field/field.d.ts.map +1 -1
- package/dist/components/ui/field/field.js +146 -24
- package/dist/components/ui/field/field.js.map +1 -1
- package/dist/components/ui/field/index.d.ts +3 -1
- package/dist/components/ui/field/index.d.ts.map +1 -1
- package/dist/components/ui/field/index.js +3 -2
- package/dist/components/ui/field/number-field.d.ts +19 -0
- package/dist/components/ui/field/number-field.d.ts.map +1 -0
- package/dist/components/ui/field/number-field.js +76 -0
- package/dist/components/ui/field/number-field.js.map +1 -0
- package/dist/components/ui/input/index.d.ts +1 -0
- package/dist/components/ui/input/index.d.ts.map +1 -1
- package/dist/components/ui/input/index.js +2 -1
- package/dist/components/ui/input/input-control.d.ts +11 -0
- package/dist/components/ui/input/input-control.d.ts.map +1 -0
- package/dist/components/ui/input/input-control.js +24 -0
- package/dist/components/ui/input/input-control.js.map +1 -0
- package/dist/components/ui/input/input.d.ts.map +1 -1
- package/dist/components/ui/input/input.js +56 -28
- package/dist/components/ui/input/input.js.map +1 -1
- package/dist/components/ui/input-group/index.d.ts +1 -0
- package/dist/components/ui/input-group/index.d.ts.map +1 -1
- package/dist/components/ui/input-group/index.js +2 -1
- package/dist/components/ui/input-group/input-group.d.ts.map +1 -1
- package/dist/components/ui/input-group/input-group.js +42 -5
- package/dist/components/ui/input-group/input-group.js.map +1 -1
- package/dist/components/ui/input-group/secret-input-group.d.ts +11 -0
- package/dist/components/ui/input-group/secret-input-group.d.ts.map +1 -0
- package/dist/components/ui/input-group/secret-input-group.js +67 -0
- package/dist/components/ui/input-group/secret-input-group.js.map +1 -0
- package/dist/components/ui/native-select/native-select.d.ts.map +1 -1
- package/dist/components/ui/native-select/native-select.js +39 -4
- package/dist/components/ui/native-select/native-select.js.map +1 -1
- package/dist/components/ui/progress/progress.d.ts.map +1 -1
- package/dist/components/ui/progress/progress.js +30 -18
- package/dist/components/ui/progress/progress.js.map +1 -1
- package/dist/components/ui/radio-group/radio-group.d.ts.map +1 -1
- package/dist/components/ui/radio-group/radio-group.js +41 -4
- package/dist/components/ui/radio-group/radio-group.js.map +1 -1
- package/dist/components/ui/switch/switch.d.ts +2 -0
- package/dist/components/ui/switch/switch.d.ts.map +1 -1
- package/dist/components/ui/switch/switch.js +24 -3
- package/dist/components/ui/switch/switch.js.map +1 -1
- package/dist/components/ui/tabs/tabs.js +1 -1
- package/dist/components/ui/tabs/tabs.js.map +1 -1
- package/dist/components/ui/text-link/index.d.ts +2 -0
- package/dist/components/ui/text-link/index.d.ts.map +1 -0
- package/dist/components/ui/text-link/index.js +2 -0
- package/dist/components/ui/text-link/text-link.d.ts +9 -0
- package/dist/components/ui/text-link/text-link.d.ts.map +1 -0
- package/dist/components/ui/text-link/text-link.js +30 -0
- package/dist/components/ui/text-link/text-link.js.map +1 -0
- package/dist/components/ui/textarea/textarea.d.ts.map +1 -1
- package/dist/components/ui/textarea/textarea.js +41 -4
- package/dist/components/ui/textarea/textarea.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -7
- package/dist/lib/clipboard.d.ts +3 -0
- package/dist/lib/clipboard.d.ts.map +1 -0
- package/dist/lib/clipboard.js +35 -0
- package/dist/lib/clipboard.js.map +1 -0
- package/dist/lib/download.d.ts +3 -0
- package/dist/lib/download.d.ts.map +1 -0
- package/dist/lib/download.js +31 -0
- package/dist/lib/download.js.map +1 -0
- package/dist/lib/form-field.d.ts +37 -0
- package/dist/lib/form-field.d.ts.map +1 -0
- package/dist/lib/form-field.js +47 -0
- package/dist/lib/form-field.js.map +1 -0
- package/dist/r/app-shell.json +5 -0
- package/dist/r/combobox.json +5 -0
- package/dist/r/empty.json +10 -1
- package/dist/r/field.json +7 -0
- package/dist/r/floating-preview.json +30 -0
- package/dist/r/input-group.json +6 -0
- package/dist/r/input.json +5 -0
- package/dist/r/lib.json +15 -0
- package/dist/r/list-row.json +1 -0
- package/dist/r/registry.json +112 -1
- package/dist/r/src/components/composites/action-button/action-button.tsx +5 -1
- package/dist/r/src/components/composites/list-row/list-row.tsx +81 -8
- package/dist/r/src/components/composites/settings/settings.tsx +67 -37
- package/dist/r/src/components/conversation/scroll-follow.ts +109 -15
- package/dist/r/src/components/layout/app-shell/index.ts +1 -0
- package/dist/r/src/components/layout/app-shell/skip-link.tsx +35 -0
- package/dist/r/src/components/layout/floating-preview/floating-preview.tsx +260 -0
- package/dist/r/src/components/layout/floating-preview/index.ts +2 -0
- package/dist/r/src/components/layout/floating-preview/model.ts +285 -0
- package/dist/r/src/components/layout/sidebar-nav/index.ts +2 -0
- package/dist/r/src/components/layout/sidebar-nav/sidebar-nav.tsx +71 -16
- package/dist/r/src/components/theme/index.ts +1 -0
- package/dist/r/src/components/theme/theme-mode-toggle.tsx +56 -0
- package/dist/r/src/components/ui/checkbox/checkbox.tsx +20 -3
- package/dist/r/src/components/ui/combobox/combobox.tsx +24 -1
- package/dist/r/src/components/ui/combobox/index.ts +1 -0
- package/dist/r/src/components/ui/combobox/value-combobox.tsx +38 -0
- package/dist/r/src/components/ui/empty/empty-state.tsx +71 -0
- package/dist/r/src/components/ui/empty/index.ts +1 -0
- package/dist/r/src/components/ui/entity-icon/entity-icon.tsx +33 -2
- package/dist/r/src/components/ui/field/field.tsx +102 -5
- package/dist/r/src/components/ui/field/index.ts +5 -0
- package/dist/r/src/components/ui/field/number-field.tsx +71 -0
- package/dist/r/src/components/ui/input/index.ts +1 -0
- package/dist/r/src/components/ui/input/input-control.tsx +38 -0
- package/dist/r/src/components/ui/input/input.tsx +32 -20
- package/dist/r/src/components/ui/input-group/index.ts +1 -0
- package/dist/r/src/components/ui/input-group/input-group.tsx +25 -2
- package/dist/r/src/components/ui/input-group/secret-input-group.tsx +58 -0
- package/dist/r/src/components/ui/native-select/native-select.tsx +27 -1
- package/dist/r/src/components/ui/progress/progress.tsx +12 -8
- package/dist/r/src/components/ui/radio-group/radio-group.tsx +30 -2
- package/dist/r/src/components/ui/switch/switch.tsx +20 -3
- package/dist/r/src/components/ui/tabs/tabs.tsx +1 -1
- package/dist/r/src/components/ui/text-link/index.ts +2 -0
- package/dist/r/src/components/ui/text-link/text-link.tsx +28 -0
- package/dist/r/src/components/ui/textarea/textarea.tsx +24 -1
- package/dist/r/src/lib/clipboard.ts +41 -0
- package/dist/r/src/lib/download.ts +29 -0
- package/dist/r/src/lib/form-field.ts +93 -0
- package/dist/r/text-link.json +22 -0
- package/dist/r/theming.json +6 -0
- package/package.json +1 -1
- package/registry.json +112 -1
- package/src/components/composites/action-button/action-button.tsx +5 -1
- package/src/components/composites/list-row/list-row.tsx +81 -8
- package/src/components/composites/settings/settings.tsx +67 -37
- package/src/components/conversation/scroll-follow.ts +109 -15
- package/src/components/layout/app-shell/index.ts +1 -0
- package/src/components/layout/app-shell/skip-link.tsx +35 -0
- package/src/components/layout/floating-preview/floating-preview.tsx +260 -0
- package/src/components/layout/floating-preview/index.ts +2 -0
- package/src/components/layout/floating-preview/model.ts +285 -0
- package/src/components/layout/sidebar-nav/index.ts +2 -0
- package/src/components/layout/sidebar-nav/sidebar-nav.tsx +71 -16
- package/src/components/theme/index.ts +1 -0
- package/src/components/theme/theme-mode-toggle.tsx +56 -0
- package/src/components/ui/checkbox/checkbox.tsx +20 -3
- package/src/components/ui/combobox/combobox.tsx +24 -1
- package/src/components/ui/combobox/index.ts +1 -0
- package/src/components/ui/combobox/value-combobox.tsx +38 -0
- package/src/components/ui/empty/empty-state.tsx +71 -0
- package/src/components/ui/empty/index.ts +1 -0
- package/src/components/ui/entity-icon/entity-icon.tsx +33 -2
- package/src/components/ui/field/field.tsx +102 -5
- package/src/components/ui/field/index.ts +5 -0
- package/src/components/ui/field/number-field.tsx +71 -0
- package/src/components/ui/input/index.ts +1 -0
- package/src/components/ui/input/input-control.tsx +38 -0
- package/src/components/ui/input/input.tsx +32 -20
- package/src/components/ui/input-group/index.ts +1 -0
- package/src/components/ui/input-group/input-group.tsx +25 -2
- package/src/components/ui/input-group/secret-input-group.tsx +58 -0
- package/src/components/ui/native-select/native-select.tsx +27 -1
- package/src/components/ui/progress/progress.tsx +12 -8
- package/src/components/ui/radio-group/radio-group.tsx +30 -2
- package/src/components/ui/switch/switch.tsx +20 -3
- package/src/components/ui/tabs/tabs.tsx +1 -1
- package/src/components/ui/text-link/index.ts +2 -0
- package/src/components/ui/text-link/text-link.tsx +28 -0
- package/src/components/ui/textarea/textarea.tsx +24 -1
- package/src/index.ts +3 -0
- package/src/lib/clipboard.ts +41 -0
- package/src/lib/download.ts +29 -0
- package/src/lib/form-field.ts +93 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { cn } from "../../../lib/utils.js";
|
|
2
2
|
import { cva } from "../../../lib/variants.js";
|
|
3
|
-
import { Dynamic, createComponent, insert, memo, mergeProps, spread, template } from "solid-js/web";
|
|
4
|
-
import { Show, splitProps } from "solid-js";
|
|
3
|
+
import { Dynamic, createComponent, effect, insert, memo, mergeProps, setAttribute, spread, template } from "solid-js/web";
|
|
4
|
+
import { Show, createSignal, splitProps } from "solid-js";
|
|
5
5
|
//#region src/components/ui/entity-icon/entity-icon.tsx
|
|
6
|
-
var _tmpl$ = /*#__PURE__*/ template(`<
|
|
7
|
-
var _tmpl$2 = /*#__PURE__*/ template(`<span
|
|
6
|
+
var _tmpl$ = /*#__PURE__*/ template(`<img data-slot=entity-icon-image alt aria-hidden=true class="pointer-events-none absolute inset-0 size-full object-contain">`);
|
|
7
|
+
var _tmpl$2 = /*#__PURE__*/ template(`<span class="absolute right-0 bottom-0 translate-x-1/4 translate-y-1/4">`);
|
|
8
|
+
var _tmpl$3 = /*#__PURE__*/ template(`<span role=img>`);
|
|
8
9
|
/**
|
|
9
10
|
* EntityIcon.
|
|
10
11
|
*
|
|
@@ -18,7 +19,8 @@ var _tmpl$2 = /*#__PURE__*/ template(`<span role=img>`);
|
|
|
18
19
|
*
|
|
19
20
|
* 1. **A glyph is always present.** A brand with no logo gets a monogram, not an
|
|
20
21
|
* empty box. `fallback` takes the name and returns the glyph, so a caller can
|
|
21
|
-
* choose initials, a domain letter, or a kind icon.
|
|
22
|
+
* choose initials, a domain letter, or a kind icon. When `src` is supplied,
|
|
23
|
+
* its contained image overlays that glyph and failure reveals the glyph below.
|
|
22
24
|
* 2. **The tile owns its own contrast.** `tone` tints the background while
|
|
23
25
|
* monogram text keeps the body foreground; vector glyphs retain the status
|
|
24
26
|
* colour. A caller never picks a colour pair or ships a glyph that disappears.
|
|
@@ -78,9 +80,24 @@ function Glyph(props) {
|
|
|
78
80
|
return props.glyph.value;
|
|
79
81
|
} }) : props.glyph.value;
|
|
80
82
|
}
|
|
83
|
+
function EntityIconImage(props) {
|
|
84
|
+
const [failed, setFailed] = createSignal(false);
|
|
85
|
+
return createComponent(Show, {
|
|
86
|
+
get when() {
|
|
87
|
+
return !failed();
|
|
88
|
+
},
|
|
89
|
+
get children() {
|
|
90
|
+
var _el$ = _tmpl$();
|
|
91
|
+
_el$.addEventListener("error", () => setFailed(true));
|
|
92
|
+
effect(() => setAttribute(_el$, "src", props.src));
|
|
93
|
+
return _el$;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
81
97
|
function EntityIcon(props) {
|
|
82
98
|
const [local, rest] = splitProps(props, [
|
|
83
99
|
"name",
|
|
100
|
+
"src",
|
|
84
101
|
"icon",
|
|
85
102
|
"fallback",
|
|
86
103
|
"badge",
|
|
@@ -102,8 +119,8 @@ function EntityIcon(props) {
|
|
|
102
119
|
};
|
|
103
120
|
};
|
|
104
121
|
return (() => {
|
|
105
|
-
var _el$ = _tmpl$
|
|
106
|
-
spread(_el
|
|
122
|
+
var _el$2 = _tmpl$3();
|
|
123
|
+
spread(_el$2, mergeProps({
|
|
107
124
|
get ["class"]() {
|
|
108
125
|
return cn(entityIconVariants({
|
|
109
126
|
shape: local.shape,
|
|
@@ -115,7 +132,7 @@ function EntityIcon(props) {
|
|
|
115
132
|
return local.name;
|
|
116
133
|
}
|
|
117
134
|
}, rest), false, true);
|
|
118
|
-
insert(_el
|
|
135
|
+
insert(_el$2, createComponent(Show, {
|
|
119
136
|
get when() {
|
|
120
137
|
return glyph();
|
|
121
138
|
},
|
|
@@ -126,17 +143,24 @@ function EntityIcon(props) {
|
|
|
126
143
|
return value();
|
|
127
144
|
} })
|
|
128
145
|
}), null);
|
|
129
|
-
insert(_el
|
|
146
|
+
insert(_el$2, createComponent(Show, {
|
|
147
|
+
get when() {
|
|
148
|
+
return local.src;
|
|
149
|
+
},
|
|
150
|
+
keyed: true,
|
|
151
|
+
children: (src) => createComponent(EntityIconImage, { src })
|
|
152
|
+
}), null);
|
|
153
|
+
insert(_el$2, createComponent(Show, {
|
|
130
154
|
get when() {
|
|
131
155
|
return local.badge;
|
|
132
156
|
},
|
|
133
157
|
get children() {
|
|
134
|
-
var _el$
|
|
135
|
-
insert(_el$
|
|
136
|
-
return _el$
|
|
158
|
+
var _el$3 = _tmpl$2();
|
|
159
|
+
insert(_el$3, () => local.badge);
|
|
160
|
+
return _el$3;
|
|
137
161
|
}
|
|
138
162
|
}), null);
|
|
139
|
-
return _el
|
|
163
|
+
return _el$2;
|
|
140
164
|
})();
|
|
141
165
|
}
|
|
142
166
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-icon.js","names":["Show","splitProps","Component","ComponentProps","JSX","Dynamic","cva","VariantProps","cn","entityIconVariants","variants","shape","rounded","circle","square","size","xs","sm","md","lg","xl","tone","neutral","primary","bare","success","warning","danger","info","defaultVariants","EntityIconVariantProps","EntityIconProps","Omit","name","icon","Element","fallback","badge","ring","monogram","words","trim","split","filter","Boolean","length","toUpperCase","slice","Glyph","kind","value","props","glyph","_$createComponent","component","EntityIcon","local","rest","undefined","_el$","_tmpl$2","_$spread","_$mergeProps","class","aria-label","_$insert","when","_$memo","children","_el$2","_tmpl$","_$createComponent","_$mergeProps","_$memo"],"sources":["../../../../src/components/ui/entity-icon/entity-icon.tsx"],"sourcesContent":["import { Show, splitProps, type Component, type ComponentProps, type JSX } from 'solid-js'\nimport { Dynamic } from 'solid-js/web'\nimport { cva, type VariantProps } from '#lib/variants'\nimport { cn } from '#lib/utils'\n\n/**\n * EntityIcon.\n *\n * A tile that stands for a thing: a room, a project, an agent, an installed\n * plugin, a workspace. Its job is to be identifiable in a column of its\n * siblings, which is a different job from `Avatar`'s (identifying a *person*) and\n * the reason the two are separate components rather than one with a `round` prop.\n *\n * Three decisions are baked in because getting them wrong is what makes icon\n * grids look messy:\n *\n * 1. **A glyph is always present.** A brand with no logo gets a monogram, not an\n * empty box. `fallback` takes the name and returns the glyph, so a caller can\n * choose initials, a domain letter, or a kind icon.\n * 2. **The tile owns its own contrast.** `tone` tints the background while\n * monogram text keeps the body foreground; vector glyphs retain the status\n * colour. A caller never picks a colour pair or ships a glyph that disappears.\n * 3. **Size is on the control ladder**, not arbitrary. A tile in a rail and a\n * tile in a detail header are the same two or three sizes every other\n * interactive element uses.\n *\n * `shape=\"rounded\"` is the default because a rounded square reads as an object\n * and a circle reads as a person; use `circle` only when the tile really does\n * hold a face.\n */\nexport const entityIconVariants = cva(\n 'relative inline-flex shrink-0 items-center justify-center overflow-hidden border font-semibold select-none [&_svg]:pointer-events-none [&_svg]:shrink-0',\n {\n variants: {\n shape: {\n rounded: 'rounded-lg',\n circle: 'rounded-full',\n square: 'rounded-none',\n },\n size: {\n xs: 'size-5 text-2xs [&_svg]:size-3',\n sm: 'size-6 text-2xs [&_svg]:size-3.5',\n md: 'size-8 text-xs [&_svg]:size-4',\n lg: 'size-10 text-sm [&_svg]:size-5',\n xl: 'size-12 text-base [&_svg]:size-6',\n },\n tone: {\n /** Neutral: an inset tile with a hairline edge — the default. */\n neutral: 'border-border bg-muted text-muted-foreground',\n /** On the brand: for a thing the application itself owns. */\n primary: 'border-transparent bg-primary-subtle text-primary',\n /** Bare: no fill and no edge, for a tile that already sits on a surface. */\n bare: 'border-transparent bg-transparent text-foreground',\n success: 'border-transparent bg-success-subtle text-foreground [&_svg]:text-success',\n warning: 'border-transparent bg-warning-subtle text-foreground [&_svg]:text-warning',\n danger: 'border-transparent bg-destructive-subtle text-foreground [&_svg]:text-destructive',\n info: 'border-transparent bg-info-subtle text-foreground [&_svg]:text-info',\n },\n },\n defaultVariants: { shape: 'rounded', size: 'md', tone: 'neutral' },\n }\n)\n\ntype EntityIconVariantProps = VariantProps<typeof entityIconVariants>\n\nexport type EntityIconProps = Omit<ComponentProps<'span'>, 'children'> &\n EntityIconVariantProps & {\n /** The entity's name. Used for the accessible label and, via `fallback`, the monogram. */\n name: string\n /**\n * A logo or icon — a Lucide icon reference (`icon={Wrench}`) or an element\n * (`icon={<Wrench />}`). Both are accepted because both are what a caller\n * naturally writes, and the difference is an implementation detail they should\n * not have to know.\n */\n icon?: Component | JSX.Element\n /** Glyph for an entity with no icon. Defaults to the name's first two letters. */\n fallback?: (name: string) => JSX.Element\n /** A corner badge: a status dot, an unread count, an installed tick. */\n badge?: JSX.Element\n /** A second edge, drawn outside the tile — an active or selected ring. */\n ring?: boolean\n }\n\n/**\n * Two letters from a name, chosen so the result is stable and readable: the\n * first letter of the first two words when there are two (\"Agent HQ\" → \"AH\"),\n * otherwise the first two characters (\"Kitchen\" → \"Ki\").\n */\nexport function monogram(name: string): string {\n const words = name.trim().split(/\\s+/).filter(Boolean)\n if (words.length >= 2) return (words[0]![0]! + words[1]![0]!).toUpperCase()\n return name.trim().slice(0, 2)\n}\n\n/**\n * A glyph is either a component reference or an element, and the two render\n * differently — `Dynamic` for the first, the element itself for the second. The\n * union is discriminated so the branch is checked rather than cast.\n */\ntype Glyph = { kind: 'component'; value: Component } | { kind: 'element'; value: JSX.Element }\n\nfunction Glyph(props: { glyph: Glyph }) {\n return props.glyph.kind === 'component' ? (\n <Dynamic component={props.glyph.value} />\n ) : (\n props.glyph.value\n )\n}\n\nexport function EntityIcon(props: EntityIconProps) {\n const [local, rest] = splitProps(props, [\n 'name',\n 'icon',\n 'fallback',\n 'badge',\n 'ring',\n 'shape',\n 'size',\n 'tone',\n 'class',\n ])\n\n const glyph = (): Glyph | undefined => {\n const icon = local.icon\n if (!icon) return undefined\n return typeof icon === 'function'\n ? { kind: 'component', value: icon as Component }\n : { kind: 'element', value: icon as JSX.Element }\n }\n\n return (\n <span\n class={cn(\n entityIconVariants({ shape: local.shape, size: local.size, tone: local.tone }),\n local.ring && 'ring-2 ring-ring ring-offset-2 ring-offset-background',\n local.class\n )}\n role=\"img\"\n aria-label={local.name}\n {...rest}\n >\n <Show\n when={glyph()}\n fallback={local.fallback ? local.fallback(local.name) : monogram(local.name)}\n >\n {(value) => <Glyph glyph={value()} />}\n </Show>\n <Show when={local.badge}>\n <span class=\"absolute right-0 bottom-0 translate-x-1/4 translate-y-1/4\">{local.badge}</span>\n </Show>\n </span>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAaS,qBAAqBH,IAChC,2JACA;CACEI,UAAU;EACRC,OAAO;GACLC,SAAS;GACTC,QAAQ;GACRC,QAAQ;EACV;EACAC,MAAM;GACJC,IAAI;GACJC,IAAI;GACJC,IAAI;GACJC,IAAI;GACJC,IAAI;EACN;EACAC,MAAM;;GAEJC,SAAS;;GAETC,SAAS;;GAETC,MAAM;GACNC,SAAS;GACTC,SAAS;GACTC,QAAQ;GACRC,MAAM;EACR;CACF;CACAC,iBAAiB;EAAElB,OAAO;EAAWI,MAAM;EAAMM,MAAM;CAAU;AACnE,CACF;;;;;;AA4BA,SAAgBkB,SAASN,MAAsB;CAC7C,MAAMO,QAAQP,KAAKQ,KAAK,CAAC,CAACC,MAAM,KAAK,CAAC,CAACC,OAAOC,OAAO;CACrD,IAAIJ,MAAMK,UAAU,GAAG,QAAQL,MAAM,EAAE,CAAE,KAAMA,MAAM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,IAACI,QAAK;IAAA,OAAEF,MAAM;GAAC,EAAA,CAAA;EAAI,CAAA,GAAA,IAAA;EAAAe,OAAAN,MAAAN,gBAEtCrD,MAAI;GAAA,IAACkE,OAAI;IAAA,OAAEV,MAAMnB;GAAK;GAAA,IAAA+B,WAAA;IAAA,IAAAC,QAAAC,OAAA;IAAAL,OAAAI,aACoDb,MAAMnB,KAAK;IAAA,OAAAgC;GAAA;EAAA,CAAA,GAAA,IAAA;EAAA,OAAAV;CAAA,EAAA,CAAA;AAI5F"}
|
|
1
|
+
{"version":3,"file":"entity-icon.js","names":["createSignal","Show","splitProps","Component","ComponentProps","JSX","Dynamic","cva","VariantProps","cn","entityIconVariants","variants","shape","rounded","circle","square","size","xs","sm","md","lg","xl","tone","neutral","primary","bare","success","warning","danger","info","defaultVariants","EntityIconVariantProps","EntityIconProps","Omit","name","src","icon","Element","fallback","badge","ring","monogram","words","trim","split","filter","Boolean","length","toUpperCase","slice","Glyph","kind","value","props","glyph","_$createComponent","component","EntityIconImage","failed","setFailed","when","children","_el$","_tmpl$","addEventListener","_$effect","_$setAttribute","EntityIcon","local","rest","undefined","_el$2","_tmpl$3","_$spread","_$mergeProps","class","aria-label","_$insert","_$memo","keyed","_el$3","_tmpl$2","_$createComponent","_$setAttribute","_$mergeProps","_$memo"],"sources":["../../../../src/components/ui/entity-icon/entity-icon.tsx"],"sourcesContent":["import {\n createSignal,\n Show,\n splitProps,\n type Component,\n type ComponentProps,\n type JSX,\n} from 'solid-js'\nimport { Dynamic } from 'solid-js/web'\nimport { cva, type VariantProps } from '#lib/variants'\nimport { cn } from '#lib/utils'\n\n/**\n * EntityIcon.\n *\n * A tile that stands for a thing: a room, a project, an agent, an installed\n * plugin, a workspace. Its job is to be identifiable in a column of its\n * siblings, which is a different job from `Avatar`'s (identifying a *person*) and\n * the reason the two are separate components rather than one with a `round` prop.\n *\n * Three decisions are baked in because getting them wrong is what makes icon\n * grids look messy:\n *\n * 1. **A glyph is always present.** A brand with no logo gets a monogram, not an\n * empty box. `fallback` takes the name and returns the glyph, so a caller can\n * choose initials, a domain letter, or a kind icon. When `src` is supplied,\n * its contained image overlays that glyph and failure reveals the glyph below.\n * 2. **The tile owns its own contrast.** `tone` tints the background while\n * monogram text keeps the body foreground; vector glyphs retain the status\n * colour. A caller never picks a colour pair or ships a glyph that disappears.\n * 3. **Size is on the control ladder**, not arbitrary. A tile in a rail and a\n * tile in a detail header are the same two or three sizes every other\n * interactive element uses.\n *\n * `shape=\"rounded\"` is the default because a rounded square reads as an object\n * and a circle reads as a person; use `circle` only when the tile really does\n * hold a face.\n */\nexport const entityIconVariants = cva(\n 'relative inline-flex shrink-0 items-center justify-center overflow-hidden border font-semibold select-none [&_svg]:pointer-events-none [&_svg]:shrink-0',\n {\n variants: {\n shape: {\n rounded: 'rounded-lg',\n circle: 'rounded-full',\n square: 'rounded-none',\n },\n size: {\n xs: 'size-5 text-2xs [&_svg]:size-3',\n sm: 'size-6 text-2xs [&_svg]:size-3.5',\n md: 'size-8 text-xs [&_svg]:size-4',\n lg: 'size-10 text-sm [&_svg]:size-5',\n xl: 'size-12 text-base [&_svg]:size-6',\n },\n tone: {\n /** Neutral: an inset tile with a hairline edge — the default. */\n neutral: 'border-border bg-muted text-muted-foreground',\n /** On the brand: for a thing the application itself owns. */\n primary: 'border-transparent bg-primary-subtle text-primary',\n /** Bare: no fill and no edge, for a tile that already sits on a surface. */\n bare: 'border-transparent bg-transparent text-foreground',\n success: 'border-transparent bg-success-subtle text-foreground [&_svg]:text-success',\n warning: 'border-transparent bg-warning-subtle text-foreground [&_svg]:text-warning',\n danger: 'border-transparent bg-destructive-subtle text-foreground [&_svg]:text-destructive',\n info: 'border-transparent bg-info-subtle text-foreground [&_svg]:text-info',\n },\n },\n defaultVariants: { shape: 'rounded', size: 'md', tone: 'neutral' },\n }\n)\n\ntype EntityIconVariantProps = VariantProps<typeof entityIconVariants>\n\nexport type EntityIconProps = Omit<ComponentProps<'span'>, 'children'> &\n EntityIconVariantProps & {\n /** The entity's name. Used for the accessible label and, via `fallback`, the monogram. */\n name: string\n /** Optional image URL. The image is decorative; `name` remains the accessible label. */\n src?: string\n /**\n * A logo or icon — a Lucide icon reference (`icon={Wrench}`) or an element\n * (`icon={<Wrench />}`). Both are accepted because both are what a caller\n * naturally writes, and the difference is an implementation detail they should\n * not have to know.\n */\n icon?: Component | JSX.Element\n /** Glyph for an entity with no icon. Defaults to the name's first two letters. */\n fallback?: (name: string) => JSX.Element\n /** A corner badge: a status dot, an unread count, an installed tick. */\n badge?: JSX.Element\n /** A second edge, drawn outside the tile — an active or selected ring. */\n ring?: boolean\n }\n\n/**\n * Two letters from a name, chosen so the result is stable and readable: the\n * first letter of the first two words when there are two (\"Agent HQ\" → \"AH\"),\n * otherwise the first two characters (\"Kitchen\" → \"Ki\").\n */\nexport function monogram(name: string): string {\n const words = name.trim().split(/\\s+/).filter(Boolean)\n if (words.length >= 2) return (words[0]![0]! + words[1]![0]!).toUpperCase()\n return name.trim().slice(0, 2)\n}\n\n/**\n * A glyph is either a component reference or an element, and the two render\n * differently — `Dynamic` for the first, the element itself for the second. The\n * union is discriminated so the branch is checked rather than cast.\n */\ntype Glyph = { kind: 'component'; value: Component } | { kind: 'element'; value: JSX.Element }\n\nfunction Glyph(props: { glyph: Glyph }) {\n return props.glyph.kind === 'component' ? (\n <Dynamic component={props.glyph.value} />\n ) : (\n props.glyph.value\n )\n}\n\nfunction EntityIconImage(props: { src: string }) {\n const [failed, setFailed] = createSignal(false)\n\n return (\n <Show when={!failed()}>\n <img\n data-slot=\"entity-icon-image\"\n src={props.src}\n alt=\"\"\n aria-hidden=\"true\"\n class=\"pointer-events-none absolute inset-0 size-full object-contain\"\n onError={() => setFailed(true)}\n />\n </Show>\n )\n}\n\nexport function EntityIcon(props: EntityIconProps) {\n const [local, rest] = splitProps(props, [\n 'name',\n 'src',\n 'icon',\n 'fallback',\n 'badge',\n 'ring',\n 'shape',\n 'size',\n 'tone',\n 'class',\n ])\n\n const glyph = (): Glyph | undefined => {\n const icon = local.icon\n if (!icon) return undefined\n return typeof icon === 'function'\n ? { kind: 'component', value: icon as Component }\n : { kind: 'element', value: icon as JSX.Element }\n }\n\n return (\n <span\n class={cn(\n entityIconVariants({ shape: local.shape, size: local.size, tone: local.tone }),\n local.ring && 'ring-2 ring-ring ring-offset-2 ring-offset-background',\n local.class\n )}\n role=\"img\"\n aria-label={local.name}\n {...rest}\n >\n <Show\n when={glyph()}\n fallback={local.fallback ? local.fallback(local.name) : monogram(local.name)}\n >\n {(value) => <Glyph glyph={value()} />}\n </Show>\n <Show when={local.src} keyed>\n {(src) => <EntityIconImage src={src} />}\n </Show>\n <Show when={local.badge}>\n <span class=\"absolute right-0 bottom-0 translate-x-1/4 translate-y-1/4\">{local.badge}</span>\n </Show>\n </span>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAaU,qBAAqBH,IAChC,2JACA;CACEI,UAAU;EACRC,OAAO;GACLC,SAAS;GACTC,QAAQ;GACRC,QAAQ;EACV;EACAC,MAAM;GACJC,IAAI;GACJC,IAAI;GACJC,IAAI;GACJC,IAAI;GACJC,IAAI;EACN;EACAC,MAAM;;GAEJC,SAAS;;GAETC,SAAS;;GAETC,MAAM;GACNC,SAAS;GACTC,SAAS;GACTC,QAAQ;GACRC,MAAM;EACR;CACF;CACAC,iBAAiB;EAAElB,OAAO;EAAWI,MAAM;EAAMM,MAAM;CAAU;AACnE,CACF;;;;;;AA8BA,SAAgBmB,SAASP,MAAsB;CAC7C,MAAMQ,QAAQR,KAAKS,KAAK,CAAC,CAACC,MAAM,KAAK,CAAC,CAACC,OAAOC,OAAO;CACrD,IAAIJ,MAAMK,UAAU,GAAG,QAAQL,MAAM,EAAE,CAAE,KAAMA,MAAM,EAAE,CAAE,GAAA,CAAKM,YAAY;CAC1E,OAAOd,KAAKS,KAAK,CAAC,CAACM,MAAM,GAAG,CAAC;AAC/B;AASA,SAASC,MAAMG,OAAyB;CAC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AI;IAAA,OAAEN,MAAM;GAAC;GAAA,IACbhB,WAAQ;IAAA,OAAEwC,WAAA,CAAA,CAAAV,MAAM9B,QAAQ,CAAA,CAAA,IAAG8B,MAAM9B,SAAS8B,MAAMlC,IAAI,IAAIO,SAAS2B,MAAMlC,IAAI;GAAC;GAAA2B,WAE1ET,UAAKG,gBAAML,OAAK,EAAA,IAACI,QAAK;IAAA,OAAEF,MAAM;GAAC,EAAA,CAAA;EAAI,CAAA,GAAA,IAAA;EAAAyB,OAAAN,OAAAhB,gBAEtCtD,MAAI;GAAA,IAAC2D,OAAI;IAAA,OAAEQ,MAAMjC;GAAG;GAAE4C,OAAK;GAAAlB,WACxB1B,QAAGoB,gBAAME,iBAAe,EAAMtB,IAAG,CAAA;EAAI,CAAA,GAAA,IAAA;EAAA0C,OAAAN,OAAAhB,gBAExCtD,MAAI;GAAA,IAAC2D,OAAI;IAAA,OAAEQ,MAAM7B;GAAK;GAAA,IAAAsB,WAAA;IAAA,IAAAmB,QAAAC,QAAA;IAAAJ,OAAAG,aACoDZ,MAAM7B,KAAK;IAAA,OAAAyC;GAAA;EAAA,CAAA,GAAA,IAAA;EAAA,OAAAT;CAAA,EAAA,CAAA;AAI5F"}
|
|
@@ -1,39 +1,62 @@
|
|
|
1
1
|
import { TextField as KobalteTextField } from '@kobalte/core/text-field';
|
|
2
|
-
import type { ComponentProps } from 'solid-js';
|
|
2
|
+
import type { ComponentProps, JSX } from 'solid-js';
|
|
3
3
|
/**
|
|
4
4
|
* Field.
|
|
5
5
|
*
|
|
6
6
|
* The wrapper that makes a form control describable and validatable: a label,
|
|
7
7
|
* a description, an error message, and the ARIA relationships between them.
|
|
8
8
|
*
|
|
9
|
+
* This Kobalte TextField composition is for its own `FieldLabel`, `FieldInput`
|
|
10
|
+
* and `FieldTextArea` parts. Use `FormField` to wire the standalone shared
|
|
11
|
+
* controls, including checkboxes, switches and comboboxes.
|
|
12
|
+
*
|
|
9
13
|
* It is built on Kobalte's TextField specifically so `aria-describedby`,
|
|
10
14
|
* `aria-invalid` and `aria-errormessage` are wired by construction. Those three
|
|
11
15
|
* attributes are the difference between "this field is required and empty" and
|
|
12
16
|
* a red border that only a sighted user can perceive — and they are also the
|
|
13
17
|
* first thing a hand-rolled form drops.
|
|
14
18
|
*
|
|
15
|
-
* `Field` owns the description and the error slot, so
|
|
16
|
-
*
|
|
17
|
-
|
|
19
|
+
* `Field` owns the description and the error slot, so its controls line up and
|
|
20
|
+
* its messages land in the same place regardless of which TextField part is used.
|
|
21
|
+
*/
|
|
22
|
+
export declare function Field(props: ComponentProps<typeof KobalteTextField>): JSX.Element;
|
|
23
|
+
export type FormFieldProps = Omit<ComponentProps<'div'>, 'children' | 'ref'> & {
|
|
24
|
+
label: string;
|
|
25
|
+
hint?: string;
|
|
26
|
+
error?: string;
|
|
27
|
+
controlId?: string;
|
|
28
|
+
group?: boolean;
|
|
29
|
+
children: JSX.Element;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* FormField.
|
|
33
|
+
*
|
|
34
|
+
* A shared label, help and validation wrapper for any one shared control. Its
|
|
35
|
+
* context is consumed by Input, Textarea, NativeSelect, Checkbox, Switch,
|
|
36
|
+
* RadioGroup and ComboboxInput, so the actual focusable element receives the
|
|
37
|
+
* generated ID and description relationships. Set `group` when the label names
|
|
38
|
+
* a set of controls; the wrapper then uses fieldset and legend semantics.
|
|
18
39
|
*/
|
|
19
|
-
export declare function
|
|
20
|
-
export declare function FieldLabel(props: ComponentProps<typeof KobalteTextField.Label>):
|
|
21
|
-
export declare function FieldDescription(props: ComponentProps<typeof KobalteTextField.Description>):
|
|
22
|
-
export declare function FieldError(props: ComponentProps<typeof KobalteTextField.ErrorMessage>):
|
|
23
|
-
export declare function FieldInput(props: ComponentProps<typeof KobalteTextField.Input>):
|
|
24
|
-
export declare function FieldTextArea(props: ComponentProps<typeof KobalteTextField.TextArea>):
|
|
40
|
+
export declare function FormField(props: FormFieldProps): JSX.Element;
|
|
41
|
+
export declare function FieldLabel(props: ComponentProps<typeof KobalteTextField.Label>): JSX.Element;
|
|
42
|
+
export declare function FieldDescription(props: ComponentProps<typeof KobalteTextField.Description>): JSX.Element;
|
|
43
|
+
export declare function FieldError(props: ComponentProps<typeof KobalteTextField.ErrorMessage>): JSX.Element;
|
|
44
|
+
export declare function FieldInput(props: ComponentProps<typeof KobalteTextField.Input>): JSX.Element;
|
|
45
|
+
export declare function FieldTextArea(props: ComponentProps<typeof KobalteTextField.TextArea>): JSX.Element;
|
|
25
46
|
/**
|
|
26
47
|
* A labelled group of fields with a single legend, for a real `<fieldset>`.
|
|
27
48
|
* Grouping is what lets a screen reader announce "Shipping address, group"
|
|
28
49
|
* before reading the four fields inside it.
|
|
29
50
|
*/
|
|
30
|
-
export declare function FieldSet(props: ComponentProps<'fieldset'>):
|
|
51
|
+
export declare function FieldSet(props: ComponentProps<'fieldset'>): JSX.Element;
|
|
52
|
+
/** A visual stack for related controls that does not imply fieldset semantics. */
|
|
53
|
+
export declare function FieldGroup(props: ComponentProps<'div'>): JSX.Element;
|
|
31
54
|
export declare function FieldLegend(props: ComponentProps<'legend'> & {
|
|
32
55
|
variant?: 'legend' | 'label';
|
|
33
|
-
}):
|
|
56
|
+
}): JSX.Element;
|
|
34
57
|
/** A horizontal rule with a word in it, for "or continue with" separators. */
|
|
35
58
|
export declare function FieldSeparator(props: {
|
|
36
59
|
class?: string;
|
|
37
60
|
children?: ComponentProps<'span'>['children'];
|
|
38
|
-
}):
|
|
61
|
+
}): JSX.Element;
|
|
39
62
|
//# sourceMappingURL=field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/field/field.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"field.d.ts","sour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,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,eAGtD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,CAAC,QAAQ,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;CAAE,eAc7F;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAA;CAC9C,eAYA"}
|
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
import { cn } from "../../../lib/utils.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { FormFieldContext, createFormFieldContext } from "../../../lib/form-field.js";
|
|
3
|
+
import { Label } from "../label/label.js";
|
|
4
|
+
import { createComponent, insert, memo, mergeProps, setAttribute, spread, template } from "solid-js/web";
|
|
5
|
+
import { Show, createUniqueId, splitProps } from "solid-js";
|
|
4
6
|
import { TextField } from "@kobalte/core/text-field";
|
|
5
7
|
//#region src/components/ui/field/field.tsx
|
|
6
|
-
var _tmpl$ = /*#__PURE__*/ template(`<
|
|
7
|
-
var _tmpl$2 = /*#__PURE__*/ template(`<
|
|
8
|
-
var _tmpl$3 = /*#__PURE__*/ template(`<
|
|
9
|
-
var _tmpl$4 = /*#__PURE__*/ template(`<
|
|
8
|
+
var _tmpl$ = /*#__PURE__*/ template(`<p class="text-muted-foreground text-sm">`);
|
|
9
|
+
var _tmpl$2 = /*#__PURE__*/ template(`<p role=alert class="text-foreground text-sm">`);
|
|
10
|
+
var _tmpl$3 = /*#__PURE__*/ template(`<div>`);
|
|
11
|
+
var _tmpl$4 = /*#__PURE__*/ template(`<fieldset>`);
|
|
12
|
+
var _tmpl$5 = /*#__PURE__*/ template(`<div data-slot=field-group>`);
|
|
13
|
+
var _tmpl$6 = /*#__PURE__*/ template(`<legend>`);
|
|
14
|
+
var _tmpl$7 = /*#__PURE__*/ template(`<span class="text-muted-foreground text-2xs tracking-wide uppercase">`);
|
|
15
|
+
var _tmpl$8 = /*#__PURE__*/ template(`<div><span class="bg-border h-px flex-1"></span><span class="bg-border h-px flex-1">`);
|
|
10
16
|
/**
|
|
11
17
|
* Field.
|
|
12
18
|
*
|
|
13
19
|
* The wrapper that makes a form control describable and validatable: a label,
|
|
14
20
|
* a description, an error message, and the ARIA relationships between them.
|
|
15
21
|
*
|
|
22
|
+
* This Kobalte TextField composition is for its own `FieldLabel`, `FieldInput`
|
|
23
|
+
* and `FieldTextArea` parts. Use `FormField` to wire the standalone shared
|
|
24
|
+
* controls, including checkboxes, switches and comboboxes.
|
|
25
|
+
*
|
|
16
26
|
* It is built on Kobalte's TextField specifically so `aria-describedby`,
|
|
17
27
|
* `aria-invalid` and `aria-errormessage` are wired by construction. Those three
|
|
18
28
|
* attributes are the difference between "this field is required and empty" and
|
|
19
29
|
* a red border that only a sighted user can perceive — and they are also the
|
|
20
30
|
* first thing a hand-rolled form drops.
|
|
21
31
|
*
|
|
22
|
-
* `Field` owns the description and the error slot, so
|
|
23
|
-
*
|
|
24
|
-
* Compose it with any control: `Field` wraps, `Label`/`Input`/`Select` fill it.
|
|
32
|
+
* `Field` owns the description and the error slot, so its controls line up and
|
|
33
|
+
* its messages land in the same place regardless of which TextField part is used.
|
|
25
34
|
*/
|
|
26
35
|
function Field(props) {
|
|
27
36
|
const [local, rest] = splitProps(props, ["class"]);
|
|
@@ -29,6 +38,108 @@ function Field(props) {
|
|
|
29
38
|
return cn("flex flex-col gap-1.5", local.class);
|
|
30
39
|
} }, rest));
|
|
31
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* FormField.
|
|
43
|
+
*
|
|
44
|
+
* A shared label, help and validation wrapper for any one shared control. Its
|
|
45
|
+
* context is consumed by Input, Textarea, NativeSelect, Checkbox, Switch,
|
|
46
|
+
* RadioGroup and ComboboxInput, so the actual focusable element receives the
|
|
47
|
+
* generated ID and description relationships. Set `group` when the label names
|
|
48
|
+
* a set of controls; the wrapper then uses fieldset and legend semantics.
|
|
49
|
+
*/
|
|
50
|
+
function FormField(props) {
|
|
51
|
+
const [local, rest] = splitProps(props, [
|
|
52
|
+
"class",
|
|
53
|
+
"label",
|
|
54
|
+
"hint",
|
|
55
|
+
"error",
|
|
56
|
+
"controlId",
|
|
57
|
+
"group",
|
|
58
|
+
"children"
|
|
59
|
+
]);
|
|
60
|
+
const fieldId = createUniqueId();
|
|
61
|
+
const labelId = `${fieldId}-label`;
|
|
62
|
+
const descriptionId = `${fieldId}-description`;
|
|
63
|
+
const errorId = `${fieldId}-error`;
|
|
64
|
+
const field = createFormFieldContext({
|
|
65
|
+
controlId: local.controlId,
|
|
66
|
+
defaultControlId: fieldId,
|
|
67
|
+
labelId,
|
|
68
|
+
descriptionId,
|
|
69
|
+
errorId,
|
|
70
|
+
hint: () => local.hint,
|
|
71
|
+
error: () => local.error,
|
|
72
|
+
group: () => local.group ?? false
|
|
73
|
+
});
|
|
74
|
+
const help = () => [createComponent(Show, {
|
|
75
|
+
get when() {
|
|
76
|
+
return local.hint;
|
|
77
|
+
},
|
|
78
|
+
get children() {
|
|
79
|
+
var _el$ = _tmpl$();
|
|
80
|
+
setAttribute(_el$, "id", descriptionId);
|
|
81
|
+
insert(_el$, () => local.hint);
|
|
82
|
+
return _el$;
|
|
83
|
+
}
|
|
84
|
+
}), createComponent(Show, {
|
|
85
|
+
get when() {
|
|
86
|
+
return local.error;
|
|
87
|
+
},
|
|
88
|
+
get children() {
|
|
89
|
+
var _el$2 = _tmpl$2();
|
|
90
|
+
setAttribute(_el$2, "id", errorId);
|
|
91
|
+
insert(_el$2, () => local.error);
|
|
92
|
+
return _el$2;
|
|
93
|
+
}
|
|
94
|
+
})];
|
|
95
|
+
return createComponent(FormFieldContext.Provider, {
|
|
96
|
+
value: field,
|
|
97
|
+
get children() {
|
|
98
|
+
var _el$3 = _tmpl$3();
|
|
99
|
+
spread(_el$3, mergeProps({ get ["class"]() {
|
|
100
|
+
return cn("flex flex-col gap-1.5", local.class);
|
|
101
|
+
} }, rest), false, true);
|
|
102
|
+
insert(_el$3, (() => {
|
|
103
|
+
var _c$ = memo(() => !!local.group);
|
|
104
|
+
return () => _c$() ? createComponent(FieldSet, {
|
|
105
|
+
"class": "flex flex-col gap-1.5",
|
|
106
|
+
get ["aria-describedby"]() {
|
|
107
|
+
return field.describedBy();
|
|
108
|
+
},
|
|
109
|
+
get ["aria-invalid"]() {
|
|
110
|
+
return field.invalid() || void 0;
|
|
111
|
+
},
|
|
112
|
+
get children() {
|
|
113
|
+
return [
|
|
114
|
+
createComponent(FieldLegend, {
|
|
115
|
+
id: labelId,
|
|
116
|
+
variant: "label",
|
|
117
|
+
get children() {
|
|
118
|
+
return local.label;
|
|
119
|
+
}
|
|
120
|
+
}),
|
|
121
|
+
memo(() => local.children),
|
|
122
|
+
memo(() => help())
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
}) : [
|
|
126
|
+
createComponent(Label, {
|
|
127
|
+
id: labelId,
|
|
128
|
+
get ["for"]() {
|
|
129
|
+
return field.controlId();
|
|
130
|
+
},
|
|
131
|
+
get children() {
|
|
132
|
+
return local.label;
|
|
133
|
+
}
|
|
134
|
+
}),
|
|
135
|
+
memo(() => local.children),
|
|
136
|
+
memo(help)
|
|
137
|
+
];
|
|
138
|
+
})());
|
|
139
|
+
return _el$3;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
32
143
|
function FieldLabel(props) {
|
|
33
144
|
const [local, rest] = splitProps(props, ["class"]);
|
|
34
145
|
return createComponent(TextField.Label, mergeProps({ get ["class"]() {
|
|
@@ -67,45 +178,56 @@ function FieldTextArea(props) {
|
|
|
67
178
|
function FieldSet(props) {
|
|
68
179
|
const [local, rest] = splitProps(props, ["class"]);
|
|
69
180
|
return (() => {
|
|
70
|
-
var _el$ = _tmpl$();
|
|
71
|
-
spread(_el
|
|
181
|
+
var _el$4 = _tmpl$4();
|
|
182
|
+
spread(_el$4, mergeProps({ get ["class"]() {
|
|
183
|
+
return cn("flex flex-col gap-4", local.class);
|
|
184
|
+
} }, rest), false, false);
|
|
185
|
+
return _el$4;
|
|
186
|
+
})();
|
|
187
|
+
}
|
|
188
|
+
/** A visual stack for related controls that does not imply fieldset semantics. */
|
|
189
|
+
function FieldGroup(props) {
|
|
190
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
191
|
+
return (() => {
|
|
192
|
+
var _el$5 = _tmpl$5();
|
|
193
|
+
spread(_el$5, mergeProps({ get ["class"]() {
|
|
72
194
|
return cn("flex flex-col gap-4", local.class);
|
|
73
195
|
} }, rest), false, false);
|
|
74
|
-
return _el
|
|
196
|
+
return _el$5;
|
|
75
197
|
})();
|
|
76
198
|
}
|
|
77
199
|
function FieldLegend(props) {
|
|
78
200
|
const [local, rest] = splitProps(props, ["class", "variant"]);
|
|
79
201
|
return (() => {
|
|
80
|
-
var _el$
|
|
81
|
-
spread(_el$
|
|
202
|
+
var _el$6 = _tmpl$6();
|
|
203
|
+
spread(_el$6, mergeProps({ get ["class"]() {
|
|
82
204
|
return cn("mb-1", local.variant === "label" ? "text-sm font-medium" : "text-base font-semibold tracking-tight", local.class);
|
|
83
205
|
} }, rest), false, false);
|
|
84
|
-
return _el$
|
|
206
|
+
return _el$6;
|
|
85
207
|
})();
|
|
86
208
|
}
|
|
87
209
|
/** A horizontal rule with a word in it, for "or continue with" separators. */
|
|
88
210
|
function FieldSeparator(props) {
|
|
89
211
|
const [local, rest] = splitProps(props, ["class", "children"]);
|
|
90
212
|
return (() => {
|
|
91
|
-
var _el$
|
|
92
|
-
spread(_el$
|
|
213
|
+
var _el$7 = _tmpl$8(), _el$0 = _el$7.firstChild.nextSibling;
|
|
214
|
+
spread(_el$7, mergeProps({ get ["class"]() {
|
|
93
215
|
return cn("relative flex items-center gap-3 py-1", local.class);
|
|
94
216
|
} }, rest), false, true);
|
|
95
|
-
insert(_el$
|
|
217
|
+
insert(_el$7, createComponent(Show, {
|
|
96
218
|
get when() {
|
|
97
219
|
return local.children;
|
|
98
220
|
},
|
|
99
221
|
get children() {
|
|
100
|
-
var _el$
|
|
101
|
-
insert(_el$
|
|
102
|
-
return _el$
|
|
222
|
+
var _el$9 = _tmpl$7();
|
|
223
|
+
insert(_el$9, () => local.children);
|
|
224
|
+
return _el$9;
|
|
103
225
|
}
|
|
104
|
-
}), _el$
|
|
105
|
-
return _el$
|
|
226
|
+
}), _el$0);
|
|
227
|
+
return _el$7;
|
|
106
228
|
})();
|
|
107
229
|
}
|
|
108
230
|
//#endregion
|
|
109
|
-
export { Field, FieldDescription, FieldError, FieldInput, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTextArea };
|
|
231
|
+
export { Field, FieldDescription, FieldError, FieldGroup, FieldInput, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTextArea, FormField };
|
|
110
232
|
|
|
111
233
|
//# sourceMappingURL=field.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.js","names":["TextField","KobalteTextField","ComponentProps","Show","splitProps","cn","Field","props","local","rest","_$createComponent","_$mergeProps","class","FieldLabel","Label","FieldDescription","Description","FieldError","ErrorMessage","FieldInput","Input","FieldTextArea","TextArea","FieldSet","_el$","_tmpl$","_$spread","FieldLegend","variant","_el$2","_tmpl$2","FieldSeparator","children","_el$3","_tmpl$4","_el$4","firstChild","_el$6","nextSibling","_$insert","when","_el$5","_tmpl$3","_$createComponent","KobalteTextField","_$mergeProps"],"sources":["../../../../src/components/ui/field/field.tsx"],"sourcesContent":["import { TextField as KobalteTextField } from '@kobalte/core/text-field'\nimport type { ComponentProps } from 'solid-js'\nimport { Show, splitProps } from 'solid-js'\nimport { cn } from '#lib/utils'\n\n/**\n * Field.\n *\n * The wrapper that makes a form control describable and validatable: a label,\n * a description, an error message, and the ARIA relationships between them.\n *\n * It is built on Kobalte's TextField specifically so `aria-describedby`,\n * `aria-invalid` and `aria-errormessage` are wired by construction. Those three\n * attributes are the difference between \"this field is required and empty\" and\n * a red border that only a sighted user can perceive — and they are also the\n * first thing a hand-rolled form drops.\n *\n * `Field` owns the description and the error slot, so a form's controls line up\n * and its messages land in the same place regardless of which control is used.\n * Compose it with any control: `Field` wraps, `Label`/`Input`/`Select` fill it.\n */\nexport function Field(props: ComponentProps<typeof KobalteTextField>) {\n const [local, rest] = splitProps(props, ['class'])\n return <KobalteTextField class={cn('flex flex-col gap-1.5', local.class)} {...rest} />\n}\n\nexport function FieldLabel(props: ComponentProps<typeof KobalteTextField.Label>) {\n const [local, rest] = splitProps(props, ['class'])\n return (\n <KobalteTextField.Label class={cn('text-sm leading-none font-medium', local.class)} {...rest} />\n )\n}\n\nexport function FieldDescription(props: ComponentProps<typeof KobalteTextField.Description>) {\n const [local, rest] = splitProps(props, ['class'])\n return (\n <KobalteTextField.Description\n class={cn('text-muted-foreground text-sm', local.class)}\n {...rest}\n />\n )\n}\n\nexport function FieldError(props: ComponentProps<typeof KobalteTextField.ErrorMessage>) {\n const [local, rest] = splitProps(props, ['class'])\n return (\n <KobalteTextField.ErrorMessage class={cn('text-foreground text-sm', local.class)} {...rest} />\n )\n}\n\nexport function FieldInput(props: ComponentProps<typeof KobalteTextField.Input>) {\n const [local, rest] = splitProps(props, ['class'])\n\n return (\n <KobalteTextField.Input\n class={cn(\n 'h-control-md w-full min-w-0 rounded-md border border-input bg-transparent px-control-md py-1 text-sm',\n 'transition-[color,box-shadow,border-color] ease-out outline-none',\n 'placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground',\n 'focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-primary-subtle',\n 'aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive-subtle',\n 'disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',\n local.class\n )}\n {...rest}\n />\n )\n}\n\nexport function FieldTextArea(props: ComponentProps<typeof KobalteTextField.TextArea>) {\n const [local, rest] = splitProps(props, ['class'])\n\n return (\n <KobalteTextField.TextArea\n class={cn(\n 'flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-control-md py-2 text-sm',\n 'transition-[color,box-shadow,border-color] ease-out outline-none resize-y',\n 'placeholder:text-muted-foreground',\n 'focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-primary-subtle',\n 'aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive-subtle',\n 'disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',\n local.class\n )}\n {...rest}\n />\n )\n}\n\n/**\n * A labelled group of fields with a single legend, for a real `<fieldset>`.\n * Grouping is what lets a screen reader announce \"Shipping address, group\"\n * before reading the four fields inside it.\n */\nexport function FieldSet(props: ComponentProps<'fieldset'>) {\n const [local, rest] = splitProps(props, ['class'])\n return <fieldset class={cn('flex flex-col gap-4', local.class)} {...rest} />\n}\n\nexport function FieldLegend(props: ComponentProps<'legend'> & { variant?: 'legend' | 'label' }) {\n const [local, rest] = splitProps(props, ['class', 'variant'])\n return (\n <legend\n class={cn(\n 'mb-1',\n local.variant === 'label'\n ? 'text-sm font-medium'\n : 'text-base font-semibold tracking-tight',\n local.class\n )}\n {...rest}\n />\n )\n}\n\n/** A horizontal rule with a word in it, for \"or continue with\" separators. */\nexport function FieldSeparator(props: {\n class?: string\n children?: ComponentProps<'span'>['children']\n}) {\n const [local, rest] = splitProps(props, ['class', 'children'])\n\n return (\n <div class={cn('relative flex items-center gap-3 py-1', local.class)} {...rest}>\n <span class=\"bg-border h-px flex-1\" />\n <Show when={local.children}>\n <span class=\"text-muted-foreground text-2xs tracking-wide uppercase\">{local.children}</span>\n </Show>\n <span class=\"bg-border h-px flex-1\" />\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgBM,MAAMC,OAAgD;CACpE,MAAM,CAACC,OAAOC,QAAQL,WAAWG,OAAO,CAAC,OAAO,CAAC;CACjD,OAAAG,gBAAQT,WAAgB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OAAAS;GAAA;EAAA,CAAA,GAAAJ,KAAA;EAAA,OAAAJ;CAAA,EAAA,CAAA;AAK5F"}
|
|
1
|
+
{"version":3,"file":"field.js","names":["TextField","KobalteTextField","ComponentProps","JSX","createUniqueId","Show","splitProps","Label","createFormFieldContext","FormFieldContext","cn","Field","props","local","rest","_$createComponent","_$mergeProps","class","FormFieldProps","Omit","label","hint","error","controlId","group","children","Element","FormField","fieldId","labelId","descriptionId","errorId","field","defaultControlId","help","when","_el$","_tmpl$","_$setAttribute","_$insert","_el$2","_tmpl$2","Provider","value","_el$3","_tmpl$3","_$spread","_c$","_$memo","FieldSet","aria-describedby","describedBy","aria-invalid","invalid","undefined","FieldLegend","id","variant","for","FieldLabel","FieldDescription","Description","FieldError","ErrorMessage","FieldInput","Input","FieldTextArea","TextArea","_el$4","_tmpl$4","FieldGroup","_el$5","_tmpl$5","_el$6","_tmpl$6","FieldSeparator","_el$7","_tmpl$8","_el$8","firstChild","_el$0","nextSibling","_el$9","_tmpl$7","_$createComponent","KobalteTextField","_$mergeProps","_$memo"],"sources":["../../../../src/components/ui/field/field.tsx"],"sourcesContent":["import { TextField as KobalteTextField } from '@kobalte/core/text-field'\nimport type { ComponentProps, JSX } from 'solid-js'\nimport { createUniqueId, Show, splitProps } from 'solid-js'\nimport { Label } from '../label/label'\nimport { createFormFieldContext, FormFieldContext } from '#lib/form-field'\nimport { cn } from '#lib/utils'\n\n/**\n * Field.\n *\n * The wrapper that makes a form control describable and validatable: a label,\n * a description, an error message, and the ARIA relationships between them.\n *\n * This Kobalte TextField composition is for its own `FieldLabel`, `FieldInput`\n * and `FieldTextArea` parts. Use `FormField` to wire the standalone shared\n * controls, including checkboxes, switches and comboboxes.\n *\n * It is built on Kobalte's TextField specifically so `aria-describedby`,\n * `aria-invalid` and `aria-errormessage` are wired by construction. Those three\n * attributes are the difference between \"this field is required and empty\" and\n * a red border that only a sighted user can perceive — and they are also the\n * first thing a hand-rolled form drops.\n *\n * `Field` owns the description and the error slot, so its controls line up and\n * its messages land in the same place regardless of which TextField part is used.\n */\nexport function Field(props: ComponentProps<typeof KobalteTextField>) {\n const [local, rest] = splitProps(props, ['class'])\n return <KobalteTextField class={cn('flex flex-col gap-1.5', local.class)} {...rest} />\n}\n\nexport type FormFieldProps = Omit<ComponentProps<'div'>, 'children' | 'ref'> & {\n label: string\n hint?: string\n error?: string\n controlId?: string\n group?: boolean\n children: JSX.Element\n}\n\n/**\n * FormField.\n *\n * A shared label, help and validation wrapper for any one shared control. Its\n * context is consumed by Input, Textarea, NativeSelect, Checkbox, Switch,\n * RadioGroup and ComboboxInput, so the actual focusable element receives the\n * generated ID and description relationships. Set `group` when the label names\n * a set of controls; the wrapper then uses fieldset and legend semantics.\n */\nexport function FormField(props: FormFieldProps) {\n const [local, rest] = splitProps(props, [\n 'class',\n 'label',\n 'hint',\n 'error',\n 'controlId',\n 'group',\n 'children',\n ])\n const fieldId = createUniqueId()\n const labelId = `${fieldId}-label`\n const descriptionId = `${fieldId}-description`\n const errorId = `${fieldId}-error`\n const field = createFormFieldContext({\n controlId: local.controlId,\n defaultControlId: fieldId,\n labelId,\n descriptionId,\n errorId,\n hint: () => local.hint,\n error: () => local.error,\n group: () => local.group ?? false,\n })\n const help = () => (\n <>\n <Show when={local.hint}>\n <p id={descriptionId} class=\"text-muted-foreground text-sm\">\n {local.hint}\n </p>\n </Show>\n <Show when={local.error}>\n <p id={errorId} role=\"alert\" class=\"text-foreground text-sm\">\n {local.error}\n </p>\n </Show>\n </>\n )\n\n return (\n <FormFieldContext.Provider value={field}>\n <div class={cn('flex flex-col gap-1.5', local.class)} {...rest}>\n {local.group ? (\n <FieldSet\n class=\"flex flex-col gap-1.5\"\n aria-describedby={field.describedBy()}\n aria-invalid={field.invalid() || undefined}\n >\n <FieldLegend id={labelId} variant=\"label\">\n {local.label}\n </FieldLegend>\n {local.children}\n {help()}\n </FieldSet>\n ) : (\n <>\n <Label id={labelId} for={field.controlId()}>\n {local.label}\n </Label>\n {local.children}\n {help()}\n </>\n )}\n </div>\n </FormFieldContext.Provider>\n )\n}\n\nexport function FieldLabel(props: ComponentProps<typeof KobalteTextField.Label>) {\n const [local, rest] = splitProps(props, ['class'])\n return (\n <KobalteTextField.Label class={cn('text-sm leading-none font-medium', local.class)} {...rest} />\n )\n}\n\nexport function FieldDescription(props: ComponentProps<typeof KobalteTextField.Description>) {\n const [local, rest] = splitProps(props, ['class'])\n return (\n <KobalteTextField.Description\n class={cn('text-muted-foreground text-sm', local.class)}\n {...rest}\n />\n )\n}\n\nexport function FieldError(props: ComponentProps<typeof KobalteTextField.ErrorMessage>) {\n const [local, rest] = splitProps(props, ['class'])\n return (\n <KobalteTextField.ErrorMessage class={cn('text-foreground text-sm', local.class)} {...rest} />\n )\n}\n\nexport function FieldInput(props: ComponentProps<typeof KobalteTextField.Input>) {\n const [local, rest] = splitProps(props, ['class'])\n\n return (\n <KobalteTextField.Input\n class={cn(\n 'h-control-md w-full min-w-0 rounded-md border border-input bg-transparent px-control-md py-1 text-sm',\n 'transition-[color,box-shadow,border-color] ease-out outline-none',\n 'placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground',\n 'focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-primary-subtle',\n 'aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive-subtle',\n 'disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',\n local.class\n )}\n {...rest}\n />\n )\n}\n\nexport function FieldTextArea(props: ComponentProps<typeof KobalteTextField.TextArea>) {\n const [local, rest] = splitProps(props, ['class'])\n\n return (\n <KobalteTextField.TextArea\n class={cn(\n 'flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-control-md py-2 text-sm',\n 'transition-[color,box-shadow,border-color] ease-out outline-none resize-y',\n 'placeholder:text-muted-foreground',\n 'focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-primary-subtle',\n 'aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive-subtle',\n 'disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',\n local.class\n )}\n {...rest}\n />\n )\n}\n\n/**\n * A labelled group of fields with a single legend, for a real `<fieldset>`.\n * Grouping is what lets a screen reader announce \"Shipping address, group\"\n * before reading the four fields inside it.\n */\nexport function FieldSet(props: ComponentProps<'fieldset'>) {\n const [local, rest] = splitProps(props, ['class'])\n return <fieldset class={cn('flex flex-col gap-4', local.class)} {...rest} />\n}\n\n/** A visual stack for related controls that does not imply fieldset semantics. */\nexport function FieldGroup(props: ComponentProps<'div'>) {\n const [local, rest] = splitProps(props, ['class'])\n return <div data-slot=\"field-group\" class={cn('flex flex-col gap-4', local.class)} {...rest} />\n}\n\nexport function FieldLegend(props: ComponentProps<'legend'> & { variant?: 'legend' | 'label' }) {\n const [local, rest] = splitProps(props, ['class', 'variant'])\n return (\n <legend\n class={cn(\n 'mb-1',\n local.variant === 'label'\n ? 'text-sm font-medium'\n : 'text-base font-semibold tracking-tight',\n local.class\n )}\n {...rest}\n />\n )\n}\n\n/** A horizontal rule with a word in it, for \"or continue with\" separators. */\nexport function FieldSeparator(props: {\n class?: string\n children?: ComponentProps<'span'>['children']\n}) {\n const [local, rest] = splitProps(props, ['class', 'children'])\n\n return (\n <div class={cn('relative flex items-center gap-3 py-1', local.class)} {...rest}>\n <span class=\"bg-border h-px flex-1\" />\n <Show when={local.children}>\n <span class=\"text-muted-foreground text-2xs tracking-wide uppercase\">{local.children}</span>\n </Show>\n <span class=\"bg-border h-px flex-1\" />\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgBW,MAAMC,OAAgD;CACpE,MAAM,CAACC,OAAOC,QAAQR,WAAWM,OAAO,CAAC,OAAO,CAAC;CACjD,OAAAG,gBAAQd,WAAgBe,WAAA,EAAA,KAAA,WAAA;EAAA,OAAQN,GAAG,yBAAyBG,MAAMI,KAAK;CAAC,EAAA,GAAMH,IAAI,CAAA;AACpF;;;;;;;;;;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;EAAA,OAAAyD;CAAA,EAAA,CAAA;AAC7F;AAEA,SAAgBhB,YAAY3C,OAAoE;CAC9F,MAAM,CAACC,OAAOC,QAAQR,WAAWM,OAAO,CAAC,SAAS,SAAS,CAAC;CAC5D,cAAA;EAAA,IAAA6D,QAAAC,QAAA;EAAA5B,OAAA2B,OAAAzD,WAAA,EAAA,KAAA,WAAA;GAAA,OAEWN,GACL,QACAG,MAAM4C,YAAY,UACd,wBACA,0CACJ5C,MAAMI,KACR;EAAC,EAAA,GACGH,IAAI,GAAA,OAAA,KAAA;EAAA,OAAA2D;CAAA,EAAA,CAAA;AAGd;;AAGA,SAAgBE,eAAe/D,OAG5B;CACD,MAAM,CAACC,OAAOC,QAAQR,WAAWM,OAAO,CAAC,SAAS,UAAU,CAAC;CAE7D,cAAA;EAAA,IAAAgE,QAAAC,QAAA,GAAAG,QAAAJ,MAAAG,WAAAE;EAAAnC,OAAA8B,OAAA5D,WAAA,EAAA,KAAA,WAAA;GAAA,OACcN,GAAG,yCAAyCG,MAAMI,KAAK;EAAC,EAAA,GAAMH,IAAI,GAAA,OAAA,IAAA;EAAAyB,OAAAqC,OAAA7D,gBAE3EV,MAAI;GAAA,IAAC8B,OAAI;IAAA,OAAEtB,MAAMY;GAAQ;GAAA,IAAAA,WAAA;IAAA,IAAAyD,QAAAC,QAAA;IAAA5C,OAAA2C,aAC8CrE,MAAMY,QAAQ;IAAA,OAAAyD;GAAA;EAAA,CAAA,GAAAF,KAAA;EAAA,OAAAJ;CAAA,EAAA,CAAA;AAK5F"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { Field, FieldDescription, FieldError, FieldInput, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTextArea, } from './field';
|
|
1
|
+
export { Field, FormField, FieldDescription, FieldError, FieldGroup, FieldInput, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTextArea, type FormFieldProps, } from './field';
|
|
2
|
+
export { NumberField } from './number-field';
|
|
3
|
+
export type { NumberFieldProps } from './number-field';
|
|
2
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/field/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,cAAc,EACd,QAAQ,EACR,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/field/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,cAAc,EACd,QAAQ,EACR,aAAa,EACb,KAAK,cAAc,GACpB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { Field, FieldDescription, FieldError, FieldInput, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTextArea } from "./field.js";
|
|
2
|
-
|
|
1
|
+
import { Field, FieldDescription, FieldError, FieldGroup, FieldInput, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTextArea, FormField } from "./field.js";
|
|
2
|
+
import { NumberField } from "./number-field.js";
|
|
3
|
+
export { Field, FieldDescription, FieldError, FieldGroup, FieldInput, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTextArea, FormField, NumberField };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type JSX } from 'solid-js';
|
|
2
|
+
export type NumberFieldProps = {
|
|
3
|
+
label: string;
|
|
4
|
+
hint?: string;
|
|
5
|
+
value: number;
|
|
6
|
+
min: number;
|
|
7
|
+
max: number;
|
|
8
|
+
integer?: boolean;
|
|
9
|
+
onChange: (value: number) => void;
|
|
10
|
+
class?: string;
|
|
11
|
+
onBlur?: JSX.EventHandler<HTMLInputElement, FocusEvent>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A controlled numeric field that keeps an editable draft while validating
|
|
15
|
+
* range and integer constraints. Invalid drafts are announced and restored
|
|
16
|
+
* to the latest controlled value when focus leaves the input.
|
|
17
|
+
*/
|
|
18
|
+
export declare function NumberField(props: NumberFieldProps): JSX.Element;
|
|
19
|
+
//# sourceMappingURL=number-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-field.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/field/number-field.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,GAAG,EAAE,MAAM,UAAU,CAAA;AAI/D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,GAAG,CAAC,YAAY,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAA;CACxD,CAAA;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,eAiDlD"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { FormField } from "./field.js";
|
|
2
|
+
import { Input } from "../input/input.js";
|
|
3
|
+
import { createComponent } from "solid-js/web";
|
|
4
|
+
import { createEffect, createSignal } from "solid-js";
|
|
5
|
+
//#region src/components/ui/field/number-field.tsx
|
|
6
|
+
/**
|
|
7
|
+
* A controlled numeric field that keeps an editable draft while validating
|
|
8
|
+
* range and integer constraints. Invalid drafts are announced and restored
|
|
9
|
+
* to the latest controlled value when focus leaves the input.
|
|
10
|
+
*/
|
|
11
|
+
function NumberField(props) {
|
|
12
|
+
const [draft, setDraft] = createSignal(String(props.value));
|
|
13
|
+
const [error, setError] = createSignal("");
|
|
14
|
+
const integer = () => props.integer ?? true;
|
|
15
|
+
createEffect(() => {
|
|
16
|
+
setDraft(String(props.value));
|
|
17
|
+
});
|
|
18
|
+
const validate = (raw) => {
|
|
19
|
+
if (!raw) return `${props.label} is required.`;
|
|
20
|
+
const next = Number(raw);
|
|
21
|
+
if (!Number.isFinite(next)) return `${props.label} must be a valid number.`;
|
|
22
|
+
if (integer() && !Number.isInteger(next)) return `${props.label} must be a whole number.`;
|
|
23
|
+
if (next < props.min || next > props.max) return `${props.label} must be between ${props.min} and ${props.max}.`;
|
|
24
|
+
return "";
|
|
25
|
+
};
|
|
26
|
+
return createComponent(FormField, {
|
|
27
|
+
get label() {
|
|
28
|
+
return props.label;
|
|
29
|
+
},
|
|
30
|
+
get hint() {
|
|
31
|
+
return props.hint;
|
|
32
|
+
},
|
|
33
|
+
get error() {
|
|
34
|
+
return error();
|
|
35
|
+
},
|
|
36
|
+
get ["class"]() {
|
|
37
|
+
return props.class;
|
|
38
|
+
},
|
|
39
|
+
get children() {
|
|
40
|
+
return createComponent(Input, {
|
|
41
|
+
type: "number",
|
|
42
|
+
get value() {
|
|
43
|
+
return draft();
|
|
44
|
+
},
|
|
45
|
+
get min() {
|
|
46
|
+
return props.min;
|
|
47
|
+
},
|
|
48
|
+
get max() {
|
|
49
|
+
return props.max;
|
|
50
|
+
},
|
|
51
|
+
get step() {
|
|
52
|
+
return integer() ? 1 : "any";
|
|
53
|
+
},
|
|
54
|
+
required: true,
|
|
55
|
+
onInput: (event) => {
|
|
56
|
+
const raw = event.currentTarget.value;
|
|
57
|
+
setDraft(raw);
|
|
58
|
+
const nextError = validate(raw);
|
|
59
|
+
setError(nextError);
|
|
60
|
+
if (!nextError) props.onChange(Number(raw));
|
|
61
|
+
},
|
|
62
|
+
onBlur: (event) => {
|
|
63
|
+
if (validate(draft())) {
|
|
64
|
+
setDraft(String(props.value));
|
|
65
|
+
setError("");
|
|
66
|
+
}
|
|
67
|
+
props.onBlur?.(event);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { NumberField };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=number-field.js.map
|