@aurora-ds/components 1.2.0 → 1.4.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/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
2
  import { keyframes, createStyles, useTheme, cx, createVariants, createTheme } from '@aurora-ds/theme';
3
3
  import * as React from 'react';
4
- import { createElement, Fragment, useRef, useState, useCallback, useEffect, useId, isValidElement, cloneElement, useLayoutEffect, useMemo, createContext, useContext } from 'react';
4
+ import { createElement, Fragment, useRef, useState, useCallback, useEffect, useId, isValidElement, cloneElement, useLayoutEffect, useMemo, createContext, useContext, Children } from 'react';
5
5
  import { createPortal } from 'react-dom';
6
6
 
7
7
  function _extends$8() { return _extends$8 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$8.apply(null, arguments); }
@@ -641,36 +641,42 @@ const IconButton = ({ ref, icon: IconComponent, ariaLabel, variant = 'contained'
641
641
  IconButton.displayName = 'IconButton';
642
642
 
643
643
  const LINK_STYLES = createStyles((theme) => ({
644
- root: ({ underline = 'hover' }) => ({
645
- display: 'inline-flex',
646
- alignItems: 'center',
647
- gap: '0.25em',
648
- color: theme.colors.linkMain,
649
- fontFamily: 'inherit',
650
- fontSize: 'inherit',
651
- lineHeight: 'inherit',
652
- fontWeight: 'inherit',
653
- textDecoration: underline === 'always' ? 'underline' : 'none',
654
- cursor: 'pointer',
655
- borderRadius: theme.radius.xs,
656
- transition: `color ${theme.transition.fast}`,
657
- ':hover:not([aria-disabled="true"])': {
658
- color: theme.colors.linkHover,
659
- textDecoration: underline !== 'none' ? 'underline' : 'none',
660
- },
661
- ':active:not([aria-disabled="true"])': {
662
- color: theme.colors.linkActive,
663
- },
664
- ':focus-visible': {
665
- outline: `2px solid ${theme.colors.linkMain}`,
666
- outlineOffset: '2px',
667
- },
668
- '&[aria-disabled="true"]': {
669
- color: theme.colors.linkDisabled,
670
- cursor: 'not-allowed',
671
- textDecoration: 'none',
672
- },
673
- }),
644
+ root: ({ underline = 'hover', color = 'default' }) => {
645
+ const mainColor = color === 'secondary' ? theme.colors.textSecondary : theme.colors.linkMain;
646
+ const hoverColor = color === 'secondary' ? theme.colors.textTertiary : theme.colors.linkHover;
647
+ const activeColor = color === 'secondary' ? theme.colors.textPrimary : theme.colors.linkActive;
648
+ const disabledColor = color === 'secondary' ? theme.colors.textDisabled : theme.colors.linkDisabled;
649
+ return {
650
+ display: 'inline-flex',
651
+ alignItems: 'center',
652
+ gap: '0.25em',
653
+ color: mainColor,
654
+ fontFamily: 'inherit',
655
+ fontSize: 'inherit',
656
+ lineHeight: 'inherit',
657
+ fontWeight: 'inherit',
658
+ textDecoration: underline === 'always' ? 'underline' : 'none',
659
+ cursor: 'pointer',
660
+ borderRadius: theme.radius.xs,
661
+ transition: `color ${theme.transition.fast}`,
662
+ ':hover:not([aria-disabled="true"])': {
663
+ color: hoverColor,
664
+ textDecoration: underline !== 'none' ? 'underline' : 'none',
665
+ },
666
+ ':active:not([aria-disabled="true"])': {
667
+ color: activeColor,
668
+ },
669
+ ':focus-visible': {
670
+ outline: `2px solid ${mainColor}`,
671
+ outlineOffset: '2px',
672
+ },
673
+ '&[aria-disabled="true"]': {
674
+ color: disabledColor,
675
+ cursor: 'not-allowed',
676
+ textDecoration: 'none',
677
+ },
678
+ };
679
+ },
674
680
  icon: {
675
681
  display: 'inline-flex',
676
682
  alignItems: 'center',
@@ -693,7 +699,7 @@ const LINK_STYLES = createStyles((theme) => ({
693
699
  * @example <Link href='/terms' underline='none'>Terms</Link>
694
700
  * @example <Link onClick={() => navigate('/about')}>About (SPA)</Link>
695
701
  */
696
- const Link = ({ ref, underline = 'hover', external = false, disabled = false, startIcon: StartIcon, endIcon: EndIcon, children, className, href, onClick, onKeyDown, ...rest }) => {
702
+ const Link = ({ ref, underline = 'hover', color = 'default', external = false, disabled = false, startIcon: StartIcon, endIcon: EndIcon, children, className, href, onClick, onKeyDown, ...rest }) => {
697
703
  // An <a> without href has no implicit ARIA role and is not focusable.
698
704
  // When used for SPA navigation (onClick only), we restore both behaviours.
699
705
  const hasHref = !!href;
@@ -714,7 +720,7 @@ const Link = ({ ref, underline = 'hover', external = false, disabled = false, st
714
720
  }
715
721
  onKeyDown?.(e);
716
722
  };
717
- return (jsxs("a", { ref: ref, href: href, className: cx(LINK_STYLES.root({ underline }), className), "aria-disabled": disabled || undefined,
723
+ return (jsxs("a", { ref: ref, href: href, className: cx(LINK_STYLES.root({ underline, color }), className), "aria-disabled": disabled || undefined,
718
724
  // Without href: must be explicitly put in the tab order.
719
725
  // With href: the browser handles focusability natively (no tabIndex needed).
720
726
  tabIndex: disabled ? -1 : (!hasHref ? 0 : undefined),
@@ -1990,7 +1996,15 @@ const useMenu = ({ open, onClose, anchorEl, minWidth }) => {
1990
1996
  setFocusedIndex(count - 1);
1991
1997
  }
1992
1998
  },
1993
- Enter: () => {
1999
+ Enter: (e) => {
2000
+ e.preventDefault();
2001
+ const options = getOptions();
2002
+ if (focusedIndex >= 0) {
2003
+ options[focusedIndex]?.click();
2004
+ }
2005
+ },
2006
+ ' ': (e) => {
2007
+ e.preventDefault();
1994
2008
  const options = getOptions();
1995
2009
  if (focusedIndex >= 0) {
1996
2010
  options[focusedIndex]?.click();
@@ -2553,6 +2567,78 @@ const Grid = ({ display = 'grid', columns, rows, autoFlow, autoColumns, autoRows
2553
2567
  };
2554
2568
  Grid.displayName = 'Grid';
2555
2569
 
2570
+ const BREADCRUMB_STYLES = createStyles((_theme) => ({
2571
+ nav: {
2572
+ display: 'block',
2573
+ },
2574
+ list: {
2575
+ display: 'flex',
2576
+ flexWrap: 'wrap',
2577
+ alignItems: 'center',
2578
+ listStyle: 'none',
2579
+ margin: 0,
2580
+ padding: 0,
2581
+ },
2582
+ }), { id: 'breadcrumb' });
2583
+
2584
+ const BreadcrumbContext = createContext({
2585
+ separator: '/',
2586
+ });
2587
+ const useBreadcrumbContext = () => useContext(BreadcrumbContext);
2588
+
2589
+ const BREADCRUMB_ITEM_STYLES = createStyles((theme) => ({
2590
+ item: {
2591
+ display: 'inline-flex',
2592
+ alignItems: 'center',
2593
+ fontSize: theme.fontSize.sm,
2594
+ lineHeight: theme.lineHeight.normal,
2595
+ },
2596
+ separator: {
2597
+ display: 'inline-flex',
2598
+ alignItems: 'center',
2599
+ marginLeft: theme.spacing.sm,
2600
+ marginRight: theme.spacing.sm,
2601
+ color: theme.colors.textTertiary,
2602
+ userSelect: 'none',
2603
+ },
2604
+ }), { id: 'breadcrumb-item' });
2605
+
2606
+ const BreadcrumbItem = ({ label, href, onClick, current = false, isFirst = false, }) => {
2607
+ const { separator } = useBreadcrumbContext();
2608
+ return (jsxs("li", { className: BREADCRUMB_ITEM_STYLES.item, "aria-current": current ? 'page' : undefined, children: [!isFirst && (jsx("span", { "aria-hidden": true, className: BREADCRUMB_ITEM_STYLES.separator, children: separator })), current ? (jsx(Text, { variant: 'span', fontWeight: 'semibold', color: 'textPrimary', children: label })) : (jsx(Link, { href: href, onClick: onClick, color: 'secondary', underline: 'hover', children: label }))] }));
2609
+ };
2610
+ BreadcrumbItem.displayName = 'Breadcrumb.Item';
2611
+
2612
+ /**
2613
+ * WAI-ARIA compliant breadcrumb navigation using a compound component API.
2614
+ *
2615
+ * ```tsx
2616
+ * <Breadcrumb separator='/'>
2617
+ * <Breadcrumb.Item label='Home' href='/' />
2618
+ * <Breadcrumb.Item label='Products' href='/products' />
2619
+ * <Breadcrumb.Item label='Laptop Pro X' current />
2620
+ * </Breadcrumb>
2621
+ * ```
2622
+ *
2623
+ * The last item is typically marked as `current` — it renders as bold text (non-clickable)
2624
+ * and exposes `aria-current="page"` for assistive technologies.
2625
+ */
2626
+ const BreadcrumbBase = ({ children, separator = '/', ariaLabel = 'Breadcrumb', }) => {
2627
+ const contextValue = useMemo(() => ({ separator }), [separator]);
2628
+ const items = Children.map(children, (child, index) => {
2629
+ if (!isValidElement(child)) {
2630
+ return child;
2631
+ }
2632
+ return cloneElement(child, {
2633
+ isFirst: index === 0,
2634
+ });
2635
+ });
2636
+ return (jsx(BreadcrumbContext.Provider, { value: contextValue, children: jsx("nav", { "aria-label": ariaLabel, className: BREADCRUMB_STYLES.nav, children: jsx("ol", { className: BREADCRUMB_STYLES.list, children: items }) }) }));
2637
+ };
2638
+ BreadcrumbBase.displayName = 'Breadcrumb';
2639
+ const Breadcrumb = BreadcrumbBase;
2640
+ Breadcrumb.Item = BreadcrumbItem;
2641
+
2556
2642
  const DrawerContext = createContext({
2557
2643
  isExpanded: true,
2558
2644
  });
@@ -2908,6 +2994,234 @@ Drawer.Body = DrawerBody;
2908
2994
  Drawer.Footer = DrawerFooter;
2909
2995
  Drawer.Item = DrawerItem;
2910
2996
 
2997
+ const TABS_LIST_STYLES = createStyles(() => ({
2998
+ root: {
2999
+ display: 'flex',
3000
+ flexDirection: 'row',
3001
+ alignItems: 'center',
3002
+ overflowX: 'auto',
3003
+ scrollbarWidth: 'none',
3004
+ width: 'fit-content',
3005
+ '::-webkit-scrollbar': { display: 'none' },
3006
+ },
3007
+ }));
3008
+
3009
+ const TabsContext = createContext(null);
3010
+
3011
+ /**
3012
+ * Internal hook — consumes the Tabs context and throws if used outside a `<Tabs>` provider.
3013
+ * @internal
3014
+ */
3015
+ const useTabsContext = () => {
3016
+ const ctx = useContext(TabsContext);
3017
+ if (!ctx) {
3018
+ throw new Error('This component must be used inside a <Tabs> provider.');
3019
+ }
3020
+ return ctx;
3021
+ };
3022
+
3023
+ const TabsList = ({ children, ariaLabel, ariaLabelledBy }) => {
3024
+ const { value, setValue, baseId, getTabValues } = useTabsContext();
3025
+ /**
3026
+ * Returns true if the tab at the given index is aria-disabled.
3027
+ * We check the DOM attribute because disabled state lives in TabItem,
3028
+ * not in the shared context, and we want to avoid adding it to the context.
3029
+ */
3030
+ const isTabDisabled = (tabValue) => {
3031
+ const el = document.getElementById(`${baseId}-tab-${tabValue}`);
3032
+ return el?.getAttribute('aria-disabled') === 'true';
3033
+ };
3034
+ /**
3035
+ * Moves focus to the nearest non-disabled tab starting from `startIndex`
3036
+ * and stepping in the given `direction` (+1 = right, -1 = left).
3037
+ * Stops after a full loop if all tabs are disabled.
3038
+ */
3039
+ const focusNextEnabled = (startIndex, direction) => {
3040
+ const values = getTabValues();
3041
+ for (let i = 1; i <= values.length; i++) {
3042
+ const index = (startIndex + direction * i + values.length) % values.length;
3043
+ const nextValue = values[index];
3044
+ if (!isTabDisabled(nextValue)) {
3045
+ document.getElementById(`${baseId}-tab-${nextValue}`)?.focus();
3046
+ setValue(nextValue);
3047
+ return;
3048
+ }
3049
+ }
3050
+ };
3051
+ const handleKeyDown = (event) => {
3052
+ const values = getTabValues();
3053
+ const currentIndex = values.indexOf(value);
3054
+ if (currentIndex === -1) {
3055
+ return;
3056
+ }
3057
+ switch (event.key) {
3058
+ case 'ArrowRight':
3059
+ event.preventDefault();
3060
+ focusNextEnabled(currentIndex, 1);
3061
+ break;
3062
+ case 'ArrowLeft':
3063
+ event.preventDefault();
3064
+ focusNextEnabled(currentIndex, -1);
3065
+ break;
3066
+ case 'Home': {
3067
+ event.preventDefault();
3068
+ // Focus the first non-disabled tab
3069
+ const firstIdx = values.findIndex((v) => !isTabDisabled(v));
3070
+ if (firstIdx !== -1) {
3071
+ document.getElementById(`${baseId}-tab-${values[firstIdx]}`)?.focus();
3072
+ setValue(values[firstIdx]);
3073
+ }
3074
+ break;
3075
+ }
3076
+ case 'End': {
3077
+ event.preventDefault();
3078
+ // Focus the last non-disabled tab
3079
+ const lastIdx = [...values].reverse().findIndex((v) => !isTabDisabled(v));
3080
+ if (lastIdx !== -1) {
3081
+ const realIndex = values.length - 1 - lastIdx;
3082
+ document.getElementById(`${baseId}-tab-${values[realIndex]}`)?.focus();
3083
+ setValue(values[realIndex]);
3084
+ }
3085
+ break;
3086
+ }
3087
+ }
3088
+ };
3089
+ return (jsx("div", { role: 'tablist', "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, className: TABS_LIST_STYLES.root, onKeyDown: handleKeyDown, children: children }));
3090
+ };
3091
+ TabsList.displayName = 'Tabs.List';
3092
+
3093
+ const TABS_PANEL_STYLES = createStyles(() => ({
3094
+ root: {
3095
+ width: '100%',
3096
+ },
3097
+ }));
3098
+
3099
+ const TabsPanel = ({ value, children, keepMounted = false }) => {
3100
+ const { value: activeValue, baseId } = useTabsContext();
3101
+ const isActive = activeValue === value;
3102
+ if (!isActive && !keepMounted) {
3103
+ return null;
3104
+ }
3105
+ return (jsx("div", { role: 'tabpanel', id: `${baseId}-panel-${value}`, "aria-labelledby": `${baseId}-tab-${value}`,
3106
+ // WAI-ARIA APG: tabIndex={0} allows keyboard scrolling when the panel has no focusable child.
3107
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
3108
+ tabIndex: 0, hidden: !isActive, className: TABS_PANEL_STYLES.root, children: children }));
3109
+ };
3110
+ TabsPanel.displayName = 'Tabs.Panel';
3111
+
3112
+ const TAB_ITEM_STYLES = createStyles((theme) => ({
3113
+ root: ({ isActive, disabled }) => ({
3114
+ display: 'inline-flex',
3115
+ alignItems: 'center',
3116
+ justifyContent: 'center',
3117
+ boxSizing: 'border-box',
3118
+ paddingTop: theme.spacing.xs,
3119
+ paddingBottom: theme.spacing.xs,
3120
+ paddingLeft: theme.spacing.md,
3121
+ paddingRight: theme.spacing.md,
3122
+ border: 'none',
3123
+ borderBottom: `2px solid ${isActive ? theme.colors.primaryMain : 'transparent'}`,
3124
+ background: 'transparent',
3125
+ cursor: disabled ? 'not-allowed' : 'pointer',
3126
+ fontFamily: 'inherit',
3127
+ whiteSpace: 'nowrap',
3128
+ transition: `border-color ${theme.transition.fast}`,
3129
+ ...(disabled ? {} : {
3130
+ ':hover': {
3131
+ borderBottomColor: isActive ? theme.colors.primaryMain : theme.colors.textTertiary,
3132
+ },
3133
+ }),
3134
+ ':focus-visible': {
3135
+ outline: `2px solid ${theme.colors.primaryMain}`,
3136
+ outlineOffset: '2px',
3137
+ },
3138
+ }),
3139
+ }));
3140
+
3141
+ /**
3142
+ * Handles tab registration, active state derivation and interaction props
3143
+ * for a single `Tabs.Tab` (TabItem) button.
3144
+ *
3145
+ * Registers the tab value into the shared ordered registry on mount so that
3146
+ * `TabsList` can perform correct ArrowLeft/Right/Home/End keyboard navigation.
3147
+ */
3148
+ const useTabItem = ({ value, disabled }) => {
3149
+ const { value: activeValue, setValue, baseId, registerTab } = useTabsContext();
3150
+ // Maintains the ordered tab registry used by TabsList for keyboard navigation.
3151
+ useEffect(() => registerTab(value), [registerTab, value]);
3152
+ const isActive = activeValue === value;
3153
+ return {
3154
+ isActive,
3155
+ buttonProps: {
3156
+ id: `${baseId}-tab-${value}`,
3157
+ 'aria-selected': isActive,
3158
+ 'aria-controls': `${baseId}-panel-${value}`,
3159
+ 'aria-disabled': disabled || undefined,
3160
+ tabIndex: isActive ? 0 : -1,
3161
+ onClick: () => {
3162
+ if (!disabled) {
3163
+ setValue(value);
3164
+ }
3165
+ },
3166
+ },
3167
+ };
3168
+ };
3169
+
3170
+ const TabItem = ({ value, label, disabled = false }) => {
3171
+ const { isActive, buttonProps } = useTabItem({ value, disabled });
3172
+ return (jsx("button", { type: 'button', role: 'tab', className: TAB_ITEM_STYLES.root({ isActive, disabled }), ...buttonProps, children: jsx(Text, { variant: 'span', fontSize: 'sm', fontWeight: isActive ? 'semibold' : 'medium', color: disabled ? 'textDisabled' : isActive ? 'textPrimary' : 'textSecondary', children: label }) }));
3173
+ };
3174
+ TabItem.displayName = 'Tabs.Tab';
3175
+
3176
+ /**
3177
+ * WAI-ARIA compliant tab interface using a compound component API.
3178
+ *
3179
+ * ```tsx
3180
+ * <Tabs defaultValue={'active'} onChange={handleChange}>
3181
+ * <Tabs.List ariaLabel={'Subscriptions'}>
3182
+ * <Tabs.Tab value={'active'} label={'Active'} />
3183
+ * <Tabs.Tab value={'cancelled'} label={'Cancelled'} />
3184
+ * </Tabs.List>
3185
+ * <Tabs.Panel value={'active'}>...</Tabs.Panel>
3186
+ * <Tabs.Panel value={'cancelled'}>...</Tabs.Panel>
3187
+ * </Tabs>
3188
+ * ```
3189
+ *
3190
+ * Supports controlled (`value` + `onChange`) and uncontrolled (`defaultValue`) modes.
3191
+ * Keyboard navigation: `ArrowLeft/Right`, `Home`, `End`.
3192
+ * Only the active panel is mounted — use `keepMounted` on `Tabs.Panel` to preserve state across switches.
3193
+ */
3194
+ const TabsBase = ({ children, value: controlledValue, defaultValue, onChange, id, }) => {
3195
+ const reactId = useId();
3196
+ const baseId = id ?? `tabs-${reactId}`;
3197
+ const [internalValue, setInternalValue] = useState(defaultValue ?? '');
3198
+ const isControlled = controlledValue !== undefined;
3199
+ const value = isControlled ? controlledValue : internalValue;
3200
+ const tabsRef = useRef([]);
3201
+ const registerTab = useCallback((tabValue) => {
3202
+ if (!tabsRef.current.includes(tabValue)) {
3203
+ tabsRef.current.push(tabValue);
3204
+ }
3205
+ return () => {
3206
+ tabsRef.current = tabsRef.current.filter((v) => v !== tabValue);
3207
+ };
3208
+ }, []);
3209
+ const getTabValues = useCallback(() => tabsRef.current, []);
3210
+ const setValue = useCallback((next) => {
3211
+ if (!isControlled) {
3212
+ setInternalValue(next);
3213
+ }
3214
+ onChange?.(next);
3215
+ }, [isControlled, onChange]);
3216
+ const contextValue = useMemo(() => ({ value, setValue, baseId, registerTab, getTabValues }), [value, setValue, baseId, registerTab, getTabValues]);
3217
+ return (jsx(TabsContext.Provider, { value: contextValue, children: children }));
3218
+ };
3219
+ TabsBase.displayName = 'Tabs';
3220
+ const Tabs = TabsBase;
3221
+ Tabs.List = TabsList;
3222
+ Tabs.Tab = TabItem;
3223
+ Tabs.Panel = TabsPanel;
3224
+
2911
3225
  const AlertContext = createContext({
2912
3226
  variant: 'default',
2913
3227
  accentColor: 'defaultActive',
@@ -3576,5 +3890,5 @@ const darkTheme = createTheme({
3576
3890
  breakpoints: themeBreakpoints,
3577
3891
  });
3578
3892
 
3579
- export { Alert, Backdrop, Badge, Box, Button, Card, Checkbox, Dialog, Drawer, Form, Grid, Icon, IconButton, InfoBubble, Link, Menu, Select, Skeleton, Stack, Switch, Text, TextField, Tooltip, darkTheme, lightTheme, useDrawerContext };
3893
+ export { Alert, Backdrop, Badge, Box, Breadcrumb, Button, Card, Checkbox, Dialog, Drawer, Form, Grid, Icon, IconButton, InfoBubble, Link, Menu, Select, Skeleton, Stack, Switch, Tabs, Text, TextField, Tooltip, darkTheme, lightTheme, useDrawerContext };
3580
3894
  //# sourceMappingURL=index.js.map