@ufoui/core 0.0.5 → 0.0.12

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.
Files changed (57) hide show
  1. package/assets/icons.d.ts +3 -0
  2. package/components/accordion/accordion.d.ts +31 -3
  3. package/components/accordion/accordionItem.d.ts +31 -3
  4. package/components/base/boxBase.d.ts +15 -37
  5. package/components/base/buttonBase.d.ts +1 -1
  6. package/components/base/dialogBase.d.ts +9 -7
  7. package/components/base/fieldBase.d.ts +2 -3
  8. package/components/base/textBase.d.ts +1 -2
  9. package/components/breadcrumbs/breadcrumbs.d.ts +48 -0
  10. package/components/calendar/calendar.d.ts +23 -0
  11. package/components/calendar/calendarUtils.d.ts +18 -0
  12. package/components/collapse/collapse.d.ts +15 -20
  13. package/components/dialogs/dialog.d.ts +1 -1
  14. package/components/dialogs/dialogTitle.d.ts +1 -1
  15. package/components/dialogs/drawer.d.ts +1 -1
  16. package/components/fieldset/fieldset.d.ts +1 -1
  17. package/components/link/link.d.ts +58 -0
  18. package/components/list/list.d.ts +1 -1
  19. package/components/rating/rating.d.ts +68 -0
  20. package/components/slider/slider.d.ts +11 -0
  21. package/components/switch/switch.d.ts +1 -9
  22. package/components/toast/toast.d.ts +18 -4
  23. package/components/toast/toastViewport.d.ts +4 -3
  24. package/components/toolbar/toolbar.d.ts +1 -1
  25. package/context/selectionContext.d.ts +18 -17
  26. package/hooks/index.d.ts +3 -1
  27. package/hooks/useAnimate.d.ts +36 -16
  28. package/hooks/useFocusTrap.d.ts +32 -0
  29. package/hooks/useFocusVisible.d.ts +16 -14
  30. package/hooks/useResizeObserver.d.ts +7 -3
  31. package/hooks/useRovingFocus.d.ts +30 -0
  32. package/hooks/useSelection.d.ts +10 -7
  33. package/hooks/useSelectionState.d.ts +29 -0
  34. package/hooks/useSliderKeys.d.ts +41 -0
  35. package/index.css +1 -1
  36. package/index.d.ts +4 -8
  37. package/index.js +4881 -0
  38. package/internal/controlGrid/controlGrid.d.ts +32 -0
  39. package/internal/controlLabel/controlLabel.d.ts +31 -0
  40. package/internal/description/description.d.ts +18 -0
  41. package/internal/index.d.ts +6 -0
  42. package/internal/inlineTooltip/index.d.ts +1 -0
  43. package/internal/inlineTooltip/inlineTooltipManager.d.ts +1 -1
  44. package/internal/slots/slot.d.ts +44 -0
  45. package/internal/stateLayer/stateLayer.d.ts +33 -0
  46. package/package.json +12 -3
  47. package/utils/color.d.ts +0 -102
  48. package/utils/getWrapperStyle.d.ts +53 -0
  49. package/utils/index.d.ts +1 -0
  50. package/utils/toasts/ensureViewport.d.ts +6 -1
  51. package/utils/toasts/toast.d.ts +66 -10
  52. package/utils/toasts/toastStore.d.ts +55 -1
  53. package/utils/utils.d.ts +65 -53
  54. package/hooks/useFocusState.d.ts +0 -16
  55. package/index.mjs +0 -4649
  56. package/internal/inlineTooltip/inlineTooltip.d.ts +0 -11
  57. package/internal/inlineTooltip/inlineTooltip2.d.ts +0 -10
@@ -1,5 +1,5 @@
1
1
  import { default as React, ReactNode } from 'react';
2
- import { BorderColor, ElementAlign, ElementDensity, ElementElevation, ElementFocusEffect, ElementFont, ElementHoverEffect, ElementOutline, ElementPressedEffect, ElementSelectedEffect, ElementShape, ElementSize, ElementTextPlacement, ElementTouchEffect, SemanticColor, SurfaceColor } from '../../utils';
2
+ import { BorderColor, ElementAlign, ElementDensity, ElementElevation, ElementFocusEffect, ElementFont, ElementHoverEffect, ElementOutline, ElementPressedEffect, ElementSelectedEffect, ElementShape, ElementSize, ElementTextPlacement, ElementTouchEffect, SemanticColor } from '../../utils';
3
3
  /**
4
4
  * Props for the Switch component.
5
5
  *
@@ -26,10 +26,6 @@ export interface SwitchProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
26
26
  density?: ElementDensity;
27
27
  /** Supporting text displayed below the label. */
28
28
  description?: string;
29
- /** Text color override for the description. */
30
- descriptionColor?: SurfaceColor;
31
- /** Font token applied to the description text. */
32
- descriptionFont?: ElementFont;
33
29
  /** Elevation level of the control surface. */
34
30
  elevation?: ElementElevation;
35
31
  /** Error message text. Overrides description when present. */
@@ -50,8 +46,6 @@ export interface SwitchProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
50
46
  id?: string;
51
47
  /** Text label associated with the control. */
52
48
  label?: string;
53
- /** Text color override for the label. */
54
- labelColor?: SurfaceColor;
55
49
  /** Name attribute forwarded to the input element. */
56
50
  name?: string;
57
51
  /** Change event handler. */
@@ -66,8 +60,6 @@ export interface SwitchProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
66
60
  shape?: ElementShape;
67
61
  /** Size of the control. */
68
62
  size?: ElementSize;
69
- /** Text color override for label and content. */
70
- textColor?: SurfaceColor;
71
63
  /** Layout of text relative to the control. */
72
64
  textPlacement?: ElementTextPlacement;
73
65
  /** Tooltip alignment relative to the control. */
@@ -1,13 +1,15 @@
1
1
  import { default as React, ReactNode } from 'react';
2
- import { ElementElevation, ElementShape, SurfaceColor } from '../../utils';
2
+ import { ElementElevation, ElementShape, SurfaceColor, ToastStatus } from '../../utils';
3
3
  import { BoxBaseProps } from '../base';
4
- import { ToastStatus } from '../../utils/toasts/toast';
4
+ import { MotionAnimation, MotionStyle } from '../../types';
5
5
  /**
6
6
  * Props for Toast component.
7
7
  *
8
8
  * @category Toast
9
9
  */
10
10
  export interface ToastProps extends Omit<BoxBaseProps, 'children'> {
11
+ /** Toast identifier used for lifecycle control. */
12
+ id: string;
11
13
  /** Primary heading text. */
12
14
  title?: string;
13
15
  /** Secondary supporting text. */
@@ -20,18 +22,30 @@ export interface ToastProps extends Omit<BoxBaseProps, 'children'> {
20
22
  action?: ReactNode;
21
23
  /** Full content override replacing internal layout. */
22
24
  content?: ReactNode;
25
+ /** Time in milliseconds before the toast is automatically dismissed. */
26
+ timeout?: number;
23
27
  /** Elevation token. Default: 3 */
24
28
  elevation?: ElementElevation;
25
29
  /** Status variant applied as CSS modifier class. */
26
30
  status?: ToastStatus;
27
31
  /** Shape token. Default: smooth */
28
32
  shape?: ElementShape;
33
+ /** Animation preset used by internal motion elements. */
34
+ animation?: MotionAnimation;
35
+ /** Animation duration in milliseconds. */
36
+ duration?: number;
37
+ /** Motion style applied to animated elements. */
38
+ motionStyle?: MotionStyle;
39
+ leaving?: boolean;
40
+ onExitComplete?: (id: string) => void;
29
41
  }
30
42
  /**
31
- * Toast overlay container.
43
+ * Toast notification container.
44
+ *
45
+ * Handles auto-dismiss lifecycle using the timeout property.
32
46
  *
33
47
  * @function
34
- * @param props Component props.
48
+ * @param props Component properties.
35
49
  *
36
50
  * @category Toast
37
51
  */
@@ -1,6 +1,7 @@
1
- export type ToastPosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
1
+ export type ToastPosition = 'topLeft' | 'topCenter' | 'topRight' | 'bottomLeft' | 'bottomCenter' | 'bottomRight';
2
2
  export interface ToastViewportProps {
3
3
  position?: ToastPosition;
4
- gap?: number;
4
+ timeout?: number;
5
+ limit?: number;
5
6
  }
6
- export declare const ToastViewport: ({ position, gap, }: ToastViewportProps) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const ToastViewport: ({ position, timeout, limit }: ToastViewportProps) => import("react/jsx-runtime").JSX.Element;
@@ -19,7 +19,7 @@ export interface ToolbarProps extends Omit<BoxBaseProps, 'component' | 'elementC
19
19
  /** Density token. */
20
20
  density?: ElementDensity;
21
21
  /** Makes toolbar full width. */
22
- fullWidth?: boolean;
22
+ wFull?: boolean;
23
23
  /** Positions floating toolbar. */
24
24
  placement?: 'top' | 'bottom' | 'left' | 'right' | 'center';
25
25
  /** Makes floating toolbar fixed. */
@@ -1,31 +1,32 @@
1
+ import { useRovingFocus } from '../hooks/useRovingFocus';
1
2
  /**
2
3
  * Context value shared by components that rely on selection behavior.
3
4
  *
4
- * Provides state and control logic for managing single or multiple
5
- * selected values.
5
+ * @typeParam T - Optional configuration object provided by the parent component.
6
6
  *
7
7
  * @category Contexts
8
8
  */
9
- export interface SelectionContextValue {
10
- /** Currently selected values. */
11
- values: string[];
12
- /** Selection mode: single or multiple. */
13
- mode: 'single' | 'multiple';
14
- /** Toggles selection state for a given value. */
15
- toggle: (value: string) => void;
16
- /** Sets a value directly (primarily for single mode). */
17
- set: (value: string) => void;
9
+ export interface SelectionContextValue<T = unknown> {
18
10
  /** Clears all selected values. */
19
11
  clear: () => void;
12
+ /** Optional configuration object passed from the parent component. */
13
+ config?: T;
14
+ /** Selection type: single or multiple. */
15
+ type: 'single' | 'multiple';
16
+ /** Optional roving focus controller for keyboard navigation between items. */
17
+ roving?: ReturnType<typeof useRovingFocus>;
18
+ /** Sets a value directly. */
19
+ set: (value: string) => void;
20
+ /** Toggles selection state for a given value. */
21
+ toggle: (value: string) => void;
22
+ /** Currently selected values. */
23
+ values: string[];
20
24
  }
21
25
  /**
22
- * SelectionContext provides access to shared selection state.
23
- *
24
- * Used by components such as Accordion, Tabs, RadioGroup,
25
- * and similar patterns that require controlled selection logic.
26
+ * React context that exposes shared selection state and optional configuration.
26
27
  *
27
- * Returns `null` if used outside a provider.
28
+ * Returns `null` when accessed outside of a provider.
28
29
  *
29
30
  * @category Contexts
30
31
  */
31
- export declare const SelectionContext: import('react').Context<SelectionContextValue | null>;
32
+ export declare const SelectionContext: import('react').Context<SelectionContextValue<unknown> | null>;
package/hooks/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  export * from './useAnimate';
2
2
  export * from './useClickOutside';
3
3
  export * from './useEscapeHandler';
4
- export * from './useFocusState';
5
4
  export * from './useFocusVisible';
6
5
  export * from './useResizeObserver';
7
6
  export * from './useSelection';
8
7
  export * from './useTheme';
8
+ export * from './useSliderKeys';
9
+ export * from './useSelectionState';
10
+ export * from './useFocusTrap';
@@ -19,36 +19,56 @@ export interface UseAnimateOptions {
19
19
  * @category Hooks
20
20
  */
21
21
  export interface UseAnimateResult {
22
- /** True while in the opening phase. */
22
+ /** True during the opening phase. */
23
23
  opening: boolean;
24
- /** True while in the closing phase. */
24
+ /** True during the closing phase. */
25
25
  closing: boolean;
26
- /** True while an animation is actively running. */
26
+ /** True when animation is running and not temporarily suppressed. */
27
27
  animating: boolean;
28
- /** True when no animation is active. */
28
+ /** True while animation is in progress (opening or closing). */
29
+ active: boolean;
30
+ /** True only before any animation has started. */
29
31
  idle: boolean;
30
32
  /** CSS variables controlling animation timing and direction. */
31
33
  animationVars: Record<string, string>;
32
- /** Triggers the next animation step or forces open or closed direction. */
34
+ /** Triggers animation towards open or closed state. */
33
35
  animate(next?: 'open' | 'closed'): void;
34
36
  }
35
37
  /**
36
- * Animation state hook supporting automatic, one-shot, and manual step modes.
38
+ * Handles open/close animation with interrupt support.
37
39
  *
38
- * Mode behavior:
39
- * - Automatic mode: when t1 is provided, animate runs a timed open or close sequence.
40
- * - One-shot mode: when enabled, only the opening transition is performed.
41
- * - Manual mode: when t1 is not provided, each animate call advances the phase by one step.
40
+ * Flow:
41
+ * - animate('open') sets phase to "opening" and starts a timer
42
+ * - after t1 phase becomes "open" and timer is cleared
43
+ * - animate('closed') sets phase to "closing" and starts a timer
44
+ * - after t2 → phase becomes "closed" and timer is cleared
42
45
  *
43
- * The hook handles animation interruption by clearing active timers and
44
- * temporarily suppressing visual animation to avoid glitches.
46
+ * Interrupt:
47
+ * - calling animate() during an active transition clears the current timer
48
+ * - a new transition starts immediately
49
+ * - for one render animating = false (reset frame)
45
50
  *
46
- * animationVars return CSS custom properties describing the active phase:
47
- * - --uui-duration defines the duration of the current phase in milliseconds.
48
- * - --uui-reverse indicates whether the animation direction should be reversed.
51
+ * State usage:
52
+ * - opening / closing current transition phase
53
+ * - active true while transition is in progress (used for mount/visibility)
54
+ * - animating → same as active, but disabled during reset frame (used for CSS classes)
55
+ * - idle → true only before the first animation
56
+ *
57
+ * Important:
58
+ * - use `active` to control visibility (mount/unmount)
59
+ * - use `animating` to apply or remove animation classes
60
+ *
61
+ * Timer:
62
+ * - created when transition starts
63
+ * - cleared on completion or interrupt
64
+ *
65
+ * Modes:
66
+ * - t1 defined → automatic timed transitions
67
+ * - t1 undefined → manual stepper (each call advances phase)
68
+ * - oneShot → only opening transition is executed
49
69
  *
50
70
  * @function
51
- * @param options Hook configuration options.
71
+ * @param options Hook configuration options
52
72
  *
53
73
  * @category Hooks
54
74
  */
@@ -0,0 +1,32 @@
1
+ import { RefObject } from 'react';
2
+ /**
3
+ * Options for the useFocusTrap hook.
4
+ *
5
+ * @category Hooks
6
+ */
7
+ export interface UseFocusTrapOptions {
8
+ /** Root element used as focus boundary. */
9
+ ref: RefObject<HTMLElement | null>;
10
+ /** Enables or disables the focus trap. */
11
+ enabled?: boolean;
12
+ /** Moves focus inside on mount when not already inside. */
13
+ autoFocus?: boolean;
14
+ }
15
+ /**
16
+ * Focus trap for modal containers.
17
+ *
18
+ * Keeps keyboard focus inside the given element.
19
+ * Handles Tab loop and restores focus on unmount.
20
+ * Also redirects focus back when returning from outside the document.
21
+ *
22
+ * Behavior:
23
+ * - traps Tab navigation within the root element
24
+ * - moves focus to element with data-autofocus or first focusable on mount
25
+ * - restores previous focus on cleanup
26
+ *
27
+ * @function
28
+ * @param options
29
+ *
30
+ * @category Hooks
31
+ */
32
+ export declare const useFocusTrap: ({ ref, enabled, autoFocus }: UseFocusTrapOptions) => void;
@@ -1,20 +1,22 @@
1
+ import { FocusEventHandler } from 'react';
1
2
  /**
2
- * Determines whether focus indicators (focus rings) should be visible.
3
+ * Tracks focus state and determines whether focus indicators
4
+ * should be visibly rendered.
3
5
  *
4
- * Returns `true` when the user is navigating with the keyboard and `false`
5
- * for pointer-based interactions (mouse, touch, pen).
6
+ * Automatically merges external focus handlers.
6
7
  *
7
- * Internally tracks global interaction modality and mirrors the behavior
8
- * of the `:focus-visible` specification.
9
- *
10
- * @returns `true` if focus should be visibly rendered
11
- *
12
- * @example
13
- * const focusVisible = useFocusVisible();
14
- *
15
- * @example
16
- * <button className={focusVisible ? 'uui-focus-visible' : undefined} />
8
+ * @function useFocusVisible
9
+ * @param onFocus External onFocus handler
10
+ * @param onBlur External onBlur handler
11
+ * @returns Object containing focus flags and merged handlers
17
12
  *
18
13
  * @category Hooks
19
14
  */
20
- export declare function useFocusVisible(): boolean;
15
+ export declare function useFocusVisible(onFocus?: FocusEventHandler<HTMLElement>, onBlur?: FocusEventHandler<HTMLElement>): {
16
+ focusVisible: boolean;
17
+ isFocused: boolean;
18
+ focusHandlers: {
19
+ onFocus: FocusEventHandler<HTMLElement>;
20
+ onBlur: FocusEventHandler<HTMLElement>;
21
+ };
22
+ };
@@ -1,6 +1,6 @@
1
1
  import { RefObject } from 'react';
2
2
  /**
3
- * Size information reported by ResizeObserver.
3
+ * Size information reported by ResizeObserver (CSS pixels).
4
4
  *
5
5
  * @category Hooks
6
6
  */
@@ -12,7 +12,10 @@ export interface ObservedElementSize {
12
12
  }
13
13
  /**
14
14
  * Observes a single DOM element using ResizeObserver
15
- * and invokes a callback when its content box size changes.
15
+ * and invokes a callback when its size changes.
16
+ *
17
+ * Uses the content box by default, or the border box when `borderBox` is true
18
+ * (includes padding and border; excludes margin).
16
19
  *
17
20
  * Does not trigger component re-render.
18
21
  *
@@ -20,7 +23,8 @@ export interface ObservedElementSize {
20
23
  * @param ref Reference to the observed HTMLElement.
21
24
  * @param onResize Called when size changes.
22
25
  * @param enabled Enables or disables observation. Default: true.
26
+ * @param borderBox When true, report border box size; when false, content box. Default: false.
23
27
  *
24
28
  * @category Hooks
25
29
  */
26
- export declare function useResizeObserver<T extends HTMLElement>(ref: RefObject<T>, onResize: (size: ObservedElementSize) => void, enabled?: boolean): void;
30
+ export declare function useResizeObserver<T extends HTMLElement>(ref: RefObject<T>, onResize: (size: ObservedElementSize) => void, enabled?: boolean, borderBox?: boolean): void;
@@ -0,0 +1,30 @@
1
+ import { default as React } from 'react';
2
+ /**
3
+ * Defines the directional axis used for roving focus navigation.
4
+ *
5
+ * @category Hooks
6
+ */
7
+ export type RovingOrientation = 'vertical' | 'horizontal';
8
+ /**
9
+ * Provides roving focus keyboard navigation for a group of elements.
10
+ *
11
+ * Enables Arrow, Home, and End key navigation across registered items
12
+ * using vertical or horizontal orientation.
13
+ *
14
+ * @param orientation Navigation direction. Default: 'vertical'.
15
+ * @param loop Whether focus should wrap around. Default: true.
16
+ *
17
+ * @returns Object containing register, unregister, and onKeyDown handlers.
18
+ *
19
+ * @example
20
+ * const roving = useRovingFocus('vertical');
21
+ *
22
+ * <button ref={roving.register} onKeyDown={roving.onKeyDown} />
23
+ *
24
+ * @category Hooks
25
+ */
26
+ export declare function useRovingFocus(orientation?: RovingOrientation, loop?: boolean): {
27
+ register: (el: HTMLElement | null) => void;
28
+ unregister: (el: HTMLElement | null) => void;
29
+ onKeyDown: (e: React.KeyboardEvent<HTMLElement>) => void;
30
+ };
@@ -1,13 +1,16 @@
1
- import { SelectionContextValue } from '../context/selectionContext';
1
+ import { SelectionContextValue } from '../context';
2
2
  /**
3
- * Hook to access the current selection context.
3
+ * Provides typed access to SelectionContext including selection state,
4
+ * optional configuration, and roving focus controller.
4
5
  *
5
- * Must be used within a component that provides SelectionContext.
6
- * If used outside, it will throw an error.
6
+ * @typeParam T Optional configuration object type provided by the parent.
7
7
  *
8
- * @throws Error if the context is unavailable.
9
- * @returns The current SelectionContextValue.
8
+ * @returns The current selection context value.
9
+ *
10
+ * @example
11
+ * const { values, toggle, config, roving } =
12
+ * useSelection<MyConfig>();
10
13
  *
11
14
  * @category Hooks
12
15
  */
13
- export declare function useSelection(): SelectionContextValue;
16
+ export declare function useSelection<T = unknown>(): SelectionContextValue<T>;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Hook that provides shared selection state logic for components
3
+ * such as Accordion, Tabs or List.
4
+ *
5
+ * Manages selected values, exposes selection helpers and optionally
6
+ * enables roving focus for keyboard navigation.
7
+ *
8
+ * @function
9
+ *
10
+ * @param type Selection type controlling whether one or multiple values can be active.
11
+ * @param orientation Orientation used by roving focus navigation.
12
+ *
13
+ * @returns Object containing selection state, helper functions and roving focus controller.
14
+ *
15
+ * @category Hooks
16
+ */
17
+ export declare function useSelectionState(type: 'single' | 'multiple', orientation?: 'vertical' | 'horizontal'): {
18
+ values: string[];
19
+ toggle: (value: string) => void;
20
+ set: (value: string) => void;
21
+ clear: () => void;
22
+ roving: {
23
+ register: (el: HTMLElement | null) => void;
24
+ unregister: (el: HTMLElement | null) => void;
25
+ onKeyDown: (e: React.KeyboardEvent<HTMLElement>) => void;
26
+ };
27
+ type: "single" | "multiple";
28
+ orientation: "vertical" | "horizontal";
29
+ };
@@ -0,0 +1,41 @@
1
+ import { default as React } from 'react';
2
+ /**
3
+ * Configuration for slider keyboard navigation.
4
+ *
5
+ * @category Hooks
6
+ */
7
+ export interface UseSliderKeysOptions {
8
+ /** Current value. */
9
+ value: number;
10
+ /** Minimum value. */
11
+ min: number;
12
+ /** Maximum value. */
13
+ max: number;
14
+ /** Step applied by arrow keys. */
15
+ step: number;
16
+ /** Disables interaction. */
17
+ disabled?: boolean;
18
+ /** Prevents value changes. */
19
+ readOnly?: boolean;
20
+ /** Called when value changes. */
21
+ onChange: (value: number) => void;
22
+ }
23
+ /**
24
+ * Provides keyboard navigation for slider-like controls.
25
+ *
26
+ * Supports Arrow, Home and End keys to change the value.
27
+ *
28
+ * @param options Slider keyboard configuration.
29
+ *
30
+ * @returns Object containing onKeyDown handler.
31
+ *
32
+ * @example
33
+ * const keys = useSliderKeys({ value, min: 0, max: 5, step: 0.5, onChange });
34
+ *
35
+ * <div role="slider" onKeyDown={keys.onKeyDown} />
36
+ *
37
+ * @category Hooks
38
+ */
39
+ export declare function useSliderKeys({ value, min, max, step, disabled, readOnly, onChange }: UseSliderKeysOptions): {
40
+ onKeyDown: (e: React.KeyboardEvent<HTMLElement>) => void;
41
+ };