@typed/ui 1.0.0-beta.4 → 1.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -9
- package/dist/Alert.d.ts +78 -0
- package/dist/Alert.d.ts.map +1 -0
- package/dist/Alert.js +37 -0
- package/dist/Button.d.ts +144 -0
- package/dist/Button.d.ts.map +1 -0
- package/dist/Button.js +38 -0
- package/dist/Carousel.d.ts +547 -0
- package/dist/Carousel.d.ts.map +1 -0
- package/dist/Carousel.js +387 -0
- package/dist/Checkbox.d.ts +203 -0
- package/dist/Checkbox.d.ts.map +1 -0
- package/dist/Checkbox.js +140 -0
- package/dist/Collection.d.ts +254 -0
- package/dist/Collection.d.ts.map +1 -0
- package/dist/Collection.js +218 -0
- package/dist/Combobox.d.ts +516 -0
- package/dist/Combobox.d.ts.map +1 -0
- package/dist/Combobox.js +371 -0
- package/dist/Component.d.ts +127 -0
- package/dist/Component.d.ts.map +1 -0
- package/dist/Component.js +60 -0
- package/dist/Composite.d.ts +823 -0
- package/dist/Composite.d.ts.map +1 -0
- package/dist/Composite.js +615 -0
- package/dist/Dialog.d.ts +544 -0
- package/dist/Dialog.d.ts.map +1 -0
- package/dist/Dialog.js +355 -0
- package/dist/Disclosure.d.ts +219 -0
- package/dist/Disclosure.d.ts.map +1 -0
- package/dist/Disclosure.js +128 -0
- package/dist/Dom/Events.d.ts +122 -0
- package/dist/Dom/Events.d.ts.map +1 -0
- package/dist/Dom/Events.js +192 -0
- package/dist/Dom/Props.d.ts +161 -0
- package/dist/Dom/Props.d.ts.map +1 -0
- package/dist/Dom/Props.js +110 -0
- package/dist/Dom/Refs.d.ts +58 -0
- package/dist/Dom/Refs.d.ts.map +1 -0
- package/dist/Dom/Refs.js +61 -0
- package/dist/Dom/Render.d.ts +59 -0
- package/dist/Dom/Render.d.ts.map +1 -0
- package/dist/Dom/Render.js +71 -0
- package/dist/Dom/Types.d.ts +570 -0
- package/dist/Dom/Types.d.ts.map +1 -0
- package/dist/Dom/Types.js +1 -0
- package/dist/Dom/index.d.ts +20 -0
- package/dist/Dom/index.d.ts.map +1 -0
- package/dist/Dom/index.js +8 -0
- package/dist/Dom.d.ts +14 -0
- package/dist/Dom.d.ts.map +1 -0
- package/dist/Dom.js +13 -0
- package/dist/Focusable.d.ts +85 -0
- package/dist/Focusable.d.ts.map +1 -0
- package/dist/Focusable.js +35 -0
- package/dist/Form.d.ts +1695 -0
- package/dist/Form.d.ts.map +1 -0
- package/dist/Form.js +987 -0
- package/dist/Grid.d.ts +569 -0
- package/dist/Grid.d.ts.map +1 -0
- package/dist/Grid.js +379 -0
- package/dist/Group.d.ts +147 -0
- package/dist/Group.d.ts.map +1 -0
- package/dist/Group.js +63 -0
- package/dist/Heading.d.ts +86 -0
- package/dist/Heading.d.ts.map +1 -0
- package/dist/Heading.js +48 -0
- package/dist/Hovercard.d.ts +297 -0
- package/dist/Hovercard.d.ts.map +1 -0
- package/dist/Hovercard.js +188 -0
- package/dist/HttpRouter.d.ts +129 -6
- package/dist/HttpRouter.d.ts.map +1 -1
- package/dist/HttpRouter.js +196 -53
- package/dist/Link.d.ts +67 -28
- package/dist/Link.d.ts.map +1 -1
- package/dist/Link.js +91 -37
- package/dist/Listbox.d.ts +437 -0
- package/dist/Listbox.d.ts.map +1 -0
- package/dist/Listbox.js +316 -0
- package/dist/Menu.d.ts +972 -0
- package/dist/Menu.d.ts.map +1 -0
- package/dist/Menu.js +731 -0
- package/dist/Menubar.d.ts +367 -0
- package/dist/Menubar.d.ts.map +1 -0
- package/dist/Menubar.js +265 -0
- package/dist/Meter.d.ts +217 -0
- package/dist/Meter.d.ts.map +1 -0
- package/dist/Meter.js +94 -0
- package/dist/NativeDetails.d.ts +41 -0
- package/dist/NativeDetails.d.ts.map +1 -0
- package/dist/NativeDetails.js +40 -0
- package/dist/NativeDialog.d.ts +64 -0
- package/dist/NativeDialog.d.ts.map +1 -0
- package/dist/NativeDialog.js +50 -0
- package/dist/NativePopover.d.ts +41 -0
- package/dist/NativePopover.d.ts.map +1 -0
- package/dist/NativePopover.js +46 -0
- package/dist/Popover.d.ts +241 -0
- package/dist/Popover.d.ts.map +1 -0
- package/dist/Popover.js +141 -0
- package/dist/RadioGroup.d.ts +432 -0
- package/dist/RadioGroup.d.ts.map +1 -0
- package/dist/RadioGroup.js +291 -0
- package/dist/Role.d.ts +64 -0
- package/dist/Role.d.ts.map +1 -0
- package/dist/Role.js +27 -0
- package/dist/Select.d.ts +529 -0
- package/dist/Select.d.ts.map +1 -0
- package/dist/Select.js +407 -0
- package/dist/Separator.d.ts +54 -0
- package/dist/Separator.d.ts.map +1 -0
- package/dist/Separator.js +26 -0
- package/dist/Slider.d.ts +188 -0
- package/dist/Slider.d.ts.map +1 -0
- package/dist/Slider.js +96 -0
- package/dist/SpinButton.d.ts +188 -0
- package/dist/SpinButton.d.ts.map +1 -0
- package/dist/SpinButton.js +96 -0
- package/dist/Storybook.d.ts +76 -0
- package/dist/Storybook.d.ts.map +1 -0
- package/dist/Storybook.js +102 -0
- package/dist/Switch.d.ts +187 -0
- package/dist/Switch.d.ts.map +1 -0
- package/dist/Switch.js +116 -0
- package/dist/Tab.d.ts +26 -0
- package/dist/Tab.d.ts.map +1 -0
- package/dist/Tab.js +25 -0
- package/dist/Tabs.d.ts +591 -0
- package/dist/Tabs.d.ts.map +1 -0
- package/dist/Tabs.js +346 -0
- package/dist/Toolbar.d.ts +366 -0
- package/dist/Toolbar.d.ts.map +1 -0
- package/dist/Toolbar.js +245 -0
- package/dist/Tooltip.d.ts +296 -0
- package/dist/Tooltip.d.ts.map +1 -0
- package/dist/Tooltip.js +172 -0
- package/dist/Tree.d.ts +591 -0
- package/dist/Tree.d.ts.map +1 -0
- package/dist/Tree.js +434 -0
- package/dist/TreeGrid.d.ts +645 -0
- package/dist/TreeGrid.d.ts.map +1 -0
- package/dist/TreeGrid.js +420 -0
- package/dist/VisuallyHidden.d.ts +54 -0
- package/dist/VisuallyHidden.d.ts.map +1 -0
- package/dist/VisuallyHidden.js +27 -0
- package/dist/WindowSplitter.d.ts +376 -0
- package/dist/WindowSplitter.d.ts.map +1 -0
- package/dist/WindowSplitter.js +222 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -0
- package/package.json +45 -18
- package/src/HttpRouter.test.ts +0 -256
- package/src/HttpRouter.ts +0 -165
- package/src/Link.test.ts +0 -84
- package/src/Link.ts +0 -107
- package/src/index.ts +0 -2
package/dist/Switch.d.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import { RefSubject } from "@typed/fx";
|
|
4
|
+
import { type Renderable } from "@typed/template";
|
|
5
|
+
import * as Dom from "./Dom.js";
|
|
6
|
+
import type { HostResult } from "./Dom/Types.js";
|
|
7
|
+
/** Current renderer-independent switch state.
|
|
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
|
|
15
|
+
*/
|
|
16
|
+
export interface State {
|
|
17
|
+
/** Whether the switch is on.
|
|
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
|
|
25
|
+
*/
|
|
26
|
+
readonly checked: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** Optional initial switch state.
|
|
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
|
|
36
|
+
*/
|
|
37
|
+
export interface InitialState {
|
|
38
|
+
/** Initial on/off value, defaulting to false.
|
|
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
|
|
46
|
+
*/
|
|
47
|
+
readonly checked?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** Schema for switch hydration state.
|
|
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
|
|
57
|
+
*/
|
|
58
|
+
export declare const StateSchema: Schema.Struct<{
|
|
59
|
+
readonly checked: Schema.Boolean;
|
|
60
|
+
}>;
|
|
61
|
+
/** Creates hydrated switch state independent of rendering.
|
|
62
|
+
* @remarks
|
|
63
|
+
* ## Why
|
|
64
|
+
* Domain code and tests can own the state while any renderer consumes it.
|
|
65
|
+
* ## Ownership and lifetime
|
|
66
|
+
* The caller's Effect Scope owns the returned RefSubject.
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { Effect } from "effect"
|
|
70
|
+
* import * as Switch from "@typed/ui/Switch"
|
|
71
|
+
*
|
|
72
|
+
* const program = Effect.gen(function* () {
|
|
73
|
+
* return yield* Switch.makeState({ checked: true })
|
|
74
|
+
* })
|
|
75
|
+
* ```
|
|
76
|
+
* @since 1.0.0
|
|
77
|
+
* @category constructors
|
|
78
|
+
*/
|
|
79
|
+
export declare function makeState(initial?: InitialState): Effect.Effect<RefSubject.HydratedRefSubject<{
|
|
80
|
+
readonly checked: boolean;
|
|
81
|
+
}, Schema.SchemaError, never, never>, never, import("effect/Scope").Scope>;
|
|
82
|
+
/** Sets the switch on/off state.
|
|
83
|
+
* @remarks
|
|
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.
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import { Effect } from "effect"
|
|
91
|
+
* import * as Switch from "@typed/ui/Switch"
|
|
92
|
+
*
|
|
93
|
+
* const program = Effect.gen(function* () {
|
|
94
|
+
* const state = yield* Switch.makeState()
|
|
95
|
+
* yield* Switch.setChecked(state, true)
|
|
96
|
+
* })
|
|
97
|
+
* ```
|
|
98
|
+
* @since 1.0.0
|
|
99
|
+
* @category state
|
|
100
|
+
*/
|
|
101
|
+
export declare function setChecked<E, R>(state: RefSubject.RefSubject<State, E, R>, checked: boolean): Effect.Effect<State, E, R>;
|
|
102
|
+
/** Atomically inverts the switch state.
|
|
103
|
+
* @remarks
|
|
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.
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { Effect } from "effect"
|
|
111
|
+
* import * as Switch from "@typed/ui/Switch"
|
|
112
|
+
*
|
|
113
|
+
* const program = Effect.gen(function* () {
|
|
114
|
+
* const state = yield* Switch.makeState({ checked: true })
|
|
115
|
+
* yield* Switch.toggle(state)
|
|
116
|
+
* })
|
|
117
|
+
* ```
|
|
118
|
+
* @since 1.0.0
|
|
119
|
+
* @category state
|
|
120
|
+
*/
|
|
121
|
+
export declare function toggle<E, R>(state: RefSubject.RefSubject<State, E, R>): Effect.Effect<State, E, R>;
|
|
122
|
+
/** Options for an ARIA switch rendered as a native button.
|
|
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
|
|
131
|
+
*/
|
|
132
|
+
export interface SwitchOptions extends Dom.HostOptions<HTMLButtonElement> {
|
|
133
|
+
/** Hydrated state synchronized with `aria-checked`.
|
|
134
|
+
* @remarks
|
|
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.
|
|
139
|
+
* @since 1.0.0
|
|
140
|
+
* @category state
|
|
141
|
+
*/
|
|
142
|
+
readonly state: RefSubject.HydratedRefSubject<State, Schema.SchemaError>;
|
|
143
|
+
/** Visible content and accessible name.
|
|
144
|
+
* @remarks
|
|
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.
|
|
149
|
+
* @since 1.0.0
|
|
150
|
+
* @category content
|
|
151
|
+
*/
|
|
152
|
+
readonly content: Renderable.Any;
|
|
153
|
+
}
|
|
154
|
+
declare function internalProps<const Options extends SwitchOptions>(options: Options): ({ property }: Dom.InternalPropsHelpers<Options>) => {
|
|
155
|
+
readonly type: "button";
|
|
156
|
+
readonly role: "switch";
|
|
157
|
+
readonly "aria-checked": RefSubject.Computed<boolean, Schema.SchemaError, never>;
|
|
158
|
+
readonly "?disabled": false | Exclude<Dom.Property<Options, "disabled">, Dom.Nullish>;
|
|
159
|
+
readonly onclick: Effect.Effect<State, Schema.SchemaError, never>;
|
|
160
|
+
readonly ref: RefSubject.HydratedRefSubject<State, Schema.SchemaError, never, never>;
|
|
161
|
+
};
|
|
162
|
+
type SwitchInternalProps<Options extends SwitchOptions> = ReturnType<ReturnType<typeof internalProps<Options>>>;
|
|
163
|
+
/** Renders a button-backed ARIA switch.
|
|
164
|
+
* @remarks
|
|
165
|
+
* ## Why
|
|
166
|
+
* The component combines native button activation with a renderer-independent
|
|
167
|
+
* boolean state and real DOM click events.
|
|
168
|
+
* ## Ownership and lifetime
|
|
169
|
+
* Running the Fx owns listener/state subscriptions in its Effect Scope. A
|
|
170
|
+
* custom host must preserve button type, role, `aria-checked`, click handler,
|
|
171
|
+
* and the single hydration ref owner.
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* import { Effect } from "effect"
|
|
175
|
+
* import * as Switch from "@typed/ui/Switch"
|
|
176
|
+
*
|
|
177
|
+
* const program = Effect.gen(function* () {
|
|
178
|
+
* const state = yield* Switch.makeState()
|
|
179
|
+
* return Switch.Switch({ state, content: "Notifications" })
|
|
180
|
+
* })
|
|
181
|
+
* ```
|
|
182
|
+
* @since 1.0.0
|
|
183
|
+
* @category components
|
|
184
|
+
*/
|
|
185
|
+
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
|
+
export {};
|
|
187
|
+
//# sourceMappingURL=Switch.d.ts.map
|
|
@@ -0,0 +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;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK;IACpB;;;;;;;;OAQG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW;;EAA6C,CAAC;AAEtE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,YAAiB;;2EAEnD;AAED;;;;;;;;;;;;;;;;;;GAkBG;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;;;;;;;;;;;;;;;;;;GAkBG;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;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAc,SAAQ,GAAG,CAAC,WAAW,CAAC,iBAAiB,CAAC;IACvE;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACzE;;;;;;;;OAQG;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;;;;;;;;;;;;;;;;;;;;;GAqBG;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
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import { RefSubject } from "@typed/fx";
|
|
3
|
+
import { html } from "@typed/template";
|
|
4
|
+
import * as Dom from "./Dom.js";
|
|
5
|
+
/** Schema for switch hydration state.
|
|
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
|
|
13
|
+
*/
|
|
14
|
+
export const StateSchema = Schema.Struct({ checked: Schema.Boolean });
|
|
15
|
+
/** Creates hydrated switch state independent of rendering.
|
|
16
|
+
* @remarks
|
|
17
|
+
* ## Why
|
|
18
|
+
* Domain code and tests can own the state while any renderer consumes it.
|
|
19
|
+
* ## Ownership and lifetime
|
|
20
|
+
* The caller's Effect Scope owns the returned RefSubject.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { Effect } from "effect"
|
|
24
|
+
* import * as Switch from "@typed/ui/Switch"
|
|
25
|
+
*
|
|
26
|
+
* const program = Effect.gen(function* () {
|
|
27
|
+
* return yield* Switch.makeState({ checked: true })
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
* @since 1.0.0
|
|
31
|
+
* @category constructors
|
|
32
|
+
*/
|
|
33
|
+
export function makeState(initial = {}) {
|
|
34
|
+
return RefSubject.hydrate(StateSchema, { checked: initial.checked ?? false });
|
|
35
|
+
}
|
|
36
|
+
/** Sets the switch on/off state.
|
|
37
|
+
* @remarks
|
|
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.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { Effect } from "effect"
|
|
45
|
+
* import * as Switch from "@typed/ui/Switch"
|
|
46
|
+
*
|
|
47
|
+
* const program = Effect.gen(function* () {
|
|
48
|
+
* const state = yield* Switch.makeState()
|
|
49
|
+
* yield* Switch.setChecked(state, true)
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
* @category state
|
|
54
|
+
*/
|
|
55
|
+
export function setChecked(state, checked) {
|
|
56
|
+
return RefSubject.update(state, (current) => ({ ...current, checked }));
|
|
57
|
+
}
|
|
58
|
+
/** Atomically inverts the switch state.
|
|
59
|
+
* @remarks
|
|
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.
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { Effect } from "effect"
|
|
67
|
+
* import * as Switch from "@typed/ui/Switch"
|
|
68
|
+
*
|
|
69
|
+
* const program = Effect.gen(function* () {
|
|
70
|
+
* const state = yield* Switch.makeState({ checked: true })
|
|
71
|
+
* yield* Switch.toggle(state)
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
* @since 1.0.0
|
|
75
|
+
* @category state
|
|
76
|
+
*/
|
|
77
|
+
export function toggle(state) {
|
|
78
|
+
return RefSubject.update(state, (current) => ({ ...current, checked: !current.checked }));
|
|
79
|
+
}
|
|
80
|
+
function internalProps(options) {
|
|
81
|
+
return ({ property }) => ({
|
|
82
|
+
type: "button",
|
|
83
|
+
role: "switch",
|
|
84
|
+
"aria-checked": RefSubject.map(options.state, (state) => state.checked),
|
|
85
|
+
"?disabled": property("disabled", false),
|
|
86
|
+
onclick: toggle(options.state),
|
|
87
|
+
ref: options.state,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** Renders a button-backed ARIA switch.
|
|
91
|
+
* @remarks
|
|
92
|
+
* ## Why
|
|
93
|
+
* The component combines native button activation with a renderer-independent
|
|
94
|
+
* boolean state and real DOM click events.
|
|
95
|
+
* ## Ownership and lifetime
|
|
96
|
+
* Running the Fx owns listener/state subscriptions in its Effect Scope. A
|
|
97
|
+
* custom host must preserve button type, role, `aria-checked`, click handler,
|
|
98
|
+
* and the single hydration ref owner.
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { Effect } from "effect"
|
|
102
|
+
* import * as Switch from "@typed/ui/Switch"
|
|
103
|
+
*
|
|
104
|
+
* const program = Effect.gen(function* () {
|
|
105
|
+
* const state = yield* Switch.makeState()
|
|
106
|
+
* return Switch.Switch({ state, content: "Notifications" })
|
|
107
|
+
* })
|
|
108
|
+
* ```
|
|
109
|
+
* @since 1.0.0
|
|
110
|
+
* @category components
|
|
111
|
+
*/
|
|
112
|
+
export function Switch(options, host) {
|
|
113
|
+
return Dom.renderHost()(options, host, internalProps(options), options.content, (props, content) => {
|
|
114
|
+
return html `<button ...${props}>${content}</button>`;
|
|
115
|
+
});
|
|
116
|
+
}
|
package/dist/Tab.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility entrypoint for the Tabs API.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Importing from `@typed/ui/Tab` exposes the same declarations as `@typed/ui/Tabs`; it does not
|
|
6
|
+
* create a second state model or renderer. Prefer whichever public specifier matches the surrounding
|
|
7
|
+
* codebase, and use one shared Tabs state across List, Tab, and Panel.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as Effect from "effect/Effect";
|
|
12
|
+
* import * as Tab from "@typed/ui/Tab";
|
|
13
|
+
*
|
|
14
|
+
* const program = Effect.scoped(
|
|
15
|
+
* Effect.gen(function* () {
|
|
16
|
+
* const state = yield* Tab.makeState({ selectedId: "overview" });
|
|
17
|
+
* return yield* state;
|
|
18
|
+
* }),
|
|
19
|
+
* );
|
|
20
|
+
* ```
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
* @category modules
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
export * from "./Tabs.js";
|
|
26
|
+
//# sourceMappingURL=Tab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tab.d.ts","sourceRoot":"","sources":["../src/Tab.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,cAAc,WAAW,CAAC"}
|
package/dist/Tab.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility entrypoint for the Tabs API.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Importing from `@typed/ui/Tab` exposes the same declarations as `@typed/ui/Tabs`; it does not
|
|
6
|
+
* create a second state model or renderer. Prefer whichever public specifier matches the surrounding
|
|
7
|
+
* codebase, and use one shared Tabs state across List, Tab, and Panel.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as Effect from "effect/Effect";
|
|
12
|
+
* import * as Tab from "@typed/ui/Tab";
|
|
13
|
+
*
|
|
14
|
+
* const program = Effect.scoped(
|
|
15
|
+
* Effect.gen(function* () {
|
|
16
|
+
* const state = yield* Tab.makeState({ selectedId: "overview" });
|
|
17
|
+
* return yield* state;
|
|
18
|
+
* }),
|
|
19
|
+
* );
|
|
20
|
+
* ```
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
* @category modules
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
export * from "./Tabs.js";
|