@aurora-ds/components 1.5.0 → 1.6.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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ComponentType, SVGProps, ButtonHTMLAttributes, Ref, FC, AnchorHTMLAttributes, ReactNode, HTMLAttributes, CSSProperties, TdHTMLAttributes, ThHTMLAttributes, AriaAttributes, ErrorInfo, Component, FormEvent, InputHTMLAttributes, MouseEvent, AriaRole } from 'react';
2
+ import { ComponentType, SVGProps, ButtonHTMLAttributes, Ref, FC, AnchorHTMLAttributes, ReactNode, HTMLAttributes, CSSProperties, TdHTMLAttributes, ThHTMLAttributes, AriaAttributes, ErrorInfo, Component, FormEvent, InputHTMLAttributes, MouseEvent, AriaRole, RefObject, RefCallback } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  declare const lightPalette: {
@@ -2739,6 +2739,29 @@ declare const Dialog: DialogComponent;
2739
2739
 
2740
2740
  /** Where the menu opens relative to its anchor. */
2741
2741
  type MenuPlacement = 'bottom' | 'right';
2742
+ type UseMenuPositionOptions = {
2743
+ /** Anchor element the menu is positioned relative to. */
2744
+ anchorEl?: HTMLElement | null;
2745
+ /** Whether the menu is currently open. */
2746
+ open: boolean;
2747
+ /** Ref to the menu panel element — used to measure actual dimensions. */
2748
+ menuRef: RefObject<HTMLElement | null>;
2749
+ /** Minimum width override. Defaults to the anchor element's width. */
2750
+ minWidth?: number | string;
2751
+ /** Gap in px between anchor and menu. @default 4 */
2752
+ gap?: number;
2753
+ /**
2754
+ * Where the menu opens relative to the anchor.
2755
+ * - `'bottom'` — opens below the anchor (default dropdown).
2756
+ * - `'right'` — opens beside the anchor (submenu), flipping to the left when there is no room.
2757
+ * @default 'bottom'
2758
+ */
2759
+ placement?: MenuPlacement;
2760
+ };
2761
+ type UseMenuPositionResult = {
2762
+ /** Computed inline style to apply on the menu panel (top, left, minWidth). */
2763
+ style: CSSProperties;
2764
+ };
2742
2765
 
2743
2766
  type MenuProps = {
2744
2767
  /** Whether the menu is visible. */
@@ -2867,9 +2890,211 @@ declare const Menu: MenuComponent;
2867
2890
  */
2868
2891
  declare const Tooltip: FC<TooltipProps>;
2869
2892
 
2893
+ /**
2894
+ * Locks scrolling on `document.body` while `active` is true.
2895
+ *
2896
+ * Preserves the current scroll position and keeps the scrollbar gutter
2897
+ * (`overflow-y: scroll`) to avoid horizontal layout shift when the scrollbar
2898
+ * disappears. The original styles and scroll position are restored on cleanup.
2899
+ *
2900
+ * @example useBodyScrollLock(isDialogOpen)
2901
+ */
2902
+ declare const useBodyScrollLock: (active: boolean) => void;
2903
+
2904
+ type UseControllableStateOptions<T> = {
2905
+ /** Controlled value. When defined, the hook operates in controlled mode. */
2906
+ value?: T;
2907
+ /** Initial value used in uncontrolled mode. */
2908
+ defaultValue: T;
2909
+ /** Called with the next value whenever `setValue` runs. */
2910
+ onChange?: (value: T) => void;
2911
+ };
2912
+ type UseControllableStateResult<T> = [T, (next: T) => void];
2913
+
2914
+ /**
2915
+ * Unifies controlled and uncontrolled value handling.
2916
+ *
2917
+ * - When `value` is provided the hook is controlled: the returned value mirrors
2918
+ * it and internal state is never used to render.
2919
+ * - Otherwise it is uncontrolled: state starts at `defaultValue` and updates
2920
+ * internally.
2921
+ *
2922
+ * In both modes `setValue` calls `onChange` with the next value, so consumers
2923
+ * have a single code path regardless of mode.
2924
+ *
2925
+ * @example
2926
+ * const [value, setValue] = useControllableState({ value, defaultValue: '', onChange })
2927
+ */
2928
+ declare const useControllableState: <T>({ value, defaultValue, onChange, }: UseControllableStateOptions<T>) => UseControllableStateResult<T>;
2929
+
2930
+ /**
2931
+ * Traps Tab / Shift+Tab focus within the element referenced by `containerRef`
2932
+ * while `active` is true. Focusable elements are recomputed on each Tab press
2933
+ * so dynamic content is handled correctly. Required for accessible modals.
2934
+ *
2935
+ * @example useFocusTrap(panelRef, open)
2936
+ */
2937
+ declare const useFocusTrap: (containerRef: RefObject<HTMLElement | null>, active: boolean) => void;
2938
+
2939
+ type KeyPressHandler = (event: KeyboardEvent) => void;
2940
+ /** Map of key name → handler, for handling multiple keys in a single hook call. */
2941
+ type KeyPressMap = Partial<Record<KeyboardEvent['key'], KeyPressHandler>>;
2942
+ type UseKeyPressOptions = {
2943
+ /** Only trigger when this element is the target (defaults to the whole document) */
2944
+ target?: EventTarget | null;
2945
+ /** Whether the listener is active */
2946
+ enabled?: boolean;
2947
+ };
2948
+
2949
+ /**
2950
+ * Listens to keyboard events and dispatches to the matching handler in `keyMap`.
2951
+ * A single hook call can handle multiple keys.
2952
+ *
2953
+ * @example
2954
+ * ` s
2955
+ * useKeyPress(
2956
+ * { ArrowDown: onDown, ArrowUp: onUp, Enter: onEnter, Escape: onClose },
2957
+ * { enabled: isOpen }
2958
+ * )
2959
+ * `
2960
+ */
2961
+ declare const useKeyPress: (keyMap: KeyPressMap, { target, enabled }?: UseKeyPressOptions) => void;
2962
+
2963
+ /**
2964
+ * Merges several refs (callback or object) into a single stable callback ref.
2965
+ *
2966
+ * Useful when a component needs an internal ref while still forwarding the
2967
+ * consumer's `ref`. The returned callback keeps a stable identity across
2968
+ * renders to avoid detach/attach churn, always assigning to the latest refs.
2969
+ *
2970
+ * @example
2971
+ * const inputRef = useRef<HTMLInputElement | null>(null)
2972
+ * const mergedRef = useMergedRefs(ref, inputRef)
2973
+ */
2974
+ declare const useMergedRefs: <T>(...refs: Array<Ref<T> | undefined>) => RefCallback<T>;
2975
+
2976
+ type UseTransitionRenderReturnType = {
2977
+ /** Whether the element should be mounted in the DOM. */
2978
+ isVisible: boolean;
2979
+ /** Whether the fade-in CSS class should be applied. */
2980
+ isFadingIn: boolean;
2981
+ };
2982
+
2983
+ /**
2984
+ * Manages mount/unmount transitions with a two-phase approach (visible → fading-in).
2985
+ *
2986
+ * Opening sequence:
2987
+ * 1. `useLayoutEffect` sets `isVisible=true` synchronously before the browser paints
2988
+ * → element is in the DOM at its initial hidden state on the very first frame.
2989
+ * 2. Double `requestAnimationFrame` in `useEffect` waits for two rendered frames
2990
+ * before setting `isFadingIn=true`, guaranteeing the CSS transition always starts
2991
+ * from the painted hidden state (prevents flickering).
2992
+ *
2993
+ * Closing sequence:
2994
+ * `isFadingIn=false` → CSS transition plays → after `duration` ms → `isVisible=false`.
2995
+ *
2996
+ * @param isOpen - Whether the element should be shown.
2997
+ * @param duration - Transition duration in milliseconds (defaults to `DEFAULT_TRANSITION_DURATION_MS`).
2998
+ */
2999
+ declare const useTransitionRender: (isOpen: boolean, duration?: number) => UseTransitionRenderReturnType;
3000
+
3001
+ type UseListKeyNavOptions = {
3002
+ /** Total number of navigable items. */
3003
+ itemCount: number;
3004
+ /** Whether keyboard navigation is active (menu is open). */
3005
+ enabled: boolean;
3006
+ /** Called with the flat index of the item confirmed via Enter. */
3007
+ onSelect: (index: number) => void;
3008
+ /** Returns true if the item at a given index should be skipped during navigation. */
3009
+ isDisabled?: (index: number) => boolean;
3010
+ /** Whether navigation wraps around at boundaries. @default true */
3011
+ loop?: boolean;
3012
+ /** Index to focus when navigation becomes active. @default 0 */
3013
+ initialIndex?: number;
3014
+ };
3015
+ type UseListKeyNavResult = {
3016
+ /** Currently keyboard-focused item index, or -1 when navigation is inactive. */
3017
+ focusedIndex: number;
3018
+ /** Manually override the focused index. */
3019
+ setFocusedIndex: (index: number) => void;
3020
+ };
3021
+
3022
+ /**
3023
+ * Manages keyboard navigation for a listbox-style menu.
3024
+ *
3025
+ * Binds ArrowDown, ArrowUp, Home, End, and Enter using `useKeyPress`.
3026
+ * Automatically skips disabled items and optionally wraps around (loop).
3027
+ * Resets focus when `enabled` toggles.
3028
+ */
3029
+ declare const useListKeyNav: ({ itemCount, enabled, onSelect, isDisabled, loop, initialIndex, }: UseListKeyNavOptions) => UseListKeyNavResult;
3030
+
3031
+ /**
3032
+ * Computes and continuously updates the `position: fixed` style for a menu panel.
3033
+ *
3034
+ * Positioning strategy:
3035
+ * - `placement="bottom"` (default): the menu opens below the anchor. If it would
3036
+ * overflow the bottom of the viewport, `top` is shifted up so the menu bottom
3037
+ * lands at `viewportHeight - margin` (never going off the top of the screen).
3038
+ * - `placement="right"` (submenu): the menu opens to the right of the anchor and
3039
+ * flips to the left when there is no horizontal room. Its `top` aligns with the
3040
+ * anchor top and is clamped to the viewport.
3041
+ *
3042
+ * Scroll handling: the page scroll is locked while the menu is open (see
3043
+ * `MenuPanel`), so the anchor cannot move out from under the menu. As a safety
3044
+ * net for nested scroll containers, the menu re-positions on scroll/resize so it
3045
+ * always stays attached to its anchor.
3046
+ *
3047
+ * Uses a two-pass strategy: first render with `menuHeight = 0`, then a rAF
3048
+ * recompute with the actual rendered size to apply any overflow offset.
3049
+ */
3050
+ declare const useMenuPosition: ({ anchorEl, open, menuRef, minWidth, gap, placement, }: UseMenuPositionOptions) => UseMenuPositionResult;
3051
+
3052
+ type UseTooltipPositionOptions = {
3053
+ /** Preferred placement of the tooltip relative to its trigger. */
3054
+ placement: TooltipPlacement;
3055
+ };
3056
+ type TooltipPosition = {
3057
+ top: number;
3058
+ left: number;
3059
+ };
3060
+ type UseTooltipPositionResult = {
3061
+ /** Ref to attach to the wrapper element (trigger container). */
3062
+ wrapperRef: RefObject<HTMLDivElement | null>;
3063
+ /** Ref to attach to the tooltip bubble element. */
3064
+ bubbleRef: RefObject<HTMLDivElement | null>;
3065
+ /** Whether the tooltip bubble should be mounted in the DOM. */
3066
+ isVisible: boolean;
3067
+ /** Whether the tooltip has faded in (drives opacity/scale transition). */
3068
+ isFadingIn: boolean;
3069
+ /** Computed fixed position for the tooltip bubble. */
3070
+ position: TooltipPosition;
3071
+ handleMouseEnter: () => void;
3072
+ handleMouseLeave: () => void;
3073
+ handleFocus: () => void;
3074
+ handleBlur: () => void;
3075
+ /** Hides the tooltip immediately (used when hideOnClick=true). */
3076
+ handleClick: () => void;
3077
+ };
3078
+
3079
+ /**
3080
+ * Computes and continuously updates the `position: fixed` coordinates for a
3081
+ * tooltip bubble, clamping it to the viewport on all four sides.
3082
+ *
3083
+ * Positioning strategy (two-pass):
3084
+ * - First pass: mount the bubble at the preferred position.
3085
+ * - Second pass (rAF): read the actual rendered size and clamp all sides.
3086
+ *
3087
+ * Handles:
3088
+ * - All four placements: top, bottom, left, right.
3089
+ * - Screen-edge clamping so the tooltip never overflows any side.
3090
+ * - Fade-in animation (sets `isFadingIn` on next tick to trigger CSS transition).
3091
+ * - Mouse/focus event handlers for show/hide.
3092
+ */
3093
+ declare const useTooltipPosition: ({ placement, }: UseTooltipPositionOptions) => UseTooltipPositionResult;
3094
+
2870
3095
  declare const lightTheme: Theme;
2871
3096
 
2872
3097
  declare const darkTheme: Theme;
2873
3098
 
2874
- export { Accordion, Alert, Article, Aside, Avatar, AvatarGroup, Backdrop, Badge, Box, Breadcrumb, Button, Card, Checkbox, DatePicker, DefaultErrorFallback, Dialog, Drawer, ErrorBoundary, Fab, Footer, Form, Grid, Header, Icon, IconButton, Image, InfoBubble, Link, LoaderScreen, Main, Menu, Nav, Pagination, RadioButton, RadioGroup, Section, Select, Separator, Skeleton, Stack, SvgImage, Switch, Table, Tabs, Text, TextField, ToggleButton, ToggleGroup, ToggleIconButton, Tooltip, darkTheme, lightTheme, useDrawerContext };
2875
- export type { AccordionBodyProps, AccordionProps, AccordionTitleProps, AlertBodyProps, AlertProps, AlertTitleProps, AlertVariant, ArticleProps, AsideProps, AvatarColor, AvatarGroupOverlap, AvatarGroupProps, AvatarProps, AvatarShape, AvatarSize, BackdropProps, BadgeColor, BadgeIcon, BadgeProps, BadgeSize, BadgeVariant, BoxProps, BreadcrumbItemProps, BreadcrumbProps, BreadcrumbSeparator, ButtonColor, ButtonIcon, ButtonProps, ButtonSize, ButtonVariant, CardBodyProps, CardHeaderProps, CardProps, CardVariant, CheckboxProps, DatePickerProps, DatePickerSize, DatePickerStatus, DefaultErrorFallbackProps, DialogBodyProps, DialogHeaderProps, DialogProps, DrawerBodyProps, DrawerFooterProps, DrawerHeaderProps, DrawerItemIcon, DrawerItemProps, DrawerProps, DrawerVariant, ErrorBoundaryFallbackRenderProps, ErrorBoundaryProps, FabColor, FabIcon, FabPlacement, FabProps, FabSize, FooterProps, FormProps, GridProps, GridStyleProps, HeaderProps, IconButtonProps, IconProps, IconStyleParams, ImageProps, InfoBubbleProps, LinkColor, LinkIcon, LinkProps, LinkUnderline, LoaderScreenProps, MainProps, MenuGroupProps, MenuItemProps, MenuItemRole, MenuPlacement, MenuProps, NavProps, PaginationProps, PaginationShape, PaginationSize, Palette, RadioButtonProps, RadioGroupProps, SectionProps, SelectOption, SelectProps, SeparatorOrientation, SeparatorProps, SeparatorStyleParams, SeparatorThickness, SkeletonAnimation, SkeletonProps, SkeletonVariant, StackProps, SvgImageProps, SwitchColor, SwitchProps, SwitchSize, TabItemProps, TableAlign, TableBodyProps, TableCellProps, TableColumn, TableFootProps, TableHeadProps, TableHeaderCellProps, TableLayout, TableProps, TableRowProps, TabsListProps, TabsPanelProps, TabsProps, TextFieldProps, TextFieldSize, TextFieldStatus, TextProps, TextStyleParams, TextVariantStyle, TextVariants, Theme, ToggleButtonProps, ToggleButtonVariant, ToggleGroupProps, ToggleIconButtonProps, TooltipPlacement, TooltipProps, WeekStart };
3099
+ export { Accordion, Alert, Article, Aside, Avatar, AvatarGroup, Backdrop, Badge, Box, Breadcrumb, Button, Card, Checkbox, DatePicker, DefaultErrorFallback, Dialog, Drawer, ErrorBoundary, Fab, Footer, Form, Grid, Header, Icon, IconButton, Image, InfoBubble, Link, LoaderScreen, Main, Menu, Nav, Pagination, RadioButton, RadioGroup, Section, Select, Separator, Skeleton, Stack, SvgImage, Switch, Table, Tabs, Text, TextField, ToggleButton, ToggleGroup, ToggleIconButton, Tooltip, darkTheme, lightTheme, useBodyScrollLock, useControllableState, useDrawerContext, useFocusTrap, useKeyPress, useListKeyNav, useMenuPosition, useMergedRefs, useTooltipPosition, useTransitionRender };
3100
+ export type { AccordionBodyProps, AccordionProps, AccordionTitleProps, AlertBodyProps, AlertProps, AlertTitleProps, AlertVariant, ArticleProps, AsideProps, AvatarColor, AvatarGroupOverlap, AvatarGroupProps, AvatarProps, AvatarShape, AvatarSize, BackdropProps, BadgeColor, BadgeIcon, BadgeProps, BadgeSize, BadgeVariant, BoxProps, BreadcrumbItemProps, BreadcrumbProps, BreadcrumbSeparator, ButtonColor, ButtonIcon, ButtonProps, ButtonSize, ButtonVariant, CardBodyProps, CardHeaderProps, CardProps, CardVariant, CheckboxProps, DatePickerProps, DatePickerSize, DatePickerStatus, DefaultErrorFallbackProps, DialogBodyProps, DialogHeaderProps, DialogProps, DrawerBodyProps, DrawerFooterProps, DrawerHeaderProps, DrawerItemIcon, DrawerItemProps, DrawerProps, DrawerVariant, ErrorBoundaryFallbackRenderProps, ErrorBoundaryProps, FabColor, FabIcon, FabPlacement, FabProps, FabSize, FooterProps, FormProps, GridProps, GridStyleProps, HeaderProps, IconButtonProps, IconProps, IconStyleParams, ImageProps, InfoBubbleProps, KeyPressHandler, KeyPressMap, LinkColor, LinkIcon, LinkProps, LinkUnderline, LoaderScreenProps, MainProps, MenuGroupProps, MenuItemProps, MenuItemRole, MenuPlacement, MenuProps, NavProps, PaginationProps, PaginationShape, PaginationSize, Palette, RadioButtonProps, RadioGroupProps, SectionProps, SelectOption, SelectProps, SeparatorOrientation, SeparatorProps, SeparatorStyleParams, SeparatorThickness, SkeletonAnimation, SkeletonProps, SkeletonVariant, StackProps, SvgImageProps, SwitchColor, SwitchProps, SwitchSize, TabItemProps, TableAlign, TableBodyProps, TableCellProps, TableColumn, TableFootProps, TableHeadProps, TableHeaderCellProps, TableLayout, TableProps, TableRowProps, TabsListProps, TabsPanelProps, TabsProps, TextFieldProps, TextFieldSize, TextFieldStatus, TextProps, TextStyleParams, TextVariantStyle, TextVariants, Theme, ToggleButtonProps, ToggleButtonVariant, ToggleGroupProps, ToggleIconButtonProps, TooltipPlacement, TooltipPosition, TooltipProps, UseControllableStateOptions, UseControllableStateResult, UseKeyPressOptions, UseListKeyNavOptions, UseListKeyNavResult, UseMenuPositionOptions, UseMenuPositionResult, UseTooltipPositionOptions, UseTooltipPositionResult, UseTransitionRenderReturnType, WeekStart };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aurora-ds/components",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
5
  "description": "Aurora DS - React Components Library",
6
6
  "main": "dist/cjs/index.js",