@helsenorge/designsystem-react 15.1.0 → 15.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AnchorLink.js +2 -2
- package/lib/AnchorLink.js.map +1 -1
- package/lib/Avatar.js +2 -2
- package/lib/Avatar.js.map +1 -1
- package/lib/Badge.js +2 -2
- package/lib/Badge.js.map +1 -1
- package/lib/Button.js +7 -7
- package/lib/Button.js.map +1 -1
- package/lib/CHANGELOG.md +23 -0
- package/lib/Checkbox.js +5 -5
- package/lib/Checkbox.js.map +1 -1
- package/lib/Checkbox2.js +2 -2
- package/lib/Checkbox2.js.map +1 -1
- package/lib/CheckboxMarker.js +2 -2
- package/lib/CheckboxMarker.js.map +1 -1
- package/lib/Chip.js +4 -4
- package/lib/Chip.js.map +1 -1
- package/lib/Close.js +3 -3
- package/lib/Close.js.map +1 -1
- package/lib/DictionaryTrigger.js +2 -2
- package/lib/DictionaryTrigger.js.map +1 -1
- package/lib/Drawer.js +11 -11
- package/lib/Drawer.js.map +1 -1
- package/lib/DrawerNavigation.js +1 -0
- package/lib/DrawerNavigation.js.map +1 -1
- package/lib/Duolist.js +5 -5
- package/lib/Duolist.js.map +1 -1
- package/lib/ElementHeader.js +9 -9
- package/lib/ElementHeader.js.map +1 -1
- package/lib/ElementHeaderText.js +4 -4
- package/lib/ElementHeaderText.js.map +1 -1
- package/lib/ErrorWrapper.js +2 -2
- package/lib/ErrorWrapper.js.map +1 -1
- package/lib/Expander.js +9 -9
- package/lib/Expander.js.map +1 -1
- package/lib/FilterButton.js +2 -2
- package/lib/FilterButton.js.map +1 -1
- package/lib/FilterButtonAndChipsWrapper.js +17 -5
- package/lib/FilterButtonAndChipsWrapper.js.map +1 -1
- package/lib/FilterDrawer.js +0 -2
- package/lib/FilterDrawer.js.map +1 -1
- package/lib/FilterLinkList.js +7 -6
- package/lib/FilterLinkList.js.map +1 -1
- package/lib/FilterOverviewLinkList.js +10 -1
- package/lib/FilterOverviewLinkList.js.map +1 -1
- package/lib/FilterOverviewSearch.js +2 -2
- package/lib/FilterOverviewSearch.js.map +1 -1
- package/lib/FilterSearch.js +6 -6
- package/lib/FilterSearch.js.map +1 -1
- package/lib/FormFieldTag.js +2 -2
- package/lib/FormFieldTag.js.map +1 -1
- package/lib/FormGroup.js +5 -5
- package/lib/FormGroup.js.map +1 -1
- package/lib/FormLayout.js +3 -3
- package/lib/FormLayout.js.map +1 -1
- package/lib/HelpDetails.js +3 -3
- package/lib/HelpDetails.js.map +1 -1
- package/lib/HelpTriggerIcon.js +2 -2
- package/lib/HelpTriggerIcon.js.map +1 -1
- package/lib/HelpTriggerStandalone.js +2 -2
- package/lib/HelpTriggerStandalone.js.map +1 -1
- package/lib/HighlightPanel.js +3 -3
- package/lib/HighlightPanel.js.map +1 -1
- package/lib/HorizontalScroll.js +4 -4
- package/lib/HorizontalScroll.js.map +1 -1
- package/lib/Icon.js +2 -2
- package/lib/Icon.js.map +1 -1
- package/lib/InfoTeaser.js +4 -4
- package/lib/InfoTeaser.js.map +1 -1
- package/lib/Input.js +4 -4
- package/lib/Input.js.map +1 -1
- package/lib/LinkList.js +5 -5
- package/lib/LinkList.js.map +1 -1
- package/lib/List.js +2 -2
- package/lib/List.js.map +1 -1
- package/lib/ListEditMode.js +4 -4
- package/lib/ListEditMode.js.map +1 -1
- package/lib/MaxCharacters.js +2 -2
- package/lib/MaxCharacters.js.map +1 -1
- package/lib/PanelTitle.js +2 -2
- package/lib/PanelTitle.js.map +1 -1
- package/lib/PopOver.js +2 -2
- package/lib/PopOver.js.map +1 -1
- package/lib/Radio.js +2 -2
- package/lib/Radio.js.map +1 -1
- package/lib/RadioButton.js +4 -4
- package/lib/RadioButton.js.map +1 -1
- package/lib/RadioMarker.js +2 -2
- package/lib/RadioMarker.js.map +1 -1
- package/lib/Select.js +4 -4
- package/lib/Select.js.map +1 -1
- package/lib/SingleSelectItem.js +3 -3
- package/lib/SingleSelectItem.js.map +1 -1
- package/lib/Slider.js +4 -4
- package/lib/Slider.js.map +1 -1
- package/lib/Spacer.js +2 -2
- package/lib/Spacer.js.map +1 -1
- package/lib/StatusDot.js +4 -4
- package/lib/StatusDot.js.map +1 -1
- package/lib/StatusDotList.js +2 -2
- package/lib/StatusDotList.js.map +1 -1
- package/lib/StepButtons.js +5 -5
- package/lib/StepButtons.js.map +1 -1
- package/lib/TabList.js +8 -8
- package/lib/TabList.js.map +1 -1
- package/lib/TabPanel.js +2 -2
- package/lib/TabPanel.js.map +1 -1
- package/lib/TableBody.js +2 -2
- package/lib/TableBody.js.map +1 -1
- package/lib/TableCell.js +2 -2
- package/lib/TableCell.js.map +1 -1
- package/lib/TableExpandedRow.js +4 -4
- package/lib/TableExpandedRow.js.map +1 -1
- package/lib/TableExpanderCell.js +2 -2
- package/lib/TableExpanderCell.js.map +1 -1
- package/lib/TableHead.js +2 -2
- package/lib/TableHead.js.map +1 -1
- package/lib/TableHeadCell.js +3 -3
- package/lib/TableHeadCell.js.map +1 -1
- package/lib/TableRow.js +3 -3
- package/lib/TableRow.js.map +1 -1
- package/lib/Textarea.js +4 -4
- package/lib/Textarea.js.map +1 -1
- package/lib/Title.js +2 -2
- package/lib/Title.js.map +1 -1
- package/lib/Toast.js +3 -3
- package/lib/Toast.js.map +1 -1
- package/lib/VisualCheckbox.js +3 -3
- package/lib/VisualCheckbox.js.map +1 -1
- package/lib/VisualRadio.js +3 -3
- package/lib/VisualRadio.js.map +1 -1
- package/lib/components/ArticleTeaser/index.js +4 -4
- package/lib/components/ArticleTeaser/index.js.map +1 -1
- package/lib/components/Drawer/Drawer.d.ts +3 -0
- package/lib/components/Drawer/styles.module.scss +24 -0
- package/lib/components/Drawer/styles.module.scss.d.ts +3 -0
- package/lib/components/Dropdown/index.js +5 -5
- package/lib/components/Dropdown/index.js.map +1 -1
- package/lib/components/DropdownOld/index.js +3 -3
- package/lib/components/DropdownOld/index.js.map +1 -1
- package/lib/components/EmptyState/index.js +2 -2
- package/lib/components/EmptyState/index.js.map +1 -1
- package/lib/components/Expander/Expander.d.ts +2 -0
- package/lib/components/Expander/styles.module.scss +24 -12
- package/lib/components/Expander/styles.module.scss.d.ts +2 -0
- package/lib/components/ExpanderHierarchy/index.js +7 -7
- package/lib/components/ExpanderHierarchy/index.js.map +1 -1
- package/lib/components/ExpanderList/index.js +6 -6
- package/lib/components/ExpanderList/index.js.map +1 -1
- package/lib/components/FavoriteButton/index.js +2 -2
- package/lib/components/FavoriteButton/index.js.map +1 -1
- package/lib/components/Filter/FilterButtonAndChipsWrapper/FilterButtonAndChipsWrapper.d.ts +3 -0
- package/lib/components/Filter/FilterButtonAndChipsWrapper/styles.module.scss +18 -2
- package/lib/components/Filter/FilterButtonAndChipsWrapper/styles.module.scss.d.ts +1 -0
- package/lib/components/Filter/FilterDrawer/styles.module.scss +0 -11
- package/lib/components/Filter/FilterDrawer/styles.module.scss.d.ts +0 -1
- package/lib/components/Filter/FilterLinkList/FilterLinkList.d.ts +2 -0
- package/lib/components/Filter/FilterLinkList/FilterLinkList.module.scss +10 -0
- package/lib/components/Filter/FilterOverviewLinkList/FilterOverviewLinkList.d.ts +4 -1
- package/lib/components/HelpBubble/index.js +3 -3
- package/lib/components/HelpBubble/index.js.map +1 -1
- package/lib/components/HelpDrawer/HelpDrawer.d.ts +1 -1
- package/lib/components/HelpDrawer/index.js +2 -1
- package/lib/components/HelpDrawer/index.js.map +1 -1
- package/lib/components/HelpPanel/index.js +2 -2
- package/lib/components/HelpPanel/index.js.map +1 -1
- package/lib/components/HelpTriggerInline/index.js +2 -2
- package/lib/components/HelpTriggerInline/index.js.map +1 -1
- package/lib/components/InfoTeaser/InfoTeaser.d.ts +1 -1
- package/lib/components/InfoTeaser/styles.module.scss +13 -16
- package/lib/components/Loader/index.js +4 -4
- package/lib/components/Loader/index.js.map +1 -1
- package/lib/components/Modal/index.js +9 -9
- package/lib/components/Modal/index.js.map +1 -1
- package/lib/components/NotificationPanel/index.js +6 -6
- package/lib/components/NotificationPanel/index.js.map +1 -1
- package/lib/components/Panel/index.js +12 -12
- package/lib/components/Panel/index.js.map +1 -1
- package/lib/components/PanelList/index.js +3 -3
- package/lib/components/PanelList/index.js.map +1 -1
- package/lib/components/PopMenu/index.js +3 -3
- package/lib/components/PopMenu/index.js.map +1 -1
- package/lib/components/Progressbar/index.js +2 -2
- package/lib/components/Progressbar/index.js.map +1 -1
- package/lib/components/PromoPanel/index.js +2 -2
- package/lib/components/PromoPanel/index.js.map +1 -1
- package/lib/components/ServiceMessage/index.js +5 -5
- package/lib/components/ServiceMessage/index.js.map +1 -1
- package/lib/components/SharingStatus/index.js +4 -4
- package/lib/components/SharingStatus/index.js.map +1 -1
- package/lib/components/Step/index.js +2 -2
- package/lib/components/Step/index.js.map +1 -1
- package/lib/components/Stepper/index.js +2 -2
- package/lib/components/Stepper/index.js.map +1 -1
- package/lib/components/StickyNote/index.js +8 -8
- package/lib/components/StickyNote/index.js.map +1 -1
- package/lib/components/Table/index.js +2 -2
- package/lib/components/Table/index.js.map +1 -1
- package/lib/components/Tabs/index.js +4 -4
- package/lib/components/Tabs/index.js.map +1 -1
- package/lib/components/Tag/constants.d.ts +2 -1
- package/lib/components/Tag/index.js +3 -2
- package/lib/components/Tag/index.js.map +1 -1
- package/lib/components/Tag/styles.module.scss +5 -0
- package/lib/components/Tag/styles.module.scss.d.ts +1 -0
- package/lib/components/Tile/index.js +4 -4
- package/lib/components/Tile/index.js.map +1 -1
- package/lib/components/Toggle/index.js +7 -7
- package/lib/components/Toggle/index.js.map +1 -1
- package/lib/components/Validation/index.js +2 -2
- package/lib/components/Validation/index.js.map +1 -1
- package/lib/components/VisualCheckboxCloud/index.js +2 -2
- package/lib/components/VisualCheckboxCloud/index.js.map +1 -1
- package/lib/components/VisualCheckboxGroup/index.js +3 -3
- package/lib/components/VisualCheckboxGroup/index.js.map +1 -1
- package/lib/components/VisualContentgroupWithImage/VisualContentgroupWithImage.d.ts +13 -0
- package/lib/components/VisualContentgroupWithImage/index.d.ts +3 -0
- package/lib/components/VisualContentgroupWithImage/index.js +22 -0
- package/lib/components/VisualContentgroupWithImage/index.js.map +1 -0
- package/lib/components/VisualContentgroupWithImage/styles.module.scss +50 -0
- package/lib/components/VisualContentgroupWithImage/styles.module.scss.d.ts +12 -0
- package/lib/components/VisualRadioCloud/index.js +2 -2
- package/lib/components/VisualRadioCloud/index.js.map +1 -1
- package/lib/components/VisualRadioGroup/index.js +3 -3
- package/lib/components/VisualRadioGroup/index.js.map +1 -1
- package/lib/getFilterChips.js +3 -3
- package/lib/getFilterChips.js.map +1 -1
- package/lib/utils2.js +7 -7
- package/lib/utils2.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/VisualCheckboxGroup/VisualCheckboxGroup.tsx","../../../src/components/VisualCheckboxGroup/index.ts"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport type { VisualCheckboxProps, VisualCheckboxVariant } from './VisualCheckbox/VisualCheckbox';\n\nimport VisualCheckbox from './VisualCheckbox/VisualCheckbox';\nimport { useIdWithFallback } from '../../hooks/useIdWithFallback';\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { isComponent } from '../../utils/component';\nimport ErrorWrapper from '../ErrorWrapper';\n\nimport styles from './styles.module.scss';\n\nexport interface VisualCheckboxGroupProps {\n /** Items in the group. Should be VisualCheckboxGroup.VisualCheckbox elements. */\n children?: React.ReactNode;\n /** Name shared by all child VisualCheckbox elements (overridable per child) */\n name?: string;\n /** Variant applied to all child VisualCheckbox elements (overridable per child). */\n variant?: VisualCheckboxVariant;\n /** When set and the number of VisualCheckbox children exceeds this limit on the mobile breakpoint, the variant is forced to `line`. */\n mobileLineVariantLimit?: number;\n /** Error message shown above the group */\n error?: string;\n /** Error text id (auto-generated if omitted) */\n errorTextId?: string;\n /** Renders the error component (Default: true) */\n renderError?: boolean;\n /** Ref passed to the error message element */\n errorMessageRef?: React.Ref<HTMLDivElement | null>;\n /** Adds custom classes to the root element. */\n className?: string;\n /** Adds custom classes to the errorWrapper */\n errorWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the data-testid attribute for the error wrapper */\n errorWrapperTestId?: string;\n}\n\ninterface VisualCheckboxGroupComponent extends React.FC<VisualCheckboxGroupProps> {\n VisualCheckbox: typeof VisualCheckbox;\n}\n\nexport const VisualCheckboxGroup: VisualCheckboxGroupComponent = props => {\n const {\n children,\n name,\n variant = 'rectangle',\n mobileLineVariantLimit,\n error,\n errorTextId: errorTextIdProp,\n renderError = true,\n errorMessageRef,\n className,\n errorWrapperClassName,\n testId,\n errorWrapperTestId,\n } = props;\n\n const errorTextId = useIdWithFallback(errorTextIdProp);\n const isMobile = useIsMobileBreakpoint();\n\n const visualCheckboxCount = React.Children.toArray(children).filter(child =>\n isComponent<VisualCheckboxProps>(child, VisualCheckbox)\n ).length;\n\n const effectiveVariant: VisualCheckboxVariant | undefined =\n isMobile && mobileLineVariantLimit !== undefined && visualCheckboxCount > mobileLineVariantLimit ? 'line' : variant;\n\n const mapChild = (child: React.ReactNode): React.ReactNode => {\n if (isComponent<VisualCheckboxProps>(child, VisualCheckbox)) {\n return React.cloneElement(child, {\n name: child.props.name ?? name,\n variant: child.props.variant ?? effectiveVariant,\n error: !!error || child.props.error,\n errorTextId: child.props.errorTextId ?? errorTextId,\n });\n }\n return child;\n };\n\n return (\n <ErrorWrapper\n className={classNames(errorWrapperClassName, className)}\n errorText={error}\n errorTextId={errorTextId}\n renderError={renderError}\n errorMessageRef={errorMessageRef}\n testId={errorWrapperTestId}\n >\n <div\n className={classNames(styles['visual-checkbox-group'], {\n [styles['visual-checkbox-group--variant-line']]: effectiveVariant === 'line',\n })}\n data-testid={testId}\n >\n {React.Children.map(children, mapChild)}\n </div>\n </ErrorWrapper>\n );\n};\n\nVisualCheckboxGroup.VisualCheckbox = VisualCheckbox;\n\nexport default VisualCheckboxGroup;\n","import VisualCheckboxGroup from './VisualCheckboxGroup';\nexport * from './VisualCheckboxGroup';\nexport default VisualCheckboxGroup;\n"],"mappings":";;;;;;;;;;AA6CA,IAAa,uBAAoD,UAAS;CACxE,MAAM,EACJ,UACA,MACA,UAAU,aACV,wBACA,OACA,aAAa,iBACb,cAAc,MACd,iBACA,WACA,uBACA,QACA,uBACE;CAEJ,MAAM,cAAc,kBAAkB,eAAe;CACrD,MAAM,WAAW,sBAAsB;CAEvC,MAAM,sBAAsB,MAAM,SAAS,QAAQ,QAAQ,EAAE,QAAO,UAClE,YAAiC,OAAO,cAAc,CACxD,EAAE;CAEF,MAAM,mBACJ,YAAY,2BAA2B,KAAA,KAAa,sBAAsB,yBAAyB,SAAS;CAE9G,MAAM,YAAY,UAA4C;EAC5D,IAAI,YAAiC,OAAO,cAAc,GACxD,OAAO,MAAM,aAAa,OAAO;GAC/B,MAAM,MAAM,MAAM,QAAQ;GAC1B,SAAS,MAAM,MAAM,WAAW;GAChC,OAAO,CAAC,CAAC,SAAS,MAAM,MAAM;GAC9B,aAAa,MAAM,MAAM,eAAe;EAC1C,CAAC;EAEH,OAAO;CACT;CAEA,OACE,oBAAC,sBAAD;EACE,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/VisualCheckboxGroup/VisualCheckboxGroup.tsx","../../../src/components/VisualCheckboxGroup/index.ts"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport type { VisualCheckboxProps, VisualCheckboxVariant } from './VisualCheckbox/VisualCheckbox';\n\nimport VisualCheckbox from './VisualCheckbox/VisualCheckbox';\nimport { useIdWithFallback } from '../../hooks/useIdWithFallback';\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { isComponent } from '../../utils/component';\nimport ErrorWrapper from '../ErrorWrapper';\n\nimport styles from './styles.module.scss';\n\nexport interface VisualCheckboxGroupProps {\n /** Items in the group. Should be VisualCheckboxGroup.VisualCheckbox elements. */\n children?: React.ReactNode;\n /** Name shared by all child VisualCheckbox elements (overridable per child) */\n name?: string;\n /** Variant applied to all child VisualCheckbox elements (overridable per child). */\n variant?: VisualCheckboxVariant;\n /** When set and the number of VisualCheckbox children exceeds this limit on the mobile breakpoint, the variant is forced to `line`. */\n mobileLineVariantLimit?: number;\n /** Error message shown above the group */\n error?: string;\n /** Error text id (auto-generated if omitted) */\n errorTextId?: string;\n /** Renders the error component (Default: true) */\n renderError?: boolean;\n /** Ref passed to the error message element */\n errorMessageRef?: React.Ref<HTMLDivElement | null>;\n /** Adds custom classes to the root element. */\n className?: string;\n /** Adds custom classes to the errorWrapper */\n errorWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the data-testid attribute for the error wrapper */\n errorWrapperTestId?: string;\n}\n\ninterface VisualCheckboxGroupComponent extends React.FC<VisualCheckboxGroupProps> {\n VisualCheckbox: typeof VisualCheckbox;\n}\n\nexport const VisualCheckboxGroup: VisualCheckboxGroupComponent = props => {\n const {\n children,\n name,\n variant = 'rectangle',\n mobileLineVariantLimit,\n error,\n errorTextId: errorTextIdProp,\n renderError = true,\n errorMessageRef,\n className,\n errorWrapperClassName,\n testId,\n errorWrapperTestId,\n } = props;\n\n const errorTextId = useIdWithFallback(errorTextIdProp);\n const isMobile = useIsMobileBreakpoint();\n\n const visualCheckboxCount = React.Children.toArray(children).filter(child =>\n isComponent<VisualCheckboxProps>(child, VisualCheckbox)\n ).length;\n\n const effectiveVariant: VisualCheckboxVariant | undefined =\n isMobile && mobileLineVariantLimit !== undefined && visualCheckboxCount > mobileLineVariantLimit ? 'line' : variant;\n\n const mapChild = (child: React.ReactNode): React.ReactNode => {\n if (isComponent<VisualCheckboxProps>(child, VisualCheckbox)) {\n return React.cloneElement(child, {\n name: child.props.name ?? name,\n variant: child.props.variant ?? effectiveVariant,\n error: !!error || child.props.error,\n errorTextId: child.props.errorTextId ?? errorTextId,\n });\n }\n return child;\n };\n\n return (\n <ErrorWrapper\n className={classNames(errorWrapperClassName, className)}\n errorText={error}\n errorTextId={errorTextId}\n renderError={renderError}\n errorMessageRef={errorMessageRef}\n testId={errorWrapperTestId}\n >\n <div\n className={classNames(styles['visual-checkbox-group'], {\n [styles['visual-checkbox-group--variant-line']]: effectiveVariant === 'line',\n })}\n data-testid={testId}\n >\n {React.Children.map(children, mapChild)}\n </div>\n </ErrorWrapper>\n );\n};\n\nVisualCheckboxGroup.VisualCheckbox = VisualCheckbox;\n\nexport default VisualCheckboxGroup;\n","import VisualCheckboxGroup from './VisualCheckboxGroup';\nexport * from './VisualCheckboxGroup';\nexport default VisualCheckboxGroup;\n"],"mappings":";;;;;;;;;;AA6CA,IAAa,uBAAoD,UAAS;CACxE,MAAM,EACJ,UACA,MACA,UAAU,aACV,wBACA,OACA,aAAa,iBACb,cAAc,MACd,iBACA,WACA,uBACA,QACA,uBACE;CAEJ,MAAM,cAAc,kBAAkB,eAAe;CACrD,MAAM,WAAW,sBAAsB;CAEvC,MAAM,sBAAsB,MAAM,SAAS,QAAQ,QAAQ,EAAE,QAAO,UAClE,YAAiC,OAAO,cAAc,CACxD,EAAE;CAEF,MAAM,mBACJ,YAAY,2BAA2B,KAAA,KAAa,sBAAsB,yBAAyB,SAAS;CAE9G,MAAM,YAAY,UAA4C;EAC5D,IAAI,YAAiC,OAAO,cAAc,GACxD,OAAO,MAAM,aAAa,OAAO;GAC/B,MAAM,MAAM,MAAM,QAAQ;GAC1B,SAAS,MAAM,MAAM,WAAW;GAChC,OAAO,CAAC,CAAC,SAAS,MAAM,MAAM;GAC9B,aAAa,MAAM,MAAM,eAAe;EAC1C,CAAC;EAEH,OAAO;CACT;CAEA,OACE,oBAAC,sBAAD;EACE,WAAW,GAAW,uBAAuB,SAAS;EACtD,WAAW;EACE;EACA;EACI;EACjB,QAAQ;YAER,oBAAC,OAAD;GACE,WAAW,GAAW,OAAO,0BAA0B,GACpD,OAAO,yCAAyC,qBAAqB,OACxE,CAAC;GACD,eAAa;aAEZ,MAAM,SAAS,IAAI,UAAU,QAAQ;EACnC,CAAA;CACO,CAAA;AAElB;AAEA,oBAAoB,iBAAiB;;;ACtGrC,IAAA,8BAAe"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ImageRatios = 'square' | 'landscape';
|
|
2
|
+
export interface VisualContentgroupWithImageProps {
|
|
3
|
+
/** Set the ratio of the image. */
|
|
4
|
+
imageRatio?: ImageRatios;
|
|
5
|
+
/** Content rendered inside the visualcontent area. */
|
|
6
|
+
visualContent: React.ReactNode;
|
|
7
|
+
/** Content rendered inside the component */
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
/** Sets the data-testid attribute. */
|
|
10
|
+
testId?: string;
|
|
11
|
+
}
|
|
12
|
+
declare const VisualContentgroupWithImage: React.FC<VisualContentgroupWithImageProps>;
|
|
13
|
+
export default VisualContentgroupWithImage;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import cn from "classnames";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import styles from "./styles.module.scss";
|
|
4
|
+
//#region src/components/VisualContentgroupWithImage/VisualContentgroupWithImage.tsx
|
|
5
|
+
var VisualContentgroupWithImage = (props) => {
|
|
6
|
+
const { imageRatio = "square", visualContent, children, testId } = props;
|
|
7
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
8
|
+
"data-testid": testId,
|
|
9
|
+
className: styles["visual-contentgroup-with-image"],
|
|
10
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
11
|
+
className: cn(styles["visual-contentgroup-with-image__frame"], { [styles[`visual-contentgroup-with-image__frame--${imageRatio}`]]: imageRatio }),
|
|
12
|
+
children: visualContent
|
|
13
|
+
}), children]
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/components/VisualContentgroupWithImage/index.ts
|
|
18
|
+
var VisualContentgroupWithImage_default = VisualContentgroupWithImage;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { VisualContentgroupWithImage_default as default };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/VisualContentgroupWithImage/VisualContentgroupWithImage.tsx","../../../src/components/VisualContentgroupWithImage/index.ts"],"sourcesContent":["import classNames from 'classnames';\n\nimport styles from './styles.module.scss';\n\nexport type ImageRatios = 'square' | 'landscape';\n\nexport interface VisualContentgroupWithImageProps {\n /** Set the ratio of the image. */\n imageRatio?: ImageRatios;\n /** Content rendered inside the visualcontent area. */\n visualContent: React.ReactNode;\n /** Content rendered inside the component */\n children: React.ReactNode;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst VisualContentgroupWithImage: React.FC<VisualContentgroupWithImageProps> = props => {\n const { imageRatio = 'square', visualContent, children, testId } = props;\n\n return (\n <div data-testid={testId} className={styles['visual-contentgroup-with-image']}>\n <div\n className={classNames(styles['visual-contentgroup-with-image__frame'], {\n [styles[`visual-contentgroup-with-image__frame--${imageRatio}`]]: imageRatio,\n })}\n >\n {visualContent}\n </div>\n {children}\n </div>\n );\n};\n\nexport default VisualContentgroupWithImage;\n","import VisualContentgroupWithImage from './VisualContentgroupWithImage';\nexport * from './VisualContentgroupWithImage';\nexport default VisualContentgroupWithImage;\n"],"mappings":";;;;AAiBA,IAAM,+BAA0E,UAAS;CACvF,MAAM,EAAE,aAAa,UAAU,eAAe,UAAU,WAAW;CAEnE,OACE,qBAAC,OAAD;EAAK,eAAa;EAAQ,WAAW,OAAO;YAA5C,CACE,oBAAC,OAAD;GACE,WAAW,GAAW,OAAO,0CAA0C,GACpE,OAAO,0CAA0C,gBAAgB,WACpE,CAAC;aAEA;EACE,CAAA,GACJ,QACE;;AAET;;;AC9BA,IAAA,sCAAe"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
@use 'sass:map';
|
|
2
|
+
@use '../../scss/breakpoints' as breakpoints;
|
|
3
|
+
@import '../../scss/supernova/styles/spacers.css';
|
|
4
|
+
|
|
5
|
+
.visual-contentgroup-with-image {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
justify-content: start;
|
|
9
|
+
align-items: start;
|
|
10
|
+
gap: var(--core-space-l);
|
|
11
|
+
|
|
12
|
+
@media (min-width: map.get(breakpoints.$grid-breakpoints, sm)) {
|
|
13
|
+
flex-direction: row-reverse;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&__frame {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
width: 100%;
|
|
22
|
+
|
|
23
|
+
> * {
|
|
24
|
+
width: 100%;
|
|
25
|
+
height: 100%;
|
|
26
|
+
object-fit: cover;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&--square {
|
|
30
|
+
aspect-ratio: 1/1;
|
|
31
|
+
|
|
32
|
+
@media (min-width: map.get(breakpoints.$grid-breakpoints, sm)) {
|
|
33
|
+
flex: 0 0 50%;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@media (min-width: map.get(breakpoints.$grid-breakpoints, lg)) {
|
|
37
|
+
max-width: 30rem;
|
|
38
|
+
max-height: 30rem;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&--landscape {
|
|
43
|
+
aspect-ratio: 3/2;
|
|
44
|
+
|
|
45
|
+
@media (min-width: map.get(breakpoints.$grid-breakpoints, sm)) {
|
|
46
|
+
flex: 0 0 50%;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Styles = {
|
|
2
|
+
'visual-contentgroup-with-image': string;
|
|
3
|
+
'visual-contentgroup-with-image__frame': string;
|
|
4
|
+
'visual-contentgroup-with-image__frame--landscape': string;
|
|
5
|
+
'visual-contentgroup-with-image__frame--square': string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ClassNames = keyof Styles;
|
|
9
|
+
|
|
10
|
+
declare const styles: Styles;
|
|
11
|
+
|
|
12
|
+
export default styles;
|
|
@@ -2,7 +2,7 @@ import { isComponent } from "../../utils/component.js";
|
|
|
2
2
|
import { useIdWithFallback } from "../../hooks/useIdWithFallback.js";
|
|
3
3
|
import { t as ErrorWrapper_default } from "../../ErrorWrapper.js";
|
|
4
4
|
import { t as Radio } from "../../Radio.js";
|
|
5
|
-
import
|
|
5
|
+
import cn from "classnames";
|
|
6
6
|
import React, { useState } from "react";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
import styles from "./styles.module.scss";
|
|
@@ -34,7 +34,7 @@ var VisualRadioCloud = (props) => {
|
|
|
34
34
|
return child;
|
|
35
35
|
};
|
|
36
36
|
return /* @__PURE__ */ jsx(ErrorWrapper_default, {
|
|
37
|
-
className:
|
|
37
|
+
className: cn(errorWrapperClassName, className),
|
|
38
38
|
errorText: error,
|
|
39
39
|
errorTextId,
|
|
40
40
|
renderError,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/VisualRadioCloud/VisualRadioCloud.tsx","../../../src/components/VisualRadioCloud/index.ts"],"sourcesContent":["import React, { useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport type { RadioProps } from './Radio/Radio';\n\nimport Radio from './Radio/Radio';\nimport { useIdWithFallback } from '../../hooks/useIdWithFallback';\nimport { isComponent } from '../../utils/component';\nimport ErrorWrapper from '../ErrorWrapper';\n\nimport styles from './styles.module.scss';\n\nexport interface VisualRadioCloudProps {\n /** Items in the cloud. Should be VisualRadioCloud.Radio elements. */\n children?: React.ReactNode;\n /** Name shared by all child Radio elements (overridable per child). Required for native form grouping. */\n name?: string;\n /** Selected value (controlled). */\n value?: string;\n /** Initial selected value (uncontrolled). */\n defaultValue?: string;\n /** Called when the selected value changes. */\n onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: string) => void;\n /** Error message shown above the cloud */\n error?: string;\n /** Error text id (auto-generated if omitted) */\n errorTextId?: string;\n /** Renders the error component (Default: true) */\n renderError?: boolean;\n /** Ref passed to the error message element */\n errorMessageRef?: React.Ref<HTMLDivElement | null>;\n /** Adds custom classes to the root element. */\n className?: string;\n /** Adds custom classes to the errorWrapper */\n errorWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the data-testid attribute for the error wrapper */\n errorWrapperTestId?: string;\n /** Accessible label for the radiogroup. Use this or `aria-labelledby` when no external `<legend>` labels the group. */\n 'aria-label'?: string;\n /** Id of element labelling the radiogroup (e.g. an external Title/legend). */\n 'aria-labelledby'?: string;\n}\n\ninterface VisualRadioCloudComponent extends React.FC<VisualRadioCloudProps> {\n Radio: typeof Radio;\n}\n\nexport const VisualRadioCloud: VisualRadioCloudComponent = props => {\n const {\n children,\n name,\n value,\n defaultValue,\n onChange,\n error,\n errorTextId: errorTextIdProp,\n renderError = true,\n errorMessageRef,\n className,\n errorWrapperClassName,\n testId,\n errorWrapperTestId,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n } = props;\n\n const errorTextId = useIdWithFallback(errorTextIdProp);\n const [selectedValue, setSelectedValue] = useState<string | undefined>(value ?? defaultValue);\n const [prevValue, setPrevValue] = useState<string | undefined>(value);\n if (prevValue !== value) {\n setPrevValue(value);\n if (value !== undefined && value !== selectedValue) {\n setSelectedValue(value);\n }\n }\n\n const mapChild = (child: React.ReactNode): React.ReactNode => {\n if (isComponent<RadioProps>(child, Radio)) {\n const isSelected = selectedValue !== undefined && child.props.value === selectedValue;\n return React.cloneElement(child, {\n name: child.props.name ?? name,\n checked: isSelected,\n error: !!error || child.props.error,\n errorTextId: child.props.errorTextId ?? errorTextId,\n onChange: (e: React.ChangeEvent<HTMLInputElement>) => {\n setSelectedValue(child.props.value);\n child.props.onChange?.(e);\n onChange?.(e, child.props.value);\n },\n });\n }\n return child;\n };\n\n return (\n <ErrorWrapper\n className={classNames(errorWrapperClassName, className)}\n errorText={error}\n errorTextId={errorTextId}\n renderError={renderError}\n errorMessageRef={errorMessageRef}\n testId={errorWrapperTestId}\n >\n <div\n role=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-invalid={error ? true : undefined}\n aria-describedby={error ? errorTextId : undefined}\n className={styles['visual-radio-cloud']}\n data-testid={testId}\n >\n {React.Children.map(children, mapChild)}\n </div>\n </ErrorWrapper>\n );\n};\n\nVisualRadioCloud.Radio = Radio;\n\nexport default VisualRadioCloud;\n","import VisualRadioCloud from './VisualRadioCloud';\nexport * from './VisualRadioCloud';\nexport default VisualRadioCloud;\n"],"mappings":";;;;;;;;;AAkDA,IAAa,oBAA8C,UAAS;CAClE,MAAM,EACJ,UACA,MACA,OACA,cACA,UACA,OACA,aAAa,iBACb,cAAc,MACd,iBACA,WACA,uBACA,QACA,oBACA,cAAc,WACd,mBAAmB,mBACjB;CAEJ,MAAM,cAAc,kBAAkB,eAAe;CACrD,MAAM,CAAC,eAAe,oBAAoB,SAA6B,SAAS,YAAY;CAC5F,MAAM,CAAC,WAAW,gBAAgB,SAA6B,KAAK;CACpE,IAAI,cAAc,OAAO;EACvB,aAAa,KAAK;EAClB,IAAI,UAAU,KAAA,KAAa,UAAU,eACnC,iBAAiB,KAAK;CAE1B;CAEA,MAAM,YAAY,UAA4C;EAC5D,IAAI,YAAwB,OAAO,KAAK,GAAG;GACzC,MAAM,aAAa,kBAAkB,KAAA,KAAa,MAAM,MAAM,UAAU;GACxE,OAAO,MAAM,aAAa,OAAO;IAC/B,MAAM,MAAM,MAAM,QAAQ;IAC1B,SAAS;IACT,OAAO,CAAC,CAAC,SAAS,MAAM,MAAM;IAC9B,aAAa,MAAM,MAAM,eAAe;IACxC,WAAW,MAA2C;KACpD,iBAAiB,MAAM,MAAM,KAAK;KAClC,MAAM,MAAM,WAAW,CAAC;KACxB,WAAW,GAAG,MAAM,MAAM,KAAK;IACjC;GACF,CAAC;EACH;EACA,OAAO;CACT;CAEA,OACE,oBAAC,sBAAD;EACE,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/VisualRadioCloud/VisualRadioCloud.tsx","../../../src/components/VisualRadioCloud/index.ts"],"sourcesContent":["import React, { useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport type { RadioProps } from './Radio/Radio';\n\nimport Radio from './Radio/Radio';\nimport { useIdWithFallback } from '../../hooks/useIdWithFallback';\nimport { isComponent } from '../../utils/component';\nimport ErrorWrapper from '../ErrorWrapper';\n\nimport styles from './styles.module.scss';\n\nexport interface VisualRadioCloudProps {\n /** Items in the cloud. Should be VisualRadioCloud.Radio elements. */\n children?: React.ReactNode;\n /** Name shared by all child Radio elements (overridable per child). Required for native form grouping. */\n name?: string;\n /** Selected value (controlled). */\n value?: string;\n /** Initial selected value (uncontrolled). */\n defaultValue?: string;\n /** Called when the selected value changes. */\n onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: string) => void;\n /** Error message shown above the cloud */\n error?: string;\n /** Error text id (auto-generated if omitted) */\n errorTextId?: string;\n /** Renders the error component (Default: true) */\n renderError?: boolean;\n /** Ref passed to the error message element */\n errorMessageRef?: React.Ref<HTMLDivElement | null>;\n /** Adds custom classes to the root element. */\n className?: string;\n /** Adds custom classes to the errorWrapper */\n errorWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the data-testid attribute for the error wrapper */\n errorWrapperTestId?: string;\n /** Accessible label for the radiogroup. Use this or `aria-labelledby` when no external `<legend>` labels the group. */\n 'aria-label'?: string;\n /** Id of element labelling the radiogroup (e.g. an external Title/legend). */\n 'aria-labelledby'?: string;\n}\n\ninterface VisualRadioCloudComponent extends React.FC<VisualRadioCloudProps> {\n Radio: typeof Radio;\n}\n\nexport const VisualRadioCloud: VisualRadioCloudComponent = props => {\n const {\n children,\n name,\n value,\n defaultValue,\n onChange,\n error,\n errorTextId: errorTextIdProp,\n renderError = true,\n errorMessageRef,\n className,\n errorWrapperClassName,\n testId,\n errorWrapperTestId,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n } = props;\n\n const errorTextId = useIdWithFallback(errorTextIdProp);\n const [selectedValue, setSelectedValue] = useState<string | undefined>(value ?? defaultValue);\n const [prevValue, setPrevValue] = useState<string | undefined>(value);\n if (prevValue !== value) {\n setPrevValue(value);\n if (value !== undefined && value !== selectedValue) {\n setSelectedValue(value);\n }\n }\n\n const mapChild = (child: React.ReactNode): React.ReactNode => {\n if (isComponent<RadioProps>(child, Radio)) {\n const isSelected = selectedValue !== undefined && child.props.value === selectedValue;\n return React.cloneElement(child, {\n name: child.props.name ?? name,\n checked: isSelected,\n error: !!error || child.props.error,\n errorTextId: child.props.errorTextId ?? errorTextId,\n onChange: (e: React.ChangeEvent<HTMLInputElement>) => {\n setSelectedValue(child.props.value);\n child.props.onChange?.(e);\n onChange?.(e, child.props.value);\n },\n });\n }\n return child;\n };\n\n return (\n <ErrorWrapper\n className={classNames(errorWrapperClassName, className)}\n errorText={error}\n errorTextId={errorTextId}\n renderError={renderError}\n errorMessageRef={errorMessageRef}\n testId={errorWrapperTestId}\n >\n <div\n role=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-invalid={error ? true : undefined}\n aria-describedby={error ? errorTextId : undefined}\n className={styles['visual-radio-cloud']}\n data-testid={testId}\n >\n {React.Children.map(children, mapChild)}\n </div>\n </ErrorWrapper>\n );\n};\n\nVisualRadioCloud.Radio = Radio;\n\nexport default VisualRadioCloud;\n","import VisualRadioCloud from './VisualRadioCloud';\nexport * from './VisualRadioCloud';\nexport default VisualRadioCloud;\n"],"mappings":";;;;;;;;;AAkDA,IAAa,oBAA8C,UAAS;CAClE,MAAM,EACJ,UACA,MACA,OACA,cACA,UACA,OACA,aAAa,iBACb,cAAc,MACd,iBACA,WACA,uBACA,QACA,oBACA,cAAc,WACd,mBAAmB,mBACjB;CAEJ,MAAM,cAAc,kBAAkB,eAAe;CACrD,MAAM,CAAC,eAAe,oBAAoB,SAA6B,SAAS,YAAY;CAC5F,MAAM,CAAC,WAAW,gBAAgB,SAA6B,KAAK;CACpE,IAAI,cAAc,OAAO;EACvB,aAAa,KAAK;EAClB,IAAI,UAAU,KAAA,KAAa,UAAU,eACnC,iBAAiB,KAAK;CAE1B;CAEA,MAAM,YAAY,UAA4C;EAC5D,IAAI,YAAwB,OAAO,KAAK,GAAG;GACzC,MAAM,aAAa,kBAAkB,KAAA,KAAa,MAAM,MAAM,UAAU;GACxE,OAAO,MAAM,aAAa,OAAO;IAC/B,MAAM,MAAM,MAAM,QAAQ;IAC1B,SAAS;IACT,OAAO,CAAC,CAAC,SAAS,MAAM,MAAM;IAC9B,aAAa,MAAM,MAAM,eAAe;IACxC,WAAW,MAA2C;KACpD,iBAAiB,MAAM,MAAM,KAAK;KAClC,MAAM,MAAM,WAAW,CAAC;KACxB,WAAW,GAAG,MAAM,MAAM,KAAK;IACjC;GACF,CAAC;EACH;EACA,OAAO;CACT;CAEA,OACE,oBAAC,sBAAD;EACE,WAAW,GAAW,uBAAuB,SAAS;EACtD,WAAW;EACE;EACA;EACI;EACjB,QAAQ;YAER,oBAAC,OAAD;GACE,MAAK;GACL,cAAY;GACZ,mBAAiB;GACjB,gBAAc,QAAQ,OAAO,KAAA;GAC7B,oBAAkB,QAAQ,cAAc,KAAA;GACxC,WAAW,OAAO;GAClB,eAAa;aAEZ,MAAM,SAAS,IAAI,UAAU,QAAQ;EACnC,CAAA;CACO,CAAA;AAElB;AAEA,iBAAiB,QAAQ;;;ACvHzB,IAAA,2BAAe"}
|
|
@@ -3,7 +3,7 @@ import { useIsMobileBreakpoint } from "../../hooks/useIsMobileBreakpoint.js";
|
|
|
3
3
|
import { useIdWithFallback } from "../../hooks/useIdWithFallback.js";
|
|
4
4
|
import { t as ErrorWrapper_default } from "../../ErrorWrapper.js";
|
|
5
5
|
import { t as VisualRadio } from "../../VisualRadio.js";
|
|
6
|
-
import
|
|
6
|
+
import cn from "classnames";
|
|
7
7
|
import React from "react";
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
9
|
import styles from "./styles.module.scss";
|
|
@@ -43,14 +43,14 @@ var VisualRadioGroup = (props) => {
|
|
|
43
43
|
return child;
|
|
44
44
|
};
|
|
45
45
|
return /* @__PURE__ */ jsx(ErrorWrapper_default, {
|
|
46
|
-
className:
|
|
46
|
+
className: cn(errorWrapperClassName, className),
|
|
47
47
|
errorText: error,
|
|
48
48
|
errorTextId,
|
|
49
49
|
renderError,
|
|
50
50
|
errorMessageRef,
|
|
51
51
|
testId: errorWrapperTestId,
|
|
52
52
|
children: /* @__PURE__ */ jsx("div", {
|
|
53
|
-
className:
|
|
53
|
+
className: cn(styles["visual-radio-group"], { [styles["visual-radio-group--variant-line"]]: effectiveVariant === "line" }),
|
|
54
54
|
"data-testid": testId,
|
|
55
55
|
role: "radiogroup",
|
|
56
56
|
children: React.Children.map(children, mapChild)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/VisualRadioGroup/VisualRadioGroup.tsx","../../../src/components/VisualRadioGroup/index.ts"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport type { VisualRadioProps, VisualRadioVariant } from './VisualRadio/VisualRadio';\n\nimport VisualRadio from './VisualRadio/VisualRadio';\nimport { useIdWithFallback } from '../../hooks/useIdWithFallback';\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { isComponent } from '../../utils/component';\nimport ErrorWrapper from '../ErrorWrapper';\n\nimport styles from './styles.module.scss';\n\nexport interface VisualRadioGroupProps {\n /** Items in the group. Should be VisualRadioGroup.VisualRadio elements. */\n children?: React.ReactNode;\n /** Name shared by all child VisualRadio elements (overridable per child). Auto-generated if omitted. */\n name?: string;\n /** Selected value (controlled). */\n value?: string;\n /** Initial selected value (uncontrolled). */\n defaultValue?: string;\n /** Called when the selected value changes. */\n onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: string) => void;\n /** Variant applied to all child VisualRadio elements (overridable per child). */\n variant?: VisualRadioVariant;\n /** When set and the number of VisualRadio children exceeds this limit on the mobile breakpoint, the variant is forced to `line`. */\n mobileLineVariantLimit?: number;\n /** Error message shown above the group */\n error?: string;\n /** Error text id (auto-generated if omitted) */\n errorTextId?: string;\n /** Renders the error component (Default: true) */\n renderError?: boolean;\n /** Ref passed to the error message element */\n errorMessageRef?: React.Ref<HTMLDivElement | null>;\n /** Adds custom classes to the root element. */\n className?: string;\n /** Adds custom classes to the errorWrapper */\n errorWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the data-testid attribute for the error wrapper */\n errorWrapperTestId?: string;\n}\n\ninterface VisualRadioGroupComponent extends React.FC<VisualRadioGroupProps> {\n VisualRadio: typeof VisualRadio;\n}\n\nexport const VisualRadioGroup: VisualRadioGroupComponent = props => {\n const {\n children,\n name: nameProp,\n value,\n defaultValue,\n onChange,\n variant = 'rectangle',\n mobileLineVariantLimit,\n error,\n errorTextId: errorTextIdProp,\n renderError = true,\n errorMessageRef,\n className,\n errorWrapperClassName,\n testId,\n errorWrapperTestId,\n } = props;\n\n const errorTextId = useIdWithFallback(errorTextIdProp);\n const name = useIdWithFallback(nameProp);\n const isMobile = useIsMobileBreakpoint();\n\n const childArray = React.Children.toArray(children);\n const radioChildren = childArray.filter((child): child is React.ReactElement<VisualRadioProps> =>\n isComponent<VisualRadioProps>(child, VisualRadio)\n );\n\n const initialSelected =\n value ?? defaultValue ?? radioChildren.find(child => child.props.defaultChecked || child.props.checked)?.props.value?.toString();\n\n const [selectedValue, setSelectedValue] = React.useState<string | undefined>(initialSelected);\n const [prevValue, setPrevValue] = React.useState<string | undefined>(value);\n if (prevValue !== value) {\n setPrevValue(value);\n if (value !== undefined && value !== selectedValue) {\n setSelectedValue(value);\n }\n }\n\n const effectiveVariant: VisualRadioVariant | undefined =\n isMobile && mobileLineVariantLimit !== undefined && radioChildren.length > mobileLineVariantLimit ? 'line' : variant;\n\n const mapChild = (child: React.ReactNode): React.ReactNode => {\n if (isComponent<VisualRadioProps>(child, VisualRadio)) {\n const childValue = child.props.value?.toString();\n const isSelected = selectedValue !== undefined && childValue !== undefined && childValue === selectedValue;\n const childOnChange = child.props.onChange;\n\n return React.cloneElement(child, {\n name: child.props.name ?? name,\n variant: child.props.variant ?? effectiveVariant,\n error: !!error || child.props.error,\n errorTextId: child.props.errorTextId ?? errorTextId,\n checked: isSelected,\n onChange: (e: React.ChangeEvent<HTMLInputElement>): void => {\n if (childValue !== undefined) {\n setSelectedValue(childValue);\n }\n childOnChange?.(e);\n if (childValue !== undefined) {\n onChange?.(e, childValue);\n }\n },\n });\n }\n return child;\n };\n\n return (\n <ErrorWrapper\n className={classNames(errorWrapperClassName, className)}\n errorText={error}\n errorTextId={errorTextId}\n renderError={renderError}\n errorMessageRef={errorMessageRef}\n testId={errorWrapperTestId}\n >\n <div\n className={classNames(styles['visual-radio-group'], {\n [styles['visual-radio-group--variant-line']]: effectiveVariant === 'line',\n })}\n data-testid={testId}\n role={'radiogroup'}\n >\n {React.Children.map(children, mapChild)}\n </div>\n </ErrorWrapper>\n );\n};\n\nVisualRadioGroup.VisualRadio = VisualRadio;\n\nexport default VisualRadioGroup;\n","import VisualRadioGroup from './VisualRadioGroup';\nexport * from './VisualRadioGroup';\nexport default VisualRadioGroup;\n"],"mappings":";;;;;;;;;;AAmDA,IAAa,oBAA8C,UAAS;CAClE,MAAM,EACJ,UACA,MAAM,UACN,OACA,cACA,UACA,UAAU,aACV,wBACA,OACA,aAAa,iBACb,cAAc,MACd,iBACA,WACA,uBACA,QACA,uBACE;CAEJ,MAAM,cAAc,kBAAkB,eAAe;CACrD,MAAM,OAAO,kBAAkB,QAAQ;CACvC,MAAM,WAAW,sBAAsB;CAGvC,MAAM,gBADa,MAAM,SAAS,QAAQ,QACpB,EAAW,QAAQ,UACvC,YAA8B,OAAO,WAAW,CAClD;CAEA,MAAM,kBACJ,SAAS,gBAAgB,cAAc,MAAK,UAAS,MAAM,MAAM,kBAAkB,MAAM,MAAM,OAAO,GAAG,MAAM,OAAO,SAAS;CAEjI,MAAM,CAAC,eAAe,oBAAoB,MAAM,SAA6B,eAAe;CAC5F,MAAM,CAAC,WAAW,gBAAgB,MAAM,SAA6B,KAAK;CAC1E,IAAI,cAAc,OAAO;EACvB,aAAa,KAAK;EAClB,IAAI,UAAU,KAAA,KAAa,UAAU,eACnC,iBAAiB,KAAK;CAE1B;CAEA,MAAM,mBACJ,YAAY,2BAA2B,KAAA,KAAa,cAAc,SAAS,yBAAyB,SAAS;CAE/G,MAAM,YAAY,UAA4C;EAC5D,IAAI,YAA8B,OAAO,WAAW,GAAG;GACrD,MAAM,aAAa,MAAM,MAAM,OAAO,SAAS;GAC/C,MAAM,aAAa,kBAAkB,KAAA,KAAa,eAAe,KAAA,KAAa,eAAe;GAC7F,MAAM,gBAAgB,MAAM,MAAM;GAElC,OAAO,MAAM,aAAa,OAAO;IAC/B,MAAM,MAAM,MAAM,QAAQ;IAC1B,SAAS,MAAM,MAAM,WAAW;IAChC,OAAO,CAAC,CAAC,SAAS,MAAM,MAAM;IAC9B,aAAa,MAAM,MAAM,eAAe;IACxC,SAAS;IACT,WAAW,MAAiD;KAC1D,IAAI,eAAe,KAAA,GACjB,iBAAiB,UAAU;KAE7B,gBAAgB,CAAC;KACjB,IAAI,eAAe,KAAA,GACjB,WAAW,GAAG,UAAU;IAE5B;GACF,CAAC;EACH;EACA,OAAO;CACT;CAEA,OACE,oBAAC,sBAAD;EACE,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/VisualRadioGroup/VisualRadioGroup.tsx","../../../src/components/VisualRadioGroup/index.ts"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport type { VisualRadioProps, VisualRadioVariant } from './VisualRadio/VisualRadio';\n\nimport VisualRadio from './VisualRadio/VisualRadio';\nimport { useIdWithFallback } from '../../hooks/useIdWithFallback';\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { isComponent } from '../../utils/component';\nimport ErrorWrapper from '../ErrorWrapper';\n\nimport styles from './styles.module.scss';\n\nexport interface VisualRadioGroupProps {\n /** Items in the group. Should be VisualRadioGroup.VisualRadio elements. */\n children?: React.ReactNode;\n /** Name shared by all child VisualRadio elements (overridable per child). Auto-generated if omitted. */\n name?: string;\n /** Selected value (controlled). */\n value?: string;\n /** Initial selected value (uncontrolled). */\n defaultValue?: string;\n /** Called when the selected value changes. */\n onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: string) => void;\n /** Variant applied to all child VisualRadio elements (overridable per child). */\n variant?: VisualRadioVariant;\n /** When set and the number of VisualRadio children exceeds this limit on the mobile breakpoint, the variant is forced to `line`. */\n mobileLineVariantLimit?: number;\n /** Error message shown above the group */\n error?: string;\n /** Error text id (auto-generated if omitted) */\n errorTextId?: string;\n /** Renders the error component (Default: true) */\n renderError?: boolean;\n /** Ref passed to the error message element */\n errorMessageRef?: React.Ref<HTMLDivElement | null>;\n /** Adds custom classes to the root element. */\n className?: string;\n /** Adds custom classes to the errorWrapper */\n errorWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets the data-testid attribute for the error wrapper */\n errorWrapperTestId?: string;\n}\n\ninterface VisualRadioGroupComponent extends React.FC<VisualRadioGroupProps> {\n VisualRadio: typeof VisualRadio;\n}\n\nexport const VisualRadioGroup: VisualRadioGroupComponent = props => {\n const {\n children,\n name: nameProp,\n value,\n defaultValue,\n onChange,\n variant = 'rectangle',\n mobileLineVariantLimit,\n error,\n errorTextId: errorTextIdProp,\n renderError = true,\n errorMessageRef,\n className,\n errorWrapperClassName,\n testId,\n errorWrapperTestId,\n } = props;\n\n const errorTextId = useIdWithFallback(errorTextIdProp);\n const name = useIdWithFallback(nameProp);\n const isMobile = useIsMobileBreakpoint();\n\n const childArray = React.Children.toArray(children);\n const radioChildren = childArray.filter((child): child is React.ReactElement<VisualRadioProps> =>\n isComponent<VisualRadioProps>(child, VisualRadio)\n );\n\n const initialSelected =\n value ?? defaultValue ?? radioChildren.find(child => child.props.defaultChecked || child.props.checked)?.props.value?.toString();\n\n const [selectedValue, setSelectedValue] = React.useState<string | undefined>(initialSelected);\n const [prevValue, setPrevValue] = React.useState<string | undefined>(value);\n if (prevValue !== value) {\n setPrevValue(value);\n if (value !== undefined && value !== selectedValue) {\n setSelectedValue(value);\n }\n }\n\n const effectiveVariant: VisualRadioVariant | undefined =\n isMobile && mobileLineVariantLimit !== undefined && radioChildren.length > mobileLineVariantLimit ? 'line' : variant;\n\n const mapChild = (child: React.ReactNode): React.ReactNode => {\n if (isComponent<VisualRadioProps>(child, VisualRadio)) {\n const childValue = child.props.value?.toString();\n const isSelected = selectedValue !== undefined && childValue !== undefined && childValue === selectedValue;\n const childOnChange = child.props.onChange;\n\n return React.cloneElement(child, {\n name: child.props.name ?? name,\n variant: child.props.variant ?? effectiveVariant,\n error: !!error || child.props.error,\n errorTextId: child.props.errorTextId ?? errorTextId,\n checked: isSelected,\n onChange: (e: React.ChangeEvent<HTMLInputElement>): void => {\n if (childValue !== undefined) {\n setSelectedValue(childValue);\n }\n childOnChange?.(e);\n if (childValue !== undefined) {\n onChange?.(e, childValue);\n }\n },\n });\n }\n return child;\n };\n\n return (\n <ErrorWrapper\n className={classNames(errorWrapperClassName, className)}\n errorText={error}\n errorTextId={errorTextId}\n renderError={renderError}\n errorMessageRef={errorMessageRef}\n testId={errorWrapperTestId}\n >\n <div\n className={classNames(styles['visual-radio-group'], {\n [styles['visual-radio-group--variant-line']]: effectiveVariant === 'line',\n })}\n data-testid={testId}\n role={'radiogroup'}\n >\n {React.Children.map(children, mapChild)}\n </div>\n </ErrorWrapper>\n );\n};\n\nVisualRadioGroup.VisualRadio = VisualRadio;\n\nexport default VisualRadioGroup;\n","import VisualRadioGroup from './VisualRadioGroup';\nexport * from './VisualRadioGroup';\nexport default VisualRadioGroup;\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,eAAe,KAAA,GACjB,WAAW,GAAG,UAAU;IAE5B;GACF,CAAC;EACH;EACA,OAAO;CACT;CAEA,OACE,oBAAC,sBAAD;EACE,WAAW,GAAW,uBAAuB,SAAS;EACtD,WAAW;EACE;EACA;EACI;EACjB,QAAQ;YAER,oBAAC,OAAD;GACE,WAAW,GAAW,OAAO,uBAAuB,GACjD,OAAO,sCAAsC,qBAAqB,OACrE,CAAC;GACD,eAAa;GACb,MAAM;aAEL,MAAM,SAAS,IAAI,UAAU,QAAQ;EACnC,CAAA;CACO,CAAA;AAElB;AAEA,iBAAiB,cAAc;;;AC5I/B,IAAA,2BAAe"}
|
package/lib/getFilterChips.js
CHANGED
|
@@ -11,7 +11,7 @@ function getFilterChips({ filter, getLabel, onChipClick, onChipRemove, onOverflo
|
|
|
11
11
|
});
|
|
12
12
|
const visibleChips = allChips.slice(0, maxVisible);
|
|
13
13
|
const overflowCount = allChips.length - maxVisible;
|
|
14
|
-
return [visibleChips.map(({ key, value: v }) => /* @__PURE__ */ jsx(Chip_default, {
|
|
14
|
+
return [...visibleChips.map(({ key, value: v }) => /* @__PURE__ */ jsx(Chip_default, {
|
|
15
15
|
onChipClick: () => onChipClick(key, v),
|
|
16
16
|
onCloseClick: () => {
|
|
17
17
|
if (onChipRemove) onChipRemove(key, v);
|
|
@@ -19,11 +19,11 @@ function getFilterChips({ filter, getLabel, onChipClick, onChipRemove, onOverflo
|
|
|
19
19
|
},
|
|
20
20
|
withCloseButton: willShowCloseButton?.(key, v),
|
|
21
21
|
children: getLabel(key, v)
|
|
22
|
-
}, `${key}-${v}`)), overflowCount > 0
|
|
22
|
+
}, `${key}-${v}`)), ...overflowCount > 0 ? [/* @__PURE__ */ jsx(Chip_default, {
|
|
23
23
|
onChipClick: onOverflowChipClick,
|
|
24
24
|
withCloseButton: false,
|
|
25
25
|
children: `+${overflowCount}`
|
|
26
|
-
}, "overflow")];
|
|
26
|
+
}, "overflow")] : []];
|
|
27
27
|
}
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/components/Filter/getFilterChips/index.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilterChips.js","names":[],"sources":["../src/components/Filter/getFilterChips/getFilterChips.tsx","../src/components/Filter/getFilterChips/index.ts"],"sourcesContent":["import type { FilterValues, UseFilterReturn } from '../useFilter';\n\nimport Chip from '../../Chip';\n\nexport interface GetFilterChipsArgs<T extends FilterValues> {\n /** The filter instance from useFilter */\n filter: UseFilterReturn<T>;\n /** Look up the display label for a filter key + value */\n getLabel: (key: keyof T, value: unknown) => string;\n /** Called when a chip is clicked (f.ex. to open the drawer at that filter category) */\n onChipClick: (key: keyof T, value: unknown) => void;\n /** Called when a chip's close button is clicked. If not provided, defaults to filter.removeFilter */\n onChipRemove?: (key: keyof T, value: unknown) => void;\n /** Called when the overflow chip is clicked */\n onOverflowChipClick: () => void;\n /** Function for mapping if close button is shown on chip or not */\n willShowCloseButton?: (key: keyof T, value?: unknown) => boolean;\n}\n\nfunction getFilterChips<T extends FilterValues>({\n filter,\n getLabel,\n onChipClick,\n onChipRemove,\n onOverflowChipClick,\n willShowCloseButton,\n}: GetFilterChipsArgs<T>): React.ReactNode[] {\n const maxVisible = 5;\n\n const allChips = Object.entries(filter.filters).flatMap(([key, raw]) => {\n const values = [raw ?? []].flat();\n return values.map(v => ({ key, value: v }));\n });\n\n const visibleChips = allChips.slice(0, maxVisible);\n const overflowCount = allChips.length - maxVisible;\n\n return [\n visibleChips.map(({ key, value: v }) => (\n <Chip\n key={`${key}-${v}`}\n onChipClick={() => onChipClick(key as keyof T, v)}\n onCloseClick={() => {\n if (onChipRemove) {\n onChipRemove(key as keyof T, v);\n } else {\n filter.removeFilter(key, v);\n }\n }}\n withCloseButton={willShowCloseButton?.(key, v)}\n >\n {getLabel(key as keyof T, v)}\n </Chip>\n )),\n overflowCount > 0
|
|
1
|
+
{"version":3,"file":"getFilterChips.js","names":[],"sources":["../src/components/Filter/getFilterChips/getFilterChips.tsx","../src/components/Filter/getFilterChips/index.ts"],"sourcesContent":["import type { FilterValues, UseFilterReturn } from '../useFilter';\n\nimport Chip from '../../Chip';\n\nexport interface GetFilterChipsArgs<T extends FilterValues> {\n /** The filter instance from useFilter */\n filter: UseFilterReturn<T>;\n /** Look up the display label for a filter key + value */\n getLabel: (key: keyof T, value: unknown) => string;\n /** Called when a chip is clicked (f.ex. to open the drawer at that filter category) */\n onChipClick: (key: keyof T, value: unknown) => void;\n /** Called when a chip's close button is clicked. If not provided, defaults to filter.removeFilter */\n onChipRemove?: (key: keyof T, value: unknown) => void;\n /** Called when the overflow chip is clicked */\n onOverflowChipClick: () => void;\n /** Function for mapping if close button is shown on chip or not */\n willShowCloseButton?: (key: keyof T, value?: unknown) => boolean;\n}\n\nfunction getFilterChips<T extends FilterValues>({\n filter,\n getLabel,\n onChipClick,\n onChipRemove,\n onOverflowChipClick,\n willShowCloseButton,\n}: GetFilterChipsArgs<T>): React.ReactNode[] {\n const maxVisible = 5;\n\n const allChips = Object.entries(filter.filters).flatMap(([key, raw]) => {\n const values = [raw ?? []].flat();\n return values.map(v => ({ key, value: v }));\n });\n\n const visibleChips = allChips.slice(0, maxVisible);\n const overflowCount = allChips.length - maxVisible;\n\n return [\n ...visibleChips.map(({ key, value: v }) => (\n <Chip\n key={`${key}-${v}`}\n onChipClick={() => onChipClick(key as keyof T, v)}\n onCloseClick={() => {\n if (onChipRemove) {\n onChipRemove(key as keyof T, v);\n } else {\n filter.removeFilter(key, v);\n }\n }}\n withCloseButton={willShowCloseButton?.(key, v)}\n >\n {getLabel(key as keyof T, v)}\n </Chip>\n )),\n ...(overflowCount > 0\n ? [<Chip key=\"overflow\" onChipClick={onOverflowChipClick} withCloseButton={false}>{`+${overflowCount}`}</Chip>]\n : []),\n ];\n}\n\nexport default getFilterChips;\n","import getFilterChips from './getFilterChips';\nexport * from './getFilterChips';\nexport default getFilterChips;\n"],"mappings":";;;AAmBA,SAAS,eAAuC,EAC9C,QACA,UACA,aACA,cACA,qBACA,uBAC2C;CAC3C,MAAM,aAAa;CAEnB,MAAM,WAAW,OAAO,QAAQ,OAAO,OAAO,EAAE,SAAS,CAAC,KAAK,SAAS;EAEtE,OADe,CAAC,OAAO,CAAC,CAAC,EAAE,KACpB,EAAO,KAAI,OAAM;GAAE;GAAK,OAAO;EAAE,EAAE;CAC5C,CAAC;CAED,MAAM,eAAe,SAAS,MAAM,GAAG,UAAU;CACjD,MAAM,gBAAgB,SAAS,SAAS;CAExC,OAAO,CACL,GAAG,aAAa,KAAK,EAAE,KAAK,OAAO,QACjC,oBAAC,cAAD;EAEE,mBAAmB,YAAY,KAAgB,CAAC;EAChD,oBAAoB;GAClB,IAAI,cACF,aAAa,KAAgB,CAAC;QAE9B,OAAO,aAAa,KAAK,CAAC;EAE9B;EACA,iBAAiB,sBAAsB,KAAK,CAAC;YAE5C,SAAS,KAAgB,CAAC;CACvB,GAZC,GAAG,IAAI,GAAG,GAYX,CACP,GACD,GAAI,gBAAgB,IAChB,CAAC,oBAAC,cAAD;EAAqB,aAAa;EAAqB,iBAAiB;YAAQ,IAAI;CAAsB,GAAhG,UAAgG,CAAC,IAC5G,CAAC,CACP;AACF;;;ACxDA,IAAA,yBAAe"}
|
package/lib/utils2.js
CHANGED
|
@@ -3,7 +3,7 @@ import { isComponent } from "./utils/component.js";
|
|
|
3
3
|
import { t as Spacer_default } from "./Spacer.js";
|
|
4
4
|
import { t as FormFieldTag_default } from "./FormFieldTag.js";
|
|
5
5
|
import { t as StatusDot_default } from "./StatusDot.js";
|
|
6
|
-
import
|
|
6
|
+
import cn from "classnames";
|
|
7
7
|
import React from "react";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
import styles from "./components/Label/styles.module.scss";
|
|
@@ -11,7 +11,7 @@ import styles from "./components/Label/styles.module.scss";
|
|
|
11
11
|
var Sublabel = ({ children, className, id, onColor, sublabelTexts, testId }) => {
|
|
12
12
|
const mapSublabels = (hideFromScreenReader) => {
|
|
13
13
|
return sublabelTexts && sublabelTexts.map((sublabelText, index) => {
|
|
14
|
-
const labelClasses =
|
|
14
|
+
const labelClasses = cn(styles.label, styles["sublabel"], {
|
|
15
15
|
[styles["sublabel--subdued"]]: sublabelText.type === "subdued",
|
|
16
16
|
[styles["sublabel--on-dark"]]: onColor === FormOnColor.ondark
|
|
17
17
|
});
|
|
@@ -43,13 +43,13 @@ var Sublabel = ({ children, className, id, onColor, sublabelTexts, testId }) =>
|
|
|
43
43
|
//#region src/components/Label/Label.tsx
|
|
44
44
|
var Label = ({ afterLabelChildren, children, className, formFieldTag, htmlFor, htmlMarkup = "label", labelClassName, labelTextClassName, labelId, labelTexts, onColor = FormOnColor.onwhite, statusDot, sublabel, sublabelWrapperClassName, testId, afterLabelChildrenClassName }) => {
|
|
45
45
|
const hasChildren = children && typeof children !== "undefined";
|
|
46
|
-
const labelWrapperClasses =
|
|
47
|
-
const mainLabelWrapperClasses =
|
|
48
|
-
const afterLabelChildrenClasses =
|
|
46
|
+
const labelWrapperClasses = cn(styles["label-wrapper"], { [styles["label-wrapper--no-bottom-margin"]]: hasChildren }, className);
|
|
47
|
+
const mainLabelWrapperClasses = cn({ [styles["label-wrapper--after-label-children"]]: afterLabelChildren });
|
|
48
|
+
const afterLabelChildrenClasses = cn(styles["after-label-children"], afterLabelChildrenClassName);
|
|
49
49
|
const mapLabels = () => {
|
|
50
50
|
if (typeof labelTexts === "undefined") return null;
|
|
51
51
|
return labelTexts.map((labelText, index) => {
|
|
52
|
-
const labelClasses =
|
|
52
|
+
const labelClasses = cn(styles.label, {
|
|
53
53
|
[styles["label--subdued"]]: labelText.type === "subdued",
|
|
54
54
|
[styles["label--on-dark"]]: onColor === FormOnColor.ondark
|
|
55
55
|
}, labelTextClassName);
|
|
@@ -121,7 +121,7 @@ var renderLabelAsParent = (props) => {
|
|
|
121
121
|
htmlFor: props.inputId,
|
|
122
122
|
onColor: props.onColor,
|
|
123
123
|
children: props.children,
|
|
124
|
-
labelClassName:
|
|
124
|
+
labelClassName: cn(props.labelClassName, props.label.props.labelClassName),
|
|
125
125
|
labelTextClassName: props.labelTextClassName,
|
|
126
126
|
htmlMarkup: props.markup || "label",
|
|
127
127
|
sublabelWrapperClassName: props.sublabelWrapperClassName,
|
package/lib/utils2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils2.js","names":[],"sources":["../src/components/Label/SubLabel.tsx","../src/components/Label/Label.tsx","../src/components/Label/utils.tsx"],"sourcesContent":["import cn from 'classnames';\n\nimport type { LabelText } from './Label';\n\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport Spacer from '../Spacer';\n\nimport styles from './styles.module.scss';\n\nexport interface SublabelProps {\n /** Sets the content of the Sublabel */\n children?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** id that is placed on the wrapper */\n id: string;\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: FormOnColor;\n /** Array of sublabel strings. Can be of type semibold or normal */\n sublabelTexts?: LabelText[];\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Sublabel: React.FC<SublabelProps> = ({ children, className, id, onColor, sublabelTexts, testId }) => {\n const mapSublabels = (hideFromScreenReader?: boolean): React.ReactNode => {\n return (\n sublabelTexts &&\n sublabelTexts.map((sublabelText, index) => {\n const labelClasses = cn(styles.label, styles['sublabel'], {\n [styles['sublabel--subdued']]: sublabelText.type === 'subdued',\n [styles['sublabel--on-dark']]: onColor === FormOnColor.ondark,\n });\n return (\n hideFromScreenReader === sublabelText.hideFromScreenReader && (\n <span className={labelClasses} key={index}>\n {sublabelText.text}\n </span>\n )\n );\n })\n );\n };\n\n const subLabels = mapSublabels();\n const ariaHiddenSublabels = mapSublabels(true);\n\n return (\n <>\n <Spacer size={'3xs'} />\n {(subLabels || children) && (\n <div className={className} id={id} data-testid={testId} data-analyticsid={AnalyticsId.Sublabel}>\n {subLabels}\n {children}\n </div>\n )}\n {ariaHiddenSublabels && (\n <div className={className} data-testid={testId}>\n {ariaHiddenSublabels}\n </div>\n )}\n </>\n );\n};\n","import type { FunctionComponent } from 'react';\nimport React from 'react';\n\nimport cn from 'classnames';\n\nimport type { SublabelProps } from './SubLabel';\nimport type { FormFieldTagProps } from '../FormFieldTag';\nimport type { StatusDotProps } from '../StatusDot';\n\nimport { Sublabel } from './SubLabel';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport { isComponent } from '../../utils/component';\nimport FormFieldTag from '../FormFieldTag';\nimport Spacer from '../Spacer';\nimport StatusDot from '../StatusDot';\n\nimport styles from './styles.module.scss';\n\nexport type LabelText = {\n hideFromScreenReader?: boolean;\n text: string;\n type?: 'normal' | 'subdued';\n};\n\nexport type LabelTags = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'span' | 'label' | 'p' | 'legend';\n\nexport interface LabelProps {\n /** Component shown after label - discourage use of this */\n afterLabelChildren?: React.ReactNode;\n /** Sets the content of the Label */\n children?: React.ReactNode;\n /** Sets a tag that describes whether the form field is required or optional */\n formFieldTag?: React.ReactNode;\n /** Adds custom classes to the label tag. */\n labelClassName?: string;\n /** Adds custom classes to the label text. */\n labelTextClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Id that is put on the \"for\" attribute of the label */\n htmlFor?: string;\n /** Changes the underlying element of the label */\n htmlMarkup?: LabelTags;\n /** Id som plasseres på <label/> */\n labelId?: string;\n /** Array of main label strings. Can be of type semibold or normal */\n labelTexts?: LabelText[];\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: keyof typeof FormOnColor;\n /** StatusDot placed underneath the last sublabel */\n statusDot?: React.ReactNode;\n /** Sublabel component */\n sublabel?: React.ReactNode;\n /** Adds custom classes to the div wrapping the sublabels. */\n sublabelWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Gives a custom classname to the afterLabelChildren wrapper. Used in checkbox and radiobutton */\n afterLabelChildrenClassName?: string;\n}\n\nconst Label: FunctionComponent<LabelProps> = ({\n afterLabelChildren,\n children,\n className,\n formFieldTag,\n htmlFor,\n htmlMarkup = 'label',\n labelClassName,\n labelTextClassName,\n labelId,\n labelTexts,\n onColor = FormOnColor.onwhite,\n statusDot,\n sublabel,\n sublabelWrapperClassName,\n testId,\n afterLabelChildrenClassName,\n}) => {\n const hasChildren = children && typeof children !== 'undefined';\n const labelWrapperClasses = cn(styles['label-wrapper'], { [styles['label-wrapper--no-bottom-margin']]: hasChildren }, className);\n const mainLabelWrapperClasses = cn({\n [styles['label-wrapper--after-label-children']]: afterLabelChildren,\n });\n const afterLabelChildrenClasses = cn(styles['after-label-children'], afterLabelChildrenClassName);\n\n const mapLabels = (): React.ReactNode => {\n if (typeof labelTexts === 'undefined') return null;\n\n return labelTexts.map((labelText, index) => {\n const labelClasses = cn(\n styles.label,\n {\n [styles['label--subdued']]: labelText.type === 'subdued',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n },\n labelTextClassName\n );\n return (\n <span aria-hidden={labelText.hideFromScreenReader} className={labelClasses} key={index}>\n {labelText.text}\n </span>\n );\n });\n };\n const CustomTag = htmlMarkup;\n\n return (\n <div className={labelWrapperClasses}>\n <div className={mainLabelWrapperClasses}>\n <CustomTag className={labelClassName} id={labelId} htmlFor={htmlFor} data-testid={testId} data-analyticsid={AnalyticsId.Label}>\n <span className={styles['label-content-wrapper']}>\n {children}\n <span className={styles.label__texts}>{mapLabels()}</span>\n </span>\n </CustomTag>\n {afterLabelChildren && <div className={afterLabelChildrenClasses}>{afterLabelChildren}</div>}\n </div>\n {(sublabel || statusDot || formFieldTag) && (\n <div className={sublabelWrapperClassName}>\n {formFieldTag && isComponent<FormFieldTagProps>(formFieldTag, FormFieldTag) && React.cloneElement(formFieldTag)}\n {sublabel &&\n isComponent<SublabelProps>(sublabel, Sublabel) &&\n React.cloneElement(sublabel, {\n onColor: onColor as FormOnColor,\n })}\n {statusDot && isComponent<StatusDotProps>(statusDot, StatusDot) && (\n <>\n <Spacer size={'3xs'} />\n {React.cloneElement(statusDot, {\n onColor: onColor === FormOnColor.ondark ? 'ondark' : 'onwhite',\n })}\n </>\n )}\n </div>\n )}\n </div>\n );\n};\n\nexport default Label;\n","import React from 'react';\n\nimport cn from 'classnames';\n\nimport type { LabelProps, LabelTags } from './Label';\nimport type { FormOnColor } from '../../constants';\n\nimport Label from './Label';\nimport { isComponent } from '../../utils/component';\n\nexport const getLabelText = (label: React.ReactNode): string => {\n let allLabelText = '';\n\n if (isComponent<LabelProps>(label, Label)) {\n label.props.labelTexts?.forEach(labelText => {\n allLabelText += !labelText.hideFromScreenReader ? labelText.text : '';\n });\n }\n\n return allLabelText;\n};\n\ninterface RenderLabelProps {\n label: React.ReactNode;\n inputId: string;\n onColor: FormOnColor;\n markup?: LabelTags;\n className?: string;\n}\n\nexport const renderLabel = (props: RenderLabelProps): React.ReactNode => {\n return (\n <>\n {props.label && isComponent<LabelProps>(props.label, Label)\n ? React.cloneElement(props.label, {\n htmlFor: props.inputId,\n htmlMarkup: props.markup || 'label',\n onColor: props.onColor,\n className: props.className,\n })\n : typeof props.label === 'string' && (\n <Label\n labelTexts={[{ text: props.label, type: 'normal' }]}\n htmlFor={props.inputId}\n onColor={props.onColor}\n className={props.className}\n />\n )}\n </>\n );\n};\n\ninterface RenderLabelAsParentProps {\n label: React.ReactNode;\n children: React.ReactNode;\n inputId: string;\n onColor: FormOnColor;\n labelClassName?: string;\n labelTextClassName?: string;\n sublabelWrapperClassName?: string;\n large?: boolean;\n markup?: LabelTags;\n afterLabelChildrenClassName?: string;\n}\n\nexport const renderLabelAsParent = (props: RenderLabelAsParentProps): React.ReactNode => {\n return (\n <>\n {props.label && isComponent<LabelProps>(props.label, Label)\n ? React.cloneElement(props.label, {\n htmlFor: props.inputId,\n onColor: props.onColor,\n children: props.children,\n labelClassName: cn(props.labelClassName, props.label.props.labelClassName),\n labelTextClassName: props.labelTextClassName,\n htmlMarkup: props.markup || 'label',\n sublabelWrapperClassName: props.sublabelWrapperClassName,\n sublabel: props.large ? undefined : props.label.props.sublabel,\n statusDot: props.large ? undefined : props.label.props.statusDot,\n afterLabelChildrenClassName: props.afterLabelChildrenClassName,\n })\n : typeof props.label === 'string' && (\n <Label\n labelTexts={[{ text: props.label, type: 'subdued' }]}\n htmlFor={props.inputId}\n onColor={props.onColor}\n htmlMarkup={props.markup || 'label'}\n labelClassName={props.labelClassName}\n labelTextClassName={props.labelTextClassName}\n sublabelWrapperClassName={props.sublabelWrapperClassName}\n afterLabelChildrenClassName={props.afterLabelChildrenClassName}\n >\n {props.children}\n </Label>\n )}\n </>\n );\n};\n"],"mappings":";;;;;;;;;;AAwBA,IAAa,YAAqC,EAAE,UAAU,WAAW,IAAI,SAAS,eAAe,aAAa;CAChH,MAAM,gBAAgB,yBAAoD;EACxE,OACE,iBACA,cAAc,KAAK,cAAc,UAAU;GACzC,MAAM,eAAe,WAAG,OAAO,OAAO,OAAO,aAAa;KACvD,OAAO,uBAAuB,aAAa,SAAS;KACpD,OAAO,uBAAuB,YAAY,YAAY;GACzD,CAAC;GACD,OACE,yBAAyB,aAAa,wBACpC,oBAAC,QAAD;IAAM,WAAW;cACd,aAAa;GACV,GAF8B,KAE9B;EAGZ,CAAC;CAEL;CAEA,MAAM,YAAY,aAAa;CAC/B,MAAM,sBAAsB,aAAa,IAAI;CAE7C,OACE,qBAAA,UAAA,EAAA,UAAA;EACE,oBAAC,gBAAD,EAAQ,MAAM,MAAQ,CAAA;GACpB,aAAa,aACb,qBAAC,OAAD;GAAgB;GAAe;GAAI,eAAa;GAAQ,oBAAkB,YAAY;aAAtF,CACG,WACA,QACE;;EAEN,uBACC,oBAAC,OAAD;GAAgB;GAAW,eAAa;aACrC;EACE,CAAA;CAEP,EAAA,CAAA;AAEN;;;ACFA,IAAM,SAAwC,EAC5C,oBACA,UACA,WACA,cACA,SACA,aAAa,SACb,gBACA,oBACA,SACA,YACA,UAAU,YAAY,SACtB,WACA,UACA,0BACA,QACA,kCACI;CACJ,MAAM,cAAc,YAAY,OAAO,aAAa;C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Y,MAAM,UAAU;EAC5B,gBAAgB,MAAM;EACtB,oBAAoB,MAAM;EAC1B,0BAA0B,MAAM;EAChC,6BAA6B,MAAM;YAElC,MAAM;CACF,CAAA,EAEb,CAAA;AAEN"}
|
|
1
|
+
{"version":3,"file":"utils2.js","names":[],"sources":["../src/components/Label/SubLabel.tsx","../src/components/Label/Label.tsx","../src/components/Label/utils.tsx"],"sourcesContent":["import cn from 'classnames';\n\nimport type { LabelText } from './Label';\n\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport Spacer from '../Spacer';\n\nimport styles from './styles.module.scss';\n\nexport interface SublabelProps {\n /** Sets the content of the Sublabel */\n children?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** id that is placed on the wrapper */\n id: string;\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: FormOnColor;\n /** Array of sublabel strings. Can be of type semibold or normal */\n sublabelTexts?: LabelText[];\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Sublabel: React.FC<SublabelProps> = ({ children, className, id, onColor, sublabelTexts, testId }) => {\n const mapSublabels = (hideFromScreenReader?: boolean): React.ReactNode => {\n return (\n sublabelTexts &&\n sublabelTexts.map((sublabelText, index) => {\n const labelClasses = cn(styles.label, styles['sublabel'], {\n [styles['sublabel--subdued']]: sublabelText.type === 'subdued',\n [styles['sublabel--on-dark']]: onColor === FormOnColor.ondark,\n });\n return (\n hideFromScreenReader === sublabelText.hideFromScreenReader && (\n <span className={labelClasses} key={index}>\n {sublabelText.text}\n </span>\n )\n );\n })\n );\n };\n\n const subLabels = mapSublabels();\n const ariaHiddenSublabels = mapSublabels(true);\n\n return (\n <>\n <Spacer size={'3xs'} />\n {(subLabels || children) && (\n <div className={className} id={id} data-testid={testId} data-analyticsid={AnalyticsId.Sublabel}>\n {subLabels}\n {children}\n </div>\n )}\n {ariaHiddenSublabels && (\n <div className={className} data-testid={testId}>\n {ariaHiddenSublabels}\n </div>\n )}\n </>\n );\n};\n","import type { FunctionComponent } from 'react';\nimport React from 'react';\n\nimport cn from 'classnames';\n\nimport type { SublabelProps } from './SubLabel';\nimport type { FormFieldTagProps } from '../FormFieldTag';\nimport type { StatusDotProps } from '../StatusDot';\n\nimport { Sublabel } from './SubLabel';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport { isComponent } from '../../utils/component';\nimport FormFieldTag from '../FormFieldTag';\nimport Spacer from '../Spacer';\nimport StatusDot from '../StatusDot';\n\nimport styles from './styles.module.scss';\n\nexport type LabelText = {\n hideFromScreenReader?: boolean;\n text: string;\n type?: 'normal' | 'subdued';\n};\n\nexport type LabelTags = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'span' | 'label' | 'p' | 'legend';\n\nexport interface LabelProps {\n /** Component shown after label - discourage use of this */\n afterLabelChildren?: React.ReactNode;\n /** Sets the content of the Label */\n children?: React.ReactNode;\n /** Sets a tag that describes whether the form field is required or optional */\n formFieldTag?: React.ReactNode;\n /** Adds custom classes to the label tag. */\n labelClassName?: string;\n /** Adds custom classes to the label text. */\n labelTextClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Id that is put on the \"for\" attribute of the label */\n htmlFor?: string;\n /** Changes the underlying element of the label */\n htmlMarkup?: LabelTags;\n /** Id som plasseres på <label/> */\n labelId?: string;\n /** Array of main label strings. Can be of type semibold or normal */\n labelTexts?: LabelText[];\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: keyof typeof FormOnColor;\n /** StatusDot placed underneath the last sublabel */\n statusDot?: React.ReactNode;\n /** Sublabel component */\n sublabel?: React.ReactNode;\n /** Adds custom classes to the div wrapping the sublabels. */\n sublabelWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Gives a custom classname to the afterLabelChildren wrapper. Used in checkbox and radiobutton */\n afterLabelChildrenClassName?: string;\n}\n\nconst Label: FunctionComponent<LabelProps> = ({\n afterLabelChildren,\n children,\n className,\n formFieldTag,\n htmlFor,\n htmlMarkup = 'label',\n labelClassName,\n labelTextClassName,\n labelId,\n labelTexts,\n onColor = FormOnColor.onwhite,\n statusDot,\n sublabel,\n sublabelWrapperClassName,\n testId,\n afterLabelChildrenClassName,\n}) => {\n const hasChildren = children && typeof children !== 'undefined';\n const labelWrapperClasses = cn(styles['label-wrapper'], { [styles['label-wrapper--no-bottom-margin']]: hasChildren }, className);\n const mainLabelWrapperClasses = cn({\n [styles['label-wrapper--after-label-children']]: afterLabelChildren,\n });\n const afterLabelChildrenClasses = cn(styles['after-label-children'], afterLabelChildrenClassName);\n\n const mapLabels = (): React.ReactNode => {\n if (typeof labelTexts === 'undefined') return null;\n\n return labelTexts.map((labelText, index) => {\n const labelClasses = cn(\n styles.label,\n {\n [styles['label--subdued']]: labelText.type === 'subdued',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n },\n labelTextClassName\n );\n return (\n <span aria-hidden={labelText.hideFromScreenReader} className={labelClasses} key={index}>\n {labelText.text}\n </span>\n );\n });\n };\n const CustomTag = htmlMarkup;\n\n return (\n <div className={labelWrapperClasses}>\n <div className={mainLabelWrapperClasses}>\n <CustomTag className={labelClassName} id={labelId} htmlFor={htmlFor} data-testid={testId} data-analyticsid={AnalyticsId.Label}>\n <span className={styles['label-content-wrapper']}>\n {children}\n <span className={styles.label__texts}>{mapLabels()}</span>\n </span>\n </CustomTag>\n {afterLabelChildren && <div className={afterLabelChildrenClasses}>{afterLabelChildren}</div>}\n </div>\n {(sublabel || statusDot || formFieldTag) && (\n <div className={sublabelWrapperClassName}>\n {formFieldTag && isComponent<FormFieldTagProps>(formFieldTag, FormFieldTag) && React.cloneElement(formFieldTag)}\n {sublabel &&\n isComponent<SublabelProps>(sublabel, Sublabel) &&\n React.cloneElement(sublabel, {\n onColor: onColor as FormOnColor,\n })}\n {statusDot && isComponent<StatusDotProps>(statusDot, StatusDot) && (\n <>\n <Spacer size={'3xs'} />\n {React.cloneElement(statusDot, {\n onColor: onColor === FormOnColor.ondark ? 'ondark' : 'onwhite',\n })}\n </>\n )}\n </div>\n )}\n </div>\n );\n};\n\nexport default Label;\n","import React from 'react';\n\nimport cn from 'classnames';\n\nimport type { LabelProps, LabelTags } from './Label';\nimport type { FormOnColor } from '../../constants';\n\nimport Label from './Label';\nimport { isComponent } from '../../utils/component';\n\nexport const getLabelText = (label: React.ReactNode): string => {\n let allLabelText = '';\n\n if (isComponent<LabelProps>(label, Label)) {\n label.props.labelTexts?.forEach(labelText => {\n allLabelText += !labelText.hideFromScreenReader ? labelText.text : '';\n });\n }\n\n return allLabelText;\n};\n\ninterface RenderLabelProps {\n label: React.ReactNode;\n inputId: string;\n onColor: FormOnColor;\n markup?: LabelTags;\n className?: string;\n}\n\nexport const renderLabel = (props: RenderLabelProps): React.ReactNode => {\n return (\n <>\n {props.label && isComponent<LabelProps>(props.label, Label)\n ? React.cloneElement(props.label, {\n htmlFor: props.inputId,\n htmlMarkup: props.markup || 'label',\n onColor: props.onColor,\n className: props.className,\n })\n : typeof props.label === 'string' && (\n <Label\n labelTexts={[{ text: props.label, type: 'normal' }]}\n htmlFor={props.inputId}\n onColor={props.onColor}\n className={props.className}\n />\n )}\n </>\n );\n};\n\ninterface RenderLabelAsParentProps {\n label: React.ReactNode;\n children: React.ReactNode;\n inputId: string;\n onColor: FormOnColor;\n labelClassName?: string;\n labelTextClassName?: string;\n sublabelWrapperClassName?: string;\n large?: boolean;\n markup?: LabelTags;\n afterLabelChildrenClassName?: string;\n}\n\nexport const renderLabelAsParent = (props: RenderLabelAsParentProps): React.ReactNode => {\n return (\n <>\n {props.label && isComponent<LabelProps>(props.label, Label)\n ? React.cloneElement(props.label, {\n htmlFor: props.inputId,\n onColor: props.onColor,\n children: props.children,\n labelClassName: cn(props.labelClassName, props.label.props.labelClassName),\n labelTextClassName: props.labelTextClassName,\n htmlMarkup: props.markup || 'label',\n sublabelWrapperClassName: props.sublabelWrapperClassName,\n sublabel: props.large ? undefined : props.label.props.sublabel,\n statusDot: props.large ? undefined : props.label.props.statusDot,\n afterLabelChildrenClassName: props.afterLabelChildrenClassName,\n })\n : typeof props.label === 'string' && (\n <Label\n labelTexts={[{ text: props.label, type: 'subdued' }]}\n htmlFor={props.inputId}\n onColor={props.onColor}\n htmlMarkup={props.markup || 'label'}\n labelClassName={props.labelClassName}\n labelTextClassName={props.labelTextClassName}\n sublabelWrapperClassName={props.sublabelWrapperClassName}\n afterLabelChildrenClassName={props.afterLabelChildrenClassName}\n >\n {props.children}\n </Label>\n )}\n </>\n );\n};\n"],"mappings":";;;;;;;;;;AAwBA,IAAa,YAAqC,EAAE,UAAU,WAAW,IAAI,SAAS,eAAe,aAAa;CAChH,MAAM,gBAAgB,yBAAoD;EACxE,OACE,iBACA,cAAc,KAAK,cAAc,UAAU;GACzC,MAAM,eAAe,GAAG,OAAO,OAAO,OAAO,aAAa;KACvD,OAAO,uBAAuB,aAAa,SAAS;KACpD,OAAO,uBAAuB,YAAY,YAAY;GACzD,CAAC;GACD,OACE,yBAAyB,aAAa,wBACpC,oBAAC,QAAD;IAAM,WAAW;cACd,aAAa;GACV,GAF8B,KAE9B;EAGZ,CAAC;CAEL;CAEA,MAAM,YAAY,aAAa;CAC/B,MAAM,sBAAsB,aAAa,IAAI;CAE7C,OACE,qBAAA,UAAA,EAAA,UAAA;EACE,oBAAC,gBAAD,EAAQ,MAAM,MAAQ,CAAA;GACpB,aAAa,aACb,qBAAC,OAAD;GAAgB;GAAe;GAAI,eAAa;GAAQ,oBAAkB,YAAY;aAAtF,CACG,WACA,QACE;;EAEN,uBACC,oBAAC,OAAD;GAAgB;GAAW,eAAa;aACrC;EACE,CAAA;CAEP,EAAA,CAAA;AAEN;;;ACFA,IAAM,SAAwC,EAC5C,oBACA,UACA,WACA,cACA,SACA,aAAa,SACb,gBACA,oBACA,SACA,YACA,UAAU,YAAY,SACtB,WACA,UACA,0BACA,QACA,kCACI;CACJ,MAAM,cAAc,YAAY,OAAO,aAAa;CACpD,MAAM,sBAAsB,GAAG,OAAO,kBAAkB,GAAG,OAAO,qCAAq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