@structyl/core 1.0.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.
@@ -0,0 +1,282 @@
1
+ import * as React from 'react';
2
+ import { Strategy } from '@floating-ui/react';
3
+
4
+ declare const NODES: readonly ["a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "span", "svg", "ul"];
5
+ type PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {
6
+ asChild?: boolean;
7
+ };
8
+ type Primitives = {
9
+ [E in (typeof NODES)[number]]: PrimitiveForwardRefComponent<E>;
10
+ };
11
+ type PrimitiveForwardRefComponent<E extends React.ElementType> = React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>>;
12
+ declare const Primitive: Primitives;
13
+
14
+ interface SlotProps extends React.HTMLAttributes<HTMLElement> {
15
+ children?: React.ReactNode;
16
+ }
17
+ /**
18
+ * Renders a copy of its child element with merged props.
19
+ * Powers the `asChild` pattern across the library.
20
+ */
21
+ declare const Slot: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
22
+ declare const Slottable: ({ children }: {
23
+ children: React.ReactNode;
24
+ }) => React.JSX.Element;
25
+
26
+ type Scope<C = unknown> = {
27
+ [scopeName: string]: React.Context<C>[];
28
+ } | undefined;
29
+ type ScopeHook = (scope: Scope) => {
30
+ [__scopeProp: string]: Scope;
31
+ };
32
+ interface CreateScope {
33
+ scopeName: string;
34
+ (): ScopeHook;
35
+ }
36
+ /**
37
+ * Create a typed context with a sensible error when used outside its Provider.
38
+ *
39
+ * @example
40
+ * const [DialogProvider, useDialogContext] = createContext<DialogContextValue>('Dialog');
41
+ */
42
+ declare function createContext<ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType): readonly [
43
+ React.FC<ContextValueType & {
44
+ children: React.ReactNode;
45
+ }>,
46
+ (consumerName: string) => ContextValueType
47
+ ];
48
+ /**
49
+ * Create a scoped context factory. Solves context leakage when the same
50
+ * component family is nested inside itself (e.g. nested Dialogs, nested Menus)
51
+ * or when two families share an internal primitive (e.g. both use PopperContext).
52
+ *
53
+ * Returns `[createContext, createScope]`:
54
+ * - `createContext` behaves like the simple version above but scoped.
55
+ * - `createScope` is a CreateScope factory consumed by other component families
56
+ * that depend on this one.
57
+ *
58
+ * @example
59
+ * const [createDialogContext, createDialogScope] = createContextScope('Dialog');
60
+ * const [DialogProvider, useDialogContext] = createDialogContext<DialogContextValue>('Dialog');
61
+ *
62
+ * // In Dialog.Root:
63
+ * function Root({ __scopeDialog, ...props }) {
64
+ * const scope = useDialogScope(__scopeDialog);
65
+ * return <DialogProvider {...scope} open={...}>{props.children}</DialogProvider>;
66
+ * }
67
+ */
68
+ declare function createContextScope(scopeName: string, createContextScopeDeps?: CreateScope[]): readonly [
69
+ <ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType) => readonly [
70
+ React.FC<ContextValueType & {
71
+ scope: Scope;
72
+ children: React.ReactNode;
73
+ }>,
74
+ (consumerName: string, scope: Scope) => ContextValueType
75
+ ],
76
+ CreateScope
77
+ ];
78
+ /**
79
+ * Merge multiple CreateScope factories into one. Used internally when a
80
+ * component family depends on another (e.g. DropdownMenu depends on Popper).
81
+ */
82
+ declare function composeContextScopes(...scopes: CreateScope[]): CreateScope;
83
+
84
+ interface PortalProps extends React.ComponentPropsWithoutRef<typeof Primitive.div> {
85
+ /** Element where the portal renders. Defaults to `document.body`. */
86
+ container?: Element | DocumentFragment | null;
87
+ }
88
+ declare const Portal: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<HTMLDivElement>>;
89
+
90
+ type VisuallyHiddenProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;
91
+ declare const VisuallyHidden: React.ForwardRefExoticComponent<Omit<React.ClassAttributes<HTMLSpanElement> & React.HTMLAttributes<HTMLSpanElement> & {
92
+ asChild?: boolean;
93
+ }, "ref"> & React.RefAttributes<HTMLSpanElement>>;
94
+
95
+ type Direction = 'ltr' | 'rtl';
96
+ interface DirectionProviderProps {
97
+ children?: React.ReactNode;
98
+ dir: Direction;
99
+ }
100
+ declare const DirectionProvider: React.FC<DirectionProviderProps>;
101
+ declare function useDirection(localDir?: Direction): Direction;
102
+
103
+ /**
104
+ * Drives an animation-aware presence state machine. When `present` flips from
105
+ * true → false the node remains mounted until a CSS animation or transition
106
+ * completes, allowing exit animations to play.
107
+ */
108
+ declare function usePresence(present: boolean): {
109
+ isPresent: boolean;
110
+ ref: (el: HTMLElement | null) => void;
111
+ };
112
+ interface PresenceProps {
113
+ present: boolean;
114
+ children: React.ReactElement | ((props: {
115
+ present: boolean;
116
+ }) => React.ReactElement);
117
+ /** Force the element to stay mounted regardless of `present`. */
118
+ forceMount?: boolean;
119
+ }
120
+ declare const Presence: React.FC<PresenceProps>;
121
+
122
+ interface FocusScopeProps extends React.ComponentPropsWithoutRef<typeof Primitive.div> {
123
+ /** When true, tabbing from the last focusable wraps to the first. */
124
+ loop?: boolean;
125
+ /** When true, focus cannot leave the scope while it is mounted. */
126
+ trapped?: boolean;
127
+ /** Called when focus moves into the scope. Call `event.preventDefault()` to prevent default. */
128
+ onMountAutoFocus?: (event: Event) => void;
129
+ /** Called when focus is about to leave the scope on unmount. Call `event.preventDefault()` to prevent default restoration. */
130
+ onUnmountAutoFocus?: (event: Event) => void;
131
+ }
132
+ declare const FocusScope: React.ForwardRefExoticComponent<FocusScopeProps & React.RefAttributes<HTMLDivElement>>;
133
+
134
+ /**
135
+ * Inject visually-hidden focusable sentinel elements at the start and end of
136
+ * the document body. When Tab attempts to leave a trapped FocusScope the
137
+ * sentinels catch focus and FocusScope re-enters the scope.
138
+ *
139
+ * Counted singleton — multiple `<FocusGuards />` mounted at once still only
140
+ * inserts one pair of guards.
141
+ */
142
+ declare function useFocusGuards(): void;
143
+ declare const FocusGuards: React.FC<{
144
+ children?: React.ReactNode;
145
+ }>;
146
+
147
+ type PointerDownOutsideEvent = CustomEvent<{
148
+ originalEvent: PointerEvent;
149
+ }>;
150
+ type FocusOutsideEvent = CustomEvent<{
151
+ originalEvent: FocusEvent;
152
+ }>;
153
+ interface DismissableLayerProps extends React.ComponentPropsWithoutRef<typeof Primitive.div> {
154
+ /** When true, hovering outside the layer disables pointer events on outside elements. */
155
+ disableOutsidePointerEvents?: boolean;
156
+ /** Called when Escape is pressed. Call `event.preventDefault()` to cancel dismissal. */
157
+ onEscapeKeyDown?: (event: KeyboardEvent) => void;
158
+ /** Called on pointerdown outside the layer. */
159
+ onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
160
+ /** Called when focus moves outside the layer. */
161
+ onFocusOutside?: (event: FocusOutsideEvent) => void;
162
+ /** Called on any interaction (pointer or focus) outside the layer. */
163
+ onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;
164
+ /** Called when the layer should dismiss. */
165
+ onDismiss?: () => void;
166
+ }
167
+ declare const DismissableLayer: React.ForwardRefExoticComponent<DismissableLayerProps & React.RefAttributes<HTMLDivElement>>;
168
+ interface DismissableLayerBranchProps extends React.ComponentPropsWithoutRef<typeof Primitive.div> {
169
+ }
170
+ declare const DismissableLayerBranch: React.ForwardRefExoticComponent<DismissableLayerBranchProps & React.RefAttributes<HTMLDivElement>>;
171
+
172
+ type Orientation = 'horizontal' | 'vertical';
173
+ interface RovingFocusGroupProps extends React.ComponentPropsWithoutRef<typeof Primitive.div> {
174
+ orientation?: Orientation;
175
+ dir?: Direction;
176
+ loop?: boolean;
177
+ currentTabStopId?: string | null;
178
+ defaultCurrentTabStopId?: string;
179
+ onCurrentTabStopIdChange?: (tabStopId: string | null) => void;
180
+ onEntryFocus?: (event: Event) => void;
181
+ preventScrollOnEntryFocus?: boolean;
182
+ }
183
+ declare const RovingFocusGroup: React.ForwardRefExoticComponent<RovingFocusGroupProps & React.RefAttributes<HTMLDivElement>>;
184
+ interface RovingFocusItemProps extends React.ComponentPropsWithoutRef<typeof Primitive.span> {
185
+ tabStopId?: string;
186
+ focusable?: boolean;
187
+ active?: boolean;
188
+ }
189
+ declare const RovingFocusItem: React.ForwardRefExoticComponent<RovingFocusItemProps & React.RefAttributes<HTMLSpanElement>>;
190
+
191
+ type CollectionElement = HTMLElement;
192
+ type ItemData<I> = {
193
+ ref: React.RefObject<CollectionElement | null>;
194
+ } & I;
195
+ /**
196
+ * Create an ordered collection for tracking child items in DOM order.
197
+ * Used by RovingFocusGroup, Menu, Select, etc. to expose
198
+ * `getItems()` returning items sorted as they appear in the DOM.
199
+ */
200
+ declare function createCollection<I extends Record<string, unknown> = Record<string, unknown>>(name: string): readonly [{
201
+ readonly Provider: React.FC<{
202
+ children?: React.ReactNode;
203
+ }>;
204
+ readonly Slot: React.ForwardRefExoticComponent<{
205
+ children: React.ReactNode;
206
+ } & React.RefAttributes<HTMLElement>>;
207
+ readonly ItemSlot: React.ForwardRefExoticComponent<React.PropsWithoutRef<{
208
+ children: React.ReactNode;
209
+ } & I> & React.RefAttributes<HTMLElement>>;
210
+ }, () => () => Array<ItemData<I>>];
211
+
212
+ interface ArrowProps extends React.ComponentPropsWithoutRef<typeof Primitive.svg> {
213
+ width?: number;
214
+ height?: number;
215
+ }
216
+ /**
217
+ * SVG arrow used by `Popper` (and any tooltip/popover that needs a pointer).
218
+ * Composed via `Popper.Arrow` which positions and rotates this element.
219
+ */
220
+ declare const Arrow: React.ForwardRefExoticComponent<ArrowProps & React.RefAttributes<SVGSVGElement>>;
221
+
222
+ interface AccessibleIconProps {
223
+ /** Visually-hidden label announced to assistive tech. */
224
+ label: string;
225
+ /** The icon element (must be a single React element). */
226
+ children: React.ReactElement;
227
+ }
228
+ /**
229
+ * Wraps an icon element with `aria-hidden` and an adjacent visually-hidden label,
230
+ * so the icon is decorative to sighted users but still announced to screen readers.
231
+ */
232
+ declare const AccessibleIcon: React.FC<AccessibleIconProps>;
233
+
234
+ /**
235
+ * Lock body scroll while mounted. Compensates for scrollbar disappearance
236
+ * to avoid layout shift. Reference-counted so nested usages work.
237
+ */
238
+ declare function useScrollLock(enabled?: boolean): void;
239
+ declare const ScrollLock: React.FC<{
240
+ children?: React.ReactNode;
241
+ enabled?: boolean;
242
+ }>;
243
+
244
+ type Side = 'top' | 'right' | 'bottom' | 'left';
245
+ type Align = 'start' | 'center' | 'end';
246
+ type Sticky = 'partial' | 'always';
247
+ declare const Popper: React.FC<{
248
+ children?: React.ReactNode;
249
+ }>;
250
+ interface PopperAnchorProps extends React.ComponentPropsWithoutRef<typeof Primitive.div> {
251
+ virtualRef?: React.RefObject<{
252
+ getBoundingClientRect: () => DOMRect;
253
+ }>;
254
+ }
255
+ declare const PopperAnchor: React.ForwardRefExoticComponent<PopperAnchorProps & React.RefAttributes<HTMLDivElement>>;
256
+ interface PopperContentProps extends React.ComponentPropsWithoutRef<typeof Primitive.div> {
257
+ side?: Side;
258
+ sideOffset?: number;
259
+ align?: Align;
260
+ alignOffset?: number;
261
+ arrowPadding?: number;
262
+ avoidCollisions?: boolean;
263
+ collisionBoundary?: Element | Element[] | null;
264
+ collisionPadding?: number | Partial<Record<Side, number>>;
265
+ sticky?: Sticky;
266
+ hideWhenDetached?: boolean;
267
+ updatePositionStrategy?: 'always' | 'optimized';
268
+ onPlaced?: () => void;
269
+ strategy?: Strategy;
270
+ }
271
+ declare const PopperContent: React.ForwardRefExoticComponent<PopperContentProps & React.RefAttributes<HTMLDivElement>>;
272
+ declare const PopperArrow: React.ForwardRefExoticComponent<ArrowProps & React.RefAttributes<SVGSVGElement>>;
273
+
274
+ type popper_Align = Align;
275
+ type popper_PopperAnchorProps = PopperAnchorProps;
276
+ type popper_PopperContentProps = PopperContentProps;
277
+ type popper_Side = Side;
278
+ declare namespace popper {
279
+ export { type popper_Align as Align, PopperAnchor as Anchor, PopperArrow as Arrow, PopperContent as Content, type popper_PopperAnchorProps as PopperAnchorProps, type popper_PopperContentProps as PopperContentProps, Popper as Root, type popper_Side as Side };
280
+ }
281
+
282
+ export { AccessibleIcon, type AccessibleIconProps, Arrow, type ArrowProps, type Direction, DirectionProvider, DismissableLayer, DismissableLayerBranch, type DismissableLayerBranchProps, type DismissableLayerProps, FocusGuards, type FocusOutsideEvent, FocusScope, type FocusScopeProps, type Orientation, type PointerDownOutsideEvent, popper as Popper, Portal, type PortalProps, Presence, type PresenceProps, Primitive, type PrimitivePropsWithRef, RovingFocusGroup, type RovingFocusGroupProps, RovingFocusItem, type RovingFocusItemProps, ScrollLock, Slot, type SlotProps, Slottable, VisuallyHidden, type VisuallyHiddenProps, composeContextScopes, createCollection, createContext, createContextScope, useDirection, useFocusGuards, usePresence, useScrollLock };