@pega/cosmos-react-core 2.0.0-dev.20.0 → 2.0.0-dev.21.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.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.js +34 -20
- package/lib/components/AppShell/AppShell.js.map +1 -1
- package/lib/components/AppShell/AppShell.styles.d.ts +4 -11
- package/lib/components/AppShell/AppShell.styles.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.styles.js +102 -89
- package/lib/components/AppShell/AppShell.styles.js.map +1 -1
- package/lib/components/AppShell/AppShell.types.d.ts +2 -2
- package/lib/components/AppShell/AppShell.types.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.types.js.map +1 -1
- package/lib/components/AppShell/AppShellContext.d.ts +2 -0
- package/lib/components/AppShell/AppShellContext.d.ts.map +1 -1
- package/lib/components/AppShell/AppShellContext.js +1 -0
- package/lib/components/AppShell/AppShellContext.js.map +1 -1
- package/lib/components/ComboBox/ComboBox.js +3 -3
- package/lib/components/ComboBox/ComboBox.js.map +1 -1
- package/lib/components/Configuration/Configuration.js +1 -1
- package/lib/components/Configuration/Configuration.js.map +1 -1
- package/lib/components/Currency/CurrencyDisplay.d.ts +3 -1
- package/lib/components/Currency/CurrencyDisplay.d.ts.map +1 -1
- package/lib/components/Currency/CurrencyDisplay.js +11 -16
- package/lib/components/Currency/CurrencyDisplay.js.map +1 -1
- package/lib/components/Currency/CurrencyInput.js +3 -3
- package/lib/components/Currency/CurrencyInput.js.map +1 -1
- package/lib/components/Currency/CurrencyInput.types.d.ts +3 -1
- package/lib/components/Currency/CurrencyInput.types.d.ts.map +1 -1
- package/lib/components/Currency/CurrencyInput.types.js.map +1 -1
- package/lib/components/Currency/utils.d.ts +12 -1
- package/lib/components/Currency/utils.d.ts.map +1 -1
- package/lib/components/Currency/utils.js +30 -2
- package/lib/components/Currency/utils.js.map +1 -1
- package/lib/components/Modal/Modal.d.ts.map +1 -1
- package/lib/components/Modal/Modal.js +19 -14
- package/lib/components/Modal/Modal.js.map +1 -1
- package/lib/components/Popover/Popover.d.ts.map +1 -1
- package/lib/components/Popover/Popover.js +6 -0
- package/lib/components/Popover/Popover.js.map +1 -1
- package/lib/components/Tree/helpers.d.ts +1 -0
- package/lib/components/Tree/helpers.d.ts.map +1 -1
- package/lib/components/Tree/helpers.js +20 -0
- package/lib/components/Tree/helpers.js.map +1 -1
- package/lib/hooks/index.d.ts +6 -6
- package/lib/hooks/index.d.ts.map +1 -1
- package/lib/hooks/index.js +6 -5
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useTransitionState.d.ts +39 -0
- package/lib/hooks/useTransitionState.d.ts.map +1 -0
- package/lib/hooks/useTransitionState.js +56 -0
- package/lib/hooks/useTransitionState.js.map +1 -0
- package/lib/theme/themes/buildTheme.json +2 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppShellContext.js","sourceRoot":"","sources":["../../../src/components/AppShell/AppShellContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAoB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"AppShellContext.js","sourceRoot":"","sources":["../../../src/components/AppShell/AppShellContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAoB,MAAM,OAAO,CAAC;AAiBxD,MAAM,eAAe,GAAG,aAAa,CAAuB;IAC1D,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,QAAQ;IAClB,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;IACvB,SAAS,EAAE,IAAI;IACf,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB,mBAAmB,EAAE;QACnB,IAAI,OAAO;YACT,OAAO,KAAK,CAAC;QACf,CAAC;KACF;IACD,QAAQ,EAAE,IAAI;CACf,CAAC,CAAC;AAEH,eAAe,eAAe,CAAC","sourcesContent":["import { createContext, MutableRefObject } from 'react';\n\nimport { openCloseStates } from '../../hooks/useTransitionState';\n\ninterface AppShellContextValue {\n navOpen: boolean;\n navState: typeof openCloseStates[keyof typeof openCloseStates];\n drawerOpen: boolean;\n setDrawerOpen: (open: boolean) => void;\n refocusEl: HTMLButtonElement | null;\n setRefocusEl: (el: HTMLButtonElement | null) => void;\n focusedImperatively: MutableRefObject<boolean>;\n headerEl: HTMLDivElement | null;\n}\n\nexport type DrawerContent = 'notifications' | 'recents';\n\nconst AppShellContext = createContext<AppShellContextValue>({\n navOpen: false,\n navState: 'closed',\n drawerOpen: false,\n setDrawerOpen: () => {},\n refocusEl: null,\n setRefocusEl: () => {},\n focusedImperatively: {\n get current() {\n return false;\n }\n },\n headerEl: null\n});\n\nexport default AppShellContext;\n"]}
|
|
@@ -64,7 +64,7 @@ const ComboBox = forwardRef((props, ref) => {
|
|
|
64
64
|
// Force a re-render to make sure useFocusWithin has valid elements to set listeners on.
|
|
65
65
|
const [, setContainerEl] = useElement();
|
|
66
66
|
const containerRef = useConsolidatedRef(ref, setContainerEl);
|
|
67
|
-
useFocusWithin([containerRef], focused => {
|
|
67
|
+
const focus = useFocusWithin([containerRef], focused => {
|
|
68
68
|
if (!focused) {
|
|
69
69
|
setOpen(false);
|
|
70
70
|
onBlur?.(selected?.items);
|
|
@@ -110,10 +110,10 @@ const ComboBox = forwardRef((props, ref) => {
|
|
|
110
110
|
onClick?.(e);
|
|
111
111
|
}, [readOnly, onClick]);
|
|
112
112
|
useEffect(() => {
|
|
113
|
-
if (menu && value && value.length > 0) {
|
|
113
|
+
if (focus && menu && value && value.length > 0) {
|
|
114
114
|
setOpen(true);
|
|
115
115
|
}
|
|
116
|
-
}, [menu, value]);
|
|
116
|
+
}, [menu, value, focus]);
|
|
117
117
|
// Workaround for the following error from jsx-ast-utils, fixed in version 3.5.0.
|
|
118
118
|
// The prop value with an expression type of JSXFragment could not be resolved. Please file issue to get this fixed immediately.
|
|
119
119
|
const inputActions = (_jsxs(_Fragment, { children: [dropdownButton, actions] }, void 0));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboBox.js","sourceRoot":"","sources":["../../../src/components/ComboBox/ComboBox.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAKV,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,EACT,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,WAAW,MAAM,6BAA6B,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9F,OAAO,OAAO,EAAE,EAAgB,aAAa,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAE1C,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAG5C,YAAY,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAEzC,MAAM,gBAAgB,GAA8B;IAClD;QACE,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,IAAI;QACb,OAAO,EAAE;YACP,kBAAkB,EAAE,CAAC,WAAW,CAAC;SAClC;KACF;IACD;QACE,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,IAAI;KACd;IACD;QACE,IAAI,EAAE,MAAM;QAC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,KAAC,IAAI,IACH,GAAG,EAAE,OAAO,EACZ,EAAE,EAAE,eAAe,EACnB,IAAI,EAAC,SAAS,EACd,IAAI,EAAE,IAAI,KACN,IAAI,EACR,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,cAAc,EAAE,QAAQ,CAAC,OAAO,IAAI,SAAS,EAC7C,WAAW,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBACzB,IAAI,IAAI,KAAK,eAAe,EAAE;4BAC5B,OAAO,CAAC,KAAK,CAAC,CAAC;yBAChB;wBACD,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;wBAE9B,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;wBAE5D,IAAI,WAAW,EAAE,OAAO,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE;4BAClD,QAAQ,EAAE,KAAK,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;yBACzC;oBACH,CAAC,EACD,0BAA0B,iBAC1B,CACH,WACO,YACK,CAClB,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,OAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YACxE,IAAI,WACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n KeyboardEvent as ReactKeyboardEvent,\n PropsWithoutRef,\n Ref,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState\n} from 'react';\nimport styled from 'styled-components';\nimport { hideVisually } from 'polished';\n\nimport Icon, { registerIcon } from '../Icon';\nimport * as caretDownIcon from '../Icon/icons/caret-down.icon';\nimport * as caretUpIcon from '../Icon/icons/caret-up.icon';\nimport { ForwardProps } from '../../types';\nimport { useConsolidatedRef, useFocusWithin, useI18n, useUID, useElement } from '../../hooks';\nimport Popover, { PopoverProps, StyledPopover } from '../Popover';\nimport FormField from '../FormField';\nimport { StyledFormControl } from '../FormControl';\nimport Menu from '../Menu';\nimport Button from '../Button';\nimport { navigatorIsAvailable } from '../../utils';\nimport menuHelpers from '../Menu/helpers';\n\nimport ComboBoxInput from './ComboBoxInput';\nimport ComboBoxProps from './ComboBox.types';\n\nregisterIcon(caretDownIcon, caretUpIcon);\n\nconst popoverModifiers: PopoverProps['modifiers'] = [\n {\n name: 'flip',\n enabled: true,\n options: {\n fallbackPlacements: ['top-start']\n }\n },\n {\n name: 'preventOverflow',\n enabled: true\n },\n {\n name: 'hide',\n enabled: false\n },\n {\n name: 'sameWidth',\n enabled: true,\n phase: 'beforeWrite',\n fn({ state }) {\n state.styles.popper.width = `${state.rects.reference.width}px`;\n },\n requires: ['computeStyles']\n }\n];\n\nexport const StyledComboBox = styled(StyledFormControl)`\n border: 0;\n\n & ${StyledPopover} {\n border-top-left-radius: 0;\n border-top-right-radius: 0;\n }\n`;\n\nconst StyledAriaDescription = styled.p`\n ${hideVisually}\n`;\n\nconst isMobile = navigatorIsAvailable && navigator.userAgent.includes('Mobile');\n\nconst ComboBox: FunctionComponent<ComboBoxProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<ComboBoxProps>, ref: Ref<HTMLDivElement>) => {\n const uid = useUID();\n const {\n value,\n required,\n id = uid,\n label,\n labelHidden,\n info,\n status,\n readOnly,\n disabled,\n mode = 'single-select',\n selected,\n onChange,\n actions,\n onFocus,\n onBlur,\n onDropdownButtonClick: onDropdownButtonClickProp,\n onClick,\n menu,\n ...restProps\n } = props;\n\n const t = useI18n();\n const inputRef = useRef<HTMLInputElement>(null);\n const [open, setOpen] = useState<boolean>(false);\n const menuRef = useRef<HTMLDivElement>(null);\n const menuComponentId = `${id}-listbox`;\n\n // Force a re-render to make sure useFocusWithin has valid elements to set listeners on.\n const [, setContainerEl] = useElement();\n const containerRef = useConsolidatedRef<HTMLDivElement>(ref, setContainerEl);\n\n useFocusWithin([containerRef], focused => {\n if (!focused) {\n setOpen(false);\n onBlur?.(selected?.items);\n } else {\n onFocus?.(selected?.items);\n if (isMobile) {\n setTimeout(() => {\n containerRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' });\n }, 150); // delay it to let keyboard expand first\n }\n }\n });\n\n const onInputKeyDown = useCallback(\n (e: ReactKeyboardEvent<HTMLInputElement>) => {\n if (!menu || readOnly) return;\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n if (!open) setOpen(true);\n break;\n case 'Escape':\n e.preventDefault();\n if (open) e.stopPropagation();\n setOpen(false);\n break;\n default:\n }\n },\n [open, readOnly, menu, value]\n );\n\n const onDropdownButtonClick = useCallback(() => {\n onDropdownButtonClickProp?.(!open);\n setOpen(!open);\n }, [open, onDropdownButtonClickProp]);\n\n const dropdownButton = useMemo(() => {\n return (menu?.items?.length || onDropdownButtonClickProp || !onChange) && !readOnly ? (\n <Button\n aria-label={t(\n open ? 'combobox_close_list_button_a11y' : 'combobox_open_list_button_a11y'\n )}\n icon\n variant='simple'\n onClick={onDropdownButtonClick}\n disabled={disabled}\n tabIndex='-1'\n >\n <Icon name={open ? 'caret-up' : 'caret-down'} />\n </Button>\n ) : null;\n }, [onDropdownButtonClick, onChange, readOnly, open, disabled]);\n\n const onInputClick = useCallback(\n (e: MouseEvent) => {\n if (readOnly) return;\n setOpen(true);\n onClick?.(e);\n },\n [readOnly, onClick]\n );\n\n useEffect(() => {\n if (menu && value && value.length > 0) {\n setOpen(true);\n }\n }, [menu, value]);\n\n // Workaround for the following error from jsx-ast-utils, fixed in version 3.5.0.\n // The prop value with an expression type of JSXFragment could not be resolved. Please file issue to get this fixed immediately.\n const inputActions = (\n <>\n {dropdownButton}\n {actions}\n </>\n );\n\n const Comp = (\n <StyledComboBox ref={containerRef} as={StyledFormControl} id={`${id}-combobox`}>\n <ComboBoxInput\n ref={inputRef}\n role='combobox'\n aria-haspopup='listbox'\n aria-expanded={!readOnly && !disabled && open}\n aria-autocomplete='list'\n aria-describedby={`${id}-inputDescription`}\n selected={selected?.items}\n spellCheck={false}\n {...{\n id,\n readOnly,\n disabled,\n onChange,\n value,\n mode,\n status\n }}\n actions={inputActions}\n onRemove={selected?.onRemove}\n onClick={onInputClick}\n onKeyDown={onInputKeyDown}\n {...restProps}\n />\n\n <StyledAriaDescription id={`${id}-inputDescription`}>\n {t('combobox_open_close')}\n {!!onChange && ` ${t('combobox_search_instructions')}`}\n </StyledAriaDescription>\n\n <Popover\n show={open && menu !== undefined}\n target={containerRef.current}\n placement='bottom-start'\n modifiers={popoverModifiers}\n strategy={isMobile ? 'absolute' : 'fixed'}\n onMouseDown={(e: MouseEvent) => e.preventDefault()}\n >\n {menu && (\n <Menu\n ref={menuRef}\n id={menuComponentId}\n role='listbox'\n mode={mode}\n {...menu}\n items={menu.items}\n focusControlEl={inputRef.current || undefined}\n onItemClick={(itemId, e) => {\n if (mode === 'single-select') {\n setOpen(false);\n }\n menu.onItemClick?.(itemId, e);\n\n const clickedItem = menuHelpers.getItem(menu.items, itemId);\n\n if (clickedItem?.primary && !clickedItem?.selected) {\n selected?.onNew?.(clickedItem?.primary);\n }\n }}\n arrowNavigationUnsupported\n />\n )}\n </Popover>\n </StyledComboBox>\n );\n\n return label ? (\n <FormField {...{ label, labelHidden, id, info, status, required, disabled }}>\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default ComboBox;\n"]}
|
|
1
|
+
{"version":3,"file":"ComboBox.js","sourceRoot":"","sources":["../../../src/components/ComboBox/ComboBox.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAKV,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,EACT,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,UA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Ae,EAAE;4BAC5B,OAAO,CAAC,KAAK,CAAC,CAAC;yBAChB;wBACD,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;wBAE9B,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;wBAE5D,IAAI,WAAW,EAAE,OAAO,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE;4BAClD,QAAQ,EAAE,KAAK,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;yBACzC;oBACH,CAAC,EACD,0BAA0B,iBAC1B,CACH,WACO,YACK,CAClB,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,OAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YACxE,IAAI,WACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n KeyboardEvent as ReactKeyboardEvent,\n PropsWithoutRef,\n Ref,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState\n} from 'react';\nimport styled from 'styled-components';\nimport { hideVisually } from 'polished';\n\nimport Icon, { registerIcon } from '../Icon';\nimport * as caretDownIcon from '../Icon/icons/caret-down.icon';\nimport * as caretUpIcon from '../Icon/icons/caret-up.icon';\nimport { ForwardProps } from '../../types';\nimport { useConsolidatedRef, useFocusWithin, useI18n, useUID, useElement } from '../../hooks';\nimport Popover, { PopoverProps, StyledPopover } from '../Popover';\nimport FormField from '../FormField';\nimport { StyledFormControl } from '../FormControl';\nimport Menu, { MenuProps } from '../Menu';\nimport Button from '../Button';\nimport { navigatorIsAvailable } from '../../utils';\nimport menuHelpers from '../Menu/helpers';\n\nimport ComboBoxInput from './ComboBoxInput';\nimport ComboBoxProps from './ComboBox.types';\n\nregisterIcon(caretDownIcon, caretUpIcon);\n\nconst popoverModifiers: PopoverProps['modifiers'] = [\n {\n name: 'flip',\n enabled: true,\n options: {\n fallbackPlacements: ['top-start']\n }\n },\n {\n name: 'preventOverflow',\n enabled: true\n },\n {\n name: 'hide',\n enabled: false\n },\n {\n name: 'sameWidth',\n enabled: true,\n phase: 'beforeWrite',\n fn({ state }) {\n state.styles.popper.width = `${state.rects.reference.width}px`;\n },\n requires: ['computeStyles']\n }\n];\n\nexport const StyledComboBox = styled(StyledFormControl)`\n border: 0;\n\n & ${StyledPopover} {\n border-top-left-radius: 0;\n border-top-right-radius: 0;\n }\n`;\n\nconst StyledAriaDescription = styled.p`\n ${hideVisually}\n`;\n\nconst isMobile = navigatorIsAvailable && navigator.userAgent.includes('Mobile');\n\nconst ComboBox: FunctionComponent<ComboBoxProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<ComboBoxProps>, ref: Ref<HTMLDivElement>) => {\n const uid = useUID();\n const {\n value,\n required,\n id = uid,\n label,\n labelHidden,\n info,\n status,\n readOnly,\n disabled,\n mode = 'single-select',\n selected,\n onChange,\n actions,\n onFocus,\n onBlur,\n onDropdownButtonClick: onDropdownButtonClickProp,\n onClick,\n menu,\n ...restProps\n } = props;\n\n const t = useI18n();\n const inputRef = useRef<HTMLInputElement>(null);\n const [open, setOpen] = useState(false);\n const menuRef: MenuProps['ref'] = useRef(null);\n const menuComponentId = `${id}-listbox`;\n\n // Force a re-render to make sure useFocusWithin has valid elements to set listeners on.\n const [, setContainerEl] = useElement();\n const containerRef = useConsolidatedRef<HTMLDivElement>(ref, setContainerEl);\n\n const focus = useFocusWithin([containerRef], focused => {\n if (!focused) {\n setOpen(false);\n onBlur?.(selected?.items);\n } else {\n onFocus?.(selected?.items);\n if (isMobile) {\n setTimeout(() => {\n containerRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' });\n }, 150); // delay it to let keyboard expand first\n }\n }\n });\n\n const onInputKeyDown = useCallback(\n (e: ReactKeyboardEvent<HTMLInputElement>) => {\n if (!menu || readOnly) return;\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n if (!open) setOpen(true);\n break;\n case 'Escape':\n e.preventDefault();\n if (open) e.stopPropagation();\n setOpen(false);\n break;\n default:\n }\n },\n [open, readOnly, menu, value]\n );\n\n const onDropdownButtonClick = useCallback(() => {\n onDropdownButtonClickProp?.(!open);\n setOpen(!open);\n }, [open, onDropdownButtonClickProp]);\n\n const dropdownButton = useMemo(() => {\n return (menu?.items?.length || onDropdownButtonClickProp || !onChange) && !readOnly ? (\n <Button\n aria-label={t(\n open ? 'combobox_close_list_button_a11y' : 'combobox_open_list_button_a11y'\n )}\n icon\n variant='simple'\n onClick={onDropdownButtonClick}\n disabled={disabled}\n tabIndex='-1'\n >\n <Icon name={open ? 'caret-up' : 'caret-down'} />\n </Button>\n ) : null;\n }, [onDropdownButtonClick, onChange, readOnly, open, disabled]);\n\n const onInputClick = useCallback(\n (e: MouseEvent) => {\n if (readOnly) return;\n setOpen(true);\n onClick?.(e);\n },\n [readOnly, onClick]\n );\n\n useEffect(() => {\n if (focus && menu && value && value.length > 0) {\n setOpen(true);\n }\n }, [menu, value, focus]);\n\n // Workaround for the following error from jsx-ast-utils, fixed in version 3.5.0.\n // The prop value with an expression type of JSXFragment could not be resolved. Please file issue to get this fixed immediately.\n const inputActions = (\n <>\n {dropdownButton}\n {actions}\n </>\n );\n\n const Comp = (\n <StyledComboBox ref={containerRef} as={StyledFormControl} id={`${id}-combobox`}>\n <ComboBoxInput\n ref={inputRef}\n role='combobox'\n aria-haspopup='listbox'\n aria-expanded={!readOnly && !disabled && open}\n aria-autocomplete='list'\n aria-describedby={`${id}-inputDescription`}\n selected={selected?.items}\n spellCheck={false}\n {...{\n id,\n readOnly,\n disabled,\n onChange,\n value,\n mode,\n status\n }}\n actions={inputActions}\n onRemove={selected?.onRemove}\n onClick={onInputClick}\n onKeyDown={onInputKeyDown}\n {...restProps}\n />\n\n <StyledAriaDescription id={`${id}-inputDescription`}>\n {t('combobox_open_close')}\n {!!onChange && ` ${t('combobox_search_instructions')}`}\n </StyledAriaDescription>\n\n <Popover\n show={open && menu !== undefined}\n target={containerRef.current}\n placement='bottom-start'\n modifiers={popoverModifiers}\n strategy={isMobile ? 'absolute' : 'fixed'}\n onMouseDown={(e: MouseEvent) => e.preventDefault()}\n >\n {menu && (\n <Menu\n ref={menuRef}\n id={menuComponentId}\n role='listbox'\n mode={mode}\n {...menu}\n items={menu.items}\n focusControlEl={inputRef.current || undefined}\n onItemClick={(itemId, e) => {\n if (mode === 'single-select') {\n setOpen(false);\n }\n menu.onItemClick?.(itemId, e);\n\n const clickedItem = menuHelpers.getItem(menu.items, itemId);\n\n if (clickedItem?.primary && !clickedItem?.selected) {\n selected?.onNew?.(clickedItem?.primary);\n }\n }}\n arrowNavigationUnsupported\n />\n )}\n </Popover>\n </StyledComboBox>\n );\n\n return label ? (\n <FormField {...{ label, labelHidden, id, info, status, required, disabled }}>\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default ComboBox;\n"]}
|
|
@@ -25,7 +25,7 @@ if (windowIsAvailable) {
|
|
|
25
25
|
if (!window[metaKey]) {
|
|
26
26
|
window[metaKey] = [];
|
|
27
27
|
}
|
|
28
|
-
window[metaKey].push({ version: '2.0.0-dev.
|
|
28
|
+
window[metaKey].push({ version: '2.0.0-dev.21.0' });
|
|
29
29
|
}
|
|
30
30
|
const Configuration = ({ context = ConfigurationContext, children, locale, direction, translations: customTranslations, theme, disableDefaultFontLoading, styleSheetTarget, portalTarget, overrideMap, renderNativeControls }) => {
|
|
31
31
|
const ctx = useContext(context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/components/Configuration/Configuration.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,UAAU,EAIV,OAAO,EACP,QAAQ,EACR,SAAS,EAEV,MAA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AG,EAAC,YAAY,EAChB,IAAI,EAAC,+GAA+G,WACpH,EACF,QAAQ,CAAC,IAAI,CACd,EACH,KAAC,WAAW,aAAG,EACd,QAAQ,YACR,WACe,CACrB,CAAC;IACF,OAAO,CACL,KAAC,oBAAoB,CAAC,QAAQ,IAC5B,KAAK,EAAE;YACL,MAAM,EAAE,MAAM,IAAI,GAAG,CAAC,MAAM;YAC5B,SAAS,EAAE,SAAS,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC;YAC1F,YAAY;YACZ,YAAY;YACZ,CAAC,cAAc,CAAC,EAAE,IAAI;YACtB,gBAAgB,EAAE,gBAAgB,IAAI,GAAG,CAAC,gBAAgB;YAC1D,YAAY,EAAE,YAAY,IAAI,GAAG,CAAC,YAAY;YAC9C,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW;YACnF,oBAAoB,EAAE,oBAAoB,IAAI,GAAG,CAAC,oBAAoB;SACvE,YAED,KAAC,aAAa,IAAC,KAAK,EAAE,YAAY,CAAC,KAAK,YAAG,eAAe,WAAiB,WAC7C,CACjC,CAAC;AACJ,CAAC,CAAC;AAEF,aAAa,CAAC,YAAY,GAAG,YAAY,CAAC;AAE1C,eAAe,aAAa,CAAC","sourcesContent":["import {\n createContext,\n useContext,\n FunctionComponent,\n ComponentType,\n ReactNode,\n useMemo,\n useState,\n useEffect,\n Context\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { ThemeProvider, StyleSheetManager } from 'styled-components';\n\nimport { GlobalStyle } from '../../styles';\nimport {\n ThemeMachine,\n BaseThemeMachine,\n DefaultSettableTheme,\n DefaultThemeDefinition\n} from '../../theme';\nimport {\n createTranslationPack,\n Translation,\n TranslationPack,\n DefaultTranslation,\n direction as directionOfLocale\n} from '../../i18n';\nimport { FileInputProps } from '../File';\nimport { windowIsAvailable, navigatorIsAvailable, documentIsAvailable } from '../../utils';\n\nexport interface ConfigurationProps {\n /**\n * Any components or nodes that should be impacted by the settings applied by this Configuration component.\n */\n children: ReactNode;\n /**\n * Context to read previous configuration values from.\n */\n context?: Context<ConfigurationContextValue>;\n /**\n * User locale as defined in [BCP-47](https://www.techonthenet.com/js/language_tags.php).\n */\n locale?: string;\n /**\n * Override rendering direction of the document. Direction will be based on the locale if now provided.\n */\n direction?: 'ltr' | 'rtl';\n /**\n * Object with (partial) translations.\n */\n translations?: Translation;\n /**\n * Theme object used to override any or all Cosmos theme properties.\n */\n theme?: DefaultSettableTheme;\n /**\n * Disables loading Open Sans from Google Fonts. Only takes effect on the root configuration.\n */\n disableDefaultFontLoading?: boolean;\n /**\n * Target element for loading styles related to `styled-components`.\n */\n styleSheetTarget?: HTMLElement;\n /**\n * Target element for rendering a `ReactDOM` portal.\n */\n portalTarget?: Element;\n /**\n * Override map to replace Cosmos components.\n */\n overrideMap?: {\n FileInput?: ComponentType<FileInputProps>;\n };\n /**\n * Use native HTML5 controls for inputs instead of rich ones.\n * @default false\n */\n renderNativeControls?: boolean;\n}\n\nconst initializedKey = Symbol.for('@pega/cosmos-react-core.configuration.initialized');\n\nexport interface ConfigurationContextValue {\n [initializedKey]: boolean;\n locale: string;\n direction: ConfigurationProps['direction'];\n translations: TranslationPack;\n themeMachine: ThemeMachine<DefaultThemeDefinition>;\n styleSheetTarget?: HTMLElement;\n portalTarget?: Element;\n overrideMap: NonNullable<ConfigurationProps['overrideMap']>;\n renderNativeControls: boolean;\n}\n\nconst defaultProps: Partial<ConfigurationProps> = {};\nconst defaultLocale = navigatorIsAvailable ? navigator.language : 'en';\n\nexport const ConfigurationContext = createContext<ConfigurationContextValue>({\n [initializedKey]: false,\n locale: defaultLocale,\n direction: directionOfLocale(defaultLocale),\n translations: DefaultTranslation,\n themeMachine: BaseThemeMachine,\n styleSheetTarget: documentIsAvailable ? document.head : undefined,\n portalTarget: documentIsAvailable ? document.body : undefined,\n overrideMap: {},\n renderNativeControls: false\n});\n\nconst metaKey = Symbol.for('@pega/cosmos-react-core.metadata');\n\ninterface CosmosMetadata {\n version: string;\n}\n\ndeclare global {\n interface Window {\n [metaKey]: CosmosMetadata[];\n }\n}\n\nif (windowIsAvailable) {\n if (!window[metaKey]) {\n window[metaKey] = [];\n }\n\n window[metaKey].push({ version: '2.0.0-dev.
|
|
1
|
+
{"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/components/Configuration/Configuration.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,UAAU,EAIV,OAAO,EACP,QAAQ,EACR,SAAS,EAEV,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EAGrB,kBAAkB,EAClB,SAAS,IAAI,iBAAiB,EAC/B,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAoD3F,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;AAcvF,MAAM,YAAY,GAAgC,EAAE,CAAC;AACrD,MAAM,aAAa,GAAG,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;AAEvE,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAA4B;IAC3E,CAAC,cAAc,CAAC,EAAE,KAAK;IACvB,MAAM,EAAE,aAAa;IACrB,SAAS,EAAE,iBAAiB,CAAC,aAA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AK,EAAE,YAAY,CAAC,KAAK,YAAG,eAAe,WAAiB,WAC7C,CACjC,CAAC;AACJ,CAAC,CAAC;AAEF,aAAa,CAAC,YAAY,GAAG,YAAY,CAAC;AAE1C,eAAe,aAAa,CAAC","sourcesContent":["import {\n createContext,\n useContext,\n FunctionComponent,\n ComponentType,\n ReactNode,\n useMemo,\n useState,\n useEffect,\n Context\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { ThemeProvider, StyleSheetManager } from 'styled-components';\n\nimport { GlobalStyle } from '../../styles';\nimport {\n ThemeMachine,\n BaseThemeMachine,\n DefaultSettableTheme,\n DefaultThemeDefinition\n} from '../../theme';\nimport {\n createTranslationPack,\n Translation,\n TranslationPack,\n DefaultTranslation,\n direction as directionOfLocale\n} from '../../i18n';\nimport { FileInputProps } from '../File';\nimport { windowIsAvailable, navigatorIsAvailable, documentIsAvailable } from '../../utils';\n\nexport interface ConfigurationProps {\n /**\n * Any components or nodes that should be impacted by the settings applied by this Configuration component.\n */\n children: ReactNode;\n /**\n * Context to read previous configuration values from.\n */\n context?: Context<ConfigurationContextValue>;\n /**\n * User locale as defined in [BCP-47](https://www.techonthenet.com/js/language_tags.php).\n */\n locale?: string;\n /**\n * Override rendering direction of the document. Direction will be based on the locale if now provided.\n */\n direction?: 'ltr' | 'rtl';\n /**\n * Object with (partial) translations.\n */\n translations?: Translation;\n /**\n * Theme object used to override any or all Cosmos theme properties.\n */\n theme?: DefaultSettableTheme;\n /**\n * Disables loading Open Sans from Google Fonts. Only takes effect on the root configuration.\n */\n disableDefaultFontLoading?: boolean;\n /**\n * Target element for loading styles related to `styled-components`.\n */\n styleSheetTarget?: HTMLElement;\n /**\n * Target element for rendering a `ReactDOM` portal.\n */\n portalTarget?: Element;\n /**\n * Override map to replace Cosmos components.\n */\n overrideMap?: {\n FileInput?: ComponentType<FileInputProps>;\n };\n /**\n * Use native HTML5 controls for inputs instead of rich ones.\n * @default false\n */\n renderNativeControls?: boolean;\n}\n\nconst initializedKey = Symbol.for('@pega/cosmos-react-core.configuration.initialized');\n\nexport interface ConfigurationContextValue {\n [initializedKey]: boolean;\n locale: string;\n direction: ConfigurationProps['direction'];\n translations: TranslationPack;\n themeMachine: ThemeMachine<DefaultThemeDefinition>;\n styleSheetTarget?: HTMLElement;\n portalTarget?: Element;\n overrideMap: NonNullable<ConfigurationProps['overrideMap']>;\n renderNativeControls: boolean;\n}\n\nconst defaultProps: Partial<ConfigurationProps> = {};\nconst defaultLocale = navigatorIsAvailable ? navigator.language : 'en';\n\nexport const ConfigurationContext = createContext<ConfigurationContextValue>({\n [initializedKey]: false,\n locale: defaultLocale,\n direction: directionOfLocale(defaultLocale),\n translations: DefaultTranslation,\n themeMachine: BaseThemeMachine,\n styleSheetTarget: documentIsAvailable ? document.head : undefined,\n portalTarget: documentIsAvailable ? document.body : undefined,\n overrideMap: {},\n renderNativeControls: false\n});\n\nconst metaKey = Symbol.for('@pega/cosmos-react-core.metadata');\n\ninterface CosmosMetadata {\n version: string;\n}\n\ndeclare global {\n interface Window {\n [metaKey]: CosmosMetadata[];\n }\n}\n\nif (windowIsAvailable) {\n if (!window[metaKey]) {\n window[metaKey] = [];\n }\n\n window[metaKey].push({ version: '2.0.0-dev.21.0' });\n}\n\nconst Configuration: FunctionComponent<ConfigurationProps> = ({\n context = ConfigurationContext,\n children,\n locale,\n direction,\n translations: customTranslations,\n theme,\n disableDefaultFontLoading,\n styleSheetTarget,\n portalTarget,\n overrideMap,\n renderNativeControls\n}: ConfigurationProps) => {\n const ctx = useContext(context);\n const themeMachine = theme\n ? new ThemeMachine<DefaultThemeDefinition>({ theme, parent: ctx.themeMachine })\n : ctx.themeMachine;\n const translations = useMemo(\n () => createTranslationPack({ ...ctx.translations, ...customTranslations }),\n [ctx.translations, customTranslations]\n );\n\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n const wrappedChildren = ctx[initializedKey] ? (\n children\n ) : (\n <StyleSheetManager disableVendorPrefixes target={styleSheetTarget ?? ctx.styleSheetTarget}>\n <>\n {!disableDefaultFontLoading &&\n mounted &&\n documentIsAvailable &&\n createPortal(\n <link\n rel='stylesheet'\n href='https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap'\n />,\n document.head\n )}\n <GlobalStyle />\n {children}\n </>\n </StyleSheetManager>\n );\n return (\n <ConfigurationContext.Provider\n value={{\n locale: locale ?? ctx.locale,\n direction: direction ?? (locale !== undefined ? directionOfLocale(locale) : ctx.direction),\n translations,\n themeMachine,\n [initializedKey]: true,\n styleSheetTarget: styleSheetTarget ?? ctx.styleSheetTarget,\n portalTarget: portalTarget ?? ctx.portalTarget,\n overrideMap: overrideMap ? { ...ctx.overrideMap, ...overrideMap } : ctx.overrideMap,\n renderNativeControls: renderNativeControls ?? ctx.renderNativeControls\n }}\n >\n <ThemeProvider theme={themeMachine.theme}>{wrappedChildren}</ThemeProvider>\n </ConfigurationContext.Provider>\n );\n};\n\nConfiguration.defaultProps = defaultProps;\n\nexport default Configuration;\n"]}
|
|
@@ -5,7 +5,9 @@ export interface CurrencyDisplayProps extends BaseProps {
|
|
|
5
5
|
value?: string;
|
|
6
6
|
/** Three letter currency shorthand ISO code. If not provided or invalid, component renders as number */
|
|
7
7
|
currencyISOCode?: string;
|
|
8
|
-
/** Always show ISO code
|
|
8
|
+
/** Always show ISO code
|
|
9
|
+
* @default false
|
|
10
|
+
* */
|
|
9
11
|
alwaysShowISOCode?: boolean;
|
|
10
12
|
formattingOptions?: {
|
|
11
13
|
/** Determines whether decimal places should be shown. The value is simply truncated if true.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAmB,GAAG,EAAW,MAAM,OAAO,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"CurrencyDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAmB,GAAG,EAAW,MAAM,OAAO,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKtD,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wGAAwG;IACxG,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;SAEK;IACL,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,EAAE;QAClB;;WAEG;QACH,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB;;WAEG;QACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;KAC/B,CAAC;IACF,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;CAC9B;AAED,QAAA,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAqC3E,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useMemo } from 'react';
|
|
3
3
|
import { useConfiguration } from '../../hooks';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const CurrencyDisplay = forwardRef(({ value = '', currencyISOCode, alwaysShowISOCode, formattingOptions = {}, ...restProps }, ref) => {
|
|
4
|
+
import { getDisplayValue } from './utils';
|
|
5
|
+
const CurrencyDisplay = forwardRef(({ value = '', currencyISOCode, alwaysShowISOCode = false, formattingOptions = {}, ...restProps }, ref) => {
|
|
7
6
|
const { locale } = useConfiguration();
|
|
8
7
|
const { showDecimal = true, showGroupSeparators = true } = formattingOptions;
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return formattedValue;
|
|
19
|
-
};
|
|
20
|
-
const symbolOrISOCode = alwaysShowISOCode ? validCurrencyISOCode : symbol;
|
|
21
|
-
return (_jsx("span", { ref: ref, ...restProps, children: value ? (`${symbolPlacement === 'before' ? symbolOrISOCode : ''}${getFormattedValue(!showDecimal ? value.split('.')[0] : addTrailingZeros(value), locale, showGroupSeparators, maximumFractionDigits)} ${symbolPlacement === 'after' ? symbolOrISOCode : ''}`) : (_jsx("span", { "aria-hidden": 'true', children: "\u2013\u2013" }, void 0)) }, void 0));
|
|
8
|
+
const displayValue = useMemo(() => value ? (getDisplayValue({
|
|
9
|
+
value,
|
|
10
|
+
locale,
|
|
11
|
+
alwaysShowISOCode,
|
|
12
|
+
showDecimal,
|
|
13
|
+
showGroupSeparators,
|
|
14
|
+
currencyISOCode
|
|
15
|
+
})) : (_jsx("span", { "aria-hidden": 'true', children: "\u2013\u2013" }, void 0)), [value, locale, alwaysShowISOCode, showDecimal, showGroupSeparators, currencyISOCode]);
|
|
16
|
+
return (_jsx("span", { ref: ref, ...restProps, children: displayValue }, void 0));
|
|
22
17
|
});
|
|
23
18
|
export default CurrencyDisplay;
|
|
24
19
|
//# sourceMappingURL=CurrencyDisplay.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyDisplay.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAA2C,OAAO,EAAE,MAAM,OAAO,CAAC;AAGrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"CurrencyDisplay.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAA2C,OAAO,EAAE,MAAM,OAAO,CAAC;AAGrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAyB1C,MAAM,eAAe,GAA2D,UAAU,CACxF,CACE,EACE,KAAK,GAAG,EAAE,EACV,eAAe,EACf,iBAAiB,GAAG,KAAK,EACzB,iBAAiB,GAAG,EAAE,EACtB,GAAG,SAAS,EAC0B,EACxC,GAAgC,EAChC,EAAE;IACF,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACtC,MAAM,EAAE,WAAW,GAAG,IAAI,EAAE,mBAAmB,GAAG,IAAI,EAAE,GAAG,iBAAiB,CAAC;IAE7E,MAAM,YAAY,GAAG,OAAO,CAC1B,GAAG,EAAE,CACH,KAAK,CAAC,CAAC,CAAC,CACN,eAAe,CAAC;QACd,KAAK;QACL,MAAM;QACN,iBAAiB;QACjB,WAAW;QACX,mBAAmB;QACnB,eAAe;KAChB,CAAC,CACH,CAAC,CAAC,CAAC,CACF,8BAAkB,MAAM,qCAAsB,CAC/C,EACH,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,mBAAmB,EAAE,eAAe,CAAC,CACtF,CAAC;IAEF,OAAO,CACL,eAAM,GAAG,EAAE,GAAG,KAAM,SAAS,YAC1B,YAAY,WACR,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef, Ref, useMemo } from 'react';\n\nimport { BaseProps, ForwardProps } from '../../types';\nimport { useConfiguration } from '../../hooks';\n\nimport { getDisplayValue } from './utils';\n\nexport interface CurrencyDisplayProps extends BaseProps {\n /** Number value */\n value?: string;\n /** Three letter currency shorthand ISO code. If not provided or invalid, component renders as number */\n currencyISOCode?: string;\n /** Always show ISO code\n * @default false\n * */\n alwaysShowISOCode?: boolean;\n formattingOptions?: {\n /** Determines whether decimal places should be shown. The value is simply truncated if true.\n * @default true\n */\n showDecimal?: boolean;\n /** Determines whether group separators should be shown.\n * @default true\n */\n showGroupSeparators?: boolean;\n };\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLAnchorElement>;\n}\n\nconst CurrencyDisplay: FunctionComponent<CurrencyDisplayProps & ForwardProps> = forwardRef(\n (\n {\n value = '',\n currencyISOCode,\n alwaysShowISOCode = false,\n formattingOptions = {},\n ...restProps\n }: PropsWithoutRef<CurrencyDisplayProps>,\n ref: CurrencyDisplayProps['ref']\n ) => {\n const { locale } = useConfiguration();\n const { showDecimal = true, showGroupSeparators = true } = formattingOptions;\n\n const displayValue = useMemo(\n () =>\n value ? (\n getDisplayValue({\n value,\n locale,\n alwaysShowISOCode,\n showDecimal,\n showGroupSeparators,\n currencyISOCode\n })\n ) : (\n <span aria-hidden='true'>––</span>\n ),\n [value, locale, alwaysShowISOCode, showDecimal, showGroupSeparators, currencyISOCode]\n );\n\n return (\n <span ref={ref} {...restProps}>\n {displayValue}\n </span>\n );\n }\n);\n\nexport default CurrencyDisplay;\n"]}
|
|
@@ -6,10 +6,10 @@ import { NumberInput } from '../Number';
|
|
|
6
6
|
import { getCurrencyMaximumFractionDigits, getCurrencySymbol, isCurrencyISOCodeValid } from './utils';
|
|
7
7
|
const CurrencyInput = forwardRef((props, ref) => {
|
|
8
8
|
const uid = useUID();
|
|
9
|
-
const { id = uid, status, label, labelHidden, info, required, disabled, readOnly, value = '', onBlur, onFocus, showDecimal = true, currencyISOCode, alwaysShowISOCode, ...restProps } = props;
|
|
9
|
+
const { id = uid, status, label, labelHidden, info, required, disabled, readOnly, value = '', onBlur, onFocus, showDecimal = true, currencyISOCode, alwaysShowISOCode = false, ...restProps } = props;
|
|
10
10
|
const { locale } = useConfiguration();
|
|
11
11
|
const validCurrencyISOCode = useMemo(() => (isCurrencyISOCodeValid(currencyISOCode) ? currencyISOCode : undefined), [currencyISOCode]);
|
|
12
|
-
const { symbol, symbolPlacement } = useMemo(() => getCurrencySymbol(locale, validCurrencyISOCode), [locale, validCurrencyISOCode]);
|
|
12
|
+
const { symbol, symbolPlacement } = useMemo(() => getCurrencySymbol(locale, alwaysShowISOCode, validCurrencyISOCode), [locale, alwaysShowISOCode, validCurrencyISOCode]);
|
|
13
13
|
const maximumFractionDigits = useMemo(() => getCurrencyMaximumFractionDigits(locale, validCurrencyISOCode), [locale, validCurrencyISOCode]);
|
|
14
14
|
const onInputFocus = useCallback(() => {
|
|
15
15
|
onFocus?.(value);
|
|
@@ -22,7 +22,7 @@ const CurrencyInput = forwardRef((props, ref) => {
|
|
|
22
22
|
}
|
|
23
23
|
onBlur?.(formattedValue);
|
|
24
24
|
}, [onBlur, maximumFractionDigits]);
|
|
25
|
-
const Comp = (_jsx(NumberInput, { numberOfDecimals: maximumFractionDigits, onFocus: onInputFocus, onBlur: onInputBlur, unit:
|
|
25
|
+
const Comp = (_jsx(NumberInput, { numberOfDecimals: maximumFractionDigits, onFocus: onInputFocus, onBlur: onInputBlur, unit: symbol, unitPlacement: symbolPlacement, ...{
|
|
26
26
|
ref,
|
|
27
27
|
id,
|
|
28
28
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyInput.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAsC,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE7F,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EACL,gCAAgC,EAChC,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,MAAM,aAAa,GAAyD,UAAU,CACpF,CAAC,KAA0C,EAAE,GAA8B,EAAE,EAAE;IAC7E,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,EACJ,EAAE,GAAG,GAAG,EACR,MAAM,EACN,KAAK,EACL,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,KAAK,GAAG,EAAE,EACV,MAAM,EACN,OAAO,EACP,WAAW,GAAG,IAAI,EAClB,eAAe,EACf,iBAAiB,
|
|
1
|
+
{"version":3,"file":"CurrencyInput.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAsC,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE7F,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EACL,gCAAgC,EAChC,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,MAAM,aAAa,GAAyD,UAAU,CACpF,CAAC,KAA0C,EAAE,GAA8B,EAAE,EAAE;IAC7E,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,EACJ,EAAE,GAAG,GAAG,EACR,MAAM,EACN,KAAK,EACL,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,KAAK,GAAG,EAAE,EACV,MAAM,EACN,OAAO,EACP,WAAW,GAAG,IAAI,EAClB,eAAe,EACf,iBAAiB,GAAG,KAAK,EACzB,GAAG,SAAS,EACb,GAAG,KAAK,CAAC;IAEV,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACtC,MAAM,oBAAoB,GAAG,OAAO,CAClC,GAAG,EAAE,CAAC,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,EAC7E,CAAC,eAAe,CAAC,CAClB,CAAC;IACF,MAA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;YACR,QAAQ;YACR,MAAM;YACN,GAAG,SAAS;SACb,WACD,CACH,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,OAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YACxE,IAAI,WACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef, useCallback, useMemo } from 'react';\n\nimport FormField from '../FormField';\nimport { ForwardProps } from '../../types';\nimport { useConfiguration, useUID } from '../../hooks';\nimport { NumberInput } from '../Number';\n\nimport CurrencyInputProps from './CurrencyInput.types';\nimport {\n getCurrencyMaximumFractionDigits,\n getCurrencySymbol,\n isCurrencyISOCodeValid\n} from './utils';\n\nconst CurrencyInput: FunctionComponent<CurrencyInputProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<CurrencyInputProps>, ref: CurrencyInputProps['ref']) => {\n const uid = useUID();\n const {\n id = uid,\n status,\n label,\n labelHidden,\n info,\n required,\n disabled,\n readOnly,\n value = '',\n onBlur,\n onFocus,\n showDecimal = true,\n currencyISOCode,\n alwaysShowISOCode = false,\n ...restProps\n } = props;\n\n const { locale } = useConfiguration();\n const validCurrencyISOCode = useMemo(\n () => (isCurrencyISOCodeValid(currencyISOCode) ? currencyISOCode : undefined),\n [currencyISOCode]\n );\n const { symbol, symbolPlacement } = useMemo(\n () => getCurrencySymbol(locale, alwaysShowISOCode, validCurrencyISOCode),\n [locale, alwaysShowISOCode, validCurrencyISOCode]\n );\n const maximumFractionDigits = useMemo(\n () => getCurrencyMaximumFractionDigits(locale, validCurrencyISOCode),\n [locale, validCurrencyISOCode]\n );\n\n const onInputFocus = useCallback(() => {\n onFocus?.(value);\n }, [onFocus, value]);\n\n const onInputBlur = useCallback(\n (inputValue: string) => {\n let formattedValue = inputValue;\n if (validCurrencyISOCode && !Number.isNaN(parseFloat(value))) {\n const [integer, fraction = ''] = inputValue.split('.');\n formattedValue = `${integer}.${fraction.padEnd(maximumFractionDigits, '0')}`;\n }\n onBlur?.(formattedValue);\n },\n [onBlur, maximumFractionDigits]\n );\n\n const Comp = (\n <NumberInput\n numberOfDecimals={maximumFractionDigits}\n onFocus={onInputFocus}\n onBlur={onInputBlur}\n unit={symbol}\n unitPlacement={symbolPlacement}\n {...{\n ref,\n id,\n value,\n showDecimal,\n readOnly,\n required,\n disabled,\n status,\n ...restProps\n }}\n />\n );\n\n return label ? (\n <FormField {...{ label, labelHidden, id, info, status, required, disabled }}>\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default CurrencyInput;\n"]}
|
|
@@ -7,7 +7,9 @@ export default interface CurrencyInputProps extends OmitStrict<NumberInputProps,
|
|
|
7
7
|
onBlur?: (value: string) => void;
|
|
8
8
|
/** Three letter currency shorthand ISO code. If not provided or invalid, component renders as NumberInput */
|
|
9
9
|
currencyISOCode?: string;
|
|
10
|
-
/** Always show ISO code
|
|
10
|
+
/** Always show ISO code
|
|
11
|
+
* @default false
|
|
12
|
+
* */
|
|
11
13
|
alwaysShowISOCode?: boolean;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=CurrencyInput.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,gBAAgB,MAAM,6BAA6B,CAAC;AAE3D,MAAM,CAAC,OAAO,WAAW,kBACvB,SAAQ,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC;IACxD,mDAAmD;IACnD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,qDAAqD;IACrD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,6GAA6G;IAC7G,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB
|
|
1
|
+
{"version":3,"file":"CurrencyInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,gBAAgB,MAAM,6BAA6B,CAAC;AAE3D,MAAM,CAAC,OAAO,WAAW,kBACvB,SAAQ,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,CAAC;IACxD,mDAAmD;IACnD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,qDAAqD;IACrD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,6GAA6G;IAC7G,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;SAEK;IACL,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyInput.types.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.types.ts"],"names":[],"mappings":"","sourcesContent":["import { OmitStrict } from '../../types';\nimport NumberInputProps from '../Number/NumberInput.types';\n\nexport default interface CurrencyInputProps\n extends OmitStrict<NumberInputProps, 'numberOfDecimals'> {\n /** Callback fired when the component gets focus */\n onFocus?: (value: string) => void;\n /** Callback fired when the component loses focus. */\n onBlur?: (value: string) => void;\n /** Three letter currency shorthand ISO code. If not provided or invalid, component renders as NumberInput */\n currencyISOCode?: string;\n /** Always show ISO code */\n alwaysShowISOCode?: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CurrencyInput.types.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.types.ts"],"names":[],"mappings":"","sourcesContent":["import { OmitStrict } from '../../types';\nimport NumberInputProps from '../Number/NumberInput.types';\n\nexport default interface CurrencyInputProps\n extends OmitStrict<NumberInputProps, 'numberOfDecimals'> {\n /** Callback fired when the component gets focus */\n onFocus?: (value: string) => void;\n /** Callback fired when the component loses focus. */\n onBlur?: (value: string) => void;\n /** Three letter currency shorthand ISO code. If not provided or invalid, component renders as NumberInput */\n currencyISOCode?: string;\n /** Always show ISO code\n * @default false\n * */\n alwaysShowISOCode?: boolean;\n}\n"]}
|
|
@@ -2,7 +2,18 @@ export declare type CurrencySymbol = {
|
|
|
2
2
|
symbol: string;
|
|
3
3
|
symbolPlacement: 'before' | 'after';
|
|
4
4
|
};
|
|
5
|
-
export declare function getCurrencySymbol(locale: string, currencyISOCode?: string): CurrencySymbol;
|
|
5
|
+
export declare function getCurrencySymbol(locale: string, alwaysShowISOCode: boolean, currencyISOCode?: string): CurrencySymbol;
|
|
6
6
|
export declare function getCurrencyMaximumFractionDigits(locale: string, currencyISOCode?: string): number;
|
|
7
7
|
export declare function isCurrencyISOCodeValid(currencyISOCode?: string): boolean;
|
|
8
|
+
export declare function addTrailingZeros(valueToFormat: string, maximumFractionDigits: number, currencyISOCode?: string): string;
|
|
9
|
+
declare type DisplayValueParams = {
|
|
10
|
+
value: string;
|
|
11
|
+
locale: string;
|
|
12
|
+
alwaysShowISOCode: boolean;
|
|
13
|
+
showDecimal: boolean;
|
|
14
|
+
showGroupSeparators: boolean;
|
|
15
|
+
currencyISOCode?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function getDisplayValue({ value, locale, alwaysShowISOCode, showDecimal, showGroupSeparators, currencyISOCode }: DisplayValueParams): string;
|
|
18
|
+
export {};
|
|
8
19
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/utils.ts"],"names":[],"mappings":"AAQA,oBAAY,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,QAAQ,GAAG,OAAO,CAAC;CACrC,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,OAAO,EAC1B,eAAe,CAAC,EAAE,MAAM,GACvB,cAAc,CAmBhB;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAOjG;AAED,wBAAgB,sBAAsB,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAExE;AAED,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,MAAM,EACrB,qBAAqB,EAAE,MAAM,EAC7B,eAAe,CAAC,EAAE,MAAM,UAQzB;AAED,aAAK,kBAAkB,GAAG;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,OAAO,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC;IACrB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,MAAM,EACN,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,eAAe,EAChB,EAAE,kBAAkB,UA+BpB"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { NUMBER_MAX_DECIMAL_PLACES } from '../Number/NumberInput.types';
|
|
2
|
+
import { getFormattedValue } from '../Number/utils';
|
|
2
3
|
// Currency & funds code list valid for Intl.NumberFormat(): https://www.currency-iso.org/en/home/tables/table-a1.html
|
|
3
4
|
import currencyCodeList from './currencyCodes';
|
|
4
|
-
export function getCurrencySymbol(locale, currencyISOCode) {
|
|
5
|
+
export function getCurrencySymbol(locale, alwaysShowISOCode, currencyISOCode) {
|
|
5
6
|
const options = currencyISOCode
|
|
6
7
|
? {
|
|
7
8
|
style: 'currency',
|
|
@@ -10,7 +11,7 @@ export function getCurrencySymbol(locale, currencyISOCode) {
|
|
|
10
11
|
: undefined;
|
|
11
12
|
return new Intl.NumberFormat(locale, options).formatToParts(1).reduce((currencyObj, part, index) => {
|
|
12
13
|
if (part.type === 'currency') {
|
|
13
|
-
currencyObj.symbol = part.value;
|
|
14
|
+
currencyObj.symbol = alwaysShowISOCode ? currencyISOCode || '' : part.value;
|
|
14
15
|
if (index === 0) {
|
|
15
16
|
currencyObj.symbolPlacement = 'before';
|
|
16
17
|
}
|
|
@@ -29,4 +30,31 @@ export function getCurrencyMaximumFractionDigits(locale, currencyISOCode) {
|
|
|
29
30
|
export function isCurrencyISOCodeValid(currencyISOCode) {
|
|
30
31
|
return currencyISOCode ? currencyCodeList.has(currencyISOCode) : false;
|
|
31
32
|
}
|
|
33
|
+
export function addTrailingZeros(valueToFormat, maximumFractionDigits, currencyISOCode) {
|
|
34
|
+
let formattedValue = valueToFormat;
|
|
35
|
+
if (currencyISOCode && !Number.isNaN(parseFloat(valueToFormat))) {
|
|
36
|
+
const [integer, fraction = ''] = valueToFormat.split('.');
|
|
37
|
+
formattedValue = `${integer}.${fraction.padEnd(maximumFractionDigits, '0')}`;
|
|
38
|
+
}
|
|
39
|
+
return formattedValue;
|
|
40
|
+
}
|
|
41
|
+
export function getDisplayValue({ value, locale, alwaysShowISOCode, showDecimal, showGroupSeparators, currencyISOCode }) {
|
|
42
|
+
const validCurrencyISOCode = isCurrencyISOCodeValid(currencyISOCode)
|
|
43
|
+
? currencyISOCode
|
|
44
|
+
: undefined;
|
|
45
|
+
const { symbol, symbolPlacement } = getCurrencySymbol(locale, alwaysShowISOCode, validCurrencyISOCode);
|
|
46
|
+
const maximumFractionDigits = getCurrencyMaximumFractionDigits(locale, validCurrencyISOCode);
|
|
47
|
+
let sign = '';
|
|
48
|
+
let formattedValue = getFormattedValue(!showDecimal
|
|
49
|
+
? value.split('.')[0]
|
|
50
|
+
: addTrailingZeros(value, maximumFractionDigits, validCurrencyISOCode), locale, showGroupSeparators, maximumFractionDigits);
|
|
51
|
+
if (formattedValue.startsWith('-')) {
|
|
52
|
+
sign = '-';
|
|
53
|
+
formattedValue = formattedValue.substring(1);
|
|
54
|
+
}
|
|
55
|
+
let symbolBefore = symbolPlacement === 'before' ? symbol : '';
|
|
56
|
+
symbolBefore += symbolBefore === currencyISOCode ? ' ' : '';
|
|
57
|
+
const symbolAfter = symbolPlacement === 'after' && symbol ? ` ${symbol}` : '';
|
|
58
|
+
return `${sign}${symbolBefore}${formattedValue}${symbolAfter}`;
|
|
59
|
+
}
|
|
32
60
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/Currency/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/Currency/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,sHAAsH;AACtH,OAAO,gBAAgB,MAAM,iBAAiB,CAAC;AAS/C,MAAM,UAAU,iBAAiB,CAC/B,MAAc,EACd,iBAA0B,EAC1B,eAAwB;IAExB,MAAM,OAAO,GAAG,eAAe;QAC7B,CAAC,CAAC;YACE,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,eAAe;SAC1B;QACH,CAAC,CAAC,SAAS,CAAC;IACd,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CACnE,CAAC,WAA2B,EAAE,IAAkB,EAAE,KAAa,EAAE,EAAE;QACjE,IAAI,IAAI,CAAC,IAAI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ECIMAL_PLACES } from '../Number/NumberInput.types';\nimport { getFormattedValue } from '../Number/utils';\n\n// Currency & funds code list valid for Intl.NumberFormat(): https://www.currency-iso.org/en/home/tables/table-a1.html\nimport currencyCodeList from './currencyCodes';\n\ntype CurrencyPart = { type: string; value: string };\n\nexport type CurrencySymbol = {\n symbol: string;\n symbolPlacement: 'before' | 'after';\n};\n\nexport function getCurrencySymbol(\n locale: string,\n alwaysShowISOCode: boolean,\n currencyISOCode?: string\n): CurrencySymbol {\n const options = currencyISOCode\n ? {\n style: 'currency',\n currency: currencyISOCode\n }\n : undefined;\n return new Intl.NumberFormat(locale, options).formatToParts(1).reduce(\n (currencyObj: CurrencySymbol, part: CurrencyPart, index: number) => {\n if (part.type === 'currency') {\n currencyObj.symbol = alwaysShowISOCode ? currencyISOCode || '' : part.value;\n if (index === 0) {\n currencyObj.symbolPlacement = 'before';\n }\n }\n return currencyObj;\n },\n { symbol: '', symbolPlacement: 'after' }\n );\n}\n\nexport function getCurrencyMaximumFractionDigits(locale: string, currencyISOCode?: string): number {\n return currencyISOCode\n ? new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: currencyISOCode\n }).resolvedOptions().maximumFractionDigits\n : NUMBER_MAX_DECIMAL_PLACES;\n}\n\nexport function isCurrencyISOCodeValid(currencyISOCode?: string): boolean {\n return currencyISOCode ? currencyCodeList.has(currencyISOCode) : false;\n}\n\nexport function addTrailingZeros(\n valueToFormat: string,\n maximumFractionDigits: number,\n currencyISOCode?: string\n) {\n let formattedValue = valueToFormat;\n if (currencyISOCode && !Number.isNaN(parseFloat(valueToFormat))) {\n const [integer, fraction = ''] = valueToFormat.split('.');\n formattedValue = `${integer}.${fraction.padEnd(maximumFractionDigits, '0')}`;\n }\n return formattedValue;\n}\n\ntype DisplayValueParams = {\n value: string;\n locale: string;\n alwaysShowISOCode: boolean;\n showDecimal: boolean;\n showGroupSeparators: boolean;\n currencyISOCode?: string;\n};\n\nexport function getDisplayValue({\n value,\n locale,\n alwaysShowISOCode,\n showDecimal,\n showGroupSeparators,\n currencyISOCode\n}: DisplayValueParams) {\n const validCurrencyISOCode = isCurrencyISOCodeValid(currencyISOCode)\n ? currencyISOCode\n : undefined;\n const { symbol, symbolPlacement } = getCurrencySymbol(\n locale,\n alwaysShowISOCode,\n validCurrencyISOCode\n );\n const maximumFractionDigits = getCurrencyMaximumFractionDigits(locale, validCurrencyISOCode);\n\n let sign = '';\n let formattedValue = getFormattedValue(\n !showDecimal\n ? value.split('.')[0]\n : addTrailingZeros(value, maximumFractionDigits, validCurrencyISOCode),\n locale,\n showGroupSeparators,\n maximumFractionDigits\n );\n if (formattedValue.startsWith('-')) {\n sign = '-';\n formattedValue = formattedValue.substring(1);\n }\n\n let symbolBefore = symbolPlacement === 'before' ? symbol : '';\n symbolBefore += symbolBefore === currencyISOCode ? ' ' : '';\n\n const symbolAfter = symbolPlacement === 'after' && symbol ? ` ${symbol}` : '';\n\n return `${sign}${symbolBefore}${formattedValue}${symbolAfter}`;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EASlB,MAAM,OAAO,CAAC;AAOf,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAkB3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAWhD,QAAA,MAAM,KAAK,EAAE,iBAAiB,CAAC,UAAU,GAAG,YAAY,CA4RvD,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useContext, useEffect, useRef } from 'react';
|
|
2
|
+
import { forwardRef, useContext, useEffect, useRef, useCallback } from 'react';
|
|
3
3
|
import Progress from '../Progress';
|
|
4
4
|
import { getFocusables } from '../../utils';
|
|
5
5
|
import Backdrop from '../Backdrop';
|
|
@@ -46,11 +46,7 @@ const Modal = forwardRef((props, refArg) => {
|
|
|
46
46
|
focusable?.focus();
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
const onKeyDown = (e) => {
|
|
50
|
-
if (dismissible && (state === 'open' || state === 'maximized') && e.key === 'Escape' && top) {
|
|
51
|
-
tryDismiss();
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
49
|
+
const onKeyDown = useCallback((e) => {
|
|
54
50
|
if (e.key === 'Tab') {
|
|
55
51
|
const focusables = getFocusables(modalRef);
|
|
56
52
|
if (!focusables || focusables.length < 2)
|
|
@@ -67,7 +63,13 @@ const Modal = forwardRef((props, refArg) => {
|
|
|
67
63
|
e.preventDefault();
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
|
-
};
|
|
66
|
+
}, []);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
document.addEventListener('keydown', onKeyDown);
|
|
69
|
+
return () => {
|
|
70
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
71
|
+
};
|
|
72
|
+
}, [onKeyDown]);
|
|
71
73
|
useOuterEvent('mousedown', [modalRef], e => {
|
|
72
74
|
if (['minimized', 'docked', 'closed'].includes(state))
|
|
73
75
|
return;
|
|
@@ -80,18 +82,21 @@ const Modal = forwardRef((props, refArg) => {
|
|
|
80
82
|
modalRef.current?.focus();
|
|
81
83
|
}
|
|
82
84
|
});
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
document.addEventListener('keydown', onKeyDown);
|
|
85
|
-
return () => {
|
|
86
|
-
document.removeEventListener('keydown', onKeyDown);
|
|
87
|
-
};
|
|
88
|
-
}, [onKeyDown]);
|
|
89
85
|
useEffect(() => {
|
|
90
86
|
if (state === 'minimized')
|
|
91
87
|
return;
|
|
92
88
|
if (state === 'open' || state === 'maximized' || state === 'docked')
|
|
93
89
|
setFocus();
|
|
94
90
|
}, [state]);
|
|
91
|
+
// Dismiss on Escape needs to be handled using React event handling to be cancelable using SyntheticEvent.stopPropagation.
|
|
92
|
+
const onModalKeyDown = useCallback((e) => {
|
|
93
|
+
if (dismissible &&
|
|
94
|
+
(state === 'open' || state === 'maximized') &&
|
|
95
|
+
e.key === 'Escape' &&
|
|
96
|
+
top) {
|
|
97
|
+
tryDismiss();
|
|
98
|
+
}
|
|
99
|
+
}, [dismissible, state, top, tryDismiss]);
|
|
95
100
|
// Set a ref based on the initial progress state to be used later to check for setting focus.
|
|
96
101
|
const focusOnProgressChange = useRef(!!progress);
|
|
97
102
|
useAfterInitialEffect(() => {
|
|
@@ -102,7 +107,7 @@ const Modal = forwardRef((props, refArg) => {
|
|
|
102
107
|
}
|
|
103
108
|
}, [progress]);
|
|
104
109
|
const maximized = stretch || state === 'maximized';
|
|
105
|
-
const modal = (_jsxs(Flex, { ...restProps, container: { direction: 'column' }, ref: modalRef, as: StyledModal, forwardedAs: as, onClick: (e) => e.stopPropagation(), alert: alert, role: alert ? 'alertdialog' : 'dialog', stretch: maximized, center: center, "aria-labelledby": `${id}-heading`, "aria-modal": state === 'docked' ? 'false' : 'true', state: state, "aria-live": 'polite', "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 }, void 0), typeof count === 'number' && _jsx(Count, { children: count }, void 0)] }, void 0), _jsxs(Flex, { container: true, children: [maximizable && !alert && state !== 'maximized' && (_jsx(Button, { icon: true, variant: 'simple', "aria-label": t('modal_maximize'), onClick: () => {
|
|
110
|
+
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-modal": state === 'docked' ? 'false' : 'true', state: state, "aria-live": 'polite', "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 }, void 0), typeof count === 'number' && _jsx(Count, { children: count }, void 0)] }, void 0), _jsxs(Flex, { container: true, children: [maximizable && !alert && state !== 'maximized' && (_jsx(Button, { icon: true, variant: 'simple', "aria-label": t('modal_maximize'), onClick: () => {
|
|
106
111
|
if (onRequestMaximize?.() !== false) {
|
|
107
112
|
maximize();
|
|
108
113
|
}
|