@cloudscape-design/components 3.0.874 → 3.0.876

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.
Files changed (78) hide show
  1. package/attribute-editor/grid-defaults.d.ts +3 -0
  2. package/attribute-editor/grid-defaults.d.ts.map +1 -0
  3. package/attribute-editor/grid-defaults.js +122 -0
  4. package/attribute-editor/grid-defaults.js.map +1 -0
  5. package/attribute-editor/interfaces.d.ts +49 -2
  6. package/attribute-editor/interfaces.d.ts.map +1 -1
  7. package/attribute-editor/interfaces.js.map +1 -1
  8. package/attribute-editor/internal.d.ts.map +1 -1
  9. package/attribute-editor/internal.js +35 -15
  10. package/attribute-editor/internal.js.map +1 -1
  11. package/attribute-editor/row.d.ts +5 -3
  12. package/attribute-editor/row.d.ts.map +1 -1
  13. package/attribute-editor/row.js +29 -26
  14. package/attribute-editor/row.js.map +1 -1
  15. package/attribute-editor/styles.css.js +15 -14
  16. package/attribute-editor/styles.scoped.css +49 -41
  17. package/attribute-editor/styles.selectors.js +15 -14
  18. package/attribute-editor/utils.d.ts +11 -0
  19. package/attribute-editor/utils.d.ts.map +1 -0
  20. package/attribute-editor/utils.js +43 -0
  21. package/attribute-editor/utils.js.map +1 -0
  22. package/button-dropdown/interfaces.d.ts +6 -2
  23. package/button-dropdown/interfaces.d.ts.map +1 -1
  24. package/button-dropdown/interfaces.js.map +1 -1
  25. package/button-dropdown/internal.d.ts.map +1 -1
  26. package/button-dropdown/internal.js +11 -3
  27. package/button-dropdown/internal.js.map +1 -1
  28. package/button-dropdown/utils/use-button-dropdown.js +1 -1
  29. package/button-dropdown/utils/use-button-dropdown.js.map +1 -1
  30. package/button-group/item-element.d.ts.map +1 -1
  31. package/button-group/item-element.js +11 -7
  32. package/button-group/item-element.js.map +1 -1
  33. package/form-field/interfaces.d.ts +2 -1
  34. package/form-field/interfaces.d.ts.map +1 -1
  35. package/form-field/interfaces.js.map +1 -1
  36. package/form-field/internal.d.ts +1 -1
  37. package/form-field/internal.d.ts.map +1 -1
  38. package/form-field/internal.js +2 -2
  39. package/form-field/internal.js.map +1 -1
  40. package/internal/components/dropdown/dropdown-fit-handler.d.ts +2 -1
  41. package/internal/components/dropdown/dropdown-fit-handler.d.ts.map +1 -1
  42. package/internal/components/dropdown/dropdown-fit-handler.js +1 -1
  43. package/internal/components/dropdown/dropdown-fit-handler.js.map +1 -1
  44. package/internal/components/dropdown/dropdown-position.d.ts +16 -0
  45. package/internal/components/dropdown/dropdown-position.d.ts.map +1 -0
  46. package/internal/components/dropdown/dropdown-position.js +27 -0
  47. package/internal/components/dropdown/dropdown-position.js.map +1 -0
  48. package/internal/components/dropdown/index.d.ts.map +1 -1
  49. package/internal/components/dropdown/index.js +15 -31
  50. package/internal/components/dropdown/index.js.map +1 -1
  51. package/internal/environment.js +1 -1
  52. package/internal/environment.json +1 -1
  53. package/internal/manifest.json +1 -1
  54. package/multiselect/interfaces.d.ts +4 -0
  55. package/multiselect/interfaces.d.ts.map +1 -1
  56. package/multiselect/interfaces.js.map +1 -1
  57. package/multiselect/internal.d.ts +1 -3
  58. package/multiselect/internal.d.ts.map +1 -1
  59. package/multiselect/internal.js.map +1 -1
  60. package/package.json +1 -1
  61. package/popover/interfaces.d.ts +3 -2
  62. package/popover/interfaces.d.ts.map +1 -1
  63. package/popover/interfaces.js.map +1 -1
  64. package/popover/internal.js +2 -2
  65. package/popover/internal.js.map +1 -1
  66. package/popover/styles.css.js +54 -53
  67. package/popover/styles.scoped.css +96 -70
  68. package/popover/styles.selectors.js +54 -53
  69. package/test-utils/dom/attribute-editor/index.d.ts +1 -0
  70. package/test-utils/dom/attribute-editor/index.js +4 -2
  71. package/test-utils/dom/attribute-editor/index.js.map +1 -1
  72. package/test-utils/selectors/attribute-editor/index.d.ts +1 -0
  73. package/test-utils/selectors/attribute-editor/index.js +4 -2
  74. package/test-utils/selectors/attribute-editor/index.js.map +1 -1
  75. package/test-utils/tsconfig.tsbuildinfo +1 -1
  76. package/top-navigation/styles.css.js +47 -47
  77. package/top-navigation/styles.scoped.css +66 -65
  78. package/top-navigation/styles.selectors.js +47 -47
@@ -0,0 +1,3 @@
1
+ import { AttributeEditorProps } from './interfaces';
2
+ export declare const gridDefaults: Record<number, AttributeEditorProps.GridLayout[]>;
3
+ //# sourceMappingURL=grid-defaults.d.ts.map
@@ -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,CA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AC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SACrC;KACF;CACF,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-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;IACjF,UAAiB,eAAe,CAAC,CAAC;QAChC,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;QACxB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;QACvB,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;QAC/C,SAAS,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;QACjD,WAAW,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;QACnD,cAAc,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;KACvD;IAED,KAAY,gBAAgB,GAA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}
@@ -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 maximum of four fields are supported.\n */\n definition: ReadonlyArray<AttributeEditorProps.FieldDefinition<T>>;\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
+ {"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":"AAiBA,OAAO,EAAE,6BAA6B,EAAwB,MAAM,cAAc,CAAC;AAOnF,QAAA,MAAM,uBAAuB,+BA6GK,CAAC;AAEnC,eAAe,uBAAuB,CAAC"}
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
- return (React.createElement("div", Object.assign({}, baseProps, { ref: mergedRef, className: clsx(baseProps.className, styles.root) }),
52
- React.createElement(InternalBox, { margin: { bottom: 'l' } },
53
- isEmpty && React.createElement("div", { className: clsx(styles.empty, wasNonEmpty.current && styles['empty-appear']) }, empty),
54
- items.map((item, index) => (React.createElement(Row, { key: index, index: index, breakpoint: breakpoint, item: item, definition: definition, i18nStrings: i18nStrings, removable: isItemRemovable(item), removeButtonText: removeButtonText, removeButtonRefs: removeButtonRefs.current, onRemoveButtonClick: onRemoveButtonClick, removeButtonAriaLabel: removeButtonAriaLabel })))),
55
- React.createElement(InternalButton, { className: styles['add-button'], disabled: disableAddButton,
56
- // Using aria-disabled="true" and tabindex="-1" instead of "disabled"
57
- // because focus can be dynamically moved to this button by calling
58
- // `focusAddButton()` on the ref.
59
- __nativeAttributes: disableAddButton ? { tabIndex: -1 } : {}, __focusable: true, onClick: onAddButtonClick, formAction: "none", ref: addButtonRef, ariaDescribedby: infoAriaDescribedBy, variant: addButtonVariant, iconName: addButtonVariant === 'inline-link' ? 'add-plus' : undefined }, addButtonText),
60
- React.createElement(InternalLiveRegion, { "data-testid": "removal-announcement", tagName: "span", hidden: true, delay: 5, key: items.length }, removalAnnouncement),
61
- !!additionalInfo && React.createElement(AdditionalInfo, { id: infoAriaDescribedBy }, additionalInfo)));
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,WAAW,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,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;AAEnD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAIrC,MAAM,uBAAuB,GAAG,KAAK,CAAC,UAAU,CAC9C,CACE,EAgBkC,EAClC,GAAwC,EACxC,EAAE;QAlBF,EACE,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,KAAK,EACL,eAAe,GAAG,GAAG,EAAE,CAAC,IAAI,EAC5B,KAAK,EACL,aAAa,EACb,gBAAgB,GAAG,QAAQ,EAC3B,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,GAAG,IAAI,OAEQ,EAD7B,KAAK,cAfV,0PAgBC,CAD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AE,gBAAgB,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAC5D,WAAW,EAAE,IAAI,EACjB,OAAO,EAAE,gBAAgB,EACzB,UAAU,EAAC,MAAM,EACjB,GAAG,EAAE,YAAY,EACjB,eAAe,EAAE,mBAAmB,EACpC,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,gBAAgB,KAAK,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,IAEpE,aAAa,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,EA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,EAAE,IAAI,EACZ,KAAK,EAAE,CAAC,EACR,GAAG,EAAE,KAAK,CAAC,MAAM,IAEhB,mBAAmB,CACD;YACpB,CAAC,CAAC,cAAc,IAAI,oBAAC,cAAc,IAAC,EAAE,EAAE,mBAAmB,IAAG,cAAc,CAAkB,CAC3F,CACF,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 { 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
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { ButtonProps } from '../button/interfaces';
3
- import { ColumnLayoutBreakpoint } from '../column-layout/internal';
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: ColumnLayoutBreakpoint | null;
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":";AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAA6B,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAIzF,OAAO,EAA0B,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAEvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAMpD,UAAU,QAAQ,CAAC,CAAC;IAClB,UAAU,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC1C,IAAI,EAAE,CAAC,CAAC;IACR,UAAU,EAAE,aAAa,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,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AAE,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"}
@@ -2,16 +2,13 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import React, { useCallback } from 'react';
4
4
  import clsx from 'clsx';
5
- import InternalBox from '../box/internal';
6
5
  import { InternalButton } from '../button/internal';
7
- import InternalColumnLayout from '../column-layout/internal';
8
6
  import InternalFormField from '../form-field/internal';
9
- import InternalGrid from '../grid/internal';
10
7
  import { useInternalI18n } from '../i18n/context';
11
8
  import { fireNonCancelableEvent } from '../internal/events';
12
9
  import { useUniqueId } from '../internal/hooks/use-unique-id';
10
+ import { getItemGridColumns, getRemoveButtonGridColumns, isRemoveButtonOnSameLine } from './utils';
13
11
  import styles from './styles.css.js';
14
- const Divider = () => React.createElement(InternalBox, { className: styles.divider, padding: { top: 'l' } });
15
12
  function render(item, itemIndex, slot) {
16
13
  if (isSlotFunction(slot)) {
17
14
  return slot(item, itemIndex);
@@ -21,33 +18,39 @@ function render(item, itemIndex, slot) {
21
18
  return typeof slot === 'function';
22
19
  }
23
20
  }
24
- const GRID_DEFINITION = [{ colspan: { default: 12, xs: 9 } }];
25
- const REMOVABLE_GRID_DEFINITION = [{ colspan: { default: 12, xs: 9 } }, { colspan: { default: 12, xs: 3 } }];
26
- export const Row = React.memo(({ breakpoint, item, definition, i18nStrings = {}, index, removable, removeButtonText, removeButtonRefs, onRemoveButtonClick, removeButtonAriaLabel, }) => {
21
+ export const Row = React.memo(({ breakpoint, item, definition, layout, i18nStrings = {}, index, removable, removeButtonText, removeButtonRefs, customRowActions, onRemoveButtonClick, removeButtonAriaLabel, }) => {
27
22
  var _a;
28
23
  const i18n = useInternalI18n('attribute-editor');
29
- const isNarrowViewport = breakpoint === 'default' || breakpoint === 'xxs';
30
- const isWideViewport = !isNarrowViewport;
31
24
  const handleRemoveClick = useCallback(() => {
32
25
  fireNonCancelableEvent(onRemoveButtonClick, { itemIndex: index });
33
26
  }, [onRemoveButtonClick, index]);
34
27
  const firstControlId = useUniqueId('first-control-id-');
35
- return (React.createElement(InternalBox, { className: styles.row, margin: { bottom: 's' } },
36
- React.createElement("div", { role: "group", "aria-labelledby": `${firstControlId}-label ${firstControlId}` },
37
- React.createElement(InternalGrid, { __breakpoint: breakpoint, gridDefinition: removable ? REMOVABLE_GRID_DEFINITION : GRID_DEFINITION },
38
- React.createElement(InternalColumnLayout, { className: styles['row-control'], columns: definition.length, __breakpoint: breakpoint }, definition.map(({ info, label, constraintText, errorText, warningText, control }, defIndex) => (React.createElement(InternalFormField, { key: defIndex, className: styles.field, label: label, info: info, constraintText: render(item, index, constraintText), errorText: render(item, index, errorText), warningText: render(item, index, warningText), stretch: true, i18nStrings: {
39
- errorIconAriaLabel: i18nStrings.errorIconAriaLabel,
40
- warningIconAriaLabel: i18nStrings.warningIconAriaLabel,
41
- }, __hideLabel: isWideViewport && index > 0, controlId: defIndex === 0 ? firstControlId : undefined }, render(item, index, control))))),
42
- removable && (React.createElement(ButtonContainer, { index: index, isNarrowViewport: isNarrowViewport, hasLabel: definition.some(row => row.label) },
43
- React.createElement(InternalButton, { className: styles['remove-button'], formAction: "none", ref: ref => {
44
- removeButtonRefs[index] = ref !== null && ref !== void 0 ? ref : undefined;
45
- }, ariaLabel: (_a = (removeButtonAriaLabel !== null && removeButtonAriaLabel !== void 0 ? removeButtonAriaLabel : i18nStrings.removeButtonAriaLabel)) === null || _a === void 0 ? void 0 : _a(item), onClick: handleRemoveClick }, i18n('removeButtonText', removeButtonText)))))),
46
- isNarrowViewport && React.createElement(Divider, null)));
28
+ const buttonRef = (ref) => {
29
+ removeButtonRefs[index] = ref !== null && ref !== void 0 ? ref : undefined;
30
+ };
31
+ let gridColumnStart = 1;
32
+ let gridColumnEnd = 1;
33
+ const removeButtonOnSameLine = isRemoveButtonOnSameLine(layout);
34
+ const customActions = customRowActions === null || customRowActions === void 0 ? void 0 : customRowActions({
35
+ item,
36
+ itemIndex: index,
37
+ ref: buttonRef,
38
+ breakpoint,
39
+ ownRow: !removeButtonOnSameLine,
40
+ });
41
+ return (React.createElement("div", { className: clsx(styles.row, layout.rows.length === 1 && styles['single-row']), role: "group", "aria-labelledby": `${firstControlId}-label ${firstControlId}` },
42
+ definition.map(({ info, label, constraintText, errorText, warningText, control }, defIndex) => {
43
+ ({ gridColumnStart, gridColumnEnd } = getItemGridColumns(layout, defIndex));
44
+ return (React.createElement(InternalFormField, { key: defIndex, className: styles.field, __style: { gridColumnStart, gridColumnEnd }, label: label, info: info, constraintText: render(item, index, constraintText), errorText: render(item, index, errorText), warningText: render(item, index, warningText), stretch: true, i18nStrings: {
45
+ errorIconAriaLabel: i18nStrings.errorIconAriaLabel,
46
+ warningIconAriaLabel: i18nStrings.warningIconAriaLabel,
47
+ }, __hideLabel: index !== 0 && removeButtonOnSameLine, controlId: defIndex === 0 ? firstControlId : undefined }, render(item, index, control)));
48
+ }),
49
+ React.createElement("div", { className: clsx(styles['remove-button-container'], {
50
+ [styles['remove-button-field-padding']]: removeButtonOnSameLine && index === 0,
51
+ [styles['remove-button-own-row']]: !removeButtonOnSameLine,
52
+ }), style: Object.assign({}, getRemoveButtonGridColumns(layout, gridColumnEnd)) }, removable &&
53
+ (customActions !== undefined ? (customActions) : (React.createElement(InternalButton, { className: styles['remove-button'], formAction: "none", ref: buttonRef, ariaLabel: (_a = (removeButtonAriaLabel !== null && removeButtonAriaLabel !== void 0 ? removeButtonAriaLabel : i18nStrings.removeButtonAriaLabel)) === null || _a === void 0 ? void 0 : _a(item), onClick: handleRemoveClick }, i18n('removeButtonText', removeButtonText))))),
54
+ !removeButtonOnSameLine && React.createElement("div", { className: styles.divider })));
47
55
  });
48
- const ButtonContainer = ({ index, children, isNarrowViewport, hasLabel }) => (React.createElement("div", { className: clsx({
49
- [styles['button-container-haslabel']]: !isNarrowViewport && index === 0 && hasLabel,
50
- [styles['button-container-nolabel']]: !isNarrowViewport && index === 0 && !hasLabel,
51
- [styles['right-align']]: isNarrowViewport,
52
- }) }, children));
53
56
  //# sourceMappingURL=row.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"row.js","sourceRoot":"","sources":["../../../src/attribute-editor/row.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,oBAAgD,MAAM,2BAA2B,CAAC;AACzF,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAA6B,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAG9D,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,oBAAC,WAAW,IAAC,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAI,CAAC;AAexF,SAAS,MAAM,CACb,IAAO,EACP,SAAiB,EACjB,IAA2E;IAE3E,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE;QACxB,OAAO,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;KAC9B;IACD,OAAO,IAAI,CAAC;IAEZ,SAAS,cAAc,CAAC,IAA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,CAAC;oBAE3C,oBAAC,cAAc,IACb,SAAS,EAAE,MAAM,CAAC,eAAe,CAAC,EAClC,UAAU,EAAC,MAAM,EACjB,GAAG,EAAE,GAAG,CAAC,EAAE;4BACT,gBAAgB,CAAC,KAAK,CAAC,GAAG,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,SAAS,CAAC;wBAC7C,CAAC,EACD,SAAS,EAAE,MAAA,CAAC,qBAAqB,aAArB,qBAAqB,cAArB,qBAAqB,GAAI,WAAW,CAAC,qBAAqB,CAAC,0CAAG,IAAI,CAAC,EAC/E,OAAO,EAAE,iBAAiB,IAEzB,IAAI,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAC5B,CACD,CACnB,CACY,CACX;QACL,gBAAgB,IAAI,oBAAC,OAAO,OAAG,CACpB,CACf,CAAC;AACJ,CAAC,CACwC,CAAC;AAS5C,MAAM,eAAe,GAAG,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,QAAQ,EAAmB,EAAE,EAAE,CAAC,CAC5F,6BACE,SAAS,EAAE,IAAI,CAAC;QACd,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC,EAAE,CAAC,gBAAgB,IAAI,KAAK,KAAK,CAAC,IAAI,QAAQ;QACnF,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC,EAAE,CAAC,gBAAgB,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,QAAQ;QACnF,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,gBAAgB;KAC1C,CAAC,IAED,QAAQ,CACL,CACP,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useCallback } from 'react';\nimport clsx from 'clsx';\n\nimport InternalBox from '../box/internal';\nimport { ButtonProps } from '../button/interfaces';\nimport { InternalButton } from '../button/internal';\nimport InternalColumnLayout, { ColumnLayoutBreakpoint } from '../column-layout/internal';\nimport InternalFormField from '../form-field/internal';\nimport InternalGrid from '../grid/internal';\nimport { useInternalI18n } from '../i18n/context';\nimport { fireNonCancelableEvent, NonCancelableEventHandler } from '../internal/events';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { AttributeEditorProps } from './interfaces';\n\nimport styles from './styles.css.js';\n\nconst Divider = () => <InternalBox className={styles.divider} padding={{ top: 'l' }} />;\n\ninterface RowProps<T> {\n breakpoint: ColumnLayoutBreakpoint | null;\n item: T;\n definition: ReadonlyArray<AttributeEditorProps.FieldDefinition<T>>;\n i18nStrings: AttributeEditorProps.I18nStrings | undefined;\n index: number;\n removable: boolean;\n removeButtonText?: string;\n removeButtonRefs: Array<ButtonProps.Ref | undefined>;\n onRemoveButtonClick?: NonCancelableEventHandler<AttributeEditorProps.RemoveButtonClickDetail>;\n removeButtonAriaLabel?: (item: T) => string;\n}\n\nfunction render<T>(\n item: T,\n itemIndex: number,\n slot: AttributeEditorProps.FieldRenderable<T> | React.ReactNode | undefined\n) {\n if (isSlotFunction(slot)) {\n return slot(item, itemIndex);\n }\n return slot;\n\n function isSlotFunction(slot: unknown): slot is AttributeEditorProps.FieldRenderable<T> {\n return typeof slot === 'function';\n }\n}\n\nconst GRID_DEFINITION = [{ colspan: { default: 12, xs: 9 } }];\nconst REMOVABLE_GRID_DEFINITION = [{ colspan: { default: 12, xs: 9 } }, { colspan: { default: 12, xs: 3 } }];\nexport const Row = React.memo(\n <T,>({\n breakpoint,\n item,\n definition,\n i18nStrings = {},\n index,\n removable,\n removeButtonText,\n removeButtonRefs,\n onRemoveButtonClick,\n removeButtonAriaLabel,\n }: RowProps<T>) => {\n const i18n = useInternalI18n('attribute-editor');\n const isNarrowViewport = breakpoint === 'default' || breakpoint === 'xxs';\n const isWideViewport = !isNarrowViewport;\n\n const handleRemoveClick = useCallback(() => {\n fireNonCancelableEvent(onRemoveButtonClick, { itemIndex: index });\n }, [onRemoveButtonClick, index]);\n\n const firstControlId = useUniqueId('first-control-id-');\n\n return (\n <InternalBox className={styles.row} margin={{ bottom: 's' }}>\n <div role=\"group\" aria-labelledby={`${firstControlId}-label ${firstControlId}`}>\n <InternalGrid\n __breakpoint={breakpoint}\n gridDefinition={removable ? REMOVABLE_GRID_DEFINITION : GRID_DEFINITION}\n >\n <InternalColumnLayout\n className={styles['row-control']}\n columns={definition.length}\n __breakpoint={breakpoint}\n >\n {definition.map(({ info, label, constraintText, errorText, warningText, control }, defIndex) => (\n <InternalFormField\n key={defIndex}\n className={styles.field}\n label={label}\n info={info}\n constraintText={render(item, index, constraintText)}\n errorText={render(item, index, errorText)}\n warningText={render(item, index, warningText)}\n stretch={true}\n i18nStrings={{\n errorIconAriaLabel: i18nStrings.errorIconAriaLabel,\n warningIconAriaLabel: i18nStrings.warningIconAriaLabel,\n }}\n __hideLabel={isWideViewport && index > 0}\n controlId={defIndex === 0 ? firstControlId : undefined}\n >\n {render(item, index, control)}\n </InternalFormField>\n ))}\n </InternalColumnLayout>\n {removable && (\n <ButtonContainer\n index={index}\n isNarrowViewport={isNarrowViewport}\n hasLabel={definition.some(row => row.label)}\n >\n <InternalButton\n className={styles['remove-button']}\n formAction=\"none\"\n ref={ref => {\n removeButtonRefs[index] = ref ?? undefined;\n }}\n ariaLabel={(removeButtonAriaLabel ?? i18nStrings.removeButtonAriaLabel)?.(item)}\n onClick={handleRemoveClick}\n >\n {i18n('removeButtonText', removeButtonText)}\n </InternalButton>\n </ButtonContainer>\n )}\n </InternalGrid>\n </div>\n {isNarrowViewport && <Divider />}\n </InternalBox>\n );\n }\n) as <T>(props: RowProps<T>) => JSX.Element;\n\ninterface ButtonContainer {\n index: number;\n children: React.ReactNode;\n isNarrowViewport: boolean;\n hasLabel: boolean;\n}\n\nconst ButtonContainer = ({ index, children, isNarrowViewport, hasLabel }: ButtonContainer) => (\n <div\n className={clsx({\n [styles['button-container-haslabel']]: !isNarrowViewport && index === 0 && hasLabel,\n [styles['button-container-nolabel']]: !isNarrowViewport && index === 0 && !hasLabel,\n [styles['right-align']]: isNarrowViewport,\n })}\n >\n {children}\n </div>\n);\n"]}
1
+ {"version":3,"file":"row.js","sourceRoot":"","sources":["../../../src/attribute-editor/row.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAAE,sBAAsB,EAA6B,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnG,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAiBrC,SAAS,MAAM,CACb,IAAO,EACP,SAAiB,EACjB,IAA2E;IAE3E,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE;QACxB,OAAO,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;KAC9B;IACD,OAAO,IAAI,CAAC;IAEZ,SAAS,cAAc,CAAC,IAAa;QACnC,OAAO,OAAO,IAAI,KAAK,UAAU,CAAC;IACpC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAC3B,CAAK,EACH,UAAU,EACV,IAAI,EACJ,UAAU,EACV,MAAM,EACN,WAAW,GAAG,EAAE,EAChB,KAAK,EACL,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,GACT,EAAE,EAAE;;IAChB,MAAM,IAAI,GAAG,eAAe,CAAC,kBAAkB,CAAC,CAAC;IAEjD,MAAM,iBAAiB,GAAG,WAAW,CAAC,G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AqB,CAAC,0CAAG,IAAI,CAAC,EAC/E,OAAO,EAAE,iBAAiB,IAEzB,IAAI,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAC5B,CAClB,CAAC,CACA;QACL,CAAC,sBAAsB,IAAI,6BAAK,SAAS,EAAE,MAAM,CAAC,OAAO,GAAI,CAC1D,CACP,CAAC;AACJ,CAAC,CACwC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useCallback } from 'react';\nimport clsx from 'clsx';\n\nimport { ButtonProps } from '../button/interfaces';\nimport { InternalButton } from '../button/internal';\nimport InternalFormField from '../form-field/internal';\nimport { useInternalI18n } from '../i18n/context';\nimport { Breakpoint } from '../internal/breakpoints';\nimport { fireNonCancelableEvent, NonCancelableEventHandler } from '../internal/events';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { AttributeEditorProps } from './interfaces';\nimport { getItemGridColumns, getRemoveButtonGridColumns, isRemoveButtonOnSameLine } from './utils';\n\nimport styles from './styles.css.js';\n\ninterface RowProps<T> {\n breakpoint: Breakpoint | null;\n layout: AttributeEditorProps.GridLayout;\n item: T;\n definition: ReadonlyArray<AttributeEditorProps.FieldDefinition<T>>;\n i18nStrings: AttributeEditorProps.I18nStrings | undefined;\n index: number;\n removable: boolean;\n removeButtonText?: string;\n removeButtonRefs: Array<ButtonProps.Ref | undefined>;\n customRowActions?: (props: AttributeEditorProps.RowActionsProps<T>) => React.ReactNode;\n onRemoveButtonClick?: NonCancelableEventHandler<AttributeEditorProps.RemoveButtonClickDetail>;\n removeButtonAriaLabel?: (item: T) => string;\n}\n\nfunction render<T>(\n item: T,\n itemIndex: number,\n slot: AttributeEditorProps.FieldRenderable<T> | React.ReactNode | undefined\n) {\n if (isSlotFunction(slot)) {\n return slot(item, itemIndex);\n }\n return slot;\n\n function isSlotFunction(slot: unknown): slot is AttributeEditorProps.FieldRenderable<T> {\n return typeof slot === 'function';\n }\n}\n\nexport const Row = React.memo(\n <T,>({\n breakpoint,\n item,\n definition,\n layout,\n i18nStrings = {},\n index,\n removable,\n removeButtonText,\n removeButtonRefs,\n customRowActions,\n onRemoveButtonClick,\n removeButtonAriaLabel,\n }: RowProps<T>) => {\n const i18n = useInternalI18n('attribute-editor');\n\n const handleRemoveClick = useCallback(() => {\n fireNonCancelableEvent(onRemoveButtonClick, { itemIndex: index });\n }, [onRemoveButtonClick, index]);\n\n const firstControlId = useUniqueId('first-control-id-');\n\n const buttonRef = (ref: ButtonProps.Ref | null) => {\n removeButtonRefs[index] = ref ?? undefined;\n };\n\n let gridColumnStart = 1;\n let gridColumnEnd = 1;\n const removeButtonOnSameLine = isRemoveButtonOnSameLine(layout);\n\n const customActions = customRowActions?.({\n item,\n itemIndex: index,\n ref: buttonRef,\n breakpoint,\n ownRow: !removeButtonOnSameLine,\n });\n\n return (\n <div\n className={clsx(styles.row, layout.rows.length === 1 && styles['single-row'])}\n role=\"group\"\n aria-labelledby={`${firstControlId}-label ${firstControlId}`}\n >\n {definition.map(({ info, label, constraintText, errorText, warningText, control }, defIndex) => {\n ({ gridColumnStart, gridColumnEnd } = getItemGridColumns(layout, defIndex));\n return (\n <InternalFormField\n key={defIndex}\n className={styles.field}\n __style={{ gridColumnStart, gridColumnEnd }}\n label={label}\n info={info}\n constraintText={render(item, index, constraintText)}\n errorText={render(item, index, errorText)}\n warningText={render(item, index, warningText)}\n stretch={true}\n i18nStrings={{\n errorIconAriaLabel: i18nStrings.errorIconAriaLabel,\n warningIconAriaLabel: i18nStrings.warningIconAriaLabel,\n }}\n __hideLabel={index !== 0 && removeButtonOnSameLine}\n controlId={defIndex === 0 ? firstControlId : undefined}\n >\n {render(item, index, control)}\n </InternalFormField>\n );\n })}\n <div\n className={clsx(styles['remove-button-container'], {\n [styles['remove-button-field-padding']]: removeButtonOnSameLine && index === 0,\n [styles['remove-button-own-row']]: !removeButtonOnSameLine,\n })}\n style={{ ...getRemoveButtonGridColumns(layout, gridColumnEnd) }}\n >\n {removable &&\n (customActions !== undefined ? (\n customActions\n ) : (\n <InternalButton\n className={styles['remove-button']}\n formAction=\"none\"\n ref={buttonRef}\n ariaLabel={(removeButtonAriaLabel ?? i18nStrings.removeButtonAriaLabel)?.(item)}\n onClick={handleRemoveClick}\n >\n {i18n('removeButtonText', removeButtonText)}\n </InternalButton>\n ))}\n </div>\n {!removeButtonOnSameLine && <div className={styles.divider} />}\n </div>\n );\n }\n) as <T>(props: RowProps<T>) => JSX.Element;\n"]}