@pega/cosmos-react-core 8.0.0-build.44.0 → 8.0.0-build.44.2
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/Checkbox/CheckboxCard.d.ts.map +1 -1
- package/lib/components/Checkbox/CheckboxCard.js +1 -6
- package/lib/components/Checkbox/CheckboxCard.js.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.js +1 -1
- package/lib/components/CompositeInput/CompositeInput.js.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.types.d.ts +1 -1
- package/lib/components/CompositeInput/CompositeInput.types.d.ts.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.types.js.map +1 -1
- package/lib/components/Progress/Progress.d.ts.map +1 -1
- package/lib/components/Progress/Progress.js +6 -2
- package/lib/components/Progress/Progress.js.map +1 -1
- package/lib/components/Progress/Progress.styles.d.ts.map +1 -1
- package/lib/components/Progress/Progress.styles.js +9 -4
- package/lib/components/Progress/Progress.styles.js.map +1 -1
- package/lib/components/RadioButton/RadioButtonCard.d.ts.map +1 -1
- package/lib/components/RadioButton/RadioButtonCard.js +1 -6
- package/lib/components/RadioButton/RadioButtonCard.js.map +1 -1
- package/lib/components/RadioCheckGroup/RadioCheckGroup.d.ts.map +1 -1
- package/lib/components/RadioCheckGroup/RadioCheckGroup.js +6 -2
- package/lib/components/RadioCheckGroup/RadioCheckGroup.js.map +1 -1
- package/lib/components/SelectionCard/SelectionCard.d.ts.map +1 -1
- package/lib/components/SelectionCard/SelectionCard.js +10 -7
- package/lib/components/SelectionCard/SelectionCard.js.map +1 -1
- package/lib/components/SelectionCard/SelectionCard.styles.d.ts.map +1 -1
- package/lib/components/SelectionCard/SelectionCard.styles.js +31 -29
- package/lib/components/SelectionCard/SelectionCard.styles.js.map +1 -1
- package/lib/components/SelectionCard/SelectionCard.types.d.ts +4 -6
- package/lib/components/SelectionCard/SelectionCard.types.d.ts.map +1 -1
- package/lib/components/SelectionCard/SelectionCard.types.js.map +1 -1
- package/lib/hooks/useBreakpoint.d.ts.map +1 -1
- package/lib/hooks/useBreakpoint.js +2 -0
- package/lib/hooks/useBreakpoint.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxCard.d.ts","sourceRoot":"","sources":["../../../src/components/Checkbox/CheckboxCard.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAK1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"CheckboxCard.d.ts","sourceRoot":"","sources":["../../../src/components/Checkbox/CheckboxCard.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAK1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAkC/E,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,kBAAkB,EAAE,SAAS,CAAC,GACvE,UAAU,CAAC,aAAa,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;;;;AAgEjD,wBAAiE"}
|
|
@@ -6,9 +6,8 @@ import SelectionCard, { focusableSelector } from '../SelectionCard/SelectionCard
|
|
|
6
6
|
import Text from '../Text';
|
|
7
7
|
import { useConsolidatedRef, useTestIds, useUID } from '../../hooks';
|
|
8
8
|
import { getActiveElement, withTestIds } from '../../utils';
|
|
9
|
-
import { StyledRadioCheck } from '../RadioCheck/RadioCheck';
|
|
10
9
|
import { getCheckboxCardTestIds } from './Checkbox.test-ids';
|
|
11
|
-
const StyledSelectionCard = styled.div(({ disabled, readOnly, theme: { components: {
|
|
10
|
+
const StyledSelectionCard = styled.div(({ disabled, readOnly, theme: { components: { 'form-control': { ':hover': { 'border-color': hoverBorderColor } } } } }) => {
|
|
12
11
|
return css `
|
|
13
12
|
${!disabled &&
|
|
14
13
|
css `
|
|
@@ -21,10 +20,6 @@ const StyledSelectionCard = styled.div(({ disabled, readOnly, theme: { component
|
|
|
21
20
|
border-color: ${hoverBorderColor};
|
|
22
21
|
}
|
|
23
22
|
`}
|
|
24
|
-
|
|
25
|
-
${StyledRadioCheck} {
|
|
26
|
-
min-height: ${input.height};
|
|
27
|
-
}
|
|
28
23
|
`;
|
|
29
24
|
});
|
|
30
25
|
StyledSelectionCard.defaultProps = defaultThemeProp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxCard.js","sourceRoot":"","sources":["../../../src/components/Checkbox/CheckboxCard.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIrE,OAAO,aAAa,EAAE,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"CheckboxCard.js","sourceRoot":"","sources":["../../../src/components/Checkbox/CheckboxCard.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIrE,OAAO,aAAa,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AAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;YAC5B,CAAC;QACH,CAAC,EACD,GAAG,EAAE,YAAY,GACjB,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC","sourcesContent":["import { forwardRef, useRef } from 'react';\nimport type { PropsWithoutRef, MouseEvent, KeyboardEvent } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { Checkbox, defaultThemeProp } from '@pega/cosmos-react-core';\nimport type { CheckboxProps } from '@pega/cosmos-react-core';\n\nimport type { OmitStrict, RefElement } from '../../types';\nimport SelectionCard, { focusableSelector } from '../SelectionCard/SelectionCard';\nimport Text from '../Text';\nimport { useConsolidatedRef, useTestIds, useUID } from '../../hooks';\nimport { getActiveElement, withTestIds } from '../../utils';\nimport type { SelectionCardProps } from '../SelectionCard/SelectionCard.types';\n\nimport { getCheckboxCardTestIds } from './Checkbox.test-ids';\n\nconst StyledSelectionCard = styled.div<Pick<CheckboxProps, 'disabled' | 'readOnly'>>(\n ({\n disabled,\n readOnly,\n theme: {\n components: {\n 'form-control': {\n ':hover': { 'border-color': hoverBorderColor }\n }\n }\n }\n }) => {\n return css`\n ${!disabled &&\n css`\n cursor: pointer;\n `}\n\n ${!(disabled || readOnly) &&\n css`\n :hover:not(:focus-within) {\n border-color: ${hoverBorderColor};\n }\n `}\n `;\n }\n);\n\nStyledSelectionCard.defaultProps = defaultThemeProp;\n\nexport type CheckboxCardProps = OmitStrict<SelectionCardProps, 'heading'> &\n OmitStrict<CheckboxProps, 'label' | 'variant'>;\n\nconst CheckboxCard = forwardRef<RefElement<CheckboxProps>, PropsWithoutRef<CheckboxCardProps>>(\n function CheckboxCard(props, ref) {\n const uid = useUID();\n const { testId, id = uid, label, disabled, readOnly, ...restProps } = props;\n\n const testIds = useTestIds(testId, getCheckboxCardTestIds);\n const contentId = `${id}-content`;\n const inputRef = useConsolidatedRef(ref);\n const containerRef = useRef<HTMLDivElement>(null);\n\n return (\n <StyledSelectionCard\n {...restProps}\n as={SelectionCard}\n testId={testIds}\n label={label}\n heading={\n <Checkbox\n testId={testIds.root}\n {...restProps}\n id={id}\n disabled={disabled}\n readOnly={readOnly}\n label={\n <Text variant='h4' as='span'>\n {label}\n </Text>\n }\n variant='simple'\n aria-details={contentId}\n ref={inputRef}\n />\n }\n readOnly={readOnly}\n disabled={disabled}\n onClick={(e: MouseEvent<HTMLDivElement>) => {\n const target = e.target as HTMLElement;\n if (readOnly || !containerRef.current?.contains(target)) return;\n if (\n containerRef.current &&\n [...containerRef.current.querySelectorAll(focusableSelector)].includes(target)\n )\n return;\n e.preventDefault();\n inputRef.current?.click();\n (inputRef.current?.hasAttribute('data-main-focus')\n ? inputRef\n : containerRef\n ).current?.focus();\n }}\n onKeyDown={(e: KeyboardEvent) => {\n if (e.key === ' ' && containerRef.current === getActiveElement()) {\n e.preventDefault();\n inputRef.current?.click();\n }\n }}\n ref={containerRef}\n />\n );\n }\n);\n\nexport default withTestIds(CheckboxCard, getCheckboxCardTestIds);\n"]}
|
|
@@ -48,7 +48,7 @@ export default withTestIds(forwardRef(function CompositeInput(props, ref) {
|
|
|
48
48
|
e.preventDefault();
|
|
49
49
|
setOpen(true);
|
|
50
50
|
}
|
|
51
|
-
}, value: value ?? '', ref: buttonRef }), _jsx(Flex, { container: { justify: 'center', alignItems: 'center' }, style: { pointerEvents: value ? '' : 'none' }, children: value && !open ? (_jsx(Button, { icon: true, compact: true, variant: 'simple', label: t('clear'), onClick: onClear, children: _jsx(Icon, { name: 'times' }) })) : (_jsx(Icon, { name: 'caret-down' })) })] }), open && containerRef.current && (_jsx(FormDialog, { arrow: false, "aria-label": label, ref: setPopoverEl, target: containerRef.current, placement: 'bottom-start', onCancel: () => onCancel({ close: closePopover }), onSubmit: {
|
|
51
|
+
}, value: value ?? '', ref: buttonRef }), _jsx(Flex, { container: { justify: 'center', alignItems: 'center' }, style: { pointerEvents: value ? '' : 'none' }, children: onClear && value && !open ? (_jsx(Button, { icon: true, compact: true, variant: 'simple', label: t('clear'), onClick: onClear, children: _jsx(Icon, { name: 'times' }) })) : (_jsx(Icon, { name: 'caret-down' })) })] }), open && containerRef.current && (_jsx(FormDialog, { arrow: false, "aria-label": label, ref: setPopoverEl, target: containerRef.current, placement: 'bottom-start', onCancel: () => onCancel({ close: closePopover }), onSubmit: {
|
|
52
52
|
text: t('apply'),
|
|
53
53
|
handler: () => onApply({ close: closePopover })
|
|
54
54
|
}, children: _jsx(Flex, { container: { direction: 'column' }, ref: formContentRef, children: _jsx(Renderer, { ...rendererProps }) }) }))] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompositeInput.js","sourceRoot":"","sources":["../../../src/components/CompositeInput/CompositeInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGhE,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,OAAO,EACP,aAAa,EACb,UAAU,EACV,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,wBAAw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CACnB,OAAO,CAAC,IAAI,CAAC,CAAC;4BAChB,CAAC;wBACH,CAAC,EACD,KAAK,EAAE,KAAK,IAAI,EAAE,EAClB,GAAG,EAAE,SAAS,GACd,EACF,KAAC,IAAI,IACH,SAAS,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,EACtD,KAAK,EAAE,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,YAE5C,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"CompositeInput.js","sourceRoot":"","sources":["../../../src/components/CompositeInput/CompositeInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGhE,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,OAAO,EACP,aAAa,EACb,UAAU,EACV,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAErE,YAAY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b,KAAC,SAAS,IACR,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,cAAc,YAE7B,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACyE,EAC5E,wBAAwB,CACzB,CAAC","sourcesContent":["import { forwardRef, useEffect, useRef, useState } from 'react';\nimport type { PropsWithoutRef } from 'react';\n\nimport Icon, { registerIcon } from '../Icon';\nimport * as caretDownIcon from '../Icon/icons/caret-down.icon';\nimport * as timesIcon from '../Icon/icons/times.icon';\nimport type { RefElement } from '../../types';\nimport {\n useConsolidatedRef,\n useElement,\n useI18n,\n useOuterEvent,\n useTestIds,\n useUID\n} from '../../hooks';\nimport { StyledFormControl } from '../FormControl';\nimport { createClassName, getFocusables, withTestIds } from '../../utils';\nimport Flex from '../Flex';\nimport Button from '../Button';\nimport FormField from '../FormField';\nimport { FormDialog } from '../Dialog';\n\nimport {\n StyledCompositeInput,\n StyledInputButton,\n StyledInputContainer\n} from './CompositeInput.styles';\nimport type { CompositeInputProps } from './CompositeInput.types';\nimport { getCompositeInputTestIds } from './CompositeInput.test-ids';\n\nregisterIcon(caretDownIcon, timesIcon);\n\nexport default withTestIds(\n forwardRef<RefElement<CompositeInputProps>, PropsWithoutRef<CompositeInputProps>>(\n function CompositeInput(props, ref) {\n const uid = useUID();\n const {\n testId,\n id = uid,\n disabled,\n value,\n onClear,\n required,\n status,\n info,\n label,\n labelHidden,\n additionalInfo,\n dialog: { renderer: Renderer, rendererProps, onApply, onCancel },\n className,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getCompositeInputTestIds);\n const t = useI18n();\n\n const [open, setOpen] = useState(false);\n\n const [popoverEl, setPopoverEl] = useElement<HTMLElement>(null);\n const containerRef = useConsolidatedRef<HTMLDivElement>(ref);\n const buttonRef = useRef<HTMLInputElement>(null);\n const formContentRef = useRef<HTMLElement>(null);\n\n const closePopover = () => {\n setOpen(false);\n buttonRef.current?.focus();\n };\n\n useOuterEvent('mousedown', [popoverEl, buttonRef], () => {\n if (open) onCancel({ close: closePopover });\n });\n\n useEffect(() => {\n if (open) {\n getFocusables(formContentRef)[0]?.focus();\n }\n }, [open, formContentRef.current]);\n\n const labelId = `${id}-label`;\n\n const Comp = (\n <Flex\n as={StyledCompositeInput}\n forwardedAs={StyledFormControl}\n container={{ alignItems: 'center' }}\n status={status}\n disabled={disabled}\n ref={containerRef}\n >\n <Flex container={{ alignItems: 'center' }} item={{ grow: 1 }} as={StyledInputContainer}>\n <StyledInputButton\n data-testid={testIds.control}\n {...restProps}\n id={id}\n disabled={disabled}\n aria-haspopup='dialog'\n aria-expanded={!disabled && open}\n aria-describedby={info ? `${id}-info` : undefined}\n className={createClassName('composite-input', className, {\n status\n })}\n readOnly\n required={required}\n onClick={() => {\n if (!disabled) {\n setOpen(true);\n }\n }}\n onKeyDown={e => {\n if (e.key === 'Enter') {\n e.preventDefault();\n setOpen(true);\n }\n }}\n value={value ?? ''}\n ref={buttonRef}\n />\n <Flex\n container={{ justify: 'center', alignItems: 'center' }}\n style={{ pointerEvents: value ? '' : 'none' }}\n >\n {onClear && value && !open ? (\n <Button icon compact variant='simple' label={t('clear')} onClick={onClear}>\n <Icon name='times' />\n </Button>\n ) : (\n <Icon name='caret-down' />\n )}\n </Flex>\n </Flex>\n\n {open && containerRef.current && (\n <FormDialog\n arrow={false}\n // FIXME: The wrath of optional labels, as a ReactNode, strikes again...\n aria-label={label as string}\n ref={setPopoverEl}\n target={containerRef.current}\n placement='bottom-start'\n onCancel={() => onCancel({ close: closePopover })}\n onSubmit={{\n text: t('apply'),\n handler: () => onApply({ close: closePopover })\n }}\n >\n <Flex container={{ direction: 'column' }} ref={formContentRef}>\n <Renderer {...rendererProps} />\n </Flex>\n </FormDialog>\n )}\n </Flex>\n );\n\n return label ? (\n <FormField\n testId={testIds}\n label={label}\n labelHidden={labelHidden}\n id={id}\n info={info}\n status={status}\n required={required}\n disabled={disabled}\n labelId={labelId}\n additionalInfo={additionalInfo}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n ) as <P extends object>(props: CompositeInputProps<P>) => JSX.Element | null,\n getCompositeInputTestIds\n);\n"]}
|
|
@@ -12,7 +12,7 @@ export type CompositeInputProps<P extends object = object> = WithAttributes<'inp
|
|
|
12
12
|
info?: FormControlProps['info'];
|
|
13
13
|
/** Indicate if the field is required. The browser defaults to false. */
|
|
14
14
|
/** Callback when clear button is clicked. */
|
|
15
|
-
onClear
|
|
15
|
+
onClear?: () => void;
|
|
16
16
|
/** Button when clicked will show additional information for the composite input */
|
|
17
17
|
additionalInfo?: FormControlProps['additionalInfo'];
|
|
18
18
|
/** Value form options. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompositeInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/CompositeInput/CompositeInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,cAAc,CACzE,OAAO,EACP,UAAU,GACR,cAAc,GAAG;IACf,oDAAoD;IACpD,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACpC,2DAA2D;IAC3D,KAAK,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC,uCAAuC;IACvC,WAAW,CAAC,EAAE,gBA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AAC,EAAE,KAAK,EAAE,EAAE;YAAE,KAAK,EAAE,MAAM,IAAI,CAAA;SAAE,KAAK,IAAI,CAAC;QACrD,6CAA6C;QAC7C,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE;YAAE,KAAK,EAAE,MAAM,IAAI,CAAA;SAAE,KAAK,IAAI,CAAC;KACrD,CAAC;CACH,CACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompositeInput.types.js","sourceRoot":"","sources":["../../../src/components/CompositeInput/CompositeInput.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType } from 'react';\n\nimport type { DeferInfer, NoChildrenProp, TestIdProp, WithAttributes } from '../../types';\nimport type { FormControlProps } from '../FormControl';\n\nexport type CompositeInputProps<P extends object = object> = WithAttributes<\n 'input',\n TestIdProp &\n NoChildrenProp & {\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n /** Callback when clear button is clicked. */\n onClear
|
|
1
|
+
{"version":3,"file":"CompositeInput.types.js","sourceRoot":"","sources":["../../../src/components/CompositeInput/CompositeInput.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType } from 'react';\n\nimport type { DeferInfer, NoChildrenProp, TestIdProp, WithAttributes } from '../../types';\nimport type { FormControlProps } from '../FormControl';\n\nexport type CompositeInputProps<P extends object = object> = WithAttributes<\n 'input',\n TestIdProp &\n NoChildrenProp & {\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n /** Callback when clear button is clicked. */\n onClear?: () => void;\n /** Button when clicked will show additional information for the composite input */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Value form options. */\n dialog: {\n /** A component to render the main portion of the form. */\n renderer: ComponentType<P>;\n /** A props object that will be passed to the form renderer. */\n rendererProps?: DeferInfer<P>;\n /** Callback when cancel button is clicked. */\n onCancel: ({ close }: { close: () => void }) => void;\n /** Callback when apply button is clicked. */\n onApply: ({ close }: { close: () => void }) => void;\n };\n }\n>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Progress.d.ts","sourceRoot":"","sources":["../../../src/components/Progress/Progress.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Progress.d.ts","sourceRoot":"","sources":["../../../src/components/Progress/Progress.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAKnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAetD,QAAA,MAAM,QAAQ,EAAE,+BAA+B,CAAC,aAAa,CAuL3D,CAAC;AAEH,eAAe,QAAQ,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useState, useEffect, useRef } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
|
+
import { getLuminance } from 'polished';
|
|
4
5
|
import Text from '../Text';
|
|
5
|
-
import { useConfiguration, useConsolidatedRef, useI18n, useLiveLog } from '../../hooks';
|
|
6
|
+
import { useConfiguration, useConsolidatedRef, useI18n, useLiveLog, useTheme } from '../../hooks';
|
|
6
7
|
import Flex from '../Flex';
|
|
7
8
|
import Bar from './Bar';
|
|
8
9
|
import Ellipsis from './Ellipsis';
|
|
@@ -19,6 +20,7 @@ const Progress = forwardRef(function Progress({ variant = 'ring', placement = 'g
|
|
|
19
20
|
const t = useI18n();
|
|
20
21
|
const { portalTarget } = useConfiguration();
|
|
21
22
|
const { announcePolite } = useLiveLog();
|
|
23
|
+
const theme = useTheme();
|
|
22
24
|
const progressEl = useConsolidatedRef(ref);
|
|
23
25
|
// Rendering states. Both are needed due to Backdrop's transition phase where isVisibleState is false but nullRender is true until onAfterTransitionOut.
|
|
24
26
|
const [isVisibleState, setIsVisibleState] = useState(delay ? false : visibleProp);
|
|
@@ -110,7 +112,9 @@ const Progress = forwardRef(function Progress({ variant = 'ring', placement = 'g
|
|
|
110
112
|
if (placement !== 'inline') {
|
|
111
113
|
indicator = (_jsxs(Flex, { container: { direction: 'column', alignItems: 'center', gap: 0.5 }, as: StyledProgress, placement: placement, children: [indicator, message && (_jsx(Text, { as: StyledMessage, variant: 'secondary', "aria-hidden": true, children: message }))] }));
|
|
112
114
|
}
|
|
113
|
-
|
|
115
|
+
// generate background variant based on theme text color
|
|
116
|
+
const progressBackdropVariant = getLuminance(theme.base.palette['foreground-color']) > 0.5 ? 'dark' : 'light';
|
|
117
|
+
const content = hasBackdrop ? (_jsx(StyledProgressBackdrop, { open: isVisibleState, container: { direction: 'column' }, position: placement === 'global' ? 'fixed' : 'absolute', variant: progressBackdropVariant, alpha: 0.8, onBeforeTransitionIn: onTransitionStartIn, onAfterTransitionIn: onTransitionEndIn, onBeforeTransitionOut: onTransitionStartOut, onAfterTransitionOut: () => {
|
|
114
118
|
setNullRender(true);
|
|
115
119
|
onTransitionEndOut?.();
|
|
116
120
|
}, children: indicator })) : (indicator);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Progress.js","sourceRoot":"","sources":["../../../src/components/Progress/Progress.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,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AAC,CAAC,UAAU,EACvD,OAAO,EAAC,OAAO,EACf,KAAK,EAAE,GAAG,EACV,oBAAoB,EAAE,mBAAmB,EACzC,mBAAmB,EAAE,iBAAiB,EACtC,qBAAqB,EAAE,oBAAoB,EAC3C,oBAAoB,EAAE,GAAG,EAAE;YACzB,aAAa,CAAC,IAAI,CAAC,CAAC;YACpB,kBAAkB,EAAE,EAAE,CAAC;QACzB,CAAC,YAEA,SAAS,GACa,CAC1B,CAAC,CAAC,CAAC,CACF,SAAS,CACV,CAAC;IAEF,OAAO,SAAS,KAAK,QAAQ,IAAI,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAChG,CAAC,CAAC,CAAC;AAEH,eAAe,QAAQ,CAAC","sourcesContent":["import { forwardRef, useState, useEffect, useRef } from 'react';\nimport type { PropsWithoutRef } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport type { ForwardRefForwardPropsComponent } from '../../types';\nimport Text from '../Text';\nimport { useConfiguration, useConsolidatedRef, useI18n, useLiveLog } from '../../hooks';\nimport Flex from '../Flex';\n\nimport type { ProgressProps } from './Progress.types';\nimport Bar from './Bar';\nimport Ellipsis from './Ellipsis';\nimport Ring from './Ring';\nimport { StyledMessage, StyledProgress, StyledProgressBackdrop } from './Progress.styles';\n\nconst variantMap = {\n ring: Ring,\n bar: Bar,\n ellipsis: Ellipsis\n} as const;\n\nconst delayDuration = 100;\nconst minVisibleDuration = 1000;\n\nconst Progress: ForwardRefForwardPropsComponent<ProgressProps> = forwardRef(function Progress(\n {\n variant = 'ring',\n placement = 'global',\n visible: visibleProp = true,\n focusOnVisible = false,\n delay = false,\n onTransitionStartIn,\n onTransitionEndIn,\n onTransitionStartOut,\n onTransitionEndOut,\n value,\n message,\n liveConfig,\n ...restProps\n }: PropsWithoutRef<ProgressProps>,\n ref: ProgressProps['ref']\n) {\n const t = useI18n();\n const { portalTarget } = useConfiguration();\n const { announcePolite } = useLiveLog();\n const progressEl = useConsolidatedRef<HTMLDivElement>(ref);\n\n // Rendering states. Both are needed due to Backdrop's transition phase where isVisibleState is false but nullRender is true until onAfterTransitionOut.\n const [isVisibleState, setIsVisibleState] = useState(delay ? false : visibleProp);\n const [nullRender, setNullRender] = useState(!isVisibleState);\n\n // Refs for timestamps and timeout ids.\n const timeBeforeVisibleRender = useRef<number>();\n const timeAfterVisibleRender = useRef<number>();\n const delayTimer = useRef<number>();\n const minVisibleTimer = useRef<number>();\n\n const hasBackdrop = placement === 'global' || placement === 'local';\n const valString = typeof value === 'number' ? `${value}%` : undefined;\n const label = message && valString ? `${message} - ${valString}` : message || valString;\n\n const renderVisible = () => {\n setIsVisibleState(true);\n setNullRender(false);\n };\n\n const renderNotVisible = () => {\n setIsVisibleState(false);\n // With a transition, setNullRender needs to be called in Backdrop's onAfterTransitionOut.\n if (!hasBackdrop) {\n setNullRender(true);\n }\n };\n\n // Handle render and visible state.\n useEffect(\n () => {\n if (visibleProp) {\n // Capture a timestamp for additional timers.\n timeBeforeVisibleRender.current = Date.now();\n\n if (delay) {\n delayTimer.current = window.setTimeout(renderVisible, delayDuration);\n } else {\n renderVisible();\n }\n } else if (\n // A timer was started to render visible either avoid it or render null.\n delayTimer.current !== undefined\n ) {\n // If a timeout has started to render visible, clear it.\n clearTimeout(delayTimer.current);\n\n // If the indicator has already rendered visible.\n if (timeAfterVisibleRender.current !== undefined) {\n const timeElapsedSinceLastVisibleRender = Date.now() - timeAfterVisibleRender.current;\n\n // If the indicator has been visible for long enough we can remove it.\n if (timeElapsedSinceLastVisibleRender >= minVisibleDuration) {\n renderNotVisible();\n } else {\n // Hold off removing until we hit the minimum visible time.\n minVisibleTimer.current = window.setTimeout(\n renderNotVisible,\n minVisibleDuration - timeElapsedSinceLastVisibleRender\n );\n }\n } else {\n renderNotVisible();\n }\n } else {\n renderNotVisible();\n }\n },\n // visibleProp is the only triggerable dependency. Others values will be captured.\n [visibleProp]\n );\n\n // Live announcement\n useEffect(\n () => {\n if (liveConfig?.contextualLabel && isVisibleState) {\n announcePolite({\n message: `${liveConfig.contextualLabel}, ${label ?? t('loading')}`,\n type: 'status'\n });\n }\n },\n // isVisibleState is the only triggerable dependency. Others values will be captured.\n [isVisibleState]\n );\n\n // Auto focusing and render timestamping.\n useEffect(\n () => {\n if (!nullRender && isVisibleState) {\n // After a visible render set a timestamp for timers above.\n timeAfterVisibleRender.current = Date.now();\n\n if (focusOnVisible) progressEl.current?.focus();\n }\n },\n // nullRender is the only triggerable dependency. Others values will be captured.\n [nullRender]\n );\n\n if (nullRender) return null;\n\n const CompVariant = variantMap[variant];\n\n let indicator = (\n <CompVariant\n aria-label={typeof value !== 'number' ? label : t('loading')}\n as={placement === 'inline' ? 'span' : undefined}\n {...restProps}\n placement={placement}\n value={value}\n aria-valuetext={typeof value === 'number' ? label : undefined}\n ref={progressEl}\n tabIndex={-1}\n />\n );\n\n if (placement !== 'inline') {\n indicator = (\n <Flex\n container={{ direction: 'column', alignItems: 'center', gap: 0.5 }}\n as={StyledProgress}\n placement={placement}\n >\n {indicator}\n {message && (\n <Text as={StyledMessage} variant='secondary' aria-hidden>\n {message}\n </Text>\n )}\n </Flex>\n );\n }\n\n const content = hasBackdrop ? (\n <StyledProgressBackdrop\n open={isVisibleState}\n container={{ direction: 'column' }}\n position={placement === 'global' ? 'fixed' : 'absolute'}\n variant='light'\n alpha={0.8}\n onBeforeTransitionIn={onTransitionStartIn}\n onAfterTransitionIn={onTransitionEndIn}\n onBeforeTransitionOut={onTransitionStartOut}\n onAfterTransitionOut={() => {\n setNullRender(true);\n onTransitionEndOut?.();\n }}\n >\n {indicator}\n </StyledProgressBackdrop>\n ) : (\n indicator\n );\n\n return placement === 'global' && portalTarget ? createPortal(content, portalTarget) : content;\n});\n\nexport default Progress;\n"]}
|
|
1
|
+
{"version":3,"file":"Progress.js","sourceRoot":"","sources":["../../../src/components/Progress/Progress.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,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AAC;IACJ,CAAC;IAED,wDAAwD;IACxD,MAAM,uBAAuB,GAC3B,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAEhF,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAC5B,KAAC,sBAAsB,IACrB,IAAI,EAAE,cAAc,EACpB,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAClC,QAAQ,EAAE,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,EACvD,OAAO,EAAE,uBAAuB,EAChC,KAAK,EAAE,GAAG,EACV,oBAAoB,EAAE,mBAAmB,EACzC,mBAAmB,EAAE,iBAAiB,EACtC,qBAAqB,EAAE,oBAAoB,EAC3C,oBAAoB,EAAE,GAAG,EAAE;YACzB,aAAa,CAAC,IAAI,CAAC,CAAC;YACpB,kBAAkB,EAAE,EAAE,CAAC;QACzB,CAAC,YAEA,SAAS,GACa,CAC1B,CAAC,CAAC,CAAC,CACF,SAAS,CACV,CAAC;IAEF,OAAO,SAAS,KAAK,QAAQ,IAAI,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAChG,CAAC,CAAC,CAAC;AAEH,eAAe,QAAQ,CAAC","sourcesContent":["import { forwardRef, useState, useEffect, useRef } from 'react';\nimport type { PropsWithoutRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport { getLuminance } from 'polished';\n\nimport type { ForwardRefForwardPropsComponent } from '../../types';\nimport Text from '../Text';\nimport { useConfiguration, useConsolidatedRef, useI18n, useLiveLog, useTheme } from '../../hooks';\nimport Flex from '../Flex';\n\nimport type { ProgressProps } from './Progress.types';\nimport Bar from './Bar';\nimport Ellipsis from './Ellipsis';\nimport Ring from './Ring';\nimport { StyledMessage, StyledProgress, StyledProgressBackdrop } from './Progress.styles';\n\nconst variantMap = {\n ring: Ring,\n bar: Bar,\n ellipsis: Ellipsis\n} as const;\n\nconst delayDuration = 100;\nconst minVisibleDuration = 1000;\n\nconst Progress: ForwardRefForwardPropsComponent<ProgressProps> = forwardRef(function Progress(\n {\n variant = 'ring',\n placement = 'global',\n visible: visibleProp = true,\n focusOnVisible = false,\n delay = false,\n onTransitionStartIn,\n onTransitionEndIn,\n onTransitionStartOut,\n onTransitionEndOut,\n value,\n message,\n liveConfig,\n ...restProps\n }: PropsWithoutRef<ProgressProps>,\n ref: ProgressProps['ref']\n) {\n const t = useI18n();\n const { portalTarget } = useConfiguration();\n const { announcePolite } = useLiveLog();\n const theme = useTheme();\n const progressEl = useConsolidatedRef<HTMLDivElement>(ref);\n\n // Rendering states. Both are needed due to Backdrop's transition phase where isVisibleState is false but nullRender is true until onAfterTransitionOut.\n const [isVisibleState, setIsVisibleState] = useState(delay ? false : visibleProp);\n const [nullRender, setNullRender] = useState(!isVisibleState);\n\n // Refs for timestamps and timeout ids.\n const timeBeforeVisibleRender = useRef<number>();\n const timeAfterVisibleRender = useRef<number>();\n const delayTimer = useRef<number>();\n const minVisibleTimer = useRef<number>();\n\n const hasBackdrop = placement === 'global' || placement === 'local';\n const valString = typeof value === 'number' ? `${value}%` : undefined;\n const label = message && valString ? `${message} - ${valString}` : message || valString;\n\n const renderVisible = () => {\n setIsVisibleState(true);\n setNullRender(false);\n };\n\n const renderNotVisible = () => {\n setIsVisibleState(false);\n // With a transition, setNullRender needs to be called in Backdrop's onAfterTransitionOut.\n if (!hasBackdrop) {\n setNullRender(true);\n }\n };\n\n // Handle render and visible state.\n useEffect(\n () => {\n if (visibleProp) {\n // Capture a timestamp for additional timers.\n timeBeforeVisibleRender.current = Date.now();\n\n if (delay) {\n delayTimer.current = window.setTimeout(renderVisible, delayDuration);\n } else {\n renderVisible();\n }\n } else if (\n // A timer was started to render visible either avoid it or render null.\n delayTimer.current !== undefined\n ) {\n // If a timeout has started to render visible, clear it.\n clearTimeout(delayTimer.current);\n\n // If the indicator has already rendered visible.\n if (timeAfterVisibleRender.current !== undefined) {\n const timeElapsedSinceLastVisibleRender = Date.now() - timeAfterVisibleRender.current;\n\n // If the indicator has been visible for long enough we can remove it.\n if (timeElapsedSinceLastVisibleRender >= minVisibleDuration) {\n renderNotVisible();\n } else {\n // Hold off removing until we hit the minimum visible time.\n minVisibleTimer.current = window.setTimeout(\n renderNotVisible,\n minVisibleDuration - timeElapsedSinceLastVisibleRender\n );\n }\n } else {\n renderNotVisible();\n }\n } else {\n renderNotVisible();\n }\n },\n // visibleProp is the only triggerable dependency. Others values will be captured.\n [visibleProp]\n );\n\n // Live announcement\n useEffect(\n () => {\n if (liveConfig?.contextualLabel && isVisibleState) {\n announcePolite({\n message: `${liveConfig.contextualLabel}, ${label ?? t('loading')}`,\n type: 'status'\n });\n }\n },\n // isVisibleState is the only triggerable dependency. Others values will be captured.\n [isVisibleState]\n );\n\n // Auto focusing and render timestamping.\n useEffect(\n () => {\n if (!nullRender && isVisibleState) {\n // After a visible render set a timestamp for timers above.\n timeAfterVisibleRender.current = Date.now();\n\n if (focusOnVisible) progressEl.current?.focus();\n }\n },\n // nullRender is the only triggerable dependency. Others values will be captured.\n [nullRender]\n );\n\n if (nullRender) return null;\n\n const CompVariant = variantMap[variant];\n\n let indicator = (\n <CompVariant\n aria-label={typeof value !== 'number' ? label : t('loading')}\n as={placement === 'inline' ? 'span' : undefined}\n {...restProps}\n placement={placement}\n value={value}\n aria-valuetext={typeof value === 'number' ? label : undefined}\n ref={progressEl}\n tabIndex={-1}\n />\n );\n\n if (placement !== 'inline') {\n indicator = (\n <Flex\n container={{ direction: 'column', alignItems: 'center', gap: 0.5 }}\n as={StyledProgress}\n placement={placement}\n >\n {indicator}\n {message && (\n <Text as={StyledMessage} variant='secondary' aria-hidden>\n {message}\n </Text>\n )}\n </Flex>\n );\n }\n\n // generate background variant based on theme text color\n const progressBackdropVariant =\n getLuminance(theme.base.palette['foreground-color']) > 0.5 ? 'dark' : 'light';\n\n const content = hasBackdrop ? (\n <StyledProgressBackdrop\n open={isVisibleState}\n container={{ direction: 'column' }}\n position={placement === 'global' ? 'fixed' : 'absolute'}\n variant={progressBackdropVariant}\n alpha={0.8}\n onBeforeTransitionIn={onTransitionStartIn}\n onAfterTransitionIn={onTransitionEndIn}\n onBeforeTransitionOut={onTransitionStartOut}\n onAfterTransitionOut={() => {\n setNullRender(true);\n onTransitionEndOut?.();\n }}\n >\n {indicator}\n </StyledProgressBackdrop>\n ) : (\n indicator\n );\n\n return placement === 'global' && portalTarget ? createPortal(content, portalTarget) : content;\n});\n\nexport default Progress;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Progress.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Progress/Progress.styles.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAO,MAAM,sBAAsB;;uDAAqB,CAAC;AAczD,eAAO,MAAM,kBAAkB;iBACqB,OAAO;
|
|
1
|
+
{"version":3,"file":"Progress.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Progress/Progress.styles.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAO,MAAM,sBAAsB;;uDAAqB,CAAC;AAczD,eAAO,MAAM,kBAAkB;iBACqB,OAAO;SAsDzD,CAAC;AAIH,eAAO,MAAM,iBAAiB;iBACG,OAAO;SA6DtC,CAAC;AAIH,eAAO,MAAM,sBAAsB,uIAqEjC,CAAC;AAIH,eAAO,MAAM,aAAa,0GAexB,CAAC;AAIH,eAAO,MAAM,cAAc,8MAezB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rgba } from 'polished';
|
|
1
|
+
import { getLuminance, rgba } from 'polished';
|
|
2
2
|
import styled, { css } from 'styled-components';
|
|
3
3
|
import { calculateFontSize, readableColor } from '../../styles';
|
|
4
4
|
import { defaultThemeProp } from '../../theme';
|
|
@@ -18,6 +18,9 @@ const StyledProgressVisual = styled.div(({ theme }) => {
|
|
|
18
18
|
StyledProgressVisual.defaultProps = defaultThemeProp;
|
|
19
19
|
export const StyledProgressRing = styled(StyledProgressVisual)(({ theme, placement, determinate }) => {
|
|
20
20
|
const size = placement === 'inline' ? '1em' : '2rem';
|
|
21
|
+
const progressTrackColor = getLuminance(theme.base.palette['foreground-color']) > 0.5
|
|
22
|
+
? theme.base.colors.gray['extra-dark']
|
|
23
|
+
: theme.base.colors.gray.light;
|
|
21
24
|
return css `
|
|
22
25
|
position: relative;
|
|
23
26
|
|
|
@@ -28,7 +31,7 @@ export const StyledProgressRing = styled(StyledProgressVisual)(({ theme, placeme
|
|
|
28
31
|
|
|
29
32
|
circle {
|
|
30
33
|
fill: transparent;
|
|
31
|
-
stroke: ${
|
|
34
|
+
stroke: ${progressTrackColor};
|
|
32
35
|
stroke-width: 2;
|
|
33
36
|
r: 45%;
|
|
34
37
|
cx: 50%;
|
|
@@ -67,8 +70,11 @@ export const StyledProgressRing = styled(StyledProgressVisual)(({ theme, placeme
|
|
|
67
70
|
});
|
|
68
71
|
StyledProgressRing.defaultProps = defaultThemeProp;
|
|
69
72
|
export const StyledProgressBar = styled(StyledProgressVisual)(({ theme, placement, determinate }) => {
|
|
73
|
+
const progressTrackColor = getLuminance(theme.base.palette['foreground-color']) > 0.5
|
|
74
|
+
? theme.base.colors.gray['extra-dark']
|
|
75
|
+
: theme.base.colors.gray.light;
|
|
70
76
|
return css `
|
|
71
|
-
background-color: ${
|
|
77
|
+
background-color: ${progressTrackColor};
|
|
72
78
|
border-radius: ${theme.base['border-radius']};
|
|
73
79
|
${placement === 'local'
|
|
74
80
|
? css `
|
|
@@ -148,7 +154,6 @@ export const StyledProgressEllipsis = styled(StyledProgressVisual)(({ theme, pla
|
|
|
148
154
|
> span {
|
|
149
155
|
display: flex;
|
|
150
156
|
justify-content: center;
|
|
151
|
-
mix-blend-mode: multiply;
|
|
152
157
|
|
|
153
158
|
${placement === 'inline' &&
|
|
154
159
|
css `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Progress.styles.js","sourceRoot":"","sources":["../../../src/components/Progress/Progress.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,IAAI,MAAM,SAAS,CAAC;AAI3B,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA,EAAE,CAAC;AAEzD,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACpD,OAAO,GAAG,CAAA;;oBAEQ,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,CAAC;;mCAExB,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC;;GAE3D,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAE5D,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,EAAE;IACtC,MAAM,IAAI,GAAG,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;IAErD,OAAO,GAAG,CAAA;;;;;eAKG,IAAI;gBACH,IAAI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K,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,EACvD,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CACzC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAEtF,OAAO,GAAG,CAAA;iBACK,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAa,CAAC;mBACvD,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,WAAW,CAAC;aAC5C,KAAK;GACf,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,aAAa,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE9C,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAmC,CAAC,EAC5E,KAAK,EACL,SAAS,EACV,EAAE,EAAE;IACH,OAAO,GAAG,CAAA;MACN,SAAS,KAAK,QAAQ;QACxB,GAAG,CAAA;;KAEF;;MAEC,SAAS,KAAK,OAAO;QACvB,GAAG,CAAA;+BACwB,KAAK,CAAC,IAAI,CAAC,OAAO;KAC5C;GACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,cAAc,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import { rgba } from 'polished';\nimport styled, { css } from 'styled-components';\n\nimport { calculateFontSize, readableColor } from '../../styles';\nimport type { FontSize } from '../../styles';\nimport { defaultThemeProp } from '../../theme';\nimport { tryCatch } from '../../utils';\nimport Backdrop from '../Backdrop';\nimport Flex from '../Flex';\n\nimport type { ProgressProps } from './Progress.types';\n\nexport const StyledProgressBackdrop = styled(Backdrop)``;\n\nconst StyledProgressVisual = styled.div(({ theme }) => {\n return css`\n &:focus-visible {\n box-shadow: ${theme.components.button['focus-shadow']};\n outline: none;\n border-radius: calc(9999 * ${theme.base['border-radius']});\n }\n `;\n});\n\nStyledProgressVisual.defaultProps = defaultThemeProp;\n\nexport const StyledProgressRing = styled(StyledProgressVisual)<\n Pick<ProgressProps, 'placement'> & { determinate: boolean }\n>(({ theme, placement, determinate }) => {\n const size = placement === 'inline' ? '1em' : '2rem';\n\n return css`\n position: relative;\n\n svg {\n display: block;\n width: ${size};\n height: ${size};\n\n circle {\n fill: transparent;\n stroke: ${theme.base.colors.gray['extra-light']};\n stroke-width: 2;\n r: 45%;\n cx: 50%;\n cy: 50%;\n transform: rotate(-90deg);\n transform-origin: 50% 50%;\n\n &:nth-child(2) {\n stroke: ${theme.components.progress['progress-color']};\n transition: stroke-dashoffset calc(0.5 * ${theme.base.animation.speed})\n ${theme.base.animation.timing.ease};\n\n ${!determinate &&\n css`\n @keyframes LoadingRing {\n 0% {\n transform: rotate(0deg);\n }\n\n 100% {\n transform: rotate(360deg);\n }\n }\n animation: LoadingRing calc(4 * ${theme.base.animation.speed}) linear infinite;\n `}\n }\n }\n }\n\n ${placement === 'inline' &&\n css`\n display: inline-flex;\n vertical-align: top;\n `}\n `;\n});\n\nStyledProgressRing.defaultProps = defaultThemeProp;\n\nexport const StyledProgressBar = styled(StyledProgressVisual)<\n ProgressProps & { determinate: boolean }\n>(({ theme, placement, determinate }) => {\n return css`\n background-color: ${theme.base.colors.gray['extra-light']};\n border-radius: ${theme.base['border-radius']};\n ${placement === 'local'\n ? css`\n width: calc(100% - 4 * ${theme.base.spacing});\n `\n : css`\n width: 100%;\n `}\n height: 0.375rem;\n min-width: 2rem;\n max-width: min(calc(100vw - 4 * ${theme.base.spacing}), ${theme.base['content-width'].lg});\n overflow: hidden;\n\n ::before {\n content: '';\n display: block;\n height: 100%;\n width: 100%;\n left: 0;\n border-radius: ${theme.base['border-radius']};\n background-color: ${theme.components.progress['progress-color']};\n ${determinate &&\n css`\n transform: translateX(var(--progress, 0));\n transform-origin: 0 50%;\n transition: transform calc(0.5 * ${theme.base.animation.speed})\n ${theme.base.animation.timing.ease};\n `}\n\n ${!determinate &&\n css`\n @keyframes LoadingBar {\n 0% {\n transform: translateX(-100%);\n }\n\n 100% {\n transform: translateX(200%);\n }\n }\n animation: LoadingBar calc(8 * ${theme.base.animation.speed}) linear infinite;\n width: 50%;\n `}\n }\n\n ${placement === 'inline' &&\n css`\n width: 3rem;\n display: inline-block;\n position: relative;\n `}\n `;\n});\n\nStyledProgressBar.defaultProps = defaultThemeProp;\n\nexport const StyledProgressEllipsis = styled(StyledProgressVisual)<\n Pick<ProgressProps, 'placement'>\n>(({ theme, placement }) => {\n return css`\n line-height: 1;\n display: ${placement === 'inline' ? 'inline-flex' : 'block'};\n\n @keyframes LoadingEllipsis {\n 0% {\n transform: scale(0);\n opacity: 0;\n }\n\n 50% {\n transform: scale(1);\n opacity: 1;\n }\n\n 100% {\n transform: scale(0);\n opacity: 0;\n }\n }\n\n > span {\n display: flex;\n justify-content: center;\n mix-blend-mode: multiply;\n\n ${placement === 'inline' &&\n css`\n display: inline-flex;\n `}\n }\n\n > span span {\n margin: 0 0.3125rem;\n background: ${theme.components.progress['progress-color']};\n border-radius: 50%;\n animation: LoadingEllipsis calc(4 * ${theme.base.animation.speed}) infinite;\n\n ${placement === 'global' &&\n css`\n width: 1.25rem;\n height: 1.25rem;\n `}\n\n ${(placement === 'local' || placement === 'block') &&\n css`\n width: 0.625rem;\n height: 0.625rem;\n `}\n\n ${placement === 'inline' &&\n css`\n width: 0.1875rem;\n height: 0.1875rem;\n margin: 0 0.1875rem;\n animation-duration: calc(4 * ${theme.base.animation.speed});\n `}\n\n &:nth-child(2) {\n animation-delay: 0.1667s;\n }\n\n &:nth-child(3) {\n animation-delay: ${0.1667 * 2}s;\n }\n }\n `;\n});\n\nStyledProgressEllipsis.defaultProps = defaultThemeProp;\n\nexport const StyledMessage = styled.span(({ theme }) => {\n const color = tryCatch(() => {\n return rgba(\n readableColor(theme.base.palette['primary-background']),\n theme.base.transparency['transparent-3']\n );\n });\n\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return css`\n font-size: ${fontSize[theme.components.label['font-size'] as FontSize]};\n font-weight: ${theme.base['font-weight']['semi-bold']};\n color: ${color};\n `;\n});\n\nStyledMessage.defaultProps = defaultThemeProp;\n\nexport const StyledProgress = styled(Flex)<Pick<ProgressProps, 'placement'>>(({\n theme,\n placement\n}) => {\n return css`\n ${placement !== 'inline' &&\n css`\n width: 100%;\n `}\n\n ${placement === 'block' &&\n css`\n margin-block: calc(2 * ${theme.base.spacing});\n `}\n `;\n});\n\nStyledProgress.defaultProps = defaultThemeProp;\n"]}
|
|
1
|
+
{"version":3,"file":"Progress.styles.js","sourceRoot":"","sources":["../../../src/components/Progress/Progress.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,IAAI,MAAM,SAAS,CAAC;AAI3B,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA,EAAE,CAAC;AAEzD,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACpD,OAAO,GAAG,CAAA;;oBAEQ,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,CAAC;;mCAExB,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC;;GAE3D,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,CAAC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C,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAmC,CAAC,EAC5E,KAAK,EACL,SAAS,EACV,EAAE,EAAE;IACH,OAAO,GAAG,CAAA;MACN,SAAS,KAAK,QAAQ;QACxB,GAAG,CAAA;;KAEF;;MAEC,SAAS,KAAK,OAAO;QACvB,GAAG,CAAA;+BACwB,KAAK,CAAC,IAAI,CAAC,OAAO;KAC5C;GACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,cAAc,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import { getLuminance, rgba } from 'polished';\nimport styled, { css } from 'styled-components';\n\nimport { calculateFontSize, readableColor } from '../../styles';\nimport type { FontSize } from '../../styles';\nimport { defaultThemeProp } from '../../theme';\nimport { tryCatch } from '../../utils';\nimport Backdrop from '../Backdrop';\nimport Flex from '../Flex';\n\nimport type { ProgressProps } from './Progress.types';\n\nexport const StyledProgressBackdrop = styled(Backdrop)``;\n\nconst StyledProgressVisual = styled.div(({ theme }) => {\n return css`\n &:focus-visible {\n box-shadow: ${theme.components.button['focus-shadow']};\n outline: none;\n border-radius: calc(9999 * ${theme.base['border-radius']});\n }\n `;\n});\n\nStyledProgressVisual.defaultProps = defaultThemeProp;\n\nexport const StyledProgressRing = styled(StyledProgressVisual)<\n Pick<ProgressProps, 'placement'> & { determinate: boolean }\n>(({ theme, placement, determinate }) => {\n const size = placement === 'inline' ? '1em' : '2rem';\n const progressTrackColor =\n getLuminance(theme.base.palette['foreground-color']) > 0.5\n ? theme.base.colors.gray['extra-dark']\n : theme.base.colors.gray.light;\n\n return css`\n position: relative;\n\n svg {\n display: block;\n width: ${size};\n height: ${size};\n\n circle {\n fill: transparent;\n stroke: ${progressTrackColor};\n stroke-width: 2;\n r: 45%;\n cx: 50%;\n cy: 50%;\n transform: rotate(-90deg);\n transform-origin: 50% 50%;\n\n &:nth-child(2) {\n stroke: ${theme.components.progress['progress-color']};\n transition: stroke-dashoffset calc(0.5 * ${theme.base.animation.speed})\n ${theme.base.animation.timing.ease};\n\n ${!determinate &&\n css`\n @keyframes LoadingRing {\n 0% {\n transform: rotate(0deg);\n }\n\n 100% {\n transform: rotate(360deg);\n }\n }\n animation: LoadingRing calc(4 * ${theme.base.animation.speed}) linear infinite;\n `}\n }\n }\n }\n\n ${placement === 'inline' &&\n css`\n display: inline-flex;\n vertical-align: top;\n `}\n `;\n});\n\nStyledProgressRing.defaultProps = defaultThemeProp;\n\nexport const StyledProgressBar = styled(StyledProgressVisual)<\n ProgressProps & { determinate: boolean }\n>(({ theme, placement, determinate }) => {\n const progressTrackColor =\n getLuminance(theme.base.palette['foreground-color']) > 0.5\n ? theme.base.colors.gray['extra-dark']\n : theme.base.colors.gray.light;\n\n return css`\n background-color: ${progressTrackColor};\n border-radius: ${theme.base['border-radius']};\n ${placement === 'local'\n ? css`\n width: calc(100% - 4 * ${theme.base.spacing});\n `\n : css`\n width: 100%;\n `}\n height: 0.375rem;\n min-width: 2rem;\n max-width: min(calc(100vw - 4 * ${theme.base.spacing}), ${theme.base['content-width'].lg});\n overflow: hidden;\n\n ::before {\n content: '';\n display: block;\n height: 100%;\n width: 100%;\n left: 0;\n border-radius: ${theme.base['border-radius']};\n background-color: ${theme.components.progress['progress-color']};\n ${determinate &&\n css`\n transform: translateX(var(--progress, 0));\n transform-origin: 0 50%;\n transition: transform calc(0.5 * ${theme.base.animation.speed})\n ${theme.base.animation.timing.ease};\n `}\n\n ${!determinate &&\n css`\n @keyframes LoadingBar {\n 0% {\n transform: translateX(-100%);\n }\n\n 100% {\n transform: translateX(200%);\n }\n }\n animation: LoadingBar calc(8 * ${theme.base.animation.speed}) linear infinite;\n width: 50%;\n `}\n }\n\n ${placement === 'inline' &&\n css`\n width: 3rem;\n display: inline-block;\n position: relative;\n `}\n `;\n});\n\nStyledProgressBar.defaultProps = defaultThemeProp;\n\nexport const StyledProgressEllipsis = styled(StyledProgressVisual)<\n Pick<ProgressProps, 'placement'>\n>(({ theme, placement }) => {\n return css`\n line-height: 1;\n display: ${placement === 'inline' ? 'inline-flex' : 'block'};\n\n @keyframes LoadingEllipsis {\n 0% {\n transform: scale(0);\n opacity: 0;\n }\n\n 50% {\n transform: scale(1);\n opacity: 1;\n }\n\n 100% {\n transform: scale(0);\n opacity: 0;\n }\n }\n\n > span {\n display: flex;\n justify-content: center;\n\n ${placement === 'inline' &&\n css`\n display: inline-flex;\n `}\n }\n\n > span span {\n margin: 0 0.3125rem;\n background: ${theme.components.progress['progress-color']};\n border-radius: 50%;\n animation: LoadingEllipsis calc(4 * ${theme.base.animation.speed}) infinite;\n\n ${placement === 'global' &&\n css`\n width: 1.25rem;\n height: 1.25rem;\n `}\n\n ${(placement === 'local' || placement === 'block') &&\n css`\n width: 0.625rem;\n height: 0.625rem;\n `}\n\n ${placement === 'inline' &&\n css`\n width: 0.1875rem;\n height: 0.1875rem;\n margin: 0 0.1875rem;\n animation-duration: calc(4 * ${theme.base.animation.speed});\n `}\n\n &:nth-child(2) {\n animation-delay: 0.1667s;\n }\n\n &:nth-child(3) {\n animation-delay: ${0.1667 * 2}s;\n }\n }\n `;\n});\n\nStyledProgressEllipsis.defaultProps = defaultThemeProp;\n\nexport const StyledMessage = styled.span(({ theme }) => {\n const color = tryCatch(() => {\n return rgba(\n readableColor(theme.base.palette['primary-background']),\n theme.base.transparency['transparent-3']\n );\n });\n\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return css`\n font-size: ${fontSize[theme.components.label['font-size'] as FontSize]};\n font-weight: ${theme.base['font-weight']['semi-bold']};\n color: ${color};\n `;\n});\n\nStyledMessage.defaultProps = defaultThemeProp;\n\nexport const StyledProgress = styled(Flex)<Pick<ProgressProps, 'placement'>>(({\n theme,\n placement\n}) => {\n return css`\n ${placement !== 'inline' &&\n css`\n width: 100%;\n `}\n\n ${placement === 'block' &&\n css`\n margin-block: calc(2 * ${theme.base.spacing});\n `}\n `;\n});\n\nStyledProgress.defaultProps = defaultThemeProp;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButtonCard.d.ts","sourceRoot":"","sources":["../../../src/components/RadioButton/RadioButtonCard.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAK1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"RadioButtonCard.d.ts","sourceRoot":"","sources":["../../../src/components/RadioButton/RadioButtonCard.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAK1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAkC/E,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,kBAAkB,EAAE,SAAS,CAAC,GAC1E,UAAU,CAAC,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;;;;AAoEpD,wBAAuE"}
|
|
@@ -6,9 +6,8 @@ import SelectionCard, { focusableSelector } from '../SelectionCard/SelectionCard
|
|
|
6
6
|
import Text from '../Text';
|
|
7
7
|
import { useConsolidatedRef, useTestIds, useUID } from '../../hooks';
|
|
8
8
|
import { getActiveElement, withTestIds } from '../../utils';
|
|
9
|
-
import { StyledRadioCheck } from '../RadioCheck/RadioCheck';
|
|
10
9
|
import { getRadioButtonCardTestIds } from './RadioButton.test-ids';
|
|
11
|
-
const StyledSelectionCard = styled.div(({ disabled, readOnly, theme: { components: {
|
|
10
|
+
const StyledSelectionCard = styled.div(({ disabled, readOnly, theme: { components: { 'form-control': { ':hover': { 'border-color': hoverBorderColor } } } } }) => {
|
|
12
11
|
return css `
|
|
13
12
|
${!disabled &&
|
|
14
13
|
css `
|
|
@@ -21,10 +20,6 @@ const StyledSelectionCard = styled.div(({ disabled, readOnly, theme: { component
|
|
|
21
20
|
border-color: ${hoverBorderColor};
|
|
22
21
|
}
|
|
23
22
|
`}
|
|
24
|
-
|
|
25
|
-
${StyledRadioCheck} {
|
|
26
|
-
min-height: ${input.height};
|
|
27
|
-
}
|
|
28
23
|
`;
|
|
29
24
|
});
|
|
30
25
|
StyledSelectionCard.defaultProps = defaultThemeProp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButtonCard.js","sourceRoot":"","sources":["../../../src/components/RadioButton/RadioButtonCard.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAIxE,OAAO,aAAa,EAAE,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"RadioButtonCard.js","sourceRoot":"","sources":["../../../src/components/RadioButton/RadioButtonCard.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAIxE,OAAO,aAAa,EAAE,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,U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C,CAAC,cAAc,EAAE,CAAC;gBACnB,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;YAC5B,CAAC;QACH,CAAC,EACD,GAAG,EAAE,YAAY,GACjB,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC","sourcesContent":["import { forwardRef, useRef } from 'react';\nimport type { PropsWithoutRef, MouseEvent, KeyboardEvent } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { defaultThemeProp, RadioButton } from '@pega/cosmos-react-core';\nimport type { RadioButtonProps } from '@pega/cosmos-react-core';\n\nimport type { OmitStrict, RefElement } from '../../types';\nimport SelectionCard, { focusableSelector } from '../SelectionCard/SelectionCard';\nimport Text from '../Text';\nimport { useConsolidatedRef, useTestIds, useUID } from '../../hooks';\nimport { getActiveElement, withTestIds } from '../../utils';\nimport type { SelectionCardProps } from '../SelectionCard/SelectionCard.types';\n\nimport { getRadioButtonCardTestIds } from './RadioButton.test-ids';\n\nconst StyledSelectionCard = styled.div<Pick<RadioButtonProps, 'disabled' | 'readOnly'>>(\n ({\n disabled,\n readOnly,\n theme: {\n components: {\n 'form-control': {\n ':hover': { 'border-color': hoverBorderColor }\n }\n }\n }\n }) => {\n return css`\n ${!disabled &&\n css`\n cursor: pointer;\n `}\n\n ${!(disabled || readOnly) &&\n css`\n :hover:not(:focus-within) {\n border-color: ${hoverBorderColor};\n }\n `}\n `;\n }\n);\n\nStyledSelectionCard.defaultProps = defaultThemeProp;\n\nexport type RadioButtonCardProps = OmitStrict<SelectionCardProps, 'heading'> &\n OmitStrict<RadioButtonProps, 'label' | 'variant'>;\n\nconst RadioButtonCard = forwardRef<\n RefElement<RadioButtonProps>,\n PropsWithoutRef<RadioButtonCardProps>\n>(function RadioButtonCard(prop, ref) {\n const uid = useUID();\n const { testId, id = uid, label, disabled, readOnly, ...restProps } = prop;\n\n const testIds = useTestIds(testId, getRadioButtonCardTestIds);\n const contentId = `${id}-content`;\n const inputRef = useConsolidatedRef(ref);\n const containerRef = useRef<HTMLDivElement>(null);\n\n return (\n <StyledSelectionCard\n {...restProps}\n as={SelectionCard}\n testId={testIds}\n label={label}\n heading={\n <RadioButton\n testId={testIds.root}\n {...restProps}\n id={id}\n disabled={disabled}\n readOnly={readOnly}\n label={\n <Text variant='h4' as='span'>\n {label}\n </Text>\n }\n variant='simple'\n aria-details={contentId}\n ref={inputRef}\n onKeyDown={(e: KeyboardEvent) => {\n if (e.key.includes('arrow')) e.preventDefault();\n }}\n />\n }\n readOnly={readOnly}\n disabled={disabled}\n onClick={(e: MouseEvent<HTMLDivElement>) => {\n const target = e.target as HTMLElement;\n if (readOnly || !containerRef.current?.contains(target)) return;\n if (\n containerRef.current &&\n [...containerRef.current.querySelectorAll(focusableSelector)].includes(target)\n )\n return;\n e.preventDefault();\n inputRef.current?.click();\n (inputRef.current?.hasAttribute('data-main-focus')\n ? inputRef\n : containerRef\n ).current?.focus();\n }}\n onKeyDown={(e: KeyboardEvent) => {\n if (e.key === ' ' && containerRef.current === getActiveElement()) {\n e.preventDefault();\n inputRef.current?.click();\n }\n }}\n ref={containerRef}\n />\n );\n});\n\nexport default withTestIds(RadioButtonCard, getRadioButtonCardTestIds);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioCheckGroup.d.ts","sourceRoot":"","sources":["../../../src/components/RadioCheckGroup/RadioCheckGroup.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAmB,YAAY,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAG7E,OAAO,KAAK,EAAE,+BAA+B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;
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AqF;IACrF,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC;;;OAGG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IAClC;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,+FAA+F;IAC/F,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,WAAW,CAAC;IACnD,8EAA8E;IAC9E,cAAc,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACpD,6CAA6C;IAC7C,GAAG,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CACxB;AAED,eAAO,MAAM,qBAAqB,8GAiBjC,CAAC;;;;AAuIF,wBAAuE"}
|
|
@@ -6,7 +6,7 @@ import { StyledFormField } from '../FormField/FormField';
|
|
|
6
6
|
import Flex from '../Flex';
|
|
7
7
|
import { useArrows, useConsolidatedRef, useElement, useTestIds, useTheme, useUID } from '../../hooks';
|
|
8
8
|
import Grid from '../Grid';
|
|
9
|
-
import { StyledImageContainer, StyledSelectionCardInline } from '../SelectionCard/SelectionCard.styles';
|
|
9
|
+
import { StyledImageContainer, StyledSelectionCard, StyledSelectionCardInline } from '../SelectionCard/SelectionCard.styles';
|
|
10
10
|
import { withTestIds } from '../../utils';
|
|
11
11
|
import { getRadioCheckGroupTestIds } from './RadioCheckGroup.test-ids';
|
|
12
12
|
export const StyledRadioCheckGroup = styled.fieldset `
|
|
@@ -18,6 +18,10 @@ export const StyledRadioCheckGroup = styled.fieldset `
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
${StyledSelectionCard} {
|
|
22
|
+
max-width: 100%;
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
${StyledSelectionCardInline} ${StyledImageContainer} {
|
|
22
26
|
/* To enlarge the image containers to the size of the biggest one */
|
|
23
27
|
min-height: 100%;
|
|
@@ -81,7 +85,7 @@ const RadioCheckGroup = forwardRef(function RadioCheckGroup(props, ref) {
|
|
|
81
85
|
gap: 1,
|
|
82
86
|
cols: (() => {
|
|
83
87
|
if (!renderInline)
|
|
84
|
-
return '
|
|
88
|
+
return 'minmax(min-content, max-content)';
|
|
85
89
|
if (autoStack)
|
|
86
90
|
return `repeat(auto-fit, minmax(min(100%, ${theme.base['content-width'].sm}), 1fr))`;
|
|
87
91
|
return `repeat(${Children.count(children)}, 1fr)`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioCheckGroup.js","sourceRoot":"","sources":["../../../src/components/RadioCheckGroup/RadioCheckGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEjG,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,UAAU,EACV,UAAU,EACV,QAAQ,EACR,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EAC1B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAiDvE,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,QAAQ,CAAA;;;;QAI5C,eAAe;;;;;IAKnB,yBAAyB,IAAI,oBAAoB;;;;CAIpD,CAAC;AAEF,MAAM,eAAe,GAA0D,UAA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,SAAS,EAAE;gBACT,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ;gBAC1C,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC9B,MAAM,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,EAAE,MAAM;aACb,YAEA,WAAW,GACP,CACR,GACS,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC","sourcesContent":["import { forwardRef, Children, cloneElement, useState, useEffect, useRef, useMemo } from 'react';\nimport type { Ref, PropsWithoutRef, ReactElement, ChangeEvent } from 'react';\nimport styled from 'styled-components';\n\nimport type { ForwardRefForwardPropsComponent, TestIdProp } from '../../types';\nimport FormField from '../FormField';\nimport type { FormFieldProps } from '../FormField';\nimport { StyledFormField } from '../FormField/FormField';\nimport type { FormControlProps } from '../FormControl';\nimport type { RadioCheckProps } from '../RadioCheck';\nimport Flex from '../Flex';\nimport {\n useArrows,\n useConsolidatedRef,\n useElement,\n useTestIds,\n useTheme,\n useUID\n} from '../../hooks';\nimport Grid from '../Grid';\nimport {\n StyledImageContainer,\n StyledSelectionCardInline\n} from '../SelectionCard/SelectionCard.styles';\nimport { withTestIds } from '../../utils';\nimport type { elements } from '../FormField/FormField.test-ids';\n\nimport { getRadioCheckGroupTestIds } from './RadioCheckGroup.test-ids';\n\nexport interface RadioCheckGroupProps extends TestIdProp<typeof elements> {\n /** Accepts Checkboxes or RadioButtons as children. */\n children: ReactElement | ReactElement[];\n /**\n * Conveniently pass an onChange handler to the group to be notified when any of the inputs change.\n * Additionally, onChange can be passed to individual children.\n * Both handlers will be called, child followed by group.\n */\n onChange?: (e: ChangeEvent<HTMLInputElement>) => void;\n /** Callback invoked when the clear button is clicked. If provided will render the clear button. */\n onClear?: FormFieldProps['onClear'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Makes the input non editable and non clickable. The browser defaults to false. */\n readOnly?: FormControlProps['readOnly'];\n /**\n * Layout field elements inline in a row.\n * @default false\n */\n inline?: FormFieldProps['inline'];\n /** Used to toggle the auto stacking feature of an inlined group.\n * @default true\n */\n autoStack?: boolean;\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /**\n * Controls the styling of the child RadioChecks.\n * @default 'simple'\n */\n variant?: RadioCheckProps['variant'] | 'card-grid';\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Ref forwarded to the wrapping element. */\n ref?: Ref<HTMLElement>;\n}\n\nexport const StyledRadioCheckGroup = styled.fieldset`\n flex-wrap: nowrap;\n\n &[disabled] {\n > ${StyledFormField} {\n opacity: unset;\n }\n }\n\n ${StyledSelectionCardInline} ${StyledImageContainer} {\n /* To enlarge the image containers to the size of the biggest one */\n min-height: 100%;\n }\n`;\n\nconst RadioCheckGroup: ForwardRefForwardPropsComponent<RadioCheckGroupProps> = forwardRef(\n function RadioCheckGroup(\n props: PropsWithoutRef<RadioCheckGroupProps>,\n ref: RadioCheckGroupProps['ref']\n ) {\n const uid = useUID();\n const {\n testId,\n children,\n name = uid,\n disabled = false,\n required = false,\n onChange,\n readOnly,\n inline = false,\n autoStack = true,\n variant = 'simple',\n onClear,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getRadioCheckGroupTestIds);\n const theme = useTheme();\n const [optionsEl, setOptionsEl] = useElement<HTMLDivElement>();\n const [renderInline, setRenderInline] = useState(inline);\n const renderInlineRef = useRef(inline);\n const minInlineWidth = useRef(0);\n const containerRef = useConsolidatedRef(ref);\n\n useArrows(containerRef, {\n selector: '[data-main-focus]',\n cycle: false,\n dir: 'left-right'\n });\n\n useEffect(() => {\n setRenderInline(inline);\n if (inline && optionsEl && optionsEl.lastChild && autoStack) {\n const intersectionObserver = new IntersectionObserver(\n entries => {\n if (entries[0].intersectionRatio < 1) {\n if (entries[0].rootBounds) minInlineWidth.current = entries[0].rootBounds.width + 1;\n renderInlineRef.current = false;\n setRenderInline(false);\n }\n },\n { root: optionsEl, threshold: 1 }\n );\n\n const resizeObserver = new ResizeObserver(entries => {\n if (!renderInlineRef.current && entries[0].contentRect.width > minInlineWidth.current) {\n renderInlineRef.current = true;\n setRenderInline(true);\n }\n });\n\n intersectionObserver.observe(optionsEl.lastChild as Element);\n resizeObserver.observe(optionsEl);\n\n return () => {\n intersectionObserver.disconnect();\n resizeObserver.disconnect();\n };\n }\n }, [optionsEl, inline, autoStack]);\n\n const mapChildren = useMemo(\n () =>\n Children.map(children, child =>\n cloneElement(child, {\n name,\n disabled: disabled || child.props.disabled,\n readOnly: readOnly || child.props.readOnly,\n variant: variant === 'card-grid' ? 'card' : variant,\n onChange: onChange\n ? (e: ChangeEvent<HTMLInputElement>) => {\n if (!(readOnly || child.props.readOnly)) {\n child.props.onChange?.(e);\n onChange(e);\n }\n }\n : child.props.onChange\n })\n ),\n [children, name, disabled, readOnly, variant, onChange]\n );\n\n return (\n <FormField\n testId={testIds}\n as={StyledRadioCheckGroup}\n labelAs='legend'\n ref={containerRef}\n name={name}\n disabled={disabled}\n required={required}\n {...restProps}\n isRadioCheck\n onClear={onClear}\n >\n {variant === 'card-grid' ? (\n <Grid\n container={{\n gap: 1,\n cols: (() => {\n if (!renderInline) return '1fr';\n if (autoStack)\n return `repeat(auto-fit, minmax(min(100%, ${theme.base['content-width'].sm}), 1fr))`;\n return `repeat(${Children.count(children)}, 1fr)`;\n })(),\n autoRows: '1fr'\n }}\n >\n {mapChildren}\n </Grid>\n ) : (\n <Flex\n ref={setOptionsEl}\n container={{\n direction: renderInline ? 'row' : 'column',\n colGap: renderInline ? 1.5 : 2,\n rowGap: variant === 'card' ? 1 : 0,\n wrap: 'wrap'\n }}\n >\n {mapChildren}\n </Flex>\n )}\n </FormField>\n );\n }\n);\n\nexport default withTestIds(RadioCheckGroup, getRadioCheckGroupTestIds);\n"]}
|
|
1
|
+
{"version":3,"file":"RadioCheckGroup.js","sourceRoot":"","sources":["../../../src/components/RadioCheckGroup/RadioCheckGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEjG,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,UAAU,EACV,UAAU,EACV,QAAQ,EACR,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EAC1B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAiDvE,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,QAAQ,CAAA;;;;QAI5C,eAAe;;;;;IAKnB,mBAAmB;;;;IAInB,yBAAyB,IAAI,oBAAoB;;;;CAIpD,CAAC;AAEF,MAAM,eAAe,GAA0D,UAAU,CACvF,SAAS,eAAe,CACtB,KAA4C,EAC5C,GAAgC;I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AC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ;gBAC1C,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC9B,MAAM,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,EAAE,MAAM;aACb,YAEA,WAAW,GACP,CACR,GACS,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC","sourcesContent":["import { forwardRef, Children, cloneElement, useState, useEffect, useRef, useMemo } from 'react';\nimport type { Ref, PropsWithoutRef, ReactElement, ChangeEvent } from 'react';\nimport styled from 'styled-components';\n\nimport type { ForwardRefForwardPropsComponent, TestIdProp } from '../../types';\nimport FormField from '../FormField';\nimport type { FormFieldProps } from '../FormField';\nimport { StyledFormField } from '../FormField/FormField';\nimport type { FormControlProps } from '../FormControl';\nimport type { RadioCheckProps } from '../RadioCheck';\nimport Flex from '../Flex';\nimport {\n useArrows,\n useConsolidatedRef,\n useElement,\n useTestIds,\n useTheme,\n useUID\n} from '../../hooks';\nimport Grid from '../Grid';\nimport {\n StyledImageContainer,\n StyledSelectionCard,\n StyledSelectionCardInline\n} from '../SelectionCard/SelectionCard.styles';\nimport { withTestIds } from '../../utils';\nimport type { elements } from '../FormField/FormField.test-ids';\n\nimport { getRadioCheckGroupTestIds } from './RadioCheckGroup.test-ids';\n\nexport interface RadioCheckGroupProps extends TestIdProp<typeof elements> {\n /** Accepts Checkboxes or RadioButtons as children. */\n children: ReactElement | ReactElement[];\n /**\n * Conveniently pass an onChange handler to the group to be notified when any of the inputs change.\n * Additionally, onChange can be passed to individual children.\n * Both handlers will be called, child followed by group.\n */\n onChange?: (e: ChangeEvent<HTMLInputElement>) => void;\n /** Callback invoked when the clear button is clicked. If provided will render the clear button. */\n onClear?: FormFieldProps['onClear'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Makes the input non editable and non clickable. The browser defaults to false. */\n readOnly?: FormControlProps['readOnly'];\n /**\n * Layout field elements inline in a row.\n * @default false\n */\n inline?: FormFieldProps['inline'];\n /** Used to toggle the auto stacking feature of an inlined group.\n * @default true\n */\n autoStack?: boolean;\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /**\n * Controls the styling of the child RadioChecks.\n * @default 'simple'\n */\n variant?: RadioCheckProps['variant'] | 'card-grid';\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Ref forwarded to the wrapping element. */\n ref?: Ref<HTMLElement>;\n}\n\nexport const StyledRadioCheckGroup = styled.fieldset`\n flex-wrap: nowrap;\n\n &[disabled] {\n > ${StyledFormField} {\n opacity: unset;\n }\n }\n\n ${StyledSelectionCard} {\n max-width: 100%;\n }\n\n ${StyledSelectionCardInline} ${StyledImageContainer} {\n /* To enlarge the image containers to the size of the biggest one */\n min-height: 100%;\n }\n`;\n\nconst RadioCheckGroup: ForwardRefForwardPropsComponent<RadioCheckGroupProps> = forwardRef(\n function RadioCheckGroup(\n props: PropsWithoutRef<RadioCheckGroupProps>,\n ref: RadioCheckGroupProps['ref']\n ) {\n const uid = useUID();\n const {\n testId,\n children,\n name = uid,\n disabled = false,\n required = false,\n onChange,\n readOnly,\n inline = false,\n autoStack = true,\n variant = 'simple',\n onClear,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getRadioCheckGroupTestIds);\n const theme = useTheme();\n const [optionsEl, setOptionsEl] = useElement<HTMLDivElement>();\n const [renderInline, setRenderInline] = useState(inline);\n const renderInlineRef = useRef(inline);\n const minInlineWidth = useRef(0);\n const containerRef = useConsolidatedRef(ref);\n\n useArrows(containerRef, {\n selector: '[data-main-focus]',\n cycle: false,\n dir: 'left-right'\n });\n\n useEffect(() => {\n setRenderInline(inline);\n if (inline && optionsEl && optionsEl.lastChild && autoStack) {\n const intersectionObserver = new IntersectionObserver(\n entries => {\n if (entries[0].intersectionRatio < 1) {\n if (entries[0].rootBounds) minInlineWidth.current = entries[0].rootBounds.width + 1;\n renderInlineRef.current = false;\n setRenderInline(false);\n }\n },\n { root: optionsEl, threshold: 1 }\n );\n\n const resizeObserver = new ResizeObserver(entries => {\n if (!renderInlineRef.current && entries[0].contentRect.width > minInlineWidth.current) {\n renderInlineRef.current = true;\n setRenderInline(true);\n }\n });\n\n intersectionObserver.observe(optionsEl.lastChild as Element);\n resizeObserver.observe(optionsEl);\n\n return () => {\n intersectionObserver.disconnect();\n resizeObserver.disconnect();\n };\n }\n }, [optionsEl, inline, autoStack]);\n\n const mapChildren = useMemo(\n () =>\n Children.map(children, child =>\n cloneElement(child, {\n name,\n disabled: disabled || child.props.disabled,\n readOnly: readOnly || child.props.readOnly,\n variant: variant === 'card-grid' ? 'card' : variant,\n onChange: onChange\n ? (e: ChangeEvent<HTMLInputElement>) => {\n if (!(readOnly || child.props.readOnly)) {\n child.props.onChange?.(e);\n onChange(e);\n }\n }\n : child.props.onChange\n })\n ),\n [children, name, disabled, readOnly, variant, onChange]\n );\n\n return (\n <FormField\n testId={testIds}\n as={StyledRadioCheckGroup}\n labelAs='legend'\n ref={containerRef}\n name={name}\n disabled={disabled}\n required={required}\n {...restProps}\n isRadioCheck\n onClear={onClear}\n >\n {variant === 'card-grid' ? (\n <Grid\n container={{\n gap: 1,\n cols: (() => {\n if (!renderInline) return 'minmax(min-content, max-content)';\n if (autoStack)\n return `repeat(auto-fit, minmax(min(100%, ${theme.base['content-width'].sm}), 1fr))`;\n return `repeat(${Children.count(children)}, 1fr)`;\n })(),\n autoRows: '1fr'\n }}\n >\n {mapChildren}\n </Grid>\n ) : (\n <Flex\n ref={setOptionsEl}\n container={{\n direction: renderInline ? 'row' : 'column',\n colGap: renderInline ? 1.5 : 2,\n rowGap: variant === 'card' ? 1 : 0,\n wrap: 'wrap'\n }}\n >\n {mapChildren}\n </Flex>\n )}\n </FormField>\n );\n }\n);\n\nexport default withTestIds(RadioCheckGroup, getRadioCheckGroupTestIds);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionCard.d.ts","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SelectionCard.d.ts","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.tsx"],"names":[],"mappings":"AA2CA,OAAO,KAAK,EAA+B,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAI7F,eAAO,MAAM,iBAAiB,wFACyD,CAAC;;;;AAqMxF,wBAAmE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useEffect, useRef, useState, useMemo, useLayoutEffect, useCallback, cloneElement } from 'react';
|
|
3
|
-
import { debounce, getActiveElement, withTestIds, isValidElement } from '../../utils';
|
|
3
|
+
import { debounce, getActiveElement, withTestIds, isValidElement, hasProp } from '../../utils';
|
|
4
4
|
import Icon, { registerIcon } from '../Icon';
|
|
5
5
|
import { useConsolidatedRef, useEscape, useFocusTrap, useFocusWithin, useI18n, usePrevious, useTestIds, useUID } from '../../hooks';
|
|
6
6
|
import Grid from '../Grid';
|
|
@@ -65,17 +65,20 @@ const SelectionCard = forwardRef(function SelectionCard(props, ref) {
|
|
|
65
65
|
onKeyDown?.(event);
|
|
66
66
|
}, [containerRef, contentRef]);
|
|
67
67
|
const imageContent = useMemo(() => {
|
|
68
|
-
if (image
|
|
69
|
-
const imagery = isBrokenImage && image.src === prevImageSrc ? (_jsx(Icon, { name: 'picture', "aria-label": t('image_load_error') })) : (_jsx(StyledImage, { "data-testid": testIds.image, ...image, onError: () => setIsBrokenImage(true), onLoad: () => setIsBrokenImage(false) }));
|
|
68
|
+
if (image) {
|
|
69
|
+
const imagery = (isBrokenImage && image.src === prevImageSrc) || image.src === undefined ? (_jsx(Icon, { name: 'picture', "aria-label": t('image_load_error') })) : (_jsx(StyledImage, { "data-testid": testIds.image, ...image, onError: () => setIsBrokenImage(true), onLoad: () => setIsBrokenImage(false) }));
|
|
70
70
|
return (_jsx(Flex, { container: { justify: 'center', alignItems: 'center' }, as: StyledImageContainer, placement: image.placement, size: image.size, children: imagery }));
|
|
71
71
|
}
|
|
72
72
|
}, [isBrokenImage, image?.src, prevImageSrc, image?.placement, image?.size]);
|
|
73
73
|
let asProp = StyledSelectionCard;
|
|
74
74
|
if (image) {
|
|
75
|
-
asProp = image.placement?.startsWith('
|
|
76
|
-
?
|
|
77
|
-
:
|
|
75
|
+
asProp = image.placement?.startsWith('block')
|
|
76
|
+
? StyledSelectionCardStacked
|
|
77
|
+
: StyledSelectionCardInline;
|
|
78
78
|
}
|
|
79
|
+
const isFieldValueListItemProps = (item) => {
|
|
80
|
+
return hasProp(item, 'name');
|
|
81
|
+
};
|
|
79
82
|
return (_jsxs(Grid, { "data-testid": testIds.root, ...restProps, onClick: onClick, as: asProp, placement: image?.placement, size: image?.size, container: { cols: '1fr', rows: 'auto' }, disabled: disabled, role: hasInteractiveElements ? 'group' : 'article', "aria-label": label, ref: containerRef, "data-main-focus": focusOnInput ? undefined : true, tabIndex: focusOnInput ? undefined : 0, onKeyDown: handleKeyDown, style: { '--content-height': `${contentHeight}px` }, children: [image && image.placement !== 'inline-end' && imageContent, _jsx("div", { children: _jsxs(Flex, { as: StyledContentContainer, container: { wrap: 'wrap', alignContent: 'start', justify: 'between' }, ref: contentRef, children: [isValidElement(heading)
|
|
80
83
|
? cloneElement(heading, {
|
|
81
84
|
...{
|
|
@@ -85,7 +88,7 @@ const SelectionCard = forwardRef(function SelectionCard(props, ref) {
|
|
|
85
88
|
}
|
|
86
89
|
})
|
|
87
90
|
: heading, actions && (_jsx(Actions, { "data-testid": testIds.actions, items: actions, menuAt: 1, disabled: disabled, contextualLabel: label })), fields.length > 0 &&
|
|
88
|
-
(fields.every(field =>
|
|
91
|
+
(fields.every(field => isFieldValueListItemProps(field)) ? (_jsx(FieldValueList, { id: contentId, "data-testid": testIds.content, fields: fields })) : (_jsx(Flex, { container: { direction: 'column', gap: 1 }, as: StyledValueList, id: contentId, "data-testid": testIds.content, children: fields.map(field => (_jsx("li", { children: field.value }, field.id))) })))] }) }), image?.placement === 'inline-end' && imageContent] }));
|
|
89
92
|
});
|
|
90
93
|
export default withTestIds(SelectionCard, getSelectionCardTestIds);
|
|
91
94
|
//# sourceMappingURL=SelectionCard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionCard.js","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,MAAM,EACN,QAAQ,EACR,OAAO,EACP,eAAe,EACf,WAAW,EACX,YAAY,EACb,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,YAAY,EACZ,cAAc,EACd,OAAO,EACP,WAAW,EACX,UAAU,EACV,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EA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EAAE,MAAM,EAAE,MAAM,GAAI,CAChF,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,IACH,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,EAC1C,EAAE,EAAE,eAAe,EACnB,EAAE,EAAE,SAAS,iBACA,OAAO,CAAC,OAAO,YAE3B,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CACnB,uBAAoB,KAAK,CAAC,KAAK,IAAtB,KAAK,CAAC,EAAE,CAAoB,CACtC,CAAC,GACG,CACR,CAAC,IACC,GACH,EACL,KAAK,EAAE,SAAS,KAAK,YAAY,IAAI,YAAY,IAC7C,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["import {\n forwardRef,\n useEffect,\n useRef,\n useState,\n useMemo,\n useLayoutEffect,\n useCallback,\n cloneElement\n} from 'react';\nimport type { KeyboardEvent, PropsWithoutRef, RefObject } from 'react';\n\nimport { debounce, getActiveElement, withTestIds, isValidElement } from '../../utils';\nimport Icon, { registerIcon } from '../Icon';\nimport type { RefElement } from '../../types';\nimport {\n useConsolidatedRef,\n useEscape,\n useFocusTrap,\n useFocusWithin,\n useI18n,\n usePrevious,\n useTestIds,\n useUID\n} from '../../hooks';\nimport Grid from '../Grid';\nimport type { GridProps } from '../Grid';\nimport Flex from '../Flex';\nimport FieldValueList from '../FieldValueList';\nimport Actions from '../Actions';\nimport { StyledImage } from '../Image';\nimport * as pictureIcon from '../Icon/icons/picture.icon';\n\nimport { getSelectionCardTestIds } from './SelectionCard.test-ids';\nimport {\n StyledSelectionCard,\n StyledContentContainer,\n StyledImageContainer,\n StyledSelectionCardInline,\n StyledSelectionCardStacked,\n StyledValueList\n} from './SelectionCard.styles';\nimport type { SelectionCardProps } from './SelectionCard.types';\n\nregisterIcon(pictureIcon);\n\nexport const focusableSelector =\n 'a[href], button, input, textarea, select, details, video[controls], audio[controls]';\n\nconst useContentHeight = (ref: RefObject<HTMLElement>) => {\n const [height, setHeight] = useState<number | undefined>();\n\n useLayoutEffect(() => {\n if (!ref.current) return;\n\n const resizeObserver = new ResizeObserver(\n debounce(() => {\n setHeight(ref.current?.scrollHeight);\n }, 100)\n );\n\n resizeObserver.observe(ref.current);\n\n return () => {\n resizeObserver.disconnect();\n };\n }, []);\n\n return height;\n};\n\nconst SelectionCard = forwardRef<\n RefElement<SelectionCardProps>,\n PropsWithoutRef<SelectionCardProps>\n>(function SelectionCard(props, ref) {\n const t = useI18n();\n\n const {\n testId,\n label,\n heading,\n disabled = false,\n image,\n fields = [],\n onClick,\n onKeyDown,\n actions,\n additionalInfo,\n ...restProps\n } = props;\n\n const contentRef = useRef<HTMLDivElement>(null);\n const containerRef = useConsolidatedRef(ref);\n\n const [focusOnInput, setFocusOnInput] = useState(false);\n const [hasInteractiveElements, setHasInteractiveElements] = useState(0);\n const [isBrokenImage, setIsBrokenImage] = useState(false);\n const prevImageSrc = usePrevious(image?.src);\n const testIds = useTestIds(testId, getSelectionCardTestIds);\n const contentId = useUID();\n const contentHeight = useContentHeight(contentRef);\n\n useEffect(() => {\n const focusables = containerRef.current?.querySelectorAll(focusableSelector);\n setHasInteractiveElements(focusables?.length || 0);\n setFocusOnInput(focusables?.length === 1 && focusables?.[0] instanceof HTMLInputElement);\n focusables?.forEach(el =>\n el.hasAttribute('data-main-focus')\n ? el.removeAttribute('tabindex')\n : el.setAttribute('tabindex', '-1')\n );\n }, [additionalInfo, fields, actions, contentHeight]);\n\n useFocusTrap(focusOnInput ? null : contentRef, false, [contentRef]);\n\n useFocusWithin([focusOnInput ? null : contentRef], focused =>\n contentRef.current\n ?.querySelectorAll(focusableSelector)\n .forEach(el => (focused ? el.removeAttribute('tabindex') : el.setAttribute('tabindex', '-1')))\n );\n\n useEscape(() => containerRef.current?.focus(), focusOnInput ? null : containerRef, [\n containerRef\n ]);\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent) => {\n if (\n event.key === 'Enter' &&\n containerRef.current === getActiveElement() &&\n (!focusOnInput || (focusOnInput && hasInteractiveElements > 1))\n ) {\n event.preventDefault();\n contentRef.current?.querySelectorAll<HTMLElement>(focusableSelector)[0]?.focus();\n }\n onKeyDown?.(event);\n },\n [containerRef, contentRef]\n );\n\n const imageContent = useMemo(() => {\n if (image?.src) {\n const imagery =\n isBrokenImage && image.src === prevImageSrc ? (\n <Icon name='picture' aria-label={t('image_load_error')} />\n ) : (\n <StyledImage\n data-testid={testIds.image}\n {...image}\n onError={() => setIsBrokenImage(true)}\n onLoad={() => setIsBrokenImage(false)}\n />\n );\n return (\n <Flex\n container={{ justify: 'center', alignItems: 'center' }}\n as={StyledImageContainer}\n placement={image.placement}\n size={image.size}\n >\n {imagery}\n </Flex>\n );\n }\n }, [isBrokenImage, image?.src, prevImageSrc, image?.placement, image?.size]);\n\n let asProp: GridProps['as'] = StyledSelectionCard;\n if (image) {\n asProp = image.placement?.startsWith('inline')\n ? StyledSelectionCardInline\n : StyledSelectionCardStacked;\n }\n\n return (\n <Grid\n data-testid={testIds.root}\n {...restProps}\n onClick={onClick}\n as={asProp}\n placement={image?.placement}\n size={image?.size}\n container={{ cols: '1fr', rows: 'auto' }}\n disabled={disabled}\n role={hasInteractiveElements ? 'group' : 'article'}\n aria-label={label}\n ref={containerRef}\n data-main-focus={focusOnInput ? undefined : true}\n tabIndex={focusOnInput ? undefined : 0}\n onKeyDown={handleKeyDown}\n style={{ '--content-height': `${contentHeight}px` }}\n >\n {image && image.placement !== 'inline-end' && imageContent}\n <div>\n <Flex\n as={StyledContentContainer}\n container={{ wrap: 'wrap', alignContent: 'start', justify: 'between' }}\n ref={contentRef}\n >\n {isValidElement(heading)\n ? cloneElement(heading, {\n ...{\n tabIndex: focusOnInput ? undefined : -1,\n additionalInfo,\n 'data-main-focus': focusOnInput ? true : undefined\n }\n })\n : heading}\n {actions && (\n <Actions\n data-testid={testIds.actions}\n items={actions}\n menuAt={1}\n disabled={disabled}\n contextualLabel={label}\n />\n )}\n {fields.length > 0 &&\n (fields.every(field => 'name' in field) ? (\n <FieldValueList id={contentId} data-testid={testIds.content} fields={fields} />\n ) : (\n <Flex\n container={{ direction: 'column', gap: 1 }}\n as={StyledValueList}\n id={contentId}\n data-testid={testIds.content}\n >\n {fields.map(field => (\n <li key={field.id}>{field.value}</li>\n ))}\n </Flex>\n ))}\n </Flex>\n </div>\n {image?.placement === 'inline-end' && imageContent}\n </Grid>\n );\n});\n\nexport default withTestIds(SelectionCard, getSelectionCardTestIds);\n"]}
|
|
1
|
+
{"version":3,"file":"SelectionCard.js","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,MAAM,EACN,QAAQ,EACR,OAAO,EACP,eAAe,EACf,WAAW,EACX,YAAY,EACb,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC/F,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,YAAY,EACZ,cAAc,EACd,OAAO,EACP,WAAW,EACX,UAAU,EACV,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAE/C,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,WAAW,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,yBAAyB,E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F,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,IACH,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,EAC1C,EAAE,EAAE,eAAe,EACnB,EAAE,EAAE,SAAS,iBACA,OAAO,CAAC,OAAO,YAE3B,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CACnB,uBAAoB,KAAK,CAAC,KAAK,IAAtB,KAAK,CAAC,EAAE,CAAoB,CACtC,CAAC,GACG,CACR,CAAC,IACC,GACH,EACL,KAAK,EAAE,SAAS,KAAK,YAAY,IAAI,YAAY,IAC7C,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["import {\n forwardRef,\n useEffect,\n useRef,\n useState,\n useMemo,\n useLayoutEffect,\n useCallback,\n cloneElement\n} from 'react';\nimport type { KeyboardEvent, PropsWithoutRef, RefObject } from 'react';\n\nimport { debounce, getActiveElement, withTestIds, isValidElement, hasProp } from '../../utils';\nimport Icon, { registerIcon } from '../Icon';\nimport type { RefElement } from '../../types';\nimport {\n useConsolidatedRef,\n useEscape,\n useFocusTrap,\n useFocusWithin,\n useI18n,\n usePrevious,\n useTestIds,\n useUID\n} from '../../hooks';\nimport Grid from '../Grid';\nimport type { GridProps } from '../Grid';\nimport Flex from '../Flex';\nimport FieldValueList from '../FieldValueList';\nimport type { FieldValueListItemProps } from '../FieldValueList';\nimport Actions from '../Actions';\nimport { StyledImage } from '../Image';\nimport * as pictureIcon from '../Icon/icons/picture.icon';\n\nimport { getSelectionCardTestIds } from './SelectionCard.test-ids';\nimport {\n StyledSelectionCard,\n StyledContentContainer,\n StyledImageContainer,\n StyledSelectionCardInline,\n StyledSelectionCardStacked,\n StyledValueList\n} from './SelectionCard.styles';\nimport type { FieldValueItemPropsOmitName, SelectionCardProps } from './SelectionCard.types';\n\nregisterIcon(pictureIcon);\n\nexport const focusableSelector =\n 'a[href], button, input, textarea, select, details, video[controls], audio[controls]';\n\nconst useContentHeight = (ref: RefObject<HTMLElement>) => {\n const [height, setHeight] = useState<number | undefined>();\n\n useLayoutEffect(() => {\n if (!ref.current) return;\n\n const resizeObserver = new ResizeObserver(\n debounce(() => {\n setHeight(ref.current?.scrollHeight);\n }, 100)\n );\n\n resizeObserver.observe(ref.current);\n\n return () => {\n resizeObserver.disconnect();\n };\n }, []);\n\n return height;\n};\n\nconst SelectionCard = forwardRef<\n RefElement<SelectionCardProps>,\n PropsWithoutRef<SelectionCardProps>\n>(function SelectionCard(props, ref) {\n const t = useI18n();\n\n const {\n testId,\n label,\n heading,\n disabled = false,\n image,\n fields = [],\n onClick,\n onKeyDown,\n actions,\n additionalInfo,\n ...restProps\n } = props;\n\n const contentRef = useRef<HTMLDivElement>(null);\n const containerRef = useConsolidatedRef(ref);\n\n const [focusOnInput, setFocusOnInput] = useState(false);\n const [hasInteractiveElements, setHasInteractiveElements] = useState(0);\n const [isBrokenImage, setIsBrokenImage] = useState(false);\n const prevImageSrc = usePrevious(image?.src);\n const testIds = useTestIds(testId, getSelectionCardTestIds);\n const contentId = useUID();\n const contentHeight = useContentHeight(contentRef);\n\n useEffect(() => {\n const focusables = containerRef.current?.querySelectorAll(focusableSelector);\n setHasInteractiveElements(focusables?.length || 0);\n setFocusOnInput(focusables?.length === 1 && focusables?.[0] instanceof HTMLInputElement);\n focusables?.forEach(el =>\n el.hasAttribute('data-main-focus')\n ? el.removeAttribute('tabindex')\n : el.setAttribute('tabindex', '-1')\n );\n }, [additionalInfo, fields, actions, contentHeight]);\n\n useFocusTrap(focusOnInput ? null : contentRef, false, [contentRef]);\n\n useFocusWithin([focusOnInput ? null : contentRef], focused =>\n contentRef.current\n ?.querySelectorAll(focusableSelector)\n .forEach(el => (focused ? el.removeAttribute('tabindex') : el.setAttribute('tabindex', '-1')))\n );\n\n useEscape(() => containerRef.current?.focus(), focusOnInput ? null : containerRef, [\n containerRef\n ]);\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent) => {\n if (\n event.key === 'Enter' &&\n containerRef.current === getActiveElement() &&\n (!focusOnInput || (focusOnInput && hasInteractiveElements > 1))\n ) {\n event.preventDefault();\n contentRef.current?.querySelectorAll<HTMLElement>(focusableSelector)[0]?.focus();\n }\n onKeyDown?.(event);\n },\n [containerRef, contentRef]\n );\n\n const imageContent = useMemo(() => {\n if (image) {\n const imagery =\n (isBrokenImage && image.src === prevImageSrc) || image.src === undefined ? (\n <Icon name='picture' aria-label={t('image_load_error')} />\n ) : (\n <StyledImage\n data-testid={testIds.image}\n {...image}\n onError={() => setIsBrokenImage(true)}\n onLoad={() => setIsBrokenImage(false)}\n />\n );\n return (\n <Flex\n container={{ justify: 'center', alignItems: 'center' }}\n as={StyledImageContainer}\n placement={image.placement}\n size={image.size}\n >\n {imagery}\n </Flex>\n );\n }\n }, [isBrokenImage, image?.src, prevImageSrc, image?.placement, image?.size]);\n\n let asProp: GridProps['as'] = StyledSelectionCard;\n if (image) {\n asProp = image.placement?.startsWith('block')\n ? StyledSelectionCardStacked\n : StyledSelectionCardInline;\n }\n\n const isFieldValueListItemProps = (\n item: FieldValueListItemProps | FieldValueItemPropsOmitName\n ): item is FieldValueListItemProps => {\n return hasProp(item, 'name');\n };\n\n return (\n <Grid\n data-testid={testIds.root}\n {...restProps}\n onClick={onClick}\n as={asProp}\n placement={image?.placement}\n size={image?.size}\n container={{ cols: '1fr', rows: 'auto' }}\n disabled={disabled}\n role={hasInteractiveElements ? 'group' : 'article'}\n aria-label={label}\n ref={containerRef}\n data-main-focus={focusOnInput ? undefined : true}\n tabIndex={focusOnInput ? undefined : 0}\n onKeyDown={handleKeyDown}\n style={{ '--content-height': `${contentHeight}px` }}\n >\n {image && image.placement !== 'inline-end' && imageContent}\n <div>\n <Flex\n as={StyledContentContainer}\n container={{ wrap: 'wrap', alignContent: 'start', justify: 'between' }}\n ref={contentRef}\n >\n {isValidElement(heading)\n ? cloneElement(heading, {\n ...{\n tabIndex: focusOnInput ? undefined : -1,\n additionalInfo,\n 'data-main-focus': focusOnInput ? true : undefined\n }\n })\n : heading}\n {actions && (\n <Actions\n data-testid={testIds.actions}\n items={actions}\n menuAt={1}\n disabled={disabled}\n contextualLabel={label}\n />\n )}\n {fields.length > 0 &&\n (fields.every(field => isFieldValueListItemProps(field)) ? (\n <FieldValueList id={contentId} data-testid={testIds.content} fields={fields} />\n ) : (\n <Flex\n container={{ direction: 'column', gap: 1 }}\n as={StyledValueList}\n id={contentId}\n data-testid={testIds.content}\n >\n {fields.map(field => (\n <li key={field.id}>{field.value}</li>\n ))}\n </Flex>\n ))}\n </Flex>\n </div>\n {image?.placement === 'inline-end' && imageContent}\n </Grid>\n );\n});\n\nexport default withTestIds(SelectionCard, getSelectionCardTestIds);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionCard.styles.d.ts","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.styles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMjD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3F,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"SelectionCard.styles.d.ts","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.styles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMjD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3F,eAAO,MAAM,mBAAmB,2IAyC/B,CAAC;AAIF,eAAO,MAAM,yBAAyB;gBACxB,aAAa,CAAC,cAAc,EAAE,aAAa,CAAC;WACjD,SAAS;SAsBhB,CAAC;AAEH,eAAO,MAAM,0BAA0B;WAAwC,SAAS;SAkBtF,CAAC;AAEH,eAAO,MAAM,oBAAoB;gBACnB,cAAc;WACnB,SAAS;SA8EjB,CAAC;AAIF,eAAO,MAAM,eAAe,wGAG3B,CAAC;AAEF,eAAO,MAAM,sBAAsB,yGAqBjC,CAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import styled, { css } from 'styled-components';
|
|
2
2
|
import { defaultThemeProp } from '../../theme';
|
|
3
3
|
import { StyledPseudoRadioCheck } from '../RadioCheck/RadioCheck';
|
|
4
|
-
import { StyledFieldValue, StyledFieldValueList } from '../FieldValueList';
|
|
4
|
+
import { StyledFieldValue, StyledFieldValueList, StyledStackedFieldValue } from '../FieldValueList';
|
|
5
5
|
import { StyledIcon } from '../Icon';
|
|
6
6
|
export const StyledSelectionCard = styled.div(({ disabled, theme: { base: { palette, 'disabled-opacity': disabledOpacity }, components: { card, 'form-control': { ':focus': { 'box-shadow': shadow, 'border-color': focusBorderColor } } } } }) => {
|
|
7
7
|
return css `
|
|
8
8
|
min-width: min-content;
|
|
9
|
+
max-width: max-content;
|
|
9
10
|
background-color: ${card.background};
|
|
10
11
|
border-radius: ${card['border-radius']};
|
|
11
12
|
border: 0.0625rem solid ${palette['border-line']};
|
|
@@ -41,11 +42,9 @@ export const StyledSelectionCardInline = styled(StyledSelectionCard)(({ placemen
|
|
|
41
42
|
case 'large':
|
|
42
43
|
imageContainerSize = '8.875rem';
|
|
43
44
|
break;
|
|
44
|
-
|
|
45
|
+
default:
|
|
45
46
|
imageContainerSize = 'minmax(2.5rem, auto)';
|
|
46
47
|
break;
|
|
47
|
-
default:
|
|
48
|
-
imageContainerSize = '';
|
|
49
48
|
}
|
|
50
49
|
return css `
|
|
51
50
|
/* stylelint-disable unit-allowed-list -- "Unexpected unit "fr\`" */
|
|
@@ -76,27 +75,22 @@ export const StyledSelectionCardStacked = styled(StyledSelectionCard)(({ size })
|
|
|
76
75
|
export const StyledImageContainer = styled.div(({ theme: { base: { palette, transparency }, components: { card: { 'border-radius': borderRadius } } }, placement = 'inline-start', size = 'flexible' }) => {
|
|
77
76
|
return css `
|
|
78
77
|
background-color: ${palette['app-background']};
|
|
78
|
+
overflow: hidden;
|
|
79
79
|
|
|
80
80
|
img {
|
|
81
81
|
height: 100%;
|
|
82
82
|
object-fit: contain;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
`
|
|
95
|
-
: css `
|
|
96
|
-
> img {
|
|
97
|
-
aspect-ratio: 4 / 5;
|
|
98
|
-
}
|
|
99
|
-
`}
|
|
85
|
+
> img {
|
|
86
|
+
aspect-ratio: 4 / 5;
|
|
87
|
+
|
|
88
|
+
${placement === 'block-start' &&
|
|
89
|
+
css `
|
|
90
|
+
aspect-ratio: 16 / 9;
|
|
91
|
+
max-height: 100%;
|
|
92
|
+
`}
|
|
93
|
+
}
|
|
100
94
|
|
|
101
95
|
${size === 'flexible' &&
|
|
102
96
|
placement !== 'block-start' &&
|
|
@@ -121,17 +115,26 @@ export const StyledImageContainer = styled.div(({ theme: { base: { palette, tran
|
|
|
121
115
|
}
|
|
122
116
|
`}
|
|
123
117
|
|
|
118
|
+
/* Recalculation of the border radius by substracting border width */
|
|
124
119
|
${placement === 'inline-start' &&
|
|
125
120
|
css `
|
|
126
|
-
border-start-start-radius: ${borderRadius};
|
|
127
|
-
border-end-start-radius: ${borderRadius};
|
|
121
|
+
border-start-start-radius: calc(${borderRadius} - 0.0625rem);
|
|
122
|
+
border-end-start-radius: calc(${borderRadius} - 0.0625rem);
|
|
128
123
|
`}
|
|
129
|
-
|
|
124
|
+
|
|
125
|
+
${placement === 'inline-end' &&
|
|
130
126
|
css `
|
|
131
|
-
border-end-end-radius: ${borderRadius};
|
|
132
|
-
border-start-end-radius: ${borderRadius};
|
|
127
|
+
border-end-end-radius: calc(${borderRadius} - 0.0625rem);
|
|
128
|
+
border-start-end-radius: calc(${borderRadius} - 0.0625rem);
|
|
133
129
|
`}
|
|
134
|
-
|
|
130
|
+
|
|
131
|
+
${placement === 'block-start' &&
|
|
132
|
+
css `
|
|
133
|
+
border-start-start-radius: calc(${borderRadius} - 0.0625rem);
|
|
134
|
+
border-start-end-radius: calc(${borderRadius} - 0.0625rem);
|
|
135
|
+
`}
|
|
136
|
+
|
|
137
|
+
${StyledIcon} {
|
|
135
138
|
opacity: ${transparency['transparent-3']};
|
|
136
139
|
}
|
|
137
140
|
`;
|
|
@@ -145,10 +148,6 @@ export const StyledContentContainer = styled.div(({ theme }) => {
|
|
|
145
148
|
return css `
|
|
146
149
|
padding: ${theme.base.spacing};
|
|
147
150
|
|
|
148
|
-
& > * {
|
|
149
|
-
min-height: ${theme.base['hit-area']['mouse-min']};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
151
|
${StyledFieldValueList}, ${StyledValueList} {
|
|
153
152
|
margin-block-start: ${theme.base.spacing};
|
|
154
153
|
}
|
|
@@ -162,6 +161,9 @@ export const StyledContentContainer = styled.div(({ theme }) => {
|
|
|
162
161
|
text-overflow: ellipsis;
|
|
163
162
|
}
|
|
164
163
|
}
|
|
164
|
+
${StyledStackedFieldValue} {
|
|
165
|
+
grid-column: 1 / -1;
|
|
166
|
+
}
|
|
165
167
|
`;
|
|
166
168
|
});
|
|
167
169
|
StyledContentContainer.defaultProps = defaultThemeProp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionCard.styles.js","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"SelectionCard.styles.js","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIrC,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAC3C,CAAC,EACC,QAAQ,EACR,KAAK,EAAE,EACL,IAAI,EAAE,EAAE,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,EACtD,UAAU,EAAE,EACV,IAAI,EACJ,cAAc,EAAE,EACd,QAAQ,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,EAAE,EACrE,EACF,EACF,EACF,EAAE,EAAE;IACH,OAAO,GAAG,CAAA;;;0BAGY,IAAI,CAAC,UAAU;uBAClB,IAAI,CAAC,eAAe,CAAC;gCACZ,OAAO,CAAC,aAAa,CAAC;;QAE9C,QAAQ;QACV,GAAG,CAAA;;mBAEU,eAAe;OAC3B;;QAEC,CAAC,QAAQ;QACX,GAAG,CAAA;;wBAEe,MAAM;;;;cAIhB,sBAAsB;0BACV,MAAM;4BACJ,gBAAgB;;;OAGrC;KACF,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,mBAAmB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEpD,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAGjE,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE;IACzB,IAAI,kBAAkB,CAAC;IACvB,QAAQ,IAAI,EAAE,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AGF;;QAEC,IAAI,KAAK,OAAO;QAClB,GAAG,CAAA;;OAEF;;QAEC,IAAI,KAAK,OAAO;QAClB,GAAG,CAAA;;;;;;;;OAQF;;;QAGC,SAAS,KAAK,cAAc;QAC9B,GAAG,CAAA;0CACiC,YAAY;wCACd,YAAY;OAC7C;;QAEC,SAAS,KAAK,YAAY;QAC5B,GAAG,CAAA;sCAC6B,YAAY;wCACV,YAAY;OAC7C;;QAEC,SAAS,KAAK,aAAa;QAC7B,GAAG,CAAA;0CACiC,YAAY;wCACd,YAAY;OAC7C;;QAEC,UAAU;mBACC,YAAY,CAAC,eAAe,CAAC;;KAE3C,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,EAAE,CAAA;;;CAGvC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC7D,OAAO,GAAG,CAAA;eACG,KAAK,CAAC,IAAI,CAAC,OAAO;;MAE3B,oBAAoB,KAAK,eAAe;4BAClB,KAAK,CAAC,IAAI,CAAC,OAAO;;;MAGxC,gBAAgB;;;;;;;;;MAShB,uBAAuB;;;GAG1B,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,sBAAsB,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport type { ExcludeStrict } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport { StyledPseudoRadioCheck } from '../RadioCheck/RadioCheck';\nimport { StyledFieldValue, StyledFieldValueList, StyledStackedFieldValue } from '../FieldValueList';\nimport { StyledIcon } from '../Icon';\n\nimport type { ImagePlacement, ImageSize, SelectionCardProps } from './SelectionCard.types';\n\nexport const StyledSelectionCard = styled.div<Pick<SelectionCardProps, 'disabled'>>(\n ({\n disabled,\n theme: {\n base: { palette, 'disabled-opacity': disabledOpacity },\n components: {\n card,\n 'form-control': {\n ':focus': { 'box-shadow': shadow, 'border-color': focusBorderColor }\n }\n }\n }\n }) => {\n return css`\n min-width: min-content;\n max-width: max-content;\n background-color: ${card.background};\n border-radius: ${card['border-radius']};\n border: 0.0625rem solid ${palette['border-line']};\n\n ${disabled &&\n css`\n cursor: not-allowed;\n opacity: ${disabledOpacity};\n `}\n\n ${!disabled &&\n css`\n :focus {\n box-shadow: ${shadow};\n border-color: transparent;\n outline: none;\n\n & ${StyledPseudoRadioCheck} {\n box-shadow: ${shadow};\n border-color: ${focusBorderColor};\n }\n }\n `}\n `;\n }\n);\n\nStyledSelectionCard.defaultProps = defaultThemeProp;\n\nexport const StyledSelectionCardInline = styled(StyledSelectionCard)<{\n placement?: ExcludeStrict<ImagePlacement, 'block-start'>;\n size?: ImageSize;\n}>(({ placement, size }) => {\n let imageContainerSize;\n switch (size) {\n case 'small':\n imageContainerSize = '2.5rem';\n break;\n case 'large':\n imageContainerSize = '8.875rem';\n break;\n default:\n imageContainerSize = 'minmax(2.5rem, auto)';\n break;\n }\n return css`\n /* stylelint-disable unit-allowed-list -- \"Unexpected unit \"fr\\`\" */\n grid-template-columns: ${placement === 'inline-end'\n ? `1fr ${imageContainerSize}`\n : `${imageContainerSize} 1fr`};\n /* stylelint-enable unit-allowed-list */\n grid-template-rows: minmax(2.75rem, 1fr);\n `;\n});\n\nexport const StyledSelectionCardStacked = styled(StyledSelectionCard)<{ size?: ImageSize }>(({\n size\n}) => {\n let containerSize;\n switch (size) {\n case 'small':\n containerSize = '2.5rem';\n break;\n case 'large':\n containerSize = '15.125rem';\n break;\n default:\n containerSize = 'minmax(2.5rem, 15.125rem)';\n }\n return css`\n grid-template-rows: ${containerSize} 1fr;\n grid-template-columns: minmax(2.75rem, 1fr);\n `;\n});\n\nexport const StyledImageContainer = styled.div<{\n placement?: ImagePlacement;\n size?: ImageSize;\n}>(\n ({\n theme: {\n base: { palette, transparency },\n components: {\n card: { 'border-radius': borderRadius }\n }\n },\n placement = 'inline-start',\n size = 'flexible'\n }) => {\n return css`\n background-color: ${palette['app-background']};\n overflow: hidden;\n\n img {\n height: 100%;\n object-fit: contain;\n }\n\n > img {\n aspect-ratio: 4 / 5;\n\n ${placement === 'block-start' &&\n css`\n aspect-ratio: 16 / 9;\n max-height: 100%;\n `}\n }\n\n ${size === 'flexible' &&\n placement !== 'block-start' &&\n css`\n max-width: 8.875rem;\n height: var(--content-height);\n `};\n\n ${size === 'large' &&\n css`\n min-height: 11.0625rem;\n `}\n\n ${size === 'small' &&\n css`\n aspect-ratio: unset;\n\n > img {\n max-width: 2rem;\n max-height: 2rem;\n aspect-ratio: 1 / 1;\n }\n `}\n\n /* Recalculation of the border radius by substracting border width */\n ${placement === 'inline-start' &&\n css`\n border-start-start-radius: calc(${borderRadius} - 0.0625rem);\n border-end-start-radius: calc(${borderRadius} - 0.0625rem);\n `}\n\n ${placement === 'inline-end' &&\n css`\n border-end-end-radius: calc(${borderRadius} - 0.0625rem);\n border-start-end-radius: calc(${borderRadius} - 0.0625rem);\n `}\n\n ${placement === 'block-start' &&\n css`\n border-start-start-radius: calc(${borderRadius} - 0.0625rem);\n border-start-end-radius: calc(${borderRadius} - 0.0625rem);\n `}\n\n ${StyledIcon} {\n opacity: ${transparency['transparent-3']};\n }\n `;\n }\n);\n\nStyledImageContainer.defaultProps = defaultThemeProp;\n\nexport const StyledValueList = styled.ul`\n width: 100%;\n list-style-type: none;\n`;\n\nexport const StyledContentContainer = styled.div(({ theme }) => {\n return css`\n padding: ${theme.base.spacing};\n\n ${StyledFieldValueList}, ${StyledValueList} {\n margin-block-start: ${theme.base.spacing};\n }\n\n ${StyledFieldValue} {\n white-space: nowrap;\n\n &,\n div {\n overflow: hidden;\n text-overflow: ellipsis;\n }\n }\n ${StyledStackedFieldValue} {\n grid-column: 1 / -1;\n }\n `;\n});\n\nStyledContentContainer.defaultProps = defaultThemeProp;\n"]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Ref, MouseEventHandler, KeyboardEventHandler, ReactNode } from 'react';
|
|
2
2
|
import type { ImageProps } from '../Image';
|
|
3
|
-
import type { FieldValueListProps } from '../FieldValueList';
|
|
3
|
+
import type { FieldValueListItemProps, FieldValueListProps } from '../FieldValueList';
|
|
4
4
|
import type { FormControlProps } from '../FormControl';
|
|
5
|
-
import type { Action, WithAttributes, NoChildrenProp, TestIdProp } from '../../types';
|
|
5
|
+
import type { Action, WithAttributes, NoChildrenProp, TestIdProp, OmitStrict } from '../../types';
|
|
6
6
|
import type { selectionCardElements } from './SelectionCard.test-ids';
|
|
7
7
|
export type ImagePlacement = 'block-start' | 'inline-end' | 'inline-start';
|
|
8
8
|
export type ImageSize = 'flexible' | 'large' | 'small';
|
|
9
|
+
export type FieldValueItemPropsOmitName = OmitStrict<FieldValueListItemProps, 'name'>;
|
|
9
10
|
export type SelectionCardProps = WithAttributes<'div', NoChildrenProp & TestIdProp<typeof selectionCardElements> & {
|
|
10
11
|
/** Pass a string or a fragment with a string. */
|
|
11
12
|
label: string;
|
|
@@ -29,10 +30,7 @@ export type SelectionCardProps = WithAttributes<'div', NoChildrenProp & TestIdPr
|
|
|
29
30
|
/** Called when user presses a key. */
|
|
30
31
|
onKeyDown?: KeyboardEventHandler;
|
|
31
32
|
/** The set of field values to render in the card. */
|
|
32
|
-
fields?: FieldValueListProps['fields'] |
|
|
33
|
-
id: string;
|
|
34
|
-
value: ReactNode;
|
|
35
|
-
}[];
|
|
33
|
+
fields?: FieldValueListProps['fields'] | FieldValueItemPropsOmitName[];
|
|
36
34
|
/** Pass a heading and content to show additional information on the field. */
|
|
37
35
|
additionalInfo?: FormControlProps['additionalInfo'];
|
|
38
36
|
/** Set the card to disabled state, ie. non-interactive. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionCard.types.d.ts","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.types.ts"],"names":[],"mappings":"AAAA,OAAO,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AAC,EAAE,cAAc,CAAC;QAC3B;;;WAGG;QACH,IAAI,CAAC,EAAE,SAAS,CAAC;KAClB,CAAC;IACF,wCAAwC;IACxC,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,sCAAsC;IACtC,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,qDAAqD;IACrD,MAAM,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CAAC,GAAG,2BAA2B,EAAE,CAAC;IACvE,8EAA8E;IAC9E,cAAc,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACpD,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,kDAAkD;IAClD,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B,CACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionCard.types.js","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Ref, MouseEventHandler, KeyboardEventHandler, ReactNode } from 'react';\n\nimport type { ImageProps } from '../Image';\nimport type { FieldValueListProps } from '../FieldValueList';\nimport type { FormControlProps } from '../FormControl';\nimport type { Action, WithAttributes, NoChildrenProp, TestIdProp } from '../../types';\n\nimport type { selectionCardElements } from './SelectionCard.test-ids';\n\nexport type ImagePlacement = 'block-start' | 'inline-end' | 'inline-start';\nexport type ImageSize = 'flexible' | 'large' | 'small';\n\nexport type SelectionCardProps = WithAttributes<\n 'div',\n NoChildrenProp &\n TestIdProp<typeof selectionCardElements> & {\n /** Pass a string or a fragment with a string. */\n label: string;\n /** Content to be rendered as a card heading */\n heading: ReactNode;\n /** The image to render in the card. */\n image?: ImageProps & {\n /**\n * Used to determine image placement\n * @default 'inline-start'\n */\n placement?: ImagePlacement;\n /**\n * Used to determine image size\n * @default 'large'\n */\n size?: ImageSize;\n };\n /** The onClick handler for the item. */\n onClick?: MouseEventHandler;\n /** Called when user presses a key. */\n onKeyDown?: KeyboardEventHandler;\n /** The set of field values to render in the card. */\n fields?: FieldValueListProps['fields'] |
|
|
1
|
+
{"version":3,"file":"SelectionCard.types.js","sourceRoot":"","sources":["../../../src/components/SelectionCard/SelectionCard.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Ref, MouseEventHandler, KeyboardEventHandler, ReactNode } from 'react';\n\nimport type { ImageProps } from '../Image';\nimport type { FieldValueListItemProps, FieldValueListProps } from '../FieldValueList';\nimport type { FormControlProps } from '../FormControl';\nimport type { Action, WithAttributes, NoChildrenProp, TestIdProp, OmitStrict } from '../../types';\n\nimport type { selectionCardElements } from './SelectionCard.test-ids';\n\nexport type ImagePlacement = 'block-start' | 'inline-end' | 'inline-start';\nexport type ImageSize = 'flexible' | 'large' | 'small';\n\nexport type FieldValueItemPropsOmitName = OmitStrict<FieldValueListItemProps, 'name'>;\n\nexport type SelectionCardProps = WithAttributes<\n 'div',\n NoChildrenProp &\n TestIdProp<typeof selectionCardElements> & {\n /** Pass a string or a fragment with a string. */\n label: string;\n /** Content to be rendered as a card heading */\n heading: ReactNode;\n /** The image to render in the card. */\n image?: ImageProps & {\n /**\n * Used to determine image placement\n * @default 'inline-start'\n */\n placement?: ImagePlacement;\n /**\n * Used to determine image size\n * @default 'large'\n */\n size?: ImageSize;\n };\n /** The onClick handler for the item. */\n onClick?: MouseEventHandler;\n /** Called when user presses a key. */\n onKeyDown?: KeyboardEventHandler;\n /** The set of field values to render in the card. */\n fields?: FieldValueListProps['fields'] | FieldValueItemPropsOmitName[];\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Set the card to disabled state, ie. non-interactive. */\n disabled?: boolean;\n /** Additional actions */\n actions?: Action[];\n /** Reference to the component's input element. */\n ref?: Ref<HTMLDivElement>;\n }\n>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBreakpoint.d.ts","sourceRoot":"","sources":["../../src/hooks/useBreakpoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAYvC;;;;;GAKG;AACH,QAAA,MAAM,aAAa,eACL,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,+CAKzC;IACD,aAAa,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAC/C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,aAAa,GAAG,eAAe,CAAC;CAC7C,
|
|
1
|
+
{"version":3,"file":"useBreakpoint.d.ts","sourceRoot":"","sources":["../../src/hooks/useBreakpoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAYvC;;;;;GAKG;AACH,QAAA,MAAM,aAAa,eACL,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,+CAKzC;IACD,aAAa,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAC/C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,aAAa,GAAG,eAAe,CAAC;CAC7C,YAuEF,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -24,6 +24,8 @@ const useBreakpoint = (breakpoint, { breakpointRef, defaultValue = false, themeP
|
|
|
24
24
|
// Breakpoint handling for contained elements
|
|
25
25
|
if (breakpointRef && breakpointRef.current) {
|
|
26
26
|
const debouncedResize = debounce((entries) => {
|
|
27
|
+
if (!breakpointRef.current?.checkVisibility())
|
|
28
|
+
return;
|
|
27
29
|
const matchesBreakpoint = entries.some(({ target, contentRect }) => {
|
|
28
30
|
if (target !== breakpointRef.current)
|
|
29
31
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBreakpoint.js","sourceRoot":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,EAAE,QAAQ,CAAC,CAAC;gBAChD,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;gBACjD,UAAU,CAAC,MAAM,CAAC,UAAU,IAAI,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC;YAC/D,CAAC;YAED,OAAO,GAAG,EAAE;gBACV,+DAA+D;gBAC/D,IAAI,mBAAmB;oBAAE,UAAU,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;qBACvE,CAAC;oBACJ,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;gBACtD,CAAC;YACH,CAAC,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;IAE7B,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { useState, useLayoutEffect, useCallback } from 'react';\nimport type { RefObject } from 'react';\n\nimport { windowIsAvailable, debounce } from '../utils';\n\nimport useChToPxConversionFactor from './useChToPxConversionFactor';\nimport useTheme from './useTheme';\n\n// We should be able to safely capture once as the computed root font size is unlikely to change during normal runtime.\nconst rootFontSize = windowIsAvailable\n ? window.getComputedStyle(document.documentElement).fontSize\n : '16px';\n\n/**\n * @example const breakpointActive = useBreakpoint(breakpoint);\n * @param breakpoint The string indicator for the breakpoint that should be checked for validity.\n * @param options\n * @returns breakpointActive:: A boolean indicating if the given breakpoint is active or not. If false, the breakpoint is too big for the screen size.\n */\nconst useBreakpoint = (\n breakpoint: 'xs' | 'sm' | 'md' | 'lg' | 'xl',\n {\n breakpointRef,\n defaultValue = false,\n themeProp = 'breakpoints'\n }: {\n breakpointRef?: RefObject<Element> | undefined;\n defaultValue?: boolean;\n themeProp?: 'breakpoints' | 'content-width';\n } = {}\n) => {\n const {\n base: { breakpoints, 'content-width': contentWidth }\n } = useTheme();\n const breakpointVal =\n themeProp === 'content-width' ? contentWidth[breakpoint] : breakpoints[breakpoint];\n\n const [matches, setMatches] = useState(\n windowIsAvailable ? window.matchMedia(`(min-width: ${breakpointVal})`).matches : !!defaultValue\n );\n\n const chToPxConversionFactor = useChToPxConversionFactor();\n\n const onResize = useCallback((e: MediaQueryListEvent) => {\n setMatches(e.matches);\n }, []);\n\n useLayoutEffect(() => {\n // Breakpoint handling for contained elements\n if (breakpointRef && breakpointRef.current) {\n const debouncedResize = debounce((entries: ResizeObserverEntry[]) => {\n const matchesBreakpoint = entries.some(({ target, contentRect }) => {\n if (target !== breakpointRef.current) return;\n\n const multiplier =\n themeProp === 'breakpoints' ? parseFloat(rootFontSize) : chToPxConversionFactor;\n return contentRect.width >= parseFloat(breakpointVal) * multiplier;\n });\n\n setMatches(matchesBreakpoint);\n }, 100);\n\n const observer = new ResizeObserver(debouncedResize);\n\n observer.observe(breakpointRef.current);\n\n return () => {\n observer.disconnect();\n };\n }\n\n // Breakpoint handling for viewport\n if (windowIsAvailable) {\n const mediaMatch = window.matchMedia(`(min-width: ${breakpointVal})`);\n const mediaMatchAvailable = 'addEventListener' in mediaMatch;\n const resizeHandler = debounce(() => {\n setMatches(window.innerWidth >= parseInt(breakpointVal, 10));\n }, 100);\n\n // Need to check useMatchMedia in order to support unit testing\n if (mediaMatchAvailable) {\n mediaMatch.addEventListener('change', onResize);\n setMatches(mediaMatch.matches);\n } else {\n window.addEventListener('resize', resizeHandler);\n setMatches(window.innerWidth >= parseInt(breakpointVal, 10));\n }\n\n return () => {\n // Need to check useMatchMedia in order to support unit testing\n if (mediaMatchAvailable) mediaMatch.removeEventListener('change', onResize);\n else {\n window.removeEventListener('resize', resizeHandler);\n }\n };\n }\n }, [breakpointRef?.current]);\n\n return matches;\n};\n\nexport default useBreakpoint;\n"]}
|
|
1
|
+
{"version":3,"file":"useBreakpoint.js","sourceRoot":"","sources":["../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,mBAAmB,EAAE,CAAC;gBACxB,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAChD,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;gBACjD,UAAU,CAAC,MAAM,CAAC,UAAU,IAAI,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC;YAC/D,CAAC;YAED,OAAO,GAAG,EAAE;gBACV,+DAA+D;gBAC/D,IAAI,mBAAmB;oBAAE,UAAU,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;qBACvE,CAAC;oBACJ,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;gBACtD,CAAC;YACH,CAAC,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;IAE7B,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { useState, useLayoutEffect, useCallback } from 'react';\nimport type { RefObject } from 'react';\n\nimport { windowIsAvailable, debounce } from '../utils';\n\nimport useChToPxConversionFactor from './useChToPxConversionFactor';\nimport useTheme from './useTheme';\n\n// We should be able to safely capture once as the computed root font size is unlikely to change during normal runtime.\nconst rootFontSize = windowIsAvailable\n ? window.getComputedStyle(document.documentElement).fontSize\n : '16px';\n\n/**\n * @example const breakpointActive = useBreakpoint(breakpoint);\n * @param breakpoint The string indicator for the breakpoint that should be checked for validity.\n * @param options\n * @returns breakpointActive:: A boolean indicating if the given breakpoint is active or not. If false, the breakpoint is too big for the screen size.\n */\nconst useBreakpoint = (\n breakpoint: 'xs' | 'sm' | 'md' | 'lg' | 'xl',\n {\n breakpointRef,\n defaultValue = false,\n themeProp = 'breakpoints'\n }: {\n breakpointRef?: RefObject<Element> | undefined;\n defaultValue?: boolean;\n themeProp?: 'breakpoints' | 'content-width';\n } = {}\n) => {\n const {\n base: { breakpoints, 'content-width': contentWidth }\n } = useTheme();\n const breakpointVal =\n themeProp === 'content-width' ? contentWidth[breakpoint] : breakpoints[breakpoint];\n\n const [matches, setMatches] = useState(\n windowIsAvailable ? window.matchMedia(`(min-width: ${breakpointVal})`).matches : !!defaultValue\n );\n\n const chToPxConversionFactor = useChToPxConversionFactor();\n\n const onResize = useCallback((e: MediaQueryListEvent) => {\n setMatches(e.matches);\n }, []);\n\n useLayoutEffect(() => {\n // Breakpoint handling for contained elements\n if (breakpointRef && breakpointRef.current) {\n const debouncedResize = debounce((entries: ResizeObserverEntry[]) => {\n if (!breakpointRef.current?.checkVisibility()) return;\n const matchesBreakpoint = entries.some(({ target, contentRect }) => {\n if (target !== breakpointRef.current) return;\n\n const multiplier =\n themeProp === 'breakpoints' ? parseFloat(rootFontSize) : chToPxConversionFactor;\n return contentRect.width >= parseFloat(breakpointVal) * multiplier;\n });\n\n setMatches(matchesBreakpoint);\n }, 100);\n\n const observer = new ResizeObserver(debouncedResize);\n\n observer.observe(breakpointRef.current);\n\n return () => {\n observer.disconnect();\n };\n }\n\n // Breakpoint handling for viewport\n if (windowIsAvailable) {\n const mediaMatch = window.matchMedia(`(min-width: ${breakpointVal})`);\n const mediaMatchAvailable = 'addEventListener' in mediaMatch;\n const resizeHandler = debounce(() => {\n setMatches(window.innerWidth >= parseInt(breakpointVal, 10));\n }, 100);\n\n // Need to check useMatchMedia in order to support unit testing\n if (mediaMatchAvailable) {\n mediaMatch.addEventListener('change', onResize);\n setMatches(mediaMatch.matches);\n } else {\n window.addEventListener('resize', resizeHandler);\n setMatches(window.innerWidth >= parseInt(breakpointVal, 10));\n }\n\n return () => {\n // Need to check useMatchMedia in order to support unit testing\n if (mediaMatchAvailable) mediaMatch.removeEventListener('change', onResize);\n else {\n window.removeEventListener('resize', resizeHandler);\n }\n };\n }\n }, [breakpointRef?.current]);\n\n return matches;\n};\n\nexport default useBreakpoint;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-core",
|
|
3
|
-
"version": "8.0.0-build.44.
|
|
3
|
+
"version": "8.0.0-build.44.2",
|
|
4
4
|
"description": "Cosmos is a visual design system and UI component collection. Its goal is to empower application developers in their pursuit to create engaging and rewarding user experiences.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|