@proyecto-viviana/solidaria-components 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -272
- package/dist/ActionBar.d.ts +79 -0
- package/dist/ActionBar.d.ts.map +1 -0
- package/dist/ActionGroup.d.ts +74 -0
- package/dist/ActionGroup.d.ts.map +1 -0
- package/dist/Alert.d.ts +70 -0
- package/dist/Alert.d.ts.map +1 -0
- package/dist/Autocomplete.d.ts +5 -5
- package/dist/Autocomplete.d.ts.map +1 -1
- package/dist/Breadcrumbs.d.ts +27 -8
- package/dist/Breadcrumbs.d.ts.map +1 -1
- package/dist/Button.d.ts +28 -5
- package/dist/Button.d.ts.map +1 -1
- package/dist/Calendar.d.ts +51 -7
- package/dist/Calendar.d.ts.map +1 -1
- package/dist/Checkbox.d.ts +33 -8
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Collection.d.ts +130 -0
- package/dist/Collection.d.ts.map +1 -0
- package/dist/Color.d.ts +210 -9
- package/dist/Color.d.ts.map +1 -1
- package/dist/ColorEditor.d.ts +42 -0
- package/dist/ColorEditor.d.ts.map +1 -0
- package/dist/ComboBox.d.ts +146 -16
- package/dist/ComboBox.d.ts.map +1 -1
- package/dist/ContextualHelpTrigger.d.ts +40 -0
- package/dist/ContextualHelpTrigger.d.ts.map +1 -0
- package/dist/DateField.d.ts +35 -8
- package/dist/DateField.d.ts.map +1 -1
- package/dist/DatePicker.d.ts +101 -5
- 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 +25 -5
- package/dist/Disclosure.d.ts.map +1 -1
- package/dist/DragAndDrop.d.ts +80 -0
- package/dist/DragAndDrop.d.ts.map +1 -0
- package/dist/DragPreview.d.ts +14 -0
- package/dist/DragPreview.d.ts.map +1 -0
- package/dist/DropZone.d.ts +27 -0
- package/dist/DropZone.d.ts.map +1 -0
- package/dist/FieldError.d.ts +27 -0
- package/dist/FieldError.d.ts.map +1 -0
- package/dist/FileTrigger.d.ts +26 -0
- package/dist/FileTrigger.d.ts.map +1 -0
- package/dist/Focusable.d.ts +27 -0
- package/dist/Focusable.d.ts.map +1 -0
- package/dist/Form.d.ts +41 -0
- package/dist/Form.d.ts.map +1 -0
- package/dist/GridList.d.ts +69 -10
- 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 +57 -0
- package/dist/Icon.d.ts.map +1 -0
- package/dist/Keyboard.d.ts +13 -0
- package/dist/Keyboard.d.ts.map +1 -0
- 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 +73 -11
- package/dist/ListBox.d.ts.map +1 -1
- package/dist/ListDropTargetDelegate.d.ts +38 -0
- package/dist/ListDropTargetDelegate.d.ts.map +1 -0
- package/dist/Menu.d.ts +79 -10
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Meter.d.ts +4 -4
- package/dist/Meter.d.ts.map +1 -1
- package/dist/Modal.d.ts +6 -4
- package/dist/Modal.d.ts.map +1 -1
- package/dist/NumberField.d.ts +10 -12
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/Popover.d.ts +32 -7
- package/dist/Popover.d.ts.map +1 -1
- package/dist/Pressable.d.ts +27 -0
- package/dist/Pressable.d.ts.map +1 -0
- package/dist/ProgressBar.d.ts +6 -4
- 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 +39 -7
- package/dist/RangeCalendar.d.ts.map +1 -1
- package/dist/RouterProvider.d.ts +75 -0
- package/dist/RouterProvider.d.ts.map +1 -0
- package/dist/SearchField.d.ts +23 -21
- package/dist/SearchField.d.ts.map +1 -1
- package/dist/Select.d.ts +48 -7
- package/dist/Select.d.ts.map +1 -1
- package/dist/SelectionIndicator.d.ts +30 -0
- package/dist/SelectionIndicator.d.ts.map +1 -0
- package/dist/Separator.d.ts +9 -3
- package/dist/Separator.d.ts.map +1 -1
- package/dist/SharedElementTransition.d.ts +41 -0
- package/dist/SharedElementTransition.d.ts.map +1 -0
- package/dist/Slider.d.ts +15 -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 +222 -19
- package/dist/Table.d.ts.map +1 -1
- package/dist/Tabs.d.ts +47 -10
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/TagGroup.d.ts +22 -10
- package/dist/TagGroup.d.ts.map +1 -1
- package/dist/Text.d.ts +10 -0
- package/dist/Text.d.ts.map +1 -0
- package/dist/TextField.d.ts +19 -11
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TimeField.d.ts +32 -7
- 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 +36 -0
- package/dist/ToggleButton.d.ts.map +1 -0
- package/dist/ToggleButtonGroup.d.ts +33 -0
- package/dist/ToggleButtonGroup.d.ts.map +1 -0
- package/dist/Toolbar.d.ts +7 -3
- package/dist/Toolbar.d.ts.map +1 -1
- package/dist/Tooltip.d.ts +58 -7
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tree.d.ts +102 -11
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Virtualizer.d.ts +61 -0
- package/dist/Virtualizer.d.ts.map +1 -0
- package/dist/VirtualizerLayouts.d.ts +82 -0
- package/dist/VirtualizerLayouts.d.ts.map +1 -0
- package/dist/VisuallyHidden.d.ts +4 -2
- package/dist/VisuallyHidden.d.ts.map +1 -1
- package/dist/contexts.d.ts +6 -1
- package/dist/contexts.d.ts.map +1 -1
- package/dist/index.d.ts +73 -39
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23342 -10644
- package/dist/index.js.map +1 -7
- package/dist/index.jsx +18110 -0
- package/dist/index.jsx.map +1 -0
- package/dist/useDragAndDrop.d.ts +93 -0
- package/dist/useDragAndDrop.d.ts.map +1 -0
- package/dist/utils.d.ts +8 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/virtualizer/Layout.d.ts +79 -0
- package/dist/virtualizer/Layout.d.ts.map +1 -0
- package/package.json +33 -32
- package/src/ActionBar.tsx +251 -0
- package/src/ActionGroup.tsx +277 -0
- package/src/Alert.tsx +152 -0
- package/src/Autocomplete.tsx +39 -44
- package/src/Breadcrumbs.tsx +227 -72
- package/src/Button.tsx +315 -74
- package/src/Calendar.tsx +347 -141
- package/src/Checkbox.tsx +414 -123
- package/src/Collection.tsx +350 -0
- package/src/Color.tsx +1325 -284
- package/src/ColorEditor.tsx +213 -0
- package/src/ComboBox.tsx +644 -245
- package/src/ContextualHelpTrigger.tsx +195 -0
- package/src/DateField.tsx +274 -106
- package/src/DatePicker.tsx +892 -111
- package/src/DateRangePickerContext.tsx +44 -0
- package/src/Dialog.tsx +173 -104
- package/src/Disclosure.tsx +158 -105
- package/src/DragAndDrop.tsx +340 -0
- package/src/DragPreview.tsx +47 -0
- package/src/DropZone.tsx +233 -0
- package/src/FieldError.tsx +89 -0
- package/src/FileTrigger.tsx +83 -0
- package/src/Focusable.tsx +103 -0
- package/src/Form.tsx +140 -0
- package/src/GridList.tsx +542 -128
- package/src/HiddenDateInput.tsx +153 -0
- package/src/HiddenTimeInput.tsx +133 -0
- package/src/Icon.tsx +133 -0
- package/src/Keyboard.tsx +26 -0
- package/src/Landmark.tsx +37 -63
- package/src/Link.tsx +132 -69
- package/src/ListBox.tsx +656 -106
- package/src/ListDropTargetDelegate.ts +283 -0
- package/src/Menu.tsx +1234 -132
- package/src/Meter.tsx +44 -58
- package/src/Modal.tsx +262 -166
- package/src/NumberField.tsx +267 -151
- package/src/Popover.tsx +452 -343
- package/src/Pressable.tsx +108 -0
- package/src/ProgressBar.tsx +54 -59
- package/src/RadioGroup.tsx +533 -121
- package/src/RangeCalendar.tsx +249 -150
- package/src/RouterProvider.tsx +223 -0
- package/src/SearchField.tsx +460 -133
- package/src/Select.tsx +804 -233
- package/src/SelectionIndicator.tsx +108 -0
- package/src/Separator.tsx +47 -49
- package/src/SharedElementTransition.tsx +264 -0
- package/src/Slider.tsx +148 -98
- package/src/StepList.tsx +272 -0
- package/src/Switch.tsx +93 -46
- package/src/Table.tsx +1551 -225
- package/src/Tabs.tsx +377 -123
- package/src/TagGroup.tsx +233 -135
- package/src/Text.tsx +18 -0
- package/src/TextField.tsx +413 -86
- package/src/TimeField.tsx +232 -222
- package/src/Toast.tsx +306 -160
- package/src/ToggleButton.tsx +169 -0
- package/src/ToggleButtonGroup.tsx +141 -0
- package/src/Toolbar.tsx +61 -70
- package/src/Tooltip.tsx +473 -116
- package/src/Tree.tsx +1514 -175
- package/src/Virtualizer.tsx +730 -0
- package/src/VirtualizerLayouts.ts +280 -0
- package/src/VisuallyHidden.tsx +32 -38
- package/src/contexts.ts +29 -36
- package/src/index.ts +972 -620
- package/src/useDragAndDrop.ts +367 -0
- package/src/utils.tsx +69 -50
- package/src/virtualizer/Layout.ts +192 -0
- package/dist/index.ssr.js +0 -9785
- package/dist/index.ssr.js.map +0 -7
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToggleButton component for solidaria-components
|
|
3
|
+
*
|
|
4
|
+
* A pre-wired headless toggle button that combines pressed + selected state.
|
|
5
|
+
* Port direction: react-aria-components/src/ToggleButton.tsx
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { type JSX, createContext, createMemo, splitProps, useContext } from "solid-js";
|
|
9
|
+
import {
|
|
10
|
+
createToggleButton,
|
|
11
|
+
createToggleButtonGroupItem,
|
|
12
|
+
createFocusRing,
|
|
13
|
+
createHover,
|
|
14
|
+
mergeProps,
|
|
15
|
+
type AriaToggleButtonProps,
|
|
16
|
+
} from "@proyecto-viviana/solidaria";
|
|
17
|
+
import type { Key } from "@proyecto-viviana/solid-stately";
|
|
18
|
+
import {
|
|
19
|
+
type RenderChildren,
|
|
20
|
+
type ClassNameOrFunction,
|
|
21
|
+
type StyleOrFunction,
|
|
22
|
+
type SlotProps,
|
|
23
|
+
useRenderProps,
|
|
24
|
+
filterDOMProps,
|
|
25
|
+
} from "./utils";
|
|
26
|
+
import { useToggleButtonGroupStateContext } from "./ToggleButtonGroup";
|
|
27
|
+
|
|
28
|
+
type RefLike<T> = ((el: T) => void) | { current?: T | null } | undefined;
|
|
29
|
+
|
|
30
|
+
function assignRef<T>(ref: RefLike<T>, el: T): void {
|
|
31
|
+
if (!ref) return;
|
|
32
|
+
if (typeof ref === "function") {
|
|
33
|
+
ref(el);
|
|
34
|
+
} else {
|
|
35
|
+
ref.current = el;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ToggleButtonRenderProps {
|
|
40
|
+
isHovered: boolean;
|
|
41
|
+
isPressed: boolean;
|
|
42
|
+
isFocused: boolean;
|
|
43
|
+
isFocusVisible: boolean;
|
|
44
|
+
isDisabled: boolean;
|
|
45
|
+
isSelected: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ToggleButtonProps extends Omit<AriaToggleButtonProps, "children">, SlotProps {
|
|
49
|
+
/** Key used when inside ToggleButtonGroup selection state. */
|
|
50
|
+
toggleKey?: Key;
|
|
51
|
+
/** Preferred group key prop, parity with RAC item id usage. */
|
|
52
|
+
id?: Key;
|
|
53
|
+
children?: RenderChildren<ToggleButtonRenderProps>;
|
|
54
|
+
class?: ClassNameOrFunction<ToggleButtonRenderProps>;
|
|
55
|
+
style?: StyleOrFunction<ToggleButtonRenderProps>;
|
|
56
|
+
/** Ref for the underlying button element. */
|
|
57
|
+
ref?: RefLike<HTMLButtonElement>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const ToggleButtonContext = createContext<ToggleButtonProps | null>(null);
|
|
61
|
+
|
|
62
|
+
function resolveDisabledValue(isDisabled: AriaToggleButtonProps["isDisabled"]): boolean {
|
|
63
|
+
if (typeof isDisabled === "function") {
|
|
64
|
+
return isDisabled();
|
|
65
|
+
}
|
|
66
|
+
return !!isDisabled;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function ToggleButton(props: ToggleButtonProps): JSX.Element {
|
|
70
|
+
const contextProps = useContext(ToggleButtonContext);
|
|
71
|
+
const mergedProps = (contextProps ? mergeProps(contextProps, props) : props) as ToggleButtonProps;
|
|
72
|
+
|
|
73
|
+
const [local, ariaProps] = splitProps(mergedProps, [
|
|
74
|
+
"children",
|
|
75
|
+
"class",
|
|
76
|
+
"style",
|
|
77
|
+
"ref",
|
|
78
|
+
"slot",
|
|
79
|
+
"toggleKey",
|
|
80
|
+
"id",
|
|
81
|
+
]);
|
|
82
|
+
const groupState = useToggleButtonGroupStateContext();
|
|
83
|
+
const groupKey = local.id ?? local.toggleKey;
|
|
84
|
+
const standaloneAriaProps = mergeProps<AriaToggleButtonProps>(ariaProps, {
|
|
85
|
+
get id() {
|
|
86
|
+
return local.id;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const toggleAria =
|
|
91
|
+
groupState && groupKey != null
|
|
92
|
+
? createToggleButtonGroupItem(
|
|
93
|
+
{
|
|
94
|
+
...ariaProps,
|
|
95
|
+
id: groupKey,
|
|
96
|
+
},
|
|
97
|
+
groupState,
|
|
98
|
+
)
|
|
99
|
+
: createToggleButton(standaloneAriaProps);
|
|
100
|
+
|
|
101
|
+
const isDisabled = () => resolveDisabledValue(ariaProps.isDisabled) || !!groupState?.isDisabled;
|
|
102
|
+
|
|
103
|
+
const { isFocused, isFocusVisible, focusProps } = createFocusRing();
|
|
104
|
+
const { isHovered, hoverProps } = createHover({
|
|
105
|
+
get isDisabled() {
|
|
106
|
+
return isDisabled();
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const renderValues = createMemo<ToggleButtonRenderProps>(() => ({
|
|
111
|
+
isHovered: isHovered(),
|
|
112
|
+
isPressed: toggleAria.isPressed(),
|
|
113
|
+
isFocused: isFocused(),
|
|
114
|
+
isFocusVisible: isFocusVisible(),
|
|
115
|
+
isDisabled: isDisabled(),
|
|
116
|
+
isSelected: toggleAria.isSelected(),
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
const renderProps = useRenderProps(
|
|
120
|
+
{
|
|
121
|
+
children: local.children,
|
|
122
|
+
class: local.class,
|
|
123
|
+
style: local.style,
|
|
124
|
+
defaultClassName: "solidaria-ToggleButton",
|
|
125
|
+
},
|
|
126
|
+
renderValues,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const domProps = createMemo(() => {
|
|
130
|
+
const filtered = filterDOMProps(ariaProps, { global: true });
|
|
131
|
+
delete (filtered as Record<string, unknown>).onClick;
|
|
132
|
+
delete (filtered as Record<string, unknown>).id;
|
|
133
|
+
return filtered;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const cleanButtonProps = () => {
|
|
137
|
+
const { ref: _ref1, ...rest } = toggleAria.buttonProps as Record<string, unknown>;
|
|
138
|
+
return rest;
|
|
139
|
+
};
|
|
140
|
+
const cleanFocusProps = () => {
|
|
141
|
+
const { ref: _ref2, ...rest } = focusProps as Record<string, unknown>;
|
|
142
|
+
return rest;
|
|
143
|
+
};
|
|
144
|
+
const cleanHoverProps = () => {
|
|
145
|
+
const { ref: _ref3, ...rest } = hoverProps as Record<string, unknown>;
|
|
146
|
+
return rest;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<button
|
|
151
|
+
{...domProps()}
|
|
152
|
+
{...cleanButtonProps()}
|
|
153
|
+
{...cleanFocusProps()}
|
|
154
|
+
{...cleanHoverProps()}
|
|
155
|
+
class={renderProps.class()}
|
|
156
|
+
style={renderProps.style()}
|
|
157
|
+
ref={(el) => assignRef(local.ref, el)}
|
|
158
|
+
slot={local.slot}
|
|
159
|
+
data-pressed={toggleAria.isPressed() || undefined}
|
|
160
|
+
data-hovered={isHovered() || undefined}
|
|
161
|
+
data-focused={isFocused() || undefined}
|
|
162
|
+
data-focus-visible={isFocusVisible() || undefined}
|
|
163
|
+
data-disabled={isDisabled() || undefined}
|
|
164
|
+
data-selected={toggleAria.isSelected() || undefined}
|
|
165
|
+
>
|
|
166
|
+
{renderProps.renderChildren()}
|
|
167
|
+
</button>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToggleButtonGroup component for solidaria-components.
|
|
3
|
+
*
|
|
4
|
+
* Groups toggle buttons with single/multiple selection state.
|
|
5
|
+
* Parity target: react-aria-components/src/ToggleButtonGroup.tsx
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { type JSX, createContext, createMemo, splitProps, useContext } from "solid-js";
|
|
9
|
+
import { createToggleButtonGroup, mergeProps } from "@proyecto-viviana/solidaria";
|
|
10
|
+
import {
|
|
11
|
+
createToggleGroupState,
|
|
12
|
+
type Key,
|
|
13
|
+
type ToggleGroupState,
|
|
14
|
+
} from "@proyecto-viviana/solid-stately";
|
|
15
|
+
import {
|
|
16
|
+
type ClassNameOrFunction,
|
|
17
|
+
type StyleOrFunction,
|
|
18
|
+
type RenderChildren,
|
|
19
|
+
type SlotProps,
|
|
20
|
+
useRenderProps,
|
|
21
|
+
filterDOMProps,
|
|
22
|
+
} from "./utils";
|
|
23
|
+
|
|
24
|
+
export interface ToggleButtonGroupRenderProps {
|
|
25
|
+
orientation: "horizontal" | "vertical";
|
|
26
|
+
isDisabled: boolean;
|
|
27
|
+
state: ToggleGroupState;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ToggleButtonGroupProps
|
|
31
|
+
extends
|
|
32
|
+
Omit<JSX.HTMLAttributes<HTMLDivElement>, "children" | "class" | "style" | "onSelectionChange">,
|
|
33
|
+
SlotProps {
|
|
34
|
+
selectionMode?: "single" | "multiple";
|
|
35
|
+
disallowEmptySelection?: boolean;
|
|
36
|
+
selectedKeys?: Iterable<Key>;
|
|
37
|
+
defaultSelectedKeys?: Iterable<Key>;
|
|
38
|
+
onSelectionChange?: (keys: Set<Key>) => void;
|
|
39
|
+
orientation?: "horizontal" | "vertical";
|
|
40
|
+
isDisabled?: boolean;
|
|
41
|
+
children?: RenderChildren<ToggleButtonGroupRenderProps>;
|
|
42
|
+
class?: ClassNameOrFunction<ToggleButtonGroupRenderProps>;
|
|
43
|
+
style?: StyleOrFunction<ToggleButtonGroupRenderProps>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const ToggleButtonGroupContext = createContext<ToggleButtonGroupProps | null>(null);
|
|
47
|
+
export const ToggleButtonGroupStateContext = createContext<ToggleGroupState | null>(null);
|
|
48
|
+
export const ToggleGroupStateContext = ToggleButtonGroupStateContext;
|
|
49
|
+
export type ToggleButtonGroupStateContextValue = ToggleGroupState;
|
|
50
|
+
|
|
51
|
+
export function ToggleButtonGroup(props: ToggleButtonGroupProps): JSX.Element {
|
|
52
|
+
const [local, domProps] = splitProps(props, [
|
|
53
|
+
"selectionMode",
|
|
54
|
+
"disallowEmptySelection",
|
|
55
|
+
"selectedKeys",
|
|
56
|
+
"defaultSelectedKeys",
|
|
57
|
+
"onSelectionChange",
|
|
58
|
+
"orientation",
|
|
59
|
+
"isDisabled",
|
|
60
|
+
"children",
|
|
61
|
+
"class",
|
|
62
|
+
"style",
|
|
63
|
+
"ref",
|
|
64
|
+
"slot",
|
|
65
|
+
"aria-label",
|
|
66
|
+
"aria-labelledby",
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
const state = createToggleGroupState(() => ({
|
|
70
|
+
selectionMode: local.selectionMode,
|
|
71
|
+
disallowEmptySelection: local.disallowEmptySelection,
|
|
72
|
+
selectedKeys: local.selectedKeys,
|
|
73
|
+
defaultSelectedKeys: local.defaultSelectedKeys,
|
|
74
|
+
onSelectionChange: local.onSelectionChange,
|
|
75
|
+
isDisabled: !!local.isDisabled,
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
const { groupProps } = createToggleButtonGroup(
|
|
79
|
+
{
|
|
80
|
+
get orientation() {
|
|
81
|
+
return local.orientation;
|
|
82
|
+
},
|
|
83
|
+
get isDisabled() {
|
|
84
|
+
return !!local.isDisabled;
|
|
85
|
+
},
|
|
86
|
+
get "aria-label"() {
|
|
87
|
+
return local["aria-label"];
|
|
88
|
+
},
|
|
89
|
+
get "aria-labelledby"() {
|
|
90
|
+
return local["aria-labelledby"];
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
state,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const renderProps = useRenderProps(
|
|
97
|
+
{
|
|
98
|
+
children: local.children,
|
|
99
|
+
class: local.class,
|
|
100
|
+
style: local.style,
|
|
101
|
+
defaultClassName: "solidaria-ToggleButtonGroup",
|
|
102
|
+
},
|
|
103
|
+
() => ({
|
|
104
|
+
orientation: local.orientation ?? "horizontal",
|
|
105
|
+
isDisabled: !!local.isDisabled,
|
|
106
|
+
state,
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const filteredDomProps = createMemo(() => filterDOMProps(domProps, { global: true }));
|
|
111
|
+
const mergedGroupProps = createMemo(() =>
|
|
112
|
+
mergeProps(filteredDomProps(), groupProps as Record<string, unknown>),
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<div
|
|
117
|
+
{...(mergedGroupProps() as JSX.HTMLAttributes<HTMLDivElement>)}
|
|
118
|
+
class={renderProps.class()}
|
|
119
|
+
style={renderProps.style()}
|
|
120
|
+
slot={local.slot}
|
|
121
|
+
data-orientation={local.orientation ?? "horizontal"}
|
|
122
|
+
data-disabled={local.isDisabled || undefined}
|
|
123
|
+
ref={(el) => {
|
|
124
|
+
if (!local.ref) return;
|
|
125
|
+
if (typeof local.ref === "function") {
|
|
126
|
+
local.ref(el);
|
|
127
|
+
}
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<ToggleButtonGroupContext.Provider value={props}>
|
|
131
|
+
<ToggleButtonGroupStateContext.Provider value={state}>
|
|
132
|
+
{renderProps.renderChildren()}
|
|
133
|
+
</ToggleButtonGroupStateContext.Provider>
|
|
134
|
+
</ToggleButtonGroupContext.Provider>
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function useToggleButtonGroupStateContext(): ToggleGroupState | null {
|
|
140
|
+
return useContext(ToggleButtonGroupStateContext);
|
|
141
|
+
}
|
package/src/Toolbar.tsx
CHANGED
|
@@ -12,53 +12,37 @@ import {
|
|
|
12
12
|
createMemo,
|
|
13
13
|
splitProps,
|
|
14
14
|
useContext,
|
|
15
|
-
} from
|
|
15
|
+
} from "solid-js";
|
|
16
16
|
import {
|
|
17
17
|
createToolbar,
|
|
18
18
|
type AriaToolbarProps,
|
|
19
19
|
type Orientation,
|
|
20
|
-
} from
|
|
21
|
-
import {
|
|
22
|
-
type SlotProps,
|
|
23
|
-
filterDOMProps,
|
|
24
|
-
} from './utils'
|
|
25
|
-
|
|
26
|
-
// ============================================
|
|
27
|
-
// TYPES
|
|
28
|
-
// ============================================
|
|
20
|
+
} from "@proyecto-viviana/solidaria";
|
|
21
|
+
import { type SlotProps, filterDOMProps } from "./utils";
|
|
29
22
|
|
|
30
23
|
export interface ToolbarRenderProps {
|
|
31
24
|
/** The orientation of the toolbar. */
|
|
32
|
-
orientation: Orientation
|
|
25
|
+
orientation: Orientation;
|
|
33
26
|
}
|
|
34
27
|
|
|
35
|
-
export interface ToolbarProps
|
|
36
|
-
extends AriaToolbarProps,
|
|
37
|
-
ParentProps,
|
|
38
|
-
SlotProps {
|
|
28
|
+
export interface ToolbarProps extends AriaToolbarProps, ParentProps, SlotProps {
|
|
39
29
|
/** The CSS className for the element. A function may be provided to receive render props. */
|
|
40
|
-
class?: string | ((renderProps: ToolbarRenderProps) => string)
|
|
30
|
+
class?: string | ((renderProps: ToolbarRenderProps) => string);
|
|
41
31
|
/** The inline style for the element. A function may be provided to receive render props. */
|
|
42
|
-
style?: JSX.CSSProperties | ((renderProps: ToolbarRenderProps) => JSX.CSSProperties)
|
|
32
|
+
style?: JSX.CSSProperties | ((renderProps: ToolbarRenderProps) => JSX.CSSProperties);
|
|
43
33
|
/** Additional data-* attributes. */
|
|
44
|
-
[key: `data-${string}`]: string | undefined
|
|
34
|
+
[key: `data-${string}`]: string | undefined;
|
|
35
|
+
/** Ref for the toolbar element. */
|
|
36
|
+
ref?: ((el: HTMLDivElement) => void) | { current?: HTMLDivElement | null };
|
|
45
37
|
}
|
|
46
38
|
|
|
47
|
-
// ============================================
|
|
48
|
-
// CONTEXT
|
|
49
|
-
// ============================================
|
|
50
|
-
|
|
51
39
|
export interface ToolbarContextValue {
|
|
52
40
|
slots?: {
|
|
53
|
-
[name: string]: Record<string, unknown
|
|
54
|
-
}
|
|
41
|
+
[name: string]: Record<string, unknown>;
|
|
42
|
+
};
|
|
55
43
|
}
|
|
56
44
|
|
|
57
|
-
export const ToolbarContext = createContext<ToolbarContextValue | null>(null)
|
|
58
|
-
|
|
59
|
-
// ============================================
|
|
60
|
-
// TOOLBAR COMPONENT
|
|
61
|
-
// ============================================
|
|
45
|
+
export const ToolbarContext = createContext<ToolbarContextValue | null>(null);
|
|
62
46
|
|
|
63
47
|
/**
|
|
64
48
|
* A toolbar is a container for a set of interactive controls,
|
|
@@ -87,63 +71,62 @@ export const ToolbarContext = createContext<ToolbarContextValue | null>(null)
|
|
|
87
71
|
export function Toolbar(props: ToolbarProps): JSX.Element {
|
|
88
72
|
const [local, ariaProps, domProps] = splitProps(
|
|
89
73
|
props,
|
|
90
|
-
[
|
|
91
|
-
[
|
|
92
|
-
)
|
|
74
|
+
["class", "style", "slot", "children", "ref"],
|
|
75
|
+
["orientation", "aria-label", "aria-labelledby"],
|
|
76
|
+
);
|
|
93
77
|
|
|
94
|
-
|
|
95
|
-
const ctx = useContext(ToolbarContext)
|
|
78
|
+
const ctx = useContext(ToolbarContext);
|
|
96
79
|
const slotProps = () => {
|
|
97
80
|
if (ctx?.slots && local.slot) {
|
|
98
|
-
return ctx.slots[local.slot] || {}
|
|
81
|
+
return ctx.slots[local.slot] || {};
|
|
99
82
|
}
|
|
100
|
-
return {}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
83
|
+
return {};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const { toolbarProps, orientation } = createToolbar({
|
|
87
|
+
get orientation() {
|
|
88
|
+
return ariaProps.orientation;
|
|
89
|
+
},
|
|
90
|
+
get "aria-label"() {
|
|
91
|
+
return (
|
|
92
|
+
(ariaProps["aria-label"] as string | undefined) ??
|
|
93
|
+
(slotProps()["aria-label"] as string | undefined)
|
|
94
|
+
);
|
|
95
|
+
},
|
|
96
|
+
get "aria-labelledby"() {
|
|
97
|
+
return ariaProps["aria-labelledby"] as string | undefined;
|
|
98
|
+
},
|
|
99
|
+
});
|
|
112
100
|
|
|
113
|
-
// Render props values
|
|
114
101
|
const renderValues = createMemo<ToolbarRenderProps>(() => ({
|
|
115
102
|
orientation: orientation(),
|
|
116
|
-
}))
|
|
103
|
+
}));
|
|
117
104
|
|
|
118
|
-
// Resolve class
|
|
119
105
|
const resolvedClass = createMemo(() => {
|
|
120
|
-
const cls = local.class
|
|
121
|
-
if (typeof cls ===
|
|
122
|
-
return cls(renderValues())
|
|
106
|
+
const cls = local.class;
|
|
107
|
+
if (typeof cls === "function") {
|
|
108
|
+
return cls(renderValues());
|
|
123
109
|
}
|
|
124
|
-
return cls ??
|
|
125
|
-
})
|
|
110
|
+
return cls ?? "solidaria-Toolbar";
|
|
111
|
+
});
|
|
126
112
|
|
|
127
|
-
// Resolve style
|
|
128
113
|
const resolvedStyle = createMemo(() => {
|
|
129
|
-
const style = local.style
|
|
130
|
-
if (typeof style ===
|
|
131
|
-
return style(renderValues())
|
|
114
|
+
const style = local.style;
|
|
115
|
+
if (typeof style === "function") {
|
|
116
|
+
return style(renderValues());
|
|
132
117
|
}
|
|
133
|
-
return style
|
|
134
|
-
})
|
|
118
|
+
return style;
|
|
119
|
+
});
|
|
135
120
|
|
|
136
|
-
// Resolve children (support render props)
|
|
137
121
|
const resolvedChildren = createMemo(() => {
|
|
138
|
-
const children = props.children
|
|
139
|
-
if (typeof children ===
|
|
140
|
-
return (children as (props: ToolbarRenderProps) => JSX.Element)(renderValues())
|
|
122
|
+
const children = props.children;
|
|
123
|
+
if (typeof children === "function") {
|
|
124
|
+
return (children as (props: ToolbarRenderProps) => JSX.Element)(renderValues());
|
|
141
125
|
}
|
|
142
|
-
return children
|
|
143
|
-
})
|
|
126
|
+
return children;
|
|
127
|
+
});
|
|
144
128
|
|
|
145
|
-
|
|
146
|
-
const filteredDOMProps = createMemo(() => filterDOMProps(domProps, { global: true }))
|
|
129
|
+
const filteredDOMProps = createMemo(() => filterDOMProps(domProps, { global: true }));
|
|
147
130
|
|
|
148
131
|
return (
|
|
149
132
|
<div
|
|
@@ -153,8 +136,16 @@ export function Toolbar(props: ToolbarProps): JSX.Element {
|
|
|
153
136
|
style={resolvedStyle()}
|
|
154
137
|
slot={local.slot}
|
|
155
138
|
data-orientation={orientation()}
|
|
139
|
+
ref={(el) => {
|
|
140
|
+
if (!local.ref) return;
|
|
141
|
+
if (typeof local.ref === "function") {
|
|
142
|
+
local.ref(el);
|
|
143
|
+
} else {
|
|
144
|
+
local.ref.current = el;
|
|
145
|
+
}
|
|
146
|
+
}}
|
|
156
147
|
>
|
|
157
148
|
{resolvedChildren()}
|
|
158
149
|
</div>
|
|
159
|
-
)
|
|
150
|
+
);
|
|
160
151
|
}
|