@proyecto-viviana/solid-stately 0.0.2 → 0.0.3
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/dist/index.d.ts +263 -6
- package/dist/index.js +18 -25
- package/dist/index.jsx +247 -0
- package/package.json +7 -5
- package/dist/checkbox/createCheckboxGroupState.d.ts +0 -70
- package/dist/checkbox/index.d.ts +0 -1
- package/dist/index.js.map +0 -1
- package/dist/radio/createRadioGroupState.d.ts +0 -76
- package/dist/radio/index.d.ts +0 -1
- package/dist/ssr/index.d.ts +0 -23
- package/dist/textfield/createTextFieldState.d.ts +0 -29
- package/dist/textfield/index.d.ts +0 -1
- package/dist/toggle/createToggleState.d.ts +0 -33
- package/dist/toggle/index.d.ts +0 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/reactivity.d.ts +0 -27
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,263 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Accessor } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reactivity utilities for Solid Stately
|
|
5
|
+
*
|
|
6
|
+
* Provides type-safe utilities for working with SolidJS reactivity patterns.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A value that may be either a raw value or an accessor function.
|
|
11
|
+
* This is a common pattern in SolidJS for props that may be reactive.
|
|
12
|
+
*/
|
|
13
|
+
type MaybeAccessor<T> = T | Accessor<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Unwraps a MaybeAccessor to get the underlying value.
|
|
16
|
+
* If the input is a function, it calls it to get the value.
|
|
17
|
+
* Otherwise, it returns the value directly.
|
|
18
|
+
*
|
|
19
|
+
* @param value - The value or accessor to unwrap.
|
|
20
|
+
*/
|
|
21
|
+
declare function access<T>(value: MaybeAccessor<T>): T;
|
|
22
|
+
/**
|
|
23
|
+
* A value that may be undefined or an accessor that returns the value or undefined.
|
|
24
|
+
*/
|
|
25
|
+
type MaybeAccessorValue<T> = T | undefined | Accessor<T | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a value is an accessor function.
|
|
28
|
+
*/
|
|
29
|
+
declare function isAccessor<T>(value: MaybeAccessor<T>): value is Accessor<T>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Toggle state for Solid Stately
|
|
33
|
+
*
|
|
34
|
+
* Provides state management for toggle components like checkboxes and switches.
|
|
35
|
+
*
|
|
36
|
+
* This is a 1:1 port of @react-stately/toggle's useToggleState.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
interface ToggleStateOptions {
|
|
40
|
+
/** Whether the element should be selected (controlled). */
|
|
41
|
+
isSelected?: boolean;
|
|
42
|
+
/** Whether the element should be selected by default (uncontrolled). */
|
|
43
|
+
defaultSelected?: boolean;
|
|
44
|
+
/** Handler that is called when the element's selection state changes. */
|
|
45
|
+
onChange?: (isSelected: boolean) => void;
|
|
46
|
+
/** Whether the element is read only. */
|
|
47
|
+
isReadOnly?: boolean;
|
|
48
|
+
}
|
|
49
|
+
interface ToggleState {
|
|
50
|
+
/** Whether the toggle is selected. */
|
|
51
|
+
readonly isSelected: Accessor<boolean>;
|
|
52
|
+
/** Whether the toggle is selected by default. */
|
|
53
|
+
readonly defaultSelected: boolean;
|
|
54
|
+
/** Updates selection state. */
|
|
55
|
+
setSelected(isSelected: boolean): void;
|
|
56
|
+
/** Toggle the selection state. */
|
|
57
|
+
toggle(): void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Provides state management for toggle components like checkboxes and switches.
|
|
61
|
+
*/
|
|
62
|
+
declare function createToggleState(props?: MaybeAccessor<ToggleStateOptions>): ToggleState;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* TextField state for Solid Stately
|
|
66
|
+
*
|
|
67
|
+
* Provides state management for text input components.
|
|
68
|
+
*
|
|
69
|
+
* This is a port of @react-stately/utils's useControlledState pattern
|
|
70
|
+
* as used by @react-aria/textfield.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
interface TextFieldStateOptions {
|
|
74
|
+
/** The current value (controlled). */
|
|
75
|
+
value?: string;
|
|
76
|
+
/** The default value (uncontrolled). */
|
|
77
|
+
defaultValue?: string;
|
|
78
|
+
/** Handler that is called when the value changes. */
|
|
79
|
+
onChange?: (value: string) => void;
|
|
80
|
+
}
|
|
81
|
+
interface TextFieldState {
|
|
82
|
+
/** The current value of the text field. */
|
|
83
|
+
readonly value: Accessor<string>;
|
|
84
|
+
/** Sets the value of the text field. */
|
|
85
|
+
setValue(value: string): void;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Provides state management for text input components.
|
|
89
|
+
* Supports both controlled and uncontrolled modes.
|
|
90
|
+
*/
|
|
91
|
+
declare function createTextFieldState(props?: MaybeAccessor<TextFieldStateOptions>): TextFieldState;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Checkbox group state for Solid Stately
|
|
95
|
+
*
|
|
96
|
+
* Provides state management for a checkbox group component.
|
|
97
|
+
* Provides a name for the group, and manages selection and focus state.
|
|
98
|
+
*
|
|
99
|
+
* This is a 1:1 port of @react-stately/checkbox's useCheckboxGroupState.
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
interface CheckboxGroupProps {
|
|
103
|
+
/** The current selected values (controlled). */
|
|
104
|
+
value?: string[];
|
|
105
|
+
/** The default selected values (uncontrolled). */
|
|
106
|
+
defaultValue?: string[];
|
|
107
|
+
/** Handler that is called when the value changes. */
|
|
108
|
+
onChange?: (value: string[]) => void;
|
|
109
|
+
/** Whether the checkbox group is disabled. */
|
|
110
|
+
isDisabled?: boolean;
|
|
111
|
+
/** Whether the checkbox group is read only. */
|
|
112
|
+
isReadOnly?: boolean;
|
|
113
|
+
/** Whether the checkbox group is required. */
|
|
114
|
+
isRequired?: boolean;
|
|
115
|
+
/** Whether the checkbox group is invalid. */
|
|
116
|
+
isInvalid?: boolean;
|
|
117
|
+
/** The name of the checkbox group, used when submitting an HTML form. */
|
|
118
|
+
name?: string;
|
|
119
|
+
/** The form to associate the checkbox group with. */
|
|
120
|
+
form?: string;
|
|
121
|
+
/** The label for the checkbox group. */
|
|
122
|
+
label?: string;
|
|
123
|
+
/** Handler that is called when the checkbox group receives focus. */
|
|
124
|
+
onFocus?: (e: FocusEvent) => void;
|
|
125
|
+
/** Handler that is called when the checkbox group loses focus. */
|
|
126
|
+
onBlur?: (e: FocusEvent) => void;
|
|
127
|
+
/** Handler that is called when the checkbox group's focus status changes. */
|
|
128
|
+
onFocusChange?: (isFocused: boolean) => void;
|
|
129
|
+
}
|
|
130
|
+
interface CheckboxGroupState {
|
|
131
|
+
/** Current selected values. */
|
|
132
|
+
readonly value: Accessor<readonly string[]>;
|
|
133
|
+
/** Default selected values. */
|
|
134
|
+
readonly defaultValue: readonly string[];
|
|
135
|
+
/** Whether the checkbox group is disabled. */
|
|
136
|
+
readonly isDisabled: boolean;
|
|
137
|
+
/** Whether the checkbox group is read only. */
|
|
138
|
+
readonly isReadOnly: boolean;
|
|
139
|
+
/** Whether the checkbox group is invalid. */
|
|
140
|
+
readonly isInvalid: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Whether the checkboxes in the group are required.
|
|
143
|
+
* This changes to false once at least one item is selected.
|
|
144
|
+
*/
|
|
145
|
+
readonly isRequired: Accessor<boolean>;
|
|
146
|
+
/** Returns whether the given value is selected. */
|
|
147
|
+
isSelected(value: string): boolean;
|
|
148
|
+
/** Sets the selected values. */
|
|
149
|
+
setValue(value: string[]): void;
|
|
150
|
+
/** Adds a value to the set of selected values. */
|
|
151
|
+
addValue(value: string): void;
|
|
152
|
+
/** Removes a value from the set of selected values. */
|
|
153
|
+
removeValue(value: string): void;
|
|
154
|
+
/** Toggles a value in the set of selected values. */
|
|
155
|
+
toggleValue(value: string): void;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Provides state management for a checkbox group component.
|
|
159
|
+
* Provides a name for the group, and manages selection and focus state.
|
|
160
|
+
*/
|
|
161
|
+
declare function createCheckboxGroupState(props?: MaybeAccessor<CheckboxGroupProps>): CheckboxGroupState;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Radio group state for Solid Stately
|
|
165
|
+
*
|
|
166
|
+
* Provides state management for a radio group component.
|
|
167
|
+
* Provides a name for the group, and manages selection and focus state.
|
|
168
|
+
*
|
|
169
|
+
* This is a 1:1 port of @react-stately/radio's useRadioGroupState.
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
interface RadioGroupProps {
|
|
173
|
+
/** The current selected value (controlled). */
|
|
174
|
+
value?: string | null;
|
|
175
|
+
/** The default selected value (uncontrolled). */
|
|
176
|
+
defaultValue?: string | null;
|
|
177
|
+
/** Handler that is called when the value changes. */
|
|
178
|
+
onChange?: (value: string) => void;
|
|
179
|
+
/** Whether the radio group is disabled. */
|
|
180
|
+
isDisabled?: boolean;
|
|
181
|
+
/** Whether the radio group is read only. */
|
|
182
|
+
isReadOnly?: boolean;
|
|
183
|
+
/** Whether the radio group is required. */
|
|
184
|
+
isRequired?: boolean;
|
|
185
|
+
/** Whether the radio group is invalid. */
|
|
186
|
+
isInvalid?: boolean;
|
|
187
|
+
/** The name of the radio group, used when submitting an HTML form. */
|
|
188
|
+
name?: string;
|
|
189
|
+
/** The form to associate the radio group with. */
|
|
190
|
+
form?: string;
|
|
191
|
+
/** The label for the radio group. */
|
|
192
|
+
label?: string;
|
|
193
|
+
/** Orientation of the radio group. */
|
|
194
|
+
orientation?: 'horizontal' | 'vertical';
|
|
195
|
+
/** Handler that is called when the radio group receives focus. */
|
|
196
|
+
onFocus?: (e: FocusEvent) => void;
|
|
197
|
+
/** Handler that is called when the radio group loses focus. */
|
|
198
|
+
onBlur?: (e: FocusEvent) => void;
|
|
199
|
+
/** Handler that is called when the radio group's focus status changes. */
|
|
200
|
+
onFocusChange?: (isFocused: boolean) => void;
|
|
201
|
+
}
|
|
202
|
+
interface RadioGroupState {
|
|
203
|
+
/** The name for the group, used for native form submission. */
|
|
204
|
+
readonly name: string;
|
|
205
|
+
/** Whether the radio group is disabled. */
|
|
206
|
+
readonly isDisabled: boolean;
|
|
207
|
+
/** Whether the radio group is read only. */
|
|
208
|
+
readonly isReadOnly: boolean;
|
|
209
|
+
/** Whether the radio group is required. */
|
|
210
|
+
readonly isRequired: boolean;
|
|
211
|
+
/** Whether the radio group is invalid. */
|
|
212
|
+
readonly isInvalid: boolean;
|
|
213
|
+
/** The currently selected value. */
|
|
214
|
+
readonly selectedValue: Accessor<string | null>;
|
|
215
|
+
/** The default selected value. */
|
|
216
|
+
readonly defaultSelectedValue: string | null;
|
|
217
|
+
/** Sets the selected value. */
|
|
218
|
+
setSelectedValue(value: string | null): void;
|
|
219
|
+
/** The value of the last focused radio. */
|
|
220
|
+
readonly lastFocusedValue: Accessor<string | null>;
|
|
221
|
+
/** Sets the last focused value. */
|
|
222
|
+
setLastFocusedValue(value: string | null): void;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Internal WeakMap to store sync version accessors for each radio group state.
|
|
226
|
+
* This is used by createRadio to trigger DOM sync when native radio behavior
|
|
227
|
+
* causes the DOM checked state to desync from our reactive state.
|
|
228
|
+
*
|
|
229
|
+
* This is kept separate from RadioGroupState to maintain API parity with React-Stately.
|
|
230
|
+
* @internal
|
|
231
|
+
*/
|
|
232
|
+
declare const radioGroupSyncVersion: WeakMap<RadioGroupState, Accessor<number>>;
|
|
233
|
+
/**
|
|
234
|
+
* Provides state management for a radio group component.
|
|
235
|
+
* Provides a name for the group, and manages selection and focus state.
|
|
236
|
+
*/
|
|
237
|
+
declare function createRadioGroupState(props?: MaybeAccessor<RadioGroupProps>): RadioGroupState;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* SSR utilities for Solid Stately
|
|
241
|
+
*
|
|
242
|
+
* SolidJS has built-in SSR support with `isServer` and `createUniqueId()`.
|
|
243
|
+
* These utilities provide a consistent API matching React-Stately's patterns.
|
|
244
|
+
*/
|
|
245
|
+
/**
|
|
246
|
+
* Returns whether the component is currently being server side rendered.
|
|
247
|
+
* Can be used to delay browser-specific rendering until after hydration.
|
|
248
|
+
*/
|
|
249
|
+
declare function createIsSSR(): boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Generate a unique ID that is stable across server and client.
|
|
252
|
+
* Uses SolidJS's built-in createUniqueId which handles SSR correctly.
|
|
253
|
+
*
|
|
254
|
+
* @param defaultId - Optional default ID to use instead of generating one.
|
|
255
|
+
*/
|
|
256
|
+
declare function createId(defaultId?: string): string;
|
|
257
|
+
/**
|
|
258
|
+
* Check if we can use DOM APIs.
|
|
259
|
+
* This is useful for code that needs to run only in the browser.
|
|
260
|
+
*/
|
|
261
|
+
declare const canUseDOM: boolean;
|
|
262
|
+
|
|
263
|
+
export { type CheckboxGroupProps, type CheckboxGroupState, type MaybeAccessor, type MaybeAccessorValue, type RadioGroupProps, type RadioGroupState, type TextFieldState, type TextFieldStateOptions, type ToggleState, type ToggleStateOptions, access, canUseDOM, createCheckboxGroupState, createId, createIsSSR, createRadioGroupState, createTextFieldState, createToggleState, isAccessor, radioGroupSyncVersion };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { createSignal, createUniqueId, untrack } from
|
|
2
|
-
import { isServer } from
|
|
1
|
+
import { createSignal, createUniqueId, untrack } from 'solid-js';
|
|
2
|
+
import { isServer } from 'solid-js/web';
|
|
3
|
+
|
|
4
|
+
// src/toggle/createToggleState.ts
|
|
5
|
+
|
|
6
|
+
// src/utils/reactivity.ts
|
|
3
7
|
function access(value) {
|
|
4
8
|
return typeof value === "function" ? value() : value;
|
|
5
9
|
}
|
|
6
10
|
function isAccessor(value) {
|
|
7
11
|
return typeof value === "function";
|
|
8
12
|
}
|
|
13
|
+
|
|
14
|
+
// src/toggle/createToggleState.ts
|
|
9
15
|
function createToggleState(props = {}) {
|
|
10
16
|
const getProps = () => access(props);
|
|
11
17
|
const initialProps = getProps();
|
|
@@ -17,7 +23,6 @@ function createToggleState(props = {}) {
|
|
|
17
23
|
return isControlled() ? p.isSelected ?? false : internalSelected();
|
|
18
24
|
};
|
|
19
25
|
function setSelected(value) {
|
|
20
|
-
var _a;
|
|
21
26
|
const p = getProps();
|
|
22
27
|
if (p.isReadOnly) {
|
|
23
28
|
return;
|
|
@@ -25,7 +30,7 @@ function createToggleState(props = {}) {
|
|
|
25
30
|
if (!isControlled()) {
|
|
26
31
|
setInternalSelected(value);
|
|
27
32
|
}
|
|
28
|
-
|
|
33
|
+
p.onChange?.(value);
|
|
29
34
|
}
|
|
30
35
|
function toggle() {
|
|
31
36
|
const p = getProps();
|
|
@@ -52,12 +57,11 @@ function createTextFieldState(props = {}) {
|
|
|
52
57
|
return isControlled() ? p.value ?? "" : internalValue();
|
|
53
58
|
};
|
|
54
59
|
function setValue(newValue) {
|
|
55
|
-
var _a;
|
|
56
60
|
const p = getProps();
|
|
57
61
|
if (!isControlled()) {
|
|
58
62
|
setInternalValue(newValue);
|
|
59
63
|
}
|
|
60
|
-
|
|
64
|
+
p.onChange?.(newValue);
|
|
61
65
|
}
|
|
62
66
|
return {
|
|
63
67
|
value,
|
|
@@ -82,7 +86,6 @@ function createCheckboxGroupState(props = {}) {
|
|
|
82
86
|
return getProps().isInvalid ?? false;
|
|
83
87
|
};
|
|
84
88
|
function setValue(newValue) {
|
|
85
|
-
var _a;
|
|
86
89
|
const p = getProps();
|
|
87
90
|
if (p.isReadOnly || p.isDisabled) {
|
|
88
91
|
return;
|
|
@@ -90,7 +93,7 @@ function createCheckboxGroupState(props = {}) {
|
|
|
90
93
|
if (!isControlled()) {
|
|
91
94
|
setInternalValue(newValue);
|
|
92
95
|
}
|
|
93
|
-
|
|
96
|
+
p.onChange?.(newValue);
|
|
94
97
|
}
|
|
95
98
|
function isSelected(checkValue) {
|
|
96
99
|
return value().includes(checkValue);
|
|
@@ -156,8 +159,10 @@ function createId(defaultId) {
|
|
|
156
159
|
}
|
|
157
160
|
return `solid-stately-${createUniqueId()}`;
|
|
158
161
|
}
|
|
159
|
-
|
|
160
|
-
|
|
162
|
+
var canUseDOM = !isServer;
|
|
163
|
+
|
|
164
|
+
// src/radio/createRadioGroupState.ts
|
|
165
|
+
var radioGroupSyncVersion = /* @__PURE__ */ new WeakMap();
|
|
161
166
|
function createRadioGroupState(props = {}) {
|
|
162
167
|
const getProps = () => access(props);
|
|
163
168
|
const initialProps = untrack(() => getProps());
|
|
@@ -179,7 +184,6 @@ function createRadioGroupState(props = {}) {
|
|
|
179
184
|
return getProps().isInvalid ?? false;
|
|
180
185
|
};
|
|
181
186
|
function setSelectedValue(value) {
|
|
182
|
-
var _a;
|
|
183
187
|
const p = getProps();
|
|
184
188
|
if (p.isReadOnly || p.isDisabled) {
|
|
185
189
|
return;
|
|
@@ -189,7 +193,7 @@ function createRadioGroupState(props = {}) {
|
|
|
189
193
|
setInternalValue(value);
|
|
190
194
|
}
|
|
191
195
|
if (value != null) {
|
|
192
|
-
|
|
196
|
+
p.onChange?.(value);
|
|
193
197
|
}
|
|
194
198
|
}
|
|
195
199
|
function setLastFocusedValue(value) {
|
|
@@ -218,16 +222,5 @@ function createRadioGroupState(props = {}) {
|
|
|
218
222
|
radioGroupSyncVersion.set(state, syncVersion);
|
|
219
223
|
return state;
|
|
220
224
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
canUseDOM,
|
|
224
|
-
createCheckboxGroupState,
|
|
225
|
-
createId,
|
|
226
|
-
createIsSSR,
|
|
227
|
-
createRadioGroupState,
|
|
228
|
-
createTextFieldState,
|
|
229
|
-
createToggleState,
|
|
230
|
-
isAccessor,
|
|
231
|
-
radioGroupSyncVersion
|
|
232
|
-
};
|
|
233
|
-
//# sourceMappingURL=index.js.map
|
|
225
|
+
|
|
226
|
+
export { access, canUseDOM, createCheckboxGroupState, createId, createIsSSR, createRadioGroupState, createTextFieldState, createToggleState, isAccessor, radioGroupSyncVersion };
|
package/dist/index.jsx
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// src/toggle/createToggleState.ts
|
|
2
|
+
import { createSignal } from "solid-js";
|
|
3
|
+
|
|
4
|
+
// src/utils/reactivity.ts
|
|
5
|
+
function access(value) {
|
|
6
|
+
return typeof value === "function" ? value() : value;
|
|
7
|
+
}
|
|
8
|
+
function isAccessor(value) {
|
|
9
|
+
return typeof value === "function";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/toggle/createToggleState.ts
|
|
13
|
+
function createToggleState(props = {}) {
|
|
14
|
+
const getProps = () => access(props);
|
|
15
|
+
const initialProps = getProps();
|
|
16
|
+
const initialSelected = initialProps.isSelected ?? initialProps.defaultSelected ?? false;
|
|
17
|
+
const [internalSelected, setInternalSelected] = createSignal(initialSelected);
|
|
18
|
+
const isControlled = () => getProps().isSelected !== void 0;
|
|
19
|
+
const isSelected = () => {
|
|
20
|
+
const p = getProps();
|
|
21
|
+
return isControlled() ? p.isSelected ?? false : internalSelected();
|
|
22
|
+
};
|
|
23
|
+
function setSelected(value) {
|
|
24
|
+
const p = getProps();
|
|
25
|
+
if (p.isReadOnly) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!isControlled()) {
|
|
29
|
+
setInternalSelected(value);
|
|
30
|
+
}
|
|
31
|
+
p.onChange?.(value);
|
|
32
|
+
}
|
|
33
|
+
function toggle() {
|
|
34
|
+
const p = getProps();
|
|
35
|
+
if (p.isReadOnly) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
setSelected(!isSelected());
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
isSelected,
|
|
42
|
+
defaultSelected: initialProps.defaultSelected ?? initialSelected,
|
|
43
|
+
setSelected,
|
|
44
|
+
toggle
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/textfield/createTextFieldState.ts
|
|
49
|
+
import { createSignal as createSignal2 } from "solid-js";
|
|
50
|
+
function createTextFieldState(props = {}) {
|
|
51
|
+
const getProps = () => access(props);
|
|
52
|
+
const initialProps = getProps();
|
|
53
|
+
const initialValue = initialProps.value ?? initialProps.defaultValue ?? "";
|
|
54
|
+
const [internalValue, setInternalValue] = createSignal2(initialValue);
|
|
55
|
+
const isControlled = () => getProps().value !== void 0;
|
|
56
|
+
const value = () => {
|
|
57
|
+
const p = getProps();
|
|
58
|
+
return isControlled() ? p.value ?? "" : internalValue();
|
|
59
|
+
};
|
|
60
|
+
function setValue(newValue) {
|
|
61
|
+
const p = getProps();
|
|
62
|
+
if (!isControlled()) {
|
|
63
|
+
setInternalValue(newValue);
|
|
64
|
+
}
|
|
65
|
+
p.onChange?.(newValue);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
value,
|
|
69
|
+
setValue
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/checkbox/createCheckboxGroupState.ts
|
|
74
|
+
import { createSignal as createSignal3 } from "solid-js";
|
|
75
|
+
function createCheckboxGroupState(props = {}) {
|
|
76
|
+
const getProps = () => access(props);
|
|
77
|
+
const initialProps = getProps();
|
|
78
|
+
const initialValue = initialProps.value ?? initialProps.defaultValue ?? [];
|
|
79
|
+
const [internalValue, setInternalValue] = createSignal3(initialValue);
|
|
80
|
+
const isControlled = () => getProps().value !== void 0;
|
|
81
|
+
const value = () => {
|
|
82
|
+
const p = getProps();
|
|
83
|
+
return isControlled() ? p.value ?? [] : internalValue();
|
|
84
|
+
};
|
|
85
|
+
const isRequired = () => {
|
|
86
|
+
const p = getProps();
|
|
87
|
+
return !!p.isRequired && value().length === 0;
|
|
88
|
+
};
|
|
89
|
+
const isInvalid = () => {
|
|
90
|
+
return getProps().isInvalid ?? false;
|
|
91
|
+
};
|
|
92
|
+
function setValue(newValue) {
|
|
93
|
+
const p = getProps();
|
|
94
|
+
if (p.isReadOnly || p.isDisabled) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!isControlled()) {
|
|
98
|
+
setInternalValue(newValue);
|
|
99
|
+
}
|
|
100
|
+
p.onChange?.(newValue);
|
|
101
|
+
}
|
|
102
|
+
function isSelected(checkValue) {
|
|
103
|
+
return value().includes(checkValue);
|
|
104
|
+
}
|
|
105
|
+
function addValue(addVal) {
|
|
106
|
+
const p = getProps();
|
|
107
|
+
if (p.isReadOnly || p.isDisabled) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const current = value();
|
|
111
|
+
if (!current.includes(addVal)) {
|
|
112
|
+
setValue([...current, addVal]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function removeValue(removeVal) {
|
|
116
|
+
const p = getProps();
|
|
117
|
+
if (p.isReadOnly || p.isDisabled) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const current = value();
|
|
121
|
+
if (current.includes(removeVal)) {
|
|
122
|
+
setValue(current.filter((v) => v !== removeVal));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function toggleValue(toggleVal) {
|
|
126
|
+
const p = getProps();
|
|
127
|
+
if (p.isReadOnly || p.isDisabled) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const current = value();
|
|
131
|
+
if (current.includes(toggleVal)) {
|
|
132
|
+
setValue(current.filter((v) => v !== toggleVal));
|
|
133
|
+
} else {
|
|
134
|
+
setValue([...current, toggleVal]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
value,
|
|
139
|
+
defaultValue: initialProps.defaultValue ?? initialValue,
|
|
140
|
+
get isDisabled() {
|
|
141
|
+
return getProps().isDisabled ?? false;
|
|
142
|
+
},
|
|
143
|
+
get isReadOnly() {
|
|
144
|
+
return getProps().isReadOnly ?? false;
|
|
145
|
+
},
|
|
146
|
+
get isInvalid() {
|
|
147
|
+
return isInvalid();
|
|
148
|
+
},
|
|
149
|
+
isRequired,
|
|
150
|
+
isSelected,
|
|
151
|
+
setValue,
|
|
152
|
+
addValue,
|
|
153
|
+
removeValue,
|
|
154
|
+
toggleValue
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/radio/createRadioGroupState.ts
|
|
159
|
+
import { createSignal as createSignal4, untrack } from "solid-js";
|
|
160
|
+
|
|
161
|
+
// src/ssr/index.ts
|
|
162
|
+
import { createUniqueId } from "solid-js";
|
|
163
|
+
import { isServer } from "solid-js/web";
|
|
164
|
+
function createIsSSR() {
|
|
165
|
+
return isServer;
|
|
166
|
+
}
|
|
167
|
+
function createId(defaultId) {
|
|
168
|
+
if (defaultId) {
|
|
169
|
+
return defaultId;
|
|
170
|
+
}
|
|
171
|
+
return `solid-stately-${createUniqueId()}`;
|
|
172
|
+
}
|
|
173
|
+
var canUseDOM = !isServer;
|
|
174
|
+
|
|
175
|
+
// src/radio/createRadioGroupState.ts
|
|
176
|
+
var radioGroupSyncVersion = /* @__PURE__ */ new WeakMap();
|
|
177
|
+
function createRadioGroupState(props = {}) {
|
|
178
|
+
const getProps = () => access(props);
|
|
179
|
+
const initialProps = untrack(() => getProps());
|
|
180
|
+
const name = initialProps.name || `radio-group-${createId()}`;
|
|
181
|
+
const [internalValue, setInternalValue] = createSignal4(
|
|
182
|
+
initialProps.defaultValue ?? null
|
|
183
|
+
);
|
|
184
|
+
const [lastFocusedValue, setLastFocusedValueInternal] = createSignal4(null);
|
|
185
|
+
const [syncVersion, setSyncVersion] = createSignal4(0);
|
|
186
|
+
const isControlled = () => getProps().value !== void 0;
|
|
187
|
+
const selectedValue = () => {
|
|
188
|
+
const p = getProps();
|
|
189
|
+
if (p.value !== void 0) {
|
|
190
|
+
return p.value ?? null;
|
|
191
|
+
}
|
|
192
|
+
return internalValue();
|
|
193
|
+
};
|
|
194
|
+
const isInvalid = () => {
|
|
195
|
+
return getProps().isInvalid ?? false;
|
|
196
|
+
};
|
|
197
|
+
function setSelectedValue(value) {
|
|
198
|
+
const p = getProps();
|
|
199
|
+
if (p.isReadOnly || p.isDisabled) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
setSyncVersion((v) => v + 1);
|
|
203
|
+
if (!isControlled()) {
|
|
204
|
+
setInternalValue(value);
|
|
205
|
+
}
|
|
206
|
+
if (value != null) {
|
|
207
|
+
p.onChange?.(value);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function setLastFocusedValue(value) {
|
|
211
|
+
setLastFocusedValueInternal(value);
|
|
212
|
+
}
|
|
213
|
+
const state = {
|
|
214
|
+
name,
|
|
215
|
+
selectedValue,
|
|
216
|
+
defaultSelectedValue: initialProps.defaultValue ?? null,
|
|
217
|
+
setSelectedValue,
|
|
218
|
+
lastFocusedValue,
|
|
219
|
+
setLastFocusedValue,
|
|
220
|
+
get isDisabled() {
|
|
221
|
+
return getProps().isDisabled ?? false;
|
|
222
|
+
},
|
|
223
|
+
get isReadOnly() {
|
|
224
|
+
return getProps().isReadOnly ?? false;
|
|
225
|
+
},
|
|
226
|
+
get isRequired() {
|
|
227
|
+
return getProps().isRequired ?? false;
|
|
228
|
+
},
|
|
229
|
+
get isInvalid() {
|
|
230
|
+
return isInvalid();
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
radioGroupSyncVersion.set(state, syncVersion);
|
|
234
|
+
return state;
|
|
235
|
+
}
|
|
236
|
+
export {
|
|
237
|
+
access,
|
|
238
|
+
canUseDOM,
|
|
239
|
+
createCheckboxGroupState,
|
|
240
|
+
createId,
|
|
241
|
+
createIsSSR,
|
|
242
|
+
createRadioGroupState,
|
|
243
|
+
createTextFieldState,
|
|
244
|
+
createToggleState,
|
|
245
|
+
isAccessor,
|
|
246
|
+
radioGroupSyncVersion
|
|
247
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proyecto-viviana/solid-stately",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A 1-1 SolidJS port of React Stately - headless state management for UI components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"solid": "./
|
|
11
|
+
"solid": "./dist/index.jsx",
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
13
|
"types": "./dist/index.d.ts"
|
|
14
14
|
}
|
|
@@ -19,15 +19,17 @@
|
|
|
19
19
|
],
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "
|
|
23
|
-
"dev": "
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
24
|
"prepublishOnly": "bun run build"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"solid-js": "^1.9.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"solid
|
|
30
|
+
"esbuild-plugin-solid": "^0.6.0",
|
|
31
|
+
"solid-js": "^1.9.10",
|
|
32
|
+
"tsup": "^8.0.0"
|
|
31
33
|
},
|
|
32
34
|
"keywords": [
|
|
33
35
|
"solid",
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checkbox group state for Solid Stately
|
|
3
|
-
*
|
|
4
|
-
* Provides state management for a checkbox group component.
|
|
5
|
-
* Provides a name for the group, and manages selection and focus state.
|
|
6
|
-
*
|
|
7
|
-
* This is a 1:1 port of @react-stately/checkbox's useCheckboxGroupState.
|
|
8
|
-
*/
|
|
9
|
-
import { Accessor } from 'solid-js';
|
|
10
|
-
import { type MaybeAccessor } from '../utils';
|
|
11
|
-
export interface CheckboxGroupProps {
|
|
12
|
-
/** The current selected values (controlled). */
|
|
13
|
-
value?: string[];
|
|
14
|
-
/** The default selected values (uncontrolled). */
|
|
15
|
-
defaultValue?: string[];
|
|
16
|
-
/** Handler that is called when the value changes. */
|
|
17
|
-
onChange?: (value: string[]) => void;
|
|
18
|
-
/** Whether the checkbox group is disabled. */
|
|
19
|
-
isDisabled?: boolean;
|
|
20
|
-
/** Whether the checkbox group is read only. */
|
|
21
|
-
isReadOnly?: boolean;
|
|
22
|
-
/** Whether the checkbox group is required. */
|
|
23
|
-
isRequired?: boolean;
|
|
24
|
-
/** Whether the checkbox group is invalid. */
|
|
25
|
-
isInvalid?: boolean;
|
|
26
|
-
/** The name of the checkbox group, used when submitting an HTML form. */
|
|
27
|
-
name?: string;
|
|
28
|
-
/** The form to associate the checkbox group with. */
|
|
29
|
-
form?: string;
|
|
30
|
-
/** The label for the checkbox group. */
|
|
31
|
-
label?: string;
|
|
32
|
-
/** Handler that is called when the checkbox group receives focus. */
|
|
33
|
-
onFocus?: (e: FocusEvent) => void;
|
|
34
|
-
/** Handler that is called when the checkbox group loses focus. */
|
|
35
|
-
onBlur?: (e: FocusEvent) => void;
|
|
36
|
-
/** Handler that is called when the checkbox group's focus status changes. */
|
|
37
|
-
onFocusChange?: (isFocused: boolean) => void;
|
|
38
|
-
}
|
|
39
|
-
export interface CheckboxGroupState {
|
|
40
|
-
/** Current selected values. */
|
|
41
|
-
readonly value: Accessor<readonly string[]>;
|
|
42
|
-
/** Default selected values. */
|
|
43
|
-
readonly defaultValue: readonly string[];
|
|
44
|
-
/** Whether the checkbox group is disabled. */
|
|
45
|
-
readonly isDisabled: boolean;
|
|
46
|
-
/** Whether the checkbox group is read only. */
|
|
47
|
-
readonly isReadOnly: boolean;
|
|
48
|
-
/** Whether the checkbox group is invalid. */
|
|
49
|
-
readonly isInvalid: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Whether the checkboxes in the group are required.
|
|
52
|
-
* This changes to false once at least one item is selected.
|
|
53
|
-
*/
|
|
54
|
-
readonly isRequired: Accessor<boolean>;
|
|
55
|
-
/** Returns whether the given value is selected. */
|
|
56
|
-
isSelected(value: string): boolean;
|
|
57
|
-
/** Sets the selected values. */
|
|
58
|
-
setValue(value: string[]): void;
|
|
59
|
-
/** Adds a value to the set of selected values. */
|
|
60
|
-
addValue(value: string): void;
|
|
61
|
-
/** Removes a value from the set of selected values. */
|
|
62
|
-
removeValue(value: string): void;
|
|
63
|
-
/** Toggles a value in the set of selected values. */
|
|
64
|
-
toggleValue(value: string): void;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Provides state management for a checkbox group component.
|
|
68
|
-
* Provides a name for the group, and manages selection and focus state.
|
|
69
|
-
*/
|
|
70
|
-
export declare function createCheckboxGroupState(props?: MaybeAccessor<CheckboxGroupProps>): CheckboxGroupState;
|
package/dist/checkbox/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createCheckboxGroupState, type CheckboxGroupProps, type CheckboxGroupState, } from './createCheckboxGroupState';
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils/reactivity.ts","../src/toggle/createToggleState.ts","../src/textfield/createTextFieldState.ts","../src/checkbox/createCheckboxGroupState.ts","../src/ssr/index.ts","../src/radio/createRadioGroupState.ts"],"sourcesContent":["/**\n * Reactivity utilities for Solid Stately\n *\n * Provides type-safe utilities for working with SolidJS reactivity patterns.\n */\n\nimport { Accessor } from 'solid-js';\n\n/**\n * A value that may be either a raw value or an accessor function.\n * This is a common pattern in SolidJS for props that may be reactive.\n */\nexport type MaybeAccessor<T> = T | Accessor<T>;\n\n/**\n * Unwraps a MaybeAccessor to get the underlying value.\n * If the input is a function, it calls it to get the value.\n * Otherwise, it returns the value directly.\n *\n * @param value - The value or accessor to unwrap.\n */\nexport function access<T>(value: MaybeAccessor<T>): T {\n return typeof value === 'function' ? (value as Accessor<T>)() : value;\n}\n\n/**\n * A value that may be undefined or an accessor that returns the value or undefined.\n */\nexport type MaybeAccessorValue<T> = T | undefined | Accessor<T | undefined>;\n\n/**\n * Checks if a value is an accessor function.\n */\nexport function isAccessor<T>(value: MaybeAccessor<T>): value is Accessor<T> {\n return typeof value === 'function';\n}\n","/**\n * Toggle state for Solid Stately\n *\n * Provides state management for toggle components like checkboxes and switches.\n *\n * This is a 1:1 port of @react-stately/toggle's useToggleState.\n */\n\nimport { createSignal, Accessor } from 'solid-js';\nimport { type MaybeAccessor, access } from '../utils';\n\n// ============================================\n// TYPES\n// ============================================\n\nexport interface ToggleStateOptions {\n /** Whether the element should be selected (controlled). */\n isSelected?: boolean;\n /** Whether the element should be selected by default (uncontrolled). */\n defaultSelected?: boolean;\n /** Handler that is called when the element's selection state changes. */\n onChange?: (isSelected: boolean) => void;\n /** Whether the element is read only. */\n isReadOnly?: boolean;\n}\n\nexport interface ToggleState {\n /** Whether the toggle is selected. */\n readonly isSelected: Accessor<boolean>;\n /** Whether the toggle is selected by default. */\n readonly defaultSelected: boolean;\n /** Updates selection state. */\n setSelected(isSelected: boolean): void;\n /** Toggle the selection state. */\n toggle(): void;\n}\n\n// ============================================\n// IMPLEMENTATION\n// ============================================\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function createToggleState(props: MaybeAccessor<ToggleStateOptions> = {}): ToggleState {\n const getProps = () => access(props);\n\n // Get initial values\n const initialProps = getProps();\n const initialSelected = initialProps.isSelected ?? initialProps.defaultSelected ?? false;\n\n // Create internal signal for uncontrolled mode\n const [internalSelected, setInternalSelected] = createSignal(initialSelected);\n\n // Determine if controlled\n const isControlled = () => getProps().isSelected !== undefined;\n\n // Get current selection state\n const isSelected: Accessor<boolean> = () => {\n const p = getProps();\n return isControlled() ? (p.isSelected ?? false) : internalSelected();\n };\n\n // Update selection state\n function setSelected(value: boolean): void {\n const p = getProps();\n if (p.isReadOnly) {\n return;\n }\n\n if (!isControlled()) {\n setInternalSelected(value);\n }\n\n p.onChange?.(value);\n }\n\n // Toggle selection state\n function toggle(): void {\n const p = getProps();\n if (p.isReadOnly) {\n return;\n }\n\n setSelected(!isSelected());\n }\n\n return {\n isSelected,\n defaultSelected: initialProps.defaultSelected ?? initialSelected,\n setSelected,\n toggle,\n };\n}\n","/**\n * TextField state for Solid Stately\n *\n * Provides state management for text input components.\n *\n * This is a port of @react-stately/utils's useControlledState pattern\n * as used by @react-aria/textfield.\n */\n\nimport { createSignal, Accessor } from 'solid-js';\nimport { type MaybeAccessor, access } from '../utils';\n\n// ============================================\n// TYPES\n// ============================================\n\nexport interface TextFieldStateOptions {\n /** The current value (controlled). */\n value?: string;\n /** The default value (uncontrolled). */\n defaultValue?: string;\n /** Handler that is called when the value changes. */\n onChange?: (value: string) => void;\n}\n\nexport interface TextFieldState {\n /** The current value of the text field. */\n readonly value: Accessor<string>;\n /** Sets the value of the text field. */\n setValue(value: string): void;\n}\n\n// ============================================\n// IMPLEMENTATION\n// ============================================\n\n/**\n * Provides state management for text input components.\n * Supports both controlled and uncontrolled modes.\n */\nexport function createTextFieldState(props: MaybeAccessor<TextFieldStateOptions> = {}): TextFieldState {\n const getProps = () => access(props);\n\n // Get initial value\n const initialProps = getProps();\n const initialValue = initialProps.value ?? initialProps.defaultValue ?? '';\n\n // Create internal signal for uncontrolled mode\n const [internalValue, setInternalValue] = createSignal(initialValue);\n\n // Determine if controlled\n const isControlled = () => getProps().value !== undefined;\n\n // Get current value\n const value: Accessor<string> = () => {\n const p = getProps();\n return isControlled() ? (p.value ?? '') : internalValue();\n };\n\n // Update value\n function setValue(newValue: string): void {\n const p = getProps();\n\n if (!isControlled()) {\n setInternalValue(newValue);\n }\n\n p.onChange?.(newValue);\n }\n\n return {\n value,\n setValue,\n };\n}\n","/**\n * Checkbox group state for Solid Stately\n *\n * Provides state management for a checkbox group component.\n * Provides a name for the group, and manages selection and focus state.\n *\n * This is a 1:1 port of @react-stately/checkbox's useCheckboxGroupState.\n */\n\nimport { createSignal, Accessor } from 'solid-js';\nimport { type MaybeAccessor, access } from '../utils';\n\n// ============================================\n// TYPES\n// ============================================\n\nexport interface CheckboxGroupProps {\n /** The current selected values (controlled). */\n value?: string[];\n /** The default selected values (uncontrolled). */\n defaultValue?: string[];\n /** Handler that is called when the value changes. */\n onChange?: (value: string[]) => void;\n /** Whether the checkbox group is disabled. */\n isDisabled?: boolean;\n /** Whether the checkbox group is read only. */\n isReadOnly?: boolean;\n /** Whether the checkbox group is required. */\n isRequired?: boolean;\n /** Whether the checkbox group is invalid. */\n isInvalid?: boolean;\n /** The name of the checkbox group, used when submitting an HTML form. */\n name?: string;\n /** The form to associate the checkbox group with. */\n form?: string;\n /** The label for the checkbox group. */\n label?: string;\n /** Handler that is called when the checkbox group receives focus. */\n onFocus?: (e: FocusEvent) => void;\n /** Handler that is called when the checkbox group loses focus. */\n onBlur?: (e: FocusEvent) => void;\n /** Handler that is called when the checkbox group's focus status changes. */\n onFocusChange?: (isFocused: boolean) => void;\n}\n\nexport interface CheckboxGroupState {\n /** Current selected values. */\n readonly value: Accessor<readonly string[]>;\n /** Default selected values. */\n readonly defaultValue: readonly string[];\n /** Whether the checkbox group is disabled. */\n readonly isDisabled: boolean;\n /** Whether the checkbox group is read only. */\n readonly isReadOnly: boolean;\n /** Whether the checkbox group is invalid. */\n readonly isInvalid: boolean;\n /**\n * Whether the checkboxes in the group are required.\n * This changes to false once at least one item is selected.\n */\n readonly isRequired: Accessor<boolean>;\n /** Returns whether the given value is selected. */\n isSelected(value: string): boolean;\n /** Sets the selected values. */\n setValue(value: string[]): void;\n /** Adds a value to the set of selected values. */\n addValue(value: string): void;\n /** Removes a value from the set of selected values. */\n removeValue(value: string): void;\n /** Toggles a value in the set of selected values. */\n toggleValue(value: string): void;\n}\n\n// ============================================\n// IMPLEMENTATION\n// ============================================\n\n/**\n * Provides state management for a checkbox group component.\n * Provides a name for the group, and manages selection and focus state.\n */\nexport function createCheckboxGroupState(\n props: MaybeAccessor<CheckboxGroupProps> = {}\n): CheckboxGroupState {\n const getProps = () => access(props);\n\n // Get initial values\n const initialProps = getProps();\n const initialValue = initialProps.value ?? initialProps.defaultValue ?? [];\n\n // Create internal signal for uncontrolled mode\n const [internalValue, setInternalValue] = createSignal<readonly string[]>(initialValue);\n\n // Determine if controlled\n const isControlled = () => getProps().value !== undefined;\n\n // Get current value\n const value: Accessor<readonly string[]> = () => {\n const p = getProps();\n return isControlled() ? (p.value ?? []) : internalValue();\n };\n\n // Check if required (true if isRequired and no items selected)\n const isRequired: Accessor<boolean> = () => {\n const p = getProps();\n return !!p.isRequired && value().length === 0;\n };\n\n // Check if invalid\n const isInvalid = () => {\n return getProps().isInvalid ?? false;\n };\n\n // Set value\n function setValue(newValue: string[]): void {\n const p = getProps();\n if (p.isReadOnly || p.isDisabled) {\n return;\n }\n\n if (!isControlled()) {\n setInternalValue(newValue);\n }\n\n p.onChange?.(newValue);\n }\n\n // Check if value is selected\n function isSelected(checkValue: string): boolean {\n return value().includes(checkValue);\n }\n\n // Add value\n function addValue(addVal: string): void {\n const p = getProps();\n if (p.isReadOnly || p.isDisabled) {\n return;\n }\n\n const current = value();\n if (!current.includes(addVal)) {\n setValue([...current, addVal]);\n }\n }\n\n // Remove value\n function removeValue(removeVal: string): void {\n const p = getProps();\n if (p.isReadOnly || p.isDisabled) {\n return;\n }\n\n const current = value();\n if (current.includes(removeVal)) {\n setValue(current.filter((v) => v !== removeVal));\n }\n }\n\n // Toggle value\n function toggleValue(toggleVal: string): void {\n const p = getProps();\n if (p.isReadOnly || p.isDisabled) {\n return;\n }\n\n const current = value();\n if (current.includes(toggleVal)) {\n setValue(current.filter((v) => v !== toggleVal));\n } else {\n setValue([...current, toggleVal]);\n }\n }\n\n return {\n value,\n defaultValue: initialProps.defaultValue ?? initialValue,\n get isDisabled() {\n return getProps().isDisabled ?? false;\n },\n get isReadOnly() {\n return getProps().isReadOnly ?? false;\n },\n get isInvalid() {\n return isInvalid();\n },\n isRequired,\n isSelected,\n setValue,\n addValue,\n removeValue,\n toggleValue,\n };\n}\n","/**\n * SSR utilities for Solid Stately\n *\n * SolidJS has built-in SSR support with `isServer` and `createUniqueId()`.\n * These utilities provide a consistent API matching React-Stately's patterns.\n */\n\nimport { createUniqueId } from 'solid-js';\nimport { isServer } from 'solid-js/web';\n\n/**\n * Returns whether the component is currently being server side rendered.\n * Can be used to delay browser-specific rendering until after hydration.\n */\nexport function createIsSSR(): boolean {\n return isServer;\n}\n\n/**\n * Generate a unique ID that is stable across server and client.\n * Uses SolidJS's built-in createUniqueId which handles SSR correctly.\n *\n * @param defaultId - Optional default ID to use instead of generating one.\n */\nexport function createId(defaultId?: string): string {\n if (defaultId) {\n return defaultId;\n }\n return `solid-stately-${createUniqueId()}`;\n}\n\n/**\n * Check if we can use DOM APIs.\n * This is useful for code that needs to run only in the browser.\n */\nexport const canUseDOM = !isServer;\n","/**\n * Radio group state for Solid Stately\n *\n * Provides state management for a radio group component.\n * Provides a name for the group, and manages selection and focus state.\n *\n * This is a 1:1 port of @react-stately/radio's useRadioGroupState.\n */\n\nimport { createSignal, Accessor, untrack } from 'solid-js';\nimport { type MaybeAccessor, access } from '../utils';\nimport { createId } from '../ssr';\n\n// ============================================\n// TYPES\n// ============================================\n\nexport interface RadioGroupProps {\n /** The current selected value (controlled). */\n value?: string | null;\n /** The default selected value (uncontrolled). */\n defaultValue?: string | null;\n /** Handler that is called when the value changes. */\n onChange?: (value: string) => void;\n /** Whether the radio group is disabled. */\n isDisabled?: boolean;\n /** Whether the radio group is read only. */\n isReadOnly?: boolean;\n /** Whether the radio group is required. */\n isRequired?: boolean;\n /** Whether the radio group is invalid. */\n isInvalid?: boolean;\n /** The name of the radio group, used when submitting an HTML form. */\n name?: string;\n /** The form to associate the radio group with. */\n form?: string;\n /** The label for the radio group. */\n label?: string;\n /** Orientation of the radio group. */\n orientation?: 'horizontal' | 'vertical';\n /** Handler that is called when the radio group receives focus. */\n onFocus?: (e: FocusEvent) => void;\n /** Handler that is called when the radio group loses focus. */\n onBlur?: (e: FocusEvent) => void;\n /** Handler that is called when the radio group's focus status changes. */\n onFocusChange?: (isFocused: boolean) => void;\n}\n\nexport interface RadioGroupState {\n /** The name for the group, used for native form submission. */\n readonly name: string;\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean;\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean;\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean;\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean;\n\n /** The currently selected value. */\n readonly selectedValue: Accessor<string | null>;\n\n /** The default selected value. */\n readonly defaultSelectedValue: string | null;\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void;\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: Accessor<string | null>;\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void;\n}\n\n// ============================================\n// INTERNAL: SolidJS-specific sync mechanism\n// ============================================\n\n/**\n * Internal WeakMap to store sync version accessors for each radio group state.\n * This is used by createRadio to trigger DOM sync when native radio behavior\n * causes the DOM checked state to desync from our reactive state.\n *\n * This is kept separate from RadioGroupState to maintain API parity with React-Stately.\n * @internal\n */\nexport const radioGroupSyncVersion: WeakMap<RadioGroupState, Accessor<number>> = new WeakMap();\n\n// ============================================\n// IMPLEMENTATION\n// ============================================\n\n/**\n * Provides state management for a radio group component.\n * Provides a name for the group, and manages selection and focus state.\n */\nexport function createRadioGroupState(\n props: MaybeAccessor<RadioGroupProps> = {}\n): RadioGroupState {\n const getProps = () => access(props);\n\n // Get initial props using untrack to avoid setting up dependencies\n // This ensures we capture the initial defaultValue without reactivity issues\n const initialProps = untrack(() => getProps());\n\n // Generate name - preserved for backward compatibility\n // React Aria now generates the name instead of stately\n const name = initialProps.name || `radio-group-${createId()}`;\n\n // Create internal signal for uncontrolled mode\n // Initialize with defaultValue only (not value, which is for controlled mode)\n const [internalValue, setInternalValue] = createSignal<string | null>(\n initialProps.defaultValue ?? null\n );\n const [lastFocusedValue, setLastFocusedValueInternal] = createSignal<string | null>(null);\n\n // SolidJS-specific: Version counter for triggering DOM sync across all radios\n // This handles the case where native radio behavior causes DOM state to desync\n // from our reactive state (e.g., clicking a radio unchecks siblings in the DOM)\n const [syncVersion, setSyncVersion] = createSignal(0);\n\n // Determine if controlled - must be reactive to handle dynamic props\n const isControlled = () => getProps().value !== undefined;\n\n // Get current value - reactive for both controlled and uncontrolled modes\n const selectedValue: Accessor<string | null> = () => {\n const p = getProps();\n // In controlled mode, always read from props.value reactively\n // In uncontrolled mode, read from internal signal\n if (p.value !== undefined) {\n return p.value ?? null;\n }\n return internalValue();\n };\n\n // Check if invalid\n const isInvalid = () => {\n return getProps().isInvalid ?? false;\n };\n\n // Set value\n function setSelectedValue(value: string | null): void {\n const p = getProps();\n if (p.isReadOnly || p.isDisabled) {\n return;\n }\n\n // Always increment syncVersion to trigger DOM sync across all radios\n // This is crucial for SolidJS because:\n // 1. Native radio behavior unchecks siblings when one is checked\n // 2. In controlled mode, isSelected() may not change even though DOM changed\n // 3. We need ALL radios to re-sync their checked state after any click\n setSyncVersion((v) => v + 1);\n\n if (!isControlled()) {\n setInternalValue(value);\n }\n\n if (value != null) {\n p.onChange?.(value);\n }\n }\n\n // Set last focused value\n function setLastFocusedValue(value: string | null): void {\n setLastFocusedValueInternal(value);\n }\n\n const state: RadioGroupState = {\n name,\n selectedValue,\n defaultSelectedValue: initialProps.defaultValue ?? null,\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n get isDisabled() {\n return getProps().isDisabled ?? false;\n },\n get isReadOnly() {\n return getProps().isReadOnly ?? false;\n },\n get isRequired() {\n return getProps().isRequired ?? false;\n },\n get isInvalid() {\n return isInvalid();\n },\n };\n\n // Store syncVersion in internal WeakMap (not part of public API)\n // This maintains API parity with React-Stately while supporting SolidJS's reactivity needs\n radioGroupSyncVersion.set(state, syncVersion);\n\n return state;\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Radio group state for Solid Stately
|
|
3
|
-
*
|
|
4
|
-
* Provides state management for a radio group component.
|
|
5
|
-
* Provides a name for the group, and manages selection and focus state.
|
|
6
|
-
*
|
|
7
|
-
* This is a 1:1 port of @react-stately/radio's useRadioGroupState.
|
|
8
|
-
*/
|
|
9
|
-
import { Accessor } from 'solid-js';
|
|
10
|
-
import { type MaybeAccessor } from '../utils';
|
|
11
|
-
export interface RadioGroupProps {
|
|
12
|
-
/** The current selected value (controlled). */
|
|
13
|
-
value?: string | null;
|
|
14
|
-
/** The default selected value (uncontrolled). */
|
|
15
|
-
defaultValue?: string | null;
|
|
16
|
-
/** Handler that is called when the value changes. */
|
|
17
|
-
onChange?: (value: string) => void;
|
|
18
|
-
/** Whether the radio group is disabled. */
|
|
19
|
-
isDisabled?: boolean;
|
|
20
|
-
/** Whether the radio group is read only. */
|
|
21
|
-
isReadOnly?: boolean;
|
|
22
|
-
/** Whether the radio group is required. */
|
|
23
|
-
isRequired?: boolean;
|
|
24
|
-
/** Whether the radio group is invalid. */
|
|
25
|
-
isInvalid?: boolean;
|
|
26
|
-
/** The name of the radio group, used when submitting an HTML form. */
|
|
27
|
-
name?: string;
|
|
28
|
-
/** The form to associate the radio group with. */
|
|
29
|
-
form?: string;
|
|
30
|
-
/** The label for the radio group. */
|
|
31
|
-
label?: string;
|
|
32
|
-
/** Orientation of the radio group. */
|
|
33
|
-
orientation?: 'horizontal' | 'vertical';
|
|
34
|
-
/** Handler that is called when the radio group receives focus. */
|
|
35
|
-
onFocus?: (e: FocusEvent) => void;
|
|
36
|
-
/** Handler that is called when the radio group loses focus. */
|
|
37
|
-
onBlur?: (e: FocusEvent) => void;
|
|
38
|
-
/** Handler that is called when the radio group's focus status changes. */
|
|
39
|
-
onFocusChange?: (isFocused: boolean) => void;
|
|
40
|
-
}
|
|
41
|
-
export interface RadioGroupState {
|
|
42
|
-
/** The name for the group, used for native form submission. */
|
|
43
|
-
readonly name: string;
|
|
44
|
-
/** Whether the radio group is disabled. */
|
|
45
|
-
readonly isDisabled: boolean;
|
|
46
|
-
/** Whether the radio group is read only. */
|
|
47
|
-
readonly isReadOnly: boolean;
|
|
48
|
-
/** Whether the radio group is required. */
|
|
49
|
-
readonly isRequired: boolean;
|
|
50
|
-
/** Whether the radio group is invalid. */
|
|
51
|
-
readonly isInvalid: boolean;
|
|
52
|
-
/** The currently selected value. */
|
|
53
|
-
readonly selectedValue: Accessor<string | null>;
|
|
54
|
-
/** The default selected value. */
|
|
55
|
-
readonly defaultSelectedValue: string | null;
|
|
56
|
-
/** Sets the selected value. */
|
|
57
|
-
setSelectedValue(value: string | null): void;
|
|
58
|
-
/** The value of the last focused radio. */
|
|
59
|
-
readonly lastFocusedValue: Accessor<string | null>;
|
|
60
|
-
/** Sets the last focused value. */
|
|
61
|
-
setLastFocusedValue(value: string | null): void;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Internal WeakMap to store sync version accessors for each radio group state.
|
|
65
|
-
* This is used by createRadio to trigger DOM sync when native radio behavior
|
|
66
|
-
* causes the DOM checked state to desync from our reactive state.
|
|
67
|
-
*
|
|
68
|
-
* This is kept separate from RadioGroupState to maintain API parity with React-Stately.
|
|
69
|
-
* @internal
|
|
70
|
-
*/
|
|
71
|
-
export declare const radioGroupSyncVersion: WeakMap<RadioGroupState, Accessor<number>>;
|
|
72
|
-
/**
|
|
73
|
-
* Provides state management for a radio group component.
|
|
74
|
-
* Provides a name for the group, and manages selection and focus state.
|
|
75
|
-
*/
|
|
76
|
-
export declare function createRadioGroupState(props?: MaybeAccessor<RadioGroupProps>): RadioGroupState;
|
package/dist/radio/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createRadioGroupState, radioGroupSyncVersion, type RadioGroupProps, type RadioGroupState, } from './createRadioGroupState';
|
package/dist/ssr/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SSR utilities for Solid Stately
|
|
3
|
-
*
|
|
4
|
-
* SolidJS has built-in SSR support with `isServer` and `createUniqueId()`.
|
|
5
|
-
* These utilities provide a consistent API matching React-Stately's patterns.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Returns whether the component is currently being server side rendered.
|
|
9
|
-
* Can be used to delay browser-specific rendering until after hydration.
|
|
10
|
-
*/
|
|
11
|
-
export declare function createIsSSR(): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Generate a unique ID that is stable across server and client.
|
|
14
|
-
* Uses SolidJS's built-in createUniqueId which handles SSR correctly.
|
|
15
|
-
*
|
|
16
|
-
* @param defaultId - Optional default ID to use instead of generating one.
|
|
17
|
-
*/
|
|
18
|
-
export declare function createId(defaultId?: string): string;
|
|
19
|
-
/**
|
|
20
|
-
* Check if we can use DOM APIs.
|
|
21
|
-
* This is useful for code that needs to run only in the browser.
|
|
22
|
-
*/
|
|
23
|
-
export declare const canUseDOM: boolean;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TextField state for Solid Stately
|
|
3
|
-
*
|
|
4
|
-
* Provides state management for text input components.
|
|
5
|
-
*
|
|
6
|
-
* This is a port of @react-stately/utils's useControlledState pattern
|
|
7
|
-
* as used by @react-aria/textfield.
|
|
8
|
-
*/
|
|
9
|
-
import { Accessor } from 'solid-js';
|
|
10
|
-
import { type MaybeAccessor } from '../utils';
|
|
11
|
-
export interface TextFieldStateOptions {
|
|
12
|
-
/** The current value (controlled). */
|
|
13
|
-
value?: string;
|
|
14
|
-
/** The default value (uncontrolled). */
|
|
15
|
-
defaultValue?: string;
|
|
16
|
-
/** Handler that is called when the value changes. */
|
|
17
|
-
onChange?: (value: string) => void;
|
|
18
|
-
}
|
|
19
|
-
export interface TextFieldState {
|
|
20
|
-
/** The current value of the text field. */
|
|
21
|
-
readonly value: Accessor<string>;
|
|
22
|
-
/** Sets the value of the text field. */
|
|
23
|
-
setValue(value: string): void;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Provides state management for text input components.
|
|
27
|
-
* Supports both controlled and uncontrolled modes.
|
|
28
|
-
*/
|
|
29
|
-
export declare function createTextFieldState(props?: MaybeAccessor<TextFieldStateOptions>): TextFieldState;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createTextFieldState, type TextFieldStateOptions, type TextFieldState, } from './createTextFieldState';
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Toggle state for Solid Stately
|
|
3
|
-
*
|
|
4
|
-
* Provides state management for toggle components like checkboxes and switches.
|
|
5
|
-
*
|
|
6
|
-
* This is a 1:1 port of @react-stately/toggle's useToggleState.
|
|
7
|
-
*/
|
|
8
|
-
import { Accessor } from 'solid-js';
|
|
9
|
-
import { type MaybeAccessor } from '../utils';
|
|
10
|
-
export interface ToggleStateOptions {
|
|
11
|
-
/** Whether the element should be selected (controlled). */
|
|
12
|
-
isSelected?: boolean;
|
|
13
|
-
/** Whether the element should be selected by default (uncontrolled). */
|
|
14
|
-
defaultSelected?: boolean;
|
|
15
|
-
/** Handler that is called when the element's selection state changes. */
|
|
16
|
-
onChange?: (isSelected: boolean) => void;
|
|
17
|
-
/** Whether the element is read only. */
|
|
18
|
-
isReadOnly?: boolean;
|
|
19
|
-
}
|
|
20
|
-
export interface ToggleState {
|
|
21
|
-
/** Whether the toggle is selected. */
|
|
22
|
-
readonly isSelected: Accessor<boolean>;
|
|
23
|
-
/** Whether the toggle is selected by default. */
|
|
24
|
-
readonly defaultSelected: boolean;
|
|
25
|
-
/** Updates selection state. */
|
|
26
|
-
setSelected(isSelected: boolean): void;
|
|
27
|
-
/** Toggle the selection state. */
|
|
28
|
-
toggle(): void;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Provides state management for toggle components like checkboxes and switches.
|
|
32
|
-
*/
|
|
33
|
-
export declare function createToggleState(props?: MaybeAccessor<ToggleStateOptions>): ToggleState;
|
package/dist/toggle/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createToggleState, type ToggleStateOptions, type ToggleState, } from './createToggleState';
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { access, isAccessor, type MaybeAccessor, type MaybeAccessorValue } from './reactivity';
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reactivity utilities for Solid Stately
|
|
3
|
-
*
|
|
4
|
-
* Provides type-safe utilities for working with SolidJS reactivity patterns.
|
|
5
|
-
*/
|
|
6
|
-
import { Accessor } from 'solid-js';
|
|
7
|
-
/**
|
|
8
|
-
* A value that may be either a raw value or an accessor function.
|
|
9
|
-
* This is a common pattern in SolidJS for props that may be reactive.
|
|
10
|
-
*/
|
|
11
|
-
export type MaybeAccessor<T> = T | Accessor<T>;
|
|
12
|
-
/**
|
|
13
|
-
* Unwraps a MaybeAccessor to get the underlying value.
|
|
14
|
-
* If the input is a function, it calls it to get the value.
|
|
15
|
-
* Otherwise, it returns the value directly.
|
|
16
|
-
*
|
|
17
|
-
* @param value - The value or accessor to unwrap.
|
|
18
|
-
*/
|
|
19
|
-
export declare function access<T>(value: MaybeAccessor<T>): T;
|
|
20
|
-
/**
|
|
21
|
-
* A value that may be undefined or an accessor that returns the value or undefined.
|
|
22
|
-
*/
|
|
23
|
-
export type MaybeAccessorValue<T> = T | undefined | Accessor<T | undefined>;
|
|
24
|
-
/**
|
|
25
|
-
* Checks if a value is an accessor function.
|
|
26
|
-
*/
|
|
27
|
-
export declare function isAccessor<T>(value: MaybeAccessor<T>): value is Accessor<T>;
|