@cloudscape-design/components 3.0.1412 → 3.0.1413

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 (155) hide show
  1. package/expandable-section/expandable-section-header.js +1 -1
  2. package/expandable-section/expandable-section-header.js.map +1 -1
  3. package/header/interfaces.d.ts +4 -0
  4. package/header/interfaces.d.ts.map +1 -1
  5. package/header/interfaces.js.map +1 -1
  6. package/header/internal.d.ts +1 -6
  7. package/header/internal.d.ts.map +1 -1
  8. package/header/internal.js +2 -2
  9. package/header/internal.js.map +1 -1
  10. package/header/styles.css.js +36 -36
  11. package/header/styles.scoped.css +55 -55
  12. package/header/styles.selectors.js +36 -36
  13. package/i18n/messages/all.all.js +1 -1
  14. package/i18n/messages/all.all.json +1 -1
  15. package/i18n/messages/all.de.js +1 -1
  16. package/i18n/messages/all.de.json +1 -1
  17. package/i18n/messages/all.en-GB.js +1 -1
  18. package/i18n/messages/all.en-GB.json +1 -1
  19. package/i18n/messages/all.en.js +1 -1
  20. package/i18n/messages/all.en.json +1 -1
  21. package/i18n/messages/all.es.js +1 -1
  22. package/i18n/messages/all.es.json +1 -1
  23. package/i18n/messages/all.fr.js +1 -1
  24. package/i18n/messages/all.fr.json +1 -1
  25. package/i18n/messages/all.id.js +1 -1
  26. package/i18n/messages/all.id.json +1 -1
  27. package/i18n/messages/all.it.js +1 -1
  28. package/i18n/messages/all.it.json +1 -1
  29. package/i18n/messages/all.ja.js +1 -1
  30. package/i18n/messages/all.ja.json +1 -1
  31. package/i18n/messages/all.ko.js +1 -1
  32. package/i18n/messages/all.ko.json +1 -1
  33. package/i18n/messages/all.pt-BR.js +1 -1
  34. package/i18n/messages/all.pt-BR.json +1 -1
  35. package/i18n/messages/all.tr.js +1 -1
  36. package/i18n/messages/all.tr.json +1 -1
  37. package/i18n/messages/all.zh-CN.js +1 -1
  38. package/i18n/messages/all.zh-CN.json +1 -1
  39. package/i18n/messages/all.zh-TW.js +1 -1
  40. package/i18n/messages/all.zh-TW.json +1 -1
  41. package/i18n/messages-types.d.ts +3 -0
  42. package/i18n/messages-types.d.ts.map +1 -1
  43. package/i18n/messages-types.js.map +1 -1
  44. package/index.d.ts +1 -0
  45. package/index.d.ts.map +1 -1
  46. package/index.js +1 -0
  47. package/index.js.map +1 -1
  48. package/internal/base-component/styles.scoped.css +1 -1
  49. package/internal/components/focus-lock/utils.d.ts +2 -0
  50. package/internal/components/focus-lock/utils.d.ts.map +1 -1
  51. package/internal/components/focus-lock/utils.js +5 -1
  52. package/internal/components/focus-lock/utils.js.map +1 -1
  53. package/internal/components/listbox/parts/item.d.ts +2 -0
  54. package/internal/components/listbox/parts/item.d.ts.map +1 -1
  55. package/internal/components/listbox/parts/item.js +3 -3
  56. package/internal/components/listbox/parts/item.js.map +1 -1
  57. package/internal/components/listbox/parts/plain-list.d.ts +6 -0
  58. package/internal/components/listbox/parts/plain-list.d.ts.map +1 -1
  59. package/internal/components/listbox/parts/plain-list.js +5 -4
  60. package/internal/components/listbox/parts/plain-list.js.map +1 -1
  61. package/internal/components/listbox/parts/scroll-to-index.d.ts +11 -0
  62. package/internal/components/listbox/parts/scroll-to-index.d.ts.map +1 -1
  63. package/internal/components/listbox/parts/scroll-to-index.js +16 -0
  64. package/internal/components/listbox/parts/scroll-to-index.js.map +1 -1
  65. package/internal/components/listbox/use-listbox.d.ts +2 -2
  66. package/internal/components/listbox/use-listbox.d.ts.map +1 -1
  67. package/internal/components/listbox/use-listbox.js.map +1 -1
  68. package/internal/components/options-list/index.d.ts +4 -1
  69. package/internal/components/options-list/index.d.ts.map +1 -1
  70. package/internal/components/options-list/index.js +1 -1
  71. package/internal/components/options-list/index.js.map +1 -1
  72. package/internal/components/options-list/utils/use-keyboard.d.ts +2 -1
  73. package/internal/components/options-list/utils/use-keyboard.d.ts.map +1 -1
  74. package/internal/components/options-list/utils/use-keyboard.js +4 -2
  75. package/internal/components/options-list/utils/use-keyboard.js.map +1 -1
  76. package/internal/components/selectable-item/index.d.ts +1 -0
  77. package/internal/components/selectable-item/index.d.ts.map +1 -1
  78. package/internal/components/selectable-item/index.js +2 -1
  79. package/internal/components/selectable-item/index.js.map +1 -1
  80. package/internal/components/selectable-item/interfaces.d.ts +1 -0
  81. package/internal/components/selectable-item/interfaces.d.ts.map +1 -1
  82. package/internal/components/selectable-item/interfaces.js.map +1 -1
  83. package/internal/components/selectable-item/styles.css.js +23 -22
  84. package/internal/components/selectable-item/styles.scoped.css +52 -49
  85. package/internal/components/selectable-item/styles.selectors.js +23 -22
  86. package/internal/components/sticky-header/use-untabbable-descendants.d.ts +2 -0
  87. package/internal/components/sticky-header/use-untabbable-descendants.d.ts.map +1 -0
  88. package/internal/components/sticky-header/use-untabbable-descendants.js +16 -0
  89. package/internal/components/sticky-header/use-untabbable-descendants.js.map +1 -0
  90. package/internal/environment.js +2 -2
  91. package/internal/environment.json +2 -2
  92. package/internal/manifest.json +1 -1
  93. package/manifest.json +2 -2
  94. package/multiselect/use-multiselect.d.ts +1 -1
  95. package/option-list/index.d.ts +5 -0
  96. package/option-list/index.d.ts.map +1 -0
  97. package/option-list/index.js +21 -0
  98. package/option-list/index.js.map +1 -0
  99. package/option-list/interfaces.d.ts +131 -0
  100. package/option-list/interfaces.d.ts.map +1 -0
  101. package/option-list/interfaces.js +2 -0
  102. package/option-list/interfaces.js.map +1 -0
  103. package/option-list/internal.d.ts +5 -0
  104. package/option-list/internal.d.ts.map +1 -0
  105. package/option-list/internal.js +138 -0
  106. package/option-list/internal.js.map +1 -0
  107. package/option-list/styles.css.js +6 -0
  108. package/option-list/styles.scoped.css +40 -0
  109. package/option-list/styles.selectors.js +7 -0
  110. package/option-list/test-classes/styles.css.js +8 -0
  111. package/option-list/test-classes/styles.scoped.css +9 -0
  112. package/option-list/test-classes/styles.selectors.js +9 -0
  113. package/option-list/use-option-list.d.ts +36 -0
  114. package/option-list/use-option-list.d.ts.map +1 -0
  115. package/option-list/use-option-list.js +69 -0
  116. package/option-list/use-option-list.js.map +1 -0
  117. package/package.json +4 -1
  118. package/table-root/index.js +1 -1
  119. package/table-root/index.js.map +1 -1
  120. package/table-root/interfaces.d.ts +15 -1
  121. package/table-root/interfaces.d.ts.map +1 -1
  122. package/table-root/interfaces.js.map +1 -1
  123. package/table-root/internal.d.ts +2 -0
  124. package/table-root/internal.d.ts.map +1 -1
  125. package/table-root/internal.js +23 -11
  126. package/table-root/internal.js.map +1 -1
  127. package/table-root/sticky-header-slot.d.ts +24 -0
  128. package/table-root/sticky-header-slot.d.ts.map +1 -0
  129. package/table-root/sticky-header-slot.js +13 -0
  130. package/table-root/sticky-header-slot.js.map +1 -0
  131. package/table-root/styles.css.js +10 -5
  132. package/table-root/styles.scoped.css +52 -7
  133. package/table-root/styles.selectors.js +10 -5
  134. package/table-root/use-sticky-header.d.ts +33 -0
  135. package/table-root/use-sticky-header.d.ts.map +1 -0
  136. package/table-root/use-sticky-header.js +141 -0
  137. package/table-root/use-sticky-header.js.map +1 -0
  138. package/test-utils/dom/header/index.d.ts +1 -0
  139. package/test-utils/dom/header/index.js +3 -0
  140. package/test-utils/dom/header/index.js.map +1 -1
  141. package/test-utils/dom/index.d.ts +28 -0
  142. package/test-utils/dom/index.js +21 -2
  143. package/test-utils/dom/index.js.map +1 -1
  144. package/test-utils/dom/option-list/index.d.ts +69 -0
  145. package/test-utils/dom/option-list/index.js +132 -0
  146. package/test-utils/dom/option-list/index.js.map +1 -0
  147. package/test-utils/selectors/header/index.d.ts +1 -0
  148. package/test-utils/selectors/header/index.js +3 -0
  149. package/test-utils/selectors/header/index.js.map +1 -1
  150. package/test-utils/selectors/index.d.ts +18 -0
  151. package/test-utils/selectors/index.js +16 -2
  152. package/test-utils/selectors/index.js.map +1 -1
  153. package/test-utils/selectors/option-list/index.d.ts +66 -0
  154. package/test-utils/selectors/option-list/index.js +108 -0
  155. package/test-utils/selectors/option-list/index.js.map +1 -0
@@ -0,0 +1,138 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import React, { useCallback, useMemo } from 'react';
4
+ import clsx from 'clsx';
5
+ import { warnOnce } from '@cloudscape-design/component-toolkit/internal';
6
+ import { useInternalI18n } from '../i18n/context';
7
+ import { getBaseProps } from '../internal/base-component';
8
+ import PlainList from '../internal/components/listbox/parts/plain-list';
9
+ import { multiSelection } from '../internal/components/listbox/selection/multi-selection';
10
+ import { singleSelection } from '../internal/components/listbox/selection/single-selection';
11
+ import { checkOptionValueField } from '../internal/components/listbox/utils/check-option-value-field';
12
+ import { isGroup } from '../internal/components/option/utils/filter-options';
13
+ import { prepareOptions } from '../internal/components/option/utils/prepare-options';
14
+ import { fireNonCancelableEvent } from '../internal/events';
15
+ import useForwardFocus from '../internal/hooks/forward-focus';
16
+ import { useControllable } from '../internal/hooks/use-controllable';
17
+ import { useOptionList } from './use-option-list';
18
+ import optionStyles from '../internal/components/option/styles.css.js';
19
+ import styles from './styles.css.js';
20
+ import testClasses from './test-classes/styles.css.js';
21
+ const EMPTY_SELECTION = [];
22
+ const isOptionGroup = (option) => isGroup(option);
23
+ /**
24
+ * Converts the public options to the options the shared list renders: the `icon` slot becomes the custom icon of
25
+ * the shared option renderer. `originals` maps each converted option back to the consumer's object, so events and
26
+ * `renderOption` receive the consumer's options.
27
+ */
28
+ function toInternalOptions(options) {
29
+ const originals = new Map();
30
+ const originalGroups = new Map();
31
+ // Options and group headers.
32
+ const convert = ({ icon, ...option }) => {
33
+ // The shared option renders a custom icon as is, so wrap it in the same class as the built-in icon of Select and
34
+ // Multiselect options, for the same spacing and alignment.
35
+ const internal = {
36
+ ...option,
37
+ __customIcon: icon && React.createElement("span", { className: optionStyles.icon }, icon),
38
+ };
39
+ return internal;
40
+ };
41
+ const internalOptions = options.map(option => {
42
+ if (!isOptionGroup(option)) {
43
+ const internal = convert(option);
44
+ originals.set(internal, option);
45
+ return internal;
46
+ }
47
+ const children = option.options.map(child => {
48
+ const internal = convert(child);
49
+ originals.set(internal, child);
50
+ return internal;
51
+ });
52
+ const group = { ...convert(option), options: children };
53
+ originalGroups.set(group, option);
54
+ return group;
55
+ });
56
+ return { internalOptions, originals, originalGroups };
57
+ }
58
+ const InternalOptionList = React.forwardRef(({ options, selectionType, selectedOptions: controlledSelectedOptions, onChange, ariaLabel, ariaLabelledby, ariaDescribedby, renderOption, renderHighlightedAriaLive, i18nStrings, __internalRootRef, ...restProps }, ref) => {
59
+ const baseProps = getBaseProps(restProps);
60
+ const i18n = useInternalI18n('option-list');
61
+ const { listOptions, parentMap, originals, originalGroups, hasDuplicateValues, hasDuplicateGroupValues } = useMemo(() => {
62
+ const { internalOptions, originals, originalGroups } = toInternalOptions(options);
63
+ // Also sets the test indexes that test-utils use to find an option by its position.
64
+ const { flatOptions, parentMap } = prepareOptions(internalOptions, 'none', '');
65
+ const values = flatOptions.filter(option => option.type !== 'parent').map(option => option.option.value);
66
+ // Groups are compared only with groups, so a group may share a value with an option.
67
+ const groupValues = options.filter(isOptionGroup).map(group => group.value);
68
+ return {
69
+ listOptions: flatOptions,
70
+ parentMap,
71
+ originals,
72
+ originalGroups,
73
+ hasDuplicateValues: new Set(values).size !== values.length,
74
+ hasDuplicateGroupValues: new Set(groupValues).size !== groupValues.length,
75
+ };
76
+ }, [options]);
77
+ // Check the options inside groups too, not only the top-level entries.
78
+ checkOptionValueField('OptionList', 'options', listOptions.filter(option => option.type !== 'parent').map(option => option.option));
79
+ if (hasDuplicateValues) {
80
+ warnOnce('OptionList', 'Every option must have a unique `value`. The component may work incorrectly.');
81
+ }
82
+ if (hasDuplicateGroupValues) {
83
+ warnOnce('OptionList', 'Every option group must have a unique `value`. The component may work incorrectly.');
84
+ }
85
+ // Maps an option the list returns back to the consumer's object. Options from `options` map to their originals;
86
+ // anything else already came from the consumer through `selectedOptions`.
87
+ const toPublicOption = useCallback((option) => { var _a; return (_a = originals.get(option)) !== null && _a !== void 0 ? _a : option; }, [originals]);
88
+ const toPublicGroup = useCallback((group) => { var _a; return (_a = originalGroups.get(group)) !== null && _a !== void 0 ? _a : group; }, [originalGroups]);
89
+ const [selectedOptions = EMPTY_SELECTION, setSelectedOptions] = useControllable(controlledSelectedOptions, onChange, EMPTY_SELECTION, { componentName: 'OptionList', controlledProp: 'selectedOptions', changeHandler: 'onChange' });
90
+ const selection = selectionType === 'multi'
91
+ ? multiSelection(selectedOptions, { options: listOptions, interactiveGroups: true })
92
+ : singleSelection(selectedOptions);
93
+ const { listRef, listProps, scrollToIndex, highlightType, announcement, getOptionProps, getRootProps } = useOptionList({
94
+ options: listOptions,
95
+ selection,
96
+ onSelect: option => {
97
+ const nextSelectedOptions = selection.getNextSelection(option).map(toPublicOption);
98
+ setSelectedOptions(nextSelectedOptions);
99
+ fireNonCancelableEvent(onChange, { selectedOptions: nextSelectedOptions });
100
+ },
101
+ getParent: option => { var _a; return (_a = parentMap.get(option)) === null || _a === void 0 ? void 0 : _a.option; },
102
+ selectedAriaLabel: i18n('i18nStrings.selectedAriaLabel', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.selectedAriaLabel),
103
+ // The consumer receives its own option and group objects, as with `renderOption`.
104
+ renderHighlightedAriaLive: renderHighlightedAriaLive &&
105
+ ((option, group) => renderHighlightedAriaLive(isGroup(option) ? toPublicGroup(option) : toPublicOption(option), group && toPublicGroup(group))),
106
+ });
107
+ useForwardFocus(ref, listRef);
108
+ const renderOriginalOption = useMemo(() => {
109
+ if (!renderOption) {
110
+ return undefined;
111
+ }
112
+ const toGroupItem = (item) => ({
113
+ ...item,
114
+ option: toPublicGroup(item.option),
115
+ });
116
+ return ({ item }) => {
117
+ if (item.type === 'item') {
118
+ const parent = item.parent && toGroupItem(item.parent);
119
+ return renderOption({ item: { ...item, option: toPublicOption(item.option), parent } });
120
+ }
121
+ if (item.type === 'group') {
122
+ return renderOption({ item: toGroupItem(item) });
123
+ }
124
+ // The listbox renders only options and group headers; it has no trigger or select-all item.
125
+ return null;
126
+ };
127
+ }, [renderOption, toPublicOption, toPublicGroup]);
128
+ return (React.createElement("div", { ...baseProps, className: clsx(baseProps.className, styles.root, testClasses.root), ref: __internalRootRef, ...getRootProps() },
129
+ React.createElement(PlainList, { ref: scrollToIndex, listProps: { ...listProps, ariaLabel, ariaLabelledby, ariaDescribedby }, filteredOptions: listOptions, filteringValue: "", highlightType: highlightType, selectionType: selection.selectionType, isMultiSelect: listProps.isMultiSelect, screenReaderContent: announcement, renderOption: renderOriginalOption, scrollStrategy: "ancestors", getOptionProps: (option, index) => ({
130
+ ...getOptionProps(option, index),
131
+ // There is no dropdown border above the list, so the first item has no top divider.
132
+ hideTopDivider: index === 0,
133
+ className: option.type === 'parent' ? testClasses['group-header'] : testClasses.option,
134
+ 'data-value': option.option.value,
135
+ }) })));
136
+ });
137
+ export default InternalOptionList;
138
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/option-list/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,SAAS,MAAM,iDAAiD,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,0DAA0D,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,2DAA2D,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,+DAA+D,CAAC;AACtG,OAAO,EAAE,OAAO,EAAE,MAAM,oDAAoD,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,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AE,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,EACnE,GAAG,EAAE,iBAAiB,KAClB,YAAY,EAAE;QAElB,oBAAC,SAAS,IACR,GAAG,EAAE,aAAa,EAClB,SAAS,EAAE,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,EACvE,eAAe,EAAE,WAAW,EAC5B,cAAc,EAAC,EAAE,EACjB,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,SAAS,CAAC,aAAa,EACtC,aAAa,EAAE,SAAS,CAAC,aAAa,EACtC,mBAAmB,EAAE,YAAY,EACjC,YAAY,EAAE,oBAAoB,EAClC,cAAc,EAAC,WAAW,EAC1B,cAAc,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;gBAClC,GAAG,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC;gBAChC,oFAAoF;gBACpF,cAAc,EAAE,KAAK,KAAK,CAAC;gBAC3B,SAAS,EAAE,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM;gBACtF,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;aAClC,CAAC,GACF,CACE,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useCallback, useMemo } from 'react';\nimport clsx from 'clsx';\n\nimport { warnOnce } from '@cloudscape-design/component-toolkit/internal';\n\nimport { useInternalI18n } from '../i18n/context';\nimport { getBaseProps } from '../internal/base-component';\nimport { ItemProps } from '../internal/components/listbox/parts/item';\nimport PlainList from '../internal/components/listbox/parts/plain-list';\nimport { multiSelection } from '../internal/components/listbox/selection/multi-selection';\nimport { singleSelection } from '../internal/components/listbox/selection/single-selection';\nimport { checkOptionValueField } from '../internal/components/listbox/utils/check-option-value-field';\nimport { isGroup } from '../internal/components/option/utils/filter-options';\nimport { prepareOptions } from '../internal/components/option/utils/prepare-options';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { useControllable } from '../internal/hooks/use-controllable';\nimport { OptionDefinition, OptionGroup } from '../types/option';\nimport { OptionListProps } from './interfaces';\nimport { useOptionList } from './use-option-list';\n\nimport optionStyles from '../internal/components/option/styles.css.js';\nimport styles from './styles.css.js';\nimport testClasses from './test-classes/styles.css.js';\n\ntype InternalOptionListProps = OptionListProps & InternalBaseComponentProps;\ntype InternalOption = OptionDefinition | OptionGroup;\n\n// The items the listbox passes to `renderOption`, before they are mapped back to the consumer's options.\ntype ListboxRenderItem = Parameters<NonNullable<ItemProps['renderOption']>>[0]['item'];\ntype ListboxGroupItem = Extract<ListboxRenderItem, { type: 'group' }>;\ntype ListboxRenderOption = (props: { item: ListboxRenderItem }) => React.ReactNode;\n\nconst EMPTY_SELECTION: ReadonlyArray<OptionListProps.Option> = [];\n\nconst isOptionGroup = (\n option: OptionListProps.Option | OptionListProps.OptionGroup\n): option is OptionListProps.OptionGroup => isGroup(option as InternalOption);\n\n/**\n * Converts the public options to the options the shared list renders: the `icon` slot becomes the custom icon of\n * the shared option renderer. `originals` maps each converted option back to the consumer's object, so events and\n * `renderOption` receive the consumer's options.\n */\nfunction toInternalOptions(options: OptionListProps.Options) {\n const originals = new Map<OptionDefinition, OptionListProps.Option>();\n const originalGroups = new Map<OptionGroup, OptionListProps.OptionGroup>();\n // Options and group headers.\n const convert = ({ icon, ...option }: OptionListProps.Option): OptionDefinition => {\n // The shared option renders a custom icon as is, so wrap it in the same class as the built-in icon of Select and\n // Multiselect options, for the same spacing and alignment.\n const internal: OptionDefinition & { __customIcon?: React.ReactNode } = {\n ...option,\n __customIcon: icon && <span className={optionStyles.icon}>{icon}</span>,\n };\n return internal;\n };\n const internalOptions = options.map<InternalOption>(option => {\n if (!isOptionGroup(option)) {\n const internal = convert(option);\n originals.set(internal, option);\n return internal;\n }\n const children = option.options.map(child => {\n const internal = convert(child);\n originals.set(internal, child);\n return internal;\n });\n const group: OptionGroup = { ...convert(option), options: children };\n originalGroups.set(group, option);\n return group;\n });\n return { internalOptions, originals, originalGroups };\n}\n\nconst InternalOptionList = React.forwardRef(\n (\n {\n options,\n selectionType,\n selectedOptions: controlledSelectedOptions,\n onChange,\n ariaLabel,\n ariaLabelledby,\n ariaDescribedby,\n renderOption,\n renderHighlightedAriaLive,\n i18nStrings,\n __internalRootRef,\n ...restProps\n }: InternalOptionListProps,\n ref: React.Ref<OptionListProps.Ref>\n ) => {\n const baseProps = getBaseProps(restProps);\n const i18n = useInternalI18n('option-list');\n\n const { listOptions, parentMap, originals, originalGroups, hasDuplicateValues, hasDuplicateGroupValues } =\n useMemo(() => {\n const { internalOptions, originals, originalGroups } = toInternalOptions(options);\n // Also sets the test indexes that test-utils use to find an option by its position.\n const { flatOptions, parentMap } = prepareOptions(internalOptions, 'none', '');\n const values = flatOptions.filter(option => option.type !== 'parent').map(option => option.option.value);\n // Groups are compared only with groups, so a group may share a value with an option.\n const groupValues = options.filter(isOptionGroup).map(group => group.value);\n return {\n listOptions: flatOptions,\n parentMap,\n originals,\n originalGroups,\n hasDuplicateValues: new Set(values).size !== values.length,\n hasDuplicateGroupValues: new Set(groupValues).size !== groupValues.length,\n };\n }, [options]);\n\n // Check the options inside groups too, not only the top-level entries.\n checkOptionValueField(\n 'OptionList',\n 'options',\n listOptions.filter(option => option.type !== 'parent').map(option => option.option)\n );\n if (hasDuplicateValues) {\n warnOnce('OptionList', 'Every option must have a unique `value`. The component may work incorrectly.');\n }\n if (hasDuplicateGroupValues) {\n warnOnce('OptionList', 'Every option group must have a unique `value`. The component may work incorrectly.');\n }\n\n // Maps an option the list returns back to the consumer's object. Options from `options` map to their originals;\n // anything else already came from the consumer through `selectedOptions`.\n const toPublicOption = useCallback(\n (option: OptionDefinition): OptionListProps.Option => originals.get(option) ?? (option as OptionListProps.Option),\n [originals]\n );\n const toPublicGroup = useCallback(\n (group: OptionGroup): OptionListProps.OptionGroup =>\n originalGroups.get(group) ?? (group as OptionListProps.OptionGroup),\n [originalGroups]\n );\n\n const [selectedOptions = EMPTY_SELECTION, setSelectedOptions] = useControllable(\n controlledSelectedOptions,\n onChange,\n EMPTY_SELECTION,\n { componentName: 'OptionList', controlledProp: 'selectedOptions', changeHandler: 'onChange' }\n );\n\n const selection =\n selectionType === 'multi'\n ? multiSelection(selectedOptions, { options: listOptions, interactiveGroups: true })\n : singleSelection(selectedOptions);\n\n const { listRef, listProps, scrollToIndex, highlightType, announcement, getOptionProps, getRootProps } =\n useOptionList({\n options: listOptions,\n selection,\n onSelect: option => {\n const nextSelectedOptions = selection.getNextSelection(option).map(toPublicOption);\n setSelectedOptions(nextSelectedOptions);\n fireNonCancelableEvent(onChange, { selectedOptions: nextSelectedOptions });\n },\n getParent: option => parentMap.get(option)?.option as OptionGroup | undefined,\n selectedAriaLabel: i18n('i18nStrings.selectedAriaLabel', i18nStrings?.selectedAriaLabel),\n // The consumer receives its own option and group objects, as with `renderOption`.\n renderHighlightedAriaLive:\n renderHighlightedAriaLive &&\n ((option, group) =>\n renderHighlightedAriaLive(\n isGroup(option) ? toPublicGroup(option) : toPublicOption(option),\n group && toPublicGroup(group)\n )),\n });\n useForwardFocus(ref, listRef);\n\n const renderOriginalOption = useMemo<ListboxRenderOption | undefined>(() => {\n if (!renderOption) {\n return undefined;\n }\n const toGroupItem = (item: ListboxGroupItem): OptionListProps.OptionGroupItem => ({\n ...item,\n option: toPublicGroup(item.option),\n });\n return ({ item }) => {\n if (item.type === 'item') {\n const parent = item.parent && toGroupItem(item.parent);\n return renderOption({ item: { ...item, option: toPublicOption(item.option), parent } });\n }\n if (item.type === 'group') {\n return renderOption({ item: toGroupItem(item) });\n }\n // The listbox renders only options and group headers; it has no trigger or select-all item.\n return null;\n };\n }, [renderOption, toPublicOption, toPublicGroup]);\n\n return (\n <div\n {...baseProps}\n className={clsx(baseProps.className, styles.root, testClasses.root)}\n ref={__internalRootRef}\n {...getRootProps()}\n >\n <PlainList\n ref={scrollToIndex}\n listProps={{ ...listProps, ariaLabel, ariaLabelledby, ariaDescribedby }}\n filteredOptions={listOptions}\n filteringValue=\"\"\n highlightType={highlightType}\n selectionType={selection.selectionType}\n isMultiSelect={listProps.isMultiSelect}\n screenReaderContent={announcement}\n renderOption={renderOriginalOption}\n scrollStrategy=\"ancestors\"\n getOptionProps={(option, index) => ({\n ...getOptionProps(option, index),\n // There is no dropdown border above the list, so the first item has no top divider.\n hideTopDivider: index === 0,\n className: option.type === 'parent' ? testClasses['group-header'] : testClasses.option,\n 'data-value': option.option.value,\n })}\n />\n </div>\n );\n }\n);\n\nexport default InternalOptionList;\n"]}
@@ -0,0 +1,6 @@
1
+
2
+ import './styles.scoped.css';
3
+ export default {
4
+ "root": "awsui_root_15gzf_1ozs6_9"
5
+ };
6
+
@@ -0,0 +1,40 @@
1
+ /*
2
+ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /* stylelint-disable @cloudscape-design/no-motion-outside-of-mixin, selector-combinator-disallowed-list, selector-pseudo-class-no-unknown, selector-class-pattern */
6
+ /* stylelint-enable @cloudscape-design/no-motion-outside-of-mixin, selector-combinator-disallowed-list, selector-pseudo-class-no-unknown, selector-class-pattern */
7
+ /* Style used for links in slots/components that are text heavy, to help links stand out among
8
+ surrounding text. (WCAG F73) https://www.w3.org/WAI/WCAG21/Techniques/failures/F73#description */
9
+ .awsui_root_15gzf_1ozs6_9:not(#\9) {
10
+ border-collapse: separate;
11
+ border-spacing: 0;
12
+ box-sizing: border-box;
13
+ caption-side: top;
14
+ cursor: auto;
15
+ direction: inherit;
16
+ empty-cells: show;
17
+ font-family: serif;
18
+ font-style: normal;
19
+ font-variant: normal;
20
+ font-stretch: normal;
21
+ hyphens: none;
22
+ letter-spacing: normal;
23
+ list-style: disc outside none;
24
+ tab-size: 8;
25
+ text-align: start;
26
+ text-indent: 0;
27
+ text-shadow: none;
28
+ text-transform: none;
29
+ visibility: visible;
30
+ white-space: normal;
31
+ word-spacing: normal;
32
+ font-size: var(--font-size-body-m-diae7s, 14px);
33
+ line-height: var(--line-height-body-m-18p63n, 20px);
34
+ color: var(--color-text-body-default-9im48h, #0f141a);
35
+ font-weight: var(--font-weight-normal-jditlz, 400);
36
+ font-family: var(--font-family-base-khplu5, "Open Sans", "Helvetica Neue", Roboto, Arial, sans-serif);
37
+ -webkit-font-smoothing: auto;
38
+ -moz-osx-font-smoothing: auto;
39
+ display: block;
40
+ }
@@ -0,0 +1,7 @@
1
+
2
+ // es-module interop with Babel and Typescript
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ module.exports.default = {
5
+ "root": "awsui_root_15gzf_1ozs6_9"
6
+ };
7
+
@@ -0,0 +1,8 @@
1
+
2
+ import './styles.scoped.css';
3
+ export default {
4
+ "root": "awsui_root_1kbcw_1ufe3_5",
5
+ "option": "awsui_option_1kbcw_1ufe3_6",
6
+ "group-header": "awsui_group-header_1kbcw_1ufe3_7"
7
+ };
8
+
@@ -0,0 +1,9 @@
1
+ /*
2
+ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ .awsui_root_1kbcw_1ufe3_5:not(#\9),
6
+ .awsui_option_1kbcw_1ufe3_6:not(#\9),
7
+ .awsui_group-header_1kbcw_1ufe3_7:not(#\9) {
8
+ /* used in test-utils */
9
+ }
@@ -0,0 +1,9 @@
1
+
2
+ // es-module interop with Babel and Typescript
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ module.exports.default = {
5
+ "root": "awsui_root_1kbcw_1ufe3_5",
6
+ "option": "awsui_option_1kbcw_1ufe3_6",
7
+ "group-header": "awsui_group-header_1kbcw_1ufe3_7"
8
+ };
9
+
@@ -0,0 +1,36 @@
1
+ import { ListElementProps } from '../internal/components/listbox/interfaces';
2
+ import { SelectionModel } from '../internal/components/listbox/selection/interfaces';
3
+ import { UseListboxProps } from '../internal/components/listbox/use-listbox';
4
+ import { DropdownOption } from '../internal/components/option/interfaces';
5
+ interface UseOptionListProps extends Pick<UseListboxProps, 'getParent' | 'selectedAriaLabel' | 'renderHighlightedAriaLive'> {
6
+ /** Flattened options in list order. */
7
+ options: ReadonlyArray<DropdownOption>;
8
+ selection: SelectionModel;
9
+ /** Called with the interactive option the user chose. */
10
+ onSelect: (option: DropdownOption) => void;
11
+ }
12
+ /**
13
+ * The list state of OptionList: the shared `useListbox` with OptionList's settings, plus the parts of a list that is
14
+ * always visible. The list is a tab stop; keyboard, mouse and aria-activedescendant come from `useListbox`.
15
+ * This hook adds focus and blur, the mouse-leave reset and type-ahead.
16
+ */
17
+ export declare function useOptionList({
18
+ options,
19
+ selection,
20
+ onSelect,
21
+ getParent,
22
+ selectedAriaLabel,
23
+ renderHighlightedAriaLive
24
+ }: UseOptionListProps): {
25
+ listRef: import("react").RefObject<HTMLDivElement>;
26
+ listProps: ListElementProps;
27
+ scrollToIndex: import("react").RefObject<import("../internal/components/listbox/interfaces").ScrollToIndexRef>;
28
+ highlightType: import("../internal/components/options-list/utils/use-highlight-option").HighlightType;
29
+ announcement: string;
30
+ getOptionProps: (option: DropdownOption, index: number) => ReturnType<typeof import("../internal/components/listbox/utils/option-props").getListboxOptionProps>;
31
+ getRootProps: () => {
32
+ onKeyDown: (event: React.KeyboardEvent) => void;
33
+ onMouseLeave: () => void;
34
+ };
35
+ };
36
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-option-list.d.ts","sourceRoot":"","sources":["../../../src/option-list/use-option-list.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AACrF,OAAO,EAAc,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAEzF,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAE1E,UAAU,kBACR,SAAQ,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,mBAAmB,GAAG,2BAA2B,CAAC;IAC9F,uCAAuC;IACvC,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACvC,SAAS,EAAE,cAAc,CAAC;IAC1B,yDAAyD;IACzD,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;CAC5C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EACP,SAAS,EACT,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,yBAAyB,GAC1B,EAAE,kBAAkB;;;;;;;;;;;EA0EpB"}
@@ -0,0 +1,69 @@
1
+ import { useListbox } from '../internal/components/listbox/use-listbox';
2
+ import { useTypeAhead } from '../internal/components/listbox/use-type-ahead';
3
+ /**
4
+ * The list state of OptionList: the shared `useListbox` with OptionList's settings, plus the parts of a list that is
5
+ * always visible. The list is a tab stop; keyboard, mouse and aria-activedescendant come from `useListbox`.
6
+ * This hook adds focus and blur, the mouse-leave reset and type-ahead.
7
+ */
8
+ export function useOptionList({ options, selection, onSelect, getParent, selectedAriaLabel, renderHighlightedAriaLive, }) {
9
+ const { listRef, getListProps, scrollToIndex, highlightType, announcement, getOptionProps, highlightedOption, highlight, selectedOptions, } = useListbox({
10
+ options,
11
+ selectedOptions: selection.selectedOptions,
12
+ selection,
13
+ interactiveGroups: selection.interactiveGroups,
14
+ onSelect,
15
+ // When the list has focus, Space always chooses.
16
+ spaceSelects: 'always',
17
+ getParent,
18
+ selectedAriaLabel,
19
+ renderHighlightedAriaLive,
20
+ });
21
+ // Focus entry, like opening Select or Multiselect with the keyboard: highlight the first selected option (in
22
+ // selection order) and scroll it into view, or the first option when nothing in the list is selected.
23
+ // A highlight that is already there, such as a hover highlight, is kept, so a click selects the hovered option.
24
+ const onFocus = () => {
25
+ if (highlightedOption) {
26
+ return;
27
+ }
28
+ const firstSelected = selectedOptions.find(option => options.includes(option));
29
+ if (firstSelected) {
30
+ highlight.highlightOptionWithKeyboard(firstSelected);
31
+ }
32
+ else {
33
+ highlight.goHomeWithKeyboard();
34
+ }
35
+ };
36
+ const listProps = {
37
+ ...getListProps({ withKeyboard: true }),
38
+ onFocus,
39
+ // Like closing Select or Multiselect, leaving the list clears the highlight.
40
+ onBlur: () => highlight.resetHighlightWithKeyboard(),
41
+ open: true,
42
+ // The list element is a tab stop without dropdown corners.
43
+ embedded: true,
44
+ isMultiSelect: selection.selectionType === 'multi' || undefined,
45
+ };
46
+ // Attached to the root, not the list, so leaving the whole component clears a hover highlight.
47
+ const onMouseLeave = () => {
48
+ if (listRef.current !== document.activeElement) {
49
+ highlight.resetHighlightWithKeyboard();
50
+ }
51
+ };
52
+ const onTypeAhead = useTypeAhead({
53
+ isEnabled: true,
54
+ options,
55
+ highlightOption: highlight.highlightOptionWithKeyboard,
56
+ highlightedOption: highlightedOption === null || highlightedOption === void 0 ? void 0 : highlightedOption.option,
57
+ interactiveGroups: selection.interactiveGroups,
58
+ });
59
+ return {
60
+ listRef,
61
+ listProps,
62
+ scrollToIndex,
63
+ highlightType,
64
+ announcement,
65
+ getOptionProps,
66
+ getRootProps: () => ({ onKeyDown: onTypeAhead, onMouseLeave }),
67
+ };
68
+ }
69
+ //# sourceMappingURL=use-option-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-option-list.js","sourceRoot":"","sources":["../../../src/option-list/use-option-list.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAmB,MAAM,4CAA4C,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAC;AAY7E;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,OAAO,EACP,SAAS,EACT,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,yBAA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AC,0BAA0B,EAAE,CAAC;QACzC,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,YAAY,CAAC;QAC/B,SAAS,EAAE,IAAI;QACf,OAAO;QACP,eAAe,EAAE,SAAS,CAAC,2BAA2B;QACtD,iBAAiB,EAAE,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,MAAM;QAC5C,iBAAiB,EAAE,SAAS,CAAC,iBAAiB;KAC/C,CAAC,CAAC;IAEH,OAAO;QACL,OAAO;QACP,SAAS;QACT,aAAa;QACb,aAAa;QACb,YAAY;QACZ,cAAc;QACd,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC;KAC/D,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ListElementProps } from '../internal/components/listbox/interfaces';\nimport { SelectionModel } from '../internal/components/listbox/selection/interfaces';\nimport { useListbox, UseListboxProps } from '../internal/components/listbox/use-listbox';\nimport { useTypeAhead } from '../internal/components/listbox/use-type-ahead';\nimport { DropdownOption } from '../internal/components/option/interfaces';\n\ninterface UseOptionListProps\n extends Pick<UseListboxProps, 'getParent' | 'selectedAriaLabel' | 'renderHighlightedAriaLive'> {\n /** Flattened options in list order. */\n options: ReadonlyArray<DropdownOption>;\n selection: SelectionModel;\n /** Called with the interactive option the user chose. */\n onSelect: (option: DropdownOption) => void;\n}\n\n/**\n * The list state of OptionList: the shared `useListbox` with OptionList's settings, plus the parts of a list that is\n * always visible. The list is a tab stop; keyboard, mouse and aria-activedescendant come from `useListbox`.\n * This hook adds focus and blur, the mouse-leave reset and type-ahead.\n */\nexport function useOptionList({\n options,\n selection,\n onSelect,\n getParent,\n selectedAriaLabel,\n renderHighlightedAriaLive,\n}: UseOptionListProps) {\n const {\n listRef,\n getListProps,\n scrollToIndex,\n highlightType,\n announcement,\n getOptionProps,\n highlightedOption,\n highlight,\n selectedOptions,\n } = useListbox({\n options,\n selectedOptions: selection.selectedOptions,\n selection,\n interactiveGroups: selection.interactiveGroups,\n onSelect,\n // When the list has focus, Space always chooses.\n spaceSelects: 'always',\n getParent,\n selectedAriaLabel,\n renderHighlightedAriaLive,\n });\n\n // Focus entry, like opening Select or Multiselect with the keyboard: highlight the first selected option (in\n // selection order) and scroll it into view, or the first option when nothing in the list is selected.\n // A highlight that is already there, such as a hover highlight, is kept, so a click selects the hovered option.\n const onFocus = () => {\n if (highlightedOption) {\n return;\n }\n const firstSelected = selectedOptions.find(option => options.includes(option));\n if (firstSelected) {\n highlight.highlightOptionWithKeyboard(firstSelected);\n } else {\n highlight.goHomeWithKeyboard();\n }\n };\n\n const listProps: ListElementProps = {\n ...getListProps({ withKeyboard: true }),\n onFocus,\n // Like closing Select or Multiselect, leaving the list clears the highlight.\n onBlur: () => highlight.resetHighlightWithKeyboard(),\n open: true,\n // The list element is a tab stop without dropdown corners.\n embedded: true,\n isMultiSelect: selection.selectionType === 'multi' || undefined,\n };\n\n // Attached to the root, not the list, so leaving the whole component clears a hover highlight.\n const onMouseLeave = () => {\n if (listRef.current !== document.activeElement) {\n highlight.resetHighlightWithKeyboard();\n }\n };\n\n const onTypeAhead = useTypeAhead({\n isEnabled: true,\n options,\n highlightOption: highlight.highlightOptionWithKeyboard,\n highlightedOption: highlightedOption?.option,\n interactiveGroups: selection.interactiveGroups,\n });\n\n return {\n listRef,\n listProps,\n scrollToIndex,\n highlightType,\n announcement,\n getOptionProps,\n getRootProps: () => ({ onKeyDown: onTypeAhead, onMouseLeave }),\n };\n}\n"]}
package/package.json CHANGED
@@ -92,6 +92,7 @@
92
92
  "./modal": "./modal/index.js",
93
93
  "./multiselect": "./multiselect/index.js",
94
94
  "./navigable-group": "./navigable-group/index.js",
95
+ "./option-list": "./option-list/index.js",
95
96
  "./pagination": "./pagination/index.js",
96
97
  "./panel-layout": "./panel-layout/index.js",
97
98
  "./pie-chart": "./pie-chart/index.js",
@@ -252,6 +253,8 @@
252
253
  "./test-utils/selectors/multiselect": "./test-utils/selectors/multiselect/index.js",
253
254
  "./test-utils/dom/navigable-group": "./test-utils/dom/navigable-group/index.js",
254
255
  "./test-utils/selectors/navigable-group": "./test-utils/selectors/navigable-group/index.js",
256
+ "./test-utils/dom/option-list": "./test-utils/dom/option-list/index.js",
257
+ "./test-utils/selectors/option-list": "./test-utils/selectors/option-list/index.js",
255
258
  "./test-utils/dom/pagination": "./test-utils/dom/pagination/index.js",
256
259
  "./test-utils/selectors/pagination": "./test-utils/selectors/pagination/index.js",
257
260
  "./test-utils/dom/panel-layout": "./test-utils/dom/panel-layout/index.js",
@@ -380,7 +383,7 @@
380
383
  "./internal/base-theme/styles.css.js",
381
384
  "./internal/base-component/styles.css.js"
382
385
  ],
383
- "version": "3.0.1412",
386
+ "version": "3.0.1413",
384
387
  "repository": {
385
388
  "type": "git",
386
389
  "url": "https://github.com/cloudscape-design/components.git"
@@ -8,7 +8,7 @@ import InternalTableRoot from './internal';
8
8
  function TableRoot({ columnLayout = { type: 'auto' }, ...props }) {
9
9
  const baseComponentProps = useBaseComponent('TableRoot', {
10
10
  props: {},
11
- metadata: { columnLayoutType: columnLayout.type },
11
+ metadata: { columnLayoutType: columnLayout.type, hasStickyHeader: !!props.stickyHeader },
12
12
  });
13
13
  return React.createElement(InternalTableRoot, { columnLayout: columnLayout, ...props, ...baseComponentProps });
14
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/table-root/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,YAAY,CAAC;AACb,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,iBAAiB,MAAM,YAAY,CAAC;AAK3C,SAAS,SAAS,CAAC,EAAE,YAAY,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,EAAkB;IAC9E,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,WAAW,EAAE;QACvD,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE,gBAAgB,EAAE,YAAY,CAAC,IAAI,EAAE;KAClD,CAAC,CAAC;IACH,OAAO,oBAAC,iBAAiB,IAAC,YAAY,EAAE,YAAY,KAAM,KAAK,KAAM,kBAAkB,GAAI,CAAC;AAC9F,CAAC;AAED,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAEzC,eAAe,SAAS,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n'use client';\nimport React from 'react';\n\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport { TableRootProps } from './interfaces';\nimport InternalTableRoot from './internal';\n\n// Each part is its own top-level component (one default export + props type) so the documenter documents it separately.\nexport { TableRootProps };\n\nfunction TableRoot({ columnLayout = { type: 'auto' }, ...props }: TableRootProps) {\n const baseComponentProps = useBaseComponent('TableRoot', {\n props: {},\n metadata: { columnLayoutType: columnLayout.type },\n });\n return <InternalTableRoot columnLayout={columnLayout} {...props} {...baseComponentProps} />;\n}\n\napplyDisplayName(TableRoot, 'TableRoot');\n\nexport default TableRoot;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/table-root/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,YAAY,CAAC;AACb,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,iBAAiB,MAAM,YAAY,CAAC;AAK3C,SAAS,SAAS,CAAC,EAAE,YAAY,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,EAAkB;IAC9E,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,WAAW,EAAE;QACvD,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE,gBAAgB,EAAE,YAAY,CAAC,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE;KACzF,CAAC,CAAC;IACH,OAAO,oBAAC,iBAAiB,IAAC,YAAY,EAAE,YAAY,KAAM,KAAK,KAAM,kBAAkB,GAAI,CAAC;AAC9F,CAAC;AAED,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAEzC,eAAe,SAAS,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n'use client';\nimport React from 'react';\n\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport { TableRootProps } from './interfaces';\nimport InternalTableRoot from './internal';\n\n// Each part is its own top-level component (one default export + props type) so the documenter documents it separately.\nexport { TableRootProps };\n\nfunction TableRoot({ columnLayout = { type: 'auto' }, ...props }: TableRootProps) {\n const baseComponentProps = useBaseComponent('TableRoot', {\n props: {},\n metadata: { columnLayoutType: columnLayout.type, hasStickyHeader: !!props.stickyHeader },\n });\n return <InternalTableRoot columnLayout={columnLayout} {...props} {...baseComponentProps} />;\n}\n\napplyDisplayName(TableRoot, 'TableRoot');\n\nexport default TableRoot;\n"]}
@@ -6,7 +6,8 @@ import { BaseComponentProps } from '../types/base-component';
6
6
  */
7
7
  export interface TableRootProps extends BaseComponentProps {
8
8
  /**
9
- * The table's content. Provide a `TableHead` followed by a `TableBody` that contains the rows.
9
+ * The table's content. Provide a `TableHead` followed by a `TableBody` that contains the rows. When you
10
+ * use `stickyHeader`, provide only the `TableBody` here.
10
11
  */
11
12
  children: React.ReactNode;
12
13
  /**
@@ -37,6 +38,19 @@ export interface TableRootProps extends BaseComponentProps {
37
38
  * subset of rows, such as with virtualization; otherwise it is derived from the DOM.
38
39
  */
39
40
  ariaRowcount?: number;
41
+ /**
42
+ * A `TableHead` that stays pinned to the top of its scroll container as the body scrolls. When you
43
+ * provide it, render only the `TableBody` as `children`.
44
+ *
45
+ * The header is rendered twice, as the real header and a pinned copy, so use controlled state for any
46
+ * controls in it.
47
+ */
48
+ stickyHeader?: React.ReactNode;
49
+ /**
50
+ * Specifies a vertical offset (in pixels) for the sticky header. For example, use this if you
51
+ * need to position the sticky header below other fixed position elements on the page.
52
+ */
53
+ stickyHeaderVerticalOffset?: number;
40
54
  }
41
55
  export declare namespace TableRootProps {
42
56
  type ColumnLayout = {
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/table-root/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,kBAAkB;IACxD;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B;;;;;;;;;;;;;;;OAeG;IACH,YAAY,CAAC,EAAE,cAAc,CAAC,YAAY,CAAC;IAE3C,kGAAkG;IAClG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mGAAmG;IACnG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uGAAuG;IACvG,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,yBAAiB,cAAc,CAAC;IAC9B,KAAY,YAAY,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAA;KAAE,CAAC;IAEzG,KAAY,gBAAgB,GACxB;QAAE,IAAI,EAAE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,CAAA;KAAE,CAAC;IAEzG,KAAY,gBAAgB,GACxB;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;QAAC,QAAQ,CAAC,EAAE,KAAK,CAAA;KAAE,GACpD;QAAE,IAAI,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,KAAK,CAAA;KAAE,GAC/D;QAAE,IAAI,CAAC,EAAE,KAAK,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5D"}
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/table-root/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 '../types/base-component';\n\n/**\n * A composable table. You render the head and rows as children, and TableRoot provides the column\n * layout and accessibility semantics.\n */\nexport interface TableRootProps extends BaseComponentProps {\n /**\n * The table's content. Provide a `TableHead` followed by a `TableBody` that contains the rows.\n */\n children: React.ReactNode;\n\n /**\n * Determines how column widths are calculated.\n * * `{ type: 'auto' }` - Renders a standard HTML table whose columns size to their content. No\n * column configuration is required.\n * * `{ type: 'grid'; columns: ColumnDefinition[] }` - Renders a CSS grid. The columns are then provided as\n * an array of objects with the following properties:\n * * `size` (number | { flex: number }) - A number sets a fixed pixel width; `{ flex }` gives the\n * column a weight that shares the remaining space in proportion. Omit it for a flexible column\n * with the default weight of 1.\n * * `minWidth` (number) - The minimum width in pixels for a flexible column. We recommend setting one;\n * without it the column can shrink until its content clips or overlaps at narrow widths.\n * * `maxWidth` (number) - Caps a flexible column's width in pixels (it grows up to the cap). A capped\n * column can't also carry a proportional `flex` weight, so weighting applies to the uncapped columns.\n *\n * Defaults to `{ type: 'auto' }`.\n */\n columnLayout?: TableRootProps.ColumnLayout;\n\n /** Provides an accessible name for the table. Use this or `ariaLabelledby` to label the table. */\n ariaLabel?: string;\n /** Sets the `aria-labelledby` attribute. Use the ID of a visible element that labels the table. */\n ariaLabelledby?: string;\n /** Sets the `aria-describedby` attribute. Use the ID of a visible element that describes the table. */\n ariaDescribedby?: string;\n\n /**\n * Sets the table's `aria-rowcount`, counting the header row. Provide it only when you render a\n * subset of rows, such as with virtualization; otherwise it is derived from the DOM.\n */\n ariaRowcount?: number;\n}\n\nexport namespace TableRootProps {\n export type ColumnLayout = { type: 'auto' } | { type: 'grid'; columns: ReadonlyArray<ColumnDefinition> };\n\n export type ColumnDefinition =\n | { size: number; minWidth?: never; maxWidth?: never }\n | { size: { flex: number }; minWidth?: number; maxWidth?: never }\n | { size?: never; minWidth?: number; maxWidth?: number };\n}\n"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/table-root/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 '../types/base-component';\n\n/**\n * A composable table. You render the head and rows as children, and TableRoot provides the column\n * layout and accessibility semantics.\n */\nexport interface TableRootProps extends BaseComponentProps {\n /**\n * The table's content. Provide a `TableHead` followed by a `TableBody` that contains the rows. When you\n * use `stickyHeader`, provide only the `TableBody` here.\n */\n children: React.ReactNode;\n\n /**\n * Determines how column widths are calculated.\n * * `{ type: 'auto' }` - Renders a standard HTML table whose columns size to their content. No\n * column configuration is required.\n * * `{ type: 'grid'; columns: ColumnDefinition[] }` - Renders a CSS grid. The columns are then provided as\n * an array of objects with the following properties:\n * * `size` (number | { flex: number }) - A number sets a fixed pixel width; `{ flex }` gives the\n * column a weight that shares the remaining space in proportion. Omit it for a flexible column\n * with the default weight of 1.\n * * `minWidth` (number) - The minimum width in pixels for a flexible column. We recommend setting one;\n * without it the column can shrink until its content clips or overlaps at narrow widths.\n * * `maxWidth` (number) - Caps a flexible column's width in pixels (it grows up to the cap). A capped\n * column can't also carry a proportional `flex` weight, so weighting applies to the uncapped columns.\n *\n * Defaults to `{ type: 'auto' }`.\n */\n columnLayout?: TableRootProps.ColumnLayout;\n\n /** Provides an accessible name for the table. Use this or `ariaLabelledby` to label the table. */\n ariaLabel?: string;\n /** Sets the `aria-labelledby` attribute. Use the ID of a visible element that labels the table. */\n ariaLabelledby?: string;\n /** Sets the `aria-describedby` attribute. Use the ID of a visible element that describes the table. */\n ariaDescribedby?: string;\n\n /**\n * Sets the table's `aria-rowcount`, counting the header row. Provide it only when you render a\n * subset of rows, such as with virtualization; otherwise it is derived from the DOM.\n */\n ariaRowcount?: number;\n\n /**\n * A `TableHead` that stays pinned to the top of its scroll container as the body scrolls. When you\n * provide it, render only the `TableBody` as `children`.\n *\n * The header is rendered twice, as the real header and a pinned copy, so use controlled state for any\n * controls in it.\n */\n stickyHeader?: React.ReactNode;\n\n /**\n * Specifies a vertical offset (in pixels) for the sticky header. For example, use this if you\n * need to position the sticky header below other fixed position elements on the page.\n */\n stickyHeaderVerticalOffset?: number;\n}\n\nexport namespace TableRootProps {\n export type ColumnLayout = { type: 'auto' } | { type: 'grid'; columns: ReadonlyArray<ColumnDefinition> };\n\n export type ColumnDefinition =\n | { size: number; minWidth?: never; maxWidth?: never }\n | { size: { flex: number }; minWidth?: number; maxWidth?: never }\n | { size?: never; minWidth?: number; maxWidth?: number };\n}\n"]}
@@ -7,6 +7,8 @@ export default function InternalTableRoot({
7
7
  ariaLabel,
8
8
  ariaLabelledby,
9
9
  ariaDescribedby,
10
+ stickyHeader,
11
+ stickyHeaderVerticalOffset,
10
12
  children,
11
13
  __internalRootRef,
12
14
  ...rest
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/table-root/internal.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAIlF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAI9C,MAAM,WAAW,sBAAuB,SAAQ,cAAc,EAAE,0BAA0B;CAAG;AAW7F,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,YAA+B,EAC/B,YAAY,EACZ,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,sBAAsB,eA8ExB"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/table-root/internal.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAIlF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAM9C,MAAM,WAAW,sBAAuB,SAAQ,cAAc,EAAE,0BAA0B;CAAG;AAW7F,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,YAA+B,EAC/B,YAAY,EACZ,SAAS,EACT,cAAc,EACd,eAAe,EACf,YAAY,EACZ,0BAA0B,EAC1B,QAAQ,EACR,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,sBAAsB,eA2GxB"}
@@ -2,12 +2,14 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import clsx from 'clsx';
5
- import { useResizeObserver } from '@cloudscape-design/component-toolkit/internal';
5
+ import { useMergeRefs, useResizeObserver } from '@cloudscape-design/component-toolkit/internal';
6
6
  import { getBaseProps } from '../internal/base-component';
7
7
  import { StickyScrollbar } from '../internal/components/sticky-scrollbar';
8
8
  import { useScrollSync } from '../internal/hooks/use-scroll-sync';
9
9
  import { TableContextProvider } from './context';
10
10
  import { computeGridTemplateColumns } from './grid-template-columns';
11
+ import StickyHeaderSlot from './sticky-header-slot';
12
+ import { useTableRootStickyHeader } from './use-sticky-header';
11
13
  import styles from './styles.css.js';
12
14
  // In grid layout the rows overflow the table element, so the scroller, not the table, measures the
13
15
  // scrollable width. scrollWidth is rounded to a whole pixel, so content that fits a fractional-width
@@ -17,7 +19,7 @@ function getScrollerContentInlineSize(_table, scroller) {
17
19
  ? scroller.scrollWidth
18
20
  : scroller.getBoundingClientRect().width;
19
21
  }
20
- export default function InternalTableRoot({ columnLayout = { type: 'auto' }, ariaRowcount, ariaLabel, ariaLabelledby, ariaDescribedby, children, __internalRootRef, ...rest }) {
22
+ export default function InternalTableRoot({ columnLayout = { type: 'auto' }, ariaRowcount, ariaLabel, ariaLabelledby, ariaDescribedby, stickyHeader, stickyHeaderVerticalOffset, children, __internalRootRef, ...rest }) {
21
23
  const isGrid = columnLayout.type === 'grid';
22
24
  const gridTemplateColumns = computeGridTemplateColumns(columnLayout);
23
25
  // Memoized because it is the TableContext value; a fresh object re-renders every cell. Both fields are
@@ -47,9 +49,17 @@ export default function InternalTableRoot({ columnLayout = { type: 'auto' }, ari
47
49
  measureScrollable();
48
50
  }
49
51
  }, [isGrid, gridTemplateColumns, measureScrollable]);
50
- const tableRef = useRef(null);
52
+ const rootRef = useRef(null);
53
+ const mergedRootRef = useMergeRefs(rootRef, __internalRootRef);
54
+ const sticky = useTableRootStickyHeader({
55
+ enabled: !!stickyHeader,
56
+ verticalOffset: stickyHeaderVerticalOffset,
57
+ isGrid,
58
+ rootRef,
59
+ scrollerRef,
60
+ });
51
61
  const scrollbarRef = useRef(null);
52
- const handleScroll = useScrollSync([scrollerRef, scrollbarRef]);
62
+ const handleScroll = useScrollSync([scrollerRef, scrollbarRef, sticky.copyScrollerRef]);
53
63
  // Set role="region" whenever scrollable (label passes through even if undefined), matching the
54
64
  // existing Table's getTableWrapperRoleProps rather than gating the role on a label.
55
65
  const scrollRegionProps = isScrollable
@@ -60,13 +70,15 @@ export default function InternalTableRoot({ columnLayout = { type: 'auto' }, ari
60
70
  'aria-labelledby': ariaLabelledby,
61
71
  }
62
72
  : {};
63
- return (React.createElement("div", { ...baseProps, className: clsx(baseProps.className, styles.root), ref: __internalRootRef },
73
+ return (React.createElement("div", { ...baseProps, className: clsx(baseProps.className, styles.root), ref: mergedRootRef },
64
74
  React.createElement(TableContextProvider, { value: tableContext },
65
- React.createElement("div", { className: styles['body-scroller'], ref: scrollerRef, onScroll: handleScroll, ...scrollRegionProps },
66
- React.createElement("table", { ref: tableRef,
67
- // Grid mode only: display:grid drops the table's implicit role. Auto mode keeps the
68
- // native role (an explicit role="table" there is redundant and flagged by a11y validators).
69
- role: isGrid ? 'table' : undefined, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, "aria-describedby": ariaDescribedby, "aria-rowcount": ariaRowcount, className: clsx(styles.table, isGrid ? styles['table-grid'] : styles['table-auto']) }, children)),
70
- React.createElement(StickyScrollbar, { ref: scrollbarRef, wrapperRef: scrollerRef, tableRef: tableRef, onScroll: handleScroll, getContentInlineSize: getScrollerContentInlineSize, contentKey: gridTemplateColumns }))));
75
+ sticky.isSticky && (React.createElement(StickyHeaderSlot, { slotRef: sticky.slotRef, copyScrollerRef: sticky.copyScrollerRef, copyTableRef: sticky.copyTableRef, onScroll: handleScroll, onFocus: sticky.onCopyFocus, isStuck: sticky.isStuck, isGrid: isGrid, style: sticky.stickyStyles.style }, stickyHeader)),
76
+ React.createElement("div", { className: styles['body-scroller'], ref: scrollerRef, onScroll: handleScroll, onFocus: sticky.onScrollerFocus, onBlur: sticky.onScrollerBlur, ...scrollRegionProps },
77
+ React.createElement("table", { ref: sticky.realTableRef,
78
+ // Without an explicit role, browsers guess whether a table holds data or is only for layout.
79
+ role: "table", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, "aria-describedby": ariaDescribedby, "aria-rowcount": ariaRowcount, className: clsx(styles.table, isGrid ? styles['table-grid'] : styles['table-auto']) },
80
+ stickyHeader,
81
+ children)),
82
+ React.createElement(StickyScrollbar, { ref: scrollbarRef, wrapperRef: scrollerRef, tableRef: sticky.realTableRef, onScroll: handleScroll, getContentInlineSize: getScrollerContentInlineSize, contentKey: gridTemplateColumns }))));
71
83
  }
72
84
  //# sourceMappingURL=internal.js.map