@typed/ui 1.0.0-beta.6 → 1.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/Alert.d.ts +35 -41
  2. package/dist/Alert.d.ts.map +1 -1
  3. package/dist/Alert.js +23 -20
  4. package/dist/Button.d.ts +34 -78
  5. package/dist/Button.d.ts.map +1 -1
  6. package/dist/Button.js +16 -12
  7. package/dist/Carousel.d.ts +35 -236
  8. package/dist/Carousel.d.ts.map +1 -1
  9. package/dist/Carousel.js +13 -136
  10. package/dist/Checkbox.d.ts +55 -90
  11. package/dist/Checkbox.d.ts.map +1 -1
  12. package/dist/Checkbox.js +44 -38
  13. package/dist/Collection.d.ts +15 -15
  14. package/dist/Collection.js +7 -7
  15. package/dist/Combobox.d.ts +38 -187
  16. package/dist/Combobox.d.ts.map +1 -1
  17. package/dist/Combobox.js +9 -80
  18. package/dist/Component.d.ts +30 -24
  19. package/dist/Component.d.ts.map +1 -1
  20. package/dist/Component.js +23 -12
  21. package/dist/Composite.d.ts +50 -50
  22. package/dist/Composite.js +20 -20
  23. package/dist/Dialog.d.ts +34 -34
  24. package/dist/Dialog.d.ts.map +1 -1
  25. package/dist/Dialog.js +16 -14
  26. package/dist/Disclosure.d.ts +15 -15
  27. package/dist/Disclosure.js +6 -6
  28. package/dist/Dom/Events.d.ts +4 -4
  29. package/dist/Dom/Events.js +4 -4
  30. package/dist/Dom/Props.d.ts +9 -9
  31. package/dist/Dom/Props.js +4 -4
  32. package/dist/Dom/Refs.d.ts +2 -2
  33. package/dist/Dom/Refs.js +1 -1
  34. package/dist/Dom/Render.d.ts +2 -2
  35. package/dist/Dom/Render.js +2 -2
  36. package/dist/Dom/Types.d.ts +33 -33
  37. package/dist/Dom/index.d.ts +5 -5
  38. package/dist/Dom/index.d.ts.map +1 -1
  39. package/dist/Dom/index.js +4 -4
  40. package/dist/Dom.d.ts +1 -1
  41. package/dist/Dom.js +1 -1
  42. package/dist/Focusable.d.ts +5 -5
  43. package/dist/Focusable.js +1 -1
  44. package/dist/Form.d.ts +565 -533
  45. package/dist/Form.d.ts.map +1 -1
  46. package/dist/Form.js +350 -195
  47. package/dist/Grid.d.ts +39 -220
  48. package/dist/Grid.d.ts.map +1 -1
  49. package/dist/Grid.js +12 -107
  50. package/dist/Group.d.ts +50 -69
  51. package/dist/Group.d.ts.map +1 -1
  52. package/dist/Group.js +33 -25
  53. package/dist/Heading.d.ts +41 -40
  54. package/dist/Heading.d.ts.map +1 -1
  55. package/dist/Heading.js +26 -16
  56. package/dist/Hovercard.d.ts +18 -18
  57. package/dist/Hovercard.js +6 -6
  58. package/dist/HttpRouter.d.ts +3 -3
  59. package/dist/HttpRouter.js +5 -5
  60. package/dist/Link.d.ts +17 -21
  61. package/dist/Link.d.ts.map +1 -1
  62. package/dist/Link.js +11 -0
  63. package/dist/Listbox.d.ts +31 -163
  64. package/dist/Listbox.d.ts.map +1 -1
  65. package/dist/Listbox.js +9 -80
  66. package/dist/Menu.d.ts +67 -376
  67. package/dist/Menu.d.ts.map +1 -1
  68. package/dist/Menu.js +17 -179
  69. package/dist/Menubar.d.ts +24 -142
  70. package/dist/Menubar.d.ts.map +1 -1
  71. package/dist/Menubar.js +8 -66
  72. package/dist/Meter.d.ts +72 -132
  73. package/dist/Meter.d.ts.map +1 -1
  74. package/dist/Meter.js +35 -42
  75. package/dist/NativeDetails.d.ts +1 -1
  76. package/dist/NativeDetails.js +1 -1
  77. package/dist/NativeDialog.d.ts +7 -5
  78. package/dist/NativeDialog.d.ts.map +1 -1
  79. package/dist/NativeDialog.js +42 -4
  80. package/dist/NativePopover.d.ts +6 -4
  81. package/dist/NativePopover.d.ts.map +1 -1
  82. package/dist/NativePopover.js +43 -5
  83. package/dist/Popover.d.ts +18 -19
  84. package/dist/Popover.d.ts.map +1 -1
  85. package/dist/Popover.js +7 -8
  86. package/dist/RadioGroup.d.ts +86 -188
  87. package/dist/RadioGroup.d.ts.map +1 -1
  88. package/dist/RadioGroup.js +55 -105
  89. package/dist/Role.d.ts +4 -4
  90. package/dist/Role.js +1 -1
  91. package/dist/Select.d.ts +109 -220
  92. package/dist/Select.d.ts.map +1 -1
  93. package/dist/Select.js +67 -117
  94. package/dist/Separator.d.ts +30 -26
  95. package/dist/Separator.d.ts.map +1 -1
  96. package/dist/Separator.js +16 -10
  97. package/dist/Slider.d.ts +64 -111
  98. package/dist/Slider.d.ts.map +1 -1
  99. package/dist/Slider.js +47 -42
  100. package/dist/SpinButton.d.ts +64 -111
  101. package/dist/SpinButton.d.ts.map +1 -1
  102. package/dist/SpinButton.js +47 -42
  103. package/dist/Storybook.d.ts +2 -2
  104. package/dist/Storybook.js +1 -1
  105. package/dist/Switch.d.ts +52 -91
  106. package/dist/Switch.d.ts.map +1 -1
  107. package/dist/Switch.js +30 -36
  108. package/dist/Tabs.d.ts +44 -224
  109. package/dist/Tabs.d.ts.map +1 -1
  110. package/dist/Tabs.js +10 -94
  111. package/dist/Toolbar.d.ts +24 -142
  112. package/dist/Toolbar.d.ts.map +1 -1
  113. package/dist/Toolbar.js +8 -66
  114. package/dist/Tooltip.d.ts +20 -20
  115. package/dist/Tooltip.js +6 -6
  116. package/dist/Tree.d.ts +43 -229
  117. package/dist/Tree.d.ts.map +1 -1
  118. package/dist/Tree.js +12 -113
  119. package/dist/TreeGrid.d.ts +45 -264
  120. package/dist/TreeGrid.d.ts.map +1 -1
  121. package/dist/TreeGrid.js +13 -125
  122. package/dist/VisuallyHidden.d.ts +41 -27
  123. package/dist/VisuallyHidden.d.ts.map +1 -1
  124. package/dist/VisuallyHidden.js +27 -10
  125. package/dist/WindowSplitter.d.ts +68 -108
  126. package/dist/WindowSplitter.d.ts.map +1 -1
  127. package/dist/WindowSplitter.js +106 -23
  128. package/package.json +9 -8
package/dist/Carousel.js CHANGED
@@ -8,6 +8,8 @@
8
8
  * the state and pure operations without mounting UI, or supply custom hosts without replacing native
9
9
  * events and browser-owned focus.
10
10
  *
11
+ * Learn the interaction in the [Carousel guide](/explore/ui-carousel).
12
+ *
11
13
  * @since 1.0.0
12
14
  * @category modules
13
15
  * @packageDocumentation
@@ -23,15 +25,6 @@ import * as Dom from "./Dom.js";
23
25
  * Effect Schema used by makeState to encode, decode, and hydrate Carousel state.
24
26
  *
25
27
  * @remarks
26
- * ## Why
27
- *
28
- * A public schema makes hydration and serialized state use the same runtime validation as direct
29
- * construction.
30
- *
31
- * ## Ownership and lifetime
32
- *
33
- * This declaration is data or schema metadata and acquires no resources.
34
- *
35
28
  * @example
36
29
  * ```ts
37
30
  * import * as Schema from "effect/Schema";
@@ -40,19 +33,13 @@ import * as Dom from "./Dom.js";
40
33
  * const decodeState = Schema.decodeUnknownEffect(Carousel.StateSchema);
41
34
  * ```
42
35
  * @since 1.0.0
43
- * @category schemas
36
+ * @category Slide and rotation state
44
37
  */
45
38
  export const StateSchema = Schema.Struct({ activeId: Schema.String, paused: Schema.Boolean });
46
39
  /**
47
40
  * Creates hydrated Carousel state. activeId is required and paused defaults to true.
48
41
  *
49
42
  * @remarks
50
- * ## Why
51
- *
52
- * State and collection ownership can be composed and tested independently from any renderer.
53
- *
54
- * ## Ownership and lifetime
55
- *
56
43
  * The returned Effect creates the RefSubject when run. That state is renderer-independent;
57
44
  * collection registrations belong to the separate Scope that runs register or ref, not to state
58
45
  * creation.
@@ -71,7 +58,7 @@ export const StateSchema = Schema.Struct({ activeId: Schema.String, paused: Sche
71
58
  * );
72
59
  * ```
73
60
  * @since 1.0.0
74
- * @category constructors
61
+ * @category Slide and rotation state
75
62
  */
76
63
  export function makeState(initial) {
77
64
  return RefSubject.hydrate(StateSchema, {
@@ -83,12 +70,6 @@ export function makeState(initial) {
83
70
  * Creates a scoped Collection for Carousel items.
84
71
  *
85
72
  * @remarks
86
- * ## Why
87
- *
88
- * State and collection ownership can be composed and tested independently from any renderer.
89
- *
90
- * ## Ownership and lifetime
91
- *
92
73
  * The returned Effect allocates the RefSubject in the caller's Scope. Each later registration is
93
74
  * owned by the Scope that runs register, independently of this construction Effect.
94
75
  *
@@ -105,31 +86,18 @@ export function makeState(initial) {
105
86
  * );
106
87
  * ```
107
88
  * @since 1.0.0
108
- * @category constructors
89
+ * @category Slide registration
109
90
  */
110
91
  export const makeCollection = Collection.makeState;
111
92
  /**
112
93
  * Sets activeId without changing paused state.
113
94
  *
114
95
  * @remarks
115
- * ## Why
116
- *
117
96
  * The operation exposes Carousel's transition directly so callers can compose it in Effect
118
97
  * programs and native event handlers.
119
98
  *
120
- * ## Ownership and lifetime
121
- *
122
- * The returned Effect performs the update or DOM side effect only when run, preserves the declared
123
- * error and service channels, and retains no resources after completion.
124
- *
125
- * ## Example
126
- *
127
- * Import with `import { select } from "@typed/ui/Carousel";` Extend the [Carousel.makeState
128
- * runnable setup](/reference/%40typed%2Fui%2FCarousel%23makeState). Inside the linked Effect
129
- * program invoke `yield* select(state, "slide-2")`, then read state to observe `activeId` become
130
- * `"slide-2"` without changing `paused`.
131
99
  * @since 1.0.0
132
- * @category combinators
100
+ * @category Slide navigation
133
101
  */
134
102
  export function select(state, activeId) {
135
103
  return RefSubject.update(state, (current) => ({ ...current, activeId }));
@@ -139,24 +107,11 @@ export function select(state, activeId) {
139
107
  * for an empty collection.
140
108
  *
141
109
  * @remarks
142
- * ## Why
143
- *
144
110
  * The operation exposes Carousel's transition directly so callers can compose it in Effect
145
111
  * programs and native event handlers.
146
112
  *
147
- * ## Ownership and lifetime
148
- *
149
- * The returned Effect performs the update or DOM side effect only when run, preserves the declared
150
- * error and service channels, and retains no resources after completion.
151
- *
152
- * ## Example
153
- *
154
- * Import with `import { move } from "@typed/ui/Carousel";` Extend the [Carousel.makeState runnable
155
- * setup](/reference/%40typed%2Fui%2FCarousel%23makeState). Inside the linked Effect program invoke
156
- * `yield* move(state, collection, "next")`, then read the state snapshot to observe the transition
157
- * described above.
158
113
  * @since 1.0.0
159
- * @category combinators
114
+ * @category Slide navigation
160
115
  */
161
116
  export function move(state, collection, direction) {
162
117
  return Effect.gen(function* () {
@@ -168,24 +123,11 @@ export function move(state, collection, direction) {
168
123
  * Flips paused and preserves activeId.
169
124
  *
170
125
  * @remarks
171
- * ## Why
172
- *
173
126
  * The operation exposes Carousel's transition directly so callers can compose it in Effect
174
127
  * programs and native event handlers.
175
128
  *
176
- * ## Ownership and lifetime
177
- *
178
- * The returned Effect performs the update or DOM side effect only when run, preserves the declared
179
- * error and service channels, and retains no resources after completion.
180
- *
181
- * ## Example
182
- *
183
- * Import with `import { toggleRotation } from "@typed/ui/Carousel";` Extend the [Carousel.makeState
184
- * runnable setup](/reference/%40typed%2Fui%2FCarousel%23makeState). Inside the linked Effect
185
- * program invoke `yield* toggleRotation(state)`, then read state to observe `paused` invert without
186
- * changing `activeId`.
187
129
  * @since 1.0.0
188
- * @category combinators
130
+ * @category Rotation policy
189
131
  */
190
132
  export function toggleRotation(state) {
191
133
  return RefSubject.update(state, (current) => ({ ...current, paused: !current.paused }));
@@ -221,25 +163,12 @@ function rootInternalProps(options) {
221
163
  * replacing its child nodes.
222
164
  *
223
165
  * @remarks
224
- * ## Why
225
- *
226
- * The component applies the family behavior while leaving callers free to supply a custom host
227
- * through the shared DOM boundary.
228
- *
229
- * ## Ownership and lifetime
230
- *
231
166
  * The returned Fx installs DOM refs, native listeners, state subscriptions, and optional
232
167
  * collection registrations only when rendered. The rendering Scope removes those resources;
233
168
  * unrelated nodes and attributes remain caller-owned.
234
169
  *
235
- * ## Example
236
- *
237
- * Import with `import { Root } from "@typed/ui/Carousel";` Extend the [Carousel.makeState runnable
238
- * setup](/reference/%40typed%2Fui%2FCarousel%23makeState). Replace the linked program's final
239
- * snapshot read with `Root({ state, content: "Slides", label: "Featured" })`; render that Fx before
240
- * the same Scope closes.
241
170
  * @since 1.0.0
242
- * @category components
171
+ * @category Carousel region
243
172
  */
244
173
  export function Root(options, host) {
245
174
  return Dom.renderHost()(options, host, rootInternalProps(options), options.content, (props, content) => {
@@ -268,25 +197,12 @@ function slideInternalProps(options) {
268
197
  * activeId.
269
198
  *
270
199
  * @remarks
271
- * ## Why
272
- *
273
- * The component applies the family behavior while leaving callers free to supply a custom host
274
- * through the shared DOM boundary.
275
- *
276
- * ## Ownership and lifetime
277
- *
278
200
  * The returned Fx installs DOM refs, native listeners, state subscriptions, and optional
279
201
  * collection registrations only when rendered. The rendering Scope removes those resources;
280
202
  * unrelated nodes and attributes remain caller-owned.
281
203
  *
282
- * ## Example
283
- *
284
- * Import with `import { Slide } from "@typed/ui/Carousel";` Extend the [Carousel.makeState runnable
285
- * setup](/reference/%40typed%2Fui%2FCarousel%23makeState). Replace the linked program's final
286
- * snapshot read with `Slide({ state, id: "slide-1", label: "1 of 3", content: "First slide" })`;
287
- * render that Fx before the same Scope closes.
288
204
  * @since 1.0.0
289
- * @category components
205
+ * @category Slide content
290
206
  */
291
207
  export function Slide(options, host) {
292
208
  return Dom.renderHost()(options, host, slideInternalProps(options), options.content, (props, content) => {
@@ -304,25 +220,12 @@ function control(options, host, action) {
304
220
  * Renders a button whose native click selects the previous registered slide with wrapping enabled.
305
221
  *
306
222
  * @remarks
307
- * ## Why
308
- *
309
- * The component applies the family behavior while leaving callers free to supply a custom host
310
- * through the shared DOM boundary.
311
- *
312
- * ## Ownership and lifetime
313
- *
314
223
  * The returned Fx installs DOM refs, native listeners, state subscriptions, and optional
315
224
  * collection registrations only when rendered. The rendering Scope removes those resources;
316
225
  * unrelated nodes and attributes remain caller-owned.
317
226
  *
318
- * ## Example
319
- *
320
- * Import with `import { Previous } from "@typed/ui/Carousel";` Extend the [Carousel.makeState
321
- * runnable setup](/reference/%40typed%2Fui%2FCarousel%23makeState). Replace the linked program's
322
- * final snapshot read with `Previous({ state, content: "Previous" })`; render that Fx before the
323
- * same Scope closes.
324
227
  * @since 1.0.0
325
- * @category components
228
+ * @category Slide controls
326
229
  */
327
230
  export function Previous(options, host) {
328
231
  return control(options, host, options.collection === undefined
@@ -333,25 +236,12 @@ export function Previous(options, host) {
333
236
  * Renders a button whose native click selects the next registered slide with wrapping enabled.
334
237
  *
335
238
  * @remarks
336
- * ## Why
337
- *
338
- * The component applies the family behavior while leaving callers free to supply a custom host
339
- * through the shared DOM boundary.
340
- *
341
- * ## Ownership and lifetime
342
- *
343
239
  * The returned Fx installs DOM refs, native listeners, state subscriptions, and optional
344
240
  * collection registrations only when rendered. The rendering Scope removes those resources;
345
241
  * unrelated nodes and attributes remain caller-owned.
346
242
  *
347
- * ## Example
348
- *
349
- * Import with `import { Next } from "@typed/ui/Carousel";` Extend the [Carousel.makeState runnable
350
- * setup](/reference/%40typed%2Fui%2FCarousel%23makeState). Replace the linked program's final
351
- * snapshot read with `Next({ state, content: "Next" })`; render that Fx before the same Scope
352
- * closes.
353
243
  * @since 1.0.0
354
- * @category components
244
+ * @category Slide controls
355
245
  */
356
246
  export function Next(options, host) {
357
247
  return control(options, host, options.collection === undefined
@@ -362,25 +252,12 @@ export function Next(options, host) {
362
252
  * Renders a button whose native click toggles the explicit paused state.
363
253
  *
364
254
  * @remarks
365
- * ## Why
366
- *
367
- * The component applies the family behavior while leaving callers free to supply a custom host
368
- * through the shared DOM boundary.
369
- *
370
- * ## Ownership and lifetime
371
- *
372
255
  * The returned Fx installs DOM refs, native listeners, state subscriptions, and optional
373
256
  * collection registrations only when rendered. The rendering Scope removes those resources;
374
257
  * unrelated nodes and attributes remain caller-owned.
375
258
  *
376
- * ## Example
377
- *
378
- * Import with `import { RotationControl } from "@typed/ui/Carousel";` Extend the
379
- * [Carousel.makeState runnable setup](/reference/%40typed%2Fui%2FCarousel%23makeState). Replace the
380
- * linked program's final snapshot read with `RotationControl({ state, content: "Pause rotation"
381
- * })`; render that Fx before the same Scope closes.
382
259
  * @since 1.0.0
383
- * @category components
260
+ * @category Rotation policy
384
261
  */
385
262
  export function RotationControl(options, host) {
386
263
  return control(options, host, toggleRotation(options.state));
@@ -1,81 +1,54 @@
1
+ /**
2
+ * A native checkbox synchronized with boolean or mixed state.
3
+ * The checked and indeterminate properties are separate; mixed is not a submitted third value.
4
+ *
5
+ * Read the [Checkbox guide](/explore/ui-checkbox) for a complete example.
6
+ *
7
+ * [APG interaction reference](https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/).
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 { EventHandler } from "@typed/template";
5
16
  import * as Dom from "./Dom.js";
6
17
  import type { HostResult } from "./Dom/Types.js";
7
- /** Three-state value accepted by a checkbox.
8
- * @remarks
9
- * ## Why
10
- * `"mixed"` models the platform's indeterminate presentation without
11
- * conflating it with either submitted boolean state.
12
- * ## Ownership and lifetime
13
- * This pure type acquires no resources.
14
- * @since 1.0.0
15
- * @category models
18
+ /**
16
19
  */
17
20
  export type Checked = boolean | "mixed";
18
- /** Current renderer-independent checkbox state.
21
+ /**
22
+ * Current renderer-independent checkbox state.
19
23
  * @remarks
20
- * ## Why
21
24
  * State can be updated and tested through RefSubject before any input mounts.
22
- * ## Ownership and lifetime
23
25
  * The value is plain data; the hydrated RefSubject returned by `makeState`
24
26
  * owns observation for its Effect Scope.
25
27
  * @since 1.0.0
26
- * @category state
28
+ * @category State models
27
29
  */
28
30
  export interface State {
29
- /** Current checked or mixed value.
30
- * @remarks
31
- * ## Why
32
- * One field drives `checked`, `indeterminate`, and `aria-checked` together.
33
- * ## Ownership and lifetime
34
- * Plain state retains no resources.
35
- * @since 1.0.0
36
- * @category state
31
+ /**
37
32
  */
38
33
  readonly checked: Checked;
39
34
  }
40
- /** Initial checkbox state accepted by `makeState`.
41
- * @remarks
42
- * ## Why
43
- * The optional value gives uncontrolled creation a deterministic false default.
44
- * ## Ownership and lifetime
45
- * This configuration is inert and retains no resources.
46
- * @since 1.0.0
47
- * @category state
35
+ /**
48
36
  */
49
37
  export interface InitialState {
50
- /** Initial checked value; defaults to `false`.
51
- * @remarks
52
- * ## Why
53
- * Explicit mixed state can survive SSR hydration.
54
- * ## Ownership and lifetime
55
- * The value is copied into hydrated state and retains no resource.
56
- * @since 1.0.0
57
- * @category state
38
+ /**
58
39
  */
59
40
  readonly checked?: Checked;
60
41
  }
61
- /** Schema used to encode and hydrate checkbox state.
62
- * @remarks
63
- * ## Why
64
- * A shared schema keeps server and client state shape identical.
65
- * ## Ownership and lifetime
66
- * The schema is immutable and acquires no resources.
67
- * @since 1.0.0
68
- * @category schemas
42
+ /**
69
43
  */
70
44
  export declare const StateSchema: Schema.Struct<{
71
45
  readonly checked: Schema.Literals<readonly [true, false, "mixed"]>;
72
46
  }>;
73
- /** Creates hydrated, renderer-independent checkbox state.
47
+ /**
48
+ * Creates hydrated, renderer-independent checkbox state.
74
49
  * @remarks
75
- * ## Why
76
50
  * State transitions remain testable without rendering and can be consumed by
77
51
  * any UI producer.
78
- * ## Ownership and lifetime
79
52
  * The caller's Effect Scope owns the hydrated RefSubject and its subscriptions.
80
53
  * @example
81
54
  * ```ts
@@ -87,16 +60,15 @@ export declare const StateSchema: Schema.Struct<{
87
60
  * })
88
61
  * ```
89
62
  * @since 1.0.0
90
- * @category constructors
63
+ * @category State construction
91
64
  */
92
65
  export declare function makeState(initial?: InitialState): Effect.Effect<RefSubject.HydratedRefSubject<{
93
66
  readonly checked: "mixed" | boolean;
94
67
  }, Schema.SchemaError, never, never>, never, import("effect/Scope").Scope>;
95
- /** Sets the checkbox state to a boolean or mixed value.
68
+ /**
69
+ * Sets the checkbox state to a boolean or mixed value.
96
70
  * @remarks
97
- * ## Why
98
71
  * A single atomic RefSubject update keeps DOM properties and ARIA state aligned.
99
- * ## Ownership and lifetime
100
72
  * The Effect uses the existing subject lifetime and acquires no new resource.
101
73
  * @example
102
74
  * ```ts
@@ -109,16 +81,11 @@ export declare function makeState(initial?: InitialState): Effect.Effect<RefSubj
109
81
  * })
110
82
  * ```
111
83
  * @since 1.0.0
112
- * @category state
84
+ * @category State transitions
113
85
  */
114
86
  export declare function setChecked<E, R>(state: RefSubject.RefSubject<State, E, R>, checked: Checked): Effect.Effect<State, E, R>;
115
- /** Toggles checked to false and false or mixed to true.
116
- * @remarks
117
- * ## Why
118
- * User activation of an indeterminate checkbox resolves to a concrete checked
119
- * state, matching native input behavior.
120
- * ## Ownership and lifetime
121
- * The Effect updates the existing RefSubject and acquires no resource.
87
+ /**
88
+ * Toggles checked state, treating the mixed state as unchecked.
122
89
  * @example
123
90
  * ```ts
124
91
  * import { Effect } from "effect"
@@ -130,27 +97,16 @@ export declare function setChecked<E, R>(state: RefSubject.RefSubject<State, E,
130
97
  * })
131
98
  * ```
132
99
  * @since 1.0.0
133
- * @category state
100
+ * @category State transitions
134
101
  */
135
102
  export declare function toggle<E, R>(state: RefSubject.RefSubject<State, E, R>): Effect.Effect<State, E, R>;
136
- /** Options for the native checkbox input.
137
- * @remarks
138
- * ## Why
139
- * The state reference is the single source for native and ARIA checked values.
140
- * ## Ownership and lifetime
141
- * Options are inert; the component Scope owns DOM subscriptions and refs.
142
- * @since 1.0.0
143
- * @category models
103
+ /**
144
104
  */
145
105
  export interface InputOptions extends Dom.HostOptions<HTMLInputElement> {
146
- /** Hydrated state synchronized with the input.
147
- * @remarks
148
- * ## Why
149
- * Hydration preserves checked identity and enables state-only tests.
150
- * ## Ownership and lifetime
151
- * The input borrows the RefSubject; its original Scope remains the owner.
106
+ /**
107
+ * Hydrated state synchronized with the input.
152
108
  * @since 1.0.0
153
- * @category state
109
+ * @category State connection
154
110
  */
155
111
  readonly state: RefSubject.HydratedRefSubject<State, Schema.SchemaError>;
156
112
  }
@@ -166,37 +122,46 @@ declare function internalProps<const Options extends InputOptions>(options: Opti
166
122
  ref: RefSubject.HydratedRefSubject<State, Schema.SchemaError, never, never>;
167
123
  };
168
124
  type InputInternalProps<Options extends InputOptions> = ReturnType<ReturnType<typeof internalProps<Options>>>;
169
- /** Renders a native checkbox input synchronized with hydrated state.
125
+ /**
126
+ * Renders a native checkbox input synchronized with hydrated state.
170
127
  * @remarks
171
- * ## Why
172
128
  * Native keyboard, form, disabled, required, and accessibility behavior remain
173
129
  * available while state is exposed through RefSubject.
174
- * ## Ownership and lifetime
175
130
  * Running the Fx installs native listeners and state subscriptions in its
176
131
  * Scope. A custom host must apply `type`, checked, indeterminate, ARIA, and ref
177
132
  * props; only one hydration owner may be composed for the element.
178
133
  * @example
179
134
  * ```ts
180
- * import { Effect } from "effect"
181
- * import * as Checkbox from "@typed/ui/Checkbox"
135
+ * import { RefSubject } from "@typed/fx";
136
+ * import { html } from "@typed/template";
137
+ * import * as Checkbox from "@typed/ui/Checkbox";
138
+ * import { component } from "@typed/ui/Component";
182
139
  *
183
- * const program = Effect.gen(function* () {
184
- * const state = yield* Checkbox.makeState()
185
- * return Checkbox.Input({ state })
186
- * })
140
+ * export const UpdatePreference = component(function* () {
141
+ * const state = yield* Checkbox.makeState({ checked: false });
142
+ * const message = RefSubject.map(state, ({ checked }) =>
143
+ * checked === true ? "Product updates enabled" : "Product updates disabled",
144
+ * );
145
+ * return html`<div class="preference">
146
+ * <label>
147
+ * ${Checkbox.Input({ state, props: { name: "updates", value: "yes" } })}
148
+ * Receive product updates
149
+ * </label>
150
+ * <p>${message}</p>
151
+ * </div>`;
152
+ * });
187
153
  * ```
188
154
  * @since 1.0.0
189
- * @category components
155
+ * @category Native controls
190
156
  */
191
157
  export declare function Input<const Options extends InputOptions, const Host extends HostResult = never>(options: Options, host?: Dom.HostOverride<Dom.RenderHostProps<Options, InputInternalProps<Options>>, "", Host>): import("./Dom/Types.js").HostComponent<Host | Options>;
192
- /** Canonical component alias for `Input`.
158
+ /**
159
+ * Canonical component alias for `Input`.
193
160
  * @remarks
194
- * ## Why
195
161
  * The alias provides the widget name while retaining the explicit input API.
196
- * ## Ownership and lifetime
197
162
  * It has exactly the same Scope and native-element ownership as `Input`.
198
163
  * @since 1.0.0
199
- * @category aliases
164
+ * @category Native controls
200
165
  */
201
166
  export declare const Checkbox: typeof Input;
202
167
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Checkbox.d.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AAC,OAAO,SAAS,YAAY,EAAE,OAAO,EAAE,OAAO,kBASnD,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC;IACrD,IAAI;IACJ,cAAc;IACd,UAAU;IACV,UAAU;IACV,WAAW;IACX,WAAW;IACX,gBAAgB;IAChB,QAAQ;IACR,GAAG;EAEN;AAED,KAAK,kBAAkB,CAAC,OAAO,SAAS,YAAY,IAAI,UAAU,CAChE,UAAU,CAAC,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC,CAC1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,KAAK,CAAC,KAAK,CAAC,OAAO,SAAS,YAAY,EAAE,KAAK,CAAC,IAAI,SAAS,UAAU,GAAG,KAAK,EAC7F,OAAO,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,eAAe,CAAC,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,0DAW7F;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,cAAQ,CAAC"}
package/dist/Checkbox.js CHANGED
@@ -1,26 +1,29 @@
1
+ /**
2
+ * A native checkbox synchronized with boolean or mixed state.
3
+ * The checked and indeterminate properties are separate; mixed is not a submitted third value.
4
+ *
5
+ * Read the [Checkbox guide](/explore/ui-checkbox) for a complete example.
6
+ *
7
+ * [APG interaction reference](https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/).
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 { EventHandler, html } from "@typed/template";
5
16
  import * as Dom from "./Dom.js";
6
- /** Schema used to encode and hydrate checkbox state.
7
- * @remarks
8
- * ## Why
9
- * A shared schema keeps server and client state shape identical.
10
- * ## Ownership and lifetime
11
- * The schema is immutable and acquires no resources.
12
- * @since 1.0.0
13
- * @category schemas
17
+ /**
14
18
  */
15
19
  export const StateSchema = Schema.Struct({
16
20
  checked: Schema.Literals([true, false, "mixed"]),
17
21
  });
18
- /** Creates hydrated, renderer-independent checkbox state.
22
+ /**
23
+ * Creates hydrated, renderer-independent checkbox state.
19
24
  * @remarks
20
- * ## Why
21
25
  * State transitions remain testable without rendering and can be consumed by
22
26
  * any UI producer.
23
- * ## Ownership and lifetime
24
27
  * The caller's Effect Scope owns the hydrated RefSubject and its subscriptions.
25
28
  * @example
26
29
  * ```ts
@@ -32,16 +35,15 @@ export const StateSchema = Schema.Struct({
32
35
  * })
33
36
  * ```
34
37
  * @since 1.0.0
35
- * @category constructors
38
+ * @category State construction
36
39
  */
37
40
  export function makeState(initial = {}) {
38
41
  return RefSubject.hydrate(StateSchema, { checked: initial.checked ?? false });
39
42
  }
40
- /** Sets the checkbox state to a boolean or mixed value.
43
+ /**
44
+ * Sets the checkbox state to a boolean or mixed value.
41
45
  * @remarks
42
- * ## Why
43
46
  * A single atomic RefSubject update keeps DOM properties and ARIA state aligned.
44
- * ## Ownership and lifetime
45
47
  * The Effect uses the existing subject lifetime and acquires no new resource.
46
48
  * @example
47
49
  * ```ts
@@ -54,18 +56,13 @@ export function makeState(initial = {}) {
54
56
  * })
55
57
  * ```
56
58
  * @since 1.0.0
57
- * @category state
59
+ * @category State transitions
58
60
  */
59
61
  export function setChecked(state, checked) {
60
62
  return RefSubject.update(state, (current) => ({ ...current, checked }));
61
63
  }
62
- /** Toggles checked to false and false or mixed to true.
63
- * @remarks
64
- * ## Why
65
- * User activation of an indeterminate checkbox resolves to a concrete checked
66
- * state, matching native input behavior.
67
- * ## Ownership and lifetime
68
- * The Effect updates the existing RefSubject and acquires no resource.
64
+ /**
65
+ * Toggles checked state, treating the mixed state as unchecked.
69
66
  * @example
70
67
  * ```ts
71
68
  * import { Effect } from "effect"
@@ -77,7 +74,7 @@ export function setChecked(state, checked) {
77
74
  * })
78
75
  * ```
79
76
  * @since 1.0.0
80
- * @category state
77
+ * @category State transitions
81
78
  */
82
79
  export function toggle(state) {
83
80
  return RefSubject.update(state, (current) => ({
@@ -101,40 +98,49 @@ function internalProps(options) {
101
98
  ref: options.state,
102
99
  });
103
100
  }
104
- /** Renders a native checkbox input synchronized with hydrated state.
101
+ /**
102
+ * Renders a native checkbox input synchronized with hydrated state.
105
103
  * @remarks
106
- * ## Why
107
104
  * Native keyboard, form, disabled, required, and accessibility behavior remain
108
105
  * available while state is exposed through RefSubject.
109
- * ## Ownership and lifetime
110
106
  * Running the Fx installs native listeners and state subscriptions in its
111
107
  * Scope. A custom host must apply `type`, checked, indeterminate, ARIA, and ref
112
108
  * props; only one hydration owner may be composed for the element.
113
109
  * @example
114
110
  * ```ts
115
- * import { Effect } from "effect"
116
- * import * as Checkbox from "@typed/ui/Checkbox"
111
+ * import { RefSubject } from "@typed/fx";
112
+ * import { html } from "@typed/template";
113
+ * import * as Checkbox from "@typed/ui/Checkbox";
114
+ * import { component } from "@typed/ui/Component";
117
115
  *
118
- * const program = Effect.gen(function* () {
119
- * const state = yield* Checkbox.makeState()
120
- * return Checkbox.Input({ state })
121
- * })
116
+ * export const UpdatePreference = component(function* () {
117
+ * const state = yield* Checkbox.makeState({ checked: false });
118
+ * const message = RefSubject.map(state, ({ checked }) =>
119
+ * checked === true ? "Product updates enabled" : "Product updates disabled",
120
+ * );
121
+ * return html`<div class="preference">
122
+ * <label>
123
+ * ${Checkbox.Input({ state, props: { name: "updates", value: "yes" } })}
124
+ * Receive product updates
125
+ * </label>
126
+ * <p>${message}</p>
127
+ * </div>`;
128
+ * });
122
129
  * ```
123
130
  * @since 1.0.0
124
- * @category components
131
+ * @category Native controls
125
132
  */
126
133
  export function Input(options, host) {
127
134
  return Dom.renderHost()(options, host, internalProps(options), "", (i) => {
128
135
  return html `<input ...${i} />`;
129
136
  });
130
137
  }
131
- /** Canonical component alias for `Input`.
138
+ /**
139
+ * Canonical component alias for `Input`.
132
140
  * @remarks
133
- * ## Why
134
141
  * The alias provides the widget name while retaining the explicit input API.
135
- * ## Ownership and lifetime
136
142
  * It has exactly the same Scope and native-element ownership as `Input`.
137
143
  * @since 1.0.0
138
- * @category aliases
144
+ * @category Native controls
139
145
  */
140
146
  export const Checkbox = Input;