@aurora-ds/components 1.2.0 → 1.4.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/cjs/index.js CHANGED
@@ -661,36 +661,42 @@ const IconButton = ({ ref, icon: IconComponent, ariaLabel, variant = 'contained'
661
661
  IconButton.displayName = 'IconButton';
662
662
 
663
663
  const LINK_STYLES = theme.createStyles((theme) => ({
664
- root: ({ underline = 'hover' }) => ({
665
- display: 'inline-flex',
666
- alignItems: 'center',
667
- gap: '0.25em',
668
- color: theme.colors.linkMain,
669
- fontFamily: 'inherit',
670
- fontSize: 'inherit',
671
- lineHeight: 'inherit',
672
- fontWeight: 'inherit',
673
- textDecoration: underline === 'always' ? 'underline' : 'none',
674
- cursor: 'pointer',
675
- borderRadius: theme.radius.xs,
676
- transition: `color ${theme.transition.fast}`,
677
- ':hover:not([aria-disabled="true"])': {
678
- color: theme.colors.linkHover,
679
- textDecoration: underline !== 'none' ? 'underline' : 'none',
680
- },
681
- ':active:not([aria-disabled="true"])': {
682
- color: theme.colors.linkActive,
683
- },
684
- ':focus-visible': {
685
- outline: `2px solid ${theme.colors.linkMain}`,
686
- outlineOffset: '2px',
687
- },
688
- '&[aria-disabled="true"]': {
689
- color: theme.colors.linkDisabled,
690
- cursor: 'not-allowed',
691
- textDecoration: 'none',
692
- },
693
- }),
664
+ root: ({ underline = 'hover', color = 'default' }) => {
665
+ const mainColor = color === 'secondary' ? theme.colors.textSecondary : theme.colors.linkMain;
666
+ const hoverColor = color === 'secondary' ? theme.colors.textTertiary : theme.colors.linkHover;
667
+ const activeColor = color === 'secondary' ? theme.colors.textPrimary : theme.colors.linkActive;
668
+ const disabledColor = color === 'secondary' ? theme.colors.textDisabled : theme.colors.linkDisabled;
669
+ return {
670
+ display: 'inline-flex',
671
+ alignItems: 'center',
672
+ gap: '0.25em',
673
+ color: mainColor,
674
+ fontFamily: 'inherit',
675
+ fontSize: 'inherit',
676
+ lineHeight: 'inherit',
677
+ fontWeight: 'inherit',
678
+ textDecoration: underline === 'always' ? 'underline' : 'none',
679
+ cursor: 'pointer',
680
+ borderRadius: theme.radius.xs,
681
+ transition: `color ${theme.transition.fast}`,
682
+ ':hover:not([aria-disabled="true"])': {
683
+ color: hoverColor,
684
+ textDecoration: underline !== 'none' ? 'underline' : 'none',
685
+ },
686
+ ':active:not([aria-disabled="true"])': {
687
+ color: activeColor,
688
+ },
689
+ ':focus-visible': {
690
+ outline: `2px solid ${mainColor}`,
691
+ outlineOffset: '2px',
692
+ },
693
+ '&[aria-disabled="true"]': {
694
+ color: disabledColor,
695
+ cursor: 'not-allowed',
696
+ textDecoration: 'none',
697
+ },
698
+ };
699
+ },
694
700
  icon: {
695
701
  display: 'inline-flex',
696
702
  alignItems: 'center',
@@ -713,7 +719,7 @@ const LINK_STYLES = theme.createStyles((theme) => ({
713
719
  * @example <Link href='/terms' underline='none'>Terms</Link>
714
720
  * @example <Link onClick={() => navigate('/about')}>About (SPA)</Link>
715
721
  */
716
- const Link = ({ ref, underline = 'hover', external = false, disabled = false, startIcon: StartIcon, endIcon: EndIcon, children, className, href, onClick, onKeyDown, ...rest }) => {
722
+ const Link = ({ ref, underline = 'hover', color = 'default', external = false, disabled = false, startIcon: StartIcon, endIcon: EndIcon, children, className, href, onClick, onKeyDown, ...rest }) => {
717
723
  // An <a> without href has no implicit ARIA role and is not focusable.
718
724
  // When used for SPA navigation (onClick only), we restore both behaviours.
719
725
  const hasHref = !!href;
@@ -734,7 +740,7 @@ const Link = ({ ref, underline = 'hover', external = false, disabled = false, st
734
740
  }
735
741
  onKeyDown?.(e);
736
742
  };
737
- return (jsxRuntime.jsxs("a", { ref: ref, href: href, className: theme.cx(LINK_STYLES.root({ underline }), className), "aria-disabled": disabled || undefined,
743
+ return (jsxRuntime.jsxs("a", { ref: ref, href: href, className: theme.cx(LINK_STYLES.root({ underline, color }), className), "aria-disabled": disabled || undefined,
738
744
  // Without href: must be explicitly put in the tab order.
739
745
  // With href: the browser handles focusability natively (no tabIndex needed).
740
746
  tabIndex: disabled ? -1 : (!hasHref ? 0 : undefined),
@@ -2573,6 +2579,78 @@ const Grid = ({ display = 'grid', columns, rows, autoFlow, autoColumns, autoRows
2573
2579
  };
2574
2580
  Grid.displayName = 'Grid';
2575
2581
 
2582
+ const BREADCRUMB_STYLES = theme.createStyles((_theme) => ({
2583
+ nav: {
2584
+ display: 'block',
2585
+ },
2586
+ list: {
2587
+ display: 'flex',
2588
+ flexWrap: 'wrap',
2589
+ alignItems: 'center',
2590
+ listStyle: 'none',
2591
+ margin: 0,
2592
+ padding: 0,
2593
+ },
2594
+ }), { id: 'breadcrumb' });
2595
+
2596
+ const BreadcrumbContext = React.createContext({
2597
+ separator: '/',
2598
+ });
2599
+ const useBreadcrumbContext = () => React.useContext(BreadcrumbContext);
2600
+
2601
+ const BREADCRUMB_ITEM_STYLES = theme.createStyles((theme) => ({
2602
+ item: {
2603
+ display: 'inline-flex',
2604
+ alignItems: 'center',
2605
+ fontSize: theme.fontSize.sm,
2606
+ lineHeight: theme.lineHeight.normal,
2607
+ },
2608
+ separator: {
2609
+ display: 'inline-flex',
2610
+ alignItems: 'center',
2611
+ marginLeft: theme.spacing.sm,
2612
+ marginRight: theme.spacing.sm,
2613
+ color: theme.colors.textTertiary,
2614
+ userSelect: 'none',
2615
+ },
2616
+ }), { id: 'breadcrumb-item' });
2617
+
2618
+ const BreadcrumbItem = ({ label, href, onClick, current = false, isFirst = false, }) => {
2619
+ const { separator } = useBreadcrumbContext();
2620
+ return (jsxRuntime.jsxs("li", { className: BREADCRUMB_ITEM_STYLES.item, "aria-current": current ? 'page' : undefined, children: [!isFirst && (jsxRuntime.jsx("span", { "aria-hidden": true, className: BREADCRUMB_ITEM_STYLES.separator, children: separator })), current ? (jsxRuntime.jsx(Text, { variant: 'span', fontWeight: 'semibold', color: 'textPrimary', children: label })) : (jsxRuntime.jsx(Link, { href: href, onClick: onClick, color: 'secondary', underline: 'hover', children: label }))] }));
2621
+ };
2622
+ BreadcrumbItem.displayName = 'Breadcrumb.Item';
2623
+
2624
+ /**
2625
+ * WAI-ARIA compliant breadcrumb navigation using a compound component API.
2626
+ *
2627
+ * ```tsx
2628
+ * <Breadcrumb separator='/'>
2629
+ * <Breadcrumb.Item label='Home' href='/' />
2630
+ * <Breadcrumb.Item label='Products' href='/products' />
2631
+ * <Breadcrumb.Item label='Laptop Pro X' current />
2632
+ * </Breadcrumb>
2633
+ * ```
2634
+ *
2635
+ * The last item is typically marked as `current` — it renders as bold text (non-clickable)
2636
+ * and exposes `aria-current="page"` for assistive technologies.
2637
+ */
2638
+ const BreadcrumbBase = ({ children, separator = '/', ariaLabel = 'Breadcrumb', }) => {
2639
+ const contextValue = React.useMemo(() => ({ separator }), [separator]);
2640
+ const items = React.Children.map(children, (child, index) => {
2641
+ if (!React.isValidElement(child)) {
2642
+ return child;
2643
+ }
2644
+ return React.cloneElement(child, {
2645
+ isFirst: index === 0,
2646
+ });
2647
+ });
2648
+ return (jsxRuntime.jsx(BreadcrumbContext.Provider, { value: contextValue, children: jsxRuntime.jsx("nav", { "aria-label": ariaLabel, className: BREADCRUMB_STYLES.nav, children: jsxRuntime.jsx("ol", { className: BREADCRUMB_STYLES.list, children: items }) }) }));
2649
+ };
2650
+ BreadcrumbBase.displayName = 'Breadcrumb';
2651
+ const Breadcrumb = BreadcrumbBase;
2652
+ Breadcrumb.Item = BreadcrumbItem;
2653
+
2576
2654
  const DrawerContext = React.createContext({
2577
2655
  isExpanded: true,
2578
2656
  });
@@ -2928,6 +3006,234 @@ Drawer.Body = DrawerBody;
2928
3006
  Drawer.Footer = DrawerFooter;
2929
3007
  Drawer.Item = DrawerItem;
2930
3008
 
3009
+ const TABS_LIST_STYLES = theme.createStyles(() => ({
3010
+ root: {
3011
+ display: 'flex',
3012
+ flexDirection: 'row',
3013
+ alignItems: 'center',
3014
+ overflowX: 'auto',
3015
+ scrollbarWidth: 'none',
3016
+ width: 'fit-content',
3017
+ '::-webkit-scrollbar': { display: 'none' },
3018
+ },
3019
+ }));
3020
+
3021
+ const TabsContext = React.createContext(null);
3022
+
3023
+ /**
3024
+ * Internal hook — consumes the Tabs context and throws if used outside a `<Tabs>` provider.
3025
+ * @internal
3026
+ */
3027
+ const useTabsContext = () => {
3028
+ const ctx = React.useContext(TabsContext);
3029
+ if (!ctx) {
3030
+ throw new Error('This component must be used inside a <Tabs> provider.');
3031
+ }
3032
+ return ctx;
3033
+ };
3034
+
3035
+ const TabsList = ({ children, ariaLabel, ariaLabelledBy }) => {
3036
+ const { value, setValue, baseId, getTabValues } = useTabsContext();
3037
+ /**
3038
+ * Returns true if the tab at the given index is aria-disabled.
3039
+ * We check the DOM attribute because disabled state lives in TabItem,
3040
+ * not in the shared context, and we want to avoid adding it to the context.
3041
+ */
3042
+ const isTabDisabled = (tabValue) => {
3043
+ const el = document.getElementById(`${baseId}-tab-${tabValue}`);
3044
+ return el?.getAttribute('aria-disabled') === 'true';
3045
+ };
3046
+ /**
3047
+ * Moves focus to the nearest non-disabled tab starting from `startIndex`
3048
+ * and stepping in the given `direction` (+1 = right, -1 = left).
3049
+ * Stops after a full loop if all tabs are disabled.
3050
+ */
3051
+ const focusNextEnabled = (startIndex, direction) => {
3052
+ const values = getTabValues();
3053
+ for (let i = 1; i <= values.length; i++) {
3054
+ const index = (startIndex + direction * i + values.length) % values.length;
3055
+ const nextValue = values[index];
3056
+ if (!isTabDisabled(nextValue)) {
3057
+ document.getElementById(`${baseId}-tab-${nextValue}`)?.focus();
3058
+ setValue(nextValue);
3059
+ return;
3060
+ }
3061
+ }
3062
+ };
3063
+ const handleKeyDown = (event) => {
3064
+ const values = getTabValues();
3065
+ const currentIndex = values.indexOf(value);
3066
+ if (currentIndex === -1) {
3067
+ return;
3068
+ }
3069
+ switch (event.key) {
3070
+ case 'ArrowRight':
3071
+ event.preventDefault();
3072
+ focusNextEnabled(currentIndex, 1);
3073
+ break;
3074
+ case 'ArrowLeft':
3075
+ event.preventDefault();
3076
+ focusNextEnabled(currentIndex, -1);
3077
+ break;
3078
+ case 'Home': {
3079
+ event.preventDefault();
3080
+ // Focus the first non-disabled tab
3081
+ const firstIdx = values.findIndex((v) => !isTabDisabled(v));
3082
+ if (firstIdx !== -1) {
3083
+ document.getElementById(`${baseId}-tab-${values[firstIdx]}`)?.focus();
3084
+ setValue(values[firstIdx]);
3085
+ }
3086
+ break;
3087
+ }
3088
+ case 'End': {
3089
+ event.preventDefault();
3090
+ // Focus the last non-disabled tab
3091
+ const lastIdx = [...values].reverse().findIndex((v) => !isTabDisabled(v));
3092
+ if (lastIdx !== -1) {
3093
+ const realIndex = values.length - 1 - lastIdx;
3094
+ document.getElementById(`${baseId}-tab-${values[realIndex]}`)?.focus();
3095
+ setValue(values[realIndex]);
3096
+ }
3097
+ break;
3098
+ }
3099
+ }
3100
+ };
3101
+ return (jsxRuntime.jsx("div", { role: 'tablist', "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, className: TABS_LIST_STYLES.root, onKeyDown: handleKeyDown, children: children }));
3102
+ };
3103
+ TabsList.displayName = 'Tabs.List';
3104
+
3105
+ const TABS_PANEL_STYLES = theme.createStyles(() => ({
3106
+ root: {
3107
+ width: '100%',
3108
+ },
3109
+ }));
3110
+
3111
+ const TabsPanel = ({ value, children, keepMounted = false }) => {
3112
+ const { value: activeValue, baseId } = useTabsContext();
3113
+ const isActive = activeValue === value;
3114
+ if (!isActive && !keepMounted) {
3115
+ return null;
3116
+ }
3117
+ return (jsxRuntime.jsx("div", { role: 'tabpanel', id: `${baseId}-panel-${value}`, "aria-labelledby": `${baseId}-tab-${value}`,
3118
+ // WAI-ARIA APG: tabIndex={0} allows keyboard scrolling when the panel has no focusable child.
3119
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
3120
+ tabIndex: 0, hidden: !isActive, className: TABS_PANEL_STYLES.root, children: children }));
3121
+ };
3122
+ TabsPanel.displayName = 'Tabs.Panel';
3123
+
3124
+ const TAB_ITEM_STYLES = theme.createStyles((theme) => ({
3125
+ root: ({ isActive, disabled }) => ({
3126
+ display: 'inline-flex',
3127
+ alignItems: 'center',
3128
+ justifyContent: 'center',
3129
+ boxSizing: 'border-box',
3130
+ paddingTop: theme.spacing.xs,
3131
+ paddingBottom: theme.spacing.xs,
3132
+ paddingLeft: theme.spacing.md,
3133
+ paddingRight: theme.spacing.md,
3134
+ border: 'none',
3135
+ borderBottom: `2px solid ${isActive ? theme.colors.primaryMain : 'transparent'}`,
3136
+ background: 'transparent',
3137
+ cursor: disabled ? 'not-allowed' : 'pointer',
3138
+ fontFamily: 'inherit',
3139
+ whiteSpace: 'nowrap',
3140
+ transition: `border-color ${theme.transition.fast}`,
3141
+ ...(disabled ? {} : {
3142
+ ':hover': {
3143
+ borderBottomColor: isActive ? theme.colors.primaryMain : theme.colors.textTertiary,
3144
+ },
3145
+ }),
3146
+ ':focus-visible': {
3147
+ outline: `2px solid ${theme.colors.primaryMain}`,
3148
+ outlineOffset: '2px',
3149
+ },
3150
+ }),
3151
+ }));
3152
+
3153
+ /**
3154
+ * Handles tab registration, active state derivation and interaction props
3155
+ * for a single `Tabs.Tab` (TabItem) button.
3156
+ *
3157
+ * Registers the tab value into the shared ordered registry on mount so that
3158
+ * `TabsList` can perform correct ArrowLeft/Right/Home/End keyboard navigation.
3159
+ */
3160
+ const useTabItem = ({ value, disabled }) => {
3161
+ const { value: activeValue, setValue, baseId, registerTab } = useTabsContext();
3162
+ // Maintains the ordered tab registry used by TabsList for keyboard navigation.
3163
+ React.useEffect(() => registerTab(value), [registerTab, value]);
3164
+ const isActive = activeValue === value;
3165
+ return {
3166
+ isActive,
3167
+ buttonProps: {
3168
+ id: `${baseId}-tab-${value}`,
3169
+ 'aria-selected': isActive,
3170
+ 'aria-controls': `${baseId}-panel-${value}`,
3171
+ 'aria-disabled': disabled || undefined,
3172
+ tabIndex: isActive ? 0 : -1,
3173
+ onClick: () => {
3174
+ if (!disabled) {
3175
+ setValue(value);
3176
+ }
3177
+ },
3178
+ },
3179
+ };
3180
+ };
3181
+
3182
+ const TabItem = ({ value, label, disabled = false }) => {
3183
+ const { isActive, buttonProps } = useTabItem({ value, disabled });
3184
+ return (jsxRuntime.jsx("button", { type: 'button', role: 'tab', className: TAB_ITEM_STYLES.root({ isActive, disabled }), ...buttonProps, children: jsxRuntime.jsx(Text, { variant: 'span', fontSize: 'sm', fontWeight: isActive ? 'semibold' : 'medium', color: disabled ? 'textDisabled' : isActive ? 'textPrimary' : 'textSecondary', children: label }) }));
3185
+ };
3186
+ TabItem.displayName = 'Tabs.Tab';
3187
+
3188
+ /**
3189
+ * WAI-ARIA compliant tab interface using a compound component API.
3190
+ *
3191
+ * ```tsx
3192
+ * <Tabs defaultValue={'active'} onChange={handleChange}>
3193
+ * <Tabs.List ariaLabel={'Subscriptions'}>
3194
+ * <Tabs.Tab value={'active'} label={'Active'} />
3195
+ * <Tabs.Tab value={'cancelled'} label={'Cancelled'} />
3196
+ * </Tabs.List>
3197
+ * <Tabs.Panel value={'active'}>...</Tabs.Panel>
3198
+ * <Tabs.Panel value={'cancelled'}>...</Tabs.Panel>
3199
+ * </Tabs>
3200
+ * ```
3201
+ *
3202
+ * Supports controlled (`value` + `onChange`) and uncontrolled (`defaultValue`) modes.
3203
+ * Keyboard navigation: `ArrowLeft/Right`, `Home`, `End`.
3204
+ * Only the active panel is mounted — use `keepMounted` on `Tabs.Panel` to preserve state across switches.
3205
+ */
3206
+ const TabsBase = ({ children, value: controlledValue, defaultValue, onChange, id, }) => {
3207
+ const reactId = React.useId();
3208
+ const baseId = id ?? `tabs-${reactId}`;
3209
+ const [internalValue, setInternalValue] = React.useState(defaultValue ?? '');
3210
+ const isControlled = controlledValue !== undefined;
3211
+ const value = isControlled ? controlledValue : internalValue;
3212
+ const tabsRef = React.useRef([]);
3213
+ const registerTab = React.useCallback((tabValue) => {
3214
+ if (!tabsRef.current.includes(tabValue)) {
3215
+ tabsRef.current.push(tabValue);
3216
+ }
3217
+ return () => {
3218
+ tabsRef.current = tabsRef.current.filter((v) => v !== tabValue);
3219
+ };
3220
+ }, []);
3221
+ const getTabValues = React.useCallback(() => tabsRef.current, []);
3222
+ const setValue = React.useCallback((next) => {
3223
+ if (!isControlled) {
3224
+ setInternalValue(next);
3225
+ }
3226
+ onChange?.(next);
3227
+ }, [isControlled, onChange]);
3228
+ const contextValue = React.useMemo(() => ({ value, setValue, baseId, registerTab, getTabValues }), [value, setValue, baseId, registerTab, getTabValues]);
3229
+ return (jsxRuntime.jsx(TabsContext.Provider, { value: contextValue, children: children }));
3230
+ };
3231
+ TabsBase.displayName = 'Tabs';
3232
+ const Tabs = TabsBase;
3233
+ Tabs.List = TabsList;
3234
+ Tabs.Tab = TabItem;
3235
+ Tabs.Panel = TabsPanel;
3236
+
2931
3237
  const AlertContext = React.createContext({
2932
3238
  variant: 'default',
2933
3239
  accentColor: 'defaultActive',
@@ -3600,6 +3906,7 @@ exports.Alert = Alert;
3600
3906
  exports.Backdrop = Backdrop;
3601
3907
  exports.Badge = Badge;
3602
3908
  exports.Box = Box;
3909
+ exports.Breadcrumb = Breadcrumb;
3603
3910
  exports.Button = Button;
3604
3911
  exports.Card = Card;
3605
3912
  exports.Checkbox = Checkbox;
@@ -3616,6 +3923,7 @@ exports.Select = Select;
3616
3923
  exports.Skeleton = Skeleton;
3617
3924
  exports.Stack = Stack;
3618
3925
  exports.Switch = Switch;
3926
+ exports.Tabs = Tabs;
3619
3927
  exports.Text = Text;
3620
3928
  exports.TextField = TextField;
3621
3929
  exports.Tooltip = Tooltip;