@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,73 @@
|
|
|
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
|
+
* Field label.
|
|
19
|
+
*
|
|
20
|
+
* Names a form control, so assistive technology announces the control by the text the reader sees beside it, and a
|
|
21
|
+
* press on that text reaches the control as a press on the control itself would.
|
|
22
|
+
*
|
|
23
|
+
* @module label
|
|
24
|
+
*/
|
|
25
|
+
import { createElement, toChildArray } from "preact";
|
|
26
|
+
import "./label.css";
|
|
27
|
+
/**
|
|
28
|
+
* Creates a label.
|
|
29
|
+
*
|
|
30
|
+
* Names its control in either of two ways, the placement of the text and the control being left to the caller:
|
|
31
|
+
*
|
|
32
|
+
* - **wrapped**: the control is given among the children, with the text before or after it, and is named without
|
|
33
|
+
* any id, as in `<Label>Title <Input/></Label>` or `<Label><Checkbox/> Remember me</Label>`
|
|
34
|
+
* - **split**: the label stands apart from its control, such as in another column of a grid, and names it by the id
|
|
35
|
+
* given as `control`, which the control carries as its own `id` wherever on the screen it stands
|
|
36
|
+
*
|
|
37
|
+
* A label naming a control the reader has to fill in shows an asterisk after its text from the start, so the reader
|
|
38
|
+
* knows what to fill in before submitting. A wrapped control marks its label through its own `required` state while
|
|
39
|
+
* it takes input; a split label is marked through `required`. Assistive technology skips the asterisk and announces
|
|
40
|
+
* the requirement from the control itself. A radio button is never marked: the caption of the
|
|
41
|
+
* {@link fieldset!Fieldset Fieldset} grouping it is marked instead, so a single pick is marked once. The screen
|
|
42
|
+
* states what the asterisk stands for, for instance in a note opening the form, before the reader reaches any field.
|
|
43
|
+
*
|
|
44
|
+
* A label stands at the size of its text and control unless told to `grow`, whatever the field it wraps: a growing
|
|
45
|
+
* field never stretches the label around it, while a growing label stretches the {@link input!Input Input},
|
|
46
|
+
* {@link textarea!Textarea Textarea} or {@link select!Select Select} it wraps to fill the room it takes.
|
|
47
|
+
*
|
|
48
|
+
* @param options The widget configuration
|
|
49
|
+
*
|
|
50
|
+
* @returns The label
|
|
51
|
+
*
|
|
52
|
+
* @see [HTML: The label element][label]
|
|
53
|
+
*
|
|
54
|
+
* [label]: https://html.spec.whatwg.org/multipage/forms.html#the-label-element
|
|
55
|
+
*/
|
|
56
|
+
export function Label({ orientation = "vertical", grow = false, control, required, children }) {
|
|
57
|
+
return createElement("clay-label", { orientation, grow, required }, _jsx("label", { for: control, children: parts(children) }));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Wraps each run of bare text in a span, so the text and the control are laid out as one part each, and the mark of
|
|
61
|
+
* a required control follows the text rather than the control standing after it in the label.
|
|
62
|
+
*/
|
|
63
|
+
function parts(children) {
|
|
64
|
+
return toChildArray(children)
|
|
65
|
+
.reduce((runs, child) => {
|
|
66
|
+
const last = runs.at(-1);
|
|
67
|
+
return typeof child === "object" ? [...runs, child]
|
|
68
|
+
: typeof last === "string" ? [...runs.slice(0, -1), `${last}${child}`]
|
|
69
|
+
: [...runs, `${child}`];
|
|
70
|
+
}, [])
|
|
71
|
+
.map(run => typeof run === "string" ? _jsx("span", { children: run }) : run);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=label.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"label.js","sourceRoot":"","sources":["../../src/controls/label.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAA0B,aAAa,EAAE,YAAY,EAAc,MAAM,QAAQ,CAAC;AACzF,OAAO,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,KAAK,CAAC,EAErB,WAAW,GAAG,UAAU,EACxB,IAAI,GAAG,KAAK,EAEZ,OAAO,EACP,QAAQ,EAER,QAAQ,EAuCR;IAEA,OAAO,aAAa,CAAC,YAAY,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,gBAAO,GAAG,EAAE,OAAO,YAAG,KAAK,CAAC,QAAQ,CAAC,GAAS,CAAC,CAAC;AAErH,CAAC;AAGD;;;GAGG;AACH,SAAS,KAAK,CAAC,QAA2B;IAEzC,OAAO,YAAY,CAAC,QAAQ,CAAC;SAE3B,MAAM,CAA8B,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAEpD,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAEzB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC;YAClD,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,KAAK,EAAE,CAAC;gBACrE,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;IAE3B,CAAC,EAAE,EAAE,CAAC;SAEL,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,yBAAO,GAAG,GAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAElE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 button is drawn as the design system draws every native radio, standing wherever the layout places it. */
|
|
18
|
+
|
|
19
|
+
clay-radio {
|
|
20
|
+
|
|
21
|
+
display: contents;
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import "./radio.css";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a radio button.
|
|
4
|
+
*
|
|
5
|
+
* Takes its pick on a native radio button, joined to the others carrying the same `group` within the same
|
|
6
|
+
* {@link form!Form Form}, so the platform supplies the keys and the focus a group owes: `Tab` reaches the group as
|
|
7
|
+
* one stop, landing on the picked option, and the arrow keys move the pick to either neighbour. Picking one option
|
|
8
|
+
* clears the one picked before, and a picked option is never cleared by a press of its own.
|
|
9
|
+
*
|
|
10
|
+
* The buttons of a group take no place of their own: the screen lays them out, and names the group as a whole by a
|
|
11
|
+
* {@link fieldset!Fieldset Fieldset} around them, whose caption says what is being picked.
|
|
12
|
+
*
|
|
13
|
+
* The pick is either held by the caller, which shows `checked` and is handed each pick through `onChange`, or left
|
|
14
|
+
* to the group where `checked` is omitted, the group then keeping whatever the reader picks.
|
|
15
|
+
*
|
|
16
|
+
* @param options The widget configuration
|
|
17
|
+
*
|
|
18
|
+
* @returns The radio button
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/radio/ ARIA Authoring Practices: Radio Group Pattern}
|
|
21
|
+
*/
|
|
22
|
+
export declare function Radio<V extends string>({ name, id, group, disabled, required, value, checked, onChange }: {
|
|
23
|
+
/**
|
|
24
|
+
* The accessible name, required where no {@link label!Label Label} names the button.
|
|
25
|
+
*/
|
|
26
|
+
name?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The id a split {@link label!Label Label} names the button by; no id if omitted.
|
|
29
|
+
*/
|
|
30
|
+
id?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The name of the group the button belongs to, shared by every button of the group and by no other, so that a form
|
|
33
|
+
* holding two groups gives each a name of its own and a pick in one never clears the other.
|
|
34
|
+
*/
|
|
35
|
+
group: string;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the button takes no pick, greyed and skipped by the arrow keys; live if omitted.
|
|
38
|
+
*/
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the group fails its constraints while no button in it is picked; stated on any button of the group, and
|
|
42
|
+
* optional if omitted on all of them, the platform checking the group as a whole rather than button by button.
|
|
43
|
+
*/
|
|
44
|
+
required?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The value the button stands for, handed to `onChange` when it is picked.
|
|
47
|
+
*/
|
|
48
|
+
value: V;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the button is shown picked, held by the caller; left to the group if omitted.
|
|
51
|
+
*/
|
|
52
|
+
checked?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Receives the value of the button when the reader picks it, so the buttons of a group share one handler.
|
|
55
|
+
*
|
|
56
|
+
* @param value The value of the picked button
|
|
57
|
+
*/
|
|
58
|
+
onChange?: (value: V) => void;
|
|
59
|
+
}): import("preact").VNode<import("preact").ClassAttributes<HTMLElement> & import("preact").HTMLAttributes<EventTarget> & import("preact").SVGAttributes<SVGElement>>;
|
|
60
|
+
//# sourceMappingURL=radio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radio.d.ts","sourceRoot":"","sources":["../../src/controls/radio.tsx"],"names":[],"mappings":"AA0BA,OAAO,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,EAEvC,IAAI,EACJ,EAAE,EACF,KAAK,EAEL,QAAQ,EACR,QAAQ,EAER,KAAK,EACL,OAAO,EAEP,QAAQ,EAER,EAAE;IAEF;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAA;IAEX;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,KAAK,EAAE,CAAC,CAAA;IAER;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAA;CAE7B,qKAoBA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
* Radio button.
|
|
19
|
+
*
|
|
20
|
+
* Offers one option of a group from which a single one is picked, such as a delivery method, with every option in
|
|
21
|
+
* view and laid out wherever the screen places it, in a row, a column or a grid of its own.
|
|
22
|
+
*
|
|
23
|
+
* @module radio
|
|
24
|
+
*/
|
|
25
|
+
import { createElement } from "preact";
|
|
26
|
+
import "./radio.css";
|
|
27
|
+
/**
|
|
28
|
+
* Creates a radio button.
|
|
29
|
+
*
|
|
30
|
+
* Takes its pick on a native radio button, joined to the others carrying the same `group` within the same
|
|
31
|
+
* {@link form!Form Form}, so the platform supplies the keys and the focus a group owes: `Tab` reaches the group as
|
|
32
|
+
* one stop, landing on the picked option, and the arrow keys move the pick to either neighbour. Picking one option
|
|
33
|
+
* clears the one picked before, and a picked option is never cleared by a press of its own.
|
|
34
|
+
*
|
|
35
|
+
* The buttons of a group take no place of their own: the screen lays them out, and names the group as a whole by a
|
|
36
|
+
* {@link fieldset!Fieldset Fieldset} around them, whose caption says what is being picked.
|
|
37
|
+
*
|
|
38
|
+
* The pick is either held by the caller, which shows `checked` and is handed each pick through `onChange`, or left
|
|
39
|
+
* to the group where `checked` is omitted, the group then keeping whatever the reader picks.
|
|
40
|
+
*
|
|
41
|
+
* @param options The widget configuration
|
|
42
|
+
*
|
|
43
|
+
* @returns The radio button
|
|
44
|
+
*
|
|
45
|
+
* @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/radio/ ARIA Authoring Practices: Radio Group Pattern}
|
|
46
|
+
*/
|
|
47
|
+
export function Radio({ name, id, group, disabled, required, value, checked, onChange }) {
|
|
48
|
+
return createElement("clay-radio", {}, _jsx("input", { id: id, name: group, disabled: disabled, required: required, "aria-label": name, type: "radio", value: value, checked: checked, onChange: () => onChange?.(value) }));
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=radio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radio.js","sourceRoot":"","sources":["../../src/controls/radio.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,KAAK,CAAmB,EAEvC,IAAI,EACJ,EAAE,EACF,KAAK,EAEL,QAAQ,EACR,QAAQ,EAER,KAAK,EACL,OAAO,EAEP,QAAQ,EAgDR;IAEA,OAAO,aAAa,CAAC,YAAY,EAAE,EAAE,EAAE,gBAEtC,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,KAAK,EAEX,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,gBAEN,IAAI,EAChB,IAAI,EAAC,OAAO,EAEZ,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAEhB,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAEhC,CAAC,CAAC;AAEL,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 menu is drawn as the design system draws every native menu, standing wherever the layout places it. */
|
|
18
|
+
|
|
19
|
+
clay-select {
|
|
20
|
+
|
|
21
|
+
display: contents;
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* A menu wrapped by a growing label spans the width the label takes, below the text naming it, or takes the room
|
|
25
|
+
* left beside the text where the label is horizontal, keeping the height of its line in either case.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
clay-label[grow] > label > & > select {
|
|
29
|
+
align-self: stretch;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
clay-label[grow][orientation="horizontal"] > label > & > select {
|
|
33
|
+
flex: auto;
|
|
34
|
+
align-self: auto;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "./select.css";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a drop-down menu.
|
|
4
|
+
*
|
|
5
|
+
* Offers the options in the order given on a native select, so the list, the keys moving through it, the typing ahead
|
|
6
|
+
* to an option and the picker suited to the device come from the platform itself.
|
|
7
|
+
*
|
|
8
|
+
* A menu given a `placeholder` opens on it while no option is picked, as a first entry that cannot be picked back; a
|
|
9
|
+
* `required` menu still showing it fails its constraints, and keeps the {@link form!Form Form} around it from being
|
|
10
|
+
* submitted until the reader picks one of the options, since the placeholder never counts as an answer.
|
|
11
|
+
*
|
|
12
|
+
* The menu stands as wide as its longest option, unless a growing {@link label!Label Label} wraps it: the menu then
|
|
13
|
+
* fills the room the label takes, below the text naming it or beside it on one line.
|
|
14
|
+
*
|
|
15
|
+
* The value is either held by the caller, which shows `value` and is handed each pick through `onChange`, or left to
|
|
16
|
+
* the menu where `value` is omitted, the menu then keeping whatever the reader picks.
|
|
17
|
+
*
|
|
18
|
+
* @param options The widget configuration
|
|
19
|
+
*
|
|
20
|
+
* @returns The menu
|
|
21
|
+
*
|
|
22
|
+
* @see [HTML: The select element][select]
|
|
23
|
+
*
|
|
24
|
+
* [select]: https://html.spec.whatwg.org/multipage/form-elements.html#the-select-element
|
|
25
|
+
*/
|
|
26
|
+
export declare function Select<V extends string>({ name, id, disabled, required, options, placeholder, value, onChange }: {
|
|
27
|
+
/**
|
|
28
|
+
* The accessible name, required where no {@link label!Label Label} names the menu.
|
|
29
|
+
*/
|
|
30
|
+
name?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The id a split {@link label!Label Label} names the menu by; no id if omitted.
|
|
33
|
+
*/
|
|
34
|
+
id?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Whether the menu takes no pick, greyed and out of the tab order; live if omitted.
|
|
37
|
+
*/
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the menu fails its constraints while showing the `placeholder`; optional if omitted.
|
|
41
|
+
*/
|
|
42
|
+
required?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The label of each option, keyed by its value, in display order.
|
|
45
|
+
*/
|
|
46
|
+
options: Readonly<Record<V, string>>;
|
|
47
|
+
/**
|
|
48
|
+
* The hint shown faded while no option is picked, such as `Pick a country`; the first option picked if omitted.
|
|
49
|
+
*/
|
|
50
|
+
placeholder?: string;
|
|
51
|
+
/**
|
|
52
|
+
* The value of the option shown as picked, held by the caller; left to the menu if omitted.
|
|
53
|
+
*/
|
|
54
|
+
value?: V;
|
|
55
|
+
/**
|
|
56
|
+
* Receives the value of the option a reader picks.
|
|
57
|
+
*
|
|
58
|
+
* @param value The value of the picked option
|
|
59
|
+
*/
|
|
60
|
+
onChange?: (value: V) => void;
|
|
61
|
+
}): import("preact").VNode<import("preact").ClassAttributes<HTMLElement> & import("preact").HTMLAttributes<EventTarget> & import("preact").SVGAttributes<SVGElement>>;
|
|
62
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/controls/select.tsx"],"names":[],"mappings":"AA0BA,OAAO,cAAc,CAAC;AAGtB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,EAExC,IAAI,EACJ,EAAE,EAEF,QAAQ,EACR,QAAQ,EAER,OAAO,EAEP,WAAW,EACX,KAAK,EAEL,QAAQ,EAER,EAAE;IAEF;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;IAEpC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,CAAA;IAET;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAA;CAE7B,qKA8BA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
* Drop-down menu.
|
|
19
|
+
*
|
|
20
|
+
* Takes one value picked from a list of options too long to keep in view, showing the picked one alone until the
|
|
21
|
+
* reader opens the list to pick another, so a long list costs the screen a single line.
|
|
22
|
+
*
|
|
23
|
+
* @module select
|
|
24
|
+
*/
|
|
25
|
+
import { createElement } from "preact";
|
|
26
|
+
import "./select.css";
|
|
27
|
+
/**
|
|
28
|
+
* Creates a drop-down menu.
|
|
29
|
+
*
|
|
30
|
+
* Offers the options in the order given on a native select, so the list, the keys moving through it, the typing ahead
|
|
31
|
+
* to an option and the picker suited to the device come from the platform itself.
|
|
32
|
+
*
|
|
33
|
+
* A menu given a `placeholder` opens on it while no option is picked, as a first entry that cannot be picked back; a
|
|
34
|
+
* `required` menu still showing it fails its constraints, and keeps the {@link form!Form Form} around it from being
|
|
35
|
+
* submitted until the reader picks one of the options, since the placeholder never counts as an answer.
|
|
36
|
+
*
|
|
37
|
+
* The menu stands as wide as its longest option, unless a growing {@link label!Label Label} wraps it: the menu then
|
|
38
|
+
* fills the room the label takes, below the text naming it or beside it on one line.
|
|
39
|
+
*
|
|
40
|
+
* The value is either held by the caller, which shows `value` and is handed each pick through `onChange`, or left to
|
|
41
|
+
* the menu where `value` is omitted, the menu then keeping whatever the reader picks.
|
|
42
|
+
*
|
|
43
|
+
* @param options The widget configuration
|
|
44
|
+
*
|
|
45
|
+
* @returns The menu
|
|
46
|
+
*
|
|
47
|
+
* @see [HTML: The select element][select]
|
|
48
|
+
*
|
|
49
|
+
* [select]: https://html.spec.whatwg.org/multipage/form-elements.html#the-select-element
|
|
50
|
+
*/
|
|
51
|
+
export function Select({ name, id, disabled, required, options, placeholder, value, onChange }) {
|
|
52
|
+
/*
|
|
53
|
+
* The placeholder is the empty first option the platform reads as a placeholder label option, which a required
|
|
54
|
+
* menu fails on; a menu holding no value of its own opens on it, the platform picking the first option otherwise.
|
|
55
|
+
*/
|
|
56
|
+
return createElement("clay-select", {}, _jsxs("select", { id: id, disabled: disabled, required: required, "aria-label": name, value: value ?? (placeholder === undefined ? undefined : ""), onChange: event => onChange?.(event.currentTarget.value), children: [placeholder !== undefined && _jsx("option", { value: "", disabled: true, children: placeholder }), Object.keys(options).map(option => // ;(cast) options is assumed to carry no keys beyond V
|
|
57
|
+
_jsx("option", { value: option, children: options[option] }, option))] }));
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/controls/select.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,cAAc,CAAC;AAGtB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,MAAM,CAAmB,EAExC,IAAI,EACJ,EAAE,EAEF,QAAQ,EACR,QAAQ,EAER,OAAO,EAEP,WAAW,EACX,KAAK,EAEL,QAAQ,EA8CR;IAEA;;;OAGG;IAEH,OAAO,aAAa,CAAC,aAAa,EAAE,EAAE,EAAE,kBAEvC,EAAE,EAAE,EAAE,EAEN,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,gBAEN,IAAI,EAEhB,KAAK,EAAE,KAAK,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAE5D,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,KAAU,CAAC,aAI5D,WAAW,KAAK,SAAS,IAAI,iBAAQ,KAAK,EAAC,EAAE,EAAC,QAAQ,kBAAE,WAAW,GAAU,EAE5E,MAAM,CAAC,IAAI,CAAC,OAAO,CAAS,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,uDAAuD;aACnG,iBAAqB,KAAK,EAAE,MAAM,YAAG,OAAO,CAAC,MAAM,CAAC,IAAvC,MAAM,CAA2C,CAC9D,IAEO,CAAC,CAAC;AAEZ,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
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 switch is drawn as a thumb sliding along a track, standing at the start while off and at the end while on, so its
|
|
19
|
+
* state reads by position as well as by colour. The track is a pill as tall as a checkbox and long enough for the thumb
|
|
20
|
+
* to travel visibly, edged in the field border and sunk into the page as an empty field is; switched on, it fills in
|
|
21
|
+
* the colour of a control that answers, as a ticked box does. The native checkbox carrying the state is drawn on
|
|
22
|
+
* directly, so the platform keeps its keys, its focus and its state, and the focus mark the design system gives a
|
|
23
|
+
* checkbox follows the rounded outline of the pill rather than squaring off around it as a drawn ring would.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
clay-switch {
|
|
27
|
+
|
|
28
|
+
display: contents;
|
|
29
|
+
|
|
30
|
+
& > input {
|
|
31
|
+
|
|
32
|
+
appearance: none;
|
|
33
|
+
|
|
34
|
+
position: relative;
|
|
35
|
+
flex-shrink: 0;
|
|
36
|
+
|
|
37
|
+
inline-size: calc(1.6 * var(--skin--scaling-100));
|
|
38
|
+
block-size: var(--skin--scaling-100);
|
|
39
|
+
margin: 0;
|
|
40
|
+
|
|
41
|
+
border: var(--skin--border-width) var(--skin--border-style) var(--skin--border-color-field);
|
|
42
|
+
border-radius: calc(var(--skin--scaling-100) / 2);
|
|
43
|
+
background-color: var(--skin--background-color-sunken);
|
|
44
|
+
|
|
45
|
+
vertical-align: middle;
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
|
|
48
|
+
transition-property: border-color, background-color;
|
|
49
|
+
transition-duration: var(--skin--duration-fast);
|
|
50
|
+
transition-timing-function: var(--skin--easing-standard);
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* The thumb is a disc set inside the track by an equal inset on every side and drawn a little smaller, an
|
|
54
|
+
* optical nudge below the spacing scale, so a clear ring parts it from the edge of the pill in every state, the
|
|
55
|
+
* disabled one included, where a grey thumb would otherwise merge with the grey line around it. It is painted
|
|
56
|
+
* in the label colour while off, standing out from the sunken track without claiming the colour a live setting
|
|
57
|
+
* is painted in once the reader switches it on and the thumb slides to the far end.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
&::before {
|
|
61
|
+
|
|
62
|
+
content: "";
|
|
63
|
+
|
|
64
|
+
position: absolute;
|
|
65
|
+
inset-block: var(--skin--border-width);
|
|
66
|
+
inset-inline-start: var(--skin--border-width);
|
|
67
|
+
|
|
68
|
+
aspect-ratio: 1;
|
|
69
|
+
border-radius: 50%;
|
|
70
|
+
scale: 0.9;
|
|
71
|
+
background-color: var(--skin--color-label);
|
|
72
|
+
|
|
73
|
+
transition-property: inset-inline-start, background-color;
|
|
74
|
+
transition-duration: var(--skin--duration-fast);
|
|
75
|
+
transition-timing-function: var(--skin--easing-standard);
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* Switched on, the track fills in the colour of a control that answers and the thumb slides to its end,
|
|
81
|
+
* painted in the colour set over a saturated fill. The thumb is placed by its logical start alone, so the
|
|
82
|
+
* switch mirrors in right-to-left text, standing at the right while off and at the left while on, as
|
|
83
|
+
* platforms mirror their switches. It lands as far from the end of the pill as it starts from the beginning
|
|
84
|
+
* whatever the width the pill is drawn at: the room inside the border, less the thumb, as tall as the track
|
|
85
|
+
* less its border and inner room on both sides, and less the inner room at the end.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
&:checked {
|
|
89
|
+
|
|
90
|
+
border-color: var(--skin--color-enabled);
|
|
91
|
+
background-color: var(--skin--color-enabled);
|
|
92
|
+
|
|
93
|
+
&::before {
|
|
94
|
+
inset-inline-start: calc(100% - var(--skin--scaling-100) + 3 * var(--skin--border-width));
|
|
95
|
+
background-color: var(--skin--color-over);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* A switch taking no flip recedes as a disabled field does, track and thumb falling back to neutral lines.
|
|
102
|
+
* Switched on, its track fills in the disabled colour, edge included, as a live track fills in its own, so the
|
|
103
|
+
* thumb keeps the same room from the visible edge of the pill whether the switch is live or not.
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
&:disabled {
|
|
107
|
+
|
|
108
|
+
border-color: var(--skin--border-color);
|
|
109
|
+
background-color: transparent;
|
|
110
|
+
cursor: default;
|
|
111
|
+
|
|
112
|
+
&::before {
|
|
113
|
+
background-color: var(--skin--color-disabled);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
* Off, the grey thumb sits against a grey line with no fill behind it, and reads as hugging the start of
|
|
118
|
+
* the pill, so it is moved a little further inwards, an optical nudge balancing the room around it.
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
&:not(:checked)::before {
|
|
122
|
+
inset-inline-start: calc(2 * var(--skin--border-width));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
&:checked {
|
|
126
|
+
|
|
127
|
+
border-color: var(--skin--color-disabled);
|
|
128
|
+
background-color: var(--skin--color-disabled);
|
|
129
|
+
|
|
130
|
+
&::before {
|
|
131
|
+
background-color: var(--skin--color-over);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/*
|
|
139
|
+
* Forced colours repaint every background in the page colour, which would wipe out the thumb, so the thumb is
|
|
140
|
+
* painted in the text colour of the system palette and the state is read from its position alone.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
@media (forced-colors: active) {
|
|
144
|
+
|
|
145
|
+
&::before {
|
|
146
|
+
forced-color-adjust: none;
|
|
147
|
+
background-color: CanvasText;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import "./switch.css";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a switch.
|
|
4
|
+
*
|
|
5
|
+
* Takes its state on a native checkbox announced as a switch, so the flip by `Space` or by a press, the tab stop, and
|
|
6
|
+
* the on or off state assistive technology reads come from the platform. The thumb stands at the end of the track
|
|
7
|
+
* and the track is filled while the switch is on, so the state reads by position as well as by colour.
|
|
8
|
+
*
|
|
9
|
+
* The state is either held by the caller, which shows `checked` and is handed each flip through `onChange`, or left
|
|
10
|
+
* to the switch where `checked` is omitted, the switch then keeping whatever the reader flips it to.
|
|
11
|
+
*
|
|
12
|
+
* An answer taking effect only when the form is submitted takes a {@link checkbox!Checkbox Checkbox} instead.
|
|
13
|
+
*
|
|
14
|
+
* @param options The widget configuration
|
|
15
|
+
*
|
|
16
|
+
* @returns The switch
|
|
17
|
+
*
|
|
18
|
+
* @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/switch/ ARIA Authoring Practices: Switch Pattern}
|
|
19
|
+
*/
|
|
20
|
+
export declare function Switch({ name, id, disabled, checked, onChange }: {
|
|
21
|
+
/**
|
|
22
|
+
* The accessible name, required where no {@link label!Label Label} names the switch.
|
|
23
|
+
*/
|
|
24
|
+
name?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The id a split {@link label!Label Label} names the switch by; no id if omitted.
|
|
27
|
+
*/
|
|
28
|
+
id?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the switch takes no flip, greyed and out of the tab order; live if omitted.
|
|
31
|
+
*/
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the switch is shown on, held by the caller; left to the switch if omitted.
|
|
35
|
+
*/
|
|
36
|
+
checked?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Receives the state of the switch on every flip.
|
|
39
|
+
*
|
|
40
|
+
* @param checked Whether the switch is now on
|
|
41
|
+
*/
|
|
42
|
+
onChange?: (checked: boolean) => void;
|
|
43
|
+
}): import("preact").VNode<import("preact").ClassAttributes<HTMLElement> & import("preact").HTMLAttributes<EventTarget> & import("preact").SVGAttributes<SVGElement>>;
|
|
44
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/controls/switch.tsx"],"names":[],"mappings":"AA0BA,OAAO,cAAc,CAAC;AAGtB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,EAEtB,IAAI,EACJ,EAAE,EAEF,QAAQ,EAER,OAAO,EAEP,QAAQ,EAER,EAAE;IAEF;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;CAErC,qKAkBA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
* On/off switch.
|
|
19
|
+
*
|
|
20
|
+
* Turns a setting on or off with immediate effect, such as notifications or a preview, drawn as a thumb sliding along
|
|
21
|
+
* a track so that it reads as a setting in force rather than as an answer waiting to be submitted.
|
|
22
|
+
*
|
|
23
|
+
* @module switch
|
|
24
|
+
*/
|
|
25
|
+
import { createElement } from "preact";
|
|
26
|
+
import "./switch.css";
|
|
27
|
+
/**
|
|
28
|
+
* Creates a switch.
|
|
29
|
+
*
|
|
30
|
+
* Takes its state on a native checkbox announced as a switch, so the flip by `Space` or by a press, the tab stop, and
|
|
31
|
+
* the on or off state assistive technology reads come from the platform. The thumb stands at the end of the track
|
|
32
|
+
* and the track is filled while the switch is on, so the state reads by position as well as by colour.
|
|
33
|
+
*
|
|
34
|
+
* The state is either held by the caller, which shows `checked` and is handed each flip through `onChange`, or left
|
|
35
|
+
* to the switch where `checked` is omitted, the switch then keeping whatever the reader flips it to.
|
|
36
|
+
*
|
|
37
|
+
* An answer taking effect only when the form is submitted takes a {@link checkbox!Checkbox Checkbox} instead.
|
|
38
|
+
*
|
|
39
|
+
* @param options The widget configuration
|
|
40
|
+
*
|
|
41
|
+
* @returns The switch
|
|
42
|
+
*
|
|
43
|
+
* @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/switch/ ARIA Authoring Practices: Switch Pattern}
|
|
44
|
+
*/
|
|
45
|
+
export function Switch({ name, id, disabled, checked, onChange }) {
|
|
46
|
+
return createElement("clay-switch", {}, _jsx("input", { id: id, disabled: disabled, "aria-label": name, role: "switch", type: "checkbox", checked: checked, onChange: event => onChange?.(event.currentTarget.checked) }));
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/controls/switch.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,cAAc,CAAC;AAGtB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAC,EAEtB,IAAI,EACJ,EAAE,EAEF,QAAQ,EAER,OAAO,EAEP,QAAQ,EA+BR;IAEA,OAAO,aAAa,CAAC,aAAa,EAAE,EAAE,EAAE,gBAEvC,EAAE,EAAE,EAAE,EAEN,QAAQ,EAAE,QAAQ,gBAEN,IAAI,EAChB,IAAI,EAAC,QAAQ,EACb,IAAI,EAAC,UAAU,EAEf,OAAO,EAAE,OAAO,EAEhB,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,GAEzD,CAAC,CAAC;AAEL,CAAC"}
|