@pega/cosmos-react-core 5.0.0-dev.12.5 → 5.0.0-dev.13.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/lib/components/AppShell/AppShell.js +1 -1
- package/lib/components/AppShell/AppShell.js.map +1 -1
- package/lib/components/AppShell/Operator.d.ts.map +1 -1
- package/lib/components/AppShell/Operator.js +5 -2
- package/lib/components/AppShell/Operator.js.map +1 -1
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.js +1 -1
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.js.map +1 -1
- package/lib/components/DateTime/DateTime.types.d.ts +1 -4
- package/lib/components/DateTime/DateTime.types.d.ts.map +1 -1
- package/lib/components/DateTime/DateTime.types.js.map +1 -1
- package/lib/components/DateTime/Input/DateInput.d.ts +3 -5
- package/lib/components/DateTime/Input/DateInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateInput.js +2 -17
- package/lib/components/DateTime/Input/DateInput.js.map +1 -1
- package/lib/components/DateTime/Input/DateRangeInput.d.ts +2 -4
- package/lib/components/DateTime/Input/DateRangeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateRangeInput.js +33 -84
- package/lib/components/DateTime/Input/DateRangeInput.js.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.d.ts +3 -0
- package/lib/components/DateTime/Input/DateTimeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.js +17 -36
- package/lib/components/DateTime/Input/DateTimeInput.js.map +1 -1
- package/lib/components/DateTime/Input/PartInput.js +1 -1
- package/lib/components/DateTime/Input/PartInput.js.map +1 -1
- package/lib/components/DateTime/Input/TimeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/TimeInput.js +13 -24
- package/lib/components/DateTime/Input/TimeInput.js.map +1 -1
- package/lib/components/DateTime/Input/TimeRangeInput.d.ts +2 -4
- package/lib/components/DateTime/Input/TimeRangeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/TimeRangeInput.js +25 -64
- package/lib/components/DateTime/Input/TimeRangeInput.js.map +1 -1
- package/lib/components/DateTime/Input/utils.d.ts +2 -1
- package/lib/components/DateTime/Input/utils.d.ts.map +1 -1
- package/lib/components/DateTime/Input/utils.js +13 -10
- package/lib/components/DateTime/Input/utils.js.map +1 -1
- package/lib/components/DateTime/Picker/TimePicker.js +1 -1
- package/lib/components/DateTime/Picker/TimePicker.js.map +1 -1
- package/lib/components/Menu/MenuItem.js +1 -1
- package/lib/components/Menu/MenuItem.js.map +1 -1
- package/lib/components/MenuButton/MenuButton.d.ts.map +1 -1
- package/lib/components/MenuButton/MenuButton.js +8 -4
- package/lib/components/MenuButton/MenuButton.js.map +1 -1
- package/lib/components/Modal/Modal.d.ts.map +1 -1
- package/lib/components/Modal/Modal.js +2 -9
- package/lib/components/Modal/Modal.js.map +1 -1
- package/lib/components/Modal/Modal.styles.d.ts +1 -3
- package/lib/components/Modal/Modal.styles.d.ts.map +1 -1
- package/lib/components/Modal/Modal.styles.js +3 -17
- package/lib/components/Modal/Modal.styles.js.map +1 -1
- package/lib/components/MultiStepForm/MultiStepForm.d.ts.map +1 -1
- package/lib/components/MultiStepForm/MultiStepForm.js +34 -53
- package/lib/components/MultiStepForm/MultiStepForm.js.map +1 -1
- package/lib/components/ShortcutManager/ShortcutManager.js +1 -1
- package/lib/components/ShortcutManager/ShortcutManager.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +3 -1
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/i18n/default.d.ts +3 -1
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +3 -2
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +3 -1
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuButton.d.ts","sourceRoot":"","sources":["../../../src/components/MenuButton/MenuButton.tsx"],"names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;AAiKD,wBAA6D"}
|
|
@@ -66,18 +66,22 @@ const MenuButton = forwardRef(function MenuButton(props, ref) {
|
|
|
66
66
|
}, buttonRef);
|
|
67
67
|
const { rtl } = useDirection();
|
|
68
68
|
return (_jsxs(_Fragment, { children: [_jsx(Button, { "data-testid": testIds.root, as: StyledMenuButton, "aria-label": text, ...restProps, id: id, ref: buttonRef, "aria-expanded": isOpen, "aria-haspopup": 'menu', "aria-controls": `${id}-popover`, label: iconOnly && !isOpen ? text : undefined, onClick: (e) => {
|
|
69
|
-
//
|
|
70
|
-
const
|
|
69
|
+
// e.detail is 0 when triggered by keyboard.
|
|
70
|
+
const mouseClick = e.detail > 0;
|
|
71
71
|
// Close the menu if it is open and either:
|
|
72
72
|
// It is a *mouse* click on the button.
|
|
73
73
|
// Or, the menu mode is not multiselect.
|
|
74
|
-
if (isOpen && (
|
|
74
|
+
if (isOpen && (mouseClick || menu?.mode !== 'multi-select')) {
|
|
75
75
|
setIsOpen(false);
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
78
78
|
setIsOpen(true);
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
// If the menu is closed or the user mouse clicks.
|
|
81
|
+
// This avoids Enter key firing onClick when selecting a menu item.
|
|
82
|
+
if (!isOpen || mouseClick) {
|
|
83
|
+
onClick?.(e);
|
|
84
|
+
}
|
|
81
85
|
}, icon: iconOnly, children: _jsxs(Flex, { as: StyledMenuButtonChildren, container: { alignItems: 'center', gap: 1 }, children: [icon && _jsx(Icon, { name: icon }), !iconOnly && (_jsxs(_Fragment, { children: [text && _jsx(Text, { children: text }), typeof count === 'number' && _jsx(Count, { children: count }), text && _jsx(Icon, { name: 'arrow-micro-down' })] }))] }) }), _jsx(StyledMenuButtonPopover, { placement: rtl ? 'bottom-end' : 'bottom-start', hideOnTargetHidden: true, ...popover, id: `${id}-popover`, show: !!menu && isOpen, target: buttonRef.current, ref: popoverRef, children: menu && (_jsx(Menu, { testId: testIds.root, ...menu, ref: menuRef, items: menu.items, onItemClick: (itemId, e) => {
|
|
82
86
|
if (menu.mode !== 'multi-select' &&
|
|
83
87
|
e
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuButton.js","sourceRoot":"","sources":["../../../src/components/MenuButton/MenuButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAS1D,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,cAAc,EACd,YAAY,EACZ,UAAU,EACV,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,OAAO,EAAE,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,kBAAkB,MAAM,qCAAqC,CAAC;AAC1E,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,YAAY,CAAC,kBAAkB,CAAC,CAAC;AA8BjC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CACpC,CAAC,EACC,KAAK,EAAE,EACL,IAAI,EAAE,EAAE,OAAO,EAAE,EAClB,EACF,EAAE,EAAE;IACH,OAAO,GAAG,CAAA;aACD,OAAO;;;;;YAKR,a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AAQ,EAC3B,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAC,KAAK,cAAE,KAAK,GAAS,EACnD,IAAI,IAAI,KAAC,IAAI,IAAC,IAAI,EAAC,kBAAkB,GAAG,IACxC,CACJ,IACI,GACA,EACT,KAAC,uBAAuB,IACtB,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc,EAC9C,kBAAkB,WACd,OAAO,EACX,EAAE,EAAE,GAAG,EAAE,UAAU,EACnB,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,MAAM,EACtB,MAAM,EAAE,SAAS,CAAC,OAAO,EACzB,GAAG,EAAE,UAAU,YAEd,IAAI,IAAI,CACP,KAAC,IAAI,IACH,MAAM,EAAE,OAAO,CAAC,IAAI,KAChB,IAAI,EACR,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,WAAW,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBACzB,IACE,IAAI,CAAC,IAAI,KAAK,cAAc;4BAC3B,CAAgF;iCAC9E,MAAM,GAAG,CAAC,EACb;4BACA,SAAS,CAAC,KAAK,CAAC,CAAC;yBAClB;wBACD,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;oBAChC,CAAC,EACD,cAAc,EAAE,SAAS,CAAC,OAAO,IAAI,SAAS,GAC9C,CACH,GACuB,IACzB,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC","sourcesContent":["import { forwardRef, useState, useCallback } from 'react';\nimport type {\n FunctionComponent,\n MouseEventHandler,\n MouseEvent,\n UIEvent,\n PropsWithoutRef,\n KeyboardEventHandler\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { BaseProps, ForwardProps, NoChildrenProp, OmitStrict, TestIdProp } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport {\n useConsolidatedRef,\n useUID,\n useFocusWithin,\n useDirection,\n useTestIds,\n useEscape\n} from '../../hooks';\nimport Button, { StyledButton } from '../Button';\nimport type { ButtonProps } from '../Button';\nimport Popover, { StyledPopover } from '../Popover';\nimport type { PopoverProps } from '../Popover';\nimport Menu from '../Menu';\nimport type { AcceptedMouseEventElement, MenuProps } from '../Menu/Menu.types';\nimport Icon, { registerIcon, StyledIcon } from '../Icon';\nimport * as arrowMicroDownIcon from '../Icon/icons/arrow-micro-down.icon';\nimport Text, { StyledText } from '../Text';\nimport Flex from '../Flex';\nimport { Count } from '../Badges';\nimport type { CountProps } from '../Badges/Count';\nimport { withTestIds } from '../../utils';\n\nimport { getMenuButtonTestIds } from './MenuButton.test-ids';\n\nregisterIcon(arrowMicroDownIcon);\n\nexport interface MenuButtonProps extends BaseProps, NoChildrenProp, TestIdProp {\n /** The text for the MenuButton also used to set the aria-label. */\n text: string;\n /**\n * Determines the Button variant for the MenuButton.\n * @default 'secondary'\n */\n variant?: ButtonProps['variant'];\n /** The name of the icon for the MenuButton. */\n icon?: string;\n /** Only display the icon. The text prop will be forwarded to a tooltip. */\n iconOnly?: ButtonProps['icon'];\n /** The total count representing the list data which was selected. */\n count?: CountProps['children'];\n /** The click handler for the MenuButton. */\n onClick?: MouseEventHandler;\n /** Menu related props. */\n menu?: MenuProps;\n /** Popover related props. */\n popover?: OmitStrict<PopoverProps, 'show' | 'target' | 'children'>;\n /** DOM id for the button element. */\n id?: string;\n /** Ref for the button element. */\n ref?: ButtonProps['ref'];\n /** The keydown handler for the MenuButton. */\n onKeyDown?: KeyboardEventHandler;\n}\n\nconst StyledMenuButton = styled.button(\n ({\n theme: {\n base: { spacing }\n }\n }) => {\n return css`\n gap: ${spacing};\n flex-shrink: 0;\n white-space: nowrap;\n max-width: 100%;\n\n & + ${StyledPopover} + ${StyledButton} {\n margin-inline-start: ${spacing};\n }\n `;\n }\n);\n\nStyledMenuButton.defaultProps = defaultThemeProp;\n\nconst StyledMenuButtonChildren = styled.span(({ theme }) => {\n return css`\n max-width: 100%;\n\n ${StyledText} {\n text-overflow: ellipsis;\n overflow: hidden;\n }\n\n ${StyledIcon}:last-child:not(:first-child) {\n /* Offsets the flex gap to make the down arrow appear to trail the text. */\n margin-inline-start: -${theme.base.spacing};\n }\n `;\n});\n\nconst StyledMenuButtonPopover = styled(Popover)`\n min-width: 20ch;\n`;\n\nconst MenuButton: FunctionComponent<ForwardProps & MenuButtonProps> = forwardRef(\n function MenuButton(props: PropsWithoutRef<MenuButtonProps>, ref: MenuButtonProps['ref']) {\n const uid = useUID();\n const {\n testId,\n id = uid,\n text,\n menu,\n popover,\n onClick,\n icon,\n count,\n iconOnly = false,\n ...restProps\n } = props;\n const testIds = useTestIds(testId, getMenuButtonTestIds);\n const [isOpen, setIsOpen] = useState(false);\n\n const buttonRef = useConsolidatedRef(ref);\n const popoverRef = useConsolidatedRef<HTMLDivElement>(popover?.ref);\n const menuRef = useConsolidatedRef<HTMLDivElement>(menu?.ref);\n\n // FIXME: Type assertion required for issue in useFocusWithin generic\n useFocusWithin<HTMLElement>(\n [popoverRef, buttonRef],\n useCallback(isFocused => {\n if (!isFocused) setIsOpen(false);\n }, [])\n );\n\n useEscape(e => {\n if (isOpen) {\n setIsOpen(false);\n e.stopPropagation();\n }\n }, buttonRef);\n\n const { rtl } = useDirection();\n\n return (\n <>\n <Button\n data-testid={testIds.root}\n as={StyledMenuButton}\n aria-label={text}\n {...restProps}\n id={id}\n ref={buttonRef}\n aria-expanded={isOpen}\n aria-haspopup='menu'\n aria-controls={`${id}-popover`}\n label={iconOnly && !isOpen ? text : undefined}\n onClick={(e: MouseEvent<HTMLButtonElement> & UIEvent<HTMLButtonElement>) => {\n // clickCount is 0 when triggered by keyboard.\n const clickCount = e.detail;\n\n // Close the menu if it is open and either:\n // It is a *mouse* click on the button.\n // Or, the menu mode is not multiselect.\n if (isOpen && (clickCount > 0 || menu?.mode !== 'multi-select')) {\n setIsOpen(false);\n } else {\n setIsOpen(true);\n }\n\n onClick?.(e);\n }}\n icon={iconOnly}\n >\n <Flex as={StyledMenuButtonChildren} container={{ alignItems: 'center', gap: 1 }}>\n {icon && <Icon name={icon} />}\n {!iconOnly && (\n <>\n {text && <Text>{text}</Text>}\n {typeof count === 'number' && <Count>{count}</Count>}\n {text && <Icon name='arrow-micro-down' />}\n </>\n )}\n </Flex>\n </Button>\n <StyledMenuButtonPopover\n placement={rtl ? 'bottom-end' : 'bottom-start'}\n hideOnTargetHidden\n {...popover}\n id={`${id}-popover`}\n show={!!menu && isOpen}\n target={buttonRef.current}\n ref={popoverRef}\n >\n {menu && (\n <Menu\n testId={testIds.root}\n {...menu}\n ref={menuRef}\n items={menu.items}\n onItemClick={(itemId, e) => {\n if (\n menu.mode !== 'multi-select' &&\n (e as MouseEvent<AcceptedMouseEventElement> & UIEvent<AcceptedMouseEventElement>)\n .detail > 0\n ) {\n setIsOpen(false);\n }\n menu.onItemClick?.(itemId, e);\n }}\n focusControlEl={buttonRef.current || undefined}\n />\n )}\n </StyledMenuButtonPopover>\n </>\n );\n }\n);\n\nexport default withTestIds(MenuButton, getMenuButtonTestIds);\n"]}
|
|
1
|
+
{"version":3,"file":"MenuButton.js","sourceRoot":"","sources":["../../../src/components/MenuButton/MenuButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAS1D,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,cAAc,EACd,YAAY,EACZ,UAAU,EACV,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,OAAO,EAAE,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,IAAI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IAAI,CAAC,KAAK,EACjB,WAAW,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBACzB,IACE,IAAI,CAAC,IAAI,KAAK,cAAc;4BAC3B,CAAgF;iCAC9E,MAAM,GAAG,CAAC,EACb;4BACA,SAAS,CAAC,KAAK,CAAC,CAAC;yBAClB;wBACD,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;oBAChC,CAAC,EACD,cAAc,EAAE,SAAS,CAAC,OAAO,IAAI,SAAS,GAC9C,CACH,GACuB,IACzB,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC","sourcesContent":["import { forwardRef, useState, useCallback } from 'react';\nimport type {\n FunctionComponent,\n MouseEventHandler,\n MouseEvent,\n UIEvent,\n PropsWithoutRef,\n KeyboardEventHandler\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { BaseProps, ForwardProps, NoChildrenProp, OmitStrict, TestIdProp } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport {\n useConsolidatedRef,\n useUID,\n useFocusWithin,\n useDirection,\n useTestIds,\n useEscape\n} from '../../hooks';\nimport Button, { StyledButton } from '../Button';\nimport type { ButtonProps } from '../Button';\nimport Popover, { StyledPopover } from '../Popover';\nimport type { PopoverProps } from '../Popover';\nimport Menu from '../Menu';\nimport type { AcceptedMouseEventElement, MenuProps } from '../Menu/Menu.types';\nimport Icon, { registerIcon, StyledIcon } from '../Icon';\nimport * as arrowMicroDownIcon from '../Icon/icons/arrow-micro-down.icon';\nimport Text, { StyledText } from '../Text';\nimport Flex from '../Flex';\nimport { Count } from '../Badges';\nimport type { CountProps } from '../Badges/Count';\nimport { withTestIds } from '../../utils';\n\nimport { getMenuButtonTestIds } from './MenuButton.test-ids';\n\nregisterIcon(arrowMicroDownIcon);\n\nexport interface MenuButtonProps extends BaseProps, NoChildrenProp, TestIdProp {\n /** The text for the MenuButton also used to set the aria-label. */\n text: string;\n /**\n * Determines the Button variant for the MenuButton.\n * @default 'secondary'\n */\n variant?: ButtonProps['variant'];\n /** The name of the icon for the MenuButton. */\n icon?: string;\n /** Only display the icon. The text prop will be forwarded to a tooltip. */\n iconOnly?: ButtonProps['icon'];\n /** The total count representing the list data which was selected. */\n count?: CountProps['children'];\n /** The click handler for the MenuButton. */\n onClick?: MouseEventHandler;\n /** Menu related props. */\n menu?: MenuProps;\n /** Popover related props. */\n popover?: OmitStrict<PopoverProps, 'show' | 'target' | 'children'>;\n /** DOM id for the button element. */\n id?: string;\n /** Ref for the button element. */\n ref?: ButtonProps['ref'];\n /** The keydown handler for the MenuButton. */\n onKeyDown?: KeyboardEventHandler;\n}\n\nconst StyledMenuButton = styled.button(\n ({\n theme: {\n base: { spacing }\n }\n }) => {\n return css`\n gap: ${spacing};\n flex-shrink: 0;\n white-space: nowrap;\n max-width: 100%;\n\n & + ${StyledPopover} + ${StyledButton} {\n margin-inline-start: ${spacing};\n }\n `;\n }\n);\n\nStyledMenuButton.defaultProps = defaultThemeProp;\n\nconst StyledMenuButtonChildren = styled.span(({ theme }) => {\n return css`\n max-width: 100%;\n\n ${StyledText} {\n text-overflow: ellipsis;\n overflow: hidden;\n }\n\n ${StyledIcon}:last-child:not(:first-child) {\n /* Offsets the flex gap to make the down arrow appear to trail the text. */\n margin-inline-start: -${theme.base.spacing};\n }\n `;\n});\n\nconst StyledMenuButtonPopover = styled(Popover)`\n min-width: 20ch;\n`;\n\nconst MenuButton: FunctionComponent<ForwardProps & MenuButtonProps> = forwardRef(\n function MenuButton(props: PropsWithoutRef<MenuButtonProps>, ref: MenuButtonProps['ref']) {\n const uid = useUID();\n const {\n testId,\n id = uid,\n text,\n menu,\n popover,\n onClick,\n icon,\n count,\n iconOnly = false,\n ...restProps\n } = props;\n const testIds = useTestIds(testId, getMenuButtonTestIds);\n const [isOpen, setIsOpen] = useState(false);\n\n const buttonRef = useConsolidatedRef(ref);\n const popoverRef = useConsolidatedRef<HTMLDivElement>(popover?.ref);\n const menuRef = useConsolidatedRef<HTMLDivElement>(menu?.ref);\n\n // FIXME: Type assertion required for issue in useFocusWithin generic\n useFocusWithin<HTMLElement>(\n [popoverRef, buttonRef],\n useCallback(isFocused => {\n if (!isFocused) setIsOpen(false);\n }, [])\n );\n\n useEscape(e => {\n if (isOpen) {\n setIsOpen(false);\n e.stopPropagation();\n }\n }, buttonRef);\n\n const { rtl } = useDirection();\n\n return (\n <>\n <Button\n data-testid={testIds.root}\n as={StyledMenuButton}\n aria-label={text}\n {...restProps}\n id={id}\n ref={buttonRef}\n aria-expanded={isOpen}\n aria-haspopup='menu'\n aria-controls={`${id}-popover`}\n label={iconOnly && !isOpen ? text : undefined}\n onClick={(e: MouseEvent<HTMLButtonElement> & UIEvent<HTMLButtonElement>) => {\n // e.detail is 0 when triggered by keyboard.\n const mouseClick = e.detail > 0;\n\n // Close the menu if it is open and either:\n // It is a *mouse* click on the button.\n // Or, the menu mode is not multiselect.\n if (isOpen && (mouseClick || menu?.mode !== 'multi-select')) {\n setIsOpen(false);\n } else {\n setIsOpen(true);\n }\n\n // If the menu is closed or the user mouse clicks.\n // This avoids Enter key firing onClick when selecting a menu item.\n if (!isOpen || mouseClick) {\n onClick?.(e);\n }\n }}\n icon={iconOnly}\n >\n <Flex as={StyledMenuButtonChildren} container={{ alignItems: 'center', gap: 1 }}>\n {icon && <Icon name={icon} />}\n {!iconOnly && (\n <>\n {text && <Text>{text}</Text>}\n {typeof count === 'number' && <Count>{count}</Count>}\n {text && <Icon name='arrow-micro-down' />}\n </>\n )}\n </Flex>\n </Button>\n <StyledMenuButtonPopover\n placement={rtl ? 'bottom-end' : 'bottom-start'}\n hideOnTargetHidden\n {...popover}\n id={`${id}-popover`}\n show={!!menu && isOpen}\n target={buttonRef.current}\n ref={popoverRef}\n >\n {menu && (\n <Menu\n testId={testIds.root}\n {...menu}\n ref={menuRef}\n items={menu.items}\n onItemClick={(itemId, e) => {\n if (\n menu.mode !== 'multi-select' &&\n (e as MouseEvent<AcceptedMouseEventElement> & UIEvent<AcceptedMouseEventElement>)\n .detail > 0\n ) {\n setIsOpen(false);\n }\n menu.onItemClick?.(itemId, e);\n }}\n focusControlEl={buttonRef.current || undefined}\n />\n )}\n </StyledMenuButtonPopover>\n </>\n );\n }\n);\n\nexport default withTestIds(MenuButton, getMenuButtonTestIds);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/Modal.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAOf,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/Modal.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAOf,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAoBhD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAWhD,QAAA,MAAM,KAAK,EAAE,iBAAiB,CAAC,UAAU,GAAG,YAAY,CA8RtD,CAAC;AAEH,eAAe,KAAK,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { getFocusables } from '../../utils';
|
|
|
5
5
|
import Backdrop from '../Backdrop';
|
|
6
6
|
import Flex from '../Flex';
|
|
7
7
|
import Button from '../Button';
|
|
8
|
-
import { useConsolidatedRef, useI18n, useOuterEvent, useUID, useFocusTrap, usePrevious, useModalContext, useEvent
|
|
8
|
+
import { useConsolidatedRef, useI18n, useOuterEvent, useUID, useFocusTrap, usePrevious, useModalContext, useEvent } from '../../hooks';
|
|
9
9
|
import Icon, { registerIcon } from '../Icon';
|
|
10
10
|
import * as timesIcon from '../Icon/icons/times.icon';
|
|
11
11
|
import * as minusIcon from '../Icon/icons/minus.icon';
|
|
@@ -98,7 +98,6 @@ const Modal = forwardRef(function Modal(props, ref) {
|
|
|
98
98
|
setFocus();
|
|
99
99
|
}
|
|
100
100
|
}, [progress]);
|
|
101
|
-
const isModalSmallOrAbove = useBreakpoint('sm', { breakpointRef: modalRef });
|
|
102
101
|
const maximized = stretch || state === 'maximized';
|
|
103
102
|
const modal = (_jsxs(Flex, { ...restProps, container: { direction: 'column' }, ref: modalRef, as: StyledModal, forwardedAs: as, onClick: (e) => e.stopPropagation(), onKeyDown: onModalKeyDown, alert: alert, role: alert ? 'alertdialog' : 'dialog', stretch: maximized, center: center, "aria-labelledby": `${id}-heading`, "aria-describedby": alert ? `${id}-content` : undefined, "aria-modal": state === 'docked' ? 'false' : 'true', state: state, "aria-busy": progress ? 'true' : 'false', children: [_jsxs(Flex, { container: { justify: 'between', alignItems: 'center', gap: 1 }, item: { shrink: 0 }, as: StyledModalHeader, hasAction: minimizable || dismissible, children: [_jsxs(Flex, { container: { alignItems: 'center', gap: 1 }, as: Text, variant: 'h2', id: `${id}-heading`, children: [_jsx("span", { children: heading }), typeof count === 'number' && _jsx(Count, { children: count })] }), _jsxs(Flex, { container: true, children: [maximizable && !alert && state !== 'maximized' && (_jsx(Button, { icon: true, variant: 'simple', label: t('modal_maximize'), onKeyDown: onHeaderActionKeyDown, onClick: () => {
|
|
104
103
|
if (onRequestMaximize?.() !== false) {
|
|
@@ -114,13 +113,7 @@ const Modal = forwardRef(function Modal(props, ref) {
|
|
|
114
113
|
}
|
|
115
114
|
}, children: _jsx(Icon, { name: 'minus' }) })), dismissible && !alert && (_jsx(Button, { icon: true, variant: 'simple', label: t('modal_close'), onKeyDown: onHeaderActionKeyDown, onClick: tryDismiss, ref: closeButtonRef, children: _jsx(Icon, { name: 'times' }) }))] })] }), _jsxs(Flex, { item: { grow: 1 }, as: StyledModalContent, ref: modalContentRef, style: modalContentRef.current
|
|
116
115
|
? { '--scroll-top': `${modalContentRef.current.scrollTop}px` }
|
|
117
|
-
: undefined, children: [children && (_jsx(StyledModalChildrenWrap, { id: `${id}-content`, inert: progress ? '' : undefined, children: children })), _jsx(Progress, { visible: !!progress, focusOnVisible: true, placement: 'local', message: typeof progress === 'object' ? progress.message : t('loading') })] }), actions && (_jsx(Flex, { container: {
|
|
118
|
-
pad: [2.5, 3, 3],
|
|
119
|
-
gap: 1,
|
|
120
|
-
...(isModalSmallOrAbove
|
|
121
|
-
? { direction: 'row', justify: 'end' }
|
|
122
|
-
: { direction: 'column' })
|
|
123
|
-
}, item: { shrink: 0 }, as: StyledModalActions, isSmallOrAbove: isModalSmallOrAbove, children: actions }))] }));
|
|
116
|
+
: undefined, children: [children && (_jsx(StyledModalChildrenWrap, { id: `${id}-content`, inert: progress ? '' : undefined, children: children })), _jsx(Progress, { visible: !!progress, focusOnVisible: true, placement: 'local', message: typeof progress === 'object' ? progress.message : t('loading') })] }), actions && (_jsx(Flex, { container: { justify: 'between' }, item: { shrink: 0 }, as: StyledModalActions, children: actions }))] }));
|
|
124
117
|
const renderModal = state === 'docked' ? (modal) : (_jsx(Backdrop, { ref: backdropRef, container: {
|
|
125
118
|
alignItems: center || maximized ? 'center' : 'start'
|
|
126
119
|
}, transitionSpeed: 'slow', open: state === 'open' || state === 'maximized', onBeforeTransitionIn: onBeforeOpen, onAfterTransitionIn: onAfterOpen, onBeforeTransitionOut: onBeforeClose, onAfterTransitionOut: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../../src/components/Modal/Modal.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AASnE,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,MAAM,MAAM,WAA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C,WAAW,CAAC;AAC5F,CAAC,CAAC,CAAC;AAEH,eAAe,KAAK,CAAC","sourcesContent":["import { forwardRef, useEffect, useRef, useCallback } from 'react';\nimport type {\n FunctionComponent,\n PropsWithoutRef,\n Ref,\n MouseEvent,\n KeyboardEvent as ReactKeyboardEvent\n} from 'react';\n\nimport Progress from '../Progress';\nimport { getFocusables } from '../../utils';\nimport Backdrop from '../Backdrop';\nimport Flex from '../Flex';\nimport Button from '../Button';\nimport type { ForwardProps } from '../../types';\nimport {\n useConsolidatedRef,\n useI18n,\n useOuterEvent,\n useUID,\n useFocusTrap,\n usePrevious,\n useModalContext,\n useEvent,\n useBreakpoint\n} from '../../hooks';\nimport Icon, { registerIcon } from '../Icon';\nimport * as timesIcon from '../Icon/icons/times.icon';\nimport * as minusIcon from '../Icon/icons/minus.icon';\nimport * as dockIcon from '../Icon/icons/dock.icon';\nimport * as undockIcon from '../Icon/icons/undock.icon';\nimport Text from '../Text';\nimport { Count } from '../Badges';\n\nimport MinimizedModal from './MinimizedModal';\nimport type { ModalProps } from './Modal.types';\nimport {\n StyledModal,\n StyledModalHeader,\n StyledModalContent,\n StyledModalActions,\n StyledModalChildrenWrap\n} from './Modal.styles';\n\nregisterIcon(timesIcon, minusIcon, dockIcon, undockIcon);\n\nconst Modal: FunctionComponent<ModalProps & ForwardProps> = forwardRef(function Modal(\n props: PropsWithoutRef<ModalProps>,\n ref: Ref<HTMLElement>\n) {\n const {\n as,\n progress = false,\n heading,\n count,\n children,\n actions,\n stretch = false,\n center = false,\n defaultFocus,\n onBeforeOpen,\n onAfterOpen,\n onBeforeClose,\n onAfterClose,\n onRequestDismiss,\n onRequestMinimize,\n onRequestMaximize,\n onRequestDock,\n onRequestActivate,\n ...restProps\n } = props;\n\n const {\n alert,\n dismissible,\n minimizable,\n maximizable,\n dockable,\n state,\n dismiss,\n minimize,\n maximize,\n dock,\n unmount,\n top\n } = useModalContext();\n\n const modalRef = useConsolidatedRef(ref);\n const modalContentRef = useRef<HTMLDivElement>(null);\n const backdropRef = useRef<HTMLDivElement>(null);\n const closeButtonRef = useRef<HTMLButtonElement>(null);\n const previousState = usePrevious(state);\n const id = useUID();\n const t = useI18n();\n\n const tryDismiss = () => {\n if (onRequestDismiss?.() !== false) {\n dismiss();\n }\n };\n\n const setFocus = () => {\n if (progress) return;\n\n const focusables = getFocusables(modalRef);\n\n if (defaultFocus?.current) {\n defaultFocus.current.focus();\n } else {\n const focusable =\n focusables.find(el => {\n return modalContentRef.current?.contains(el);\n }) ??\n closeButtonRef.current ??\n focusables[0];\n\n focusable?.focus();\n }\n };\n\n useFocusTrap(modalRef, false);\n useEvent('shortcut', e => e.stopPropagation(), { eventOptions: { capture: true } });\n\n useOuterEvent('mousedown', [modalRef], e => {\n if (['minimized', 'docked', 'closed'].includes(state)) return;\n\n if (dismissible) {\n if (e.target === backdropRef.current) {\n tryDismiss();\n }\n } else {\n modalRef.current?.focus();\n }\n });\n\n useEffect(() => {\n if (state === 'minimized') return;\n if (state === 'open' || state === 'maximized' || state === 'docked') setFocus();\n\n // This won't actually run until potential changes to docked modal handling.\n if (state === 'closed' && previousState === 'docked') {\n onBeforeClose?.();\n unmount();\n onAfterClose?.();\n }\n }, [state]);\n\n useEffect(() => {\n // If a modal is already in a closed state on initial mount, unmount it.\n // This only happens when a docked modal closes since the ModalManager\n // remounts it outside of the DockedModals container if state !== 'docked'.\n if (state === 'closed') {\n onBeforeClose?.();\n unmount();\n onAfterClose?.();\n }\n }, []);\n\n // Dismiss on Escape needs to be handled using React event handling to be cancelable using SyntheticEvent.stopPropagation.\n const onModalKeyDown = useCallback(\n (e: ReactKeyboardEvent) => {\n if (dismissible && (state === 'open' || state === 'maximized') && e.key === 'Escape' && top) {\n tryDismiss();\n }\n },\n [dismissible, state, top, tryDismiss]\n );\n\n const onHeaderActionKeyDown = useCallback((e: ReactKeyboardEvent<HTMLButtonElement>) => {\n if (e.repeat && (e.key === 'Enter' || e.key === ' ')) e.preventDefault();\n }, []);\n\n useEffect(() => {\n if (!progress) {\n setFocus();\n }\n }, [progress]);\n\n const isModalSmallOrAbove = useBreakpoint('sm', { breakpointRef: modalRef });\n\n const maximized = stretch || state === 'maximized';\n\n const modal = (\n <Flex\n {...restProps}\n container={{ direction: 'column' }}\n ref={modalRef}\n as={StyledModal}\n forwardedAs={as}\n onClick={(e: MouseEvent) => e.stopPropagation()}\n onKeyDown={onModalKeyDown}\n alert={alert}\n role={alert ? 'alertdialog' : 'dialog'}\n stretch={maximized}\n center={center}\n aria-labelledby={`${id}-heading`}\n aria-describedby={alert ? `${id}-content` : undefined}\n aria-modal={state === 'docked' ? 'false' : 'true'}\n state={state}\n aria-busy={progress ? 'true' : 'false'}\n >\n <Flex\n container={{ justify: 'between', alignItems: 'center', gap: 1 }}\n item={{ shrink: 0 }}\n as={StyledModalHeader}\n hasAction={minimizable || dismissible}\n >\n <Flex\n container={{ alignItems: 'center', gap: 1 }}\n as={Text}\n variant='h2'\n id={`${id}-heading`}\n >\n <span>{heading}</span>\n {typeof count === 'number' && <Count>{count}</Count>}\n </Flex>\n\n <Flex container>\n {maximizable && !alert && state !== 'maximized' && (\n <Button\n icon\n variant='simple'\n label={t('modal_maximize')}\n onKeyDown={onHeaderActionKeyDown}\n onClick={() => {\n if (onRequestMaximize?.() !== false) {\n maximize();\n }\n }}\n >\n <Icon name='undock' />\n </Button>\n )}\n {dockable && !alert && state !== 'docked' && (\n <Button\n icon\n variant='simple'\n label={t('modal_dock')}\n onKeyDown={onHeaderActionKeyDown}\n onClick={() => {\n if (onRequestDock?.() !== false) {\n dock();\n }\n }}\n >\n <Icon name='dock' />\n </Button>\n )}\n {minimizable && !alert && (\n <Button\n icon\n variant='simple'\n label={t('modal_minimize')}\n onKeyDown={onHeaderActionKeyDown}\n onClick={() => {\n if (onRequestMinimize?.() !== false) {\n minimize();\n }\n }}\n >\n <Icon name='minus' />\n </Button>\n )}\n {dismissible && !alert && (\n <Button\n icon\n variant='simple'\n label={t('modal_close')}\n onKeyDown={onHeaderActionKeyDown}\n onClick={tryDismiss}\n ref={closeButtonRef}\n >\n <Icon name='times' />\n </Button>\n )}\n </Flex>\n </Flex>\n\n <Flex\n item={{ grow: 1 }}\n as={StyledModalContent}\n ref={modalContentRef}\n style={\n modalContentRef.current\n ? { '--scroll-top': `${modalContentRef.current.scrollTop}px` }\n : undefined\n }\n >\n {children && (\n <StyledModalChildrenWrap id={`${id}-content`} inert={progress ? '' : undefined}>\n {children}\n </StyledModalChildrenWrap>\n )}\n\n <Progress\n visible={!!progress}\n focusOnVisible\n placement='local'\n message={typeof progress === 'object' ? progress.message : t('loading')}\n />\n </Flex>\n\n {actions && (\n <Flex\n container={{\n pad: [2.5, 3, 3],\n gap: 1,\n ...(isModalSmallOrAbove\n ? { direction: 'row', justify: 'end' }\n : { direction: 'column' })\n }}\n item={{ shrink: 0 }}\n as={StyledModalActions}\n isSmallOrAbove={isModalSmallOrAbove}\n >\n {actions}\n </Flex>\n )}\n </Flex>\n );\n\n const renderModal =\n state === 'docked' ? (\n modal\n ) : (\n <Backdrop\n ref={backdropRef}\n container={{\n alignItems: center || maximized ? 'center' : 'start'\n }}\n transitionSpeed='slow'\n open={state === 'open' || state === 'maximized'}\n onBeforeTransitionIn={onBeforeOpen}\n onAfterTransitionIn={onAfterOpen}\n onBeforeTransitionOut={onBeforeClose}\n onAfterTransitionOut={() => {\n unmount();\n onAfterClose?.();\n }}\n >\n {modal}\n </Backdrop>\n );\n\n return state === 'minimized' ? <MinimizedModal {...props} {...restProps} /> : renderModal;\n});\n\nexport default Modal;\n"]}
|
|
1
|
+
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../../src/components/Modal/Modal.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AASnE,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,QAAQ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B,OAAO,EAAE,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GACvE,IACG,EAEN,OAAO,IAAI,CACV,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,kBAAkB,YACjF,OAAO,GACH,CACR,IACI,CACR,CAAC;IAEF,MAAM,WAAW,GACf,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CACnB,KAAK,CACN,CAAC,CAAC,CAAC,CACF,KAAC,QAAQ,IACP,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE;YACT,UAAU,EAAE,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO;SACrD,EACD,eAAe,EAAC,MAAM,EACtB,IAAI,EAAE,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,WAAW,EAC/C,oBAAoB,EAAE,YAAY,EAClC,mBAAmB,EAAE,WAAW,EAChC,qBAAqB,EAAE,aAAa,EACpC,oBAAoB,EAAE,GAAG,EAAE;YACzB,OAAO,EAAE,CAAC;YACV,YAAY,EAAE,EAAE,CAAC;QACnB,CAAC,YAEA,KAAK,GACG,CACZ,CAAC;IAEJ,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,KAAC,cAAc,OAAK,KAAK,KAAM,SAAS,GAAI,CAAC,CAAC,CAAC,WAAW,CAAC;AAC5F,CAAC,CAAC,CAAC;AAEH,eAAe,KAAK,CAAC","sourcesContent":["import { forwardRef, useEffect, useRef, useCallback } from 'react';\nimport type {\n FunctionComponent,\n PropsWithoutRef,\n Ref,\n MouseEvent,\n KeyboardEvent as ReactKeyboardEvent\n} from 'react';\n\nimport Progress from '../Progress';\nimport { getFocusables } from '../../utils';\nimport Backdrop from '../Backdrop';\nimport Flex from '../Flex';\nimport Button from '../Button';\nimport type { ForwardProps } from '../../types';\nimport {\n useConsolidatedRef,\n useI18n,\n useOuterEvent,\n useUID,\n useFocusTrap,\n usePrevious,\n useModalContext,\n useEvent\n} from '../../hooks';\nimport Icon, { registerIcon } from '../Icon';\nimport * as timesIcon from '../Icon/icons/times.icon';\nimport * as minusIcon from '../Icon/icons/minus.icon';\nimport * as dockIcon from '../Icon/icons/dock.icon';\nimport * as undockIcon from '../Icon/icons/undock.icon';\nimport Text from '../Text';\nimport { Count } from '../Badges';\n\nimport MinimizedModal from './MinimizedModal';\nimport type { ModalProps } from './Modal.types';\nimport {\n StyledModal,\n StyledModalHeader,\n StyledModalContent,\n StyledModalActions,\n StyledModalChildrenWrap\n} from './Modal.styles';\n\nregisterIcon(timesIcon, minusIcon, dockIcon, undockIcon);\n\nconst Modal: FunctionComponent<ModalProps & ForwardProps> = forwardRef(function Modal(\n props: PropsWithoutRef<ModalProps>,\n ref: Ref<HTMLElement>\n) {\n const {\n as,\n progress = false,\n heading,\n count,\n children,\n actions,\n stretch = false,\n center = false,\n defaultFocus,\n onBeforeOpen,\n onAfterOpen,\n onBeforeClose,\n onAfterClose,\n onRequestDismiss,\n onRequestMinimize,\n onRequestMaximize,\n onRequestDock,\n onRequestActivate,\n ...restProps\n } = props;\n\n const {\n alert,\n dismissible,\n minimizable,\n maximizable,\n dockable,\n state,\n dismiss,\n minimize,\n maximize,\n dock,\n unmount,\n top\n } = useModalContext();\n\n const modalRef = useConsolidatedRef(ref);\n const modalContentRef = useRef<HTMLDivElement>(null);\n const backdropRef = useRef<HTMLDivElement>(null);\n const closeButtonRef = useRef<HTMLButtonElement>(null);\n const previousState = usePrevious(state);\n const id = useUID();\n const t = useI18n();\n\n const tryDismiss = () => {\n if (onRequestDismiss?.() !== false) {\n dismiss();\n }\n };\n\n const setFocus = () => {\n if (progress) return;\n\n const focusables = getFocusables(modalRef);\n\n if (defaultFocus?.current) {\n defaultFocus.current.focus();\n } else {\n const focusable =\n focusables.find(el => {\n return modalContentRef.current?.contains(el);\n }) ??\n closeButtonRef.current ??\n focusables[0];\n\n focusable?.focus();\n }\n };\n\n useFocusTrap(modalRef, false);\n useEvent('shortcut', e => e.stopPropagation(), { eventOptions: { capture: true } });\n\n useOuterEvent('mousedown', [modalRef], e => {\n if (['minimized', 'docked', 'closed'].includes(state)) return;\n\n if (dismissible) {\n if (e.target === backdropRef.current) {\n tryDismiss();\n }\n } else {\n modalRef.current?.focus();\n }\n });\n\n useEffect(() => {\n if (state === 'minimized') return;\n if (state === 'open' || state === 'maximized' || state === 'docked') setFocus();\n\n // This won't actually run until potential changes to docked modal handling.\n if (state === 'closed' && previousState === 'docked') {\n onBeforeClose?.();\n unmount();\n onAfterClose?.();\n }\n }, [state]);\n\n useEffect(() => {\n // If a modal is already in a closed state on initial mount, unmount it.\n // This only happens when a docked modal closes since the ModalManager\n // remounts it outside of the DockedModals container if state !== 'docked'.\n if (state === 'closed') {\n onBeforeClose?.();\n unmount();\n onAfterClose?.();\n }\n }, []);\n\n // Dismiss on Escape needs to be handled using React event handling to be cancelable using SyntheticEvent.stopPropagation.\n const onModalKeyDown = useCallback(\n (e: ReactKeyboardEvent) => {\n if (dismissible && (state === 'open' || state === 'maximized') && e.key === 'Escape' && top) {\n tryDismiss();\n }\n },\n [dismissible, state, top, tryDismiss]\n );\n\n const onHeaderActionKeyDown = useCallback((e: ReactKeyboardEvent<HTMLButtonElement>) => {\n if (e.repeat && (e.key === 'Enter' || e.key === ' ')) e.preventDefault();\n }, []);\n\n useEffect(() => {\n if (!progress) {\n setFocus();\n }\n }, [progress]);\n\n const maximized = stretch || state === 'maximized';\n\n const modal = (\n <Flex\n {...restProps}\n container={{ direction: 'column' }}\n ref={modalRef}\n as={StyledModal}\n forwardedAs={as}\n onClick={(e: MouseEvent) => e.stopPropagation()}\n onKeyDown={onModalKeyDown}\n alert={alert}\n role={alert ? 'alertdialog' : 'dialog'}\n stretch={maximized}\n center={center}\n aria-labelledby={`${id}-heading`}\n aria-describedby={alert ? `${id}-content` : undefined}\n aria-modal={state === 'docked' ? 'false' : 'true'}\n state={state}\n aria-busy={progress ? 'true' : 'false'}\n >\n <Flex\n container={{ justify: 'between', alignItems: 'center', gap: 1 }}\n item={{ shrink: 0 }}\n as={StyledModalHeader}\n hasAction={minimizable || dismissible}\n >\n <Flex\n container={{ alignItems: 'center', gap: 1 }}\n as={Text}\n variant='h2'\n id={`${id}-heading`}\n >\n <span>{heading}</span>\n {typeof count === 'number' && <Count>{count}</Count>}\n </Flex>\n\n <Flex container>\n {maximizable && !alert && state !== 'maximized' && (\n <Button\n icon\n variant='simple'\n label={t('modal_maximize')}\n onKeyDown={onHeaderActionKeyDown}\n onClick={() => {\n if (onRequestMaximize?.() !== false) {\n maximize();\n }\n }}\n >\n <Icon name='undock' />\n </Button>\n )}\n {dockable && !alert && state !== 'docked' && (\n <Button\n icon\n variant='simple'\n label={t('modal_dock')}\n onKeyDown={onHeaderActionKeyDown}\n onClick={() => {\n if (onRequestDock?.() !== false) {\n dock();\n }\n }}\n >\n <Icon name='dock' />\n </Button>\n )}\n {minimizable && !alert && (\n <Button\n icon\n variant='simple'\n label={t('modal_minimize')}\n onKeyDown={onHeaderActionKeyDown}\n onClick={() => {\n if (onRequestMinimize?.() !== false) {\n minimize();\n }\n }}\n >\n <Icon name='minus' />\n </Button>\n )}\n {dismissible && !alert && (\n <Button\n icon\n variant='simple'\n label={t('modal_close')}\n onKeyDown={onHeaderActionKeyDown}\n onClick={tryDismiss}\n ref={closeButtonRef}\n >\n <Icon name='times' />\n </Button>\n )}\n </Flex>\n </Flex>\n\n <Flex\n item={{ grow: 1 }}\n as={StyledModalContent}\n ref={modalContentRef}\n style={\n modalContentRef.current\n ? { '--scroll-top': `${modalContentRef.current.scrollTop}px` }\n : undefined\n }\n >\n {children && (\n <StyledModalChildrenWrap id={`${id}-content`} inert={progress ? '' : undefined}>\n {children}\n </StyledModalChildrenWrap>\n )}\n\n <Progress\n visible={!!progress}\n focusOnVisible\n placement='local'\n message={typeof progress === 'object' ? progress.message : t('loading')}\n />\n </Flex>\n\n {actions && (\n <Flex container={{ justify: 'between' }} item={{ shrink: 0 }} as={StyledModalActions}>\n {actions}\n </Flex>\n )}\n </Flex>\n );\n\n const renderModal =\n state === 'docked' ? (\n modal\n ) : (\n <Backdrop\n ref={backdropRef}\n container={{\n alignItems: center || maximized ? 'center' : 'start'\n }}\n transitionSpeed='slow'\n open={state === 'open' || state === 'maximized'}\n onBeforeTransitionIn={onBeforeOpen}\n onAfterTransitionIn={onAfterOpen}\n onBeforeTransitionOut={onBeforeClose}\n onAfterTransitionOut={() => {\n unmount();\n onAfterClose?.();\n }}\n >\n {modal}\n </Backdrop>\n );\n\n return state === 'minimized' ? <MinimizedModal {...props} {...restProps} /> : renderModal;\n});\n\nexport default Modal;\n"]}
|
|
@@ -4,8 +4,6 @@ export declare const StyledModalHeader: import("styled-components").StyledCompon
|
|
|
4
4
|
hasAction?: boolean | undefined;
|
|
5
5
|
}, never>;
|
|
6
6
|
export declare const StyledModalContent: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
7
|
-
export declare const StyledModalActions: import("styled-components").StyledComponent<"footer", import("styled-components").DefaultTheme, {
|
|
8
|
-
isSmallOrAbove: boolean;
|
|
9
|
-
}, never>;
|
|
7
|
+
export declare const StyledModalActions: import("styled-components").StyledComponent<"footer", import("styled-components").DefaultTheme, {}, never>;
|
|
10
8
|
export declare const StyledModal: import("styled-components").StyledComponent<"article", import("styled-components").DefaultTheme, Partial<import("../Card").CardProps> & Pick<ModalProps, "progress" | "children" | "as" | "heading" | "className" | "actions" | "count" | "forwardedAs" | "defaultFocus" | "onBeforeOpen" | "onAfterOpen" | "onBeforeClose" | "onAfterClose" | "onRequestDismiss" | "onRequestMinimize" | "onRequestMaximize" | "onRequestDock" | "onRequestActivate"> & Required<Pick<ModalProps, "stretch" | "center" | "autoWidth">> & Pick<ModalContextValue, "alert" | "state">, never>;
|
|
11
9
|
//# sourceMappingURL=Modal.styles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/Modal.styles.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAInE,eAAO,MAAM,uBAAuB,yGAAe,CAAC;AAEpD,eAAO,MAAM,iBAAiB;;SAyB7B,CAAC;AAIF,eAAO,MAAM,kBAAkB,yGAc7B,CAAC;AAIH,eAAO,MAAM,kBAAkB
|
|
1
|
+
{"version":3,"file":"Modal.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/Modal.styles.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAInE,eAAO,MAAM,uBAAuB,yGAAe,CAAC;AAEpD,eAAO,MAAM,iBAAiB;;SAyB7B,CAAC;AAIF,eAAO,MAAM,kBAAkB,yGAc7B,CAAC;AAIH,eAAO,MAAM,kBAAkB,4GAI7B,CAAC;AAIH,eAAO,MAAM,WAAW,8iBAoFtB,CAAC"}
|
|
@@ -45,24 +45,10 @@ export const StyledModalContent = styled.div(({ theme: { base } }) => {
|
|
|
45
45
|
`;
|
|
46
46
|
});
|
|
47
47
|
StyledModalContent.defaultProps = defaultThemeProp;
|
|
48
|
-
export const StyledModalActions = styled.footer(({
|
|
48
|
+
export const StyledModalActions = styled.footer(({ theme: { base } }) => {
|
|
49
49
|
return css `
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
& > :not(button) {
|
|
55
|
-
display: contents;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
${isSmallOrAbove &&
|
|
59
|
-
css `
|
|
60
|
-
& > button:first-child:not(:last-child),
|
|
61
|
-
& > :first-child:not(:last-child) button:first-child {
|
|
62
|
-
margin-inline-end: auto;
|
|
63
|
-
}
|
|
64
|
-
`}
|
|
65
|
-
`;
|
|
50
|
+
padding: calc(2.5 * ${base.spacing}) calc(3 * ${base.spacing}) calc(3 * ${base.spacing});
|
|
51
|
+
`;
|
|
66
52
|
});
|
|
67
53
|
StyledModalActions.defaultProps = defaultThemeProp;
|
|
68
54
|
export const StyledModal = styled(StyledCard)(({ theme: { base }, alert, autoWidth, center, stretch, state }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.styles.js","sourceRoot":"","sources":["../../../src/components/Modal/Modal.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAM7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAA,EAAE,CAAC;AAEpD,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAC5C,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;IACjC,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAEvC,OAAO,GAAG,CAAA;sBACQ,CAAC,GAAG,SAAS,MAAM,IAAI,CAAC,OAAO,UAAU,CAAC,GAAG,SAAS,MAAM,IAAI,CAAC,OAAO;eAC/E,GAAG,GAAG,SAAS,MAAM,IAAI,CAAC,OAAO,cAAc,IAAI,CAAC,OAAO;aAC7D,UAAU;6BACM,IAAI,CAAC,OAAO;;;;;;;;;;;;QAYjC,YAAY;iBACH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AAI,eAAe,GAAG,MAAM,CAAC;IAE7B,IAAI,KAAK,EAAE;QACT,eAAe,GAAG,MAAM,CAAC;QACzB,eAAe,GAAG,MAAM,CAAC;KAC1B;SAAM,IAAI,SAAS,EAAE;QACpB,eAAe,GAAG,MAAM,CAAC;KAC1B;IAED,OAAO,GAAG,CAAA;;kBAEM,IAAI,CAAC,MAAM,CAAC,IAAI;;MAE5B,CAAC,KAAK,IAAI,OAAO;QACjB,CAAC,CAAC,GAAG,CAAA;;;;0CAI+B,IAAI,CAAC,WAAW,CAAC,EAAE;;;;;0CAKnB,IAAI,CAAC,WAAW,CAAC,EAAE;;;;SAIpD;QACH,CAAC,CAAC,GAAG,CAAA;8CACmC,eAAe;8CACf,eAAe;;YAEjD,CAAC,MAAM;YACT,GAAG,CAAA;;WAEF;;0CAE+B,IAAI,CAAC,WAAW,CAAC,EAAE;gDACb,eAAe;gDACf,eAAe;;cAEjD,CAAC,MAAM;YACT,GAAG,CAAA;;aAEF;;;0CAG6B,IAAI,CAAC,WAAW,CAAC,EAAE;gDACb,eAAe;gDACf,eAAe;;cAEjD,CAAC,MAAM;YACT,GAAG,CAAA;;aAEF;;SAEJ;;MAEH,KAAK,KAAK,QAAQ;QACpB,GAAG,CAAA;;;;;;;;;;;KAWF;;;QAGG,kBAAkB;;;;;;GAMvB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,WAAW,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport { StyledButton } from '../Button';\nimport type { PropsWithDefaults } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport { StyledIcon } from '../Icon';\nimport { StyledCard } from '../Card';\nimport { StyledBackdrop } from '../Backdrop';\n\nimport type { ModalContextValue, ModalProps } from './Modal.types';\n\ntype ModalPropsWithDefaults = PropsWithDefaults<ModalProps, 'stretch' | 'center' | 'autoWidth'>;\n\nexport const StyledModalChildrenWrap = styled.div``;\n\nexport const StyledModalHeader = styled.header<{ hasAction?: boolean }>(\n ({ theme: { base }, hasAction }) => {\n const padAdjust = hasAction ? 0.75 : 0;\n\n return css`\n padding: calc(${3 - padAdjust} * ${base.spacing}) calc(${3 - padAdjust} * ${base.spacing})\n calc(${2.5 - padAdjust} * ${base.spacing}) calc(3 * ${base.spacing});\n h2 > ${StyledIcon} {\n margin-inline-end: ${base.spacing};\n }\n\n > h2 {\n overflow-x: hidden;\n > :first-child {\n overflow-x: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n }\n }\n\n ${StyledButton} {\n color: ${base.palette['foreground-color']};\n }\n `;\n }\n);\n\nStyledModalHeader.defaultProps = defaultThemeProp;\n\nexport const StyledModalContent = styled.div(({ theme: { base } }) => {\n return css`\n position: relative;\n padding: calc(0.5 * ${base.spacing}) calc(3 * ${base.spacing});\n overflow-y: auto;\n\n &:last-child {\n padding-bottom: calc(3 * ${base.spacing});\n }\n\n & > ${StyledBackdrop} {\n top: var(--scroll-top, 0);\n }\n `;\n});\n\nStyledModalContent.defaultProps = defaultThemeProp;\n\nexport const StyledModalActions = styled.footer(({ theme: { base } }) => {\n return css`\n padding: calc(2.5 * ${base.spacing}) calc(3 * ${base.spacing}) calc(3 * ${base.spacing});\n `;\n});\n\nStyledModalActions.defaultProps = defaultThemeProp;\n\nexport const StyledModal = styled(StyledCard)<\n ModalPropsWithDefaults & Pick<ModalContextValue, 'alert' | 'state'>\n>(({ theme: { base }, alert, autoWidth, center, stretch, state }) => {\n let defaultMinWidth = '80ch';\n let defaultMaxWidth = '80ch';\n\n if (alert) {\n defaultMinWidth = '60ch';\n defaultMaxWidth = '60ch';\n } else if (autoWidth) {\n defaultMaxWidth = '100%';\n }\n\n return css`\n position: relative;\n box-shadow: ${base.shadow.high};\n\n ${!alert && stretch\n ? css`\n width: calc(100% - 1rem);\n height: calc(100% - 1rem);\n\n @media screen and (min-width: ${base.breakpoints.sm}) {\n width: calc(100% - 2rem);\n height: calc(100% - 2rem);\n }\n\n @media screen and (min-width: ${base.breakpoints.md}) {\n width: calc(100% - 4rem);\n height: calc(100% - 4rem);\n }\n `\n : css`\n min-width: min(calc(100% - 1rem), ${defaultMinWidth});\n max-width: min(calc(100% - 1rem), ${defaultMaxWidth});\n max-height: calc(100% - 1rem);\n ${!center &&\n css`\n margin-block-start: 0.5rem;\n `}\n\n @media screen and (min-width: ${base.breakpoints.sm}) {\n min-width: min(calc(100% - 2rem), ${defaultMinWidth});\n max-width: min(calc(100% - 2rem), ${defaultMaxWidth});\n max-height: calc(100% - 2rem);\n ${!center &&\n css`\n margin-block-start: 1rem;\n `}\n }\n\n @media screen and (min-width: ${base.breakpoints.md}) {\n min-width: min(calc(100% - 4rem), ${defaultMinWidth});\n max-width: min(calc(100% - 4rem), ${defaultMaxWidth});\n max-height: calc(100% - 4rem);\n ${!center &&\n css`\n margin-block-start: 2rem;\n `}\n }\n `}\n\n ${state === 'docked' &&\n css`\n /*\n * This seems like the most optimal of the suboptimal solutions.\n * https://styled-components.com/docs/faqs#how-can-i-override-styles-with-higher-specificity\n */\n &&& {\n /* Using non logical properties due to Safari 14.x support and since the inline bottom values are the same. */\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n pointer-events: auto;\n }\n `}\n\n &[aria-busy='true'] {\n ${StyledModalContent} {\n /* TODO: Replace with useScrollToggle hook. */\n overflow: hidden;\n min-height: 8rem;\n }\n }\n `;\n});\n\nStyledModal.defaultProps = defaultThemeProp;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiStepForm.d.ts","sourceRoot":"","sources":["../../../src/components/MultiStepForm/MultiStepForm.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MultiStepForm.d.ts","sourceRoot":"","sources":["../../../src/components/MultiStepForm/MultiStepForm.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,OAAO,CAAC;AAWhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAWhD,OAAO,KAAK,kBAAkB,MAAM,uBAAuB,CAAC;AAI5D,eAAO,MAAM,UAAU;;;SAkBtB,CAAC;AAIF,eAAO,MAAM,iBAAiB,yGAAe,CAAC;AAE9C,eAAO,MAAM,yBAAyB,iKAqBpC,CAAC;AAIH,eAAO,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CAqJ9E,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useRef, useEffect } from 'react';
|
|
3
3
|
import styled, { css } from 'styled-components';
|
|
4
|
-
import { useAfterInitialEffect, useUID, useI18n, usePrevious, useBreakpoint, useTheme
|
|
4
|
+
import { useAfterInitialEffect, useUID, useI18n, usePrevious, useBreakpoint, useTheme } from '../../hooks';
|
|
5
5
|
import { getFocusables } from '../../utils';
|
|
6
6
|
import { calculateFontSize } from '../../styles';
|
|
7
7
|
import Flex from '../Flex';
|
|
@@ -11,8 +11,6 @@ import VisuallyHiddenText from '../VisuallyHiddenText';
|
|
|
11
11
|
import Grid, { StyledGrid } from '../Grid';
|
|
12
12
|
import { defaultThemeProp } from '../../theme';
|
|
13
13
|
import Progress from '../Progress';
|
|
14
|
-
import { StyledButton } from '../Button';
|
|
15
|
-
import { StyledRequiredAsterisk } from '../FormField/FormField';
|
|
16
14
|
import VerticalFormProgress from './VerticalFormProgress';
|
|
17
15
|
import HorizontalFormProgress from './HorizontalFormProgress';
|
|
18
16
|
export const StyledForm = styled.form(({ actions, heading, theme }) => {
|
|
@@ -33,51 +31,25 @@ export const StyledForm = styled.form(({ actions, heading, theme }) => {
|
|
|
33
31
|
`;
|
|
34
32
|
});
|
|
35
33
|
StyledForm.defaultProps = defaultThemeProp;
|
|
36
|
-
const StyledFormDescriptionBlock = styled.div(({ theme }) => {
|
|
37
|
-
return css `
|
|
38
|
-
margin-block-end: ${theme.base.spacing};
|
|
39
|
-
`;
|
|
40
|
-
});
|
|
41
|
-
StyledFormDescriptionBlock.defaultProps = defaultThemeProp;
|
|
42
|
-
const StyledFormBannerBlock = styled.div(({ theme }) => {
|
|
43
|
-
return css `
|
|
44
|
-
margin-block-start: ${theme.base.spacing};
|
|
45
|
-
margin-block-end: calc(2 * ${theme.base.spacing});
|
|
46
|
-
`;
|
|
47
|
-
});
|
|
48
|
-
StyledFormBannerBlock.defaultProps = defaultThemeProp;
|
|
49
34
|
export const StyledFormContent = styled.div ``;
|
|
50
35
|
export const StyledRequiredFieldLegend = styled(Text)(({ theme }) => {
|
|
51
|
-
const { base: { 'font-size': fontSize, 'font-scale': fontScale } } = theme;
|
|
36
|
+
const { base: { 'font-size': fontSize, 'font-scale': fontScale, palette: { urgent } } } = theme;
|
|
52
37
|
const { xxs: infoFontSize } = calculateFontSize(fontSize, fontScale);
|
|
53
38
|
return css `
|
|
54
39
|
font-size: ${infoFontSize};
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
StyledRequiredFieldLegend.defaultProps = defaultThemeProp;
|
|
58
|
-
const StyledActionsContainer = styled(Flex)(({ isSmallOrAbove }) => {
|
|
59
|
-
return css `
|
|
60
|
-
${StyledButton} + ${StyledButton} {
|
|
61
|
-
margin-inline-start: unset;
|
|
62
|
-
}
|
|
40
|
+
font-style: italic;
|
|
63
41
|
|
|
64
|
-
|
|
65
|
-
display:
|
|
42
|
+
&::before {
|
|
43
|
+
display: 'inline';
|
|
44
|
+
content: '\\00a0*';
|
|
45
|
+
vertical-align: top;
|
|
46
|
+
color: ${urgent};
|
|
66
47
|
}
|
|
67
|
-
|
|
68
|
-
${isSmallOrAbove &&
|
|
69
|
-
css `
|
|
70
|
-
& > button:first-child:not(:last-child),
|
|
71
|
-
& > :first-child:not(:last-child) button:first-child {
|
|
72
|
-
margin-inline-end: auto;
|
|
73
|
-
}
|
|
74
|
-
`}
|
|
75
48
|
`;
|
|
76
49
|
});
|
|
77
|
-
|
|
50
|
+
StyledRequiredFieldLegend.defaultProps = defaultThemeProp;
|
|
78
51
|
export const MultiStepForm = forwardRef(function MultiStepForm({ currentStepId, steps, heading, stepIndicator: stepIndicatorProp = steps.length < 2 ? 'none' : 'horizontal', progress, ...restProps }, ref) {
|
|
79
52
|
const multiStepFormContentRef = useRef(null);
|
|
80
|
-
const formRef = useConsolidatedRef(ref);
|
|
81
53
|
const previousId = usePrevious(currentStepId);
|
|
82
54
|
const currentStep = steps.find(step => step.id === currentStepId);
|
|
83
55
|
const headingId = useUID();
|
|
@@ -105,16 +77,32 @@ export const MultiStepForm = forwardRef(function MultiStepForm({ currentStepId,
|
|
|
105
77
|
}
|
|
106
78
|
}, [progress]);
|
|
107
79
|
const isSmallOrAbove = useBreakpoint('sm');
|
|
108
|
-
const isFormSmallOrAbove = useBreakpoint('sm', { breakpointRef: formRef });
|
|
109
80
|
const stepIndicator = stepIndicatorProp === 'vertical' && !isSmallOrAbove ? 'horizontal' : stepIndicatorProp;
|
|
110
|
-
let areaDef = '
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
81
|
+
let areaDef = '';
|
|
82
|
+
switch (stepIndicator) {
|
|
83
|
+
case 'horizontal':
|
|
84
|
+
areaDef += '"stepIndicator" ';
|
|
85
|
+
if (currentStep.banners)
|
|
86
|
+
areaDef += '"banners" ';
|
|
87
|
+
if (currentStep.description)
|
|
88
|
+
areaDef += '"description" ';
|
|
89
|
+
areaDef += '"content"';
|
|
90
|
+
break;
|
|
91
|
+
case 'vertical':
|
|
92
|
+
if (currentStep.banners)
|
|
93
|
+
areaDef += '"banners stepIndicator" ';
|
|
94
|
+
if (currentStep.description)
|
|
95
|
+
areaDef += '"description stepIndicator" ';
|
|
96
|
+
areaDef += '"content stepIndicator"';
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
if (currentStep.banners)
|
|
100
|
+
areaDef += '"banners" ';
|
|
101
|
+
if (currentStep.description)
|
|
102
|
+
areaDef += '"description" ';
|
|
103
|
+
areaDef += '"content"';
|
|
116
104
|
}
|
|
117
|
-
return (_jsxs(StyledForm, { ref:
|
|
105
|
+
return (_jsxs(StyledForm, { ref: ref, ...restProps, "aria-labelledby": heading ? headingId : undefined, "aria-describedby": currentStep.description ? descriptionId : undefined, heading: !!heading, actions: !!currentStep.actions, children: [heading && (_jsx(Text, { id: headingId, variant: 'h3', children: heading })), _jsxs(Grid, { container: {
|
|
118
106
|
cols: stepIndicator === 'vertical'
|
|
119
107
|
? `2fr minmax(${contentWidth.xs}, 1fr)`
|
|
120
108
|
: 'minmax(0, 1fr)',
|
|
@@ -122,14 +110,7 @@ export const MultiStepForm = forwardRef(function MultiStepForm({ currentStepId,
|
|
|
122
110
|
gap: 2
|
|
123
111
|
}, inert: progress ? '' : undefined, children: [steps.length > 1 && (_jsxs(Grid, { item: { area: 'stepIndicator' }, children: [stepIndicator === 'horizontal' && (_jsx(Grid, { item: { area: 'stepIndicator' }, as: HorizontalFormProgress, steps: steps, currentStepId: currentStepId })), stepIndicator === 'vertical' && (_jsx(Grid, { item: { area: 'stepIndicator' }, as: VerticalFormProgress, steps: steps, currentStepId: currentStepId })), _jsx(VisuallyHiddenText, { "aria-live": 'polite', children: previousId !== undefined && previousId !== currentStepId
|
|
124
112
|
? t('step_changed_to_name', [currentStep.name])
|
|
125
|
-
: '' })] })),
|
|
126
|
-
_jsx(StyledRequiredAsterisk, { children: "*" })
|
|
127
|
-
]) })] }), _jsx(Grid, { item: { area: 'content' }, as: StyledFormContent, ref: multiStepFormContentRef, children: currentStep.content }), _jsx(Progress, { visible: !!progress, focusOnVisible: true, placement: 'local', message: typeof progress === 'string' ? progress : undefined })] }), currentStep.actions && (_jsx(StyledActionsContainer, { isSmallOrAbove: isFormSmallOrAbove, container: {
|
|
128
|
-
gap: 1,
|
|
129
|
-
...(isFormSmallOrAbove
|
|
130
|
-
? { direction: 'row', justify: 'end' }
|
|
131
|
-
: { direction: 'column' })
|
|
132
|
-
}, children: currentStep.actions }))] }));
|
|
113
|
+
: '' })] })), currentStep.banners && _jsx(Grid, { item: { area: 'banners' }, children: currentStep.banners }), currentStep.description && (_jsx(Grid, { item: { area: 'description' }, children: _jsx(HTML, { id: descriptionId, as: 'p', content: currentStep.description }) })), _jsx(Grid, { item: { area: 'content' }, as: StyledFormContent, ref: multiStepFormContentRef, children: currentStep.content }), _jsx(Progress, { visible: !!progress, focusOnVisible: true, placement: 'local', message: typeof progress === 'string' ? progress : undefined })] }), currentStep.actions && (_jsx(Flex, { container: { justify: 'between', alignItems: 'center' }, children: currentStep.actions }))] }));
|
|
133
114
|
});
|
|
134
115
|
export default MultiStepForm;
|
|
135
116
|
//# sourceMappingURL=MultiStepForm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiStepForm.js","sourceRoot":"","sources":["../../../src/components/MultiStepForm/MultiStepForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,qBAAqB,EACrB,MAAM,EACN,OAAO,EACP,WAAW,EACX,aAAa,EACb,QAAQ,EACR,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AACvD,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MA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,EAAE,OAAO,EAAE,KAAK,EAAE;wBACtC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;iBAC7B,YAEA,WAAW,CAAC,OAAO,GACG,CAC1B,IACU,CACd,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { forwardRef, useRef, useEffect } from 'react';\nimport type { FunctionComponent, PropsWithoutRef } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n useAfterInitialEffect,\n useUID,\n useI18n,\n usePrevious,\n useBreakpoint,\n useTheme,\n useConsolidatedRef\n} from '../../hooks';\nimport type { ForwardProps } from '../../types';\nimport { getFocusables } from '../../utils';\nimport { calculateFontSize } from '../../styles';\nimport Flex from '../Flex';\nimport Text from '../Text';\nimport HTML from '../HTML';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\nimport Grid, { StyledGrid } from '../Grid';\nimport { defaultThemeProp } from '../../theme';\nimport Progress from '../Progress';\nimport { StyledButton } from '../Button';\nimport { StyledRequiredAsterisk } from '../FormField/FormField';\n\nimport type MultiStepFormProps from './MultiStepForm.types';\nimport VerticalFormProgress from './VerticalFormProgress';\nimport HorizontalFormProgress from './HorizontalFormProgress';\n\nexport const StyledForm = styled.form<{ actions?: boolean; heading?: boolean }>(\n ({ actions, heading, theme }) => {\n return css`\n & > ${StyledGrid} {\n position: relative;\n\n ${actions &&\n css`\n padding-block-end: calc(2 * ${theme.base.spacing});\n `}\n\n ${heading &&\n css`\n padding-block-start: calc(2 * ${theme.base.spacing});\n `}\n }\n `;\n }\n);\n\nStyledForm.defaultProps = defaultThemeProp;\n\nconst StyledFormDescriptionBlock = styled.div(({ theme }) => {\n return css`\n margin-block-end: ${theme.base.spacing};\n `;\n});\n\nStyledFormDescriptionBlock.defaultProps = defaultThemeProp;\n\nconst StyledFormBannerBlock = styled.div(({ theme }) => {\n return css`\n margin-block-start: ${theme.base.spacing};\n margin-block-end: calc(2 * ${theme.base.spacing});\n `;\n});\n\nStyledFormBannerBlock.defaultProps = defaultThemeProp;\n\nexport const StyledFormContent = styled.div``;\n\nexport const StyledRequiredFieldLegend = styled(Text)(({ theme }) => {\n const {\n base: { 'font-size': fontSize, 'font-scale': fontScale }\n } = theme;\n const { xxs: infoFontSize } = calculateFontSize(fontSize, fontScale);\n\n return css`\n font-size: ${infoFontSize};\n `;\n});\n\nStyledRequiredFieldLegend.defaultProps = defaultThemeProp;\n\nconst StyledActionsContainer = styled(Flex)<{ isSmallOrAbove: boolean }>(({ isSmallOrAbove }) => {\n return css`\n ${StyledButton} + ${StyledButton} {\n margin-inline-start: unset;\n }\n\n & > :not(button) {\n display: contents;\n }\n\n ${isSmallOrAbove &&\n css`\n & > button:first-child:not(:last-child),\n & > :first-child:not(:last-child) button:first-child {\n margin-inline-end: auto;\n }\n `}\n `;\n});\n\nStyledActionsContainer.defaultProps = defaultThemeProp;\n\nexport const MultiStepForm: FunctionComponent<MultiStepFormProps & ForwardProps> = forwardRef(\n function MultiStepForm(\n {\n currentStepId,\n steps,\n heading,\n stepIndicator: stepIndicatorProp = steps.length < 2 ? 'none' : 'horizontal',\n progress,\n ...restProps\n }: PropsWithoutRef<MultiStepFormProps>,\n ref: MultiStepFormProps['ref']\n ) {\n const multiStepFormContentRef = useRef(null);\n const formRef = useConsolidatedRef<HTMLFormElement>(ref);\n\n const previousId = usePrevious(currentStepId);\n const currentStep = steps.find(step => step.id === currentStepId)!;\n const headingId = useUID();\n const descriptionId = useUID();\n const t = useI18n();\n const {\n base: { 'content-width': contentWidth }\n } = useTheme();\n\n const setFocus = () => {\n if (progress) return;\n\n const focusables = getFocusables(multiStepFormContentRef);\n focusables[0]?.focus();\n };\n\n useEffect(() => {\n if (previousId === undefined) return;\n\n if (previousId !== currentStepId) {\n const focusableElements = getFocusables(multiStepFormContentRef);\n\n if (focusableElements.length) focusableElements[0].focus();\n }\n }, [currentStepId, previousId]);\n\n useAfterInitialEffect(() => {\n if (!progress) {\n setFocus();\n }\n }, [progress]);\n\n const isSmallOrAbove = useBreakpoint('sm');\n const isFormSmallOrAbove = useBreakpoint('sm', { breakpointRef: formRef });\n\n const stepIndicator =\n stepIndicatorProp === 'vertical' && !isSmallOrAbove ? 'horizontal' : stepIndicatorProp;\n\n let areaDef = '\"banner_description_legend\" \"content\"';\n\n if (stepIndicator === 'horizontal') {\n areaDef = '\"stepIndicator\"'.concat(' ', areaDef);\n }\n\n if (stepIndicator === 'vertical') {\n areaDef = '\"banner_description_legend stepIndicator\" \"content stepIndicator\"';\n }\n\n return (\n <StyledForm\n ref={formRef}\n {...restProps}\n aria-labelledby={heading ? headingId : undefined}\n aria-describedby={currentStep.description ? descriptionId : undefined}\n heading={!!heading}\n actions={!!currentStep.actions}\n >\n {heading && (\n <Text id={headingId} variant='h3'>\n {heading}\n </Text>\n )}\n\n <Grid\n container={{\n cols:\n stepIndicator === 'vertical'\n ? `2fr minmax(${contentWidth.xs}, 1fr)`\n : 'minmax(0, 1fr)',\n areas: areaDef,\n gap: 2\n }}\n inert={progress ? '' : undefined}\n >\n {steps.length > 1 && (\n <Grid item={{ area: 'stepIndicator' }}>\n {stepIndicator === 'horizontal' && (\n <Grid\n item={{ area: 'stepIndicator' }}\n as={HorizontalFormProgress}\n steps={steps}\n currentStepId={currentStepId}\n />\n )}\n {stepIndicator === 'vertical' && (\n <Grid\n item={{ area: 'stepIndicator' }}\n as={VerticalFormProgress}\n steps={steps}\n currentStepId={currentStepId}\n />\n )}\n <VisuallyHiddenText aria-live='polite'>\n {previousId !== undefined && previousId !== currentStepId\n ? t('step_changed_to_name', [currentStep.name])\n : ''}\n </VisuallyHiddenText>\n </Grid>\n )}\n\n <Grid item={{ area: 'banner_description_legend' }}>\n {currentStep.banners && (\n <StyledFormBannerBlock>{currentStep.banners}</StyledFormBannerBlock>\n )}\n\n {currentStep.description && (\n <StyledFormDescriptionBlock>\n <HTML id={descriptionId} as='p' content={currentStep.description} />\n </StyledFormDescriptionBlock>\n )}\n\n <StyledRequiredFieldLegend>\n {t('symbol_indicates_required_field', [\n <StyledRequiredAsterisk>*</StyledRequiredAsterisk>\n ])}\n </StyledRequiredFieldLegend>\n </Grid>\n\n <Grid item={{ area: 'content' }} as={StyledFormContent} ref={multiStepFormContentRef}>\n {currentStep.content}\n </Grid>\n\n <Progress\n visible={!!progress}\n focusOnVisible\n placement='local'\n message={typeof progress === 'string' ? progress : undefined}\n />\n </Grid>\n\n {currentStep.actions && (\n <StyledActionsContainer\n isSmallOrAbove={isFormSmallOrAbove}\n container={{\n gap: 1,\n ...(isFormSmallOrAbove\n ? { direction: 'row', justify: 'end' }\n : { direction: 'column' })\n }}\n >\n {currentStep.actions}\n </StyledActionsContainer>\n )}\n </StyledForm>\n );\n }\n);\n\nexport default MultiStepForm;\n"]}
|
|
1
|
+
{"version":3,"file":"MultiStepForm.js","sourceRoot":"","sources":["../../../src/components/MultiStepForm/MultiStepForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,qBAAqB,EACrB,MAAM,EACN,OAAO,EACP,WAAW,EACX,aAAa,EACb,QAAQ,EACT,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AACvD,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,QAAQ,MAAM,aAAa,CAAC;AAGnC,OAAO,oBAAo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IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,iBAAiB,EAAE,GAAG,EAAE,uBAAuB,YACjF,WAAW,CAAC,OAAO,GACf,EAEP,KAAC,QAAQ,IACP,OAAO,EAAE,CAAC,CAAC,QAAQ,EACnB,cAAc,QACd,SAAS,EAAC,OAAO,EACjB,OAAO,EAAE,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,GAC5D,IACG,EACN,WAAW,CAAC,OAAO,IAAI,CACtB,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,YAC1D,WAAW,CAAC,OAAO,GACf,CACR,IACU,CACd,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { forwardRef, useRef, useEffect } from 'react';\nimport type { FunctionComponent, PropsWithoutRef } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n useAfterInitialEffect,\n useUID,\n useI18n,\n usePrevious,\n useBreakpoint,\n useTheme\n} from '../../hooks';\nimport type { ForwardProps } from '../../types';\nimport { getFocusables } from '../../utils';\nimport { calculateFontSize } from '../../styles';\nimport Flex from '../Flex';\nimport Text from '../Text';\nimport HTML from '../HTML';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\nimport Grid, { StyledGrid } from '../Grid';\nimport { defaultThemeProp } from '../../theme';\nimport Progress from '../Progress';\n\nimport type MultiStepFormProps from './MultiStepForm.types';\nimport VerticalFormProgress from './VerticalFormProgress';\nimport HorizontalFormProgress from './HorizontalFormProgress';\n\nexport const StyledForm = styled.form<{ actions?: boolean; heading?: boolean }>(\n ({ actions, heading, theme }) => {\n return css`\n & > ${StyledGrid} {\n position: relative;\n\n ${actions &&\n css`\n padding-block-end: calc(2 * ${theme.base.spacing});\n `}\n\n ${heading &&\n css`\n padding-block-start: calc(2 * ${theme.base.spacing});\n `}\n }\n `;\n }\n);\n\nStyledForm.defaultProps = defaultThemeProp;\n\nexport const StyledFormContent = styled.div``;\n\nexport const StyledRequiredFieldLegend = styled(Text)(({ theme }) => {\n const {\n base: {\n 'font-size': fontSize,\n 'font-scale': fontScale,\n palette: { urgent }\n }\n } = theme;\n const { xxs: infoFontSize } = calculateFontSize(fontSize, fontScale);\n\n return css`\n font-size: ${infoFontSize};\n font-style: italic;\n\n &::before {\n display: 'inline';\n content: '\\\\00a0*';\n vertical-align: top;\n color: ${urgent};\n }\n `;\n});\n\nStyledRequiredFieldLegend.defaultProps = defaultThemeProp;\n\nexport const MultiStepForm: FunctionComponent<MultiStepFormProps & ForwardProps> = forwardRef(\n function MultiStepForm(\n {\n currentStepId,\n steps,\n heading,\n stepIndicator: stepIndicatorProp = steps.length < 2 ? 'none' : 'horizontal',\n progress,\n ...restProps\n }: PropsWithoutRef<MultiStepFormProps>,\n ref: MultiStepFormProps['ref']\n ) {\n const multiStepFormContentRef = useRef(null);\n\n const previousId = usePrevious(currentStepId);\n const currentStep = steps.find(step => step.id === currentStepId)!;\n const headingId = useUID();\n const descriptionId = useUID();\n const t = useI18n();\n const {\n base: { 'content-width': contentWidth }\n } = useTheme();\n\n const setFocus = () => {\n if (progress) return;\n\n const focusables = getFocusables(multiStepFormContentRef);\n focusables[0]?.focus();\n };\n\n useEffect(() => {\n if (previousId === undefined) return;\n\n if (previousId !== currentStepId) {\n const focusableElements = getFocusables(multiStepFormContentRef);\n\n if (focusableElements.length) focusableElements[0].focus();\n }\n }, [currentStepId, previousId]);\n\n useAfterInitialEffect(() => {\n if (!progress) {\n setFocus();\n }\n }, [progress]);\n\n const isSmallOrAbove = useBreakpoint('sm');\n\n const stepIndicator =\n stepIndicatorProp === 'vertical' && !isSmallOrAbove ? 'horizontal' : stepIndicatorProp;\n\n let areaDef = '';\n switch (stepIndicator) {\n case 'horizontal':\n areaDef += '\"stepIndicator\" ';\n if (currentStep.banners) areaDef += '\"banners\" ';\n if (currentStep.description) areaDef += '\"description\" ';\n areaDef += '\"content\"';\n break;\n case 'vertical':\n if (currentStep.banners) areaDef += '\"banners stepIndicator\" ';\n if (currentStep.description) areaDef += '\"description stepIndicator\" ';\n areaDef += '\"content stepIndicator\"';\n break;\n default:\n if (currentStep.banners) areaDef += '\"banners\" ';\n if (currentStep.description) areaDef += '\"description\" ';\n areaDef += '\"content\"';\n }\n\n return (\n <StyledForm\n ref={ref}\n {...restProps}\n aria-labelledby={heading ? headingId : undefined}\n aria-describedby={currentStep.description ? descriptionId : undefined}\n heading={!!heading}\n actions={!!currentStep.actions}\n >\n {heading && (\n <Text id={headingId} variant='h3'>\n {heading}\n </Text>\n )}\n\n <Grid\n container={{\n cols:\n stepIndicator === 'vertical'\n ? `2fr minmax(${contentWidth.xs}, 1fr)`\n : 'minmax(0, 1fr)',\n areas: areaDef,\n gap: 2\n }}\n inert={progress ? '' : undefined}\n >\n {steps.length > 1 && (\n <Grid item={{ area: 'stepIndicator' }}>\n {stepIndicator === 'horizontal' && (\n <Grid\n item={{ area: 'stepIndicator' }}\n as={HorizontalFormProgress}\n steps={steps}\n currentStepId={currentStepId}\n />\n )}\n {stepIndicator === 'vertical' && (\n <Grid\n item={{ area: 'stepIndicator' }}\n as={VerticalFormProgress}\n steps={steps}\n currentStepId={currentStepId}\n />\n )}\n <VisuallyHiddenText aria-live='polite'>\n {previousId !== undefined && previousId !== currentStepId\n ? t('step_changed_to_name', [currentStep.name])\n : ''}\n </VisuallyHiddenText>\n </Grid>\n )}\n\n {currentStep.banners && <Grid item={{ area: 'banners' }}>{currentStep.banners}</Grid>}\n\n {currentStep.description && (\n <Grid item={{ area: 'description' }}>\n <HTML id={descriptionId} as='p' content={currentStep.description} />\n </Grid>\n )}\n\n <Grid item={{ area: 'content' }} as={StyledFormContent} ref={multiStepFormContentRef}>\n {currentStep.content}\n </Grid>\n\n <Progress\n visible={!!progress}\n focusOnVisible\n placement='local'\n message={typeof progress === 'string' ? progress : undefined}\n />\n </Grid>\n {currentStep.actions && (\n <Flex container={{ justify: 'between', alignItems: 'center' }}>\n {currentStep.actions}\n </Flex>\n )}\n </StyledForm>\n );\n }\n);\n\nexport default MultiStepForm;\n"]}
|
|
@@ -54,7 +54,7 @@ const ShortcutManager = ({ children, target, bindings: customBindings = {} }) =>
|
|
|
54
54
|
// don't process event during typing letters/digits into inputs without modifier keys
|
|
55
55
|
!(e.target instanceof HTMLElement &&
|
|
56
56
|
['input', 'textarea'].includes(e.target.nodeName.toLowerCase()) &&
|
|
57
|
-
e.
|
|
57
|
+
(e.code.startsWith('Key') || e.code.startsWith('Digit') || e.code.startsWith('Numpad')) &&
|
|
58
58
|
!['Control', 'Meta'].some(modifier => e.getModifierState(modifier))),
|
|
59
59
|
shortcuts: bindings.map(({ action, shortcut }) => ({
|
|
60
60
|
shortcut,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShortcutManager.js","sourceRoot":"","sources":["../../../src/components/ShortcutManager/ShortcutManager.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAG,OAAyB,EAAQ,EAAE;IACnE,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC3B,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,iBAAiB,EAAE,eAAe,EAAE,EAAE,EAAE;YAC7D,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;gBACrB,QAAQ,GAAG;oBACT,GAAI,Q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E,CAAC,CAAC,CAAC;gBACnC,CAAC;aACF,CAAC,CAAC;SACJ,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;YAC9B,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC;QACnC,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,qBAAqB,CAAC,GAAG,EAAE;QACzB,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,CAAC;QAC9C,IAAI,gBAAgB,EAAE;YACpB,gBAAgB,CAAC,KAAK,EAAE,CAAC;YACzB,gBAAgB,CAAC,GAAG,CAClB,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;gBACtC,QAAQ;gBACR,OAAO,EAAE,CAAC,CAAC,EAAE;oBACX,CAAC,CAAC,cAAc,EAAE,CAAC;oBACnB,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBACnC,CAAC;aACF,CAAC,CAAC,CACJ,CAAC;SACH;IACH,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE/B,OAAO,4BAAG,QAAQ,GAAI,CAAC;AACzB,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { FunctionComponent } from 'react';\nimport { Shortcuts } from 'shortcuts';\n\nimport { useAfterInitialEffect, useSimpleStore } from '../../hooks';\nimport { hasProp } from '../../utils';\n\nimport type { ShortcutAction, ShortcutManagerProps } from './ShortcutManager.types';\nimport { actionStore } from './Store';\nimport type { ActionDefinitions } from './Store';\n\n/**\n * Function to register an action triggerable using a shortcut. All actions must be registered before\n * binding a callback.\n * @param actions actions with definitions to be registered.\n */\nexport const registerAction = (...actions: ShortcutAction[]): void => {\n actionStore.setStore(store => {\n let newStore = store;\n actions.forEach(({ id, defaultKeyBinding: defaultShortcut }) => {\n if (!hasProp(store, id))\n newStore = {\n ...(newStore as ActionDefinitions),\n [id]: { defaultKeyBinding: defaultShortcut, keyBinding: defaultShortcut }\n };\n });\n return newStore;\n });\n};\n\nconst dispatchShortcutEvent = (actionId: ShortcutAction['id'], e: KeyboardEvent) => {\n const shortcutEvent = new CustomEvent('shortcut', {\n bubbles: true,\n detail: { actionId }\n });\n e.target?.dispatchEvent(shortcutEvent);\n};\n\nconst ShortcutManager: FunctionComponent<ShortcutManagerProps> = ({\n children,\n target,\n bindings: customBindings = {}\n}) => {\n const shortcutsRef = useRef<Shortcuts>();\n\n const [bindings, setBindings] = useSimpleStore(actionStore, store =>\n Object.entries(store).map(([actionId, actionDefinition]) => ({\n action: actionId,\n shortcut: actionDefinition.keyBinding\n }))\n );\n\n useEffect(() => {\n setBindings(store => {\n let newStore = store;\n Object.entries(customBindings).forEach(([actionId, keyBinding]) => {\n newStore = { ...newStore, [actionId]: { ...newStore[actionId], keyBinding } };\n });\n return newStore;\n });\n }, [JSON.stringify(customBindings)]);\n\n useEffect(() => {\n shortcutsRef.current = new Shortcuts({\n target,\n shouldHandleEvent: e =>\n // both 'keydown' and 'keypress' events are handled by default ('shortcuts' bug?)\n e.type === 'keydown' &&\n !e.defaultPrevented &&\n // don't process event during typing letters/digits into inputs without modifier keys\n !(\n e.target instanceof HTMLElement &&\n ['input', 'textarea'].includes(e.target.nodeName.toLowerCase()) &&\n (e.code.startsWith('Key') || e.code.startsWith('Digit') || e.code.startsWith('Numpad')) &&\n !['Control', 'Meta'].some(modifier => e.getModifierState(modifier))\n ),\n shortcuts: bindings.map(({ action, shortcut }) => ({\n shortcut,\n handler: e => {\n e.preventDefault();\n dispatchShortcutEvent(action, e);\n }\n }))\n });\n\n return () => {\n shortcutsRef.current?.reset();\n shortcutsRef.current = undefined;\n };\n }, [target]);\n\n useAfterInitialEffect(() => {\n const shortcutInstance = shortcutsRef.current;\n if (shortcutInstance) {\n shortcutInstance.reset();\n shortcutInstance.add(\n bindings.map(({ action, shortcut }) => ({\n shortcut,\n handler: e => {\n e.preventDefault();\n dispatchShortcutEvent(action, e);\n }\n }))\n );\n }\n }, [JSON.stringify(bindings)]);\n\n return <>{children}</>;\n};\n\nexport default ShortcutManager;\n"]}
|
package/lib/hooks/useI18n.d.ts
CHANGED
|
@@ -187,6 +187,7 @@ declare const useI18n: () => import("../i18n/translate").TranslationFunction<Rea
|
|
|
187
187
|
app_shell_main_navigation_label: string;
|
|
188
188
|
shortcut_NextRegion: string;
|
|
189
189
|
shortcut_PrevRegion: string;
|
|
190
|
+
app_shell_user_account: string;
|
|
190
191
|
combobox_open_close: string;
|
|
191
192
|
combobox_search_instructions: string;
|
|
192
193
|
combobox_open_list_button_a11y: string;
|
|
@@ -206,7 +207,6 @@ declare const useI18n: () => import("../i18n/translate").TranslationFunction<Rea
|
|
|
206
207
|
modal_maximize: string;
|
|
207
208
|
modal_dock: string;
|
|
208
209
|
modal_close: string;
|
|
209
|
-
symbol_indicates_required_field: string;
|
|
210
210
|
selected_date_a11y: string;
|
|
211
211
|
open_calendar_button_a11y: string;
|
|
212
212
|
close_calendar_button_a11y: string;
|
|
@@ -655,6 +655,8 @@ declare const useI18n: () => import("../i18n/translate").TranslationFunction<Rea
|
|
|
655
655
|
sentiment_negative: string;
|
|
656
656
|
sentiment_neutral: string;
|
|
657
657
|
no_recommendations: string;
|
|
658
|
+
items_added_to_previous_list: string;
|
|
659
|
+
items_added_to_current_list: string;
|
|
658
660
|
condition_builder_advanced_condition_label: string;
|
|
659
661
|
condition_builder_advanced_condition_placeholder: string;
|
|
660
662
|
condition_builder_advanced_mode_button_label: string;
|