@cloudscape-design/components 3.0.873 → 3.0.875
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/app-layout/visual-refresh-toolbar/toolbar/trigger-button/index.js +4 -4
- package/app-layout/visual-refresh-toolbar/toolbar/trigger-button/index.js.map +1 -1
- package/attribute-editor/grid-defaults.d.ts +3 -0
- package/attribute-editor/grid-defaults.d.ts.map +1 -0
- package/attribute-editor/grid-defaults.js +122 -0
- package/attribute-editor/grid-defaults.js.map +1 -0
- package/attribute-editor/interfaces.d.ts +49 -2
- package/attribute-editor/interfaces.d.ts.map +1 -1
- package/attribute-editor/interfaces.js.map +1 -1
- package/attribute-editor/internal.d.ts.map +1 -1
- package/attribute-editor/internal.js +35 -15
- package/attribute-editor/internal.js.map +1 -1
- package/attribute-editor/row.d.ts +5 -3
- package/attribute-editor/row.d.ts.map +1 -1
- package/attribute-editor/row.js +29 -26
- package/attribute-editor/row.js.map +1 -1
- package/attribute-editor/styles.css.js +15 -14
- package/attribute-editor/styles.scoped.css +49 -41
- package/attribute-editor/styles.selectors.js +15 -14
- package/attribute-editor/utils.d.ts +11 -0
- package/attribute-editor/utils.d.ts.map +1 -0
- package/attribute-editor/utils.js +43 -0
- package/attribute-editor/utils.js.map +1 -0
- package/button-dropdown/interfaces.d.ts +6 -2
- package/button-dropdown/interfaces.d.ts.map +1 -1
- package/button-dropdown/interfaces.js.map +1 -1
- package/button-dropdown/internal.d.ts.map +1 -1
- package/button-dropdown/internal.js +11 -3
- package/button-dropdown/internal.js.map +1 -1
- package/button-dropdown/utils/use-button-dropdown.js +1 -1
- package/button-dropdown/utils/use-button-dropdown.js.map +1 -1
- package/button-group/item-element.d.ts.map +1 -1
- package/button-group/item-element.js +15 -11
- package/button-group/item-element.js.map +1 -1
- package/code-editor/resizable-box/index.js +4 -4
- package/code-editor/resizable-box/index.js.map +1 -1
- package/container/use-sticky-header.js +4 -4
- package/container/use-sticky-header.js.map +1 -1
- package/file-dropzone/use-files-dragging.d.ts.map +1 -1
- package/file-dropzone/use-files-dragging.js +5 -6
- package/file-dropzone/use-files-dragging.js.map +1 -1
- package/form-field/interfaces.d.ts +2 -1
- package/form-field/interfaces.d.ts.map +1 -1
- package/form-field/interfaces.js.map +1 -1
- package/form-field/internal.d.ts +1 -1
- package/form-field/internal.d.ts.map +1 -1
- package/form-field/internal.js +2 -2
- package/form-field/internal.js.map +1 -1
- package/internal/analytics/components/analytics-funnel.js +4 -4
- package/internal/analytics/components/analytics-funnel.js.map +1 -1
- package/internal/animate.js +1 -1
- package/internal/animate.js.map +1 -1
- package/internal/components/chart-plot/focus-outline.js +4 -4
- package/internal/components/chart-plot/focus-outline.js.map +1 -1
- package/internal/components/dropdown/dropdown-fit-handler.d.ts +2 -1
- package/internal/components/dropdown/dropdown-fit-handler.d.ts.map +1 -1
- package/internal/components/dropdown/dropdown-fit-handler.js +1 -1
- package/internal/components/dropdown/dropdown-fit-handler.js.map +1 -1
- package/internal/components/dropdown/dropdown-position.d.ts +16 -0
- package/internal/components/dropdown/dropdown-position.d.ts.map +1 -0
- package/internal/components/dropdown/dropdown-position.js +27 -0
- package/internal/components/dropdown/dropdown-position.js.map +1 -0
- package/internal/components/dropdown/index.d.ts.map +1 -1
- package/internal/components/dropdown/index.js +19 -35
- package/internal/components/dropdown/index.js.map +1 -1
- package/internal/components/transition/index.js +4 -4
- package/internal/components/transition/index.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/focus-tracker.d.ts +1 -0
- package/internal/focus-tracker.d.ts.map +1 -1
- package/internal/focus-tracker.js +4 -4
- package/internal/focus-tracker.js.map +1 -1
- package/internal/hooks/use-mouse-down-target.js +4 -4
- package/internal/hooks/use-mouse-down-target.js.map +1 -1
- package/internal/manifest.json +1 -1
- package/multiselect/interfaces.d.ts +4 -0
- package/multiselect/interfaces.d.ts.map +1 -1
- package/multiselect/interfaces.js.map +1 -1
- package/multiselect/internal.d.ts +1 -3
- package/multiselect/internal.d.ts.map +1 -1
- package/multiselect/internal.js.map +1 -1
- package/package.json +1 -1
- package/popover/container.d.ts.map +1 -1
- package/popover/container.js +5 -6
- package/popover/container.js.map +1 -1
- package/table/resizer/index.d.ts.map +1 -1
- package/table/resizer/index.js +5 -6
- package/table/resizer/index.js.map +1 -1
- package/table/table-role/grid-navigation.js +5 -6
- package/table/table-role/grid-navigation.js.map +1 -1
- package/test-utils/dom/attribute-editor/index.d.ts +1 -0
- package/test-utils/dom/attribute-editor/index.js +4 -2
- package/test-utils/dom/attribute-editor/index.js.map +1 -1
- package/test-utils/dom/index.d.ts +78 -78
- package/test-utils/dom/index.js +9 -3
- package/test-utils/dom/index.js.map +1 -1
- package/test-utils/selectors/attribute-editor/index.d.ts +1 -0
- package/test-utils/selectors/attribute-editor/index.js +4 -2
- package/test-utils/selectors/attribute-editor/index.js.map +1 -1
- package/test-utils/selectors/index.d.ts +78 -78
- package/test-utils/selectors/index.js +5 -1
- package/test-utils/selectors/index.js.map +1 -1
- package/test-utils/tsconfig.tsbuildinfo +1 -1
- package/top-navigation/styles.css.js +47 -47
- package/top-navigation/styles.scoped.css +66 -65
- package/top-navigation/styles.selectors.js +47 -47
|
@@ -84,11 +84,11 @@ function TriggerButton({ ariaLabel, className, iconName, iconSvg, ariaExpanded,
|
|
|
84
84
|
};
|
|
85
85
|
const wrapperDiv = containerRef.current;
|
|
86
86
|
if (wrapperDiv) {
|
|
87
|
-
|
|
88
|
-
wrapperDiv.addEventListener('
|
|
87
|
+
const controller = new AbortController();
|
|
88
|
+
wrapperDiv.addEventListener('pointerdown', handlePointerDownEvent, { signal: controller.signal });
|
|
89
|
+
wrapperDiv.addEventListener('keydown', handleKeyDownEvent, { signal: controller.signal });
|
|
89
90
|
return () => {
|
|
90
|
-
|
|
91
|
-
wrapperDiv.removeEventListener('keydown', handleKeyDownEvent);
|
|
91
|
+
controller.abort();
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/app-layout/visual-refresh-toolbar/toolbar/trigger-button/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAO,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtF,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,IAAI,MAAM,2BAA2B,CAAC;AAC7C,OAAO,OAAO,MAAM,yCAAyC,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,kDAAkD,CAAC;AAEnF,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAoDrC,SAAS,aAAa,CACpB,EACE,SAAS,EACT,SAAS,EACT,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,MAAM,EACN,QAAQ,GAAG,KAAK,EAChB,KAAK,EACL,QAAQ,GAAG,KAAK,EAChB,UAAU,GAAG,KAAK,EAClB,WAAW,EACX,aAAa,GAAG,KAAK,EACrB,QAAQ,GAAG,KAAK,EAChB,yBAAyB,GAAG,KAAK,EACjC,eAAe,GAAG,KAAK,GACJ,EACrB,GAA+B;IAE/B,MAAM,YAAY,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IACzD,MAAM,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5E,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IAC/D,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IAEtE,MAAM,kBAAkB,GAAG,CAAC,KAA0C,E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cAAc,CAAC,4BAA4B,CAAC,CAAC,EAAE,KAAK;aACtD,EACD,SAAS,CACV,EACD,OAAO,EAAE,kBAAkB,EAC3B,GAAG,EAAE,GAA6B,EAClC,IAAI,EAAC,QAAQ,iBACA,MAAM,sBACF,6BAA6B;YAE9C,8BAAM,SAAS,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAC,uBAAuB,CAAC,CAAC,CAAC,IACnG,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,oBAAC,IAAI,IAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,GAAI,CAC3D,CACA;QACR,KAAK,IAAI,6BAAK,SAAS,EAAE,MAAM,CAAC,GAAG,GAAI;QACvC,cAAc,IAAI,CACjB,oBAAC,OAAO,IAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,cAAc,CAAC,iBAAiB,CAAC,GAAI,CACvG,CACG,CACP,CAAC;AACJ,CAAC;AAED,eAAe,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { Ref, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { ButtonProps } from '../../../../button/interfaces';\nimport { IconProps } from '../../../../icon/interfaces';\nimport Icon from '../../../../icon/internal';\nimport Tooltip from '../../../../internal/components/tooltip';\nimport { registerTooltip } from '../../../../internal/components/tooltip/registry';\n\nimport testutilStyles from '../../../test-classes/styles.css.js';\nimport styles from './styles.css.js';\n\nexport interface TriggerButtonProps {\n ariaLabel?: string;\n className?: string;\n iconName?: IconProps.Name;\n iconSvg?: React.ReactNode;\n ariaExpanded: boolean | undefined;\n ariaControls?: string;\n disabled?: boolean;\n /**\n * Ovewrwrites any internal testIds when provided\n */\n testId?: string;\n /**\n * If button is selected. Used only for desktop and applies a selected class\n */\n selected?: boolean;\n onClick: React.MouseEventHandler<HTMLButtonElement>;\n\n badge?: boolean;\n /**\n * If the button is expected to have a tooltip. When false it will not set the event listeners\n *\n * defaults to false\n */\n hasTooltip?: boolean;\n /**\n * This text allows for a customized tooltip.\n *\n * When falsy, the tooltip will parse the tooltip form the aria-lable\n */\n tooltipText?: string;\n hasOpenDrawer?: boolean;\n /**\n * If the AppLayout is in mobile mode\n * Used to determine if and where to render tooltips\n */\n isMobile?: boolean;\n /**\n * set to true if the trigger button was used to open the last active drawer\n * this is also used to hide the tooltip should the focus be set programmatically\n * on focus from a drawer close using this\n */\n isForPreviousActiveDrawer?: boolean;\n /**\n * if the trigger button is for the split panel\n */\n isForSplitPanel?: boolean;\n tabIndex?: number | undefined;\n}\n\nfunction TriggerButton(\n {\n ariaLabel,\n className,\n iconName,\n iconSvg,\n ariaExpanded,\n ariaControls,\n onClick,\n testId,\n disabled = false,\n badge,\n selected = false,\n hasTooltip = false,\n tooltipText,\n hasOpenDrawer = false,\n isMobile = false,\n isForPreviousActiveDrawer = false,\n isForSplitPanel = false,\n }: TriggerButtonProps,\n ref: React.Ref<ButtonProps.Ref>\n) {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const tooltipValue = tooltipText ? tooltipText : ariaLabel ? ariaLabel : '';\n const [showTooltip, setShowTooltip] = useState<boolean>(false);\n const [suppressTooltip, setSupressTooltip] = useState<boolean>(false);\n\n const handleTriggerClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n event.stopPropagation(); // Stop the event from propagating to the badge icon\n setShowTooltip(false);\n setSupressTooltip(true);\n onClick(event);\n };\n\n const handleBlur = (keepSupressed = false) => {\n setSupressTooltip(keepSupressed);\n setShowTooltip(false);\n };\n\n const handlePointerEnter = () => {\n setSupressTooltip(false);\n setShowTooltip(true);\n };\n\n /**\n * Takes the drawer being closed and the data-shift-focus value from a close button on that drawer that persists\n * on the event relatedTarget to determine not to show the tooltip\n * @param event\n */\n const handleOnFocus = useCallback(\n (event: FocusEvent) => {\n let shouldShowTooltip = false;\n const eventWithRelatedTarget = event as any;\n const relatedTarget = eventWithRelatedTarget?.relatedTarget;\n const isFromAnotherTrigger = relatedTarget?.dataset?.shiftFocus === 'awsui-layout-drawer-trigger';\n if (\n (isForSplitPanel && !!relatedTarget) || // relatedTarget is null when split panel is closed\n (!isForSplitPanel &&\n (isFromAnotherTrigger || // for key navigation from another trigger button\n !isForPreviousActiveDrawer)) // for when the drawer was not opened recently\n ) {\n shouldShowTooltip = true;\n }\n setSupressTooltip(!shouldShowTooltip);\n setShowTooltip(true);\n },\n [\n // To assert reference equality check\n isForPreviousActiveDrawer,\n isForSplitPanel,\n ]\n );\n\n const tooltipVisible = useMemo(() => {\n return (\n hasTooltip &&\n showTooltip &&\n !suppressTooltip &&\n !!containerRef?.current &&\n tooltipValue &&\n !(isMobile && hasOpenDrawer)\n );\n }, [hasTooltip, showTooltip, containerRef, tooltipValue, isMobile, hasOpenDrawer, suppressTooltip]);\n\n useEffect(() => {\n if (hasTooltip && tooltipValue) {\n const close = () => {\n setShowTooltip(false);\n setSupressTooltip(false);\n };\n\n const shouldCloseTooltip = (event: PointerEvent) => {\n if (event.target && containerRef && (containerRef.current as any)?.contains(event.target as HTMLElement)) {\n return false;\n }\n return true;\n };\n\n const handlePointerDownEvent = (event: PointerEvent) => {\n if (shouldCloseTooltip(event)) {\n close();\n }\n };\n\n const handleKeyDownEvent = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n close();\n }\n };\n\n const wrapperDiv = containerRef.current;\n if (wrapperDiv) {\n wrapperDiv.addEventListener('pointerdown', handlePointerDownEvent);\n wrapperDiv.addEventListener('keydown', handleKeyDownEvent);\n\n return () => {\n wrapperDiv.removeEventListener('pointerdown', handlePointerDownEvent);\n wrapperDiv.removeEventListener('keydown', handleKeyDownEvent);\n };\n }\n }\n }, [containerRef, hasTooltip, tooltipValue]);\n\n useEffect(() => {\n if (tooltipVisible) {\n return registerTooltip(() => {\n setShowTooltip(false);\n setSupressTooltip(false);\n });\n }\n }, [tooltipVisible]);\n\n return (\n <div\n ref={containerRef}\n {...(hasTooltip && {\n onPointerEnter: () => handlePointerEnter(),\n onPointerLeave: () => handleBlur(true),\n onFocus: e => handleOnFocus(e as any),\n onBlur: () => handleBlur(true),\n })}\n className={styles['trigger-wrapper']}\n >\n <button\n aria-expanded={ariaExpanded}\n aria-controls={ariaControls}\n aria-haspopup={true}\n aria-label={ariaLabel}\n aria-disabled={disabled}\n disabled={disabled}\n className={clsx(\n styles.trigger,\n styles['trigger-button-styles'],\n {\n [styles.selected]: selected,\n [styles.badge]: badge,\n [testutilStyles['drawers-trigger-with-badge']]: badge,\n },\n className\n )}\n onClick={handleTriggerClick}\n ref={ref as Ref<HTMLButtonElement>}\n type=\"button\"\n data-testid={testId}\n data-shift-focus=\"awsui-layout-drawer-trigger\"\n >\n <span className={clsx(badge && clsx(styles['trigger-badge-wrapper'], styles['trigger-button-styles']))}>\n {(iconName || iconSvg) && <Icon name={iconName} svg={iconSvg} />}\n </span>\n </button>\n {badge && <div className={styles.dot} />}\n {tooltipVisible && (\n <Tooltip trackRef={containerRef} value={tooltipValue} className={testutilStyles['trigger-tooltip']} />\n )}\n </div>\n );\n}\n\nexport default React.forwardRef(TriggerButton);\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/app-layout/visual-refresh-toolbar/toolbar/trigger-button/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAO,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtF,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,IAAI,MAAM,2BAA2B,CAAC;AAC7C,OAAO,OAAO,MAAM,yCAAyC,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,kDAAkD,CAAC;AAEnF,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EAAE,GAAG,EAAE,OAAO,GAAI,CAC3D,CACA;QACR,KAAK,IAAI,6BAAK,SAAS,EAAE,MAAM,CAAC,GAAG,GAAI;QACvC,cAAc,IAAI,CACjB,oBAAC,OAAO,IAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,cAAc,CAAC,iBAAiB,CAAC,GAAI,CACvG,CACG,CACP,CAAC;AACJ,CAAC;AAED,eAAe,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { Ref, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { ButtonProps } from '../../../../button/interfaces';\nimport { IconProps } from '../../../../icon/interfaces';\nimport Icon from '../../../../icon/internal';\nimport Tooltip from '../../../../internal/components/tooltip';\nimport { registerTooltip } from '../../../../internal/components/tooltip/registry';\n\nimport testutilStyles from '../../../test-classes/styles.css.js';\nimport styles from './styles.css.js';\n\nexport interface TriggerButtonProps {\n ariaLabel?: string;\n className?: string;\n iconName?: IconProps.Name;\n iconSvg?: React.ReactNode;\n ariaExpanded: boolean | undefined;\n ariaControls?: string;\n disabled?: boolean;\n /**\n * Ovewrwrites any internal testIds when provided\n */\n testId?: string;\n /**\n * If button is selected. Used only for desktop and applies a selected class\n */\n selected?: boolean;\n onClick: React.MouseEventHandler<HTMLButtonElement>;\n\n badge?: boolean;\n /**\n * If the button is expected to have a tooltip. When false it will not set the event listeners\n *\n * defaults to false\n */\n hasTooltip?: boolean;\n /**\n * This text allows for a customized tooltip.\n *\n * When falsy, the tooltip will parse the tooltip form the aria-lable\n */\n tooltipText?: string;\n hasOpenDrawer?: boolean;\n /**\n * If the AppLayout is in mobile mode\n * Used to determine if and where to render tooltips\n */\n isMobile?: boolean;\n /**\n * set to true if the trigger button was used to open the last active drawer\n * this is also used to hide the tooltip should the focus be set programmatically\n * on focus from a drawer close using this\n */\n isForPreviousActiveDrawer?: boolean;\n /**\n * if the trigger button is for the split panel\n */\n isForSplitPanel?: boolean;\n tabIndex?: number | undefined;\n}\n\nfunction TriggerButton(\n {\n ariaLabel,\n className,\n iconName,\n iconSvg,\n ariaExpanded,\n ariaControls,\n onClick,\n testId,\n disabled = false,\n badge,\n selected = false,\n hasTooltip = false,\n tooltipText,\n hasOpenDrawer = false,\n isMobile = false,\n isForPreviousActiveDrawer = false,\n isForSplitPanel = false,\n }: TriggerButtonProps,\n ref: React.Ref<ButtonProps.Ref>\n) {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const tooltipValue = tooltipText ? tooltipText : ariaLabel ? ariaLabel : '';\n const [showTooltip, setShowTooltip] = useState<boolean>(false);\n const [suppressTooltip, setSupressTooltip] = useState<boolean>(false);\n\n const handleTriggerClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n event.stopPropagation(); // Stop the event from propagating to the badge icon\n setShowTooltip(false);\n setSupressTooltip(true);\n onClick(event);\n };\n\n const handleBlur = (keepSupressed = false) => {\n setSupressTooltip(keepSupressed);\n setShowTooltip(false);\n };\n\n const handlePointerEnter = () => {\n setSupressTooltip(false);\n setShowTooltip(true);\n };\n\n /**\n * Takes the drawer being closed and the data-shift-focus value from a close button on that drawer that persists\n * on the event relatedTarget to determine not to show the tooltip\n * @param event\n */\n const handleOnFocus = useCallback(\n (event: FocusEvent) => {\n let shouldShowTooltip = false;\n const eventWithRelatedTarget = event as any;\n const relatedTarget = eventWithRelatedTarget?.relatedTarget;\n const isFromAnotherTrigger = relatedTarget?.dataset?.shiftFocus === 'awsui-layout-drawer-trigger';\n if (\n (isForSplitPanel && !!relatedTarget) || // relatedTarget is null when split panel is closed\n (!isForSplitPanel &&\n (isFromAnotherTrigger || // for key navigation from another trigger button\n !isForPreviousActiveDrawer)) // for when the drawer was not opened recently\n ) {\n shouldShowTooltip = true;\n }\n setSupressTooltip(!shouldShowTooltip);\n setShowTooltip(true);\n },\n [\n // To assert reference equality check\n isForPreviousActiveDrawer,\n isForSplitPanel,\n ]\n );\n\n const tooltipVisible = useMemo(() => {\n return (\n hasTooltip &&\n showTooltip &&\n !suppressTooltip &&\n !!containerRef?.current &&\n tooltipValue &&\n !(isMobile && hasOpenDrawer)\n );\n }, [hasTooltip, showTooltip, containerRef, tooltipValue, isMobile, hasOpenDrawer, suppressTooltip]);\n\n useEffect(() => {\n if (hasTooltip && tooltipValue) {\n const close = () => {\n setShowTooltip(false);\n setSupressTooltip(false);\n };\n\n const shouldCloseTooltip = (event: PointerEvent) => {\n if (event.target && containerRef && (containerRef.current as any)?.contains(event.target as HTMLElement)) {\n return false;\n }\n return true;\n };\n\n const handlePointerDownEvent = (event: PointerEvent) => {\n if (shouldCloseTooltip(event)) {\n close();\n }\n };\n\n const handleKeyDownEvent = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n close();\n }\n };\n\n const wrapperDiv = containerRef.current;\n if (wrapperDiv) {\n const controller = new AbortController();\n wrapperDiv.addEventListener('pointerdown', handlePointerDownEvent, { signal: controller.signal });\n wrapperDiv.addEventListener('keydown', handleKeyDownEvent, { signal: controller.signal });\n\n return () => {\n controller.abort();\n };\n }\n }\n }, [containerRef, hasTooltip, tooltipValue]);\n\n useEffect(() => {\n if (tooltipVisible) {\n return registerTooltip(() => {\n setShowTooltip(false);\n setSupressTooltip(false);\n });\n }\n }, [tooltipVisible]);\n\n return (\n <div\n ref={containerRef}\n {...(hasTooltip && {\n onPointerEnter: () => handlePointerEnter(),\n onPointerLeave: () => handleBlur(true),\n onFocus: e => handleOnFocus(e as any),\n onBlur: () => handleBlur(true),\n })}\n className={styles['trigger-wrapper']}\n >\n <button\n aria-expanded={ariaExpanded}\n aria-controls={ariaControls}\n aria-haspopup={true}\n aria-label={ariaLabel}\n aria-disabled={disabled}\n disabled={disabled}\n className={clsx(\n styles.trigger,\n styles['trigger-button-styles'],\n {\n [styles.selected]: selected,\n [styles.badge]: badge,\n [testutilStyles['drawers-trigger-with-badge']]: badge,\n },\n className\n )}\n onClick={handleTriggerClick}\n ref={ref as Ref<HTMLButtonElement>}\n type=\"button\"\n data-testid={testId}\n data-shift-focus=\"awsui-layout-drawer-trigger\"\n >\n <span className={clsx(badge && clsx(styles['trigger-badge-wrapper'], styles['trigger-button-styles']))}>\n {(iconName || iconSvg) && <Icon name={iconName} svg={iconSvg} />}\n </span>\n </button>\n {badge && <div className={styles.dot} />}\n {tooltipVisible && (\n <Tooltip trackRef={containerRef} value={tooltipValue} className={testutilStyles['trigger-tooltip']} />\n )}\n </div>\n );\n}\n\nexport default React.forwardRef(TriggerButton);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid-defaults.d.ts","sourceRoot":"","sources":["../../../src/attribute-editor/grid-defaults.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,UAAU,EAAE,CAwH1E,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export const gridDefaults = {
|
|
2
|
+
1: [
|
|
3
|
+
{
|
|
4
|
+
breakpoint: 'xxs',
|
|
5
|
+
rows: [[3]],
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
rows: [[1]],
|
|
9
|
+
removeButton: {
|
|
10
|
+
ownRow: true,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
2: [
|
|
15
|
+
{
|
|
16
|
+
breakpoint: 'xs',
|
|
17
|
+
rows: [[3, 3]],
|
|
18
|
+
removeButton: {
|
|
19
|
+
width: 2,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
breakpoint: 'xxs',
|
|
24
|
+
rows: [[1, 1]],
|
|
25
|
+
removeButton: {
|
|
26
|
+
ownRow: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
rows: [[1], [1]],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
3: [
|
|
34
|
+
{
|
|
35
|
+
breakpoint: 'xs',
|
|
36
|
+
rows: [[3, 3, 3]],
|
|
37
|
+
removeButton: {
|
|
38
|
+
width: 3,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
breakpoint: 'xxs',
|
|
43
|
+
rows: [[1, 1], [1]],
|
|
44
|
+
removeButton: {
|
|
45
|
+
ownRow: true,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
rows: [[1], [1], [1]],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
4: [
|
|
53
|
+
{
|
|
54
|
+
breakpoint: 'xs',
|
|
55
|
+
rows: [[3, 3, 3, 3]],
|
|
56
|
+
removeButton: {
|
|
57
|
+
width: 4,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
breakpoint: 'xxs',
|
|
62
|
+
rows: [
|
|
63
|
+
[1, 1],
|
|
64
|
+
[1, 1],
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
rows: [[1], [1], [1], [1]],
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
5: [
|
|
72
|
+
{
|
|
73
|
+
breakpoint: 's',
|
|
74
|
+
rows: [[3, 3, 3, 3, 3]],
|
|
75
|
+
removeButton: {
|
|
76
|
+
width: 5,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
breakpoint: 'xs',
|
|
81
|
+
rows: [
|
|
82
|
+
[1, 1, 1],
|
|
83
|
+
[1, 1],
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
breakpoint: 'xxs',
|
|
88
|
+
rows: [[1, 1], [1, 1], [1]],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
rows: [[1], [1], [1], [1], [1]],
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
6: [
|
|
95
|
+
{
|
|
96
|
+
breakpoint: 's',
|
|
97
|
+
rows: [[3, 3, 3, 3, 3, 3]],
|
|
98
|
+
removeButton: {
|
|
99
|
+
width: 6,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
breakpoint: 'xs',
|
|
104
|
+
rows: [
|
|
105
|
+
[1, 1, 1],
|
|
106
|
+
[1, 1, 1],
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
breakpoint: 'xxs',
|
|
111
|
+
rows: [
|
|
112
|
+
[1, 1],
|
|
113
|
+
[1, 1],
|
|
114
|
+
[1, 1],
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
rows: [[1], [1], [1], [1], [1], [1]],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=grid-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid-defaults.js","sourceRoot":"","sources":["../../../src/attribute-editor/grid-defaults.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,YAAY,GAAsD;IAC7E,CAAC,EAAE;QACD;YACE,UAAU,EAAE,KAAK;YACjB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SACZ;QACD;YACE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACX,YAAY,EAAE;gBACZ,MAAM,EAAE,IAAI;aACb;SACF;KACF;IACD,CAAC,EAAE;QACD;YACE,UAAU,EAAE,IAAI;YAChB,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACd,YAAY,EAAE;gBACZ,KAAK,EAAE,CAAC;aACT;SACF;QACD;YACE,UAAU,EAAE,KAAK;YACjB,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC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ache-2.0\nimport { AttributeEditorProps } from './interfaces';\n\nexport const gridDefaults: Record<number, AttributeEditorProps.GridLayout[]> = {\n 1: [\n {\n breakpoint: 'xxs',\n rows: [[3]],\n },\n {\n rows: [[1]],\n removeButton: {\n ownRow: true,\n },\n },\n ],\n 2: [\n {\n breakpoint: 'xs',\n rows: [[3, 3]],\n removeButton: {\n width: 2,\n },\n },\n {\n breakpoint: 'xxs',\n rows: [[1, 1]],\n removeButton: {\n ownRow: true,\n },\n },\n {\n rows: [[1], [1]],\n },\n ],\n 3: [\n {\n breakpoint: 'xs',\n rows: [[3, 3, 3]],\n removeButton: {\n width: 3,\n },\n },\n {\n breakpoint: 'xxs',\n rows: [[1, 1], [1]],\n removeButton: {\n ownRow: true,\n },\n },\n {\n rows: [[1], [1], [1]],\n },\n ],\n 4: [\n {\n breakpoint: 'xs',\n rows: [[3, 3, 3, 3]],\n removeButton: {\n width: 4,\n },\n },\n {\n breakpoint: 'xxs',\n rows: [\n [1, 1],\n [1, 1],\n ],\n },\n {\n rows: [[1], [1], [1], [1]],\n },\n ],\n 5: [\n {\n breakpoint: 's',\n rows: [[3, 3, 3, 3, 3]],\n removeButton: {\n width: 5,\n },\n },\n {\n breakpoint: 'xs',\n rows: [\n [1, 1, 1],\n [1, 1],\n ],\n },\n {\n breakpoint: 'xxs',\n rows: [[1, 1], [1, 1], [1]],\n },\n {\n rows: [[1], [1], [1], [1], [1]],\n },\n ],\n 6: [\n {\n breakpoint: 's',\n rows: [[3, 3, 3, 3, 3, 3]],\n removeButton: {\n width: 6,\n },\n },\n {\n breakpoint: 'xs',\n rows: [\n [1, 1, 1],\n [1, 1, 1],\n ],\n },\n {\n breakpoint: 'xxs',\n rows: [\n [1, 1],\n [1, 1],\n [1, 1],\n ],\n },\n {\n rows: [[1], [1], [1], [1], [1], [1]],\n },\n ],\n};\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ButtonDropdownProps } from '../button-dropdown/interfaces';
|
|
2
3
|
import { BaseComponentProps } from '../internal/base-component';
|
|
4
|
+
import { Breakpoint as InternalBreakpoint } from '../internal/breakpoints';
|
|
3
5
|
import { NonCancelableEventHandler } from '../internal/events';
|
|
4
6
|
export interface AttributeEditorForwardRefType {
|
|
5
7
|
<T>(props: AttributeEditorProps<T> & {
|
|
@@ -33,6 +35,13 @@ export declare namespace AttributeEditorProps {
|
|
|
33
35
|
*/
|
|
34
36
|
focusAddButton(): void;
|
|
35
37
|
}
|
|
38
|
+
interface RowActionsProps<T> {
|
|
39
|
+
item: T;
|
|
40
|
+
itemIndex: number;
|
|
41
|
+
ref: React.Ref<ButtonDropdownProps.Ref>;
|
|
42
|
+
breakpoint: Breakpoint | null;
|
|
43
|
+
ownRow: boolean;
|
|
44
|
+
}
|
|
36
45
|
interface I18nStrings<T = any> {
|
|
37
46
|
errorIconAriaLabel?: string;
|
|
38
47
|
warningIconAriaLabel?: string;
|
|
@@ -42,6 +51,15 @@ export declare namespace AttributeEditorProps {
|
|
|
42
51
|
*/
|
|
43
52
|
removeButtonAriaLabel?: (item: T) => string;
|
|
44
53
|
}
|
|
54
|
+
type Breakpoint = InternalBreakpoint;
|
|
55
|
+
interface GridLayout {
|
|
56
|
+
breakpoint?: Breakpoint;
|
|
57
|
+
rows: ReadonlyArray<ReadonlyArray<number>>;
|
|
58
|
+
removeButton?: {
|
|
59
|
+
ownRow?: boolean;
|
|
60
|
+
width?: number | 'auto';
|
|
61
|
+
};
|
|
62
|
+
}
|
|
45
63
|
}
|
|
46
64
|
export interface AttributeEditorProps<T> extends BaseComponentProps {
|
|
47
65
|
/**
|
|
@@ -88,6 +106,7 @@ export interface AttributeEditorProps<T> extends BaseComponentProps {
|
|
|
88
106
|
addButtonVariant?: AttributeEditorProps.AddButtonVariant;
|
|
89
107
|
/**
|
|
90
108
|
* Defines the editor configuration. Each object in the array represents one form field in the row.
|
|
109
|
+
* If more than 6 attributes are specified, a `gridLayout` must be provided.
|
|
91
110
|
*
|
|
92
111
|
* * `label` (ReactNode) - Text label for the form field.
|
|
93
112
|
* * `info` (ReactNode) - Info link for the form field.
|
|
@@ -97,10 +116,38 @@ export interface AttributeEditorProps<T> extends BaseComponentProps {
|
|
|
97
116
|
* It renders the form field in a warning state if the returned value is not `null` or `undefined`.
|
|
98
117
|
* * `constraintText` ((item, itemIndex) => ReactNode) - Text to display as a constraint message below the field.
|
|
99
118
|
* * `control` ((item, itemIndex) => ReactNode) - A control to use as the input for the field.
|
|
100
|
-
*
|
|
101
|
-
* A maximum of four fields are supported.
|
|
102
119
|
*/
|
|
103
120
|
definition: ReadonlyArray<AttributeEditorProps.FieldDefinition<T>>;
|
|
121
|
+
/**
|
|
122
|
+
* Optionally specifies the layout of the attributes. By default, all attributes will be
|
|
123
|
+
* equally spaced and wrapped into multiple rows on smaller viewports.
|
|
124
|
+
*
|
|
125
|
+
* A `gridLayout` is an array of breakpoint definitions. Each definition consists of:
|
|
126
|
+
* - `rows` (`number[][]`): the rows in which to display the attributes. Each row consists of a list of numbers indicating
|
|
127
|
+
* the relative width of each attribute. For example, `[[1, 1, 1, 1]]` is a single row of four evenly-spaced attributes,
|
|
128
|
+
* or `[[1, 2], [1, 1, 1]]` splits five attributes onto two rows.
|
|
129
|
+
* - `breakpoint` (`string`): optionally specifies that the given entry should only be used when at least that much width is available.
|
|
130
|
+
* - `removeButton`: optionally configures the remove (or row action) button placement. If this is not provided, the button will be
|
|
131
|
+
* placed at the end of a single row, or below if multiple rows are present. The `removeButton` property supports contains two properties:
|
|
132
|
+
* - `ownRow` (`boolean`): forces the remove button onto its own row.
|
|
133
|
+
* - `width` (`number | 'auto'`): a number indicating the relative width (equivalent to a `rows` entry), or 'auto' to fit to the button width.
|
|
134
|
+
*/
|
|
135
|
+
gridLayout?: ReadonlyArray<AttributeEditorProps.GridLayout>;
|
|
136
|
+
/**
|
|
137
|
+
* Specifies a custom action trigger for each row, in place of the remove button.
|
|
138
|
+
* Only button and button dropdown components are supported.
|
|
139
|
+
* If you provide this, `removeButtonText`, `removeButtonAriaLabel`,
|
|
140
|
+
* and `onRemoveButtonClick` will be ignored.
|
|
141
|
+
* The trigger must be given the provided `ref` in order for `focusRemoveButton`
|
|
142
|
+
* to work.
|
|
143
|
+
* The function receives the following properties:
|
|
144
|
+
* - `item`: The item being rendered in the current row.
|
|
145
|
+
* - `itemIndex` (`number`): The index of the item.
|
|
146
|
+
* - `ref` (`ReactRef`): A React ref that should be passed to the rendered button.
|
|
147
|
+
* - `breakpoint` (`Breakpoint`): The current breakpoint, for responsive behavior.
|
|
148
|
+
* - `ownRow` (`boolean`): Whether the button is rendered on its own row.
|
|
149
|
+
*/
|
|
150
|
+
customRowActions?: (props: AttributeEditorProps.RowActionsProps<T>) => React.ReactNode;
|
|
104
151
|
/**
|
|
105
152
|
* Called when add button is clicked.
|
|
106
153
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/attribute-editor/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAY/D,MAAM,WAAW,6BAA6B;IAC5C,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG;QAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAA;KAAE,GAAG,GAAG,CAAC,OAAO,CAAC;CAClG;AAED,yBAAiB,oBAAoB,CAAC;IACpC,UAAiB,uBAAuB,CAAC,CAAC;QACxC,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC;KACpB;IAED,KAAY,eAAe,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;IAC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AS,CAAC;IAEvF;;OAEG;IACH,gBAAgB,CAAC,EAAE,yBAAyB,CAAC;IAE7C;;;OAGG;IACH,mBAAmB,CAAC,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,uBAAuB,CAAC,CAAC;IAE9F;;OAEG;IACH,WAAW,CAAC,EAAE,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CACnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/attribute-editor/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\n\nimport { BaseComponentProps } from '../internal/base-component';\nimport { NonCancelableEventHandler } from '../internal/events';\n\n/*\n * HACK: Cast the component to a named parametrized interface.\n *\n * This lets us use React.forwardRef and still let the component have type\n * parameters, and the naming convention lets the documenter know that this is\n * a forwardRef-wrapped component.\n *\n * We don't need to expose this type to customers because it's just a simple\n * function type.\n */\nexport interface AttributeEditorForwardRefType {\n <T>(props: AttributeEditorProps<T> & { ref?: React.Ref<AttributeEditorProps.Ref> }): JSX.Element;\n}\n\nexport namespace AttributeEditorProps {\n export interface IsItemRemovableFunction<T> {\n (item: T): boolean;\n }\n\n export type FieldRenderable<T> = (item: T, itemIndex: number) => React.ReactNode;\n export interface FieldDefinition<T> {\n label?: React.ReactNode;\n info?: React.ReactNode;\n control?: FieldRenderable<T> | React.ReactNode;\n errorText?: FieldRenderable<T> | React.ReactNode;\n warningText?: FieldRenderable<T> | React.ReactNode;\n constraintText?: FieldRenderable<T> | React.ReactNode;\n }\n\n export type AddButtonVariant = 'normal' | 'inline-link';\n\n export interface RemoveButtonClickDetail {\n itemIndex: number;\n }\n\n export interface Ref {\n /**\n * Focuses the 'remove' button for the given row index.\n */\n focusRemoveButton(itemIndex: number): void;\n /**\n * Focuses the 'add' button. Use this, for example, after a user removes the last row.\n */\n focusAddButton(): void;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n export interface I18nStrings<T = any> {\n errorIconAriaLabel?: string;\n warningIconAriaLabel?: string;\n itemRemovedAriaLive?: string;\n\n /**\n * @deprecated Use `removeButtonAriaLabel` on the component instead.\n */\n removeButtonAriaLabel?: (item: T) => string;\n }\n}\n\nexport interface AttributeEditorProps<T> extends BaseComponentProps {\n /**\n * Displayed when there are no items to display.\n */\n empty?: React.ReactNode;\n\n /**\n * Displayed below the add button. Use it for additional information related to the attribute editor.\n */\n additionalInfo?: React.ReactNode;\n\n /**\n * Specifies the text that's displayed in the add button.\n */\n addButtonText: string;\n\n /**\n * Specifies the text that's displayed in the remove button.\n * @i18n\n */\n removeButtonText?: string;\n\n /**\n * Adds an `aria-label` to the remove button.\n */\n removeButtonAriaLabel?: (item: T) => string;\n\n /**\n * Specifies the items that serve as the data source for all rows.\n * The display of a row is handled by the `definition` property.\n */\n items?: ReadonlyArray<T>;\n\n /**\n * Function that determines whether an item is removable. When this function returns `false`, the remove\n * button is not rendered and the user can't remove the item.\n * By default, all items are removable.\n */\n isItemRemovable?: AttributeEditorProps.IsItemRemovableFunction<T>;\n\n /**\n * Determines whether the add button is disabled.\n */\n disableAddButton?: boolean;\n\n /**\n * Specifies the variant to use for the add button. By default a normal button is used.\n * Use `inline-link` when using an attribute editor nested inside complex attribute editing\n * with expandable sections.\n */\n addButtonVariant?: AttributeEditorProps.AddButtonVariant;\n\n /**\n * Defines the editor configuration. Each object in the array represents one form field in the row.\n *\n * * `label` (ReactNode) - Text label for the form field.\n * * `info` (ReactNode) - Info link for the form field.\n * * `errorText` ((item, itemIndex) => ReactNode) - Error message text to display as a control validation message.\n * It renders the form field as invalid if the returned value is not `null` or `undefined`.\n * * `warningText` ((item, itemIndex) => ReactNode) - Warning message text to display as a control validation message.\n * It renders the form field in a warning state if the returned value is not `null` or `undefined`.\n * * `constraintText` ((item, itemIndex) => ReactNode) - Text to display as a constraint message below the field.\n * * `control` ((item, itemIndex) => ReactNode) - A control to use as the input for the field.\n *\n * A
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/attribute-editor/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\n\nimport { ButtonDropdownProps } from '../button-dropdown/interfaces';\nimport { BaseComponentProps } from '../internal/base-component';\nimport { Breakpoint as InternalBreakpoint } from '../internal/breakpoints';\nimport { NonCancelableEventHandler } from '../internal/events';\n\n/*\n * HACK: Cast the component to a named parametrized interface.\n *\n * This lets us use React.forwardRef and still let the component have type\n * parameters, and the naming convention lets the documenter know that this is\n * a forwardRef-wrapped component.\n *\n * We don't need to expose this type to customers because it's just a simple\n * function type.\n */\nexport interface AttributeEditorForwardRefType {\n <T>(props: AttributeEditorProps<T> & { ref?: React.Ref<AttributeEditorProps.Ref> }): JSX.Element;\n}\n\nexport namespace AttributeEditorProps {\n export interface IsItemRemovableFunction<T> {\n (item: T): boolean;\n }\n\n export type FieldRenderable<T> = (item: T, itemIndex: number) => React.ReactNode;\n export interface FieldDefinition<T> {\n label?: React.ReactNode;\n info?: React.ReactNode;\n control?: FieldRenderable<T> | React.ReactNode;\n errorText?: FieldRenderable<T> | React.ReactNode;\n warningText?: FieldRenderable<T> | React.ReactNode;\n constraintText?: FieldRenderable<T> | React.ReactNode;\n }\n\n export type AddButtonVariant = 'normal' | 'inline-link';\n\n export interface RemoveButtonClickDetail {\n itemIndex: number;\n }\n\n export interface Ref {\n /**\n * Focuses the 'remove' button for the given row index.\n */\n focusRemoveButton(itemIndex: number): void;\n /**\n * Focuses the 'add' button. Use this, for example, after a user removes the last row.\n */\n focusAddButton(): void;\n }\n\n export interface RowActionsProps<T> {\n item: T;\n itemIndex: number;\n ref: React.Ref<ButtonDropdownProps.Ref>;\n breakpoint: Breakpoint | null;\n ownRow: boolean;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n export interface I18nStrings<T = any> {\n errorIconAriaLabel?: string;\n warningIconAriaLabel?: string;\n itemRemovedAriaLive?: string;\n\n /**\n * @deprecated Use `removeButtonAriaLabel` on the component instead.\n */\n removeButtonAriaLabel?: (item: T) => string;\n }\n\n export type Breakpoint = InternalBreakpoint;\n\n export interface GridLayout {\n breakpoint?: Breakpoint;\n rows: ReadonlyArray<ReadonlyArray<number>>;\n removeButton?: {\n ownRow?: boolean;\n width?: number | 'auto';\n };\n }\n}\n\nexport interface AttributeEditorProps<T> extends BaseComponentProps {\n /**\n * Displayed when there are no items to display.\n */\n empty?: React.ReactNode;\n\n /**\n * Displayed below the add button. Use it for additional information related to the attribute editor.\n */\n additionalInfo?: React.ReactNode;\n\n /**\n * Specifies the text that's displayed in the add button.\n */\n addButtonText: string;\n\n /**\n * Specifies the text that's displayed in the remove button.\n * @i18n\n */\n removeButtonText?: string;\n\n /**\n * Adds an `aria-label` to the remove button.\n */\n removeButtonAriaLabel?: (item: T) => string;\n\n /**\n * Specifies the items that serve as the data source for all rows.\n * The display of a row is handled by the `definition` property.\n */\n items?: ReadonlyArray<T>;\n\n /**\n * Function that determines whether an item is removable. When this function returns `false`, the remove\n * button is not rendered and the user can't remove the item.\n * By default, all items are removable.\n */\n isItemRemovable?: AttributeEditorProps.IsItemRemovableFunction<T>;\n\n /**\n * Determines whether the add button is disabled.\n */\n disableAddButton?: boolean;\n\n /**\n * Specifies the variant to use for the add button. By default a normal button is used.\n * Use `inline-link` when using an attribute editor nested inside complex attribute editing\n * with expandable sections.\n */\n addButtonVariant?: AttributeEditorProps.AddButtonVariant;\n\n /**\n * Defines the editor configuration. Each object in the array represents one form field in the row.\n * If more than 6 attributes are specified, a `gridLayout` must be provided.\n *\n * * `label` (ReactNode) - Text label for the form field.\n * * `info` (ReactNode) - Info link for the form field.\n * * `errorText` ((item, itemIndex) => ReactNode) - Error message text to display as a control validation message.\n * It renders the form field as invalid if the returned value is not `null` or `undefined`.\n * * `warningText` ((item, itemIndex) => ReactNode) - Warning message text to display as a control validation message.\n * It renders the form field in a warning state if the returned value is not `null` or `undefined`.\n * * `constraintText` ((item, itemIndex) => ReactNode) - Text to display as a constraint message below the field.\n * * `control` ((item, itemIndex) => ReactNode) - A control to use as the input for the field.\n */\n definition: ReadonlyArray<AttributeEditorProps.FieldDefinition<T>>;\n\n /**\n * Optionally specifies the layout of the attributes. By default, all attributes will be\n * equally spaced and wrapped into multiple rows on smaller viewports.\n *\n * A `gridLayout` is an array of breakpoint definitions. Each definition consists of:\n * - `rows` (`number[][]`): the rows in which to display the attributes. Each row consists of a list of numbers indicating\n * the relative width of each attribute. For example, `[[1, 1, 1, 1]]` is a single row of four evenly-spaced attributes,\n * or `[[1, 2], [1, 1, 1]]` splits five attributes onto two rows.\n * - `breakpoint` (`string`): optionally specifies that the given entry should only be used when at least that much width is available.\n * - `removeButton`: optionally configures the remove (or row action) button placement. If this is not provided, the button will be\n * placed at the end of a single row, or below if multiple rows are present. The `removeButton` property supports contains two properties:\n * - `ownRow` (`boolean`): forces the remove button onto its own row.\n * - `width` (`number | 'auto'`): a number indicating the relative width (equivalent to a `rows` entry), or 'auto' to fit to the button width.\n */\n gridLayout?: ReadonlyArray<AttributeEditorProps.GridLayout>;\n\n /**\n * Specifies a custom action trigger for each row, in place of the remove button.\n * Only button and button dropdown components are supported.\n * If you provide this, `removeButtonText`, `removeButtonAriaLabel`,\n * and `onRemoveButtonClick` will be ignored.\n * The trigger must be given the provided `ref` in order for `focusRemoveButton`\n * to work.\n * The function receives the following properties:\n * - `item`: The item being rendered in the current row.\n * - `itemIndex` (`number`): The index of the item.\n * - `ref` (`ReactRef`): A React ref that should be passed to the rendered button.\n * - `breakpoint` (`Breakpoint`): The current breakpoint, for responsive behavior.\n * - `ownRow` (`boolean`): Whether the button is rendered on its own row.\n */\n customRowActions?: (props: AttributeEditorProps.RowActionsProps<T>) => React.ReactNode;\n\n /**\n * Called when add button is clicked.\n */\n onAddButtonClick?: NonCancelableEventHandler;\n\n /**\n * Called when remove button is clicked.\n * The event `detail` contains the index of the corresponding item.\n */\n onRemoveButtonClick?: NonCancelableEventHandler<AttributeEditorProps.RemoveButtonClickDetail>;\n\n /**\n * An object containing all the necessary localized strings required by the component.\n */\n i18nStrings?: AttributeEditorProps.I18nStrings<T>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/attribute-editor/internal.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/attribute-editor/internal.tsx"],"names":[],"mappings":"AAkBA,OAAO,EAAE,6BAA6B,EAAwB,MAAM,cAAc,CAAC;AAQnF,QAAA,MAAM,uBAAuB,+BAwJK,CAAC;AAEnC,eAAe,uBAAuB,CAAC"}
|
|
@@ -3,20 +3,21 @@ import { __rest } from "tslib";
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import React, { useImperativeHandle, useRef, useState } from 'react';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
|
-
import InternalBox from '../box/internal';
|
|
7
6
|
import { InternalButton } from '../button/internal';
|
|
8
7
|
import { getBaseProps } from '../internal/base-component';
|
|
8
|
+
import { matchBreakpointMapping } from '../internal/breakpoints';
|
|
9
9
|
import { useContainerBreakpoints } from '../internal/hooks/container-queries';
|
|
10
10
|
import { useMergeRefs } from '../internal/hooks/use-merge-refs';
|
|
11
11
|
import { usePrevious } from '../internal/hooks/use-previous';
|
|
12
12
|
import { useUniqueId } from '../internal/hooks/use-unique-id';
|
|
13
13
|
import InternalLiveRegion from '../live-region/internal';
|
|
14
14
|
import { AdditionalInfo } from './additional-info';
|
|
15
|
+
import { gridDefaults } from './grid-defaults';
|
|
15
16
|
import { Row } from './row';
|
|
17
|
+
import { getGridTemplateColumns } from './utils';
|
|
16
18
|
import styles from './styles.css.js';
|
|
17
19
|
const InternalAttributeEditor = React.forwardRef((_a, ref) => {
|
|
18
|
-
var { additionalInfo, disableAddButton, definition, items, isItemRemovable = () => true, empty, addButtonText, addButtonVariant = 'normal', removeButtonText, removeButtonAriaLabel, i18nStrings, onAddButtonClick, onRemoveButtonClick, __internalRootRef = null } = _a, props = __rest(_a, ["additionalInfo", "disableAddButton", "definition", "items", "isItemRemovable", "empty", "addButtonText", "addButtonVariant", "removeButtonText", "removeButtonAriaLabel", "i18nStrings", "onAddButtonClick", "onRemoveButtonClick", "__internalRootRef"]);
|
|
19
|
-
const [breakpoint, breakpointRef] = useContainerBreakpoints(['default', 'xxs', 'xs']);
|
|
20
|
+
var { additionalInfo, disableAddButton, definition = [{}], gridLayout, items, isItemRemovable = () => true, empty, addButtonText, addButtonVariant = 'normal', removeButtonText, removeButtonAriaLabel, customRowActions, i18nStrings, onAddButtonClick, onRemoveButtonClick, __internalRootRef = null } = _a, props = __rest(_a, ["additionalInfo", "disableAddButton", "definition", "gridLayout", "items", "isItemRemovable", "empty", "addButtonText", "addButtonVariant", "removeButtonText", "removeButtonAriaLabel", "customRowActions", "i18nStrings", "onAddButtonClick", "onRemoveButtonClick", "__internalRootRef"]);
|
|
20
21
|
const removeButtonRefs = useRef([]);
|
|
21
22
|
const addButtonRef = useRef(null);
|
|
22
23
|
const wasNonEmpty = useRef(false);
|
|
@@ -34,7 +35,6 @@ const InternalAttributeEditor = React.forwardRef((_a, ref) => {
|
|
|
34
35
|
(_a = addButtonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
35
36
|
},
|
|
36
37
|
}));
|
|
37
|
-
const mergedRef = useMergeRefs(breakpointRef, __internalRootRef);
|
|
38
38
|
const additionalInfoId = useUniqueId('attribute-editor-info');
|
|
39
39
|
const infoAriaDescribedBy = additionalInfo ? additionalInfoId : undefined;
|
|
40
40
|
const prevItemsLength = usePrevious(items.length);
|
|
@@ -48,17 +48,37 @@ const InternalAttributeEditor = React.forwardRef((_a, ref) => {
|
|
|
48
48
|
// we only want to announce when the number of items decreases (i.e. when an item is removed)
|
|
49
49
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
50
50
|
}, [items, i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.itemRemovedAriaLive]);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
if (!gridLayout) {
|
|
52
|
+
gridLayout = gridDefaults[definition.length];
|
|
53
|
+
if (!gridLayout) {
|
|
54
|
+
console.warn('AttributeEditor', '`gridLayout` is required for more than 6 attributes. Cannot render.');
|
|
55
|
+
gridLayout = [];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const gridLayoutBreakpoints = gridLayout.reduce((acc, layout) => (Object.assign(Object.assign({}, acc), { [layout.breakpoint || 'default']: layout })), {});
|
|
59
|
+
const [breakpoint, breakpointRef] = useContainerBreakpoints(Object.keys(gridLayoutBreakpoints));
|
|
60
|
+
const mergedRef = useMergeRefs(breakpointRef, __internalRootRef);
|
|
61
|
+
const gridLayoutForBreakpoint = matchBreakpointMapping(gridLayoutBreakpoints, breakpoint || 'default');
|
|
62
|
+
if (!gridLayoutForBreakpoint) {
|
|
63
|
+
console.warn('AttributeEditor', `No \`gridLayout\` entry found for breakpoint ${breakpoint}. Cannot render.`);
|
|
64
|
+
return React.createElement("div", null);
|
|
65
|
+
}
|
|
66
|
+
const totalColumnsInLayout = gridLayoutForBreakpoint.rows.reduce((total, columns) => total + columns.length, 0);
|
|
67
|
+
if (totalColumnsInLayout !== definition.length) {
|
|
68
|
+
console.warn('AttributeEditor', `Incorrect number of columns in layout (${totalColumnsInLayout}) for definition (${definition.length}). Cannot render.`);
|
|
69
|
+
return React.createElement("div", null);
|
|
70
|
+
}
|
|
71
|
+
return (React.createElement("div", Object.assign({}, baseProps, { ref: mergedRef, className: clsx(baseProps.className, styles.root), style: { gridTemplateColumns: getGridTemplateColumns(gridLayoutForBreakpoint) } }),
|
|
72
|
+
isEmpty && React.createElement("div", { className: clsx(styles.empty, wasNonEmpty.current && styles['empty-appear']) }, empty),
|
|
73
|
+
items.map((item, index) => (React.createElement(Row, { key: index, index: index, breakpoint: breakpoint, layout: gridLayoutForBreakpoint, item: item, definition: definition, i18nStrings: i18nStrings, removable: isItemRemovable(item), removeButtonText: removeButtonText, removeButtonRefs: removeButtonRefs.current, customRowActions: customRowActions, onRemoveButtonClick: onRemoveButtonClick, removeButtonAriaLabel: removeButtonAriaLabel }))),
|
|
74
|
+
React.createElement("div", { className: styles['add-row'] },
|
|
75
|
+
React.createElement(InternalButton, { className: styles['add-button'], disabled: disableAddButton,
|
|
76
|
+
// Using aria-disabled="true" and tabindex="-1" instead of "disabled"
|
|
77
|
+
// because focus can be dynamically moved to this button by calling
|
|
78
|
+
// `focusAddButton()` on the ref.
|
|
79
|
+
__nativeAttributes: disableAddButton ? { tabIndex: -1 } : {}, __focusable: true, onClick: onAddButtonClick, formAction: "none", ref: addButtonRef, ariaDescribedby: infoAriaDescribedBy, variant: addButtonVariant, iconName: addButtonVariant === 'inline-link' ? 'add-plus' : undefined }, addButtonText),
|
|
80
|
+
React.createElement(InternalLiveRegion, { "data-testid": "removal-announcement", tagName: "span", hidden: true, delay: 5, key: items.length }, removalAnnouncement),
|
|
81
|
+
!!additionalInfo && React.createElement(AdditionalInfo, { id: infoAriaDescribedBy }, additionalInfo))));
|
|
62
82
|
});
|
|
63
83
|
export default InternalAttributeEditor;
|
|
64
84
|
//# sourceMappingURL=internal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/attribute-editor/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,mBAAmB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,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a,CACC;QACjB,oBAAC,kBAAkB,mBACL,sBAAsB,EAClC,OAAO,EAAC,MAAM,EACd,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,CAAC,EACR,GAAG,EAAE,KAAK,CAAC,MAAM,IAEhB,mBAAmB,CACD;QACpB,CAAC,CAAC,cAAc,IAAI,oBAAC,cAAc,IAAC,EAAE,EAAE,mBAAmB,IAAG,cAAc,CAAkB,CAC3F,CACP,CAAC;AACJ,CAAC,CAC+B,CAAC;AAEnC,eAAe,uBAAuB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useImperativeHandle, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport InternalBox from '../box/internal';\nimport { ButtonProps } from '../button/interfaces';\nimport { InternalButton } from '../button/internal';\nimport { getBaseProps } from '../internal/base-component';\nimport { useContainerBreakpoints } from '../internal/hooks/container-queries';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { usePrevious } from '../internal/hooks/use-previous';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { SomeRequired } from '../internal/types';\nimport InternalLiveRegion from '../live-region/internal';\nimport { AdditionalInfo } from './additional-info';\nimport { AttributeEditorForwardRefType, AttributeEditorProps } from './interfaces';\nimport { Row } from './row';\n\nimport styles from './styles.css.js';\n\ntype InternalAttributeEditorProps<T> = SomeRequired<AttributeEditorProps<T>, 'items'> & InternalBaseComponentProps;\n\nconst InternalAttributeEditor = React.forwardRef(\n <T,>(\n {\n additionalInfo,\n disableAddButton,\n definition,\n items,\n isItemRemovable = () => true,\n empty,\n addButtonText,\n addButtonVariant = 'normal',\n removeButtonText,\n removeButtonAriaLabel,\n i18nStrings,\n onAddButtonClick,\n onRemoveButtonClick,\n __internalRootRef = null,\n ...props\n }: InternalAttributeEditorProps<T>,\n ref: React.Ref<AttributeEditorProps.Ref>\n ) => {\n const [breakpoint, breakpointRef] = useContainerBreakpoints(['default', 'xxs', 'xs']);\n const removeButtonRefs = useRef<Array<ButtonProps.Ref | undefined>>([]);\n const addButtonRef = useRef<ButtonProps.Ref>(null);\n const wasNonEmpty = useRef<boolean>(false);\n const [removalAnnouncement, setRemovalAnnouncement] = useState<string>('');\n\n const baseProps = getBaseProps(props);\n const isEmpty = items && items.length === 0;\n\n wasNonEmpty.current = wasNonEmpty.current || !isEmpty;\n\n useImperativeHandle(ref, () => ({\n focusRemoveButton(rowIndex: number) {\n removeButtonRefs.current[rowIndex]?.focus();\n },\n focusAddButton() {\n addButtonRef.current?.focus();\n },\n }));\n\n const mergedRef = useMergeRefs(breakpointRef, __internalRootRef);\n\n const additionalInfoId = useUniqueId('attribute-editor-info');\n const infoAriaDescribedBy = additionalInfo ? additionalInfoId : undefined;\n\n const prevItemsLength = usePrevious(items.length);\n\n React.useEffect(() => {\n if (prevItemsLength && prevItemsLength > items.length && i18nStrings?.itemRemovedAriaLive) {\n setRemovalAnnouncement(i18nStrings.itemRemovedAriaLive);\n } else {\n setRemovalAnnouncement('');\n }\n // we only want to announce when the number of items decreases (i.e. when an item is removed)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [items, i18nStrings?.itemRemovedAriaLive]);\n\n return (\n <div {...baseProps} ref={mergedRef} className={clsx(baseProps.className, styles.root)}>\n <InternalBox margin={{ bottom: 'l' }}>\n {isEmpty && <div className={clsx(styles.empty, wasNonEmpty.current && styles['empty-appear'])}>{empty}</div>}\n {items.map((item, index) => (\n <Row<T>\n key={index}\n index={index}\n breakpoint={breakpoint}\n item={item}\n definition={definition}\n i18nStrings={i18nStrings}\n removable={isItemRemovable(item)}\n removeButtonText={removeButtonText}\n removeButtonRefs={removeButtonRefs.current}\n onRemoveButtonClick={onRemoveButtonClick}\n removeButtonAriaLabel={removeButtonAriaLabel}\n />\n ))}\n </InternalBox>\n\n <InternalButton\n className={styles['add-button']}\n disabled={disableAddButton}\n // Using aria-disabled=\"true\" and tabindex=\"-1\" instead of \"disabled\"\n // because focus can be dynamically moved to this button by calling\n // `focusAddButton()` on the ref.\n __nativeAttributes={disableAddButton ? { tabIndex: -1 } : {}}\n __focusable={true}\n onClick={onAddButtonClick}\n formAction=\"none\"\n ref={addButtonRef}\n ariaDescribedby={infoAriaDescribedBy}\n variant={addButtonVariant}\n iconName={addButtonVariant === 'inline-link' ? 'add-plus' : undefined}\n >\n {addButtonText}\n </InternalButton>\n <InternalLiveRegion\n data-testid=\"removal-announcement\"\n tagName=\"span\"\n hidden={true}\n delay={5}\n key={items.length}\n >\n {removalAnnouncement}\n </InternalLiveRegion>\n {!!additionalInfo && <AdditionalInfo id={infoAriaDescribedBy}>{additionalInfo}</AdditionalInfo>}\n </div>\n );\n }\n) as AttributeEditorForwardRefType;\n\nexport default InternalAttributeEditor;\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/attribute-editor/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,mBAAmB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAE9E,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,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port React, { useImperativeHandle, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { ButtonProps } from '../button/interfaces';\nimport { InternalButton } from '../button/internal';\nimport { getBaseProps } from '../internal/base-component';\nimport { matchBreakpointMapping } from '../internal/breakpoints';\nimport { useContainerBreakpoints } from '../internal/hooks/container-queries';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { usePrevious } from '../internal/hooks/use-previous';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { SomeRequired } from '../internal/types';\nimport InternalLiveRegion from '../live-region/internal';\nimport { AdditionalInfo } from './additional-info';\nimport { gridDefaults } from './grid-defaults';\nimport { AttributeEditorForwardRefType, AttributeEditorProps } from './interfaces';\nimport { Row } from './row';\nimport { getGridTemplateColumns } from './utils';\n\nimport styles from './styles.css.js';\n\ntype InternalAttributeEditorProps<T> = SomeRequired<AttributeEditorProps<T>, 'items'> & InternalBaseComponentProps;\n\nconst InternalAttributeEditor = React.forwardRef(\n <T,>(\n {\n additionalInfo,\n disableAddButton,\n definition = [{}],\n gridLayout,\n items,\n isItemRemovable = () => true,\n empty,\n addButtonText,\n addButtonVariant = 'normal',\n removeButtonText,\n removeButtonAriaLabel,\n customRowActions,\n i18nStrings,\n onAddButtonClick,\n onRemoveButtonClick,\n __internalRootRef = null,\n ...props\n }: InternalAttributeEditorProps<T>,\n ref: React.Ref<AttributeEditorProps.Ref>\n ) => {\n const removeButtonRefs = useRef<Array<ButtonProps.Ref | undefined>>([]);\n const addButtonRef = useRef<ButtonProps.Ref>(null);\n const wasNonEmpty = useRef<boolean>(false);\n const [removalAnnouncement, setRemovalAnnouncement] = useState<string>('');\n\n const baseProps = getBaseProps(props);\n const isEmpty = items && items.length === 0;\n\n wasNonEmpty.current = wasNonEmpty.current || !isEmpty;\n\n useImperativeHandle(ref, () => ({\n focusRemoveButton(rowIndex: number) {\n removeButtonRefs.current[rowIndex]?.focus();\n },\n focusAddButton() {\n addButtonRef.current?.focus();\n },\n }));\n\n const additionalInfoId = useUniqueId('attribute-editor-info');\n const infoAriaDescribedBy = additionalInfo ? additionalInfoId : undefined;\n\n const prevItemsLength = usePrevious(items.length);\n\n React.useEffect(() => {\n if (prevItemsLength && prevItemsLength > items.length && i18nStrings?.itemRemovedAriaLive) {\n setRemovalAnnouncement(i18nStrings.itemRemovedAriaLive);\n } else {\n setRemovalAnnouncement('');\n }\n // we only want to announce when the number of items decreases (i.e. when an item is removed)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [items, i18nStrings?.itemRemovedAriaLive]);\n\n if (!gridLayout) {\n gridLayout = gridDefaults[definition.length];\n if (!gridLayout) {\n console.warn('AttributeEditor', '`gridLayout` is required for more than 6 attributes. Cannot render.');\n gridLayout = [];\n }\n }\n\n const gridLayoutBreakpoints = gridLayout.reduce(\n (acc, layout) => ({\n ...acc,\n [layout.breakpoint || 'default']: layout,\n }),\n {} as Record<AttributeEditorProps.Breakpoint, AttributeEditorProps.GridLayout>\n );\n\n const [breakpoint, breakpointRef] = useContainerBreakpoints(\n Object.keys(gridLayoutBreakpoints) as AttributeEditorProps.Breakpoint[]\n );\n const mergedRef = useMergeRefs(breakpointRef, __internalRootRef);\n\n const gridLayoutForBreakpoint = matchBreakpointMapping(gridLayoutBreakpoints, breakpoint || 'default');\n\n if (!gridLayoutForBreakpoint) {\n console.warn('AttributeEditor', `No \\`gridLayout\\` entry found for breakpoint ${breakpoint}. Cannot render.`);\n return <div />;\n }\n\n const totalColumnsInLayout = gridLayoutForBreakpoint.rows.reduce((total, columns) => total + columns.length, 0);\n if (totalColumnsInLayout !== definition.length) {\n console.warn(\n 'AttributeEditor',\n `Incorrect number of columns in layout (${totalColumnsInLayout}) for definition (${definition.length}). Cannot render.`\n );\n return <div />;\n }\n\n return (\n <div\n {...baseProps}\n ref={mergedRef}\n className={clsx(baseProps.className, styles.root)}\n style={{ gridTemplateColumns: getGridTemplateColumns(gridLayoutForBreakpoint) }}\n >\n {isEmpty && <div className={clsx(styles.empty, wasNonEmpty.current && styles['empty-appear'])}>{empty}</div>}\n {items.map((item, index) => (\n <Row<T>\n key={index}\n index={index}\n breakpoint={breakpoint}\n layout={gridLayoutForBreakpoint}\n item={item}\n definition={definition}\n i18nStrings={i18nStrings}\n removable={isItemRemovable(item)}\n removeButtonText={removeButtonText}\n removeButtonRefs={removeButtonRefs.current}\n customRowActions={customRowActions}\n onRemoveButtonClick={onRemoveButtonClick}\n removeButtonAriaLabel={removeButtonAriaLabel}\n />\n ))}\n\n <div className={styles['add-row']}>\n <InternalButton\n className={styles['add-button']}\n disabled={disableAddButton}\n // Using aria-disabled=\"true\" and tabindex=\"-1\" instead of \"disabled\"\n // because focus can be dynamically moved to this button by calling\n // `focusAddButton()` on the ref.\n __nativeAttributes={disableAddButton ? { tabIndex: -1 } : {}}\n __focusable={true}\n onClick={onAddButtonClick}\n formAction=\"none\"\n ref={addButtonRef}\n ariaDescribedby={infoAriaDescribedBy}\n variant={addButtonVariant}\n iconName={addButtonVariant === 'inline-link' ? 'add-plus' : undefined}\n >\n {addButtonText}\n </InternalButton>\n <InternalLiveRegion\n data-testid=\"removal-announcement\"\n tagName=\"span\"\n hidden={true}\n delay={5}\n key={items.length}\n >\n {removalAnnouncement}\n </InternalLiveRegion>\n {!!additionalInfo && <AdditionalInfo id={infoAriaDescribedBy}>{additionalInfo}</AdditionalInfo>}\n </div>\n </div>\n );\n }\n) as AttributeEditorForwardRefType;\n\nexport default InternalAttributeEditor;\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { ButtonProps } from '../button/interfaces';
|
|
3
|
-
import {
|
|
3
|
+
import { Breakpoint } from '../internal/breakpoints';
|
|
4
4
|
import { NonCancelableEventHandler } from '../internal/events';
|
|
5
5
|
import { AttributeEditorProps } from './interfaces';
|
|
6
6
|
interface RowProps<T> {
|
|
7
|
-
breakpoint:
|
|
7
|
+
breakpoint: Breakpoint | null;
|
|
8
|
+
layout: AttributeEditorProps.GridLayout;
|
|
8
9
|
item: T;
|
|
9
10
|
definition: ReadonlyArray<AttributeEditorProps.FieldDefinition<T>>;
|
|
10
11
|
i18nStrings: AttributeEditorProps.I18nStrings | undefined;
|
|
@@ -12,6 +13,7 @@ interface RowProps<T> {
|
|
|
12
13
|
removable: boolean;
|
|
13
14
|
removeButtonText?: string;
|
|
14
15
|
removeButtonRefs: Array<ButtonProps.Ref | undefined>;
|
|
16
|
+
customRowActions?: (props: AttributeEditorProps.RowActionsProps<T>) => React.ReactNode;
|
|
15
17
|
onRemoveButtonClick?: NonCancelableEventHandler<AttributeEditorProps.RemoveButtonClickDetail>;
|
|
16
18
|
removeButtonAriaLabel?: (item: T) => string;
|
|
17
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row.d.ts","sourceRoot":"","sources":["../../../src/attribute-editor/row.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"row.d.ts","sourceRoot":"","sources":["../../../src/attribute-editor/row.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAG3C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAA0B,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAEvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAKpD,UAAU,QAAQ,CAAC,CAAC;IAClB,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,oBAAoB,CAAC,UAAU,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC;IACR,UAAU,EAAE,aAAa,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,WAAW,EAAE,oBAAoB,CAAC,WAAW,GAAG,SAAS,CAAC;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC;IACrD,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;IACvF,mBAAmB,CAAC,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,uBAAuB,CAAC,CAAC;IAC9F,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;CAC7C;AAiBD,eAAO,MAAM,GAAG,6BA+FgB,WAAW,CAAC"}
|