@typed/ui 1.0.0-beta.6 → 1.0.0-beta.8
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 +21 -0
- package/README.md +1 -1
- package/dist/Alert.d.ts +35 -41
- package/dist/Alert.d.ts.map +1 -1
- package/dist/Alert.js +23 -20
- package/dist/Button.d.ts +34 -78
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +16 -12
- package/dist/Carousel.d.ts +35 -236
- package/dist/Carousel.d.ts.map +1 -1
- package/dist/Carousel.js +13 -136
- package/dist/Checkbox.d.ts +55 -90
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Checkbox.js +44 -38
- package/dist/Collection.d.ts +15 -15
- package/dist/Collection.js +7 -7
- package/dist/Combobox.d.ts +38 -187
- package/dist/Combobox.d.ts.map +1 -1
- package/dist/Combobox.js +9 -80
- package/dist/Component.d.ts +30 -24
- package/dist/Component.d.ts.map +1 -1
- package/dist/Component.js +23 -12
- package/dist/Composite.d.ts +50 -50
- package/dist/Composite.js +20 -20
- package/dist/Dialog.d.ts +34 -34
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Dialog.js +16 -14
- package/dist/Disclosure.d.ts +15 -15
- package/dist/Disclosure.js +6 -6
- package/dist/Dom/Events.d.ts +4 -4
- package/dist/Dom/Events.js +4 -4
- package/dist/Dom/Props.d.ts +9 -9
- package/dist/Dom/Props.js +4 -4
- package/dist/Dom/Refs.d.ts +2 -2
- package/dist/Dom/Refs.js +1 -1
- package/dist/Dom/Render.d.ts +2 -2
- package/dist/Dom/Render.js +2 -2
- package/dist/Dom/Types.d.ts +33 -33
- package/dist/Dom/index.d.ts +5 -5
- package/dist/Dom/index.d.ts.map +1 -1
- package/dist/Dom/index.js +4 -4
- package/dist/Dom.d.ts +1 -1
- package/dist/Dom.js +1 -1
- package/dist/Focusable.d.ts +5 -5
- package/dist/Focusable.js +1 -1
- package/dist/Form.d.ts +565 -533
- package/dist/Form.d.ts.map +1 -1
- package/dist/Form.js +350 -195
- package/dist/Grid.d.ts +39 -220
- package/dist/Grid.d.ts.map +1 -1
- package/dist/Grid.js +12 -107
- package/dist/Group.d.ts +50 -69
- package/dist/Group.d.ts.map +1 -1
- package/dist/Group.js +33 -25
- package/dist/Heading.d.ts +41 -40
- package/dist/Heading.d.ts.map +1 -1
- package/dist/Heading.js +26 -16
- package/dist/Hovercard.d.ts +18 -18
- package/dist/Hovercard.js +6 -6
- package/dist/HttpRouter.d.ts +3 -3
- package/dist/HttpRouter.js +5 -5
- package/dist/Link.d.ts +17 -21
- package/dist/Link.d.ts.map +1 -1
- package/dist/Link.js +11 -0
- package/dist/Listbox.d.ts +31 -163
- package/dist/Listbox.d.ts.map +1 -1
- package/dist/Listbox.js +9 -80
- package/dist/Menu.d.ts +67 -376
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Menu.js +17 -179
- package/dist/Menubar.d.ts +24 -142
- package/dist/Menubar.d.ts.map +1 -1
- package/dist/Menubar.js +8 -66
- package/dist/Meter.d.ts +72 -132
- package/dist/Meter.d.ts.map +1 -1
- package/dist/Meter.js +35 -42
- package/dist/NativeDetails.d.ts +1 -1
- package/dist/NativeDetails.js +1 -1
- package/dist/NativeDialog.d.ts +7 -5
- package/dist/NativeDialog.d.ts.map +1 -1
- package/dist/NativeDialog.js +42 -4
- package/dist/NativePopover.d.ts +6 -4
- package/dist/NativePopover.d.ts.map +1 -1
- package/dist/NativePopover.js +43 -5
- package/dist/Popover.d.ts +18 -19
- package/dist/Popover.d.ts.map +1 -1
- package/dist/Popover.js +7 -8
- package/dist/RadioGroup.d.ts +86 -188
- package/dist/RadioGroup.d.ts.map +1 -1
- package/dist/RadioGroup.js +55 -105
- package/dist/Role.d.ts +4 -4
- package/dist/Role.js +1 -1
- package/dist/Select.d.ts +109 -220
- package/dist/Select.d.ts.map +1 -1
- package/dist/Select.js +67 -117
- package/dist/Separator.d.ts +30 -26
- package/dist/Separator.d.ts.map +1 -1
- package/dist/Separator.js +16 -10
- package/dist/Slider.d.ts +64 -111
- package/dist/Slider.d.ts.map +1 -1
- package/dist/Slider.js +47 -42
- package/dist/SpinButton.d.ts +64 -111
- package/dist/SpinButton.d.ts.map +1 -1
- package/dist/SpinButton.js +47 -42
- package/dist/Storybook.d.ts +2 -2
- package/dist/Storybook.js +1 -1
- package/dist/Switch.d.ts +52 -91
- package/dist/Switch.d.ts.map +1 -1
- package/dist/Switch.js +30 -36
- package/dist/Tabs.d.ts +44 -224
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/Tabs.js +10 -94
- package/dist/Toolbar.d.ts +24 -142
- package/dist/Toolbar.d.ts.map +1 -1
- package/dist/Toolbar.js +8 -66
- package/dist/Tooltip.d.ts +20 -20
- package/dist/Tooltip.js +6 -6
- package/dist/Tree.d.ts +43 -229
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Tree.js +12 -113
- package/dist/TreeGrid.d.ts +45 -264
- package/dist/TreeGrid.d.ts.map +1 -1
- package/dist/TreeGrid.js +13 -125
- package/dist/VisuallyHidden.d.ts +41 -27
- package/dist/VisuallyHidden.d.ts.map +1 -1
- package/dist/VisuallyHidden.js +27 -10
- package/dist/WindowSplitter.d.ts +68 -108
- package/dist/WindowSplitter.d.ts.map +1 -1
- package/dist/WindowSplitter.js +106 -23
- package/package.json +13 -12
package/dist/Switch.d.ts
CHANGED
|
@@ -1,68 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A button-backed on/off setting with a stable accessible name.
|
|
3
|
+
* The internal click toggles boolean state; persistence and form serialization remain explicit.
|
|
4
|
+
*
|
|
5
|
+
* Read the [Switch guide](/explore/ui-switch) for a complete example.
|
|
6
|
+
*
|
|
7
|
+
* [APG interaction reference](https://www.w3.org/WAI/ARIA/apg/patterns/switch/).
|
|
8
|
+
* @since 1.0.0
|
|
9
|
+
* @category Overview
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
1
12
|
import * as Effect from "effect/Effect";
|
|
2
13
|
import * as Schema from "effect/Schema";
|
|
3
14
|
import { RefSubject } from "@typed/fx";
|
|
4
15
|
import { type Renderable } from "@typed/template";
|
|
5
16
|
import * as Dom from "./Dom.js";
|
|
6
17
|
import type { HostResult } from "./Dom/Types.js";
|
|
7
|
-
/**
|
|
8
|
-
* @remarks
|
|
9
|
-
* ## Why
|
|
10
|
-
* The boolean can be tested and transformed without mounting a button.
|
|
11
|
-
* ## Ownership and lifetime
|
|
12
|
-
* Plain state retains no resources; its RefSubject owns updates by Scope.
|
|
13
|
-
* @since 1.0.0
|
|
14
|
-
* @category state
|
|
18
|
+
/**
|
|
15
19
|
*/
|
|
16
20
|
export interface State {
|
|
17
|
-
/**
|
|
18
|
-
* @remarks
|
|
19
|
-
* ## Why
|
|
20
|
-
* This value drives the required `aria-checked` state.
|
|
21
|
-
* ## Ownership and lifetime
|
|
22
|
-
* Plain data acquires no resources.
|
|
23
|
-
* @since 1.0.0
|
|
24
|
-
* @category state
|
|
21
|
+
/**
|
|
25
22
|
*/
|
|
26
23
|
readonly checked: boolean;
|
|
27
24
|
}
|
|
28
|
-
/**
|
|
29
|
-
* @remarks
|
|
30
|
-
* ## Why
|
|
31
|
-
* Omission provides a deterministic off state for SSR and clients.
|
|
32
|
-
* ## Ownership and lifetime
|
|
33
|
-
* Configuration is inert.
|
|
34
|
-
* @since 1.0.0
|
|
35
|
-
* @category state
|
|
25
|
+
/**
|
|
36
26
|
*/
|
|
37
27
|
export interface InitialState {
|
|
38
|
-
/**
|
|
39
|
-
* @remarks
|
|
40
|
-
* ## Why
|
|
41
|
-
* The value seeds the serializable hydration contract.
|
|
42
|
-
* ## Ownership and lifetime
|
|
43
|
-
* It is copied into state and retains no resource.
|
|
44
|
-
* @since 1.0.0
|
|
45
|
-
* @category state
|
|
28
|
+
/**
|
|
46
29
|
*/
|
|
47
30
|
readonly checked?: boolean;
|
|
48
31
|
}
|
|
49
|
-
/**
|
|
50
|
-
* @remarks
|
|
51
|
-
* ## Why
|
|
52
|
-
* Shared encoding keeps SSR and browser state compatible.
|
|
53
|
-
* ## Ownership and lifetime
|
|
54
|
-
* The immutable schema acquires no resources.
|
|
55
|
-
* @since 1.0.0
|
|
56
|
-
* @category schemas
|
|
32
|
+
/**
|
|
57
33
|
*/
|
|
58
34
|
export declare const StateSchema: Schema.Struct<{
|
|
59
35
|
readonly checked: Schema.Boolean;
|
|
60
36
|
}>;
|
|
61
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Creates hydrated switch state independent of rendering.
|
|
62
39
|
* @remarks
|
|
63
|
-
* ## Why
|
|
64
40
|
* Domain code and tests can own the state while any renderer consumes it.
|
|
65
|
-
* ## Ownership and lifetime
|
|
66
41
|
* The caller's Effect Scope owns the returned RefSubject.
|
|
67
42
|
* @example
|
|
68
43
|
* ```ts
|
|
@@ -74,17 +49,13 @@ export declare const StateSchema: Schema.Struct<{
|
|
|
74
49
|
* })
|
|
75
50
|
* ```
|
|
76
51
|
* @since 1.0.0
|
|
77
|
-
* @category
|
|
52
|
+
* @category State construction
|
|
78
53
|
*/
|
|
79
54
|
export declare function makeState(initial?: InitialState): Effect.Effect<RefSubject.HydratedRefSubject<{
|
|
80
55
|
readonly checked: boolean;
|
|
81
56
|
}, Schema.SchemaError, never, never>, never, import("effect/Scope").Scope>;
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* ## Why
|
|
85
|
-
* Explicit transitions keep state logic outside the renderer.
|
|
86
|
-
* ## Ownership and lifetime
|
|
87
|
-
* The Effect reuses the subject's lifetime and acquires no resource.
|
|
57
|
+
/**
|
|
58
|
+
* Sets the switch to the requested checked state.
|
|
88
59
|
* @example
|
|
89
60
|
* ```ts
|
|
90
61
|
* import { Effect } from "effect"
|
|
@@ -96,15 +67,11 @@ export declare function makeState(initial?: InitialState): Effect.Effect<RefSubj
|
|
|
96
67
|
* })
|
|
97
68
|
* ```
|
|
98
69
|
* @since 1.0.0
|
|
99
|
-
* @category
|
|
70
|
+
* @category State transitions
|
|
100
71
|
*/
|
|
101
72
|
export declare function setChecked<E, R>(state: RefSubject.RefSubject<State, E, R>, checked: boolean): Effect.Effect<State, E, R>;
|
|
102
|
-
/**
|
|
103
|
-
*
|
|
104
|
-
* ## Why
|
|
105
|
-
* A RefSubject update prevents stale read-then-write transitions.
|
|
106
|
-
* ## Ownership and lifetime
|
|
107
|
-
* The Effect acquires no resource and uses the existing state Scope.
|
|
73
|
+
/**
|
|
74
|
+
* Toggles the switch between checked and unchecked.
|
|
108
75
|
* @example
|
|
109
76
|
* ```ts
|
|
110
77
|
* import { Effect } from "effect"
|
|
@@ -116,38 +83,22 @@ export declare function setChecked<E, R>(state: RefSubject.RefSubject<State, E,
|
|
|
116
83
|
* })
|
|
117
84
|
* ```
|
|
118
85
|
* @since 1.0.0
|
|
119
|
-
* @category
|
|
86
|
+
* @category State transitions
|
|
120
87
|
*/
|
|
121
88
|
export declare function toggle<E, R>(state: RefSubject.RefSubject<State, E, R>): Effect.Effect<State, E, R>;
|
|
122
|
-
/**
|
|
123
|
-
* @remarks
|
|
124
|
-
* ## Why
|
|
125
|
-
* Button behavior supplies focus and keyboard activation while ARIA exposes
|
|
126
|
-
* the binary switch semantic.
|
|
127
|
-
* ## Ownership and lifetime
|
|
128
|
-
* Options are inert; rendering owns subscriptions and listeners by Scope.
|
|
129
|
-
* @since 1.0.0
|
|
130
|
-
* @category models
|
|
89
|
+
/**
|
|
131
90
|
*/
|
|
132
91
|
export interface SwitchOptions extends Dom.HostOptions<HTMLButtonElement> {
|
|
133
|
-
/**
|
|
134
|
-
*
|
|
135
|
-
* ## Why
|
|
136
|
-
* One source controls SSR, render output, and activation updates.
|
|
137
|
-
* ## Ownership and lifetime
|
|
138
|
-
* The component borrows the state; its originating Scope owns it.
|
|
92
|
+
/**
|
|
93
|
+
* Hydrated state synchronized with `aria-checked`.
|
|
139
94
|
* @since 1.0.0
|
|
140
|
-
* @category
|
|
95
|
+
* @category State connection
|
|
141
96
|
*/
|
|
142
97
|
readonly state: RefSubject.HydratedRefSubject<State, Schema.SchemaError>;
|
|
143
|
-
/**
|
|
144
|
-
*
|
|
145
|
-
* ## Why
|
|
146
|
-
* A switch requires an accessible name, normally supplied by its content.
|
|
147
|
-
* ## Ownership and lifetime
|
|
148
|
-
* Dynamic content follows the component Scope.
|
|
98
|
+
/**
|
|
99
|
+
* Visible content and accessible name.
|
|
149
100
|
* @since 1.0.0
|
|
150
|
-
* @category content
|
|
101
|
+
* @category Rendered content
|
|
151
102
|
*/
|
|
152
103
|
readonly content: Renderable.Any;
|
|
153
104
|
}
|
|
@@ -160,27 +111,37 @@ declare function internalProps<const Options extends SwitchOptions>(options: Opt
|
|
|
160
111
|
readonly ref: RefSubject.HydratedRefSubject<State, Schema.SchemaError, never, never>;
|
|
161
112
|
};
|
|
162
113
|
type SwitchInternalProps<Options extends SwitchOptions> = ReturnType<ReturnType<typeof internalProps<Options>>>;
|
|
163
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* Renders a button-backed ARIA switch.
|
|
164
116
|
* @remarks
|
|
165
|
-
* ## Why
|
|
166
117
|
* The component combines native button activation with a renderer-independent
|
|
167
118
|
* boolean state and real DOM click events.
|
|
168
|
-
* ## Ownership and lifetime
|
|
169
119
|
* Running the Fx owns listener/state subscriptions in its Effect Scope. A
|
|
170
120
|
* custom host must preserve button type, role, `aria-checked`, click handler,
|
|
171
121
|
* and the single hydration ref owner.
|
|
172
122
|
* @example
|
|
173
123
|
* ```ts
|
|
174
|
-
* import {
|
|
175
|
-
* import
|
|
124
|
+
* import { RefSubject } from "@typed/fx";
|
|
125
|
+
* import { html } from "@typed/template";
|
|
126
|
+
* import { component } from "@typed/ui/Component";
|
|
127
|
+
* import * as Switch from "@typed/ui/Switch";
|
|
176
128
|
*
|
|
177
|
-
* const
|
|
178
|
-
* const state = yield* Switch.makeState()
|
|
179
|
-
*
|
|
180
|
-
*
|
|
129
|
+
* export const PreviewSetting = component(function* () {
|
|
130
|
+
* const state = yield* Switch.makeState({ checked: true });
|
|
131
|
+
* const status = RefSubject.map(state, ({ checked }) => checked ? "On" : "Off");
|
|
132
|
+
* return html`<section>
|
|
133
|
+
* ${Switch.Switch({
|
|
134
|
+
* state,
|
|
135
|
+
* content: "Show live preview",
|
|
136
|
+
* props: { class: "preview-switch", "aria-describedby": "preview-setting-help" },
|
|
137
|
+
* })}
|
|
138
|
+
* <span aria-hidden="true">${status}</span>
|
|
139
|
+
* <p id="preview-setting-help">Updates the preview while you edit.</p>
|
|
140
|
+
* </section>`;
|
|
141
|
+
* });
|
|
181
142
|
* ```
|
|
182
143
|
* @since 1.0.0
|
|
183
|
-
* @category
|
|
144
|
+
* @category Native controls
|
|
184
145
|
*/
|
|
185
146
|
export declare function Switch<const Options extends SwitchOptions, const Host extends HostResult = never>(options: Options, host?: Dom.HostOverride<Dom.RenderHostProps<Options, SwitchInternalProps<Options>>, Options["content"], Host>): import("./Dom/Types.js").HostComponent<Host | Options>;
|
|
186
147
|
export {};
|
package/dist/Switch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../src/Switch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD
|
|
1
|
+
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../src/Switch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD;GACG;AACH,MAAM,WAAW,KAAK;IACpB;OACG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;GACG;AACH,MAAM,WAAW,YAAY;IAC3B;OACG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;GACG;AACH,eAAO,MAAM,WAAW;;EAA6C,CAAC;AAEtE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,YAAiB;;2EAEnD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAC7B,KAAK,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,EACzC,OAAO,EAAE,OAAO,GACf,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAE5B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EACzB,KAAK,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,GACxC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAE5B;AAED;GACG;AACH,MAAM,WAAW,aAAc,SAAQ,GAAG,CAAC,WAAW,CAAC,iBAAiB,CAAC;IACvE;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACzE;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC;CAClC;AAED,iBAAS,aAAa,CAAC,KAAK,CAAC,OAAO,SAAS,aAAa,EAAE,OAAO,EAAE,OAAO,kBACpD,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC;aAEnD,IAAI,EAAE,QAAQ;aACd,IAAI,EAAE,QAAQ;aACd,cAAc;aACd,WAAW;aACX,OAAO;aACP,GAAG;EAER;AACD,KAAK,mBAAmB,CAAC,OAAO,SAAS,aAAa,IAAI,UAAU,CAClE,UAAU,CAAC,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC,CAC1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,MAAM,CAAC,KAAK,CAAC,OAAO,SAAS,aAAa,EAAE,KAAK,CAAC,IAAI,SAAS,UAAU,GAAG,KAAK,EAC/F,OAAO,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,GAAG,CAAC,YAAY,CACrB,GAAG,CAAC,eAAe,CAAC,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAC1D,OAAO,CAAC,SAAS,CAAC,EAClB,IAAI,CACL,0DAWF"}
|
package/dist/Switch.js
CHANGED
|
@@ -2,21 +2,13 @@ import * as Schema from "effect/Schema";
|
|
|
2
2
|
import { RefSubject } from "@typed/fx";
|
|
3
3
|
import { html } from "@typed/template";
|
|
4
4
|
import * as Dom from "./Dom.js";
|
|
5
|
-
/**
|
|
6
|
-
* @remarks
|
|
7
|
-
* ## Why
|
|
8
|
-
* Shared encoding keeps SSR and browser state compatible.
|
|
9
|
-
* ## Ownership and lifetime
|
|
10
|
-
* The immutable schema acquires no resources.
|
|
11
|
-
* @since 1.0.0
|
|
12
|
-
* @category schemas
|
|
5
|
+
/**
|
|
13
6
|
*/
|
|
14
7
|
export const StateSchema = Schema.Struct({ checked: Schema.Boolean });
|
|
15
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Creates hydrated switch state independent of rendering.
|
|
16
10
|
* @remarks
|
|
17
|
-
* ## Why
|
|
18
11
|
* Domain code and tests can own the state while any renderer consumes it.
|
|
19
|
-
* ## Ownership and lifetime
|
|
20
12
|
* The caller's Effect Scope owns the returned RefSubject.
|
|
21
13
|
* @example
|
|
22
14
|
* ```ts
|
|
@@ -28,17 +20,13 @@ export const StateSchema = Schema.Struct({ checked: Schema.Boolean });
|
|
|
28
20
|
* })
|
|
29
21
|
* ```
|
|
30
22
|
* @since 1.0.0
|
|
31
|
-
* @category
|
|
23
|
+
* @category State construction
|
|
32
24
|
*/
|
|
33
25
|
export function makeState(initial = {}) {
|
|
34
26
|
return RefSubject.hydrate(StateSchema, { checked: initial.checked ?? false });
|
|
35
27
|
}
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
* ## Why
|
|
39
|
-
* Explicit transitions keep state logic outside the renderer.
|
|
40
|
-
* ## Ownership and lifetime
|
|
41
|
-
* The Effect reuses the subject's lifetime and acquires no resource.
|
|
28
|
+
/**
|
|
29
|
+
* Sets the switch to the requested checked state.
|
|
42
30
|
* @example
|
|
43
31
|
* ```ts
|
|
44
32
|
* import { Effect } from "effect"
|
|
@@ -50,17 +38,13 @@ export function makeState(initial = {}) {
|
|
|
50
38
|
* })
|
|
51
39
|
* ```
|
|
52
40
|
* @since 1.0.0
|
|
53
|
-
* @category
|
|
41
|
+
* @category State transitions
|
|
54
42
|
*/
|
|
55
43
|
export function setChecked(state, checked) {
|
|
56
44
|
return RefSubject.update(state, (current) => ({ ...current, checked }));
|
|
57
45
|
}
|
|
58
|
-
/**
|
|
59
|
-
*
|
|
60
|
-
* ## Why
|
|
61
|
-
* A RefSubject update prevents stale read-then-write transitions.
|
|
62
|
-
* ## Ownership and lifetime
|
|
63
|
-
* The Effect acquires no resource and uses the existing state Scope.
|
|
46
|
+
/**
|
|
47
|
+
* Toggles the switch between checked and unchecked.
|
|
64
48
|
* @example
|
|
65
49
|
* ```ts
|
|
66
50
|
* import { Effect } from "effect"
|
|
@@ -72,7 +56,7 @@ export function setChecked(state, checked) {
|
|
|
72
56
|
* })
|
|
73
57
|
* ```
|
|
74
58
|
* @since 1.0.0
|
|
75
|
-
* @category
|
|
59
|
+
* @category State transitions
|
|
76
60
|
*/
|
|
77
61
|
export function toggle(state) {
|
|
78
62
|
return RefSubject.update(state, (current) => ({ ...current, checked: !current.checked }));
|
|
@@ -87,27 +71,37 @@ function internalProps(options) {
|
|
|
87
71
|
ref: options.state,
|
|
88
72
|
});
|
|
89
73
|
}
|
|
90
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Renders a button-backed ARIA switch.
|
|
91
76
|
* @remarks
|
|
92
|
-
* ## Why
|
|
93
77
|
* The component combines native button activation with a renderer-independent
|
|
94
78
|
* boolean state and real DOM click events.
|
|
95
|
-
* ## Ownership and lifetime
|
|
96
79
|
* Running the Fx owns listener/state subscriptions in its Effect Scope. A
|
|
97
80
|
* custom host must preserve button type, role, `aria-checked`, click handler,
|
|
98
81
|
* and the single hydration ref owner.
|
|
99
82
|
* @example
|
|
100
83
|
* ```ts
|
|
101
|
-
* import {
|
|
102
|
-
* import
|
|
84
|
+
* import { RefSubject } from "@typed/fx";
|
|
85
|
+
* import { html } from "@typed/template";
|
|
86
|
+
* import { component } from "@typed/ui/Component";
|
|
87
|
+
* import * as Switch from "@typed/ui/Switch";
|
|
103
88
|
*
|
|
104
|
-
* const
|
|
105
|
-
* const state = yield* Switch.makeState()
|
|
106
|
-
*
|
|
107
|
-
*
|
|
89
|
+
* export const PreviewSetting = component(function* () {
|
|
90
|
+
* const state = yield* Switch.makeState({ checked: true });
|
|
91
|
+
* const status = RefSubject.map(state, ({ checked }) => checked ? "On" : "Off");
|
|
92
|
+
* return html`<section>
|
|
93
|
+
* ${Switch.Switch({
|
|
94
|
+
* state,
|
|
95
|
+
* content: "Show live preview",
|
|
96
|
+
* props: { class: "preview-switch", "aria-describedby": "preview-setting-help" },
|
|
97
|
+
* })}
|
|
98
|
+
* <span aria-hidden="true">${status}</span>
|
|
99
|
+
* <p id="preview-setting-help">Updates the preview while you edit.</p>
|
|
100
|
+
* </section>`;
|
|
101
|
+
* });
|
|
108
102
|
* ```
|
|
109
103
|
* @since 1.0.0
|
|
110
|
-
* @category
|
|
104
|
+
* @category Native controls
|
|
111
105
|
*/
|
|
112
106
|
export function Switch(options, host) {
|
|
113
107
|
return Dom.renderHost()(options, host, internalProps(options), options.content, (props, content) => {
|