@grafctory/clay-widgets 0.0.0-stage → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +46 -2
- package/dist/content/empty.css +107 -0
- package/dist/content/empty.d.ts +40 -0
- package/dist/content/empty.d.ts.map +1 -0
- package/dist/content/empty.js +42 -0
- package/dist/content/empty.js.map +1 -0
- package/dist/content/heading.css +34 -0
- package/dist/content/heading.d.ts +45 -0
- package/dist/content/heading.d.ts.map +1 -0
- package/dist/content/heading.js +49 -0
- package/dist/content/heading.js.map +1 -0
- package/dist/content/image.css +176 -0
- package/dist/content/image.d.ts +71 -0
- package/dist/content/image.d.ts.map +1 -0
- package/dist/content/image.js +63 -0
- package/dist/content/image.js.map +1 -0
- package/dist/content/infobox.css +186 -0
- package/dist/content/infobox.d.ts +72 -0
- package/dist/content/infobox.d.ts.map +1 -0
- package/dist/content/infobox.js +63 -0
- package/dist/content/infobox.js.map +1 -0
- package/dist/content/pill.css +76 -0
- package/dist/content/pill.d.ts +57 -0
- package/dist/content/pill.d.ts.map +1 -0
- package/dist/content/pill.js +48 -0
- package/dist/content/pill.js.map +1 -0
- package/dist/content/text.css +44 -0
- package/dist/content/text.d.ts +30 -0
- package/dist/content/text.d.ts.map +1 -0
- package/dist/content/text.js +42 -0
- package/dist/content/text.js.map +1 -0
- package/dist/controls/button.css +469 -0
- package/dist/controls/button.d.ts +116 -0
- package/dist/controls/button.d.ts.map +1 -0
- package/dist/controls/button.js +61 -0
- package/dist/controls/button.js.map +1 -0
- package/dist/controls/checkbox.css +23 -0
- package/dist/controls/checkbox.d.ts +54 -0
- package/dist/controls/checkbox.d.ts.map +1 -0
- package/dist/controls/checkbox.js +49 -0
- package/dist/controls/checkbox.js.map +1 -0
- package/dist/controls/choice.css +288 -0
- package/dist/controls/choice.d.ts +63 -0
- package/dist/controls/choice.d.ts.map +1 -0
- package/dist/controls/choice.js +52 -0
- package/dist/controls/choice.js.map +1 -0
- package/dist/controls/fieldset.css +37 -0
- package/dist/controls/fieldset.d.ts +49 -0
- package/dist/controls/fieldset.d.ts.map +1 -0
- package/dist/controls/fieldset.js +51 -0
- package/dist/controls/fieldset.js.map +1 -0
- package/dist/controls/form.css +50 -0
- package/dist/controls/form.d.ts +64 -0
- package/dist/controls/form.d.ts.map +1 -0
- package/dist/controls/form.js +62 -0
- package/dist/controls/form.js.map +1 -0
- package/dist/controls/input.css +57 -0
- package/dist/controls/input.d.ts +120 -0
- package/dist/controls/input.d.ts.map +1 -0
- package/dist/controls/input.js +78 -0
- package/dist/controls/input.js.map +1 -0
- package/dist/controls/label.css +73 -0
- package/dist/controls/label.d.ts +76 -0
- package/dist/controls/label.d.ts.map +1 -0
- package/dist/controls/label.js +73 -0
- package/dist/controls/label.js.map +1 -0
- package/dist/controls/radio.css +23 -0
- package/dist/controls/radio.d.ts +60 -0
- package/dist/controls/radio.d.ts.map +1 -0
- package/dist/controls/radio.js +50 -0
- package/dist/controls/radio.js.map +1 -0
- package/dist/controls/select.css +37 -0
- package/dist/controls/select.d.ts +62 -0
- package/dist/controls/select.d.ts.map +1 -0
- package/dist/controls/select.js +59 -0
- package/dist/controls/select.js.map +1 -0
- package/dist/controls/switch.css +154 -0
- package/dist/controls/switch.d.ts +44 -0
- package/dist/controls/switch.d.ts.map +1 -0
- package/dist/controls/switch.js +48 -0
- package/dist/controls/switch.js.map +1 -0
- package/dist/controls/textarea.css +50 -0
- package/dist/controls/textarea.d.ts +97 -0
- package/dist/controls/textarea.d.ts.map +1 -0
- package/dist/controls/textarea.js +75 -0
- package/dist/controls/textarea.js.map +1 -0
- package/dist/glyphs/icon.core.d.ts +52 -0
- package/dist/glyphs/icon.core.d.ts.map +1 -0
- package/dist/glyphs/icon.core.js +67 -0
- package/dist/glyphs/icon.core.js.map +1 -0
- package/dist/glyphs/icon.css +32 -0
- package/dist/glyphs/icon.d.ts +152 -0
- package/dist/glyphs/icon.d.ts.map +1 -0
- package/dist/glyphs/icon.js +167 -0
- package/dist/glyphs/icon.js.map +1 -0
- package/dist/glyphs/icon.md +76 -0
- package/dist/glyphs/logo.css +73 -0
- package/dist/glyphs/logo.d.ts +27 -0
- package/dist/glyphs/logo.d.ts.map +1 -0
- package/dist/glyphs/logo.js +49 -0
- package/dist/glyphs/logo.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/layouts/card.css +166 -0
- package/dist/layouts/card.d.ts +69 -0
- package/dist/layouts/card.d.ts.map +1 -0
- package/dist/layouts/card.js +57 -0
- package/dist/layouts/card.js.map +1 -0
- package/dist/layouts/stack.css +58 -0
- package/dist/layouts/stack.d.ts +64 -0
- package/dist/layouts/stack.d.ts.map +1 -0
- package/dist/layouts/stack.js +69 -0
- package/dist/layouts/stack.js.map +1 -0
- package/dist/layouts/strip.css +58 -0
- package/dist/layouts/strip.d.ts +72 -0
- package/dist/layouts/strip.d.ts.map +1 -0
- package/dist/layouts/strip.js +73 -0
- package/dist/layouts/strip.js.map +1 -0
- package/dist/layouts/tabs.core.d.ts +73 -0
- package/dist/layouts/tabs.core.d.ts.map +1 -0
- package/dist/layouts/tabs.core.js +65 -0
- package/dist/layouts/tabs.core.js.map +1 -0
- package/dist/layouts/tabs.css +260 -0
- package/dist/layouts/tabs.d.ts +57 -0
- package/dist/layouts/tabs.d.ts.map +1 -0
- package/dist/layouts/tabs.js +128 -0
- package/dist/layouts/tabs.js.map +1 -0
- package/dist/layouts/tree.css +138 -0
- package/dist/layouts/tree.d.ts +46 -0
- package/dist/layouts/tree.d.ts.map +1 -0
- package/dist/layouts/tree.js +69 -0
- package/dist/layouts/tree.js.map +1 -0
- package/dist/navigation/link.css +229 -0
- package/dist/navigation/link.d.ts +89 -0
- package/dist/navigation/link.d.ts.map +1 -0
- package/dist/navigation/link.js +91 -0
- package/dist/navigation/link.js.map +1 -0
- package/dist/navigation/path.css +122 -0
- package/dist/navigation/path.d.ts +42 -0
- package/dist/navigation/path.d.ts.map +1 -0
- package/dist/navigation/path.js +49 -0
- package/dist/navigation/path.js.map +1 -0
- package/dist/navigation/toc.core.d.ts +111 -0
- package/dist/navigation/toc.core.d.ts.map +1 -0
- package/dist/navigation/toc.core.js +60 -0
- package/dist/navigation/toc.core.js.map +1 -0
- package/dist/navigation/toc.css +53 -0
- package/dist/navigation/toc.d.ts +112 -0
- package/dist/navigation/toc.d.ts.map +1 -0
- package/dist/navigation/toc.js +321 -0
- package/dist/navigation/toc.js.map +1 -0
- package/dist/scopes/guard.css +26 -0
- package/dist/scopes/guard.d.ts +37 -0
- package/dist/scopes/guard.d.ts.map +1 -0
- package/dist/scopes/guard.js +60 -0
- package/dist/scopes/guard.js.map +1 -0
- package/dist/scopes/style.css +26 -0
- package/dist/scopes/style.d.ts +68 -0
- package/dist/scopes/style.d.ts.map +1 -0
- package/dist/scopes/style.js +108 -0
- package/dist/scopes/style.js.map +1 -0
- package/dist/shells/tool.css +778 -0
- package/dist/shells/tool.d.ts +164 -0
- package/dist/shells/tool.d.ts.map +1 -0
- package/dist/shells/tool.js +251 -0
- package/dist/shells/tool.js.map +1 -0
- package/dist/signals/more.css +42 -0
- package/dist/signals/more.d.ts +28 -0
- package/dist/signals/more.d.ts.map +1 -0
- package/dist/signals/more.js +61 -0
- package/dist/signals/more.js.map +1 -0
- package/dist/signals/note.css +221 -0
- package/dist/signals/note.d.ts +83 -0
- package/dist/signals/note.d.ts.map +1 -0
- package/dist/signals/note.js +72 -0
- package/dist/signals/note.js.map +1 -0
- package/dist/signals/toasts.css +463 -0
- package/dist/signals/toasts.d.ts +68 -0
- package/dist/signals/toasts.d.ts.map +1 -0
- package/dist/signals/toasts.js +160 -0
- package/dist/signals/toasts.js.map +1 -0
- package/package.json +331 -4
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* A form draws nothing of its own: it stands in the flow as the block its fields are laid out in.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
clay-form {
|
|
22
|
+
|
|
23
|
+
display: block;
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* A growing form takes the room a column leaves, shared with whatever else the column holds. A container laying
|
|
27
|
+
* its content out as a page does shares no room, so a form standing alone in one fills its height instead, which
|
|
28
|
+
* the container makes definite where it is meant to be filled, as the main body of a tool does. The element and
|
|
29
|
+
* the native form inside it both lay the fields out as a column, so a growing field or stack takes the room next.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
&[grow] {
|
|
33
|
+
|
|
34
|
+
display: flex;
|
|
35
|
+
flex-direction: column;
|
|
36
|
+
flex: auto;
|
|
37
|
+
|
|
38
|
+
&:only-child {
|
|
39
|
+
min-block-size: 100%;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
& > form {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
flex: auto;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editing form.
|
|
3
|
+
*
|
|
4
|
+
* Gathers the fields a resource is read and edited through, telling the screen whether what was entered is valid as
|
|
5
|
+
* the reader types, and handing over the submission the `Enter` key asks for without letting the page navigate away.
|
|
6
|
+
*
|
|
7
|
+
* @module form
|
|
8
|
+
*/
|
|
9
|
+
import { type ComponentChildren } from "preact";
|
|
10
|
+
import "./form.css";
|
|
11
|
+
/**
|
|
12
|
+
* Creates a form.
|
|
13
|
+
*
|
|
14
|
+
* Wraps its fields in a native form, so the constraints each field states (`required`, `pattern`, `min`, `max` and the
|
|
15
|
+
* like) are checked by the platform, and pressing `Enter` in a field submits the form even where it shows no submit
|
|
16
|
+
* button. The browser never navigates on submission: whatever the submission means is left to `onSubmit`.
|
|
17
|
+
*
|
|
18
|
+
* A submit button placed inside the form does not reach `onSubmit`: the action it stands for belongs to its own
|
|
19
|
+
* `onClick`, leaving `onSubmit` with the submissions asked for from the keyboard alone.
|
|
20
|
+
*
|
|
21
|
+
* The form stands as tall as its fields unless told to grow. A growing form takes the room its container leaves and
|
|
22
|
+
* lays its fields out as a column, so a {@link stack!Stack Stack}, a {@link textarea!Textarea Textarea} or a
|
|
23
|
+
* {@link label!Label Label} told to grow inside it takes that room in turn: a single long text then fills the body of
|
|
24
|
+
* a screen, and runs on past it, lengthening the form rather than scrolling inside it.
|
|
25
|
+
*
|
|
26
|
+
* @param options The widget configuration
|
|
27
|
+
*
|
|
28
|
+
* @returns The form
|
|
29
|
+
*
|
|
30
|
+
* @see [MDN: Client-side form validation][validation]
|
|
31
|
+
*
|
|
32
|
+
* [validation]: https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation
|
|
33
|
+
*/
|
|
34
|
+
export declare function Form({ grow, onSubmit, onValidate, children }: {
|
|
35
|
+
/**
|
|
36
|
+
* Whether the form takes the room its container leaves; sized to its fields if omitted. In a column, such as a
|
|
37
|
+
* {@link stack!Stack Stack} or the side column of a {@link tool!Tool Tool}, the form shares that room with the
|
|
38
|
+
* other items of the column. In a container laying its content out as a page, such as the main column of a `Tool`,
|
|
39
|
+
* the form fills the room only when it stands alone, with no heading or note beside it in the same container.
|
|
40
|
+
*/
|
|
41
|
+
grow?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* What a submission asked for by pressing `Enter` in a field is handed to; submissions are ignored if omitted.
|
|
44
|
+
* Not called where a field fails its constraints, the platform reporting the failure to the reader instead.
|
|
45
|
+
*/
|
|
46
|
+
onSubmit?: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* What the validity of the form is handed to whenever the reader changes a field, as true where every field
|
|
49
|
+
* meets its constraints and false otherwise; validity goes untracked if omitted.
|
|
50
|
+
*
|
|
51
|
+
* A value set by a script signals nothing on its own, so a composite field setting values that way dispatches a
|
|
52
|
+
* bubbling `input` event from its own element to have the form checked against the new value.
|
|
53
|
+
*
|
|
54
|
+
* @param valid Whether every field in the form meets its constraints
|
|
55
|
+
*/
|
|
56
|
+
onValidate?: (valid: boolean) => void;
|
|
57
|
+
/**
|
|
58
|
+
* The fields of the form.
|
|
59
|
+
*/
|
|
60
|
+
children?: ComponentChildren;
|
|
61
|
+
}): import("preact").VNode<{
|
|
62
|
+
grow: boolean;
|
|
63
|
+
}>;
|
|
64
|
+
//# sourceMappingURL=form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/controls/form.tsx"],"names":[],"mappings":"AAgBA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,QAAQ,CAAC;AAC/D,OAAO,YAAY,CAAC;AAGpB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,IAAI,CAAC,EAEpB,IAAY,EAEZ,QAAQ,EACR,UAAU,EAEV,QAAQ,EAER,EAAE;IAEF;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAGd;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IAErB;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAGrC;;OAEG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAA;CAE5B;;GA6BA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright © 2026 Metreeca srl
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Editing form.
|
|
19
|
+
*
|
|
20
|
+
* Gathers the fields a resource is read and edited through, telling the screen whether what was entered is valid as
|
|
21
|
+
* the reader types, and handing over the submission the `Enter` key asks for without letting the page navigate away.
|
|
22
|
+
*
|
|
23
|
+
* @module form
|
|
24
|
+
*/
|
|
25
|
+
import { createElement } from "preact";
|
|
26
|
+
import "./form.css";
|
|
27
|
+
/**
|
|
28
|
+
* Creates a form.
|
|
29
|
+
*
|
|
30
|
+
* Wraps its fields in a native form, so the constraints each field states (`required`, `pattern`, `min`, `max` and the
|
|
31
|
+
* like) are checked by the platform, and pressing `Enter` in a field submits the form even where it shows no submit
|
|
32
|
+
* button. The browser never navigates on submission: whatever the submission means is left to `onSubmit`.
|
|
33
|
+
*
|
|
34
|
+
* A submit button placed inside the form does not reach `onSubmit`: the action it stands for belongs to its own
|
|
35
|
+
* `onClick`, leaving `onSubmit` with the submissions asked for from the keyboard alone.
|
|
36
|
+
*
|
|
37
|
+
* The form stands as tall as its fields unless told to grow. A growing form takes the room its container leaves and
|
|
38
|
+
* lays its fields out as a column, so a {@link stack!Stack Stack}, a {@link textarea!Textarea Textarea} or a
|
|
39
|
+
* {@link label!Label Label} told to grow inside it takes that room in turn: a single long text then fills the body of
|
|
40
|
+
* a screen, and runs on past it, lengthening the form rather than scrolling inside it.
|
|
41
|
+
*
|
|
42
|
+
* @param options The widget configuration
|
|
43
|
+
*
|
|
44
|
+
* @returns The form
|
|
45
|
+
*
|
|
46
|
+
* @see [MDN: Client-side form validation][validation]
|
|
47
|
+
*
|
|
48
|
+
* [validation]: https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation
|
|
49
|
+
*/
|
|
50
|
+
export function Form({ grow = false, onSubmit, onValidate, children }) {
|
|
51
|
+
/*
|
|
52
|
+
* The hidden submit input gives the form a default button, which pressing `Enter` in a field submits through even
|
|
53
|
+
* where the form holds several fields and shows the reader no submit button of its own.
|
|
54
|
+
*/
|
|
55
|
+
return createElement("clay-form", { grow }, _jsxs("form", { onInput: event => onValidate?.(event.currentTarget.checkValidity()), onSubmit: event => {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
if (!(event.submitter instanceof HTMLButtonElement)) {
|
|
58
|
+
onSubmit?.();
|
|
59
|
+
}
|
|
60
|
+
}, children: [_jsx("input", { type: "submit", hidden: true }), children] }));
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=form.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.js","sourceRoot":"","sources":["../../src/controls/form.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAA0B,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,YAAY,CAAC;AAGpB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,IAAI,CAAC,EAEpB,IAAI,GAAG,KAAK,EAEZ,QAAQ,EACR,UAAU,EAEV,QAAQ,EAoCR;IAEA;;;OAGG;IAEH,OAAO,aAAa,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,gBAE3C,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC,EAEnE,QAAQ,EAAE,KAAK,CAAC,EAAE;YAEjB,KAAK,CAAC,cAAc,EAAE,CAAC;YAEvB,IAAK,CAAC,CAAC,KAAK,CAAC,SAAS,YAAY,iBAAiB,CAAC,EAAG,CAAC;gBACvD,QAAQ,EAAE,EAAE,CAAC;YACd,CAAC;QAEF,CAAC,aAID,gBAAO,IAAI,EAAC,QAAQ,EAAC,MAAM,SAAE,EAE5B,QAAQ,IAEH,CAAC,CAAC;AAEV,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/* A field is drawn as the design system draws every native field, standing wherever the layout places it. */
|
|
18
|
+
|
|
19
|
+
clay-input {
|
|
20
|
+
|
|
21
|
+
display: contents;
|
|
22
|
+
|
|
23
|
+
/* A field sized in characters never stands wider than the column holding it, shrinking on a narrow viewport. */
|
|
24
|
+
|
|
25
|
+
& > input {
|
|
26
|
+
max-inline-size: 100%;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* A growing field, or one wrapped by a growing label, spans the column holding it, whatever width its characters
|
|
31
|
+
* ask for. In a row, a strip or a horizontal label beside its text, it takes the room the row leaves instead.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
&[grow] > input, clay-label[grow] > label > & > input {
|
|
35
|
+
align-self: stretch;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
clay-strip > &[grow] > input,
|
|
39
|
+
clay-label[orientation="horizontal"] > label > &[grow] > input,
|
|
40
|
+
clay-label[grow][orientation="horizontal"] > label > & > input {
|
|
41
|
+
flex: auto;
|
|
42
|
+
align-self: auto;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* An empty date or time field shows the pattern of its value where a text field shows its placeholder, so the
|
|
47
|
+
* pattern takes the placeholder colour, telling a field still to be filled from one holding a value. The field
|
|
48
|
+
* holding the keyboard takes the text colour back, since the parts the reader types land in the pattern itself.
|
|
49
|
+
*
|
|
50
|
+
* The types listed are kept in sync with the date and time types the `type` prop of the widget accepts.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
&[empty] > input:is([type=date], [type=time], [type=datetime-local], [type=month], [type=week]):not(:focus) {
|
|
54
|
+
color: var(--skin--color-placeholder);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import "./input.css";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a single-line field.
|
|
4
|
+
*
|
|
5
|
+
* Takes its value on a native input, so the editing keys, the on-screen keyboard suited to `type`, the date and time
|
|
6
|
+
* pickers, and the checking of every constraint come from the platform. A field failing a constraint is marked once
|
|
7
|
+
* the reader has had a say on it, and stops the {@link form!Form Form} around it from being submitted.
|
|
8
|
+
*
|
|
9
|
+
* The value is either held by the caller, which shows `value` and is handed each edit through `onChange`, or left to
|
|
10
|
+
* the field where `value` is omitted, the field then keeping whatever the reader types.
|
|
11
|
+
*
|
|
12
|
+
* @param options The widget configuration
|
|
13
|
+
*
|
|
14
|
+
* @returns The field
|
|
15
|
+
*
|
|
16
|
+
* @see [HTML: The input element][input]
|
|
17
|
+
*
|
|
18
|
+
* [input]: https://html.spec.whatwg.org/multipage/input.html#the-input-element
|
|
19
|
+
*/
|
|
20
|
+
export declare function Input({ name, id, description, disabled, readonly, required, type, min, max, step, minLength, maxLength, pattern, error, grow, size, placeholder, value, onChange }: {
|
|
21
|
+
/**
|
|
22
|
+
* The accessible name, required where no {@link label!Label Label} names the field.
|
|
23
|
+
*/
|
|
24
|
+
name?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The id a split {@link label!Label Label} names the field by; no id if omitted.
|
|
27
|
+
*/
|
|
28
|
+
id?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The id of the element describing the field, such as a hint on the value expected, which assistive technology
|
|
31
|
+
* reads out along with the accessible name whenever the field takes focus; none if omitted. The id has to resolve
|
|
32
|
+
* to a rendered element, or the field is described by nothing at all and the hint reaches sighted readers only.
|
|
33
|
+
*/
|
|
34
|
+
description?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Whether the field takes no input, greyed and out of the tab order; editable if omitted.
|
|
37
|
+
*/
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the field shows its value without taking edits, while staying in the tab order; editable if omitted.
|
|
41
|
+
*/
|
|
42
|
+
readonly?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the field fails its constraints while empty; optional if omitted.
|
|
45
|
+
*/
|
|
46
|
+
required?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The kind of value the field takes, deciding the constraints checked on it and the keyboard or picker offered to
|
|
49
|
+
* type it with; `text` if omitted. Whatever the kind, the value is handed over as the text the field holds, as
|
|
50
|
+
* the platform writes it in every locale: a `date` as `YYYY-MM-DD`, a `time` as `hh:mm`, a `datetime-local` as
|
|
51
|
+
* `YYYY-MM-DDThh:mm`, a `month` as `YYYY-MM` and a `week` as `YYYY-Www`, with the week number in two digits.
|
|
52
|
+
*/
|
|
53
|
+
type?: "text" | "email" | "url" | "tel" | "password" | "number" | "date" | "time" | "datetime-local" | "month" | "week";
|
|
54
|
+
/**
|
|
55
|
+
* The least value a `number` field or a date or time field accepts, written as its values are; none if omitted.
|
|
56
|
+
*/
|
|
57
|
+
min?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The greatest value a `number` field or a date or time field accepts, written as its values are; none if omitted.
|
|
60
|
+
*/
|
|
61
|
+
max?: string;
|
|
62
|
+
/**
|
|
63
|
+
* The granularity of the values a `number` field or a date or time field accepts, such as `0.01` for a price or
|
|
64
|
+
* `60` seconds for a time stated to the minute; the platform default for the type if omitted.
|
|
65
|
+
*/
|
|
66
|
+
step?: string;
|
|
67
|
+
/**
|
|
68
|
+
* The least number of characters a non-empty value holds; no floor if omitted.
|
|
69
|
+
*/
|
|
70
|
+
minLength?: number;
|
|
71
|
+
/**
|
|
72
|
+
* The greatest number of characters the field takes, typing past it being refused; no ceiling if omitted.
|
|
73
|
+
*/
|
|
74
|
+
maxLength?: number;
|
|
75
|
+
/**
|
|
76
|
+
* The regular expression the whole value has to match, read as the platform reads it; any value if omitted.
|
|
77
|
+
*/
|
|
78
|
+
pattern?: string;
|
|
79
|
+
/**
|
|
80
|
+
* The message reported while the field fails its constraints, stating the rule a valid value follows, such as
|
|
81
|
+
* `Enter an address at a partner university` for an address restricted by `pattern`; the platform message if
|
|
82
|
+
* omitted. It takes the place of the platform message wherever the platform shows one, and never changes whether
|
|
83
|
+
* the field or the {@link form!Form Form} around it is valid, which the constraints alone decide.
|
|
84
|
+
*/
|
|
85
|
+
error?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Whether the field spans the column holding it, or the room left on its line in a {@link strip!Strip Strip};
|
|
88
|
+
* sized to `size` characters if omitted. A growing field of any type takes that whole room, so a long value such as
|
|
89
|
+
* an address stays in view. A field wrapped in a {@link label!Label Label} is bounded by the room the label takes
|
|
90
|
+
* instead, so spanning the column, or the room beside the label text, takes a label told to grow.
|
|
91
|
+
*/
|
|
92
|
+
grow?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* The width the field stands at, in characters, never wider than the column holding it; a `number` field or a
|
|
95
|
+
* date or time field ignores it, as does a growing field. The platform width, about 20 characters, if omitted.
|
|
96
|
+
*/
|
|
97
|
+
size?: number;
|
|
98
|
+
/**
|
|
99
|
+
* The hint shown in the field while it is empty, such as an example of the value expected. It disappears as soon
|
|
100
|
+
* as the reader types, so it never stands in for a {@link label!Label Label}; no hint if omitted.
|
|
101
|
+
*
|
|
102
|
+
* A date or time field shows no hint: the platform fills it with the pattern of the value instead, such as
|
|
103
|
+
* `dd/mm/yyyy`, in the order and with the separators of the locale of the reader.
|
|
104
|
+
*/
|
|
105
|
+
placeholder?: string;
|
|
106
|
+
/**
|
|
107
|
+
* The value shown in the field, held by the caller; left to the field if omitted.
|
|
108
|
+
*/
|
|
109
|
+
value?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Receives the value of the field on every edit, as the reader types it.
|
|
112
|
+
*
|
|
113
|
+
* @param value The value the field now holds
|
|
114
|
+
*/
|
|
115
|
+
onChange?: (value: string) => void;
|
|
116
|
+
}): import("preact").VNode<{
|
|
117
|
+
empty: boolean;
|
|
118
|
+
grow: boolean;
|
|
119
|
+
}>;
|
|
120
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/controls/input.tsx"],"names":[],"mappings":"AA2BA,OAAO,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,KAAK,CAAC,EAErB,IAAI,EACJ,EAAE,EACF,WAAW,EAEX,QAAQ,EACR,QAAQ,EACR,QAAQ,EAER,IAAa,EAEb,GAAG,EACH,GAAG,EACH,IAAI,EACJ,SAAS,EACT,SAAS,EACT,OAAO,EACP,KAAK,EAEL,IAAY,EACZ,IAAI,EAEJ,WAAW,EACX,KAAK,EAEL,QAAQ,EAER,EAAE;IAEF;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAA;IAEX;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;;;OAKG;IAEH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,GAC5D,MAAM,GAAG,MAAM,GAAG,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAA;IAExD;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAEd;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAElC;;;GA2DA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright © 2026 Metreeca srl
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Single-line field.
|
|
19
|
+
*
|
|
20
|
+
* Takes a value typed on one line, such as a title, an address, a number or a date, checked against the constraints
|
|
21
|
+
* the field states as the reader types it, so a mistake is caught before the form is submitted.
|
|
22
|
+
*
|
|
23
|
+
* @module input
|
|
24
|
+
*/
|
|
25
|
+
import { createElement } from "preact";
|
|
26
|
+
import { useLayoutEffect, useRef, useState } from "preact/hooks";
|
|
27
|
+
import "./input.css";
|
|
28
|
+
/**
|
|
29
|
+
* Creates a single-line field.
|
|
30
|
+
*
|
|
31
|
+
* Takes its value on a native input, so the editing keys, the on-screen keyboard suited to `type`, the date and time
|
|
32
|
+
* pickers, and the checking of every constraint come from the platform. A field failing a constraint is marked once
|
|
33
|
+
* the reader has had a say on it, and stops the {@link form!Form Form} around it from being submitted.
|
|
34
|
+
*
|
|
35
|
+
* The value is either held by the caller, which shows `value` and is handed each edit through `onChange`, or left to
|
|
36
|
+
* the field where `value` is omitted, the field then keeping whatever the reader types.
|
|
37
|
+
*
|
|
38
|
+
* @param options The widget configuration
|
|
39
|
+
*
|
|
40
|
+
* @returns The field
|
|
41
|
+
*
|
|
42
|
+
* @see [HTML: The input element][input]
|
|
43
|
+
*
|
|
44
|
+
* [input]: https://html.spec.whatwg.org/multipage/input.html#the-input-element
|
|
45
|
+
*/
|
|
46
|
+
export function Input({ name, id, description, disabled, readonly, required, type = "text", min, max, step, minLength, maxLength, pattern, error, grow = false, size, placeholder, value, onChange }) {
|
|
47
|
+
/*
|
|
48
|
+
* The element tells a stylesheet whether the field holds a value, which a date or time field offers no selector
|
|
49
|
+
* for, having no placeholder. A value held by the caller settles it; otherwise the last edit of the reader does.
|
|
50
|
+
*/
|
|
51
|
+
const [typed, setTyped] = useState("");
|
|
52
|
+
const empty = (value ?? typed) === "";
|
|
53
|
+
/*
|
|
54
|
+
* The platform takes a custom message only through setCustomValidity, with no attribute standing for it, so the
|
|
55
|
+
* message is set on the element after every render, catching a value or an error changed by the caller, and on
|
|
56
|
+
* every edit, before the form around the field reads its validity and hands it over to its own validation handler.
|
|
57
|
+
*/
|
|
58
|
+
const field = useRef(null);
|
|
59
|
+
useLayoutEffect(() => {
|
|
60
|
+
if (field.current) {
|
|
61
|
+
report(field.current, error);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return createElement("clay-input", { empty, grow }, _jsx("input", { ref: field, id: id, disabled: disabled, readOnly: readonly, required: required, "aria-label": name, "aria-describedby": description, type: type, min: min, max: max, step: step, minLength: minLength, maxLength: maxLength, pattern: pattern, size: size, placeholder: placeholder, value: value, onInput: event => {
|
|
65
|
+
report(event.currentTarget, error);
|
|
66
|
+
setTyped(event.currentTarget.value);
|
|
67
|
+
onChange?.(event.currentTarget.value);
|
|
68
|
+
} }));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Sets the custom message of a field to the error given while the field fails its own constraints, and clears it
|
|
72
|
+
* otherwise, so the message names the rule a failing value breaks but never decides whether the field is valid.
|
|
73
|
+
*/
|
|
74
|
+
function report(field, error) {
|
|
75
|
+
field.setCustomValidity("");
|
|
76
|
+
field.setCustomValidity(error === undefined || field.validity.valid ? "" : error);
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/controls/input.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,KAAK,CAAC,EAErB,IAAI,EACJ,EAAE,EACF,WAAW,EAEX,QAAQ,EACR,QAAQ,EACR,QAAQ,EAER,IAAI,GAAG,MAAM,EAEb,GAAG,EACH,GAAG,EACH,IAAI,EACJ,SAAS,EACT,SAAS,EACT,OAAO,EACP,KAAK,EAEL,IAAI,GAAG,KAAK,EACZ,IAAI,EAEJ,WAAW,EACX,KAAK,EAEL,QAAQ,EAwHR;IAEA;;;OAGG;IAEH,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEvC,MAAM,KAAK,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;IAEtC;;;;OAIG;IAEH,MAAM,KAAK,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IAE7C,eAAe,CAAC,GAAG,EAAE;QACpB,IAAK,KAAK,CAAC,OAAO,EAAG,CAAC;YACrB,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC9B,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,gBAEnD,GAAG,EAAE,KAAK,EAEV,EAAE,EAAE,EAAE,EAEN,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,gBAEN,IAAI,sBACE,WAAW,EAC7B,IAAI,EAAE,IAAI,EAEV,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,EAEhB,IAAI,EAAE,IAAI,EAEV,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,EAEZ,OAAO,EAAE,KAAK,CAAC,EAAE;YAChB,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;YACnC,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACpC,QAAQ,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC,GAEA,CAAC,CAAC;AAEL,CAAC;AAGD;;;GAGG;AACH,SAAS,MAAM,CAAC,KAAuB,EAAE,KAAyB;IACjE,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAC5B,KAAK,CAAC,iBAAiB,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/* A label is the native one, standing wherever the layout around it places it with no box of its own. */
|
|
18
|
+
|
|
19
|
+
clay-label {
|
|
20
|
+
|
|
21
|
+
display: contents;
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* The colour, the weight, the size and the gap of a label are the design system's, which lays a label out by the
|
|
25
|
+
* control it wraps: a field below its text, a box beside it. The orientation the widget states takes the place of
|
|
26
|
+
* that guess, so a label stands as told whatever it wraps, and names a control standing apart at the size told.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
&[orientation="vertical"] > label {
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
align-items: start;
|
|
32
|
+
font-size: var(--skin--font-size-small);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&[orientation="horizontal"] > label {
|
|
36
|
+
flex-direction: row;
|
|
37
|
+
align-items: center;
|
|
38
|
+
font-size: inherit;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* A growing label spans the column holding it, a vertical one also taking the height the column leaves; in a
|
|
43
|
+
* strip, it takes the room left on its line instead. The field it wraps is stretched to fill that room in turn.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
&[grow] > label {
|
|
47
|
+
display: flex;
|
|
48
|
+
align-self: stretch;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&[grow][orientation="vertical"] > label {
|
|
52
|
+
flex: 1 0 auto;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
clay-strip > &[grow] > label {
|
|
56
|
+
flex: auto;
|
|
57
|
+
align-self: auto;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
* A label naming a control the reader has to fill in is marked by an asterisk after its text from the moment the
|
|
62
|
+
* form is shown, so the reader knows what to fill in before trying to submit. The mark is silent to assistive
|
|
63
|
+
* technology, which already announces the requirement the control states. A radio button is left unmarked, the
|
|
64
|
+
* caption of the group it belongs to being marked instead, so a single pick is never marked once per button. The
|
|
65
|
+
* mark takes the colour of a failure, the one a field still empty will be marked in when the reader submits it.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
&:is([required], :has(> label :required:enabled:not([type="radio"]))) > label > span:first-of-type::after {
|
|
69
|
+
content: " *" / "";
|
|
70
|
+
color: var(--skin--color-fail);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field label.
|
|
3
|
+
*
|
|
4
|
+
* Names a form control, so assistive technology announces the control by the text the reader sees beside it, and a
|
|
5
|
+
* press on that text reaches the control as a press on the control itself would.
|
|
6
|
+
*
|
|
7
|
+
* @module label
|
|
8
|
+
*/
|
|
9
|
+
import { type ComponentChildren, type VNode } from "preact";
|
|
10
|
+
import "./label.css";
|
|
11
|
+
/**
|
|
12
|
+
* Creates a label.
|
|
13
|
+
*
|
|
14
|
+
* Names its control in either of two ways, the placement of the text and the control being left to the caller:
|
|
15
|
+
*
|
|
16
|
+
* - **wrapped**: the control is given among the children, with the text before or after it, and is named without
|
|
17
|
+
* any id, as in `<Label>Title <Input/></Label>` or `<Label><Checkbox/> Remember me</Label>`
|
|
18
|
+
* - **split**: the label stands apart from its control, such as in another column of a grid, and names it by the id
|
|
19
|
+
* given as `control`, which the control carries as its own `id` wherever on the screen it stands
|
|
20
|
+
*
|
|
21
|
+
* A label naming a control the reader has to fill in shows an asterisk after its text from the start, so the reader
|
|
22
|
+
* knows what to fill in before submitting. A wrapped control marks its label through its own `required` state while
|
|
23
|
+
* it takes input; a split label is marked through `required`. Assistive technology skips the asterisk and announces
|
|
24
|
+
* the requirement from the control itself. A radio button is never marked: the caption of the
|
|
25
|
+
* {@link fieldset!Fieldset Fieldset} grouping it is marked instead, so a single pick is marked once. The screen
|
|
26
|
+
* states what the asterisk stands for, for instance in a note opening the form, before the reader reaches any field.
|
|
27
|
+
*
|
|
28
|
+
* A label stands at the size of its text and control unless told to `grow`, whatever the field it wraps: a growing
|
|
29
|
+
* field never stretches the label around it, while a growing label stretches the {@link input!Input Input},
|
|
30
|
+
* {@link textarea!Textarea Textarea} or {@link select!Select Select} it wraps to fill the room it takes.
|
|
31
|
+
*
|
|
32
|
+
* @param options The widget configuration
|
|
33
|
+
*
|
|
34
|
+
* @returns The label
|
|
35
|
+
*
|
|
36
|
+
* @see [HTML: The label element][label]
|
|
37
|
+
*
|
|
38
|
+
* [label]: https://html.spec.whatwg.org/multipage/forms.html#the-label-element
|
|
39
|
+
*/
|
|
40
|
+
export declare function Label({ orientation, grow, control, required, children }: {
|
|
41
|
+
/**
|
|
42
|
+
* How a wrapped control and its text are arranged: `vertical`, the default, stacks them one over the other, each
|
|
43
|
+
* aligned to the start, as a field stands under the text naming it; `horizontal` sets them side by side on one
|
|
44
|
+
* line, centred on each other, as a checkbox, a radio button or a switch stands beside the text naming it.
|
|
45
|
+
*/
|
|
46
|
+
orientation?: "vertical" | "horizontal";
|
|
47
|
+
/**
|
|
48
|
+
* Whether the label spans the column holding it, a vertical label also taking the height the column leaves, or
|
|
49
|
+
* takes the room left on its line in a {@link strip!Strip Strip}; sized to its text and control if omitted. The
|
|
50
|
+
* field wrapped by a growing label fills that room, below the text or beside it, whether told to `grow` or not.
|
|
51
|
+
*/
|
|
52
|
+
grow?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* The id of the control the label names where the label stands apart from it; the control wrapped among the
|
|
55
|
+
* children if omitted. The id has to resolve to a rendered control, or the label names nothing at all.
|
|
56
|
+
*/
|
|
57
|
+
control?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the control named by `control` must be filled in, marking the label with an asterisk; unmarked if
|
|
60
|
+
* omitted. The setting marks the label only: the control still states the requirement through its own `required`,
|
|
61
|
+
* which the platform checks on submission and assistive technology announces on reaching the control.
|
|
62
|
+
*/
|
|
63
|
+
required?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The text naming the control, and the control itself where the label wraps it.
|
|
66
|
+
*
|
|
67
|
+
* Plain text may be given as it stands, but text mixing in markup, such as a link to the terms being accepted,
|
|
68
|
+
* goes inside a single `span`: each run of text and each element is otherwise laid out as a part of its own.
|
|
69
|
+
*/
|
|
70
|
+
children?: ComponentChildren;
|
|
71
|
+
}): VNode<{
|
|
72
|
+
orientation: "vertical" | "horizontal";
|
|
73
|
+
grow: boolean;
|
|
74
|
+
required: boolean | undefined;
|
|
75
|
+
}>;
|
|
76
|
+
//# sourceMappingURL=label.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"label.d.ts","sourceRoot":"","sources":["../../src/controls/label.tsx"],"names":[],"mappings":"AAgBA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,iBAAiB,EAA+B,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACzF,OAAO,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,KAAK,CAAC,EAErB,WAAwB,EACxB,IAAY,EAEZ,OAAO,EACP,QAAQ,EAER,QAAQ,EAER,EAAE;IAEF;;;;OAIG;IACH,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,CAAA;IAEvC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAEd;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAA;CAE5B;;;;GAIA"}
|