@pega/cosmos-react-core 9.0.0-build.6.9 → 9.0.0-build.7.1
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/FieldGroup/FieldGroup.d.ts +5 -0
- package/lib/components/FieldGroup/FieldGroup.d.ts.map +1 -1
- package/lib/components/FieldGroup/FieldGroup.js +10 -6
- package/lib/components/FieldGroup/FieldGroup.js.map +1 -1
- package/lib/components/FieldGroup/FieldGroupList.d.ts +17 -2
- package/lib/components/FieldGroup/FieldGroupList.d.ts.map +1 -1
- package/lib/components/FieldGroup/FieldGroupList.js +200 -50
- package/lib/components/FieldGroup/FieldGroupList.js.map +1 -1
- package/lib/components/FieldGroup/FieldGroupList.utils.d.ts +33 -0
- package/lib/components/FieldGroup/FieldGroupList.utils.d.ts.map +1 -0
- package/lib/components/FieldGroup/FieldGroupList.utils.js +74 -0
- package/lib/components/FieldGroup/FieldGroupList.utils.js.map +1 -0
- package/lib/components/FieldGroup/FieldGroupListContext.d.ts +8 -0
- package/lib/components/FieldGroup/FieldGroupListContext.d.ts.map +1 -0
- package/lib/components/FieldGroup/FieldGroupListContext.js +9 -0
- package/lib/components/FieldGroup/FieldGroupListContext.js.map +1 -0
- package/lib/components/FieldGroup/index.d.ts +2 -0
- package/lib/components/FieldGroup/index.d.ts.map +1 -1
- package/lib/components/FieldGroup/index.js +2 -0
- package/lib/components/FieldGroup/index.js.map +1 -1
- package/lib/components/FieldValueList/FieldValueList.d.ts.map +1 -1
- package/lib/components/FieldValueList/FieldValueList.js +3 -3
- package/lib/components/FieldValueList/FieldValueList.js.map +1 -1
- package/lib/components/Form/Form.d.ts +2 -0
- package/lib/components/Form/Form.d.ts.map +1 -1
- package/lib/components/Form/Form.js +2 -2
- package/lib/components/Form/Form.js.map +1 -1
- package/lib/components/Icon/streamline-icons/lock-closed.icon.d.ts +5 -0
- package/lib/components/Icon/streamline-icons/lock-closed.icon.d.ts.map +1 -0
- package/lib/components/Icon/streamline-icons/lock-closed.icon.js +7 -0
- package/lib/components/Icon/streamline-icons/lock-closed.icon.js.map +1 -0
- package/lib/components/Icon/streamlineIconNames.d.ts +1 -1
- package/lib/components/Icon/streamlineIconNames.d.ts.map +1 -1
- package/lib/components/Icon/streamlineIconNames.js +1 -0
- package/lib/components/Icon/streamlineIconNames.js.map +1 -1
- package/lib/components/Lightbox/Lightbox.d.ts +1 -1
- package/lib/components/Lightbox/Lightbox.d.ts.map +1 -1
- package/lib/components/Lightbox/Lightbox.js +9 -3
- package/lib/components/Lightbox/Lightbox.js.map +1 -1
- package/lib/components/Lightbox/Lightbox.test-ids.d.ts +1 -1
- package/lib/components/Lightbox/Lightbox.test-ids.d.ts.map +1 -1
- package/lib/components/Lightbox/Lightbox.test-ids.js +1 -0
- package/lib/components/Lightbox/Lightbox.test-ids.js.map +1 -1
- package/lib/components/MultiStepForm/MultiStepForm.d.ts.map +1 -1
- package/lib/components/MultiStepForm/MultiStepForm.js +29 -3
- package/lib/components/MultiStepForm/MultiStepForm.js.map +1 -1
- package/lib/components/Popover/Popover.styles.d.ts.map +1 -1
- package/lib/components/Popover/Popover.styles.js +2 -2
- package/lib/components/Popover/Popover.styles.js.map +1 -1
- package/lib/hooks/useAnimatedText.d.ts.map +1 -1
- package/lib/hooks/useAnimatedText.js +5 -2
- package/lib/hooks/useAnimatedText.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +7 -0
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/hooks/useItemIntersection.d.ts.map +1 -1
- package/lib/hooks/useItemIntersection.js +3 -1
- package/lib/hooks/useItemIntersection.js.map +1 -1
- package/lib/i18n/default.d.ts +7 -0
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +9 -1
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +7 -0
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/lib/theme/theme.d.ts +12 -0
- package/lib/theme/theme.d.ts.map +1 -1
- package/lib/theme/themeDefinition.json +6 -0
- package/lib/theme/themeOverrides.schema.json +9 -0
- package/lib/theme/themes/studioDarkTheme.json +3 -0
- package/lib/utils/focusNonInteractiveElement.d.ts +9 -0
- package/lib/utils/focusNonInteractiveElement.d.ts.map +1 -0
- package/lib/utils/focusNonInteractiveElement.js +27 -0
- package/lib/utils/focusNonInteractiveElement.js.map +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +1 -0
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -14,6 +14,8 @@ export type FieldGroupProps = BaseProps & {
|
|
|
14
14
|
} & ({
|
|
15
15
|
/** The name associated with the Field Group. */
|
|
16
16
|
name: string;
|
|
17
|
+
/** Provides a contextual label for the name. */
|
|
18
|
+
contextualLabel?: string;
|
|
17
19
|
/** Select the heading tag for header */
|
|
18
20
|
headingTag?: HeadingTag;
|
|
19
21
|
/** Provides additional info relevant to the field group. */
|
|
@@ -35,6 +37,7 @@ export type FieldGroupProps = BaseProps & {
|
|
|
35
37
|
onToggleCollapsed?: () => void;
|
|
36
38
|
} | {
|
|
37
39
|
name?: undefined;
|
|
40
|
+
contextualLabel?: never;
|
|
38
41
|
headingTag?: never;
|
|
39
42
|
additionalInfo?: never;
|
|
40
43
|
actions?: never;
|
|
@@ -42,6 +45,8 @@ export type FieldGroupProps = BaseProps & {
|
|
|
42
45
|
onToggleCollapsed?: never;
|
|
43
46
|
});
|
|
44
47
|
export declare const StyledFieldGroupName: import("styled-components").StyledComponent<"span", import("styled-components").DefaultTheme, {}, never>;
|
|
48
|
+
export declare const StyledFieldHeader: import("styled-components").StyledComponent<ForwardRefForwardPropsComponent<import("../Flex").FlexProps>, import("styled-components").DefaultTheme, {}, never>;
|
|
49
|
+
export declare const StyledFieldGroupContent: import("styled-components").StyledComponent<ForwardRefForwardPropsComponent<import("../Grid").GridProps>, import("styled-components").DefaultTheme, {}, never>;
|
|
45
50
|
export declare const StyledFieldGroupLegend: import("styled-components").StyledComponent<"legend", import("styled-components").DefaultTheme, Pick<FieldGroupProps, "collapsed">, never>;
|
|
46
51
|
export declare const StyledFieldGroup: import("styled-components").StyledComponent<"fieldset", import("styled-components").DefaultTheme, {}, never>;
|
|
47
52
|
export declare const StyledGroupContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldGroup.d.ts","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroup.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAY7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA+B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAK1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAK7D,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG;IACxC,sCAAsC;IACtC,QAAQ,EAAE,SAAS,CAAC;IACpB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,2CAA2C;IAC3C,GAAG,CAAC,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC;CAChC,GAAG,CACE;IACE,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,4DAA4D;IAC5D,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;QACzC,OAAO,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;KAC1C,CAAC;IACF,gDAAgD;IAChD,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAChC;;;;OAIG;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O,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;KAC1C,CAAC;IACF,gDAAgD;IAChD,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAChC;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAC;CAChC,GACD;IACE,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,eAAe,CAAC,EAAE,KAAK,CAAC;IACxB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,cAAc,CAAC,EAAE,KAAK,CAAC;IACvB,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,iBAAiB,CAAC,EAAE,KAAK,CAAC;CAC3B,CACJ,CAAC;AAgCJ,eAAO,MAAM,oBAAoB,0GAAgB,CAAC;AAElD,eAAO,MAAM,iBAAiB,gKAAiB,CAAC;AAEhD,eAAO,MAAM,uBAAuB,gKAAiB,CAAC;AAEtD,eAAO,MAAM,sBAAsB,4IA+BlC,CAAC;AAIF,eAAO,MAAM,gBAAgB,8GAiC5B,CAAC;AAIF,eAAO,MAAM,oBAAoB;gBAA4B,OAAO;aAAW,OAAO;SA+BrF,CAAC;AAiCF,QAAA,MAAM,UAAU,EAAE,+BAA+B,CAAC,eAAe,CAuF/D,CAAC;AAEH,eAAe,UAAU,CAAC"}
|
|
@@ -32,6 +32,8 @@ const StyledExpandButton = styled(Button)(({ theme: { base: { animation } } }) =
|
|
|
32
32
|
});
|
|
33
33
|
StyledExpandButton.defaultProps = defaultThemeProp;
|
|
34
34
|
export const StyledFieldGroupName = styled.span ``;
|
|
35
|
+
export const StyledFieldHeader = styled(Flex) ``;
|
|
36
|
+
export const StyledFieldGroupContent = styled(Grid) ``;
|
|
35
37
|
export const StyledFieldGroupLegend = styled.legend.withConfig(omitProps('collapsed'))(({ collapsed, theme: { base: { spacing, animation, 'hit-area': { 'mouse-min': hitAreaMouse, 'finger-min': hitAreaFinger } } } }) => {
|
|
36
38
|
return css `
|
|
37
39
|
width: 100%;
|
|
@@ -100,16 +102,18 @@ export const StyledGroupContainer = styled.div(({ theme, collapsed, border }) =>
|
|
|
100
102
|
});
|
|
101
103
|
StyledGroupContainer.defaultProps = defaultThemeProp;
|
|
102
104
|
// Components
|
|
103
|
-
const FieldGroupLegend = ({ name, children, collapsed, actions, additionalInfo }) => {
|
|
104
|
-
return (_jsx(StyledFieldGroupLegend, { collapsed: collapsed, children: _jsxs(Flex, { container: { alignItems: 'center', justify: 'between', gap: 0.5 }, children: [_jsxs(Flex, { container: { alignItems: 'center', gap: 0.5 }, children: [children, additionalInfo && (_jsx(AdditionalInfo, { heading: additionalInfo.heading, contextualLabel: name, children: additionalInfo.content }))] }), actions && _jsx(Actions, { items: actions })] }) }));
|
|
105
|
+
const FieldGroupLegend = ({ name, contextualLabel, children, collapsed, actions, additionalInfo }) => {
|
|
106
|
+
return (_jsx(StyledFieldGroupLegend, { collapsed: collapsed, children: _jsxs(Flex, { container: { alignItems: 'center', justify: 'between', gap: 0.5 }, children: [_jsxs(Flex, { container: { alignItems: 'center', gap: 0.5 }, as: StyledFieldHeader, children: [children, additionalInfo && (_jsx(AdditionalInfo, { heading: additionalInfo.heading, contextualLabel: contextualLabel || name, children: additionalInfo.content }))] }), actions && _jsx(Actions, { items: actions, contextualLabel: contextualLabel })] }) }));
|
|
105
107
|
};
|
|
106
|
-
const FieldGroup = forwardRef(function FieldGroup({ children, description, name, additionalInfo, actions, collapsed, headingTag, onToggleCollapsed, variant, ...restProps }, ref) {
|
|
108
|
+
const FieldGroup = forwardRef(function FieldGroup({ children, description, name, contextualLabel, additionalInfo, actions, collapsed, headingTag, onToggleCollapsed, variant, ...restProps }, ref) {
|
|
107
109
|
const t = useI18n();
|
|
108
110
|
const uid = useUID();
|
|
109
|
-
const descAndChildren = (_jsxs(
|
|
110
|
-
return (_jsx(StyledGroupContainer, { border: variant === 'form-group', collapsed: collapsed, children: _jsxs(StyledFieldGroup, { "aria-label": name, "aria-describedby": description ? `${uid}-description` : undefined, as: name ? 'fieldset' : 'div', ...restProps, ref: ref, children: [name && (_jsx(FieldGroupLegend, { collapsed: collapsed, actions: actions, additionalInfo: additionalInfo, name: name, children: typeof collapsed === 'boolean' ? (_jsx(StyledExpandButton, { type: 'button', variant: 'text', onClick: () => {
|
|
111
|
+
const descAndChildren = (_jsxs(StyledFieldGroupContent, { container: { cols: 'minmax(0, 1fr)', gap: 2 }, children: [description && _jsx(HTML, { id: `${uid}-description`, as: 'p', content: description }), _jsx("div", { children: children })] }));
|
|
112
|
+
return (_jsx(StyledGroupContainer, { border: variant === 'form-group', collapsed: collapsed, children: _jsxs(StyledFieldGroup, { "aria-label": contextualLabel || name, "aria-describedby": description ? `${uid}-description` : undefined, as: name ? 'fieldset' : 'div', ...restProps, ref: ref, children: [name && (_jsx(FieldGroupLegend, { collapsed: collapsed, actions: actions, additionalInfo: additionalInfo, name: name, contextualLabel: contextualLabel, children: typeof collapsed === 'boolean' ? (_jsx(StyledExpandButton, { type: 'button', variant: 'text', onClick: () => {
|
|
111
113
|
onToggleCollapsed?.();
|
|
112
|
-
}, "aria-expanded": !collapsed, "aria-label": t(collapsed ? 'expand_noun' : 'collapse_noun', [
|
|
114
|
+
}, "aria-expanded": !collapsed, "aria-label": t(collapsed ? 'expand_noun' : 'collapse_noun', [
|
|
115
|
+
contextualLabel || name
|
|
116
|
+
]), children: _jsxs(Flex, { container: { direction: 'row', alignItems: 'center', gap: 0.5 }, forwardedAs: 'span', children: [_jsx(Icon, { name: 'caret-right' }), headingTag ? (_jsx(Text, { variant: headingTag, children: name })) : (_jsx(StyledFieldGroupName, { children: name }))] }) })) : (_jsx(_Fragment, { children: headingTag ? (_jsx(Text, { variant: headingTag, children: name })) : (_jsx(StyledFieldGroupName, { children: name })) })) })), typeof collapsed === 'boolean' ? (_jsx(ExpandCollapse, { collapsed: collapsed, children: descAndChildren })) : (descAndChildren)] }) }));
|
|
113
117
|
});
|
|
114
118
|
export default FieldGroup;
|
|
115
119
|
//# sourceMappingURL=FieldGroup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldGroup.js","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAG/C,YAAY,CAAC,cAAc,CAAC,CAAC;AAqD7B,SAAS;AACT,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EACzC,KAAK,EAAE,EACL,IAAI,EAAE,EAAE,SAAS,EAAE,EACpB,EACF,EAAE,EAAE;IACH,MAAM,EAAE,GAAG,EAAE,GAAG,YAAY,EAAE,CAAC;IAC/B,OAAO,GAAG,CAAA;MACN,UAAU;8BACc,SAAS,CAAC,KAAK,IAAI,SAAS,CAA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CACJ,GACgB,CACpB,EAEA,OAAO,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,CAChC,KAAC,cAAc,IAAC,SAAS,EAAE,SAAS,YAAG,eAAe,GAAkB,CACzE,CAAC,CAAC,CAAC,CACF,eAAe,CAChB,IACgB,GACE,CACxB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,UAAU,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef, Ref, ReactNode } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Text from '../Text';\nimport Button from '../Button';\nimport ExpandCollapse from '../ExpandCollapse';\nimport Flex from '../Flex';\nimport Grid from '../Grid';\nimport HTML from '../HTML';\nimport Icon, { StyledIcon, registerIcon } from '../Icon';\nimport * as caretRightIcon from '../Icon/icons/caret-right.icon';\nimport Actions from '../Actions';\nimport type { ActionsProps } from '../Actions';\nimport { defaultThemeProp } from '../../theme';\nimport type { BaseProps, ForwardRefForwardPropsComponent, HeadingTag } from '../../types';\nimport { useDirection, useI18n, useUID } from '../../hooks';\nimport { calculateFontSize, omitProps } from '../../styles';\nimport type { FontSize } from '../../styles';\nimport AdditionalInfo from '../AdditionalInfo';\nimport type { AdditionalInfoProps } from '../AdditionalInfo';\n\nregisterIcon(caretRightIcon);\n\n// Types\nexport type FieldGroupProps = BaseProps & {\n /** The content of the Field Group. */\n children: ReactNode;\n /** A description of the field group to be displayed above the controls. */\n description?: string;\n /** The display and markup variant to apply to the group. */\n variant?: 'form-group';\n /** A reference to the wrapping element. */\n ref?: Ref<HTMLFieldSetElement>;\n} & (\n | {\n /** The name associated with the Field Group. */\n name: string;\n /** Select the heading tag for header */\n headingTag?: HeadingTag;\n /** Provides additional info relevant to the field group. */\n additionalInfo?: {\n heading?: AdditionalInfoProps['heading'];\n content: AdditionalInfoProps['children'];\n };\n /** An array of actions to add to the header. */\n actions?: ActionsProps['items'];\n /**\n * Controls the collapsed state of the field group.\n * Passing undefined will render the field group as non-collapsible.\n * @default false\n */\n collapsed?: boolean;\n /**\n * Called when user clicks the toggle button.\n */\n onToggleCollapsed?: () => void;\n }\n | {\n name?: undefined;\n headingTag?: never;\n additionalInfo?: never;\n actions?: never;\n collapsed?: never;\n onToggleCollapsed?: never;\n }\n );\n\ninterface FieldGroupLegendProps extends Pick<FieldGroupProps, 'collapsed'> {\n name: NonNullable<FieldGroupProps['name']>;\n actions?: ActionsProps['items'];\n children?: ReactNode;\n additionalInfo?: FieldGroupProps['additionalInfo'];\n}\n\n// Styles\nconst StyledExpandButton = styled(Button)(({\n theme: {\n base: { animation }\n }\n}) => {\n const { rtl } = useDirection();\n return css`\n ${StyledIcon} {\n transition: transform ${animation.speed} ${animation.timing.ease};\n }\n &[aria-expanded='true'] ${StyledIcon} {\n transform: rotate(90deg);\n }\n &[aria-expanded='false'] ${StyledIcon} {\n transform: rotate(${rtl ? 180 : 0}deg);\n }\n `;\n});\n\nStyledExpandButton.defaultProps = defaultThemeProp;\n\nexport const StyledFieldGroupName = styled.span``;\n\nexport const StyledFieldGroupLegend = styled.legend.withConfig<Pick<FieldGroupProps, 'collapsed'>>(\n omitProps('collapsed')\n)(\n ({\n collapsed,\n theme: {\n base: {\n spacing,\n animation,\n 'hit-area': { 'mouse-min': hitAreaMouse, 'finger-min': hitAreaFinger }\n }\n }\n }) => {\n return css`\n width: 100%;\n margin-bottom: 0;\n ${!collapsed &&\n css`\n margin-block-end: calc(1.5 * ${spacing});\n `}\n transition: margin-block-end ${animation.speed} ${animation.timing.ease};\n\n > ${StyledExpandButton} {\n min-height: ${hitAreaMouse};\n\n @media (pointer: 'coarse') {\n min-height: ${hitAreaFinger};\n }\n }\n `;\n }\n);\n\nStyledFieldGroupLegend.defaultProps = defaultThemeProp;\n\nexport const StyledFieldGroup = styled.fieldset(\n ({\n theme: {\n base: { 'font-size': fontSize, 'font-scale': fontScale },\n components: { text }\n }\n }) => {\n const fontSizes = calculateFontSize(fontSize, fontScale);\n\n return css`\n border: none;\n\n & ${StyledFieldGroupName} {\n font-size: ${fontSizes[text.h3['font-size'] as FontSize]};\n font-weight: ${text.h3['font-weight']};\n }\n\n & & ${StyledFieldGroupName} {\n font-size: ${fontSizes[text.h4['font-size'] as FontSize]};\n font-weight: ${text.h4['font-weight']};\n }\n\n & & & ${StyledFieldGroupName} {\n font-size: ${fontSizes[text.h5['font-size'] as FontSize]};\n font-weight: ${text.h5['font-weight']};\n }\n\n & & & & ${StyledFieldGroupName} {\n font-size: ${fontSizes[text.h6['font-size'] as FontSize]};\n font-weight: ${text.h6['font-weight']};\n }\n `;\n }\n);\n\nStyledFieldGroup.defaultProps = defaultThemeProp;\n\nexport const StyledGroupContainer = styled.div<{ collapsed?: boolean; border?: boolean }>(\n ({ theme, collapsed, border }) => {\n const {\n base: {\n animation: { speed, timing },\n palette: { 'border-line': borderColor },\n spacing,\n 'border-radius': baseBorderRadius\n },\n components: {\n 'form-control': { 'border-width': borderWidth }\n }\n } = theme;\n if (!border) return null;\n\n const showBorder = !collapsed;\n\n return css`\n padding: ${spacing};\n border-radius: calc(${baseBorderRadius} / 2);\n border: ${borderWidth} solid transparent;\n transition-property: border-color;\n transition-duration: ${speed};\n transition-timing-function: ${timing.ease};\n\n ${showBorder &&\n css`\n border-color: ${borderColor};\n `}\n `;\n }\n);\n\nStyledGroupContainer.defaultProps = defaultThemeProp;\n\n// Components\nconst FieldGroupLegend = ({\n name,\n children,\n collapsed,\n actions,\n additionalInfo\n}: FieldGroupLegendProps) => {\n return (\n <StyledFieldGroupLegend collapsed={collapsed}>\n <Flex container={{ alignItems: 'center', justify: 'between', gap: 0.5 }}>\n <Flex container={{ alignItems: 'center', gap: 0.5 }}>\n {children}\n {additionalInfo && (\n <AdditionalInfo heading={additionalInfo.heading} contextualLabel={name}>\n {additionalInfo.content}\n </AdditionalInfo>\n )}\n </Flex>\n {actions && <Actions items={actions} />}\n </Flex>\n </StyledFieldGroupLegend>\n );\n};\n\nconst FieldGroup: ForwardRefForwardPropsComponent<FieldGroupProps> = forwardRef(function FieldGroup(\n {\n children,\n description,\n name,\n additionalInfo,\n actions,\n collapsed,\n headingTag,\n onToggleCollapsed,\n variant,\n ...restProps\n }: PropsWithoutRef<FieldGroupProps>,\n ref: FieldGroupProps['ref']\n) {\n const t = useI18n();\n const uid = useUID();\n\n const descAndChildren = (\n <Grid container={{ cols: 'minmax(0, 1fr)', gap: 2 }}>\n {description && <HTML id={`${uid}-description`} as='p' content={description} />}\n <div>{children}</div>\n </Grid>\n );\n\n return (\n <StyledGroupContainer border={variant === 'form-group'} collapsed={collapsed}>\n <StyledFieldGroup\n aria-label={name}\n aria-describedby={description ? `${uid}-description` : undefined}\n as={name ? 'fieldset' : 'div'}\n {...restProps}\n ref={ref}\n >\n {name && (\n <FieldGroupLegend\n collapsed={collapsed}\n actions={actions}\n additionalInfo={additionalInfo}\n name={name}\n >\n {typeof collapsed === 'boolean' ? (\n <StyledExpandButton\n type='button'\n variant='text'\n onClick={() => {\n onToggleCollapsed?.();\n }}\n aria-expanded={!collapsed}\n aria-label={t(collapsed ? 'expand_noun' : 'collapse_noun', [name])}\n >\n <Flex\n container={{ direction: 'row', alignItems: 'center', gap: 0.5 }}\n forwardedAs='span'\n >\n <Icon name='caret-right' />\n {headingTag ? (\n <Text variant={headingTag}>{name}</Text>\n ) : (\n <StyledFieldGroupName>{name}</StyledFieldGroupName>\n )}\n </Flex>\n </StyledExpandButton>\n ) : (\n <>\n {headingTag ? (\n <Text variant={headingTag}>{name}</Text>\n ) : (\n <StyledFieldGroupName>{name}</StyledFieldGroupName>\n )}\n </>\n )}\n </FieldGroupLegend>\n )}\n\n {typeof collapsed === 'boolean' ? (\n <ExpandCollapse collapsed={collapsed}>{descAndChildren}</ExpandCollapse>\n ) : (\n descAndChildren\n )}\n </StyledFieldGroup>\n </StyledGroupContainer>\n );\n});\n\nexport default FieldGroup;\n"]}
|
|
1
|
+
{"version":3,"file":"FieldGroup.js","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroup.tsx"],"names":[],"mappings":";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,OAAO,EAAE,UAAU,YAAG,IAAI,GAAQ,CACzC,CAAC,CAAC,CAAC,CACF,KAAC,oBAAoB,cAAE,IAAI,GAAwB,CACpD,GACA,CACJ,GACgB,CACpB,EAEA,OAAO,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,CAChC,KAAC,cAAc,IAAC,SAAS,EAAE,SAAS,YAAG,eAAe,GAAkB,CACzE,CAAC,CAAC,CAAC,CACF,eAAe,CAChB,IACgB,GACE,CACxB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,UAAU,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef, Ref, ReactNode } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Text from '../Text';\nimport Button from '../Button';\nimport ExpandCollapse from '../ExpandCollapse';\nimport Flex from '../Flex';\nimport Grid from '../Grid';\nimport HTML from '../HTML';\nimport Icon, { StyledIcon, registerIcon } from '../Icon';\nimport * as caretRightIcon from '../Icon/icons/caret-right.icon';\nimport Actions from '../Actions';\nimport type { ActionsProps } from '../Actions';\nimport { defaultThemeProp } from '../../theme';\nimport type { BaseProps, ForwardRefForwardPropsComponent, HeadingTag } from '../../types';\nimport { useDirection, useI18n, useUID } from '../../hooks';\nimport { calculateFontSize, omitProps } from '../../styles';\nimport type { FontSize } from '../../styles';\nimport AdditionalInfo from '../AdditionalInfo';\nimport type { AdditionalInfoProps } from '../AdditionalInfo';\n\nregisterIcon(caretRightIcon);\n\n// Types\nexport type FieldGroupProps = BaseProps & {\n /** The content of the Field Group. */\n children: ReactNode;\n /** A description of the field group to be displayed above the controls. */\n description?: string;\n /** The display and markup variant to apply to the group. */\n variant?: 'form-group';\n /** A reference to the wrapping element. */\n ref?: Ref<HTMLFieldSetElement>;\n} & (\n | {\n /** The name associated with the Field Group. */\n name: string;\n /** Provides a contextual label for the name. */\n contextualLabel?: string;\n /** Select the heading tag for header */\n headingTag?: HeadingTag;\n /** Provides additional info relevant to the field group. */\n additionalInfo?: {\n heading?: AdditionalInfoProps['heading'];\n content: AdditionalInfoProps['children'];\n };\n /** An array of actions to add to the header. */\n actions?: ActionsProps['items'];\n /**\n * Controls the collapsed state of the field group.\n * Passing undefined will render the field group as non-collapsible.\n * @default false\n */\n collapsed?: boolean;\n /**\n * Called when user clicks the toggle button.\n */\n onToggleCollapsed?: () => void;\n }\n | {\n name?: undefined;\n contextualLabel?: never;\n headingTag?: never;\n additionalInfo?: never;\n actions?: never;\n collapsed?: never;\n onToggleCollapsed?: never;\n }\n );\n\ninterface FieldGroupLegendProps extends Pick<FieldGroupProps, 'collapsed'> {\n name: NonNullable<FieldGroupProps['name']>;\n actions?: ActionsProps['items'];\n children?: ReactNode;\n additionalInfo?: FieldGroupProps['additionalInfo'];\n contextualLabel?: FieldGroupProps['contextualLabel'];\n}\n\n// Styles\nconst StyledExpandButton = styled(Button)(({\n theme: {\n base: { animation }\n }\n}) => {\n const { rtl } = useDirection();\n return css`\n ${StyledIcon} {\n transition: transform ${animation.speed} ${animation.timing.ease};\n }\n &[aria-expanded='true'] ${StyledIcon} {\n transform: rotate(90deg);\n }\n &[aria-expanded='false'] ${StyledIcon} {\n transform: rotate(${rtl ? 180 : 0}deg);\n }\n `;\n});\n\nStyledExpandButton.defaultProps = defaultThemeProp;\n\nexport const StyledFieldGroupName = styled.span``;\n\nexport const StyledFieldHeader = styled(Flex)``;\n\nexport const StyledFieldGroupContent = styled(Grid)``;\n\nexport const StyledFieldGroupLegend = styled.legend.withConfig<Pick<FieldGroupProps, 'collapsed'>>(\n omitProps('collapsed')\n)(\n ({\n collapsed,\n theme: {\n base: {\n spacing,\n animation,\n 'hit-area': { 'mouse-min': hitAreaMouse, 'finger-min': hitAreaFinger }\n }\n }\n }) => {\n return css`\n width: 100%;\n margin-bottom: 0;\n ${!collapsed &&\n css`\n margin-block-end: calc(1.5 * ${spacing});\n `}\n transition: margin-block-end ${animation.speed} ${animation.timing.ease};\n\n > ${StyledExpandButton} {\n min-height: ${hitAreaMouse};\n\n @media (pointer: 'coarse') {\n min-height: ${hitAreaFinger};\n }\n }\n `;\n }\n);\n\nStyledFieldGroupLegend.defaultProps = defaultThemeProp;\n\nexport const StyledFieldGroup = styled.fieldset(\n ({\n theme: {\n base: { 'font-size': fontSize, 'font-scale': fontScale },\n components: { text }\n }\n }) => {\n const fontSizes = calculateFontSize(fontSize, fontScale);\n\n return css`\n border: none;\n\n & ${StyledFieldGroupName} {\n font-size: ${fontSizes[text.h3['font-size'] as FontSize]};\n font-weight: ${text.h3['font-weight']};\n }\n\n & & ${StyledFieldGroupName} {\n font-size: ${fontSizes[text.h4['font-size'] as FontSize]};\n font-weight: ${text.h4['font-weight']};\n }\n\n & & & ${StyledFieldGroupName} {\n font-size: ${fontSizes[text.h5['font-size'] as FontSize]};\n font-weight: ${text.h5['font-weight']};\n }\n\n & & & & ${StyledFieldGroupName} {\n font-size: ${fontSizes[text.h6['font-size'] as FontSize]};\n font-weight: ${text.h6['font-weight']};\n }\n `;\n }\n);\n\nStyledFieldGroup.defaultProps = defaultThemeProp;\n\nexport const StyledGroupContainer = styled.div<{ collapsed?: boolean; border?: boolean }>(\n ({ theme, collapsed, border }) => {\n const {\n base: {\n animation: { speed, timing },\n palette: { 'border-line': borderColor },\n spacing,\n 'border-radius': baseBorderRadius\n },\n components: {\n 'form-control': { 'border-width': borderWidth }\n }\n } = theme;\n if (!border) return null;\n\n const showBorder = !collapsed;\n\n return css`\n padding: ${spacing};\n border-radius: calc(${baseBorderRadius} / 2);\n border: ${borderWidth} solid transparent;\n transition-property: border-color;\n transition-duration: ${speed};\n transition-timing-function: ${timing.ease};\n\n ${showBorder &&\n css`\n border-color: ${borderColor};\n `}\n `;\n }\n);\n\nStyledGroupContainer.defaultProps = defaultThemeProp;\n\n// Components\nconst FieldGroupLegend = ({\n name,\n contextualLabel,\n children,\n collapsed,\n actions,\n additionalInfo\n}: FieldGroupLegendProps) => {\n return (\n <StyledFieldGroupLegend collapsed={collapsed}>\n <Flex container={{ alignItems: 'center', justify: 'between', gap: 0.5 }}>\n <Flex container={{ alignItems: 'center', gap: 0.5 }} as={StyledFieldHeader}>\n {children}\n {additionalInfo && (\n <AdditionalInfo\n heading={additionalInfo.heading}\n contextualLabel={contextualLabel || name}\n >\n {additionalInfo.content}\n </AdditionalInfo>\n )}\n </Flex>\n {actions && <Actions items={actions} contextualLabel={contextualLabel} />}\n </Flex>\n </StyledFieldGroupLegend>\n );\n};\n\nconst FieldGroup: ForwardRefForwardPropsComponent<FieldGroupProps> = forwardRef(function FieldGroup(\n {\n children,\n description,\n name,\n contextualLabel,\n additionalInfo,\n actions,\n collapsed,\n headingTag,\n onToggleCollapsed,\n variant,\n ...restProps\n }: PropsWithoutRef<FieldGroupProps>,\n ref: FieldGroupProps['ref']\n) {\n const t = useI18n();\n const uid = useUID();\n\n const descAndChildren = (\n <StyledFieldGroupContent container={{ cols: 'minmax(0, 1fr)', gap: 2 }}>\n {description && <HTML id={`${uid}-description`} as='p' content={description} />}\n <div>{children}</div>\n </StyledFieldGroupContent>\n );\n\n return (\n <StyledGroupContainer border={variant === 'form-group'} collapsed={collapsed}>\n <StyledFieldGroup\n aria-label={contextualLabel || name}\n aria-describedby={description ? `${uid}-description` : undefined}\n as={name ? 'fieldset' : 'div'}\n {...restProps}\n ref={ref}\n >\n {name && (\n <FieldGroupLegend\n collapsed={collapsed}\n actions={actions}\n additionalInfo={additionalInfo}\n name={name}\n contextualLabel={contextualLabel}\n >\n {typeof collapsed === 'boolean' ? (\n <StyledExpandButton\n type='button'\n variant='text'\n onClick={() => {\n onToggleCollapsed?.();\n }}\n aria-expanded={!collapsed}\n aria-label={t(collapsed ? 'expand_noun' : 'collapse_noun', [\n contextualLabel || name\n ])}\n >\n <Flex\n container={{ direction: 'row', alignItems: 'center', gap: 0.5 }}\n forwardedAs='span'\n >\n <Icon name='caret-right' />\n {headingTag ? (\n <Text variant={headingTag}>{name}</Text>\n ) : (\n <StyledFieldGroupName>{name}</StyledFieldGroupName>\n )}\n </Flex>\n </StyledExpandButton>\n ) : (\n <>\n {headingTag ? (\n <Text variant={headingTag}>{name}</Text>\n ) : (\n <StyledFieldGroupName>{name}</StyledFieldGroupName>\n )}\n </>\n )}\n </FieldGroupLegend>\n )}\n\n {typeof collapsed === 'boolean' ? (\n <ExpandCollapse collapsed={collapsed}>{descAndChildren}</ExpandCollapse>\n ) : (\n descAndChildren\n )}\n </StyledFieldGroup>\n </StyledGroupContainer>\n );\n});\n\nexport default FieldGroup;\n"]}
|
|
@@ -6,15 +6,30 @@ export type FieldGroupListItemProps = FieldGroupProps & {
|
|
|
6
6
|
id: string;
|
|
7
7
|
/** Item level onDelete callback. */
|
|
8
8
|
onDelete?: (id: string) => void;
|
|
9
|
+
/** Indicates if the item is dynamic. */
|
|
10
|
+
isDynamic?: boolean;
|
|
9
11
|
};
|
|
10
12
|
export interface FieldGroupListProps {
|
|
11
13
|
items: FieldGroupListItemProps[];
|
|
12
14
|
contextualLabel?: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
additionalContext?: string | JSX.Element;
|
|
13
17
|
onAdd?: () => void;
|
|
14
18
|
onDelete?: (id: string) => void;
|
|
15
|
-
ref?: Ref<
|
|
19
|
+
ref?: Ref<HTMLOListElement>;
|
|
16
20
|
}
|
|
17
|
-
export
|
|
21
|
+
export interface ListItemProps {
|
|
22
|
+
item: FieldGroupListItemProps;
|
|
23
|
+
index: number;
|
|
24
|
+
isAddFocused: boolean;
|
|
25
|
+
handleDelete: FieldGroupListProps['onDelete'];
|
|
26
|
+
fieldGroupRef: (el: HTMLFieldSetElement | null) => void;
|
|
27
|
+
}
|
|
28
|
+
export declare const StyledListItem: import("styled-components").StyledComponent<"li", import("styled-components").DefaultTheme, {
|
|
29
|
+
depth: number;
|
|
30
|
+
listGroupIndex: number;
|
|
31
|
+
shouldHighlight: boolean;
|
|
32
|
+
}, never>;
|
|
18
33
|
declare const FieldGroupList: ForwardRefForwardPropsComponent<FieldGroupListProps>;
|
|
19
34
|
export default FieldGroupList;
|
|
20
35
|
//# sourceMappingURL=FieldGroupList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldGroupList.d.ts","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,
|
|
1
|
+
{"version":3,"file":"FieldGroupList.d.ts","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAc,MAAM,OAAO,CAAC;AAI9D,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAqBnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAKpD,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG;IACtD,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,oCAAoC;IACpC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,wCAAwC;IACxC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,uBAAuB,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC9C,aAAa,EAAE,CAAC,EAAE,EAAE,mBAAmB,GAAG,IAAI,KAAK,IAAI,CAAC;CACzD;AAUD,eAAO,MAAM,cAAc;WAClB,MAAM;oBACG,MAAM;qBACL,OAAO;SA2EzB,CAAC;AAoJF,QAAA,MAAM,cAAc,EAAE,+BAA+B,CAAC,mBAAmB,CAiJxE,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,75 +1,225 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef,
|
|
2
|
+
import { forwardRef, useRef, useLayoutEffect, useContext, useMemo, useState } from 'react';
|
|
3
3
|
import styled, { css } from 'styled-components';
|
|
4
|
+
import { transparentize } from 'polished';
|
|
4
5
|
import Button from '../Button';
|
|
5
6
|
import Icon, { registerIcon } from '../Icon';
|
|
6
7
|
import * as plusIcon from '../Icon/icons/plus.icon';
|
|
7
|
-
import { useI18n } from '../../hooks';
|
|
8
|
+
import { useDirection, useI18n } from '../../hooks';
|
|
8
9
|
import { defaultThemeProp } from '../../theme';
|
|
9
|
-
import { getActiveElement, getFocusables } from '../../utils';
|
|
10
|
-
import
|
|
10
|
+
import { getActiveElement, getFocusables, tryCatch } from '../../utils';
|
|
11
|
+
import Flex from '../Flex';
|
|
12
|
+
import EmptyState from '../EmptyState';
|
|
13
|
+
import AdditionalInfo from '../AdditionalInfo';
|
|
14
|
+
import Text from '../Text';
|
|
15
|
+
import { nlpColors, readableHue } from '../../styles';
|
|
16
|
+
import { getIndexDetails } from './FieldGroupList.utils';
|
|
17
|
+
import FieldGroup, { StyledFieldGroup, StyledFieldGroupContent, StyledFieldGroupLegend, StyledGroupContainer, StyledFieldHeader } from './FieldGroup';
|
|
18
|
+
import FieldGroupListContext from './FieldGroupListContext';
|
|
11
19
|
registerIcon(plusIcon);
|
|
12
|
-
const StyledFieldGroupList = styled.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
${StyledFieldGroup} {
|
|
16
|
-
margin-block-start: 0;
|
|
17
|
-
}
|
|
20
|
+
const StyledFieldGroupList = styled.ol(() => css `
|
|
21
|
+
list-style: none;
|
|
18
22
|
`);
|
|
19
23
|
StyledFieldGroupList.defaultProps = defaultThemeProp;
|
|
20
|
-
export const StyledListItem = styled(
|
|
21
|
-
|
|
24
|
+
export const StyledListItem = styled.li(({ theme: { base: { spacing, palette, 'border-radius': borderRadius } }, depth, listGroupIndex, shouldHighlight }) => {
|
|
25
|
+
const bgColor = tryCatch(() => readableHue(nlpColors[listGroupIndex % nlpColors.length], palette['app-background']), () => nlpColors[listGroupIndex % nlpColors.length]);
|
|
26
|
+
return css `
|
|
27
|
+
display: block;
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
29
|
+
> ${StyledGroupContainer} {
|
|
30
|
+
position: relative;
|
|
31
|
+
padding-inline-end: ${spacing};
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
&::before {
|
|
34
|
+
content: '';
|
|
35
|
+
position: absolute;
|
|
36
|
+
inset-block-start: 0;
|
|
37
|
+
bottom: 0;
|
|
38
|
+
inset-inline-start: 0;
|
|
39
|
+
width: calc(0.5 * ${spacing});
|
|
40
|
+
background: ${transparentize(0.75, bgColor)};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
${depth > 1 &&
|
|
44
|
+
css `
|
|
45
|
+
margin-inline-end: -${spacing};
|
|
46
|
+
`}
|
|
47
|
+
|
|
48
|
+
${shouldHighlight &&
|
|
49
|
+
css `
|
|
50
|
+
border-start-end-radius: calc(0.5 * ${borderRadius});
|
|
51
|
+
border-end-end-radius: calc(0.5 * ${borderRadius});
|
|
52
|
+
background: ${transparentize(0.95, palette['foreground-color'])};
|
|
53
|
+
`}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
> ${StyledGroupContainer} > ${StyledFieldGroup} {
|
|
57
|
+
margin-block-start: 0;
|
|
58
|
+
padding: ${spacing} 0;
|
|
59
|
+
|
|
60
|
+
&:not(:last-of-type) {
|
|
61
|
+
border-bottom: 0.0625rem solid ${palette['border-line']};
|
|
62
|
+
margin-block-end: calc(2 * ${spacing});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
legend {
|
|
66
|
+
margin-block-end: 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
> ${StyledGroupContainer} > ${StyledFieldGroup} > ${StyledFieldGroupContent} {
|
|
71
|
+
padding-inline-start: calc(1.5 * ${spacing});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
> ${StyledGroupContainer} > ${StyledFieldGroup} > ${StyledFieldGroupLegend} {
|
|
75
|
+
${StyledFieldHeader} {
|
|
76
|
+
margin-inline-start: calc(0.5 * ${spacing});
|
|
77
|
+
padding-inline: ${spacing};
|
|
78
|
+
height: calc(4 * ${spacing});
|
|
79
|
+
border-start-end-radius: calc(0.5 * ${borderRadius});
|
|
80
|
+
border-end-end-radius: calc(0.5 * ${borderRadius});
|
|
81
|
+
background: ${transparentize(0.75, bgColor)};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
});
|
|
32
86
|
StyledListItem.defaultProps = defaultThemeProp;
|
|
33
|
-
const StyledAddButton = styled(Button)(({ theme }) => css `
|
|
34
|
-
|
|
87
|
+
const StyledAddButton = styled(Button)(({ theme: { base: { spacing, 'hit-area': { 'mouse-min': hitAreaMouse } } } }) => css `
|
|
88
|
+
display: inline-flex;
|
|
89
|
+
align-items: center;
|
|
90
|
+
min-height: ${hitAreaMouse};
|
|
91
|
+
min-width: ${hitAreaMouse};
|
|
92
|
+
width: fit-content;
|
|
93
|
+
margin-inline-start: calc(2 * ${spacing});
|
|
35
94
|
`);
|
|
36
95
|
StyledAddButton.defaultProps = defaultThemeProp;
|
|
37
|
-
const
|
|
96
|
+
const StyledFieldGroupListContainer = styled.div(({ theme: { base: { spacing, palette, 'border-radius': borderRadius } }, hasAdd }) => css `
|
|
97
|
+
position: relative;
|
|
98
|
+
margin-block-start: ${spacing};
|
|
99
|
+
|
|
100
|
+
${hasAdd &&
|
|
101
|
+
css `
|
|
102
|
+
&::before {
|
|
103
|
+
content: '';
|
|
104
|
+
position: absolute;
|
|
105
|
+
inset-inline-start: 0;
|
|
106
|
+
bottom: calc(1.5 * ${spacing});
|
|
107
|
+
width: calc(1.5 * ${spacing});
|
|
108
|
+
height: calc(2.5 * ${spacing});
|
|
109
|
+
border-end-start-radius: calc(0.5 * ${borderRadius});
|
|
110
|
+
border-inline-start: calc(0.5 * ${spacing}) solid ${palette['border-line']};
|
|
111
|
+
border-bottom: calc(0.5 * ${spacing}) solid ${palette['border-line']};
|
|
112
|
+
}
|
|
113
|
+
`}
|
|
114
|
+
`);
|
|
115
|
+
StyledFieldGroupListContainer.defaultProps = defaultThemeProp;
|
|
116
|
+
const StyledDivider = styled.div(({ theme: { base: { spacing, palette } } }) => css `
|
|
117
|
+
flex: 1;
|
|
118
|
+
height: calc(0.5 * ${spacing});
|
|
119
|
+
background-color: ${palette['border-line']};
|
|
120
|
+
`);
|
|
121
|
+
StyledDivider.defaultProps = defaultThemeProp;
|
|
122
|
+
const ListItem = ({ item, index, isAddFocused, handleDelete, fieldGroupRef }) => {
|
|
123
|
+
const { id, children, name = '', isDynamic, headingTag, ...restItemProps } = item;
|
|
124
|
+
const t = useI18n();
|
|
125
|
+
const { rtl } = useDirection();
|
|
126
|
+
const { depth = 1, ancestorIndices = [], isAncestorHighlighted = false } = useContext(FieldGroupListContext);
|
|
127
|
+
const [isItemFocused, setIsItemFocused] = useState(false);
|
|
128
|
+
const [isDeleteHovered, setIsDeleteHovered] = useState(false);
|
|
129
|
+
const listIndices = [...ancestorIndices, index];
|
|
130
|
+
const { rootIndex, currentIndex, compoundIndex } = getIndexDetails(listIndices);
|
|
131
|
+
const shouldHighlight = !isAncestorHighlighted && (isAddFocused || isDeleteHovered || isItemFocused);
|
|
132
|
+
let formattedName;
|
|
133
|
+
if (isDynamic) {
|
|
134
|
+
formattedName = name;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
formattedName = rtl ? `${currentIndex}\u200F ${name}` : `${currentIndex} ${name}`;
|
|
138
|
+
}
|
|
139
|
+
const contextualLabel = isDynamic ? name : `${name} ${compoundIndex}`;
|
|
140
|
+
const ctxValue = useMemo(() => ({
|
|
141
|
+
depth: depth + 1,
|
|
142
|
+
isAncestorHighlighted: shouldHighlight || isAncestorHighlighted,
|
|
143
|
+
ancestorIndices: listIndices
|
|
144
|
+
}), [depth, index, shouldHighlight, isAncestorHighlighted, listIndices]);
|
|
145
|
+
return (_jsx(StyledListItem, { depth: depth, listGroupIndex: rootIndex, shouldHighlight: shouldHighlight, onFocus: () => {
|
|
146
|
+
setIsItemFocused(true);
|
|
147
|
+
}, onBlur: () => {
|
|
148
|
+
setIsItemFocused(false);
|
|
149
|
+
}, children: _jsx(FieldGroupListContext.Provider, { value: ctxValue, children: _jsx(FieldGroup, { name: formattedName, contextualLabel: contextualLabel, headingTag: headingTag, ...restItemProps, actions: handleDelete
|
|
150
|
+
? [
|
|
151
|
+
{
|
|
152
|
+
id: 'delete',
|
|
153
|
+
text: t('delete'),
|
|
154
|
+
icon: 'trash',
|
|
155
|
+
iconOnly: true,
|
|
156
|
+
onClick: () => {
|
|
157
|
+
handleDelete(id);
|
|
158
|
+
},
|
|
159
|
+
onMouseEnter: () => setIsDeleteHovered(true),
|
|
160
|
+
onMouseLeave: () => setIsDeleteHovered(false)
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
: undefined, ref: fieldGroupRef, children: children }) }) }));
|
|
164
|
+
};
|
|
165
|
+
const FieldGroupList = forwardRef(function FieldGroupList({ label, additionalContext, items, onAdd, onDelete, contextualLabel, ...restProps }, ref) {
|
|
38
166
|
const t = useI18n();
|
|
39
|
-
const lastItemRef = useRef(null);
|
|
40
167
|
const addBtnRef = useRef(null);
|
|
41
|
-
|
|
168
|
+
const itemRefs = useRef([]);
|
|
169
|
+
const deletedItemIndexRef = useRef(null);
|
|
170
|
+
const [isAddFocused, setIsAddFocused] = useState(false);
|
|
171
|
+
const focusElement = (itemRef, focusPreference) => {
|
|
172
|
+
if (!itemRef)
|
|
173
|
+
return;
|
|
174
|
+
const focusables = getFocusables(itemRef);
|
|
175
|
+
const groupItemLegend = itemRef.querySelector(':scope > legend');
|
|
176
|
+
const groupActionButtons = focusables.filter(focusable => groupItemLegend?.contains(focusable));
|
|
177
|
+
const groupContentFocusables = focusables.filter(focusable => !groupItemLegend?.contains(focusable));
|
|
178
|
+
if (focusPreference === 'action') {
|
|
179
|
+
(groupActionButtons[0] || groupContentFocusables[0])?.focus();
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
(groupContentFocusables[0] || groupActionButtons[0])?.focus();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
useLayoutEffect(() => {
|
|
42
186
|
const currentActiveEl = getActiveElement();
|
|
43
|
-
if (
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const groupContentFocusables = focusables.filter(focusable => !groupItemLegend?.contains(focusable));
|
|
48
|
-
if (groupContentFocusables.length > 0) {
|
|
49
|
-
groupContentFocusables[0].focus();
|
|
187
|
+
if (deletedItemIndexRef.current !== null) {
|
|
188
|
+
const deletedIndex = deletedItemIndexRef.current;
|
|
189
|
+
if (items.length === 0 && addBtnRef.current) {
|
|
190
|
+
addBtnRef.current.focus();
|
|
50
191
|
}
|
|
51
192
|
else {
|
|
52
|
-
|
|
193
|
+
const nextIndex = Math.min(deletedIndex, items.length - 1);
|
|
194
|
+
const nextItemRef = itemRefs.current[nextIndex];
|
|
195
|
+
focusElement(nextItemRef, 'action');
|
|
53
196
|
}
|
|
197
|
+
deletedItemIndexRef.current = null;
|
|
198
|
+
}
|
|
199
|
+
if (currentActiveEl === addBtnRef.current) {
|
|
200
|
+
const lastIndex = items.length - 1;
|
|
201
|
+
const lastItemRef = itemRefs.current[lastIndex];
|
|
202
|
+
focusElement(lastItemRef, 'content');
|
|
54
203
|
}
|
|
55
204
|
}, [items.length]);
|
|
56
|
-
return (_jsxs(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
205
|
+
return (_jsxs(Flex, { container: { direction: 'column', gap: 1 }, as: StyledFieldGroupListContainer, hasAdd: !!onAdd, onFocus: (e) => {
|
|
206
|
+
e.stopPropagation();
|
|
207
|
+
}, onBlur: (e) => {
|
|
208
|
+
e.stopPropagation();
|
|
209
|
+
}, children: [label && (_jsxs(Flex, { container: { gap: 0.5, alignItems: 'center' }, children: [_jsx(Text, { variant: 'h3', children: label }), additionalContext && (_jsx(AdditionalInfo, { contextualLabel: label, children: additionalContext })), _jsx(StyledDivider, { "aria-hidden": 'true' })] })), items.length === 0 ? (_jsx(EmptyState, {})) : (_jsx(Flex, { container: { direction: 'column', gap: 1 }, as: StyledFieldGroupList, ref: ref, ...restProps, children: items.map((item, index) => {
|
|
210
|
+
const handleDelete = onDelete || item.onDelete
|
|
211
|
+
? (id) => {
|
|
212
|
+
deletedItemIndexRef.current = index;
|
|
213
|
+
item.onDelete?.(id);
|
|
214
|
+
onDelete?.(id);
|
|
215
|
+
}
|
|
216
|
+
: undefined;
|
|
217
|
+
return (_jsx(ListItem, { item: item, index: index, isAddFocused: isAddFocused, handleDelete: handleDelete, fieldGroupRef: (el) => {
|
|
218
|
+
itemRefs.current[index] = el;
|
|
219
|
+
} }, item.id));
|
|
220
|
+
}) })), onAdd && (_jsxs(StyledAddButton, { variant: 'link', onClick: onAdd, onFocus: () => {
|
|
221
|
+
setIsAddFocused(true);
|
|
222
|
+
}, onBlur: () => setIsAddFocused(false), ref: addBtnRef, children: [_jsx(Icon, { name: 'plus' }), contextualLabel ? t('add_noun', [contextualLabel]) : t('add')] }))] }));
|
|
73
223
|
});
|
|
74
224
|
export default FieldGroupList;
|
|
75
225
|
//# sourceMappingURL=FieldGroupList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldGroupList.js","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG5D,YAAY,CAAC,QAAQ,CAAC,CAAC;AAiBvB,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CACrC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,CAAA;0BACM,KAAK,CAAC,IAAI,CAAC,OAAO;;MAEtC,gBAAgB;;;GAGnB,CACF,CAAC;AAEF,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,CAC9C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,CAAA;eACL,KAAK,CAAC,IAAI,CAAC,OAAO,eAAe,KAAK,CAAC,IAAI,CAAC,OAAO;;;u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G,EAAE,SAAS,aAC5D,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,EACnB,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAC9C,CACnB,IACoB,CACxB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { forwardRef, useEffect, useRef } from 'react';\nimport type { PropsWithoutRef, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { ForwardRefForwardPropsComponent } from '../../types';\nimport Button from '../Button';\nimport Icon, { registerIcon } from '../Icon';\nimport * as plusIcon from '../Icon/icons/plus.icon';\nimport { useI18n } from '../../hooks';\nimport { defaultThemeProp } from '../../theme';\nimport { getActiveElement, getFocusables } from '../../utils';\n\nimport FieldGroup, { StyledFieldGroup } from './FieldGroup';\nimport type { FieldGroupProps } from './FieldGroup';\n\nregisterIcon(plusIcon);\n\nexport type FieldGroupListItemProps = FieldGroupProps & {\n /** The ID of the field group list item */\n id: string;\n /** Item level onDelete callback. */\n onDelete?: (id: string) => void;\n};\n\nexport interface FieldGroupListProps {\n items: FieldGroupListItemProps[];\n contextualLabel?: string;\n onAdd?: () => void;\n onDelete?: (id: string) => void;\n ref?: Ref<HTMLDivElement>;\n}\n\nconst StyledFieldGroupList = styled.div(\n ({ theme }) => css`\n margin-block-start: ${theme.base.spacing};\n\n ${StyledFieldGroup} {\n margin-block-start: 0;\n }\n `\n);\n\nStyledFieldGroupList.defaultProps = defaultThemeProp;\n\nexport const StyledListItem = styled(FieldGroup)(\n ({ theme }) => css`\n padding: ${theme.base.spacing} 0 calc(2 * ${theme.base.spacing});\n\n &:not(:last-of-type) {\n border-bottom: 0.0625rem solid ${theme.base.palette['border-line']};\n margin-block-end: calc(2 * ${theme.base.spacing});\n }\n\n legend {\n margin-block-end: 0;\n }\n `\n);\n\nStyledListItem.defaultProps = defaultThemeProp;\n\nconst StyledAddButton = styled(Button)(\n ({ theme }) => css`\n margin-top: ${theme.base.spacing};\n `\n);\n\nStyledAddButton.defaultProps = defaultThemeProp;\n\nconst FieldGroupList: ForwardRefForwardPropsComponent<FieldGroupListProps> = forwardRef(\n function FieldGroupList(\n { items, onAdd, onDelete, contextualLabel, ...restProps }: PropsWithoutRef<FieldGroupListProps>,\n ref: FieldGroupListProps['ref']\n ) {\n const t = useI18n();\n const lastItemRef = useRef<HTMLDivElement>(null);\n const addBtnRef = useRef<HTMLButtonElement>(null);\n\n useEffect(() => {\n const currentActiveEl = getActiveElement();\n if (currentActiveEl === addBtnRef.current && lastItemRef.current) {\n const groupItemLegend = lastItemRef.current.querySelector(':scope > legend');\n const focusables = getFocusables(lastItemRef.current);\n\n const groupActionButtons = focusables.filter(focusable =>\n groupItemLegend?.contains(focusable)\n );\n\n const groupContentFocusables = focusables.filter(\n focusable => !groupItemLegend?.contains(focusable)\n );\n\n if (groupContentFocusables.length > 0) {\n groupContentFocusables[0].focus();\n } else {\n groupActionButtons[0]?.focus();\n }\n }\n }, [items.length]);\n\n return (\n <StyledFieldGroupList ref={ref} {...restProps}>\n {items.map(\n (\n {\n id,\n children,\n name,\n headingTag,\n onDelete: itemOnDelete,\n ...restItemProps\n }: FieldGroupListItemProps,\n index\n ) => {\n const isLastItem = index === items.length - 1;\n return (\n <StyledListItem\n key={id}\n name={name}\n headingTag={headingTag}\n {...restItemProps}\n actions={\n onDelete || itemOnDelete\n ? [\n {\n id: 'delete',\n text: t('delete'),\n icon: 'trash',\n iconOnly: true,\n onClick: () => {\n itemOnDelete?.(id);\n onDelete?.(id);\n }\n }\n ]\n : undefined\n }\n ref={isLastItem ? lastItemRef : undefined}\n >\n {children}\n </StyledListItem>\n );\n }\n )}\n {onAdd && (\n <StyledAddButton variant='link' onClick={onAdd} ref={addBtnRef}>\n <Icon name='plus' />\n {contextualLabel ? t('add_noun', [contextualLabel]) : t('add')}\n </StyledAddButton>\n )}\n </StyledFieldGroupList>\n );\n }\n);\n\nexport default FieldGroupList;\n"]}
|
|
1
|
+
{"version":3,"file":"FieldGroupList.js","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE3F,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,UAAU,EAAE,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAE5D,YAAY,CAAC,QAAQ,CAAC,CAAC;AA6BvB,MAAM,oBAAoB,GAAG,MAAM,CAAC,EAAE,CACpC,GAAG,EAAE,CAAC,GA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EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,EACpC,GAAG,EAAE,SAAS,aAEd,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,EACnB,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAC9C,CACnB,IACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { forwardRef, useRef, useLayoutEffect, useContext, useMemo, useState } from 'react';\nimport type { PropsWithoutRef, Ref, FocusEvent } from 'react';\nimport styled, { css } from 'styled-components';\nimport { transparentize } from 'polished';\n\nimport type { ForwardRefForwardPropsComponent } from '../../types';\nimport Button from '../Button';\nimport Icon, { registerIcon } from '../Icon';\nimport * as plusIcon from '../Icon/icons/plus.icon';\nimport { useDirection, useI18n } from '../../hooks';\nimport { defaultThemeProp } from '../../theme';\nimport { getActiveElement, getFocusables, tryCatch } from '../../utils';\nimport Flex from '../Flex';\nimport EmptyState from '../EmptyState';\nimport AdditionalInfo from '../AdditionalInfo';\nimport Text from '../Text';\nimport { nlpColors, readableHue } from '../../styles';\n\nimport { getIndexDetails } from './FieldGroupList.utils';\nimport FieldGroup, {\n StyledFieldGroup,\n StyledFieldGroupContent,\n StyledFieldGroupLegend,\n StyledGroupContainer,\n StyledFieldHeader\n} from './FieldGroup';\nimport type { FieldGroupProps } from './FieldGroup';\nimport FieldGroupListContext from './FieldGroupListContext';\n\nregisterIcon(plusIcon);\n\nexport type FieldGroupListItemProps = FieldGroupProps & {\n /** The ID of the field group list item */\n id: string;\n /** Item level onDelete callback. */\n onDelete?: (id: string) => void;\n /** Indicates if the item is dynamic. */\n isDynamic?: boolean;\n};\n\nexport interface FieldGroupListProps {\n items: FieldGroupListItemProps[];\n contextualLabel?: string;\n label?: string;\n additionalContext?: string | JSX.Element;\n onAdd?: () => void;\n onDelete?: (id: string) => void;\n ref?: Ref<HTMLOListElement>;\n}\n\nexport interface ListItemProps {\n item: FieldGroupListItemProps;\n index: number;\n isAddFocused: boolean;\n handleDelete: FieldGroupListProps['onDelete'];\n fieldGroupRef: (el: HTMLFieldSetElement | null) => void;\n}\n\nconst StyledFieldGroupList = styled.ol(\n () => css`\n list-style: none;\n `\n);\n\nStyledFieldGroupList.defaultProps = defaultThemeProp;\n\nexport const StyledListItem = styled.li<{\n depth: number;\n listGroupIndex: number;\n shouldHighlight: boolean;\n}>(\n ({\n theme: {\n base: { spacing, palette, 'border-radius': borderRadius }\n },\n depth,\n listGroupIndex,\n shouldHighlight\n }) => {\n const bgColor = tryCatch(\n () => readableHue(nlpColors[listGroupIndex % nlpColors.length], palette['app-background']),\n () => nlpColors[listGroupIndex % nlpColors.length]\n );\n\n return css`\n display: block;\n\n > ${StyledGroupContainer} {\n position: relative;\n padding-inline-end: ${spacing};\n\n &::before {\n content: '';\n position: absolute;\n inset-block-start: 0;\n bottom: 0;\n inset-inline-start: 0;\n width: calc(0.5 * ${spacing});\n background: ${transparentize(0.75, bgColor)};\n }\n\n ${depth > 1 &&\n css`\n margin-inline-end: -${spacing};\n `}\n\n ${shouldHighlight &&\n css`\n border-start-end-radius: calc(0.5 * ${borderRadius});\n border-end-end-radius: calc(0.5 * ${borderRadius});\n background: ${transparentize(0.95, palette['foreground-color'])};\n `}\n }\n\n > ${StyledGroupContainer} > ${StyledFieldGroup} {\n margin-block-start: 0;\n padding: ${spacing} 0;\n\n &:not(:last-of-type) {\n border-bottom: 0.0625rem solid ${palette['border-line']};\n margin-block-end: calc(2 * ${spacing});\n }\n\n legend {\n margin-block-end: 0;\n }\n }\n\n > ${StyledGroupContainer} > ${StyledFieldGroup} > ${StyledFieldGroupContent} {\n padding-inline-start: calc(1.5 * ${spacing});\n }\n\n > ${StyledGroupContainer} > ${StyledFieldGroup} > ${StyledFieldGroupLegend} {\n ${StyledFieldHeader} {\n margin-inline-start: calc(0.5 * ${spacing});\n padding-inline: ${spacing};\n height: calc(4 * ${spacing});\n border-start-end-radius: calc(0.5 * ${borderRadius});\n border-end-end-radius: calc(0.5 * ${borderRadius});\n background: ${transparentize(0.75, bgColor)};\n }\n }\n `;\n }\n);\n\nStyledListItem.defaultProps = defaultThemeProp;\n\nconst StyledAddButton = styled(Button)(\n ({\n theme: {\n base: {\n spacing,\n 'hit-area': { 'mouse-min': hitAreaMouse }\n }\n }\n }) => css`\n display: inline-flex;\n align-items: center;\n min-height: ${hitAreaMouse};\n min-width: ${hitAreaMouse};\n width: fit-content;\n margin-inline-start: calc(2 * ${spacing});\n `\n);\n\nStyledAddButton.defaultProps = defaultThemeProp;\n\nconst StyledFieldGroupListContainer = styled.div<{ hasAdd: boolean }>(\n ({\n theme: {\n base: { spacing, palette, 'border-radius': borderRadius }\n },\n hasAdd\n }) => css`\n position: relative;\n margin-block-start: ${spacing};\n\n ${hasAdd &&\n css`\n &::before {\n content: '';\n position: absolute;\n inset-inline-start: 0;\n bottom: calc(1.5 * ${spacing});\n width: calc(1.5 * ${spacing});\n height: calc(2.5 * ${spacing});\n border-end-start-radius: calc(0.5 * ${borderRadius});\n border-inline-start: calc(0.5 * ${spacing}) solid ${palette['border-line']};\n border-bottom: calc(0.5 * ${spacing}) solid ${palette['border-line']};\n }\n `}\n `\n);\n\nStyledFieldGroupListContainer.defaultProps = defaultThemeProp;\n\nconst StyledDivider = styled.div(\n ({\n theme: {\n base: { spacing, palette }\n }\n }) => css`\n flex: 1;\n height: calc(0.5 * ${spacing});\n background-color: ${palette['border-line']};\n `\n);\n\nStyledDivider.defaultProps = defaultThemeProp;\n\nconst ListItem = ({ item, index, isAddFocused, handleDelete, fieldGroupRef }: ListItemProps) => {\n const { id, children, name = '', isDynamic, headingTag, ...restItemProps } = item;\n\n const t = useI18n();\n const { rtl } = useDirection();\n const {\n depth = 1,\n ancestorIndices = [],\n isAncestorHighlighted = false\n } = useContext(FieldGroupListContext);\n\n const [isItemFocused, setIsItemFocused] = useState(false);\n const [isDeleteHovered, setIsDeleteHovered] = useState(false);\n\n const listIndices = [...ancestorIndices, index];\n const { rootIndex, currentIndex, compoundIndex } = getIndexDetails(listIndices);\n\n const shouldHighlight =\n !isAncestorHighlighted && (isAddFocused || isDeleteHovered || isItemFocused);\n\n let formattedName: string;\n if (isDynamic) {\n formattedName = name;\n } else {\n formattedName = rtl ? `${currentIndex}\\u200F ${name}` : `${currentIndex} ${name}`;\n }\n const contextualLabel = isDynamic ? name : `${name} ${compoundIndex}`;\n\n const ctxValue = useMemo(\n () => ({\n depth: depth + 1,\n isAncestorHighlighted: shouldHighlight || isAncestorHighlighted,\n ancestorIndices: listIndices\n }),\n [depth, index, shouldHighlight, isAncestorHighlighted, listIndices]\n );\n\n return (\n <StyledListItem\n depth={depth}\n listGroupIndex={rootIndex}\n shouldHighlight={shouldHighlight}\n onFocus={() => {\n setIsItemFocused(true);\n }}\n onBlur={() => {\n setIsItemFocused(false);\n }}\n >\n <FieldGroupListContext.Provider value={ctxValue}>\n <FieldGroup\n name={formattedName}\n contextualLabel={contextualLabel}\n headingTag={headingTag}\n {...restItemProps}\n actions={\n handleDelete\n ? [\n {\n id: 'delete',\n text: t('delete'),\n icon: 'trash',\n iconOnly: true,\n onClick: () => {\n handleDelete(id);\n },\n onMouseEnter: () => setIsDeleteHovered(true),\n onMouseLeave: () => setIsDeleteHovered(false)\n }\n ]\n : undefined\n }\n ref={fieldGroupRef}\n >\n {children}\n </FieldGroup>\n </FieldGroupListContext.Provider>\n </StyledListItem>\n );\n};\n\nconst FieldGroupList: ForwardRefForwardPropsComponent<FieldGroupListProps> = forwardRef(\n function FieldGroupList(\n {\n label,\n additionalContext,\n items,\n onAdd,\n onDelete,\n contextualLabel,\n ...restProps\n }: PropsWithoutRef<FieldGroupListProps>,\n ref: FieldGroupListProps['ref']\n ) {\n const t = useI18n();\n\n const addBtnRef = useRef<HTMLButtonElement>(null);\n const itemRefs = useRef<(HTMLFieldSetElement | null)[]>([]);\n const deletedItemIndexRef = useRef<number | null>(null);\n\n const [isAddFocused, setIsAddFocused] = useState(false);\n\n const focusElement = (\n itemRef: HTMLFieldSetElement | null,\n focusPreference: 'action' | 'content'\n ) => {\n if (!itemRef) return;\n\n const focusables = getFocusables(itemRef);\n const groupItemLegend = itemRef.querySelector(':scope > legend');\n\n const groupActionButtons = focusables.filter(focusable =>\n groupItemLegend?.contains(focusable)\n );\n\n const groupContentFocusables = focusables.filter(\n focusable => !groupItemLegend?.contains(focusable)\n );\n\n if (focusPreference === 'action') {\n (groupActionButtons[0] || groupContentFocusables[0])?.focus();\n } else {\n (groupContentFocusables[0] || groupActionButtons[0])?.focus();\n }\n };\n\n useLayoutEffect(() => {\n const currentActiveEl = getActiveElement();\n\n if (deletedItemIndexRef.current !== null) {\n const deletedIndex = deletedItemIndexRef.current;\n\n if (items.length === 0 && addBtnRef.current) {\n addBtnRef.current.focus();\n } else {\n const nextIndex = Math.min(deletedIndex, items.length - 1);\n const nextItemRef = itemRefs.current[nextIndex];\n focusElement(nextItemRef, 'action');\n }\n\n deletedItemIndexRef.current = null;\n }\n\n if (currentActiveEl === addBtnRef.current) {\n const lastIndex = items.length - 1;\n const lastItemRef = itemRefs.current[lastIndex];\n focusElement(lastItemRef, 'content');\n }\n }, [items.length]);\n\n return (\n <Flex\n container={{ direction: 'column', gap: 1 }}\n as={StyledFieldGroupListContainer}\n hasAdd={!!onAdd}\n onFocus={(e: FocusEvent) => {\n e.stopPropagation();\n }}\n onBlur={(e: FocusEvent) => {\n e.stopPropagation();\n }}\n >\n {label && (\n <Flex container={{ gap: 0.5, alignItems: 'center' }}>\n <Text variant='h3'>{label}</Text>\n\n {additionalContext && (\n <AdditionalInfo contextualLabel={label}>{additionalContext}</AdditionalInfo>\n )}\n\n <StyledDivider aria-hidden='true' />\n </Flex>\n )}\n\n {items.length === 0 ? (\n <EmptyState />\n ) : (\n <Flex\n container={{ direction: 'column', gap: 1 }}\n as={StyledFieldGroupList}\n ref={ref}\n {...restProps}\n >\n {items.map((item, index) => {\n const handleDelete =\n onDelete || item.onDelete\n ? (id: string) => {\n deletedItemIndexRef.current = index;\n item.onDelete?.(id);\n onDelete?.(id);\n }\n : undefined;\n\n return (\n <ListItem\n key={item.id}\n item={item}\n index={index}\n isAddFocused={isAddFocused}\n handleDelete={handleDelete}\n fieldGroupRef={(el: HTMLFieldSetElement | null) => {\n itemRefs.current[index] = el;\n }}\n />\n );\n })}\n </Flex>\n )}\n\n {onAdd && (\n <StyledAddButton\n variant='link'\n onClick={onAdd}\n onFocus={() => {\n setIsAddFocused(true);\n }}\n onBlur={() => setIsAddFocused(false)}\n ref={addBtnRef}\n >\n <Icon name='plus' />\n {contextualLabel ? t('add_noun', [contextualLabel]) : t('add')}\n </StyledAddButton>\n )}\n </Flex>\n );\n }\n);\n\nexport default FieldGroupList;\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a number to a Roman numeral.
|
|
3
|
+
* @param num - The number to convert.
|
|
4
|
+
* @returns The Roman numeral representation.
|
|
5
|
+
*/
|
|
6
|
+
export declare const convertToRoman: (num: number) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Converts a number to a base-26 alphabetic string (a, b, c... aa, ab, ac...).
|
|
9
|
+
* @param num - The 0-based index to convert.
|
|
10
|
+
* @returns The alphabetic representation.
|
|
11
|
+
*/
|
|
12
|
+
export declare const convertToAlphabetic: (num: number) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Generates a list number based on depth and index.
|
|
15
|
+
* @param levelIndex - The index of the item in the list (0-based).
|
|
16
|
+
* @param depth - The depth of the list (0-based).
|
|
17
|
+
* @returns The formatted list number.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getFormattedListNumber: (levelIndex: number, depth: number) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Generates a compound index and the current list index based on the depth and index of the current item and its ancestors.
|
|
22
|
+
* @param indices - An array of indices representing the position at each depth (e.g., [0, 1, 2]).
|
|
23
|
+
* @returns An object containing:
|
|
24
|
+
* - `rootIndex`: The zero-based index at the root level (e.g., 0 for "1.", 1 for "2.").
|
|
25
|
+
* - `currentIndex`: The index at the latest depth (e.g., "a." or "i.").
|
|
26
|
+
* - `compoundIndex`: The full compound index (e.g., "1.a.i").
|
|
27
|
+
*/
|
|
28
|
+
export declare const getIndexDetails: (indices: number[]) => {
|
|
29
|
+
rootIndex: number;
|
|
30
|
+
currentIndex: string;
|
|
31
|
+
compoundIndex: string;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=FieldGroupList.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldGroupList.utils.d.ts","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,WA0BzC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,WAQ9C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,YAAY,MAAM,EAAE,OAAO,MAAM,WAUvE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EAAE,KAChB;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAUlE,CAAC"}
|