@entropix/react 1.0.0 → 1.0.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/dist/accordion.cjs +27 -0
- package/dist/accordion.css +57 -0
- package/dist/accordion.d.cts +30 -0
- package/dist/accordion.d.ts +30 -0
- package/dist/accordion.js +6 -0
- package/dist/button.cjs +15 -0
- package/dist/button.css +113 -0
- package/dist/button.d.cts +25 -0
- package/dist/button.d.ts +25 -0
- package/dist/button.js +6 -0
- package/dist/checkbox.cjs +15 -0
- package/dist/checkbox.css +89 -0
- package/dist/checkbox.d.cts +26 -0
- package/dist/checkbox.d.ts +26 -0
- package/dist/checkbox.js +6 -0
- package/dist/chunk-2MKJZEUK.cjs +4 -0
- package/dist/chunk-34IVVIO3.cjs +119 -0
- package/dist/chunk-36ZHHJYV.js +79 -0
- package/dist/chunk-5DKE5YQD.cjs +10 -0
- package/dist/chunk-664P2RGR.js +108 -0
- package/dist/chunk-6NKHMBF3.cjs +97 -0
- package/dist/chunk-6UAQCHIW.js +8 -0
- package/dist/chunk-7AUIZOEH.cjs +84 -0
- package/dist/chunk-AVCBDUKH.js +3 -0
- package/dist/chunk-B5JZHE4I.cjs +90 -0
- package/dist/chunk-BN57JPKV.js +26 -0
- package/dist/chunk-BY4E26CV.js +114 -0
- package/dist/chunk-CL6JXZIY.js +88 -0
- package/dist/chunk-CTT3LXMZ.js +76 -0
- package/dist/chunk-EASSPJBG.cjs +110 -0
- package/dist/chunk-EWY7MSXF.cjs +94 -0
- package/dist/chunk-FJGLK3I4.js +89 -0
- package/dist/chunk-GTVBKK3W.js +88 -0
- package/dist/chunk-GZXXUFCJ.cjs +15 -0
- package/dist/chunk-IXH7OVN3.cjs +86 -0
- package/dist/chunk-KGIUECLG.cjs +91 -0
- package/dist/chunk-LDOP6DVX.cjs +28 -0
- package/dist/chunk-LJK6KK2H.cjs +43 -0
- package/dist/chunk-OT2HJUCB.js +84 -0
- package/dist/chunk-PILZGMQG.js +87 -0
- package/dist/chunk-PN42JF6U.js +92 -0
- package/dist/chunk-RPIYYBFJ.cjs +90 -0
- package/dist/chunk-S6DVQAH4.cjs +240 -0
- package/dist/chunk-U5CZHO6D.js +13 -0
- package/dist/chunk-UGCCJI2F.js +111 -0
- package/dist/chunk-W6N4D4N4.js +230 -0
- package/dist/chunk-Y2M2LJGJ.js +41 -0
- package/dist/chunk-YJG5KX6O.cjs +81 -0
- package/dist/chunk-ZG4PZBSL.cjs +113 -0
- package/dist/dialog.cjs +39 -0
- package/dist/dialog.css +89 -0
- package/dist/dialog.d.cts +62 -0
- package/dist/dialog.d.ts +62 -0
- package/dist/dialog.js +6 -0
- package/dist/index.cjs +170 -1223
- package/dist/index.d.cts +17 -477
- package/dist/index.d.ts +17 -477
- package/dist/index.js +19 -1189
- package/dist/input.cjs +15 -0
- package/dist/input.css +135 -0
- package/dist/input.d.cts +37 -0
- package/dist/input.d.ts +37 -0
- package/dist/input.js +6 -0
- package/dist/layout.cjs +25 -0
- package/dist/layout.css +176 -0
- package/dist/layout.d.cts +108 -0
- package/dist/layout.d.ts +108 -0
- package/dist/layout.js +4 -0
- package/dist/menu.cjs +27 -0
- package/dist/menu.css +51 -0
- package/dist/menu.d.cts +31 -0
- package/dist/menu.d.ts +31 -0
- package/dist/menu.js +6 -0
- package/dist/radio.cjs +19 -0
- package/dist/radio.css +93 -0
- package/dist/radio.d.cts +37 -0
- package/dist/radio.d.ts +37 -0
- package/dist/radio.js +6 -0
- package/dist/select.cjs +27 -0
- package/dist/select.css +114 -0
- package/dist/select.d.cts +59 -0
- package/dist/select.d.ts +59 -0
- package/dist/select.js +6 -0
- package/dist/styles/accordion.css +1 -67
- package/dist/styles/button.css +1 -133
- package/dist/styles/checkbox.css +1 -119
- package/dist/styles/dialog.css +1 -102
- package/dist/styles/index.css +1 -14
- package/dist/styles/input.css +1 -176
- package/dist/styles/layout.css +1 -125
- package/dist/styles/menu.css +1 -62
- package/dist/styles/radio.css +1 -128
- package/dist/styles/select.css +1 -148
- package/dist/styles/switch.css +1 -53
- package/dist/styles/tabs.css +1 -84
- package/dist/styles/toggle.css +1 -45
- package/dist/switch.cjs +16 -0
- package/dist/switch.css +89 -0
- package/dist/switch.d.cts +14 -0
- package/dist/switch.d.ts +14 -0
- package/dist/switch.js +7 -0
- package/dist/tabs.cjs +27 -0
- package/dist/tabs.css +69 -0
- package/dist/tabs.d.cts +31 -0
- package/dist/tabs.d.ts +31 -0
- package/dist/tabs.js +6 -0
- package/dist/textarea.cjs +15 -0
- package/dist/textarea.css +135 -0
- package/dist/textarea.d.cts +41 -0
- package/dist/textarea.d.ts +41 -0
- package/dist/textarea.js +6 -0
- package/dist/toggle.cjs +19 -0
- package/dist/toggle.css +41 -0
- package/dist/toggle.d.cts +34 -0
- package/dist/toggle.d.ts +34 -0
- package/dist/toggle.js +6 -0
- package/package.json +135 -4
- package/dist/index.cjs.map +0 -1
- package/dist/index.css.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLDOP6DVX_cjs = require('./chunk-LDOP6DVX.cjs');
|
|
4
|
+
var chunkLJK6KK2H_cjs = require('./chunk-LJK6KK2H.cjs');
|
|
5
|
+
var chunk5DKE5YQD_cjs = require('./chunk-5DKE5YQD.cjs');
|
|
6
|
+
var core = require('@entropix/core');
|
|
7
|
+
var react = require('react');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
var reactDom = require('react-dom');
|
|
10
|
+
|
|
11
|
+
var DialogContext = react.createContext(null);
|
|
12
|
+
function useDialogContext() {
|
|
13
|
+
const context = react.useContext(DialogContext);
|
|
14
|
+
if (!context) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
"Dialog compound components must be used within a <Dialog> provider."
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
function Dialog({
|
|
22
|
+
children,
|
|
23
|
+
isOpen,
|
|
24
|
+
defaultOpen,
|
|
25
|
+
onOpenChange,
|
|
26
|
+
closeOnOverlayPress,
|
|
27
|
+
closeOnEscape,
|
|
28
|
+
modal,
|
|
29
|
+
role
|
|
30
|
+
}) {
|
|
31
|
+
const dialog = core.useDialog({
|
|
32
|
+
isOpen,
|
|
33
|
+
defaultOpen,
|
|
34
|
+
onOpenChange,
|
|
35
|
+
closeOnOverlayPress,
|
|
36
|
+
closeOnEscape,
|
|
37
|
+
modal,
|
|
38
|
+
role
|
|
39
|
+
});
|
|
40
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DialogContext.Provider, { value: dialog, children });
|
|
41
|
+
}
|
|
42
|
+
var DialogTrigger = react.forwardRef(
|
|
43
|
+
function DialogTrigger2({ children, className, onClick, ...rest }, ref) {
|
|
44
|
+
const { getTriggerProps } = useDialogContext();
|
|
45
|
+
const propGetterReturn = getTriggerProps();
|
|
46
|
+
const ariaProps = chunkLJK6KK2H_cjs.mapAccessibilityToAria(propGetterReturn.accessibility);
|
|
47
|
+
const handleClick = react.useCallback(
|
|
48
|
+
(event) => {
|
|
49
|
+
propGetterReturn.onAction?.();
|
|
50
|
+
onClick?.(event);
|
|
51
|
+
},
|
|
52
|
+
[propGetterReturn.onAction, onClick]
|
|
53
|
+
);
|
|
54
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
55
|
+
"button",
|
|
56
|
+
{
|
|
57
|
+
ref,
|
|
58
|
+
type: "button",
|
|
59
|
+
...ariaProps,
|
|
60
|
+
...rest,
|
|
61
|
+
className: chunk5DKE5YQD_cjs.cn("entropix-dialog-trigger", className),
|
|
62
|
+
onClick: handleClick,
|
|
63
|
+
children
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
var FOCUSABLE_SELECTOR = [
|
|
69
|
+
"a[href]",
|
|
70
|
+
"button:not([disabled])",
|
|
71
|
+
"input:not([disabled])",
|
|
72
|
+
"select:not([disabled])",
|
|
73
|
+
"textarea:not([disabled])",
|
|
74
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
75
|
+
].join(", ");
|
|
76
|
+
function useFocusTrap(containerRef, isActive) {
|
|
77
|
+
react.useEffect(() => {
|
|
78
|
+
if (!isActive) return;
|
|
79
|
+
const container = containerRef.current;
|
|
80
|
+
if (!container) return;
|
|
81
|
+
const focusableElements = container.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
82
|
+
if (focusableElements.length > 0) {
|
|
83
|
+
focusableElements[0].focus();
|
|
84
|
+
}
|
|
85
|
+
function handleKeyDown(event) {
|
|
86
|
+
if (event.key !== "Tab") return;
|
|
87
|
+
const focusable = container.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
88
|
+
if (focusable.length === 0) return;
|
|
89
|
+
const first = focusable[0];
|
|
90
|
+
const last = focusable[focusable.length - 1];
|
|
91
|
+
if (event.shiftKey) {
|
|
92
|
+
if (document.activeElement === first) {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
last.focus();
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
if (document.activeElement === last) {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
first.focus();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
container.addEventListener("keydown", handleKeyDown);
|
|
104
|
+
return () => {
|
|
105
|
+
container.removeEventListener("keydown", handleKeyDown);
|
|
106
|
+
};
|
|
107
|
+
}, [isActive, containerRef]);
|
|
108
|
+
}
|
|
109
|
+
function useFocusRestore(isActive) {
|
|
110
|
+
const savedElement = react.useRef(null);
|
|
111
|
+
react.useEffect(() => {
|
|
112
|
+
if (isActive) {
|
|
113
|
+
savedElement.current = document.activeElement;
|
|
114
|
+
} else if (savedElement.current) {
|
|
115
|
+
const el = savedElement.current;
|
|
116
|
+
if (el && document.body.contains(el) && typeof el.focus === "function") {
|
|
117
|
+
el.focus();
|
|
118
|
+
}
|
|
119
|
+
savedElement.current = null;
|
|
120
|
+
}
|
|
121
|
+
}, [isActive]);
|
|
122
|
+
}
|
|
123
|
+
var DialogContent = react.forwardRef(
|
|
124
|
+
function DialogContent2({ children, className, onKeyDown: externalOnKeyDown, ...rest }, ref) {
|
|
125
|
+
const { isOpen, close, ids, focusManagement, getContentProps } = useDialogContext();
|
|
126
|
+
const [mounted, setMounted] = react.useState(false);
|
|
127
|
+
react.useEffect(() => {
|
|
128
|
+
setMounted(true);
|
|
129
|
+
}, []);
|
|
130
|
+
const internalRef = react.useRef(null);
|
|
131
|
+
useFocusTrap(internalRef, isOpen && focusManagement.trapFocus);
|
|
132
|
+
useFocusRestore(isOpen && focusManagement.restoreFocus);
|
|
133
|
+
const propGetterReturn = getContentProps();
|
|
134
|
+
const ariaProps = chunkLJK6KK2H_cjs.mapAccessibilityToAria(propGetterReturn.accessibility);
|
|
135
|
+
const actionMap = react.useMemo(() => ({ dismiss: close }), [close]);
|
|
136
|
+
const onKeyDown = chunkLDOP6DVX_cjs.useKeyboardHandler(
|
|
137
|
+
propGetterReturn.keyboardConfig,
|
|
138
|
+
actionMap
|
|
139
|
+
);
|
|
140
|
+
if (!mounted || !isOpen) return null;
|
|
141
|
+
const content = /* @__PURE__ */ jsxRuntime.jsx(
|
|
142
|
+
"div",
|
|
143
|
+
{
|
|
144
|
+
ref: (node) => {
|
|
145
|
+
internalRef.current = node;
|
|
146
|
+
if (typeof ref === "function") {
|
|
147
|
+
ref(node);
|
|
148
|
+
} else if (ref) {
|
|
149
|
+
ref.current = node;
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
id: ids.content,
|
|
153
|
+
...ariaProps,
|
|
154
|
+
...rest,
|
|
155
|
+
className: chunk5DKE5YQD_cjs.cn("entropix-dialog-content", className),
|
|
156
|
+
onKeyDown: onKeyDown ? (event) => {
|
|
157
|
+
onKeyDown(event);
|
|
158
|
+
externalOnKeyDown?.(event);
|
|
159
|
+
} : externalOnKeyDown,
|
|
160
|
+
"data-state": isOpen ? "open" : "closed",
|
|
161
|
+
children
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
return reactDom.createPortal(content, document.body);
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
var DialogTitle = react.forwardRef(
|
|
168
|
+
function DialogTitle2({ children, className, ...rest }, ref) {
|
|
169
|
+
const { ids } = useDialogContext();
|
|
170
|
+
return /* @__PURE__ */ jsxRuntime.jsx("h2", { ref, id: ids.title, ...rest, className: chunk5DKE5YQD_cjs.cn("entropix-dialog-title", className), children });
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
var DialogDescription = react.forwardRef(function DialogDescription2({ children, className, ...rest }, ref) {
|
|
174
|
+
const { ids } = useDialogContext();
|
|
175
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { ref, id: ids.description, ...rest, className: chunk5DKE5YQD_cjs.cn("entropix-dialog-description", className), children });
|
|
176
|
+
});
|
|
177
|
+
var DialogClose = react.forwardRef(
|
|
178
|
+
function DialogClose2({ children, className, onClick, ...rest }, ref) {
|
|
179
|
+
const { getCloseProps } = useDialogContext();
|
|
180
|
+
const propGetterReturn = getCloseProps();
|
|
181
|
+
const ariaProps = chunkLJK6KK2H_cjs.mapAccessibilityToAria(propGetterReturn.accessibility);
|
|
182
|
+
const handleClick = react.useCallback(
|
|
183
|
+
(event) => {
|
|
184
|
+
propGetterReturn.onAction?.();
|
|
185
|
+
onClick?.(event);
|
|
186
|
+
},
|
|
187
|
+
[propGetterReturn.onAction, onClick]
|
|
188
|
+
);
|
|
189
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
190
|
+
"button",
|
|
191
|
+
{
|
|
192
|
+
ref,
|
|
193
|
+
type: "button",
|
|
194
|
+
...ariaProps,
|
|
195
|
+
...rest,
|
|
196
|
+
className: chunk5DKE5YQD_cjs.cn("entropix-dialog-close", className),
|
|
197
|
+
onClick: handleClick,
|
|
198
|
+
children
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
var DialogOverlay = react.forwardRef(
|
|
204
|
+
function DialogOverlay2({ className, onClick, ...rest }, ref) {
|
|
205
|
+
const { isOpen, getOverlayProps } = useDialogContext();
|
|
206
|
+
const propGetterReturn = getOverlayProps();
|
|
207
|
+
const ariaProps = chunkLJK6KK2H_cjs.mapAccessibilityToAria(propGetterReturn.accessibility);
|
|
208
|
+
const handleClick = react.useCallback(
|
|
209
|
+
(event) => {
|
|
210
|
+
propGetterReturn.onAction?.();
|
|
211
|
+
onClick?.(event);
|
|
212
|
+
},
|
|
213
|
+
[propGetterReturn.onAction, onClick]
|
|
214
|
+
);
|
|
215
|
+
if (!isOpen) return null;
|
|
216
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
217
|
+
"div",
|
|
218
|
+
{
|
|
219
|
+
ref,
|
|
220
|
+
...ariaProps,
|
|
221
|
+
...rest,
|
|
222
|
+
className: chunk5DKE5YQD_cjs.cn("entropix-dialog-overlay", className),
|
|
223
|
+
onClick: propGetterReturn.onAction || onClick ? handleClick : void 0,
|
|
224
|
+
"data-state": isOpen ? "open" : "closed"
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
exports.Dialog = Dialog;
|
|
231
|
+
exports.DialogClose = DialogClose;
|
|
232
|
+
exports.DialogContent = DialogContent;
|
|
233
|
+
exports.DialogDescription = DialogDescription;
|
|
234
|
+
exports.DialogOverlay = DialogOverlay;
|
|
235
|
+
exports.DialogTitle = DialogTitle;
|
|
236
|
+
exports.DialogTrigger = DialogTrigger;
|
|
237
|
+
exports.useFocusRestore = useFocusRestore;
|
|
238
|
+
exports.useFocusTrap = useFocusTrap;
|
|
239
|
+
//# sourceMappingURL=chunk-S6DVQAH4.cjs.map
|
|
240
|
+
//# sourceMappingURL=chunk-S6DVQAH4.cjs.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ToggleInner } from './chunk-PILZGMQG.js';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
var Switch = forwardRef(
|
|
6
|
+
function Switch2(props, ref) {
|
|
7
|
+
return /* @__PURE__ */ jsx(ToggleInner, { ...props, ref, role: "switch", componentClass: "entropix-switch" });
|
|
8
|
+
}
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export { Switch };
|
|
12
|
+
//# sourceMappingURL=chunk-U5CZHO6D.js.map
|
|
13
|
+
//# sourceMappingURL=chunk-U5CZHO6D.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { mapAccessibilityToAria } from './chunk-Y2M2LJGJ.js';
|
|
2
|
+
import { cn } from './chunk-6UAQCHIW.js';
|
|
3
|
+
import { forwardRef, useCallback } from 'react';
|
|
4
|
+
import { useInput } from '@entropix/core';
|
|
5
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
var Textarea = forwardRef(
|
|
8
|
+
function Textarea2({
|
|
9
|
+
value,
|
|
10
|
+
defaultValue,
|
|
11
|
+
onChange,
|
|
12
|
+
disabled,
|
|
13
|
+
readOnly,
|
|
14
|
+
required,
|
|
15
|
+
invalid,
|
|
16
|
+
label,
|
|
17
|
+
helperText,
|
|
18
|
+
errorMessage,
|
|
19
|
+
variant = "default",
|
|
20
|
+
size = "md",
|
|
21
|
+
rows,
|
|
22
|
+
resize = "vertical",
|
|
23
|
+
className,
|
|
24
|
+
placeholder,
|
|
25
|
+
name,
|
|
26
|
+
style,
|
|
27
|
+
...rest
|
|
28
|
+
}, ref) {
|
|
29
|
+
const isInvalid = invalid || !!errorMessage;
|
|
30
|
+
const {
|
|
31
|
+
value: inputValue,
|
|
32
|
+
isDisabled,
|
|
33
|
+
isReadOnly,
|
|
34
|
+
isRequired,
|
|
35
|
+
getInputProps,
|
|
36
|
+
getLabelProps,
|
|
37
|
+
getHelperTextProps,
|
|
38
|
+
getErrorMessageProps
|
|
39
|
+
} = useInput({
|
|
40
|
+
value,
|
|
41
|
+
defaultValue,
|
|
42
|
+
onChange,
|
|
43
|
+
disabled,
|
|
44
|
+
readOnly,
|
|
45
|
+
required,
|
|
46
|
+
invalid: isInvalid,
|
|
47
|
+
placeholder,
|
|
48
|
+
name
|
|
49
|
+
});
|
|
50
|
+
const propGetterReturn = getInputProps();
|
|
51
|
+
const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
|
|
52
|
+
const labelProps = getLabelProps();
|
|
53
|
+
const helperProps = getHelperTextProps();
|
|
54
|
+
const errorProps = getErrorMessageProps();
|
|
55
|
+
const handleChange = useCallback(
|
|
56
|
+
(event) => {
|
|
57
|
+
onChange?.(event.target.value);
|
|
58
|
+
},
|
|
59
|
+
[onChange]
|
|
60
|
+
);
|
|
61
|
+
const dataState = isInvalid ? "invalid" : isDisabled ? "disabled" : void 0;
|
|
62
|
+
return /* @__PURE__ */ jsxs(
|
|
63
|
+
"div",
|
|
64
|
+
{
|
|
65
|
+
className: cn("entropix-input-wrapper", className),
|
|
66
|
+
"data-state": dataState,
|
|
67
|
+
"data-variant": variant,
|
|
68
|
+
"data-size": size,
|
|
69
|
+
children: [
|
|
70
|
+
label && /* @__PURE__ */ jsxs(
|
|
71
|
+
"label",
|
|
72
|
+
{
|
|
73
|
+
className: "entropix-input-label",
|
|
74
|
+
id: labelProps.id,
|
|
75
|
+
htmlFor: labelProps.htmlFor,
|
|
76
|
+
children: [
|
|
77
|
+
label,
|
|
78
|
+
isRequired && /* @__PURE__ */ jsx("span", { className: "entropix-input-required", children: "*" })
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
/* @__PURE__ */ jsx(
|
|
83
|
+
"textarea",
|
|
84
|
+
{
|
|
85
|
+
ref,
|
|
86
|
+
className: "entropix-textarea",
|
|
87
|
+
...ariaProps,
|
|
88
|
+
...rest,
|
|
89
|
+
name,
|
|
90
|
+
placeholder,
|
|
91
|
+
value: inputValue,
|
|
92
|
+
onChange: handleChange,
|
|
93
|
+
disabled: isDisabled || void 0,
|
|
94
|
+
readOnly: isReadOnly || void 0,
|
|
95
|
+
rows,
|
|
96
|
+
style: { ...style, resize },
|
|
97
|
+
"data-state": dataState,
|
|
98
|
+
"data-variant": variant,
|
|
99
|
+
"data-size": size
|
|
100
|
+
}
|
|
101
|
+
),
|
|
102
|
+
isInvalid && errorMessage ? /* @__PURE__ */ jsx("span", { className: "entropix-input-error", ...errorProps, children: errorMessage }) : helperText ? /* @__PURE__ */ jsx("span", { className: "entropix-input-helper", ...helperProps, children: helperText }) : null
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
export { Textarea };
|
|
110
|
+
//# sourceMappingURL=chunk-UGCCJI2F.js.map
|
|
111
|
+
//# sourceMappingURL=chunk-UGCCJI2F.js.map
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { useKeyboardHandler } from './chunk-BN57JPKV.js';
|
|
2
|
+
import { mapAccessibilityToAria } from './chunk-Y2M2LJGJ.js';
|
|
3
|
+
import { cn } from './chunk-6UAQCHIW.js';
|
|
4
|
+
import { useDialog } from '@entropix/core';
|
|
5
|
+
import { createContext, forwardRef, useCallback, useState, useEffect, useRef, useMemo, useContext } from 'react';
|
|
6
|
+
import { jsx } from 'react/jsx-runtime';
|
|
7
|
+
import { createPortal } from 'react-dom';
|
|
8
|
+
|
|
9
|
+
var DialogContext = createContext(null);
|
|
10
|
+
function useDialogContext() {
|
|
11
|
+
const context = useContext(DialogContext);
|
|
12
|
+
if (!context) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
"Dialog compound components must be used within a <Dialog> provider."
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return context;
|
|
18
|
+
}
|
|
19
|
+
function Dialog({
|
|
20
|
+
children,
|
|
21
|
+
isOpen,
|
|
22
|
+
defaultOpen,
|
|
23
|
+
onOpenChange,
|
|
24
|
+
closeOnOverlayPress,
|
|
25
|
+
closeOnEscape,
|
|
26
|
+
modal,
|
|
27
|
+
role
|
|
28
|
+
}) {
|
|
29
|
+
const dialog = useDialog({
|
|
30
|
+
isOpen,
|
|
31
|
+
defaultOpen,
|
|
32
|
+
onOpenChange,
|
|
33
|
+
closeOnOverlayPress,
|
|
34
|
+
closeOnEscape,
|
|
35
|
+
modal,
|
|
36
|
+
role
|
|
37
|
+
});
|
|
38
|
+
return /* @__PURE__ */ jsx(DialogContext.Provider, { value: dialog, children });
|
|
39
|
+
}
|
|
40
|
+
var DialogTrigger = forwardRef(
|
|
41
|
+
function DialogTrigger2({ children, className, onClick, ...rest }, ref) {
|
|
42
|
+
const { getTriggerProps } = useDialogContext();
|
|
43
|
+
const propGetterReturn = getTriggerProps();
|
|
44
|
+
const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
|
|
45
|
+
const handleClick = useCallback(
|
|
46
|
+
(event) => {
|
|
47
|
+
propGetterReturn.onAction?.();
|
|
48
|
+
onClick?.(event);
|
|
49
|
+
},
|
|
50
|
+
[propGetterReturn.onAction, onClick]
|
|
51
|
+
);
|
|
52
|
+
return /* @__PURE__ */ jsx(
|
|
53
|
+
"button",
|
|
54
|
+
{
|
|
55
|
+
ref,
|
|
56
|
+
type: "button",
|
|
57
|
+
...ariaProps,
|
|
58
|
+
...rest,
|
|
59
|
+
className: cn("entropix-dialog-trigger", className),
|
|
60
|
+
onClick: handleClick,
|
|
61
|
+
children
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
var FOCUSABLE_SELECTOR = [
|
|
67
|
+
"a[href]",
|
|
68
|
+
"button:not([disabled])",
|
|
69
|
+
"input:not([disabled])",
|
|
70
|
+
"select:not([disabled])",
|
|
71
|
+
"textarea:not([disabled])",
|
|
72
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
73
|
+
].join(", ");
|
|
74
|
+
function useFocusTrap(containerRef, isActive) {
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!isActive) return;
|
|
77
|
+
const container = containerRef.current;
|
|
78
|
+
if (!container) return;
|
|
79
|
+
const focusableElements = container.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
80
|
+
if (focusableElements.length > 0) {
|
|
81
|
+
focusableElements[0].focus();
|
|
82
|
+
}
|
|
83
|
+
function handleKeyDown(event) {
|
|
84
|
+
if (event.key !== "Tab") return;
|
|
85
|
+
const focusable = container.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
86
|
+
if (focusable.length === 0) return;
|
|
87
|
+
const first = focusable[0];
|
|
88
|
+
const last = focusable[focusable.length - 1];
|
|
89
|
+
if (event.shiftKey) {
|
|
90
|
+
if (document.activeElement === first) {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
last.focus();
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
if (document.activeElement === last) {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
first.focus();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
container.addEventListener("keydown", handleKeyDown);
|
|
102
|
+
return () => {
|
|
103
|
+
container.removeEventListener("keydown", handleKeyDown);
|
|
104
|
+
};
|
|
105
|
+
}, [isActive, containerRef]);
|
|
106
|
+
}
|
|
107
|
+
function useFocusRestore(isActive) {
|
|
108
|
+
const savedElement = useRef(null);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (isActive) {
|
|
111
|
+
savedElement.current = document.activeElement;
|
|
112
|
+
} else if (savedElement.current) {
|
|
113
|
+
const el = savedElement.current;
|
|
114
|
+
if (el && document.body.contains(el) && typeof el.focus === "function") {
|
|
115
|
+
el.focus();
|
|
116
|
+
}
|
|
117
|
+
savedElement.current = null;
|
|
118
|
+
}
|
|
119
|
+
}, [isActive]);
|
|
120
|
+
}
|
|
121
|
+
var DialogContent = forwardRef(
|
|
122
|
+
function DialogContent2({ children, className, onKeyDown: externalOnKeyDown, ...rest }, ref) {
|
|
123
|
+
const { isOpen, close, ids, focusManagement, getContentProps } = useDialogContext();
|
|
124
|
+
const [mounted, setMounted] = useState(false);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
setMounted(true);
|
|
127
|
+
}, []);
|
|
128
|
+
const internalRef = useRef(null);
|
|
129
|
+
useFocusTrap(internalRef, isOpen && focusManagement.trapFocus);
|
|
130
|
+
useFocusRestore(isOpen && focusManagement.restoreFocus);
|
|
131
|
+
const propGetterReturn = getContentProps();
|
|
132
|
+
const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
|
|
133
|
+
const actionMap = useMemo(() => ({ dismiss: close }), [close]);
|
|
134
|
+
const onKeyDown = useKeyboardHandler(
|
|
135
|
+
propGetterReturn.keyboardConfig,
|
|
136
|
+
actionMap
|
|
137
|
+
);
|
|
138
|
+
if (!mounted || !isOpen) return null;
|
|
139
|
+
const content = /* @__PURE__ */ jsx(
|
|
140
|
+
"div",
|
|
141
|
+
{
|
|
142
|
+
ref: (node) => {
|
|
143
|
+
internalRef.current = node;
|
|
144
|
+
if (typeof ref === "function") {
|
|
145
|
+
ref(node);
|
|
146
|
+
} else if (ref) {
|
|
147
|
+
ref.current = node;
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
id: ids.content,
|
|
151
|
+
...ariaProps,
|
|
152
|
+
...rest,
|
|
153
|
+
className: cn("entropix-dialog-content", className),
|
|
154
|
+
onKeyDown: onKeyDown ? (event) => {
|
|
155
|
+
onKeyDown(event);
|
|
156
|
+
externalOnKeyDown?.(event);
|
|
157
|
+
} : externalOnKeyDown,
|
|
158
|
+
"data-state": isOpen ? "open" : "closed",
|
|
159
|
+
children
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
return createPortal(content, document.body);
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
var DialogTitle = forwardRef(
|
|
166
|
+
function DialogTitle2({ children, className, ...rest }, ref) {
|
|
167
|
+
const { ids } = useDialogContext();
|
|
168
|
+
return /* @__PURE__ */ jsx("h2", { ref, id: ids.title, ...rest, className: cn("entropix-dialog-title", className), children });
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
var DialogDescription = forwardRef(function DialogDescription2({ children, className, ...rest }, ref) {
|
|
172
|
+
const { ids } = useDialogContext();
|
|
173
|
+
return /* @__PURE__ */ jsx("p", { ref, id: ids.description, ...rest, className: cn("entropix-dialog-description", className), children });
|
|
174
|
+
});
|
|
175
|
+
var DialogClose = forwardRef(
|
|
176
|
+
function DialogClose2({ children, className, onClick, ...rest }, ref) {
|
|
177
|
+
const { getCloseProps } = useDialogContext();
|
|
178
|
+
const propGetterReturn = getCloseProps();
|
|
179
|
+
const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
|
|
180
|
+
const handleClick = useCallback(
|
|
181
|
+
(event) => {
|
|
182
|
+
propGetterReturn.onAction?.();
|
|
183
|
+
onClick?.(event);
|
|
184
|
+
},
|
|
185
|
+
[propGetterReturn.onAction, onClick]
|
|
186
|
+
);
|
|
187
|
+
return /* @__PURE__ */ jsx(
|
|
188
|
+
"button",
|
|
189
|
+
{
|
|
190
|
+
ref,
|
|
191
|
+
type: "button",
|
|
192
|
+
...ariaProps,
|
|
193
|
+
...rest,
|
|
194
|
+
className: cn("entropix-dialog-close", className),
|
|
195
|
+
onClick: handleClick,
|
|
196
|
+
children
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
var DialogOverlay = forwardRef(
|
|
202
|
+
function DialogOverlay2({ className, onClick, ...rest }, ref) {
|
|
203
|
+
const { isOpen, getOverlayProps } = useDialogContext();
|
|
204
|
+
const propGetterReturn = getOverlayProps();
|
|
205
|
+
const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
|
|
206
|
+
const handleClick = useCallback(
|
|
207
|
+
(event) => {
|
|
208
|
+
propGetterReturn.onAction?.();
|
|
209
|
+
onClick?.(event);
|
|
210
|
+
},
|
|
211
|
+
[propGetterReturn.onAction, onClick]
|
|
212
|
+
);
|
|
213
|
+
if (!isOpen) return null;
|
|
214
|
+
return /* @__PURE__ */ jsx(
|
|
215
|
+
"div",
|
|
216
|
+
{
|
|
217
|
+
ref,
|
|
218
|
+
...ariaProps,
|
|
219
|
+
...rest,
|
|
220
|
+
className: cn("entropix-dialog-overlay", className),
|
|
221
|
+
onClick: propGetterReturn.onAction || onClick ? handleClick : void 0,
|
|
222
|
+
"data-state": isOpen ? "open" : "closed"
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogOverlay, DialogTitle, DialogTrigger, useFocusRestore, useFocusTrap };
|
|
229
|
+
//# sourceMappingURL=chunk-W6N4D4N4.js.map
|
|
230
|
+
//# sourceMappingURL=chunk-W6N4D4N4.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/utils/map-accessibility-to-aria.ts
|
|
2
|
+
var ARIA_MAP = {
|
|
3
|
+
role: "role",
|
|
4
|
+
label: "aria-label",
|
|
5
|
+
labelledBy: "aria-labelledby",
|
|
6
|
+
describedBy: "aria-describedby",
|
|
7
|
+
disabled: "aria-disabled",
|
|
8
|
+
expanded: "aria-expanded",
|
|
9
|
+
selected: "aria-selected",
|
|
10
|
+
checked: "aria-checked",
|
|
11
|
+
pressed: "aria-pressed",
|
|
12
|
+
busy: "aria-busy",
|
|
13
|
+
modal: "aria-modal",
|
|
14
|
+
hasPopup: "aria-haspopup",
|
|
15
|
+
controls: "aria-controls",
|
|
16
|
+
owns: "aria-owns",
|
|
17
|
+
live: "aria-live",
|
|
18
|
+
orientation: "aria-orientation",
|
|
19
|
+
tabIndex: "tabIndex",
|
|
20
|
+
hidden: "aria-hidden",
|
|
21
|
+
valueNow: "aria-valuenow",
|
|
22
|
+
valueMin: "aria-valuemin",
|
|
23
|
+
valueMax: "aria-valuemax",
|
|
24
|
+
valueText: "aria-valuetext",
|
|
25
|
+
required: "aria-required",
|
|
26
|
+
invalid: "aria-invalid"
|
|
27
|
+
};
|
|
28
|
+
function mapAccessibilityToAria(props) {
|
|
29
|
+
const result = {};
|
|
30
|
+
for (const [key, attrName] of Object.entries(ARIA_MAP)) {
|
|
31
|
+
const value = props[key];
|
|
32
|
+
if (value !== void 0) {
|
|
33
|
+
result[attrName] = value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { mapAccessibilityToAria };
|
|
40
|
+
//# sourceMappingURL=chunk-Y2M2LJGJ.js.map
|
|
41
|
+
//# sourceMappingURL=chunk-Y2M2LJGJ.js.map
|