@proyecto-viviana/solidaria-components 0.2.9 → 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/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 +23247 -18564
- package/dist/index.js.map +1 -1
- package/dist/index.jsx +18110 -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 +243 -175
- package/src/NumberField.tsx +139 -143
- package/src/Popover.tsx +386 -233
- 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 +209 -157
- 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 +40 -55
- package/src/virtualizer/Layout.ts +14 -22
- package/dist/index.ssr.js +0 -16996
- package/dist/index.ssr.js.map +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createContext, useContext } from "solid-js";
|
|
2
|
+
import { type createDateRangePicker } from "@proyecto-viviana/solidaria";
|
|
3
|
+
import {
|
|
4
|
+
type DateFieldState,
|
|
5
|
+
type DateValue,
|
|
6
|
+
type RangeCalendarState,
|
|
7
|
+
} from "@proyecto-viviana/solid-stately";
|
|
8
|
+
|
|
9
|
+
export interface DateRangePickerFieldContextValue {
|
|
10
|
+
state: DateFieldState<DateValue>;
|
|
11
|
+
aria: {
|
|
12
|
+
labelProps: Record<string, unknown>;
|
|
13
|
+
inputProps: Record<string, unknown>;
|
|
14
|
+
descriptionProps: Record<string, unknown>;
|
|
15
|
+
errorMessageProps: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface DateRangePickerContextValue {
|
|
20
|
+
calendarState: RangeCalendarState<DateValue>;
|
|
21
|
+
startFieldState: DateFieldState<DateValue>;
|
|
22
|
+
endFieldState: DateFieldState<DateValue>;
|
|
23
|
+
startFieldContext: DateRangePickerFieldContextValue;
|
|
24
|
+
endFieldContext: DateRangePickerFieldContextValue;
|
|
25
|
+
overlayState: {
|
|
26
|
+
isOpen: boolean;
|
|
27
|
+
open: () => void;
|
|
28
|
+
close: () => void;
|
|
29
|
+
toggle: () => void;
|
|
30
|
+
};
|
|
31
|
+
triggerRef: () => HTMLElement | null;
|
|
32
|
+
setTriggerRef: (element: HTMLElement | null) => void;
|
|
33
|
+
pickerAria: ReturnType<typeof createDateRangePicker>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const DateRangePickerContext = createContext<DateRangePickerContextValue | null>(null);
|
|
37
|
+
|
|
38
|
+
export function useDateRangePickerContext(): DateRangePickerContextValue {
|
|
39
|
+
const context = useContext(DateRangePickerContext);
|
|
40
|
+
if (!context) {
|
|
41
|
+
throw new Error("DateRangePicker components must be used within a DateRangePicker");
|
|
42
|
+
}
|
|
43
|
+
return context;
|
|
44
|
+
}
|
package/src/Dialog.tsx
CHANGED
|
@@ -15,14 +15,18 @@ import {
|
|
|
15
15
|
useContext,
|
|
16
16
|
Switch,
|
|
17
17
|
Match,
|
|
18
|
-
} from
|
|
18
|
+
} from "solid-js";
|
|
19
19
|
import {
|
|
20
20
|
createDialog,
|
|
21
21
|
createOverlayTrigger,
|
|
22
|
+
focusSafely,
|
|
22
23
|
type AriaDialogProps,
|
|
23
|
-
} from
|
|
24
|
-
import {
|
|
25
|
-
|
|
24
|
+
} from "@proyecto-viviana/solidaria";
|
|
25
|
+
import {
|
|
26
|
+
createOverlayTriggerState,
|
|
27
|
+
type OverlayTriggerState,
|
|
28
|
+
} from "@proyecto-viviana/solid-stately";
|
|
29
|
+
import { DialogTriggerContext, useOverlayTriggerState } from "./contexts";
|
|
26
30
|
import {
|
|
27
31
|
type RenderChildren,
|
|
28
32
|
type ClassNameOrFunction,
|
|
@@ -30,181 +34,206 @@ import {
|
|
|
30
34
|
type SlotProps,
|
|
31
35
|
useRenderProps,
|
|
32
36
|
filterDOMProps,
|
|
33
|
-
} from
|
|
34
|
-
|
|
35
|
-
// ============================================
|
|
36
|
-
// TYPES
|
|
37
|
-
// ============================================
|
|
37
|
+
} from "./utils";
|
|
38
38
|
|
|
39
39
|
export interface DialogRenderProps {
|
|
40
40
|
/** Function to close the dialog */
|
|
41
|
-
close: () => void
|
|
41
|
+
close: () => void;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export interface DialogProps extends Omit<AriaDialogProps,
|
|
44
|
+
export interface DialogProps extends Omit<AriaDialogProps, "class" | "style">, SlotProps {
|
|
45
45
|
/** The children of the component - can be JSX or render function. */
|
|
46
|
-
children?: RenderChildren<DialogRenderProps
|
|
46
|
+
children?: RenderChildren<DialogRenderProps>;
|
|
47
47
|
/** The CSS className for the element. */
|
|
48
|
-
class?: ClassNameOrFunction<DialogRenderProps
|
|
48
|
+
class?: ClassNameOrFunction<DialogRenderProps>;
|
|
49
49
|
/** The inline style for the element. */
|
|
50
|
-
style?: StyleOrFunction<DialogRenderProps
|
|
50
|
+
style?: StyleOrFunction<DialogRenderProps>;
|
|
51
51
|
/** Callback when dialog should close */
|
|
52
|
-
onClose?: () => void
|
|
52
|
+
onClose?: () => void;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export interface DialogTriggerProps {
|
|
56
56
|
/** The children - should include a trigger and modal/popover content. */
|
|
57
|
-
children: JSX.Element
|
|
57
|
+
children: JSX.Element;
|
|
58
58
|
/** Whether the dialog is open (controlled). */
|
|
59
|
-
isOpen?: boolean
|
|
59
|
+
isOpen?: boolean;
|
|
60
60
|
/** Whether the dialog is open by default (uncontrolled). */
|
|
61
|
-
defaultOpen?: boolean
|
|
61
|
+
defaultOpen?: boolean;
|
|
62
62
|
/** Callback when open state changes. */
|
|
63
|
-
onOpenChange?: (isOpen: boolean) => void
|
|
63
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
// ============================================
|
|
67
|
-
// CONTEXTS
|
|
68
|
-
// ============================================
|
|
69
|
-
|
|
70
66
|
interface DialogContextValue {
|
|
71
|
-
close: () => void
|
|
72
|
-
titleId?: string
|
|
67
|
+
close: () => void;
|
|
68
|
+
titleId?: string;
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
export const DialogContext = createContext<DialogContextValue | null>(null)
|
|
71
|
+
export const DialogContext = createContext<DialogContextValue | null>(null);
|
|
76
72
|
|
|
77
|
-
|
|
78
|
-
export { DialogTriggerContext, useDialogTrigger } from './contexts'
|
|
79
|
-
|
|
80
|
-
// ============================================
|
|
81
|
-
// DIALOG TRIGGER COMPONENT
|
|
82
|
-
// ============================================
|
|
73
|
+
export { DialogTriggerContext, useDialogTrigger } from "./contexts";
|
|
83
74
|
|
|
84
75
|
/**
|
|
85
76
|
* A DialogTrigger opens a dialog when a trigger element is pressed.
|
|
86
77
|
* Children should include a trigger element (e.g. Button) and the dialog content.
|
|
87
78
|
*/
|
|
88
79
|
export function DialogTrigger(props: DialogTriggerProps): JSX.Element {
|
|
89
|
-
const [local] = splitProps(props, [
|
|
80
|
+
const [local] = splitProps(props, ["isOpen", "defaultOpen", "onOpenChange"]);
|
|
90
81
|
|
|
91
|
-
// Create overlay trigger state
|
|
92
82
|
const state = createOverlayTriggerState({
|
|
93
83
|
get isOpen() {
|
|
94
|
-
return local.isOpen
|
|
84
|
+
return local.isOpen;
|
|
95
85
|
},
|
|
96
86
|
get defaultOpen() {
|
|
97
|
-
return local.defaultOpen
|
|
87
|
+
return local.defaultOpen;
|
|
98
88
|
},
|
|
99
89
|
onOpenChange: local.onOpenChange,
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
createOverlayTrigger(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
let triggerRef: HTMLElement | null = null;
|
|
93
|
+
const triggerId = createUniqueId();
|
|
94
|
+
|
|
95
|
+
// Create overlay trigger props so registered trigger components can expose
|
|
96
|
+
// the same expanded/controls relationship as React Aria DialogTrigger.
|
|
97
|
+
const triggerAria = createOverlayTrigger({ type: "dialog" }, state, () => triggerRef);
|
|
98
|
+
|
|
99
|
+
const restoreFocusToTrigger = () => {
|
|
100
|
+
const trigger = triggerRef;
|
|
101
|
+
if (!trigger?.isConnected) return;
|
|
102
|
+
|
|
103
|
+
const win = trigger.ownerDocument.defaultView ?? window;
|
|
104
|
+
win.requestAnimationFrame(() => {
|
|
105
|
+
win.requestAnimationFrame(() => {
|
|
106
|
+
if (trigger.isConnected && !state.isOpen()) {
|
|
107
|
+
focusSafely(trigger);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const stateWithFocusRestore: OverlayTriggerState = {
|
|
114
|
+
isOpen: state.isOpen,
|
|
115
|
+
setOpen: (isOpen) => {
|
|
116
|
+
state.setOpen(isOpen);
|
|
117
|
+
if (!isOpen) {
|
|
118
|
+
restoreFocusToTrigger();
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
open: state.open,
|
|
122
|
+
close: () => {
|
|
123
|
+
state.close();
|
|
124
|
+
restoreFocusToTrigger();
|
|
125
|
+
},
|
|
126
|
+
toggle: () => {
|
|
127
|
+
const wasOpen = state.isOpen();
|
|
128
|
+
state.toggle();
|
|
129
|
+
if (wasOpen) {
|
|
130
|
+
restoreFocusToTrigger();
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
};
|
|
112
134
|
|
|
113
135
|
const setTriggerRef = (el: HTMLElement | null) => {
|
|
114
|
-
if (!el) return
|
|
136
|
+
if (!el) return;
|
|
115
137
|
if (!triggerRef || !triggerRef.isConnected) {
|
|
116
|
-
triggerRef = el
|
|
138
|
+
triggerRef = el;
|
|
117
139
|
}
|
|
118
|
-
}
|
|
140
|
+
};
|
|
119
141
|
|
|
120
142
|
// Context value - memoized to avoid unnecessary re-renders
|
|
121
143
|
const contextValue = createMemo(() => ({
|
|
122
|
-
state,
|
|
144
|
+
state: stateWithFocusRestore,
|
|
123
145
|
triggerRef: () => triggerRef,
|
|
124
146
|
setTriggerRef,
|
|
125
147
|
triggerId,
|
|
126
|
-
|
|
148
|
+
triggerProps: triggerAria.triggerProps,
|
|
149
|
+
overlayProps: triggerAria.overlayProps,
|
|
150
|
+
}));
|
|
127
151
|
|
|
128
152
|
// In SolidJS, we simply render children directly within the provider
|
|
129
|
-
// The children will have access to the context
|
|
130
153
|
return (
|
|
131
154
|
<DialogTriggerContext.Provider value={contextValue()}>
|
|
132
155
|
{props.children}
|
|
133
156
|
</DialogTriggerContext.Provider>
|
|
134
|
-
)
|
|
157
|
+
);
|
|
135
158
|
}
|
|
136
159
|
|
|
137
|
-
// ============================================
|
|
138
|
-
// DIALOG COMPONENT
|
|
139
|
-
// ============================================
|
|
140
|
-
|
|
141
160
|
/**
|
|
142
161
|
* A dialog is an overlay shown above other content in an application.
|
|
143
162
|
*/
|
|
144
163
|
export function Dialog(props: DialogProps): JSX.Element {
|
|
145
164
|
const [local, ariaProps, rest] = splitProps(
|
|
146
165
|
props,
|
|
147
|
-
[
|
|
148
|
-
[
|
|
149
|
-
)
|
|
166
|
+
["class", "style", "slot", "onClose"],
|
|
167
|
+
["role", "aria-label", "aria-labelledby", "aria-describedby"],
|
|
168
|
+
);
|
|
150
169
|
|
|
151
|
-
let dialogRef!: HTMLDivElement
|
|
170
|
+
let dialogRef!: HTMLDivElement;
|
|
152
171
|
|
|
153
172
|
// Get trigger context for aria-labelledby fallback
|
|
154
|
-
const triggerContext = useContext(DialogTriggerContext)
|
|
173
|
+
const triggerContext = useContext(DialogTriggerContext);
|
|
155
174
|
|
|
156
175
|
// createDialog returns dialogProps AND titleProps (with the id for the Heading)
|
|
157
176
|
const { dialogProps, titleProps } = createDialog(
|
|
158
177
|
{
|
|
159
178
|
get role() {
|
|
160
|
-
return ariaProps.role
|
|
179
|
+
return ariaProps.role;
|
|
161
180
|
},
|
|
162
|
-
get
|
|
163
|
-
return ariaProps[
|
|
181
|
+
get "aria-label"() {
|
|
182
|
+
return ariaProps["aria-label"];
|
|
164
183
|
},
|
|
165
|
-
get
|
|
166
|
-
return ariaProps[
|
|
184
|
+
get "aria-labelledby"() {
|
|
185
|
+
return ariaProps["aria-labelledby"];
|
|
167
186
|
},
|
|
168
|
-
get
|
|
169
|
-
return ariaProps[
|
|
187
|
+
get "aria-describedby"() {
|
|
188
|
+
return ariaProps["aria-describedby"];
|
|
170
189
|
},
|
|
171
190
|
},
|
|
172
|
-
() => dialogRef
|
|
173
|
-
)
|
|
191
|
+
() => dialogRef,
|
|
192
|
+
);
|
|
174
193
|
|
|
175
194
|
// Get titleId from titleProps - this links Dialog's aria-labelledby to Heading's id
|
|
176
|
-
const titleId = () => titleProps()?.id
|
|
195
|
+
const titleId = () => titleProps()?.id as string | undefined;
|
|
177
196
|
|
|
178
197
|
// Get close function from OverlayTriggerState context or onClose prop
|
|
179
|
-
const overlayState = useOverlayTriggerState()
|
|
198
|
+
const overlayState = useOverlayTriggerState();
|
|
180
199
|
|
|
181
200
|
const close = () => {
|
|
182
|
-
local.onClose?.()
|
|
201
|
+
local.onClose?.();
|
|
183
202
|
if (overlayState) {
|
|
184
|
-
overlayState.close()
|
|
185
|
-
return
|
|
203
|
+
overlayState.close();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
triggerContext?.state.close();
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
createEffect(() => {
|
|
210
|
+
if (!dialogRef || ariaProps["aria-label"] || ariaProps["aria-labelledby"]) return;
|
|
211
|
+
const labelledBy = dialogRef.getAttribute("aria-labelledby");
|
|
212
|
+
if (labelledBy && dialogRef.ownerDocument.getElementById(labelledBy)) return;
|
|
213
|
+
|
|
214
|
+
const trigger = triggerContext?.triggerRef();
|
|
215
|
+
if (trigger?.id) {
|
|
216
|
+
dialogRef.setAttribute("aria-labelledby", trigger.id);
|
|
186
217
|
}
|
|
187
|
-
|
|
188
|
-
}
|
|
218
|
+
});
|
|
189
219
|
|
|
190
|
-
// Render props values
|
|
191
220
|
const renderValues = createMemo<DialogRenderProps>(() => ({
|
|
192
221
|
close,
|
|
193
|
-
}))
|
|
222
|
+
}));
|
|
194
223
|
|
|
195
|
-
// Resolve render props
|
|
196
224
|
const renderProps = useRenderProps(
|
|
197
225
|
{
|
|
198
226
|
children: props.children,
|
|
199
227
|
class: local.class,
|
|
200
228
|
style: local.style,
|
|
201
|
-
defaultClassName:
|
|
229
|
+
defaultClassName: "solidaria-Dialog",
|
|
202
230
|
},
|
|
203
|
-
renderValues
|
|
204
|
-
)
|
|
231
|
+
renderValues,
|
|
232
|
+
);
|
|
205
233
|
|
|
206
|
-
|
|
207
|
-
|
|
234
|
+
const domProps = createMemo(() =>
|
|
235
|
+
filterDOMProps(rest as Record<string, unknown>, { global: true }),
|
|
236
|
+
);
|
|
208
237
|
|
|
209
238
|
return (
|
|
210
239
|
<DialogContext.Provider value={{ close, titleId: titleId() }}>
|
|
@@ -214,26 +243,23 @@ export function Dialog(props: DialogProps): JSX.Element {
|
|
|
214
243
|
ref={dialogRef}
|
|
215
244
|
class={renderProps.class()}
|
|
216
245
|
style={renderProps.style()}
|
|
246
|
+
slot={local.slot}
|
|
217
247
|
>
|
|
218
248
|
{renderProps.renderChildren()}
|
|
219
249
|
</div>
|
|
220
250
|
</DialogContext.Provider>
|
|
221
|
-
)
|
|
251
|
+
);
|
|
222
252
|
}
|
|
223
253
|
|
|
224
|
-
// ============================================
|
|
225
|
-
// HEADING COMPONENT
|
|
226
|
-
// ============================================
|
|
227
|
-
|
|
228
254
|
export interface HeadingProps {
|
|
229
255
|
/** The children of the heading. */
|
|
230
|
-
children: JSX.Element
|
|
256
|
+
children: JSX.Element;
|
|
231
257
|
/** The CSS className. */
|
|
232
|
-
class?: string
|
|
258
|
+
class?: string;
|
|
233
259
|
/** The heading level (1-6). Defaults to 2. */
|
|
234
|
-
level?: 1 | 2 | 3 | 4 | 5 | 6
|
|
260
|
+
level?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
235
261
|
/** The slot to render into. */
|
|
236
|
-
slot?: string
|
|
262
|
+
slot?: string;
|
|
237
263
|
}
|
|
238
264
|
|
|
239
265
|
/**
|
|
@@ -241,53 +267,65 @@ export interface HeadingProps {
|
|
|
241
267
|
* When rendered inside a Dialog, automatically gets the titleProps.
|
|
242
268
|
*/
|
|
243
269
|
export function Heading(props: HeadingProps): JSX.Element {
|
|
244
|
-
const dialogContext = useContext(DialogContext)
|
|
245
|
-
const level = () => props.level ?? 2
|
|
246
|
-
const id = () => dialogContext?.titleId
|
|
247
|
-
let headingRef: HTMLHeadingElement | undefined
|
|
270
|
+
const dialogContext = useContext(DialogContext);
|
|
271
|
+
const level = () => props.level ?? 2;
|
|
272
|
+
const id = () => dialogContext?.titleId;
|
|
273
|
+
let headingRef: HTMLHeadingElement | undefined;
|
|
248
274
|
|
|
249
275
|
createEffect(() => {
|
|
250
|
-
const el = headingRef
|
|
251
|
-
if (!el) return
|
|
276
|
+
const el = headingRef;
|
|
277
|
+
if (!el) return;
|
|
252
278
|
|
|
253
|
-
const contextId = id()
|
|
279
|
+
const contextId = id();
|
|
254
280
|
if (contextId) {
|
|
255
|
-
el.id = contextId
|
|
256
|
-
return
|
|
281
|
+
el.id = contextId;
|
|
282
|
+
return;
|
|
257
283
|
}
|
|
258
284
|
|
|
259
285
|
if (!el.id) {
|
|
260
|
-
const dialog = el.closest('[role="dialog"],[role="alertdialog"]')
|
|
261
|
-
const labelledBy = dialog?.getAttribute(
|
|
286
|
+
const dialog = el.closest('[role="dialog"],[role="alertdialog"]');
|
|
287
|
+
const labelledBy = dialog?.getAttribute("aria-labelledby");
|
|
262
288
|
if (labelledBy && !el.ownerDocument.getElementById(labelledBy)) {
|
|
263
|
-
el.id = labelledBy
|
|
289
|
+
el.id = labelledBy;
|
|
264
290
|
}
|
|
265
291
|
}
|
|
266
|
-
})
|
|
292
|
+
});
|
|
267
293
|
|
|
268
294
|
return (
|
|
269
295
|
<Switch>
|
|
270
296
|
<Match when={level() === 1}>
|
|
271
|
-
<h1 ref={headingRef} id={id()} class={props.class}>
|
|
297
|
+
<h1 ref={headingRef} id={id()} class={props.class}>
|
|
298
|
+
{props.children}
|
|
299
|
+
</h1>
|
|
272
300
|
</Match>
|
|
273
301
|
<Match when={level() === 2}>
|
|
274
|
-
<h2 ref={headingRef} id={id()} class={props.class}>
|
|
302
|
+
<h2 ref={headingRef} id={id()} class={props.class}>
|
|
303
|
+
{props.children}
|
|
304
|
+
</h2>
|
|
275
305
|
</Match>
|
|
276
306
|
<Match when={level() === 3}>
|
|
277
|
-
<h3 ref={headingRef} id={id()} class={props.class}>
|
|
307
|
+
<h3 ref={headingRef} id={id()} class={props.class}>
|
|
308
|
+
{props.children}
|
|
309
|
+
</h3>
|
|
278
310
|
</Match>
|
|
279
311
|
<Match when={level() === 4}>
|
|
280
|
-
<h4 ref={headingRef} id={id()} class={props.class}>
|
|
312
|
+
<h4 ref={headingRef} id={id()} class={props.class}>
|
|
313
|
+
{props.children}
|
|
314
|
+
</h4>
|
|
281
315
|
</Match>
|
|
282
316
|
<Match when={level() === 5}>
|
|
283
|
-
<h5 ref={headingRef} id={id()} class={props.class}>
|
|
317
|
+
<h5 ref={headingRef} id={id()} class={props.class}>
|
|
318
|
+
{props.children}
|
|
319
|
+
</h5>
|
|
284
320
|
</Match>
|
|
285
321
|
<Match when={level() === 6}>
|
|
286
|
-
<h6 ref={headingRef} id={id()} class={props.class}>
|
|
322
|
+
<h6 ref={headingRef} id={id()} class={props.class}>
|
|
323
|
+
{props.children}
|
|
324
|
+
</h6>
|
|
287
325
|
</Match>
|
|
288
326
|
</Switch>
|
|
289
|
-
)
|
|
327
|
+
);
|
|
290
328
|
}
|
|
291
329
|
|
|
292
330
|
// Keep backward compatibility
|
|
293
|
-
export { Heading as DialogHeading }
|
|
331
|
+
export { Heading as DialogHeading };
|