@entropix/react 0.1.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/dist/index.cjs +817 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +641 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +379 -0
- package/dist/index.d.ts +379 -0
- package/dist/index.js +782 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/accordion.css +67 -0
- package/dist/styles/button.css +133 -0
- package/dist/styles/dialog.css +102 -0
- package/dist/styles/index.css +9 -0
- package/dist/styles/layout.css +125 -0
- package/dist/styles/menu.css +62 -0
- package/dist/styles/switch.css +50 -0
- package/dist/styles/tabs.css +84 -0
- package/dist/styles/toggle.css +45 -0
- package/package.json +84 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { AccessibilityProps, KeyboardHandlerConfig, KeyIntent, UseDialogOptions, UseTabsOptions, UseAccordionOptions, UseMenuOptions } from '@entropix/core';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import react__default from 'react';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Maps platform-neutral AccessibilityProps from @entropix/core
|
|
8
|
+
* to DOM-ready aria-* attributes.
|
|
9
|
+
*
|
|
10
|
+
* Filters out undefined values to keep rendered DOM clean.
|
|
11
|
+
*/
|
|
12
|
+
declare function mapAccessibilityToAria(props: AccessibilityProps): Record<string, unknown>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Converts a core KeyboardHandlerConfig + intent-to-callback map
|
|
16
|
+
* into a React onKeyDown handler.
|
|
17
|
+
*
|
|
18
|
+
* Returns undefined when no keyboardConfig is provided (e.g., disabled state).
|
|
19
|
+
*/
|
|
20
|
+
declare function useKeyboardHandler(keyboardConfig: KeyboardHandlerConfig | undefined, actionMap: Partial<Record<KeyIntent, () => void>>): React.KeyboardEventHandler<HTMLElement> | undefined;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Traps focus within a container element when active.
|
|
24
|
+
*
|
|
25
|
+
* - Tab at the last focusable element wraps to the first
|
|
26
|
+
* - Shift+Tab at the first focusable element wraps to the last
|
|
27
|
+
* - Auto-focuses the first focusable element on activation
|
|
28
|
+
*
|
|
29
|
+
* All DOM access is inside useEffect for SSR safety.
|
|
30
|
+
*/
|
|
31
|
+
declare function useFocusTrap(containerRef: React.RefObject<HTMLElement | null>, isActive: boolean): void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Saves the currently focused element when isActive transitions to true,
|
|
35
|
+
* and restores focus to it when isActive transitions to false.
|
|
36
|
+
*
|
|
37
|
+
* Guards against elements that have been removed from the DOM.
|
|
38
|
+
* All DOM access inside useEffect for SSR safety.
|
|
39
|
+
*/
|
|
40
|
+
declare function useFocusRestore(isActive: boolean): void;
|
|
41
|
+
|
|
42
|
+
interface ButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLElement>, "disabled"> {
|
|
43
|
+
/** Whether the button is disabled */
|
|
44
|
+
disabled?: boolean;
|
|
45
|
+
/** Whether the button is in a loading state */
|
|
46
|
+
loading?: boolean;
|
|
47
|
+
/** Called when the button is activated */
|
|
48
|
+
onPress?: () => void;
|
|
49
|
+
/** Render as a different element type */
|
|
50
|
+
as?: React.ElementType;
|
|
51
|
+
/** Visual variant for CSS targeting via data-variant */
|
|
52
|
+
variant?: string;
|
|
53
|
+
/** Size for CSS targeting via data-size */
|
|
54
|
+
size?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Button component — web adapter for @entropix/core's useButton.
|
|
58
|
+
*
|
|
59
|
+
* Renders a `<button>` by default. Use the `as` prop for other elements.
|
|
60
|
+
* Provides data-state, data-variant, data-size attributes for CSS targeting.
|
|
61
|
+
*/
|
|
62
|
+
declare const Button: react.ForwardRefExoticComponent<ButtonProps & react.RefAttributes<HTMLElement>>;
|
|
63
|
+
|
|
64
|
+
interface ToggleProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onChange" | "disabled"> {
|
|
65
|
+
/** Controlled checked state */
|
|
66
|
+
checked?: boolean;
|
|
67
|
+
/** Default checked state for uncontrolled mode */
|
|
68
|
+
defaultChecked?: boolean;
|
|
69
|
+
/** Called when checked state changes */
|
|
70
|
+
onChange?: (checked: boolean) => void;
|
|
71
|
+
/** Whether the toggle is disabled */
|
|
72
|
+
disabled?: boolean;
|
|
73
|
+
/** Accessible label (if no children) */
|
|
74
|
+
label?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Toggle component — web adapter for @entropix/core's useToggle.
|
|
78
|
+
*
|
|
79
|
+
* Renders a `<button type="button">` with role="checkbox".
|
|
80
|
+
* Use the Switch component for role="switch" semantics.
|
|
81
|
+
* Sets data-state="checked"|"unchecked" for CSS targeting.
|
|
82
|
+
*/
|
|
83
|
+
declare const Toggle: react.ForwardRefExoticComponent<ToggleProps & react.RefAttributes<HTMLButtonElement>>;
|
|
84
|
+
|
|
85
|
+
type SwitchProps = ToggleProps;
|
|
86
|
+
/**
|
|
87
|
+
* Switch component — Toggle with role="switch" semantics.
|
|
88
|
+
*
|
|
89
|
+
* API-identical to Toggle, but renders with `role="switch"`
|
|
90
|
+
* instead of `role="checkbox"`.
|
|
91
|
+
*/
|
|
92
|
+
declare const Switch: react.ForwardRefExoticComponent<ToggleProps & react.RefAttributes<HTMLButtonElement>>;
|
|
93
|
+
|
|
94
|
+
interface DialogProps extends UseDialogOptions {
|
|
95
|
+
children: React.ReactNode;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Dialog root — provides dialog state to compound sub-components.
|
|
99
|
+
* Renders no DOM of its own.
|
|
100
|
+
*/
|
|
101
|
+
declare function Dialog({ children, isOpen, defaultOpen, onOpenChange, closeOnOverlayPress, closeOnEscape, modal, role, }: DialogProps): react_jsx_runtime.JSX.Element;
|
|
102
|
+
|
|
103
|
+
interface DialogTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* DialogTrigger — button that opens/closes the dialog.
|
|
107
|
+
* Maps core's getTriggerProps() to DOM attributes.
|
|
108
|
+
*/
|
|
109
|
+
declare const DialogTrigger: react.ForwardRefExoticComponent<DialogTriggerProps & react.RefAttributes<HTMLButtonElement>>;
|
|
110
|
+
|
|
111
|
+
interface DialogContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* DialogContent — the dialog panel rendered in a portal.
|
|
115
|
+
*
|
|
116
|
+
* Implements focus trap, focus restore, Escape-to-close keyboard handling,
|
|
117
|
+
* and portal rendering. SSR-safe via useEffect mount gating.
|
|
118
|
+
*/
|
|
119
|
+
declare const DialogContent: react.ForwardRefExoticComponent<DialogContentProps & react.RefAttributes<HTMLDivElement>>;
|
|
120
|
+
|
|
121
|
+
interface DialogTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* DialogTitle — heading element with auto-linked ID for aria-labelledby.
|
|
125
|
+
*/
|
|
126
|
+
declare const DialogTitle: react.ForwardRefExoticComponent<DialogTitleProps & react.RefAttributes<HTMLHeadingElement>>;
|
|
127
|
+
|
|
128
|
+
interface DialogDescriptionProps extends React.HTMLAttributes<HTMLParagraphElement> {
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* DialogDescription — paragraph element with auto-linked ID for aria-describedby.
|
|
132
|
+
*/
|
|
133
|
+
declare const DialogDescription: react.ForwardRefExoticComponent<DialogDescriptionProps & react.RefAttributes<HTMLParagraphElement>>;
|
|
134
|
+
|
|
135
|
+
interface DialogCloseProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* DialogClose — button that closes the dialog.
|
|
139
|
+
* Maps core's getCloseProps() to DOM attributes.
|
|
140
|
+
*/
|
|
141
|
+
declare const DialogClose: react.ForwardRefExoticComponent<DialogCloseProps & react.RefAttributes<HTMLButtonElement>>;
|
|
142
|
+
|
|
143
|
+
interface DialogOverlayProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* DialogOverlay — backdrop element behind the dialog.
|
|
147
|
+
* Hidden from the accessibility tree. Optionally closes the dialog on click.
|
|
148
|
+
*/
|
|
149
|
+
declare const DialogOverlay: react.ForwardRefExoticComponent<DialogOverlayProps & react.RefAttributes<HTMLDivElement>>;
|
|
150
|
+
|
|
151
|
+
interface TabsProps extends UseTabsOptions {
|
|
152
|
+
children: react__default.ReactNode;
|
|
153
|
+
className?: string;
|
|
154
|
+
}
|
|
155
|
+
declare function Tabs({ children, className, orientation, activationMode, ...options }: TabsProps): react_jsx_runtime.JSX.Element;
|
|
156
|
+
|
|
157
|
+
interface TabListProps {
|
|
158
|
+
children: react__default.ReactNode;
|
|
159
|
+
className?: string;
|
|
160
|
+
}
|
|
161
|
+
declare function TabList({ children, className }: TabListProps): react_jsx_runtime.JSX.Element;
|
|
162
|
+
|
|
163
|
+
interface TabProps {
|
|
164
|
+
value: string;
|
|
165
|
+
children: react__default.ReactNode;
|
|
166
|
+
className?: string;
|
|
167
|
+
}
|
|
168
|
+
declare function Tab({ value, children, className }: TabProps): react_jsx_runtime.JSX.Element;
|
|
169
|
+
|
|
170
|
+
interface TabPanelProps {
|
|
171
|
+
value: string;
|
|
172
|
+
children: react__default.ReactNode;
|
|
173
|
+
className?: string;
|
|
174
|
+
}
|
|
175
|
+
declare function TabPanel({ value, children, className }: TabPanelProps): react_jsx_runtime.JSX.Element | null;
|
|
176
|
+
|
|
177
|
+
interface AccordionProps extends UseAccordionOptions {
|
|
178
|
+
children: react__default.ReactNode;
|
|
179
|
+
className?: string;
|
|
180
|
+
}
|
|
181
|
+
declare function Accordion({ children, className, ...options }: AccordionProps): react_jsx_runtime.JSX.Element;
|
|
182
|
+
|
|
183
|
+
interface AccordionItemProps {
|
|
184
|
+
value: string;
|
|
185
|
+
children: react__default.ReactNode;
|
|
186
|
+
className?: string;
|
|
187
|
+
}
|
|
188
|
+
declare function AccordionItem({ value, children, className, }: AccordionItemProps): react_jsx_runtime.JSX.Element;
|
|
189
|
+
|
|
190
|
+
interface AccordionTriggerProps {
|
|
191
|
+
children: react__default.ReactNode;
|
|
192
|
+
className?: string;
|
|
193
|
+
}
|
|
194
|
+
declare function AccordionTrigger({ children, className, }: AccordionTriggerProps): react_jsx_runtime.JSX.Element;
|
|
195
|
+
|
|
196
|
+
interface AccordionPanelProps {
|
|
197
|
+
children: react__default.ReactNode;
|
|
198
|
+
className?: string;
|
|
199
|
+
}
|
|
200
|
+
declare function AccordionPanel({ children, className }: AccordionPanelProps): react_jsx_runtime.JSX.Element | null;
|
|
201
|
+
|
|
202
|
+
interface MenuProps extends UseMenuOptions {
|
|
203
|
+
children: react__default.ReactNode;
|
|
204
|
+
}
|
|
205
|
+
declare function Menu({ children, ...options }: MenuProps): react_jsx_runtime.JSX.Element;
|
|
206
|
+
|
|
207
|
+
interface MenuTriggerProps {
|
|
208
|
+
children: react__default.ReactNode;
|
|
209
|
+
className?: string;
|
|
210
|
+
}
|
|
211
|
+
declare function MenuTrigger({ children, className }: MenuTriggerProps): react_jsx_runtime.JSX.Element;
|
|
212
|
+
|
|
213
|
+
interface MenuContentProps {
|
|
214
|
+
children: react__default.ReactNode;
|
|
215
|
+
className?: string;
|
|
216
|
+
}
|
|
217
|
+
declare function MenuContent({ children, className }: MenuContentProps): react_jsx_runtime.JSX.Element | null;
|
|
218
|
+
|
|
219
|
+
interface MenuItemProps {
|
|
220
|
+
index: number;
|
|
221
|
+
onSelect?: () => void;
|
|
222
|
+
disabled?: boolean;
|
|
223
|
+
children: react__default.ReactNode;
|
|
224
|
+
className?: string;
|
|
225
|
+
}
|
|
226
|
+
declare function MenuItem({ index, onSelect, disabled, children, className, }: MenuItemProps): react_jsx_runtime.JSX.Element;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Breakpoint values in pixels, matching @entropix/tokens breakpoint primitives.
|
|
230
|
+
*/
|
|
231
|
+
declare const BREAKPOINTS: {
|
|
232
|
+
readonly sm: 640;
|
|
233
|
+
readonly md: 768;
|
|
234
|
+
readonly lg: 1024;
|
|
235
|
+
readonly xl: 1280;
|
|
236
|
+
readonly "2xl": 1536;
|
|
237
|
+
};
|
|
238
|
+
type Breakpoint = "base" | "sm" | "md" | "lg" | "xl" | "2xl";
|
|
239
|
+
/**
|
|
240
|
+
* Returns the current breakpoint name based on viewport width.
|
|
241
|
+
*
|
|
242
|
+
* - `"base"` — <640px (mobile)
|
|
243
|
+
* - `"sm"` — ≥640px (landscape phones)
|
|
244
|
+
* - `"md"` — ≥768px (tablets)
|
|
245
|
+
* - `"lg"` — ≥1024px (laptops)
|
|
246
|
+
* - `"xl"` — ≥1280px (desktops)
|
|
247
|
+
* - `"2xl"` — ≥1536px (wide screens)
|
|
248
|
+
*
|
|
249
|
+
* ```tsx
|
|
250
|
+
* const breakpoint = useBreakpoint();
|
|
251
|
+
* const isMobile = breakpoint === "base" || breakpoint === "sm";
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
declare function useBreakpoint(): Breakpoint;
|
|
255
|
+
/**
|
|
256
|
+
* Subscribes to a CSS media query and returns whether it matches.
|
|
257
|
+
*
|
|
258
|
+
* ```tsx
|
|
259
|
+
* const isMobile = useMediaQuery("(max-width: 767px)");
|
|
260
|
+
* const prefersDark = useMediaQuery("(prefers-color-scheme: dark)");
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
declare function useMediaQuery(query: string): boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Returns true if the current viewport is at or above the given breakpoint.
|
|
266
|
+
*
|
|
267
|
+
* ```tsx
|
|
268
|
+
* const isDesktop = useBreakpointValue("lg");
|
|
269
|
+
* // true when viewport ≥1024px
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
declare function useBreakpointValue(breakpoint: Exclude<Breakpoint, "base">): boolean;
|
|
273
|
+
|
|
274
|
+
type SpacingSize$1 = "none" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl";
|
|
275
|
+
interface StackProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
276
|
+
/** Gap between children. Default uses --entropix-space-layout-stack token */
|
|
277
|
+
gap?: SpacingSize$1;
|
|
278
|
+
/** Cross-axis alignment */
|
|
279
|
+
align?: "start" | "center" | "end" | "stretch";
|
|
280
|
+
/** Whether to take full width */
|
|
281
|
+
fullWidth?: boolean;
|
|
282
|
+
/** Render as a different element */
|
|
283
|
+
as?: React.ElementType;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Stack — vertical flex layout primitive.
|
|
287
|
+
*
|
|
288
|
+
* Uses the `space.layout.stack` token (16px) as default gap.
|
|
289
|
+
*
|
|
290
|
+
* ```tsx
|
|
291
|
+
* <Stack gap="lg" align="center">
|
|
292
|
+
* <Button>First</Button>
|
|
293
|
+
* <Button>Second</Button>
|
|
294
|
+
* </Stack>
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
declare const Stack: react.ForwardRefExoticComponent<StackProps & react.RefAttributes<HTMLDivElement>>;
|
|
298
|
+
|
|
299
|
+
type SpacingSize = "none" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl";
|
|
300
|
+
interface InlineProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
301
|
+
/** Gap between children. Default uses --entropix-space-layout-inline token */
|
|
302
|
+
gap?: SpacingSize;
|
|
303
|
+
/** Cross-axis alignment */
|
|
304
|
+
align?: "start" | "center" | "end" | "stretch" | "baseline";
|
|
305
|
+
/** Main-axis justification */
|
|
306
|
+
justify?: "start" | "center" | "end" | "between" | "around";
|
|
307
|
+
/** Whether to wrap children */
|
|
308
|
+
wrap?: boolean;
|
|
309
|
+
/** Render as a different element */
|
|
310
|
+
as?: React.ElementType;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Inline — horizontal flex layout primitive.
|
|
314
|
+
*
|
|
315
|
+
* Uses the `space.layout.inline` token (12px) as default gap.
|
|
316
|
+
*
|
|
317
|
+
* ```tsx
|
|
318
|
+
* <Inline gap="sm" justify="between" wrap>
|
|
319
|
+
* <Button variant="primary">Save</Button>
|
|
320
|
+
* <Button variant="ghost">Cancel</Button>
|
|
321
|
+
* </Inline>
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
declare const Inline: react.ForwardRefExoticComponent<InlineProps & react.RefAttributes<HTMLDivElement>>;
|
|
325
|
+
|
|
326
|
+
type ContainerSize = "xs" | "sm" | "md" | "lg" | "xl" | "full";
|
|
327
|
+
interface ContainerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
328
|
+
/** Maximum width constraint. Default: "lg" (1024px) */
|
|
329
|
+
maxWidth?: ContainerSize;
|
|
330
|
+
/** Whether to center children vertically */
|
|
331
|
+
center?: boolean;
|
|
332
|
+
/** Render as a different element */
|
|
333
|
+
as?: React.ElementType;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Container — page-level width constraint with horizontal margins.
|
|
337
|
+
*
|
|
338
|
+
* Uses the `space.layout.page-margin` token (24px) for horizontal padding.
|
|
339
|
+
* Centers itself horizontally via auto margins.
|
|
340
|
+
*
|
|
341
|
+
* ```tsx
|
|
342
|
+
* <Container maxWidth="lg">
|
|
343
|
+
* <Stack gap="xl">
|
|
344
|
+
* <h1>Page Title</h1>
|
|
345
|
+
* <p>Content</p>
|
|
346
|
+
* </Stack>
|
|
347
|
+
* </Container>
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
declare const Container: react.ForwardRefExoticComponent<ContainerProps & react.RefAttributes<HTMLDivElement>>;
|
|
351
|
+
|
|
352
|
+
interface DividerProps extends React.HTMLAttributes<HTMLHRElement> {
|
|
353
|
+
/** Orientation of the divider */
|
|
354
|
+
orientation?: "horizontal" | "vertical";
|
|
355
|
+
/** Spacing above and below (or left and right for vertical) */
|
|
356
|
+
spacing?: "sm" | "md" | "lg";
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Divider — visual separator line.
|
|
360
|
+
*
|
|
361
|
+
* Uses the `color.border.default` token for line color.
|
|
362
|
+
*
|
|
363
|
+
* ```tsx
|
|
364
|
+
* <Stack>
|
|
365
|
+
* <p>Section A</p>
|
|
366
|
+
* <Divider spacing="md" />
|
|
367
|
+
* <p>Section B</p>
|
|
368
|
+
* </Stack>
|
|
369
|
+
*
|
|
370
|
+
* <Inline>
|
|
371
|
+
* <span>Left</span>
|
|
372
|
+
* <Divider orientation="vertical" spacing="sm" />
|
|
373
|
+
* <span>Right</span>
|
|
374
|
+
* </Inline>
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
377
|
+
declare const Divider: react.ForwardRefExoticComponent<DividerProps & react.RefAttributes<HTMLHRElement>>;
|
|
378
|
+
|
|
379
|
+
export { Accordion, AccordionItem, type AccordionItemProps, AccordionPanel, type AccordionPanelProps, type AccordionProps, AccordionTrigger, type AccordionTriggerProps, BREAKPOINTS, type Breakpoint, Button, type ButtonProps, Container, type ContainerProps, type ContainerSize, Dialog, DialogClose, type DialogCloseProps, DialogContent, type DialogContentProps, DialogDescription, type DialogDescriptionProps, DialogOverlay, type DialogOverlayProps, type DialogProps, DialogTitle, type DialogTitleProps, DialogTrigger, type DialogTriggerProps, Divider, type DividerProps, Inline, type InlineProps, Menu, MenuContent, type MenuContentProps, MenuItem, type MenuItemProps, type MenuProps, MenuTrigger, type MenuTriggerProps, type SpacingSize$1 as SpacingSize, Stack, type StackProps, Switch, type SwitchProps, Tab, TabList, type TabListProps, TabPanel, type TabPanelProps, type TabProps, Tabs, type TabsProps, Toggle, type ToggleProps, mapAccessibilityToAria, useBreakpoint, useBreakpointValue, useFocusRestore, useFocusTrap, useKeyboardHandler, useMediaQuery };
|