@lumx/react 2.2.16 → 2.2.17

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.
@@ -1 +1 @@
1
- {"version":3,"file":"FlexBox.js","sources":["../../../src/components/flex-box/FlexBox.tsx"],"sourcesContent":["import { Alignment, HorizontalAlignment, Orientation, VerticalAlignment } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport classNames from 'classnames';\nimport castArray from 'lodash/castArray';\nimport React, { forwardRef, ReactNode } from 'react';\nimport { Size } from '..';\n\nexport type MarginAutoAlignment = Extract<Alignment, 'top' | 'bottom' | 'right' | 'left'>;\nexport type GapSize = Extract<Size, 'regular' | 'big' | 'huge'>;\n\n/**\n * Defines the props of the component.\n */\nexport interface FlexBoxProps extends GenericProps {\n /** Children elements. */\n children?: ReactNode;\n /** Whether the \"content filling space\" is enabled or not. */\n fillSpace?: boolean;\n /** Gap space between flexbox items. */\n gap?: GapSize;\n /** Flex horizontal alignment. */\n hAlign?: VerticalAlignment;\n /** Whether the \"auto margin\" is enabled all around or not. */\n marginAuto?: MarginAutoAlignment | MarginAutoAlignment[];\n /** Whether the \"content shrink\" is disabled or not. */\n noShrink?: boolean;\n /** Flex direction. */\n orientation?: Orientation;\n /** Flex vertical alignment. */\n vAlign?: HorizontalAlignment;\n /** Whether the \"flex wrap\" is enabled or not. */\n wrap?: boolean;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'FlexBox';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * FlexBox component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const FlexBox: Comp<FlexBoxProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n children,\n className,\n fillSpace,\n gap,\n hAlign,\n marginAuto,\n noShrink,\n orientation,\n vAlign,\n wrap,\n ...forwardedProps\n } = props;\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n prefix: CLASSNAME,\n orientation: orientation ?? (wrap || hAlign || vAlign ? Orientation.horizontal : null),\n vAlign,\n hAlign,\n gap,\n }),\n wrap && `${CLASSNAME}--wrap`,\n fillSpace && `${CLASSNAME}--fill-space`,\n noShrink && `${CLASSNAME}--no-shrink`,\n marginAuto && castArray(marginAuto).map((align) => `${CLASSNAME}--margin-auto-${align}`),\n )}\n >\n {children}\n </div>\n );\n});\nFlexBox.displayName = COMPONENT_NAME;\nFlexBox.className = CLASSNAME;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","FlexBox","forwardRef","props","ref","children","className","fillSpace","gap","hAlign","marginAuto","noShrink","orientation","vAlign","wrap","forwardedProps","classNames","handleBasicClasses","prefix","Orientation","horizontal","castArray","map","align","displayName"],"mappings":";;;;;;AAkCA;;;AAGA,IAAMA,cAAc,GAAG,SAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;;;;;IAOaG,OAA2C,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MAE9EC,QAF8E,GAa9EF,KAb8E,CAE9EE,QAF8E;AAAA,MAG9EC,SAH8E,GAa9EH,KAb8E,CAG9EG,SAH8E;AAAA,MAI9EC,SAJ8E,GAa9EJ,KAb8E,CAI9EI,SAJ8E;AAAA,MAK9EC,GAL8E,GAa9EL,KAb8E,CAK9EK,GAL8E;AAAA,MAM9EC,MAN8E,GAa9EN,KAb8E,CAM9EM,MAN8E;AAAA,MAO9EC,UAP8E,GAa9EP,KAb8E,CAO9EO,UAP8E;AAAA,MAQ9EC,QAR8E,GAa9ER,KAb8E,CAQ9EQ,QAR8E;AAAA,MAS9EC,WAT8E,GAa9ET,KAb8E,CAS9ES,WAT8E;AAAA,MAU9EC,MAV8E,GAa9EV,KAb8E,CAU9EU,MAV8E;AAAA,MAW9EC,IAX8E,GAa9EX,KAb8E,CAW9EW,IAX8E;AAAA,MAY3EC,cAZ2E,4BAa9EZ,KAb8E;;AAelF,SACI;AACI,IAAA,GAAG,EAAEC;AADT,KAEQW,cAFR;AAGI,IAAA,SAAS,EAAEC,UAAU,CACjBV,SADiB,EAEjBW,kBAAkB,CAAC;AACfC,MAAAA,MAAM,EAAEnB,SADO;AAEfa,MAAAA,WAAW,EAAEA,WAAF,aAAEA,WAAF,cAAEA,WAAF,GAAkBE,IAAI,IAAIL,MAAR,IAAkBI,MAAlB,GAA2BM,WAAW,CAACC,UAAvC,GAAoD,IAFlE;AAGfP,MAAAA,MAAM,EAANA,MAHe;AAIfJ,MAAAA,MAAM,EAANA,MAJe;AAKfD,MAAAA,GAAG,EAAHA;AALe,KAAD,CAFD,EASjBM,IAAI,cAAOf,SAAP,WATa,EAUjBQ,SAAS,cAAOR,SAAP,iBAVQ,EAWjBY,QAAQ,cAAOZ,SAAP,gBAXS,EAYjBW,UAAU,IAAIW,SAAS,CAACX,UAAD,CAAT,CAAsBY,GAAtB,CAA0B,UAACC,KAAD;AAAA,uBAAcxB,SAAd,2BAAwCwB,KAAxC;AAAA,KAA1B,CAZG;AAHzB,MAkBKlB,QAlBL,CADJ;AAsBH,CArCoE;AAsCrEJ,OAAO,CAACuB,WAAR,GAAsB1B,cAAtB;AACAG,OAAO,CAACK,SAAR,GAAoBP,SAApB;;;;"}
1
+ {"version":3,"file":"FlexBox.js","sources":["../../../src/components/flex-box/FlexBox.tsx"],"sourcesContent":["import { Alignment, HorizontalAlignment, Orientation, VerticalAlignment } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport classNames from 'classnames';\nimport castArray from 'lodash/castArray';\nimport React, { forwardRef, ReactNode } from 'react';\nimport { Size } from '..';\n\nexport type MarginAutoAlignment = Extract<Alignment, 'top' | 'bottom' | 'right' | 'left'>;\nexport type GapSize = Extract<Size, 'regular' | 'medium' | 'big' | 'huge'>;\n\n/**\n * Defines the props of the component.\n */\nexport interface FlexBoxProps extends GenericProps {\n /** Children elements. */\n children?: ReactNode;\n /** Whether the \"content filling space\" is enabled or not. */\n fillSpace?: boolean;\n /** Gap space between flexbox items. */\n gap?: GapSize;\n /** Flex horizontal alignment. */\n hAlign?: VerticalAlignment;\n /** Whether the \"auto margin\" is enabled all around or not. */\n marginAuto?: MarginAutoAlignment | MarginAutoAlignment[];\n /** Whether the \"content shrink\" is disabled or not. */\n noShrink?: boolean;\n /** Flex direction. */\n orientation?: Orientation;\n /** Flex vertical alignment. */\n vAlign?: HorizontalAlignment;\n /** Whether the \"flex wrap\" is enabled or not. */\n wrap?: boolean;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'FlexBox';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * FlexBox component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const FlexBox: Comp<FlexBoxProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n children,\n className,\n fillSpace,\n gap,\n hAlign,\n marginAuto,\n noShrink,\n orientation,\n vAlign,\n wrap,\n ...forwardedProps\n } = props;\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n prefix: CLASSNAME,\n orientation: orientation ?? (wrap || hAlign || vAlign ? Orientation.horizontal : null),\n vAlign,\n hAlign,\n gap,\n }),\n wrap && `${CLASSNAME}--wrap`,\n fillSpace && `${CLASSNAME}--fill-space`,\n noShrink && `${CLASSNAME}--no-shrink`,\n marginAuto && castArray(marginAuto).map((align) => `${CLASSNAME}--margin-auto-${align}`),\n )}\n >\n {children}\n </div>\n );\n});\nFlexBox.displayName = COMPONENT_NAME;\nFlexBox.className = CLASSNAME;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","FlexBox","forwardRef","props","ref","children","className","fillSpace","gap","hAlign","marginAuto","noShrink","orientation","vAlign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;AALe,KAAD,CAFD,EASjBM,IAAI,cAAOf,SAAP,WATa,EAUjBQ,SAAS,cAAOR,SAAP,iBAVQ,EAWjBY,QAAQ,cAAOZ,SAAP,gBAXS,EAYjBW,UAAU,IAAIW,SAAS,CAACX,UAAD,CAAT,CAAsBY,GAAtB,CAA0B,UAACC,KAAD;AAAA,uBAAcxB,SAAd,2BAAwCwB,KAAxC;AAAA,KAA1B,CAZG;AAHzB,MAkBKlB,QAlBL,CADJ;AAsBH,CArCoE;AAsCrEJ,OAAO,CAACuB,WAAR,GAAsB1B,cAAtB;AACAG,OAAO,CAACK,SAAR,GAAoBP,SAApB;;;;"}
@@ -58,6 +58,7 @@ var Size = {
58
58
  xxl: 'xxl',
59
59
  tiny: 'tiny',
60
60
  regular: 'regular',
61
+ medium: 'medium',
61
62
  big: 'big',
62
63
  huge: 'huge'
63
64
  };
@@ -1 +1 @@
1
- {"version":3,"file":"components.js","sources":["../../../src/components/index.ts"],"sourcesContent":["import { ValueOf } from '@lumx/react/utils';\n\n/**\n * Alignments.\n */\nexport const Alignment = {\n bottom: 'bottom',\n center: 'center',\n end: 'end',\n left: 'left',\n right: 'right',\n spaceAround: 'space-around',\n spaceBetween: 'space-between',\n start: 'start',\n top: 'top',\n} as const;\nexport type Alignment = ValueOf<typeof Alignment>;\nexport type VerticalAlignment = Extract<Alignment, 'top' | 'center' | 'bottom'>;\nexport type HorizontalAlignment = Extract<Alignment, 'right' | 'center' | 'left'>;\n\n/**\n * See SCSS variable $lumx-color-palette\n */\nexport const ColorPalette = {\n primary: 'primary',\n secondary: 'secondary',\n blue: 'blue',\n dark: 'dark',\n green: 'green',\n yellow: 'yellow',\n red: 'red',\n light: 'light',\n grey: 'grey',\n} as const;\nexport type ColorPalette = ValueOf<typeof ColorPalette>;\nexport type Color = ColorPalette | string;\n\n/**\n * See SCSS variable $lumx-color-variants\n */\nexport const ColorVariant = {\n D1: 'D1',\n D2: 'D2',\n L1: 'L1',\n L2: 'L2',\n L3: 'L3',\n L4: 'L4',\n L5: 'L5',\n L6: 'L6',\n N: 'N',\n} as const;\nexport type ColorVariant = ValueOf<typeof ColorVariant>;\n\nexport const Theme = {\n light: 'light',\n dark: 'dark',\n} as const;\nexport type Theme = ValueOf<typeof Theme>;\n\nexport const Size = {\n xxs: 'xxs',\n xs: 'xs',\n s: 's',\n m: 'm',\n l: 'l',\n xl: 'xl',\n xxl: 'xxl',\n tiny: 'tiny',\n regular: 'regular',\n big: 'big',\n huge: 'huge',\n} as const;\nexport type Size = ValueOf<typeof Size>;\nexport type GlobalSize = Extract<Size, 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'>;\n\nexport const Orientation = {\n horizontal: 'horizontal',\n vertical: 'vertical',\n} as const;\nexport type Orientation = ValueOf<typeof Orientation>;\n\nexport const Emphasis = {\n low: 'low',\n medium: 'medium',\n high: 'high',\n} as const;\nexport type Emphasis = ValueOf<typeof Emphasis>;\n\n/**\n * List of typographies that can't be customized.\n */\nexport const TypographyInterface = {\n overline: 'overline',\n caption: 'caption',\n body1: 'body1',\n body2: 'body2',\n subtitle1: 'subtitle1',\n subtitle2: 'subtitle2',\n title: 'title',\n headline: 'headline',\n display1: 'display1',\n} as const;\nexport type TypographyInterface = ValueOf<typeof TypographyInterface>;\n\n/**\n * List of title typographies that can be customized (via CSS variables).\n */\nexport const TypographyTitleCustom = {\n title1: 'custom-title1',\n title2: 'custom-title2',\n title3: 'custom-title3',\n title4: 'custom-title4',\n title5: 'custom-title5',\n title6: 'custom-title6',\n} as const;\nexport type TypographyTitleCustom = ValueOf<typeof TypographyTitleCustom>;\n\n/**\n * List of typographies that can be customized (via CSS variables).\n */\nconst TypographyCustom = {\n ...TypographyTitleCustom,\n intro: 'intro',\n 'body-large': 'body-large',\n body: 'body',\n quote: 'quote',\n 'publish-info': 'publish-info',\n button: 'button',\n} as const;\nexport type TypographyCustom = ValueOf<typeof TypographyCustom>;\n\n/**\n * List of all typographies.\n */\nexport const Typography = {\n ...TypographyInterface,\n custom: TypographyCustom,\n} as const;\nexport type Typography = TypographyInterface | TypographyCustom;\n\n/**\n * All available aspect ratios.\n */\nexport const AspectRatio = {\n /** Intrinsic content ratio. */\n original: 'original',\n /** Ratio 16:9 */\n wide: 'wide',\n /** Ratio 3:2 */\n horizontal: 'horizontal',\n /** Ratio 3:2 */\n vertical: 'vertical',\n /** Ratio 1:1 */\n square: 'square',\n /** Ratio constrained by the parent. */\n free: 'free',\n} as const;\nexport type AspectRatio = ValueOf<typeof AspectRatio>;\n\n/**\n * Semantic info about the purpose of the component\n */\nexport const Kind = {\n info: 'info',\n success: 'success',\n warning: 'warning',\n error: 'error',\n} as const;\nexport type Kind = ValueOf<typeof Kind>;\n"],"names":["Alignment","bottom","center","end","left","right","spaceAround","spaceBetween","start","top","ColorPalette","primary","secondary","blue","dark","green","yellow","red","light","grey","ColorVariant","D1","D2","L1","L2","L3","L4","L5","L6","N","Theme","Size","xxs","xs","s","m","l","xl","xxl","tiny","regular","big","huge","Orientation","horizontal","vertical","Emphasis","low","medium","high","TypographyInterface","overline","caption","body1","body2","subtitle1","subtitle2","title","headline","display1","TypographyTitleCustom","title1","title2","title3","title4","title5","title6","TypographyCustom","intro","body","quote","button","Typography","custom","AspectRatio","original","wide","square","free","Kind","info","success","warning","error"],"mappings":";;AAEA;;;IAGaA,SAAS,GAAG;AACrBC,EAAAA,MAAM,EAAE,QADa;AAErBC,EAAAA,MAAM,EAAE,QAFa;AAGrBC,EAAAA,GAAG,EAAE,KAHgB;AAIrBC,EAAAA,IAAI,EAAE,MAJe;AAKrBC,EAAAA,KAAK,EAAE,OALc;AAMrBC,EAAAA,WAAW,EAAE,cANQ;AAOrBC,EAAAA,YAAY,EAAE,eAPO;AAQrBC,EAAAA,KAAK,EAAE,OARc;AASrBC,EAAAA,GAAG,EAAE;AATgB;;AAezB;;;IAGaC,YAAY,GAAG;AACxBC,EAAAA,OAAO,EAAE,SADe;AAExBC,EAAAA,SAAS,EAAE,WAFa;AAGxBC,EAAA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,OAAO,EAAE,SAFO;AAGhBC,EAAAA,OAAO,EAAE,SAHO;AAIhBC,EAAAA,KAAK,EAAE;AAJS;;;;"}
1
+ {"version":3,"file":"components.js","sources":["../../../src/components/index.ts"],"sourcesContent":["import { ValueOf } from '@lumx/react/utils';\n\n/**\n * Alignments.\n */\nexport const Alignment = {\n bottom: 'bottom',\n center: 'center',\n end: 'end',\n left: 'left',\n right: 'right',\n spaceAround: 'space-around',\n spaceBetween: 'space-between',\n start: 'start',\n top: 'top',\n} as const;\nexport type Alignment = ValueOf<typeof Alignment>;\nexport type VerticalAlignment = Extract<Alignment, 'top' | 'center' | 'bottom'>;\nexport type HorizontalAlignment = Extract<Alignment, 'right' | 'center' | 'left'>;\n\n/**\n * See SCSS variable $lumx-color-palette\n */\nexport const ColorPalette = {\n primary: 'primary',\n secondary: 'secondary',\n blue: 'blue',\n dark: 'dark',\n green: 'green',\n yellow: 'yellow',\n red: 'red',\n light: 'light',\n grey: 'grey',\n} as const;\nexport type ColorPalette = ValueOf<typeof ColorPalette>;\nexport type Color = ColorPalette | string;\n\n/**\n * See SCSS variable $lumx-color-variants\n */\nexport const ColorVariant = {\n D1: 'D1',\n D2: 'D2',\n L1: 'L1',\n L2: 'L2',\n L3: 'L3',\n L4: 'L4',\n L5: 'L5',\n L6: 'L6',\n N: 'N',\n} as const;\nexport type ColorVariant = ValueOf<typeof ColorVariant>;\n\nexport const Theme = {\n light: 'light',\n dark: 'dark',\n} as const;\nexport type Theme = ValueOf<typeof Theme>;\n\nexport const Size = {\n xxs: 'xxs',\n xs: 'xs',\n s: 's',\n m: 'm',\n l: 'l',\n xl: 'xl',\n xxl: 'xxl',\n tiny: 'tiny',\n regular: 'regular',\n medium: 'medium',\n big: 'big',\n huge: 'huge',\n} as const;\nexport type Size = ValueOf<typeof Size>;\nexport type GlobalSize = Extract<Size, 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'>;\n\nexport const Orientation = {\n horizontal: 'horizontal',\n vertical: 'vertical',\n} as const;\nexport type Orientation = ValueOf<typeof Orientation>;\n\nexport const Emphasis = {\n low: 'low',\n medium: 'medium',\n high: 'high',\n} as const;\nexport type Emphasis = ValueOf<typeof Emphasis>;\n\n/**\n * List of typographies that can't be customized.\n */\nexport const TypographyInterface = {\n overline: 'overline',\n caption: 'caption',\n body1: 'body1',\n body2: 'body2',\n subtitle1: 'subtitle1',\n subtitle2: 'subtitle2',\n title: 'title',\n headline: 'headline',\n display1: 'display1',\n} as const;\nexport type TypographyInterface = ValueOf<typeof TypographyInterface>;\n\n/**\n * List of title typographies that can be customized (via CSS variables).\n */\nexport const TypographyTitleCustom = {\n title1: 'custom-title1',\n title2: 'custom-title2',\n title3: 'custom-title3',\n title4: 'custom-title4',\n title5: 'custom-title5',\n title6: 'custom-title6',\n} as const;\nexport type TypographyTitleCustom = ValueOf<typeof TypographyTitleCustom>;\n\n/**\n * List of typographies that can be customized (via CSS variables).\n */\nconst TypographyCustom = {\n ...TypographyTitleCustom,\n intro: 'intro',\n 'body-large': 'body-large',\n body: 'body',\n quote: 'quote',\n 'publish-info': 'publish-info',\n button: 'button',\n} as const;\nexport type TypographyCustom = ValueOf<typeof TypographyCustom>;\n\n/**\n * List of all typographies.\n */\nexport const Typography = {\n ...TypographyInterface,\n custom: TypographyCustom,\n} as const;\nexport type Typography = TypographyInterface | TypographyCustom;\n\n/**\n * All available aspect ratios.\n */\nexport const AspectRatio = {\n /** Intrinsic content ratio. */\n original: 'original',\n /** Ratio 16:9 */\n wide: 'wide',\n /** Ratio 3:2 */\n horizontal: 'horizontal',\n /** Ratio 3:2 */\n vertical: 'vertical',\n /** Ratio 1:1 */\n square: 'square',\n /** Ratio constrained by the parent. */\n free: 'free',\n} as const;\nexport type AspectRatio = ValueOf<typeof AspectRatio>;\n\n/**\n * Semantic info about the purpose of the component\n */\nexport const Kind = {\n info: 'info',\n success: 'success',\n warning: 'warning',\n error: 'error',\n} as const;\nexport type Kind = ValueOf<typeof Kind>;\n"],"names":["Alignment","bottom","center","end","left","right","spaceAround","spaceBetween","start","top","ColorPalette","primary","secondary","blue","dark","green","yellow","red","light","grey","ColorVariant","D1","D2","L1","L2","L3","L4","L5","L6","N","Theme","Size","xxs","xs","s","m","l","xl","xxl","tiny","regular","medium","big","huge","Orientation","horizontal","vertical","Emphasis","low","high","TypographyInterface","overline","caption","body1","body2","subtitle1","subtitle2","title","headline","display1","TypographyTitleCustom","title1","title2","title3","title4","title5","title6","TypographyCustom","intro","body","quote","button","Typography","custom","AspectRatio","original","wide","square","free","Kind","info","success","warning","error"],"mappings":";;AAEA;;;IAGaA,SAAS,GAAG;AACrBC,EAAAA,MAAM,EAAE,QADa;AAErBC,EAAAA,MAAM,EAAE,QAFa;AAGrBC,EAAAA,GAAG,EAAE,KAHgB;AAIrBC,EAAAA,IAAI,EAAE,MAJe;AAKrBC,EAAAA,KAAK,EAAE,OALc;AAMrBC,EAAAA,WAAW,EAAE,cANQ;AAOrBC,EAAAA,YAAY,EAAE,eAPO;AAQrBC,EAAAA,KAAK,EAAE,OARc;AASrBC,EAAAA,GAAG,EAAE;AATgB;;AAezB;;;IAGaC,YAAY,GAAG;AACxBC,EAAAA,OAAO,EAAE,SADe;AAExBC,EAAAA,SAAS,EAAE,WAFa;AAGxBC,EAAAA,IAAI,EAAE,MAHkB;AAIxBC,EAAAA,IAAI,EAAE,MAJkB;AAKxBC,EAAAA,KAAK,EAAE,OALiB;AAMxBC,EAAAA,MAAM,EAAE,QANgB;AAOxBC,EAAAA,GAAG,EAAE,KAPmB;AAQxBC,EAAAA,KAAK,EAAE,OARiB;AASxBC,EAAAA,IAAI,EAAE;AATkB;;AAc5B;;;IAGaC,YAAY,GAAG;AACxBC,EAAAA,EAAE,EAAE,IADoB;AAExBC,EAAAA,EAAE,EAAE,IAFoB;AAGxBC,EAAAA,EAAE,EAAE,IAHoB;AAIxBC,EAAAA,EAAE,EAAE,IAJoB;AAKxBC,EAAAA,EAAE,EAAE,IALoB;AAMxBC,EAAAA,EAAE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;AAEjCC,EAAAA,MAAM,EAAE,eAFyB;AAGjCC,EAAAA,MAAM,EAAE,eAHyB;AAIjCC,EAAAA,MAAM,EAAE,eAJyB;AAKjCC,EAAAA,MAAM,EAAE,eALyB;AAMjCC,EAAAA,MAAM,EAAE;AANyB;;AAUrC;;;AAGA,IAAMC,gBAAgB,sBACfP,qBADe;AAElBQ,EAAAA,KAAK,EAAE,OAFW;AAGlB,gBAAc,YAHI;AAIlBC,EAAAA,IAAI,EAAE,MAJY;AAKlBC,EAAAA,KAAK,EAAE,OALW;AAMlB,kBAAgB,cANE;AAOlBC,EAAAA,MAAM,EAAE;AAPU,EAAtB;;AAWA;;;IAGaC,UAAU,sBAChBtB,mBADgB;AAEnBuB,EAAAA,MAAM,EAAEN;AAFW;;AAMvB;;;IAGaO,WAAW,GAAG;AACvB;AACAC,EAAAA,QAAQ,EAAE,UAFa;;AAGvB;AACAC,EAAAA,IAAI,EAAE,MAJiB;;AAKvB;AACA/B,EAAAA,UAAU,EAAE,YANW;;AAOvB;AACAC,EAAAA,QAAQ,EAAE,UARa;;AASvB;AACA+B,EAAAA,MAAM,EAAE,QAVe;;AAWvB;AACAC,EAAAA,IAAI,EAAE;AAZiB;;AAgB3B;;;IAGaC,IAAI,GAAG;AAChBC,EAAAA,IAAI,EAAE,MADU;AAEhBC,EAAAA,OAAO,EAAE,SAFO;AAGhBC,EAAAA,OAAO,EAAE,SAHO;AAIhBC,EAAAA,KAAK,EAAE;AAJS;;;;"}
@@ -1,6 +1,9 @@
1
1
  import { useEffect } from 'react';
2
2
  import { D as DOCUMENT } from './constants.js';
3
3
 
4
+ /** CSS selector listing all tabbable elements. */
5
+
6
+ var TABBABLE_ELEMENTS_SELECTOR = "a[href]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\nbutton:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ntextarea:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"text\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"radio\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"checkbox\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\n[tabindex]:not([tabindex=\"-1\"], [disabled], [aria-disabled])";
4
7
  /**
5
8
  * Get first and last elements focusable in an element.
6
9
  *
@@ -9,7 +12,7 @@ import { D as DOCUMENT } from './constants.js';
9
12
  */
10
13
 
11
14
  function getFocusable(parentElement) {
12
- var focusableElements = parentElement.querySelectorAll('a[href]:not([tabindex="-1"]), button:not([tabindex="-1"]), textarea:not([tabindex="-1"]), input[type="text"]:not([tabindex="-1"]), input[type="radio"]:not([tabindex="-1"]), input[type="checkbox"]:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"])');
15
+ var focusableElements = parentElement.querySelectorAll(TABBABLE_ELEMENTS_SELECTOR);
13
16
 
14
17
  if (focusableElements.length <= 0) {
15
18
  return {};
@@ -52,23 +55,26 @@ function useFocusTrap(focusZoneElement, focusElement) {
52
55
  return;
53
56
  }
54
57
 
55
- var _getFocusable = getFocusable(focusZoneElement),
56
- first = _getFocusable.first,
57
- last = _getFocusable.last; // Prevent focus switch if no focusable available.
58
+ var focusable = getFocusable(focusZoneElement); // Prevent focus switch if no focusable available.
58
59
 
60
+ if (!focusable.first) {
61
+ evt.preventDefault();
62
+ return;
63
+ }
59
64
 
60
- if (!first) {
65
+ if ( // No previous focus
66
+ !document.activeElement || // Previous focus is at the end of the focus zone.
67
+ !evt.shiftKey && document.activeElement === focusable.last || // Previous focus is outside the focus zone
68
+ !focusZoneElement.contains(document.activeElement)) {
69
+ focusable.first.focus();
61
70
  evt.preventDefault();
62
71
  return;
63
72
  }
64
73
 
65
- if (evt.shiftKey) {
66
- if (document.activeElement === first) {
67
- last === null || last === void 0 ? void 0 : last.focus();
68
- evt.preventDefault();
69
- }
70
- } else if (document.activeElement === last) {
71
- first === null || first === void 0 ? void 0 : first.focus();
74
+ if ( // Focus order reversed
75
+ evt.shiftKey && // Previous focus is at the start of the focus zone.
76
+ document.activeElement === focusable.first) {
77
+ focusable.last.focus();
72
78
  evt.preventDefault();
73
79
  }
74
80
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useFocusTrap.js","sources":["../../../src/hooks/useFocusTrap.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { DOCUMENT } from '@lumx/react/constants';\n\n/**\n * Get first and last elements focusable in an element.\n *\n * @param parentElement The element in which to search focusable elements.\n * @return first and last focusable elements\n */\nfunction getFocusable(parentElement: HTMLElement) {\n const focusableElements = parentElement.querySelectorAll<HTMLElement>(\n 'a[href]:not([tabindex=\"-1\"]), button:not([tabindex=\"-1\"]), textarea:not([tabindex=\"-1\"]), input[type=\"text\"]:not([tabindex=\"-1\"]), input[type=\"radio\"]:not([tabindex=\"-1\"]), input[type=\"checkbox\"]:not([tabindex=\"-1\"]), [tabindex]:not([tabindex=\"-1\"])',\n );\n\n if (focusableElements.length <= 0) {\n return {};\n }\n\n const first = focusableElements[0];\n const last = focusableElements[focusableElements.length - 1];\n return { first, last };\n}\n\n/**\n * Add a key down event handler to the given root element (document.body by default) to trap the move of focus\n * (TAB and SHIFT-TAB keys) inside the given focusZoneElement.\n * Will focus the given focus element when activating the focus trap.\n *\n * @param focusZoneElement The element in which to trap the focus.\n * @param focusElement The element to focus when the focus trap is activated.\n * @param rootElement The element on which the key down event will be placed.\n */\nexport function useFocusTrap(\n focusZoneElement: HTMLElement | null,\n focusElement?: HTMLElement | null,\n rootElement = DOCUMENT?.body,\n): void {\n useEffect(() => {\n if (rootElement && focusZoneElement) {\n (document.activeElement as HTMLElement)?.blur();\n if (focusElement) {\n focusElement.focus();\n }\n\n const onKeyDown = (evt: KeyboardEvent) => {\n const { key } = evt;\n if (key !== 'Tab') {\n return;\n }\n const { first, last } = getFocusable(focusZoneElement);\n\n // Prevent focus switch if no focusable available.\n if (!first) {\n evt.preventDefault();\n return;\n }\n\n if (evt.shiftKey) {\n if (document.activeElement === first) {\n last?.focus();\n evt.preventDefault();\n }\n } else if (document.activeElement === last) {\n first?.focus();\n evt.preventDefault();\n }\n };\n rootElement.addEventListener('keydown', onKeyDown);\n return () => rootElement.removeEventListener('keydown', onKeyDown);\n }\n return undefined;\n }, [focusElement, focusZoneElement, rootElement]);\n}\n"],"names":["getFocusable","parentElement","focusableElements","querySelectorAll","length","first","last","useFocusTrap","focusZoneElement","focusElement","rootElement","DOCUMENT","body","useEffect","document","activeElement","blur","focus","onKeyDown","evt","key","preventDefault","shiftKey","addEventListener","removeEventListener","undefined"],"mappings":";;;AAIA;;;;;;;AAMA,SAASA,YAAT,CAAsBC,aAAtB,EAAkD;AAC9C,MAAMC,iBAAiB,GAAGD,aAAa,CAACE,gBAAd,CACtB,2PADsB,CAA1B;;AAIA,MAAID,iBAAiB,CAACE,MAAlB,IAA4B,CAAhC,EAAmC;AAC/B,WAAO,EAAP;AACH;;AAED,MAAMC,KAAK,GAAGH,iBAAiB,CAAC,CAAD,CAA/B;AACA,MAAMI,IAAI,GAAGJ,iBAAiB,CAACA,iBAAiB,CAACE,MAAlB,GAA2B,CAA5B,CAA9B;AACA,SAAO;AAAEC,IAAAA,KAAK,EAALA,KAAF;AAASC,IAAAA,IAAI,EAAJA;AAAT,GAAP;AACH;AAED;;;;;;;;;;;AASO,SAASC,YAAT,CACHC,gBADG,EAEHC,YAFG,EAIC;AAAA,MADJC,WACI,uEADUC,QACV,aADUA,QACV,uBADUA,QAAQ,CAAEC,IACpB;AACJC,EAAAA,SAAS,CAAC,YAAM;AACZ,QAAIH,WAAW,IAAIF,gBAAnB,EAAqC;AAAA;;AACjC,cAACM,QAAQ,CAACC,aAAV,8CAAyCC,IAAzC;;AACA,UAAIP,YAAJ,EAAkB;AACdA,QAAAA,YAAY,CAACQ,KAAb;AACH;;AAED,UAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,GAAD,EAAwB;AAAA,YAC9BC,GAD8B,GACtBD,GADsB,CAC9BC,GAD8B;;AAEtC,YAAIA,GAAG,KAAK,KAAZ,EAAmB;AACf;AACH;;AAJqC,4BAKdpB,YAAY,CAACQ,gBAAD,CALE;AAAA,YAK9BH,KAL8B,iBAK9BA,KAL8B;AAAA,YAKvBC,IALuB,iBAKvBA,IALuB;;;AAQtC,YAAI,CAACD,KAAL,EAAY;AACRc,UAAAA,GAAG,CAACE,cAAJ;AACA;AACH;;AAED,YAAIF,GAAG,CAACG,QAAR,EAAkB;AACd,cAAIR,QAAQ,CAACC,aAAT,KAA2BV,KAA/B,EAAsC;AAClCC,YAAAA,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAEW,KAAN;AACAE,YAAAA,GAAG,CAACE,cAAJ;AACH;AACJ,SALD,MAKO,IAAIP,QAAQ,CAACC,aAAT,KAA2BT,IAA/B,EAAqC;AACxCD,UAAAA,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEY,KAAP;AACAE,UAAAA,GAAG,CAACE,cAAJ;AACH;AACJ,OAtBD;;AAuBAX,MAAAA,WAAW,CAACa,gBAAZ,CAA6B,SAA7B,EAAwCL,SAAxC;AACA,aAAO;AAAA,eAAMR,WAAW,CAACc,mBAAZ,CAAgC,SAAhC,EAA2CN,SAA3C,CAAN;AAAA,OAAP;AACH;;AACD,WAAOO,SAAP;AACH,GAlCQ,EAkCN,CAAChB,YAAD,EAAeD,gBAAf,EAAiCE,WAAjC,CAlCM,CAAT;AAmCH;;;;"}
1
+ {"version":3,"file":"useFocusTrap.js","sources":["../../../src/hooks/useFocusTrap.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { DOCUMENT } from '@lumx/react/constants';\n\n/** CSS selector listing all tabbable elements. */\nconst TABBABLE_ELEMENTS_SELECTOR = `a[href]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\nbutton:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ntextarea:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"text\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"radio\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"checkbox\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\n[tabindex]:not([tabindex=\"-1\"], [disabled], [aria-disabled])`;\n\n/**\n * Get first and last elements focusable in an element.\n *\n * @param parentElement The element in which to search focusable elements.\n * @return first and last focusable elements\n */\nfunction getFocusable(parentElement: HTMLElement) {\n const focusableElements = parentElement.querySelectorAll<HTMLElement>(TABBABLE_ELEMENTS_SELECTOR);\n\n if (focusableElements.length <= 0) {\n return {};\n }\n\n const first = focusableElements[0];\n const last = focusableElements[focusableElements.length - 1];\n return { first, last };\n}\n\n/**\n * Add a key down event handler to the given root element (document.body by default) to trap the move of focus\n * (TAB and SHIFT-TAB keys) inside the given focusZoneElement.\n * Will focus the given focus element when activating the focus trap.\n *\n * @param focusZoneElement The element in which to trap the focus.\n * @param focusElement The element to focus when the focus trap is activated.\n * @param rootElement The element on which the key down event will be placed.\n */\nexport function useFocusTrap(\n focusZoneElement: HTMLElement | null,\n focusElement?: HTMLElement | null,\n rootElement = DOCUMENT?.body,\n): void {\n useEffect(() => {\n if (rootElement && focusZoneElement) {\n (document.activeElement as HTMLElement)?.blur();\n if (focusElement) {\n focusElement.focus();\n }\n\n const onKeyDown = (evt: KeyboardEvent) => {\n const { key } = evt;\n if (key !== 'Tab') {\n return;\n }\n const focusable = getFocusable(focusZoneElement);\n\n // Prevent focus switch if no focusable available.\n if (!focusable.first) {\n evt.preventDefault();\n return;\n }\n\n if (\n // No previous focus\n !document.activeElement ||\n // Previous focus is at the end of the focus zone.\n (!evt.shiftKey && document.activeElement === focusable.last) ||\n // Previous focus is outside the focus zone\n !focusZoneElement.contains(document.activeElement)\n ) {\n focusable.first.focus();\n evt.preventDefault();\n return;\n }\n\n if (\n // Focus order reversed\n evt.shiftKey &&\n // Previous focus is at the start of the focus zone.\n document.activeElement === focusable.first\n ) {\n focusable.last.focus();\n evt.preventDefault();\n }\n };\n rootElement.addEventListener('keydown', onKeyDown);\n return () => rootElement.removeEventListener('keydown', onKeyDown);\n }\n return undefined;\n }, [focusElement, focusZoneElement, rootElement]);\n}\n"],"names":["TABBABLE_ELEMENTS_SELECTOR","getFocusable","parentElement","focusableElements","querySelectorAll","length","first","last","useFocusTrap","focusZoneElement","focusElement","rootElement","DOCUMENT","body","useEffect","document","activeElement","blur","focus","onKeyDown","evt","key","focusable","preventDefault","shiftKey","contains","addEventListener","removeEventListener","undefined"],"mappings":";;;AAIA;;AACA,IAAMA,0BAA0B,meAAhC;AAQA;;;;;;;AAMA,SAASC,YAAT,CAAsBC,aAAtB,EAAkD;AAC9C,MAAMC,iBAAiB,GAAGD,aAAa,CAACE,gBAAd,CAA4CJ,0BAA5C,CAA1B;;AAEA,MAAIG,iBAAiB,CAACE,MAAlB,IAA4B,CAAhC,EAAmC;AAC/B,WAAO,EAAP;AACH;;AAED,MAAMC,KAAK,GAAGH,iBAAiB,CAAC,CAAD,CAA/B;AACA,MAAMI,IAAI,GAAGJ,iBAAiB,CAACA,iBAAiB,CAACE,MAAlB,GAA2B,CAA5B,CAA9B;AACA,SAAO;AAAEC,IAAAA,KAAK,EAALA,KAAF;AAASC,IAAAA,IAAI,EAAJA;AAAT,GAAP;AACH;AAED;;;;;;;;;;;AASO,SAASC,YAAT,CACHC,gBADG,EAEHC,YAFG,EAIC;AAAA,MADJC,WACI,uEADUC,QACV,aADUA,QACV,uBADUA,QAAQ,CAAEC,IACpB;AACJC,EAAAA,SAAS,CAAC,YAAM;AACZ,QAAIH,WAAW,IAAIF,gBAAnB,EAAqC;AAAA;;AACjC,cAACM,QAAQ,CAACC,aAAV,8CAAyCC,IAAzC;;AACA,UAAIP,YAAJ,EAAkB;AACdA,QAAAA,YAAY,CAACQ,KAAb;AACH;;AAED,UAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,GAAD,EAAwB;AAAA,YAC9BC,GAD8B,GACtBD,GADsB,CAC9BC,GAD8B;;AAEtC,YAAIA,GAAG,KAAK,KAAZ,EAAmB;AACf;AACH;;AACD,YAAMC,SAAS,GAAGrB,YAAY,CAACQ,gBAAD,CAA9B,CALsC;;AAQtC,YAAI,CAACa,SAAS,CAAChB,KAAf,EAAsB;AAClBc,UAAAA,GAAG,CAACG,cAAJ;AACA;AACH;;AAED;AAEI,SAACR,QAAQ,CAACC,aAAV;AAEC,SAACI,GAAG,CAACI,QAAL,IAAiBT,QAAQ,CAACC,aAAT,KAA2BM,SAAS,CAACf,IAFvD;AAIA,SAACE,gBAAgB,CAACgB,QAAjB,CAA0BV,QAAQ,CAACC,aAAnC,CANL,EAOE;AACEM,UAAAA,SAAS,CAAChB,KAAV,CAAgBY,KAAhB;AACAE,UAAAA,GAAG,CAACG,cAAJ;AACA;AACH;;AAED;AAEIH,QAAAA,GAAG,CAACI,QAAJ;AAEAT,QAAAA,QAAQ,CAACC,aAAT,KAA2BM,SAAS,CAAChB,KAJzC,EAKE;AACEgB,UAAAA,SAAS,CAACf,IAAV,CAAeW,KAAf;AACAE,UAAAA,GAAG,CAACG,cAAJ;AACH;AACJ,OAnCD;;AAoCAZ,MAAAA,WAAW,CAACe,gBAAZ,CAA6B,SAA7B,EAAwCP,SAAxC;AACA,aAAO;AAAA,eAAMR,WAAW,CAACgB,mBAAZ,CAAgC,SAAhC,EAA2CR,SAA3C,CAAN;AAAA,OAAP;AACH;;AACD,WAAOS,SAAP;AACH,GA/CQ,EA+CN,CAAClB,YAAD,EAAeD,gBAAf,EAAiCE,WAAjC,CA/CM,CAAT;AAgDH;;;;"}
package/package.json CHANGED
@@ -7,8 +7,8 @@
7
7
  },
8
8
  "dependencies": {
9
9
  "@juggle/resize-observer": "^3.2.0",
10
- "@lumx/core": "^2.2.16",
11
- "@lumx/icons": "^2.2.16",
10
+ "@lumx/core": "^2.2.17",
11
+ "@lumx/icons": "^2.2.17",
12
12
  "@popperjs/core": "^2.5.4",
13
13
  "body-scroll-lock": "^3.1.5",
14
14
  "classnames": "^2.2.6",
@@ -120,6 +120,6 @@
120
120
  "build:storybook": "cd storybook && ./build"
121
121
  },
122
122
  "sideEffects": false,
123
- "version": "2.2.16",
124
- "gitHead": "0dfe6e9bceccdcabcd8c9b41627e01b2ef3332df"
123
+ "version": "2.2.17",
124
+ "gitHead": "61e7475ca5f8a66e8e672cefe8f694b823051afd"
125
125
  }
@@ -333,7 +333,7 @@ export const DialogWithFocusableElements = ({ theme }: any) => {
333
333
  label="Checkbox input"
334
334
  />
335
335
 
336
- <FlexBox orientation="horizontal">
336
+ <FlexBox orientation="horizontal" hAlign="bottom" gap="regular">
337
337
  <DatePickerField
338
338
  locale="fr"
339
339
  label="Start date"
@@ -366,6 +366,8 @@ export const DialogWithFocusableElements = ({ theme }: any) => {
366
366
  ))}
367
367
  </List>
368
368
  </Select>
369
+
370
+ <Button isDisabled>Disabled button (focus ignored)</Button>
369
371
  </FlexBox>
370
372
 
371
373
  {/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */}
@@ -152,6 +152,8 @@ exports[`<Dialog> Snapshots and structure should render story DialogWithFocusabl
152
152
  theme="light"
153
153
  />
154
154
  <FlexBox
155
+ gap="regular"
156
+ hAlign="bottom"
155
157
  orientation="horizontal"
156
158
  >
157
159
  <DatePickerField
@@ -210,6 +212,14 @@ exports[`<Dialog> Snapshots and structure should render story DialogWithFocusabl
210
212
  </ListItem>
211
213
  </List>
212
214
  </Select>
215
+ <Button
216
+ emphasis="high"
217
+ isDisabled={true}
218
+ size="m"
219
+ theme="light"
220
+ >
221
+ Disabled button (focus ignored)
222
+ </Button>
213
223
  </FlexBox>
214
224
  <div
215
225
  tabIndex={0}
@@ -1,5 +1,5 @@
1
1
  import { mdiPencil } from '@lumx/icons';
2
- import { Alignment, Button, Icon, Orientation } from '@lumx/react';
2
+ import { Alignment, Button, Icon, Orientation, Size } from '@lumx/react';
3
3
  import { boolean, number, select, text } from '@storybook/addon-knobs';
4
4
  import fromPairs from 'lodash/fromPairs';
5
5
  import React from 'react';
@@ -18,6 +18,7 @@ const flexViewKnobConfigs: Array<
18
18
  ['fillSpace', boolean],
19
19
  ['noShrink', boolean],
20
20
  ['wrap', boolean],
21
+ ['gap', select, [DEFAULT_PROPS.gap, Size.regular, Size.medium, Size.big, Size.huge]],
21
22
  ['hAlign', select, [DEFAULT_PROPS.hAlign, Alignment.center, Alignment.top, Alignment.bottom]],
22
23
  ['vAlign', select, [DEFAULT_PROPS.vAlign, Alignment.center, Alignment.right, Alignment.left]],
23
24
  ['orientation', select, [undefined, Orientation.horizontal, Orientation.vertical]],
@@ -52,7 +53,7 @@ const setupFlexBoxKnobs = (group: string, knobs: FlexBoxPropName[] = []) =>
52
53
  const flexChildKnobs: FlexBoxPropName[] = ['fillSpace', 'noShrink', 'marginAuto'];
53
54
 
54
55
  export const Flex = () => (
55
- <FlexBox {...setupFlexBoxKnobs('-flex container', ['orientation', 'hAlign', 'vAlign', 'wrap'])}>
56
+ <FlexBox {...setupFlexBoxKnobs('-flex container', ['orientation', 'hAlign', 'vAlign', 'wrap', 'gap'])}>
56
57
  <FlexBox {...setupFlexBoxKnobs('start', flexChildKnobs)}>
57
58
  <Icon icon={mdiPencil} />
58
59
  </FlexBox>
@@ -78,6 +79,16 @@ const vAlign = (prefix?: string) =>
78
79
  Alignment.center,
79
80
  );
80
81
 
82
+ const orientation = (prefix?: string) =>
83
+ select(
84
+ `${prefix ? `${prefix}: ` : ''}Set orientation`,
85
+ [Orientation.vertical, Orientation.horizontal],
86
+ Orientation.vertical,
87
+ );
88
+
89
+ const gapSize = (prefix?: string) =>
90
+ select(`${prefix ? `${prefix}: ` : ''}Gap size`, [Size.regular, Size.medium, Size.big, Size.huge], Size.regular);
91
+
81
92
  export const HorizontalFlex = () => (
82
93
  <FlexBox
83
94
  orientation={Orientation.horizontal}
@@ -122,6 +133,21 @@ export const VerticalFlex = () => (
122
133
  </FlexBox>
123
134
  );
124
135
 
136
+ export const GapSizeFlex = () => (
137
+ <FlexBox orientation={orientation()} gap={gapSize()}>
138
+ <Button>Item 1</Button>
139
+ <FlexBox vAlign={Alignment.left}>
140
+ <Button>Item 2</Button>
141
+ </FlexBox>
142
+ <FlexBox>
143
+ <Button>Item 3</Button>
144
+ </FlexBox>
145
+ <FlexBox vAlign={Alignment.right}>
146
+ <Button>Item 4</Button>
147
+ </FlexBox>
148
+ </FlexBox>
149
+ );
150
+
125
151
  export const WrapFlex = () => (
126
152
  <FlexBox
127
153
  orientation={Orientation.horizontal}
@@ -6,7 +6,7 @@ import React, { forwardRef, ReactNode } from 'react';
6
6
  import { Size } from '..';
7
7
 
8
8
  export type MarginAutoAlignment = Extract<Alignment, 'top' | 'bottom' | 'right' | 'left'>;
9
- export type GapSize = Extract<Size, 'regular' | 'big' | 'huge'>;
9
+ export type GapSize = Extract<Size, 'regular' | 'medium' | 'big' | 'huge'>;
10
10
 
11
11
  /**
12
12
  * Defines the props of the component.
@@ -89,6 +89,86 @@ Array [
89
89
  ]
90
90
  `;
91
91
 
92
+ exports[`<FlexBox> Snapshots and structure should render story 'GapSizeFlex' 1`] = `
93
+ Array [
94
+ <div
95
+ className="lumx-flex-box lumx-flex-box--orientation-vertical lumx-flex-box--gap-regular"
96
+ >
97
+ <Button
98
+ emphasis="high"
99
+ size="m"
100
+ theme="light"
101
+ >
102
+ Item 1
103
+ </Button>
104
+ <FlexBox
105
+ vAlign="left"
106
+ >
107
+ <Button
108
+ emphasis="high"
109
+ size="m"
110
+ theme="light"
111
+ >
112
+ Item 2
113
+ </Button>
114
+ </FlexBox>
115
+ <FlexBox>
116
+ <Button
117
+ emphasis="high"
118
+ size="m"
119
+ theme="light"
120
+ >
121
+ Item 3
122
+ </Button>
123
+ </FlexBox>
124
+ <FlexBox
125
+ vAlign="right"
126
+ >
127
+ <Button
128
+ emphasis="high"
129
+ size="m"
130
+ theme="light"
131
+ >
132
+ Item 4
133
+ </Button>
134
+ </FlexBox>
135
+ </div>,
136
+ <div
137
+ className="lumx-flex-box lumx-flex-box--orientation-horizontal lumx-flex-box--v-align-left"
138
+ >
139
+ <Button
140
+ emphasis="high"
141
+ size="m"
142
+ theme="light"
143
+ >
144
+ Item 2
145
+ </Button>
146
+ </div>,
147
+ <div
148
+ className="lumx-flex-box"
149
+ >
150
+ <Button
151
+ emphasis="high"
152
+ size="m"
153
+ theme="light"
154
+ >
155
+ Item 3
156
+ </Button>
157
+ </div>,
158
+ <div
159
+ className="lumx-flex-box lumx-flex-box--orientation-horizontal lumx-flex-box--v-align-right"
160
+ >
161
+ <Button
162
+ emphasis="high"
163
+ size="m"
164
+ theme="light"
165
+ >
166
+ Item 4
167
+ </Button>
168
+ </div>,
169
+ ]
170
+ `;
171
+
92
172
  exports[`<FlexBox> Snapshots and structure should render story 'HorizontalFlex' 1`] = `
93
173
  Array [
94
174
  <div
@@ -67,6 +67,7 @@ export const Size = {
67
67
  xxl: 'xxl',
68
68
  tiny: 'tiny',
69
69
  regular: 'regular',
70
+ medium: 'medium',
70
71
  big: 'big',
71
72
  huge: 'huge',
72
73
  } as const;
@@ -2,6 +2,15 @@ import { useEffect } from 'react';
2
2
 
3
3
  import { DOCUMENT } from '@lumx/react/constants';
4
4
 
5
+ /** CSS selector listing all tabbable elements. */
6
+ const TABBABLE_ELEMENTS_SELECTOR = `a[href]:not([tabindex="-1"], [disabled], [aria-disabled]),
7
+ button:not([tabindex="-1"], [disabled], [aria-disabled]),
8
+ textarea:not([tabindex="-1"], [disabled], [aria-disabled]),
9
+ input[type="text"]:not([tabindex="-1"], [disabled], [aria-disabled]),
10
+ input[type="radio"]:not([tabindex="-1"], [disabled], [aria-disabled]),
11
+ input[type="checkbox"]:not([tabindex="-1"], [disabled], [aria-disabled]),
12
+ [tabindex]:not([tabindex="-1"], [disabled], [aria-disabled])`;
13
+
5
14
  /**
6
15
  * Get first and last elements focusable in an element.
7
16
  *
@@ -9,9 +18,7 @@ import { DOCUMENT } from '@lumx/react/constants';
9
18
  * @return first and last focusable elements
10
19
  */
11
20
  function getFocusable(parentElement: HTMLElement) {
12
- const focusableElements = parentElement.querySelectorAll<HTMLElement>(
13
- 'a[href]:not([tabindex="-1"]), button:not([tabindex="-1"]), textarea:not([tabindex="-1"]), input[type="text"]:not([tabindex="-1"]), input[type="radio"]:not([tabindex="-1"]), input[type="checkbox"]:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"])',
14
- );
21
+ const focusableElements = parentElement.querySelectorAll<HTMLElement>(TABBABLE_ELEMENTS_SELECTOR);
15
22
 
16
23
  if (focusableElements.length <= 0) {
17
24
  return {};
@@ -48,21 +55,34 @@ export function useFocusTrap(
48
55
  if (key !== 'Tab') {
49
56
  return;
50
57
  }
51
- const { first, last } = getFocusable(focusZoneElement);
58
+ const focusable = getFocusable(focusZoneElement);
52
59
 
53
60
  // Prevent focus switch if no focusable available.
54
- if (!first) {
61
+ if (!focusable.first) {
62
+ evt.preventDefault();
63
+ return;
64
+ }
65
+
66
+ if (
67
+ // No previous focus
68
+ !document.activeElement ||
69
+ // Previous focus is at the end of the focus zone.
70
+ (!evt.shiftKey && document.activeElement === focusable.last) ||
71
+ // Previous focus is outside the focus zone
72
+ !focusZoneElement.contains(document.activeElement)
73
+ ) {
74
+ focusable.first.focus();
55
75
  evt.preventDefault();
56
76
  return;
57
77
  }
58
78
 
59
- if (evt.shiftKey) {
60
- if (document.activeElement === first) {
61
- last?.focus();
62
- evt.preventDefault();
63
- }
64
- } else if (document.activeElement === last) {
65
- first?.focus();
79
+ if (
80
+ // Focus order reversed
81
+ evt.shiftKey &&
82
+ // Previous focus is at the start of the focus zone.
83
+ document.activeElement === focusable.first
84
+ ) {
85
+ focusable.last.focus();
66
86
  evt.preventDefault();
67
87
  }
68
88
  };
package/types.d.ts CHANGED
@@ -95,6 +95,7 @@ export declare const Size: {
95
95
  readonly xxl: "xxl";
96
96
  readonly tiny: "tiny";
97
97
  readonly regular: "regular";
98
+ readonly medium: "medium";
98
99
  readonly big: "big";
99
100
  readonly huge: "huge";
100
101
  };
@@ -1091,7 +1092,7 @@ export interface FlagProps extends GenericProps {
1091
1092
  */
1092
1093
  export declare const Flag: Comp<FlagProps, HTMLDivElement>;
1093
1094
  export declare type MarginAutoAlignment = Extract<Alignment, "top" | "bottom" | "right" | "left">;
1094
- export declare type GapSize = Extract<Size, "regular" | "big" | "huge">;
1095
+ export declare type GapSize = Extract<Size, "regular" | "medium" | "big" | "huge">;
1095
1096
  /**
1096
1097
  * Defines the props of the component.
1097
1098
  */