@proyecto-viviana/solidaria-components 0.2.9 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -272
- package/dist/ActionBar.d.ts +21 -13
- package/dist/ActionBar.d.ts.map +1 -1
- package/dist/ActionGroup.d.ts +8 -8
- package/dist/ActionGroup.d.ts.map +1 -1
- package/dist/Alert.d.ts +5 -5
- package/dist/Alert.d.ts.map +1 -1
- package/dist/Autocomplete.d.ts +5 -5
- package/dist/Autocomplete.d.ts.map +1 -1
- package/dist/Breadcrumbs.d.ts +18 -7
- package/dist/Breadcrumbs.d.ts.map +1 -1
- package/dist/Button.d.ts +24 -5
- package/dist/Button.d.ts.map +1 -1
- package/dist/Calendar.d.ts +38 -7
- package/dist/Calendar.d.ts.map +1 -1
- package/dist/Checkbox.d.ts +32 -7
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Collection.d.ts +19 -14
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Color.d.ts +103 -14
- package/dist/Color.d.ts.map +1 -1
- package/dist/ColorEditor.d.ts +6 -6
- package/dist/ColorEditor.d.ts.map +1 -1
- package/dist/ComboBox.d.ts +85 -19
- package/dist/ComboBox.d.ts.map +1 -1
- package/dist/ContextualHelpTrigger.d.ts +2 -2
- package/dist/ContextualHelpTrigger.d.ts.map +1 -1
- package/dist/DateField.d.ts +8 -6
- package/dist/DateField.d.ts.map +1 -1
- package/dist/DatePicker.d.ts +53 -22
- package/dist/DatePicker.d.ts.map +1 -1
- package/dist/DateRangePickerContext.d.ts +30 -0
- package/dist/DateRangePickerContext.d.ts.map +1 -0
- package/dist/Dialog.d.ts +5 -5
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Disclosure.d.ts +23 -5
- package/dist/Disclosure.d.ts.map +1 -1
- package/dist/DragAndDrop.d.ts +6 -6
- package/dist/DragAndDrop.d.ts.map +1 -1
- package/dist/DragPreview.d.ts +2 -2
- package/dist/DragPreview.d.ts.map +1 -1
- package/dist/DropZone.d.ts +4 -4
- package/dist/DropZone.d.ts.map +1 -1
- package/dist/FieldError.d.ts +9 -5
- package/dist/FieldError.d.ts.map +1 -1
- package/dist/FileTrigger.d.ts +3 -3
- package/dist/FileTrigger.d.ts.map +1 -1
- package/dist/Focusable.d.ts +2 -2
- package/dist/Focusable.d.ts.map +1 -1
- package/dist/Form.d.ts +18 -4
- package/dist/Form.d.ts.map +1 -1
- package/dist/GridList.d.ts +32 -12
- package/dist/GridList.d.ts.map +1 -1
- package/dist/HiddenDateInput.d.ts +26 -0
- package/dist/HiddenDateInput.d.ts.map +1 -0
- package/dist/HiddenTimeInput.d.ts +25 -0
- package/dist/HiddenTimeInput.d.ts.map +1 -0
- package/dist/Icon.d.ts +5 -5
- package/dist/Icon.d.ts.map +1 -1
- package/dist/Keyboard.d.ts +1 -1
- package/dist/Landmark.d.ts +3 -3
- package/dist/Landmark.d.ts.map +1 -1
- package/dist/Link.d.ts +10 -4
- package/dist/Link.d.ts.map +1 -1
- package/dist/ListBox.d.ts +32 -12
- package/dist/ListBox.d.ts.map +1 -1
- package/dist/ListDropTargetDelegate.d.ts +6 -6
- package/dist/ListDropTargetDelegate.d.ts.map +1 -1
- package/dist/Menu.d.ts +65 -14
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Meter.d.ts +3 -3
- package/dist/Meter.d.ts.map +1 -1
- package/dist/Modal.d.ts +5 -5
- package/dist/Modal.d.ts.map +1 -1
- package/dist/NumberField.d.ts +8 -12
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/Popover.d.ts +28 -5
- package/dist/Popover.d.ts.map +1 -1
- package/dist/Pressable.d.ts +2 -2
- package/dist/Pressable.d.ts.map +1 -1
- package/dist/ProgressBar.d.ts +5 -3
- package/dist/ProgressBar.d.ts.map +1 -1
- package/dist/RadioGroup.d.ts +43 -9
- package/dist/RadioGroup.d.ts.map +1 -1
- package/dist/RangeCalendar.d.ts +34 -7
- package/dist/RangeCalendar.d.ts.map +1 -1
- package/dist/RouterProvider.d.ts +2 -2
- package/dist/RouterProvider.d.ts.map +1 -1
- package/dist/SearchField.d.ts +23 -20
- package/dist/SearchField.d.ts.map +1 -1
- package/dist/Select.d.ts +41 -11
- package/dist/Select.d.ts.map +1 -1
- package/dist/SelectionIndicator.d.ts +3 -3
- package/dist/SelectionIndicator.d.ts.map +1 -1
- package/dist/Separator.d.ts +9 -3
- package/dist/Separator.d.ts.map +1 -1
- package/dist/SharedElementTransition.d.ts +6 -4
- package/dist/SharedElementTransition.d.ts.map +1 -1
- package/dist/Slider.d.ts +12 -8
- package/dist/Slider.d.ts.map +1 -1
- package/dist/StepList.d.ts +90 -0
- package/dist/StepList.d.ts.map +1 -0
- package/dist/Switch.d.ts +11 -5
- package/dist/Switch.d.ts.map +1 -1
- package/dist/Table.d.ts +187 -23
- package/dist/Table.d.ts.map +1 -1
- package/dist/Tabs.d.ts +45 -9
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/TagGroup.d.ts +12 -10
- package/dist/TagGroup.d.ts.map +1 -1
- package/dist/Text.d.ts +2 -2
- package/dist/TextField.d.ts +15 -11
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TimeField.d.ts +6 -6
- package/dist/TimeField.d.ts.map +1 -1
- package/dist/Toast.d.ts +29 -14
- package/dist/Toast.d.ts.map +1 -1
- package/dist/ToggleButton.d.ts +11 -5
- package/dist/ToggleButton.d.ts.map +1 -1
- package/dist/ToggleButtonGroup.d.ts +7 -7
- package/dist/ToggleButtonGroup.d.ts.map +1 -1
- package/dist/Toolbar.d.ts +7 -3
- package/dist/Toolbar.d.ts.map +1 -1
- package/dist/Tooltip.d.ts +50 -8
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tree.d.ts +66 -17
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Virtualizer.d.ts +12 -12
- package/dist/Virtualizer.d.ts.map +1 -1
- package/dist/VirtualizerLayouts.d.ts +2 -2
- package/dist/VirtualizerLayouts.d.ts.map +1 -1
- package/dist/VisuallyHidden.d.ts +1 -1
- package/dist/VisuallyHidden.d.ts.map +1 -1
- package/dist/contexts.d.ts +5 -1
- package/dist/contexts.d.ts.map +1 -1
- package/dist/index.d.ts +73 -71
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23253 -18564
- package/dist/index.js.map +1 -1
- package/dist/index.jsx +18116 -0
- package/dist/index.jsx.map +1 -0
- package/dist/useDragAndDrop.d.ts +13 -13
- package/dist/useDragAndDrop.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/virtualizer/Layout.d.ts +1 -1
- package/dist/virtualizer/Layout.d.ts.map +1 -1
- package/package.json +31 -32
- package/src/ActionBar.tsx +75 -72
- package/src/ActionGroup.tsx +53 -61
- package/src/Alert.tsx +17 -42
- package/src/Autocomplete.tsx +39 -44
- package/src/Breadcrumbs.tsx +149 -80
- package/src/Button.tsx +267 -70
- package/src/Calendar.tsx +218 -138
- package/src/Checkbox.tsx +413 -121
- package/src/Collection.tsx +67 -58
- package/src/Color.tsx +803 -380
- package/src/ColorEditor.tsx +131 -149
- package/src/ComboBox.tsx +414 -249
- package/src/ContextualHelpTrigger.tsx +86 -74
- package/src/DateField.tsx +185 -91
- package/src/DatePicker.tsx +524 -213
- package/src/DateRangePickerContext.tsx +44 -0
- package/src/Dialog.tsx +156 -118
- package/src/Disclosure.tsx +127 -80
- package/src/DragAndDrop.tsx +60 -54
- package/src/DragPreview.tsx +13 -11
- package/src/DropZone.tsx +42 -22
- package/src/FieldError.tsx +45 -23
- package/src/FileTrigger.tsx +19 -19
- package/src/Focusable.tsx +21 -24
- package/src/Form.tsx +71 -16
- package/src/GridList.tsx +273 -197
- package/src/HiddenDateInput.tsx +153 -0
- package/src/HiddenTimeInput.tsx +133 -0
- package/src/Icon.tsx +22 -43
- package/src/Keyboard.tsx +3 -3
- package/src/Landmark.tsx +37 -63
- package/src/Link.tsx +125 -75
- package/src/ListBox.tsx +332 -233
- package/src/ListDropTargetDelegate.ts +81 -80
- package/src/Menu.tsx +1023 -274
- package/src/Meter.tsx +38 -56
- package/src/Modal.tsx +251 -176
- package/src/NumberField.tsx +139 -143
- package/src/Popover.tsx +396 -234
- package/src/Pressable.tsx +21 -21
- package/src/ProgressBar.tsx +48 -57
- package/src/RadioGroup.tsx +524 -122
- package/src/RangeCalendar.tsx +157 -90
- package/src/RouterProvider.tsx +30 -47
- package/src/SearchField.tsx +362 -143
- package/src/Select.tsx +656 -233
- package/src/SelectionIndicator.tsx +18 -15
- package/src/Separator.tsx +47 -49
- package/src/SharedElementTransition.tsx +103 -97
- package/src/Slider.tsx +138 -98
- package/src/StepList.tsx +272 -0
- package/src/Switch.tsx +93 -46
- package/src/Table.tsx +1308 -342
- package/src/Tabs.tsx +324 -103
- package/src/TagGroup.tsx +139 -126
- package/src/Text.tsx +3 -3
- package/src/TextField.tsx +389 -79
- package/src/TimeField.tsx +136 -76
- package/src/Toast.tsx +216 -158
- package/src/ToggleButton.tsx +47 -37
- package/src/ToggleButtonGroup.tsx +39 -34
- package/src/Toolbar.tsx +54 -69
- package/src/Tooltip.tsx +387 -119
- package/src/Tree.tsx +651 -368
- package/src/Virtualizer.tsx +208 -180
- package/src/VirtualizerLayouts.ts +45 -30
- package/src/VisuallyHidden.tsx +19 -19
- package/src/contexts.ts +29 -37
- package/src/index.ts +110 -195
- package/src/useDragAndDrop.ts +87 -71
- package/src/utils.tsx +49 -60
- package/src/virtualizer/Layout.ts +14 -22
- package/dist/index.ssr.js +0 -16996
- package/dist/index.ssr.js.map +0 -1
package/src/ActionGroup.tsx
CHANGED
|
@@ -18,33 +18,29 @@ import {
|
|
|
18
18
|
splitProps,
|
|
19
19
|
useContext,
|
|
20
20
|
For,
|
|
21
|
-
} from
|
|
21
|
+
} from "solid-js";
|
|
22
22
|
import {
|
|
23
23
|
createActionGroup,
|
|
24
24
|
createActionGroupItem,
|
|
25
25
|
type AriaActionGroupProps,
|
|
26
|
-
} from
|
|
26
|
+
} from "@proyecto-viviana/solidaria";
|
|
27
27
|
import {
|
|
28
28
|
createListState,
|
|
29
29
|
type ListState,
|
|
30
30
|
type Key,
|
|
31
31
|
type SelectionMode,
|
|
32
|
-
} from
|
|
32
|
+
} from "@proyecto-viviana/solid-stately";
|
|
33
33
|
import {
|
|
34
34
|
type ClassNameOrFunction,
|
|
35
35
|
type StyleOrFunction,
|
|
36
36
|
type SlotProps,
|
|
37
37
|
useRenderProps,
|
|
38
38
|
filterDOMProps,
|
|
39
|
-
} from
|
|
40
|
-
|
|
41
|
-
// ============================================
|
|
42
|
-
// TYPES
|
|
43
|
-
// ============================================
|
|
39
|
+
} from "./utils";
|
|
44
40
|
|
|
45
41
|
export interface ActionGroupRenderProps {
|
|
46
42
|
/** The orientation of the action group. */
|
|
47
|
-
orientation:
|
|
43
|
+
orientation: "horizontal" | "vertical";
|
|
48
44
|
/** Whether the entire group is disabled. */
|
|
49
45
|
isDisabled: boolean;
|
|
50
46
|
/** The selection mode. */
|
|
@@ -67,26 +63,25 @@ export interface ActionGroupItem {
|
|
|
67
63
|
[key: string]: unknown;
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
export interface ActionGroupProps<T extends ActionGroupItem = ActionGroupItem>
|
|
71
|
-
extends SlotProps {
|
|
66
|
+
export interface ActionGroupProps<T extends ActionGroupItem = ActionGroupItem> extends SlotProps {
|
|
72
67
|
/** The items in the action group. */
|
|
73
68
|
items: T[];
|
|
74
69
|
/** The selection mode. @default 'none' */
|
|
75
70
|
selectionMode?: SelectionMode;
|
|
76
71
|
/** Orientation of the group. @default 'horizontal' */
|
|
77
|
-
orientation?:
|
|
72
|
+
orientation?: "horizontal" | "vertical";
|
|
78
73
|
/** Whether the entire group is disabled. */
|
|
79
74
|
isDisabled?: boolean;
|
|
80
75
|
/** Accessible label. */
|
|
81
|
-
|
|
76
|
+
"aria-label"?: string;
|
|
82
77
|
/** Labelled-by id. */
|
|
83
|
-
|
|
78
|
+
"aria-labelledby"?: string;
|
|
84
79
|
/** Currently selected keys (controlled). */
|
|
85
80
|
selectedKeys?: Iterable<Key>;
|
|
86
81
|
/** Default selected keys (uncontrolled). */
|
|
87
82
|
defaultSelectedKeys?: Iterable<Key>;
|
|
88
83
|
/** Handler called when selection changes. */
|
|
89
|
-
onSelectionChange?: (keys:
|
|
84
|
+
onSelectionChange?: (keys: "all" | Set<Key>) => void;
|
|
90
85
|
/** Handler called when an item action is triggered. */
|
|
91
86
|
onAction?: (key: Key) => void;
|
|
92
87
|
/** Keys of disabled items. */
|
|
@@ -99,10 +94,6 @@ export interface ActionGroupProps<T extends ActionGroupItem = ActionGroupItem>
|
|
|
99
94
|
style?: StyleOrFunction<ActionGroupRenderProps>;
|
|
100
95
|
}
|
|
101
96
|
|
|
102
|
-
// ============================================
|
|
103
|
-
// CONTEXT
|
|
104
|
-
// ============================================
|
|
105
|
-
|
|
106
97
|
export interface ActionGroupContextValue<T extends ActionGroupItem = ActionGroupItem> {
|
|
107
98
|
state: ListState<T>;
|
|
108
99
|
}
|
|
@@ -110,31 +101,27 @@ export interface ActionGroupContextValue<T extends ActionGroupItem = ActionGroup
|
|
|
110
101
|
export const ActionGroupContext = createContext<ActionGroupContextValue | null>(null);
|
|
111
102
|
export const ActionGroupStateContext = createContext<ListState<ActionGroupItem> | null>(null);
|
|
112
103
|
|
|
113
|
-
// ============================================
|
|
114
|
-
// ACTIONGROUP COMPONENT
|
|
115
|
-
// ============================================
|
|
116
|
-
|
|
117
104
|
export function ActionGroup<T extends ActionGroupItem = ActionGroupItem>(
|
|
118
|
-
props: ActionGroupProps<T
|
|
105
|
+
props: ActionGroupProps<T>,
|
|
119
106
|
): JSX.Element {
|
|
120
107
|
const [local, ariaGroupProps, domProps] = splitProps(
|
|
121
108
|
props,
|
|
122
109
|
[
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
110
|
+
"items",
|
|
111
|
+
"selectionMode",
|
|
112
|
+
"orientation",
|
|
113
|
+
"isDisabled",
|
|
114
|
+
"selectedKeys",
|
|
115
|
+
"defaultSelectedKeys",
|
|
116
|
+
"onSelectionChange",
|
|
117
|
+
"onAction",
|
|
118
|
+
"disabledKeys",
|
|
119
|
+
"children",
|
|
120
|
+
"class",
|
|
121
|
+
"style",
|
|
122
|
+
"slot",
|
|
136
123
|
],
|
|
137
|
-
[
|
|
124
|
+
["aria-label", "aria-labelledby"],
|
|
138
125
|
);
|
|
139
126
|
|
|
140
127
|
const state = createListState<T>({
|
|
@@ -142,7 +129,7 @@ export function ActionGroup<T extends ActionGroupItem = ActionGroupItem>(
|
|
|
142
129
|
return local.items;
|
|
143
130
|
},
|
|
144
131
|
get selectionMode() {
|
|
145
|
-
return local.selectionMode ??
|
|
132
|
+
return local.selectionMode ?? "none";
|
|
146
133
|
},
|
|
147
134
|
get selectedKeys() {
|
|
148
135
|
return local.selectedKeys;
|
|
@@ -171,11 +158,11 @@ export function ActionGroup<T extends ActionGroupItem = ActionGroupItem>(
|
|
|
171
158
|
get orientation() {
|
|
172
159
|
return local.orientation;
|
|
173
160
|
},
|
|
174
|
-
get
|
|
175
|
-
return ariaGroupProps[
|
|
161
|
+
get "aria-label"() {
|
|
162
|
+
return ariaGroupProps["aria-label"];
|
|
176
163
|
},
|
|
177
|
-
get
|
|
178
|
-
return ariaGroupProps[
|
|
164
|
+
get "aria-labelledby"() {
|
|
165
|
+
return ariaGroupProps["aria-labelledby"];
|
|
179
166
|
},
|
|
180
167
|
get onAction() {
|
|
181
168
|
return local.onAction;
|
|
@@ -184,23 +171,25 @@ export function ActionGroup<T extends ActionGroupItem = ActionGroupItem>(
|
|
|
184
171
|
|
|
185
172
|
const { actionGroupProps } = createActionGroup(groupAriaProps, state as ListState<T>);
|
|
186
173
|
|
|
187
|
-
const orientation = () => local.orientation ??
|
|
174
|
+
const orientation = () => local.orientation ?? "horizontal";
|
|
188
175
|
|
|
189
176
|
const renderProps = useRenderProps(
|
|
190
177
|
{
|
|
191
178
|
children: undefined,
|
|
192
179
|
class: local.class,
|
|
193
180
|
style: local.style,
|
|
194
|
-
defaultClassName:
|
|
181
|
+
defaultClassName: "solidaria-ActionGroup",
|
|
195
182
|
},
|
|
196
183
|
() => ({
|
|
197
184
|
orientation: orientation(),
|
|
198
185
|
isDisabled: !!local.isDisabled,
|
|
199
|
-
selectionMode: (local.selectionMode ??
|
|
200
|
-
})
|
|
186
|
+
selectionMode: (local.selectionMode ?? "none") as SelectionMode,
|
|
187
|
+
}),
|
|
201
188
|
);
|
|
202
189
|
|
|
203
|
-
const filteredDOMProps = createMemo(() =>
|
|
190
|
+
const filteredDOMProps = createMemo(() =>
|
|
191
|
+
filterDOMProps(domProps as Record<string, unknown>, { global: true }),
|
|
192
|
+
);
|
|
204
193
|
|
|
205
194
|
return (
|
|
206
195
|
<ActionGroupContext.Provider value={{ state: state as ListState<ActionGroupItem> }}>
|
|
@@ -223,7 +212,12 @@ export function ActionGroup<T extends ActionGroupItem = ActionGroupItem>(
|
|
|
223
212
|
<ActionGroupItemWrapper
|
|
224
213
|
item={item}
|
|
225
214
|
state={state as ListState<ActionGroupItem>}
|
|
226
|
-
renderChild={
|
|
215
|
+
renderChild={
|
|
216
|
+
local.children as (
|
|
217
|
+
item: ActionGroupItem,
|
|
218
|
+
rp: ActionGroupItemRenderProps,
|
|
219
|
+
) => JSX.Element
|
|
220
|
+
}
|
|
227
221
|
/>
|
|
228
222
|
)}
|
|
229
223
|
</For>
|
|
@@ -233,10 +227,6 @@ export function ActionGroup<T extends ActionGroupItem = ActionGroupItem>(
|
|
|
233
227
|
);
|
|
234
228
|
}
|
|
235
229
|
|
|
236
|
-
// ============================================
|
|
237
|
-
// INTERNAL ITEM WRAPPER
|
|
238
|
-
// ============================================
|
|
239
|
-
|
|
240
230
|
interface ActionGroupItemWrapperProps {
|
|
241
231
|
item: ActionGroupItem;
|
|
242
232
|
state: ListState<ActionGroupItem>;
|
|
@@ -245,14 +235,18 @@ interface ActionGroupItemWrapperProps {
|
|
|
245
235
|
|
|
246
236
|
function ActionGroupItemWrapper(props: ActionGroupItemWrapperProps): JSX.Element {
|
|
247
237
|
const { buttonProps } = createActionGroupItem(
|
|
248
|
-
{
|
|
249
|
-
|
|
238
|
+
{
|
|
239
|
+
get key() {
|
|
240
|
+
return props.item.id;
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
props.state,
|
|
250
244
|
);
|
|
251
245
|
|
|
252
246
|
const isFocused = () => props.state.focusedKey() === props.item.id;
|
|
253
247
|
const isSelected = () => {
|
|
254
248
|
const keys = props.state.selectedKeys();
|
|
255
|
-
return keys ===
|
|
249
|
+
return keys === "all" || (keys instanceof Set && keys.has(props.item.id));
|
|
256
250
|
};
|
|
257
251
|
const isDisabled = () => props.state.isDisabled(props.item.id);
|
|
258
252
|
|
|
@@ -262,7 +256,9 @@ function ActionGroupItemWrapper(props: ActionGroupItemWrapperProps): JSX.Element
|
|
|
262
256
|
isFocused: isFocused(),
|
|
263
257
|
}));
|
|
264
258
|
|
|
265
|
-
const { ref: _ref, ...restButtonProps } = buttonProps as Record<string, unknown> & {
|
|
259
|
+
const { ref: _ref, ...restButtonProps } = buttonProps as Record<string, unknown> & {
|
|
260
|
+
ref?: unknown;
|
|
261
|
+
};
|
|
266
262
|
|
|
267
263
|
return (
|
|
268
264
|
<button
|
|
@@ -276,10 +272,6 @@ function ActionGroupItemWrapper(props: ActionGroupItemWrapperProps): JSX.Element
|
|
|
276
272
|
);
|
|
277
273
|
}
|
|
278
274
|
|
|
279
|
-
// ============================================
|
|
280
|
-
// HOOKS
|
|
281
|
-
// ============================================
|
|
282
|
-
|
|
283
275
|
export function useActionGroupContext(): ActionGroupContextValue | null {
|
|
284
276
|
return useContext(ActionGroupContext);
|
|
285
277
|
}
|
package/src/Alert.tsx
CHANGED
|
@@ -6,27 +6,17 @@
|
|
|
6
6
|
* for styling/composition only.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
type JSX,
|
|
11
|
-
createContext,
|
|
12
|
-
createMemo,
|
|
13
|
-
splitProps,
|
|
14
|
-
useContext,
|
|
15
|
-
} from 'solid-js';
|
|
9
|
+
import { type JSX, createContext, createMemo, splitProps, useContext } from "solid-js";
|
|
16
10
|
import {
|
|
17
11
|
type RenderChildren,
|
|
18
12
|
type ClassNameOrFunction,
|
|
19
13
|
type StyleOrFunction,
|
|
20
14
|
type SlotProps,
|
|
21
15
|
filterDOMProps,
|
|
22
|
-
} from
|
|
23
|
-
import { Button, type ButtonProps } from
|
|
24
|
-
|
|
25
|
-
// ============================================
|
|
26
|
-
// TYPES
|
|
27
|
-
// ============================================
|
|
16
|
+
} from "./utils";
|
|
17
|
+
import { Button, type ButtonProps } from "./Button";
|
|
28
18
|
|
|
29
|
-
export type AlertVariant =
|
|
19
|
+
export type AlertVariant = "info" | "success" | "warning" | "error";
|
|
30
20
|
|
|
31
21
|
export interface AlertRenderProps {
|
|
32
22
|
/** The variant of the alert. */
|
|
@@ -52,10 +42,6 @@ export interface AlertProps extends SlotProps {
|
|
|
52
42
|
id?: string;
|
|
53
43
|
}
|
|
54
44
|
|
|
55
|
-
// ============================================
|
|
56
|
-
// CONTEXT
|
|
57
|
-
// ============================================
|
|
58
|
-
|
|
59
45
|
export interface AlertContextValue {
|
|
60
46
|
variant: () => AlertVariant;
|
|
61
47
|
isDismissible: () => boolean;
|
|
@@ -64,10 +50,6 @@ export interface AlertContextValue {
|
|
|
64
50
|
|
|
65
51
|
export const AlertContext = createContext<AlertContextValue | null>(null);
|
|
66
52
|
|
|
67
|
-
// ============================================
|
|
68
|
-
// ALERT COMPONENT
|
|
69
|
-
// ============================================
|
|
70
|
-
|
|
71
53
|
/**
|
|
72
54
|
* An alert displays a brief, important message in a way that
|
|
73
55
|
* attracts the user's attention without interrupting their task.
|
|
@@ -84,19 +66,18 @@ export const AlertContext = createContext<AlertContextValue | null>(null);
|
|
|
84
66
|
*/
|
|
85
67
|
export function Alert(props: AlertProps): JSX.Element {
|
|
86
68
|
const [local, rest] = splitProps(props, [
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
69
|
+
"children",
|
|
70
|
+
"class",
|
|
71
|
+
"style",
|
|
72
|
+
"slot",
|
|
73
|
+
"variant",
|
|
74
|
+
"isDismissible",
|
|
75
|
+
"onDismiss",
|
|
94
76
|
]);
|
|
95
77
|
|
|
96
|
-
const variant = () => local.variant ??
|
|
78
|
+
const variant = () => local.variant ?? "info";
|
|
97
79
|
const isDismissible = () => !!local.isDismissible;
|
|
98
80
|
|
|
99
|
-
// Render props values
|
|
100
81
|
const renderValues = createMemo<AlertRenderProps>(() => ({
|
|
101
82
|
variant: variant(),
|
|
102
83
|
isDismissible: isDismissible(),
|
|
@@ -108,18 +89,16 @@ export function Alert(props: AlertProps): JSX.Element {
|
|
|
108
89
|
// is in scope, breaking context for sub-components.
|
|
109
90
|
const computedClass = createMemo(() => {
|
|
110
91
|
const cls = local.class;
|
|
111
|
-
return typeof cls ===
|
|
92
|
+
return typeof cls === "function" ? cls(renderValues()) : (cls ?? "solidaria-Alert");
|
|
112
93
|
});
|
|
113
94
|
|
|
114
95
|
const computedStyle = createMemo(() => {
|
|
115
96
|
const s = local.style;
|
|
116
|
-
return typeof s ===
|
|
97
|
+
return typeof s === "function" ? s(renderValues()) : s;
|
|
117
98
|
});
|
|
118
99
|
|
|
119
|
-
// Filter DOM props
|
|
120
100
|
const domProps = createMemo(() => filterDOMProps(rest, { global: true }));
|
|
121
101
|
|
|
122
|
-
// Context value for sub-components
|
|
123
102
|
const contextValue: AlertContextValue = {
|
|
124
103
|
variant,
|
|
125
104
|
isDismissible,
|
|
@@ -138,7 +117,7 @@ export function Alert(props: AlertProps): JSX.Element {
|
|
|
138
117
|
data-variant={variant()}
|
|
139
118
|
data-dismissible={isDismissible() || undefined}
|
|
140
119
|
>
|
|
141
|
-
{typeof local.children ===
|
|
120
|
+
{typeof local.children === "function"
|
|
142
121
|
? (local.children as (props: AlertRenderProps) => JSX.Element)(renderValues())
|
|
143
122
|
: local.children}
|
|
144
123
|
</div>
|
|
@@ -146,11 +125,7 @@ export function Alert(props: AlertProps): JSX.Element {
|
|
|
146
125
|
);
|
|
147
126
|
}
|
|
148
127
|
|
|
149
|
-
|
|
150
|
-
// ALERT DISMISS BUTTON
|
|
151
|
-
// ============================================
|
|
152
|
-
|
|
153
|
-
export interface AlertDismissButtonProps extends Omit<ButtonProps, 'onPress'> {}
|
|
128
|
+
export interface AlertDismissButtonProps extends Omit<ButtonProps, "onPress"> {}
|
|
154
129
|
|
|
155
130
|
/**
|
|
156
131
|
* A dismiss button for use inside an Alert.
|
|
@@ -170,7 +145,7 @@ export function AlertDismissButton(props: AlertDismissButtonProps): JSX.Element
|
|
|
170
145
|
return (
|
|
171
146
|
<Button
|
|
172
147
|
{...props}
|
|
173
|
-
aria-label={props[
|
|
148
|
+
aria-label={props["aria-label"] ?? "Dismiss"}
|
|
174
149
|
onPress={() => context?.onDismiss?.()}
|
|
175
150
|
/>
|
|
176
151
|
);
|
package/src/Autocomplete.tsx
CHANGED
|
@@ -15,62 +15,56 @@ import {
|
|
|
15
15
|
createMemo,
|
|
16
16
|
splitProps,
|
|
17
17
|
createSignal,
|
|
18
|
-
} from
|
|
18
|
+
} from "solid-js";
|
|
19
19
|
import {
|
|
20
20
|
createAutocomplete,
|
|
21
21
|
type AriaAutocompleteOptions,
|
|
22
22
|
type AutocompleteInputProps,
|
|
23
23
|
type CollectionOptions,
|
|
24
|
-
} from
|
|
24
|
+
} from "@proyecto-viviana/solidaria";
|
|
25
25
|
import {
|
|
26
26
|
createAutocompleteState,
|
|
27
27
|
type AutocompleteState,
|
|
28
28
|
type AutocompleteStateOptions,
|
|
29
|
-
} from
|
|
30
|
-
import { type SlotProps } from
|
|
31
|
-
|
|
32
|
-
// ============================================
|
|
33
|
-
// TYPES
|
|
34
|
-
// ============================================
|
|
29
|
+
} from "@proyecto-viviana/solid-stately";
|
|
30
|
+
import { type SlotProps } from "./utils";
|
|
35
31
|
|
|
36
32
|
export interface AutocompleteProps<T = unknown>
|
|
37
|
-
extends
|
|
38
|
-
Omit<
|
|
33
|
+
extends
|
|
34
|
+
Omit<AutocompleteStateOptions, "children">,
|
|
35
|
+
Omit<AriaAutocompleteOptions<T>, "inputRef" | "collectionRef">,
|
|
39
36
|
ParentProps,
|
|
40
37
|
SlotProps {}
|
|
41
38
|
|
|
42
|
-
// ============================================
|
|
43
|
-
// CONTEXTS
|
|
44
|
-
// ============================================
|
|
45
|
-
|
|
46
39
|
export interface AutocompleteContextValue {
|
|
47
|
-
inputProps: AutocompleteInputProps
|
|
48
|
-
inputRef: (el: HTMLInputElement) => void
|
|
40
|
+
inputProps: AutocompleteInputProps;
|
|
41
|
+
inputRef: (el: HTMLInputElement) => void;
|
|
49
42
|
}
|
|
50
43
|
|
|
51
44
|
export interface AutocompleteCollectionContextValue {
|
|
52
|
-
collectionProps: CollectionOptions
|
|
53
|
-
collectionRef: (el: HTMLElement) => void
|
|
54
|
-
filter?: (textValue: string) => boolean
|
|
45
|
+
collectionProps: CollectionOptions;
|
|
46
|
+
collectionRef: (el: HTMLElement) => void;
|
|
47
|
+
filter?: (textValue: string) => boolean;
|
|
55
48
|
}
|
|
56
49
|
|
|
57
|
-
export const AutocompleteContext = createContext<AutocompleteContextValue | null>(null)
|
|
58
|
-
export const AutocompleteStateContext = createContext<AutocompleteState | null>(null)
|
|
59
|
-
export const AutocompleteCollectionContext =
|
|
50
|
+
export const AutocompleteContext = createContext<AutocompleteContextValue | null>(null);
|
|
51
|
+
export const AutocompleteStateContext = createContext<AutocompleteState | null>(null);
|
|
52
|
+
export const AutocompleteCollectionContext =
|
|
53
|
+
createContext<AutocompleteCollectionContextValue | null>(null);
|
|
60
54
|
|
|
61
55
|
/**
|
|
62
56
|
* Hook to consume autocomplete input context.
|
|
63
57
|
* Use this in your input component (TextField/SearchField) to get the autocomplete props.
|
|
64
58
|
*/
|
|
65
59
|
export function useAutocompleteInput() {
|
|
66
|
-
return useContext(AutocompleteContext)
|
|
60
|
+
return useContext(AutocompleteContext);
|
|
67
61
|
}
|
|
68
62
|
|
|
69
63
|
/**
|
|
70
64
|
* Hook to consume autocomplete state context.
|
|
71
65
|
*/
|
|
72
66
|
export function useAutocompleteState() {
|
|
73
|
-
return useContext(AutocompleteStateContext)
|
|
67
|
+
return useContext(AutocompleteStateContext);
|
|
74
68
|
}
|
|
75
69
|
|
|
76
70
|
/**
|
|
@@ -78,13 +72,9 @@ export function useAutocompleteState() {
|
|
|
78
72
|
* Use this in your collection component (ListBox/Menu) to get the autocomplete props.
|
|
79
73
|
*/
|
|
80
74
|
export function useAutocompleteCollection() {
|
|
81
|
-
return useContext(AutocompleteCollectionContext)
|
|
75
|
+
return useContext(AutocompleteCollectionContext);
|
|
82
76
|
}
|
|
83
77
|
|
|
84
|
-
// ============================================
|
|
85
|
-
// AUTOCOMPLETE COMPONENT
|
|
86
|
-
// ============================================
|
|
87
|
-
|
|
88
78
|
/**
|
|
89
79
|
* An autocomplete allows users to search or filter a list of suggestions.
|
|
90
80
|
* It wraps a text input and a collection component (ListBox or Menu),
|
|
@@ -124,16 +114,21 @@ export function useAutocompleteCollection() {
|
|
|
124
114
|
export function Autocomplete<T = unknown>(props: AutocompleteProps<T>): JSX.Element {
|
|
125
115
|
const [stateProps, ariaProps, local] = splitProps(
|
|
126
116
|
props,
|
|
127
|
-
[
|
|
128
|
-
[
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
["inputValue", "defaultInputValue", "onInputChange"],
|
|
118
|
+
[
|
|
119
|
+
"filter",
|
|
120
|
+
"disableAutoFocusFirst",
|
|
121
|
+
"disableVirtualFocus",
|
|
122
|
+
"collectionId",
|
|
123
|
+
"collectionAriaLabel",
|
|
124
|
+
],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const state = createAutocompleteState(stateProps);
|
|
133
128
|
|
|
134
129
|
// Create refs
|
|
135
|
-
let inputRef: HTMLInputElement | undefined
|
|
136
|
-
let collectionRef: HTMLElement | undefined
|
|
130
|
+
let inputRef: HTMLInputElement | undefined;
|
|
131
|
+
let collectionRef: HTMLElement | undefined;
|
|
137
132
|
|
|
138
133
|
// Create autocomplete aria
|
|
139
134
|
const autocomplete = createAutocomplete<T>(
|
|
@@ -142,25 +137,25 @@ export function Autocomplete<T = unknown>(props: AutocompleteProps<T>): JSX.Elem
|
|
|
142
137
|
inputRef: () => inputRef,
|
|
143
138
|
collectionRef: () => collectionRef,
|
|
144
139
|
},
|
|
145
|
-
state
|
|
146
|
-
)
|
|
140
|
+
state,
|
|
141
|
+
);
|
|
147
142
|
|
|
148
143
|
// Input context value
|
|
149
144
|
const inputContextValue = createMemo<AutocompleteContextValue>(() => ({
|
|
150
145
|
inputProps: autocomplete.inputProps,
|
|
151
146
|
inputRef: (el: HTMLInputElement) => {
|
|
152
|
-
inputRef = el
|
|
147
|
+
inputRef = el;
|
|
153
148
|
},
|
|
154
|
-
}))
|
|
149
|
+
}));
|
|
155
150
|
|
|
156
151
|
// Collection context value
|
|
157
152
|
const collectionContextValue = createMemo<AutocompleteCollectionContextValue>(() => ({
|
|
158
153
|
collectionProps: autocomplete.collectionProps,
|
|
159
154
|
collectionRef: (el: HTMLElement) => {
|
|
160
|
-
collectionRef = el
|
|
155
|
+
collectionRef = el;
|
|
161
156
|
},
|
|
162
157
|
filter: autocomplete.filter,
|
|
163
|
-
}))
|
|
158
|
+
}));
|
|
164
159
|
|
|
165
160
|
return (
|
|
166
161
|
<AutocompleteStateContext.Provider value={state}>
|
|
@@ -170,5 +165,5 @@ export function Autocomplete<T = unknown>(props: AutocompleteProps<T>): JSX.Elem
|
|
|
170
165
|
</AutocompleteCollectionContext.Provider>
|
|
171
166
|
</AutocompleteContext.Provider>
|
|
172
167
|
</AutocompleteStateContext.Provider>
|
|
173
|
-
)
|
|
168
|
+
);
|
|
174
169
|
}
|