@react-spectrum/tag 3.3.10 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/dist/import.mjs +3 -3
  2. package/dist/main.js +4 -4
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +3 -3
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +3 -0
  7. package/package.json +14 -39
  8. package/src/index.ts +4 -3
  9. package/dist/Tag.main.js +0 -95
  10. package/dist/Tag.main.js.map +0 -1
  11. package/dist/Tag.mjs +0 -90
  12. package/dist/Tag.module.js +0 -90
  13. package/dist/Tag.module.js.map +0 -1
  14. package/dist/TagGroup.main.js +0 -269
  15. package/dist/TagGroup.main.js.map +0 -1
  16. package/dist/TagGroup.mjs +0 -264
  17. package/dist/TagGroup.module.js +0 -264
  18. package/dist/TagGroup.module.js.map +0 -1
  19. package/dist/ar-AE.main.js +0 -9
  20. package/dist/ar-AE.main.js.map +0 -1
  21. package/dist/ar-AE.mjs +0 -11
  22. package/dist/ar-AE.module.js +0 -11
  23. package/dist/ar-AE.module.js.map +0 -1
  24. package/dist/bg-BG.main.js +0 -9
  25. package/dist/bg-BG.main.js.map +0 -1
  26. package/dist/bg-BG.mjs +0 -11
  27. package/dist/bg-BG.module.js +0 -11
  28. package/dist/bg-BG.module.js.map +0 -1
  29. package/dist/cs-CZ.main.js +0 -9
  30. package/dist/cs-CZ.main.js.map +0 -1
  31. package/dist/cs-CZ.mjs +0 -11
  32. package/dist/cs-CZ.module.js +0 -11
  33. package/dist/cs-CZ.module.js.map +0 -1
  34. package/dist/da-DK.main.js +0 -9
  35. package/dist/da-DK.main.js.map +0 -1
  36. package/dist/da-DK.mjs +0 -11
  37. package/dist/da-DK.module.js +0 -11
  38. package/dist/da-DK.module.js.map +0 -1
  39. package/dist/de-DE.main.js +0 -9
  40. package/dist/de-DE.main.js.map +0 -1
  41. package/dist/de-DE.mjs +0 -11
  42. package/dist/de-DE.module.js +0 -11
  43. package/dist/de-DE.module.js.map +0 -1
  44. package/dist/el-GR.main.js +0 -9
  45. package/dist/el-GR.main.js.map +0 -1
  46. package/dist/el-GR.mjs +0 -11
  47. package/dist/el-GR.module.js +0 -11
  48. package/dist/el-GR.module.js.map +0 -1
  49. package/dist/en-US.main.js +0 -9
  50. package/dist/en-US.main.js.map +0 -1
  51. package/dist/en-US.mjs +0 -11
  52. package/dist/en-US.module.js +0 -11
  53. package/dist/en-US.module.js.map +0 -1
  54. package/dist/es-ES.main.js +0 -9
  55. package/dist/es-ES.main.js.map +0 -1
  56. package/dist/es-ES.mjs +0 -11
  57. package/dist/es-ES.module.js +0 -11
  58. package/dist/es-ES.module.js.map +0 -1
  59. package/dist/et-EE.main.js +0 -9
  60. package/dist/et-EE.main.js.map +0 -1
  61. package/dist/et-EE.mjs +0 -11
  62. package/dist/et-EE.module.js +0 -11
  63. package/dist/et-EE.module.js.map +0 -1
  64. package/dist/fi-FI.main.js +0 -9
  65. package/dist/fi-FI.main.js.map +0 -1
  66. package/dist/fi-FI.mjs +0 -11
  67. package/dist/fi-FI.module.js +0 -11
  68. package/dist/fi-FI.module.js.map +0 -1
  69. package/dist/fr-FR.main.js +0 -9
  70. package/dist/fr-FR.main.js.map +0 -1
  71. package/dist/fr-FR.mjs +0 -11
  72. package/dist/fr-FR.module.js +0 -11
  73. package/dist/fr-FR.module.js.map +0 -1
  74. package/dist/he-IL.main.js +0 -9
  75. package/dist/he-IL.main.js.map +0 -1
  76. package/dist/he-IL.mjs +0 -11
  77. package/dist/he-IL.module.js +0 -11
  78. package/dist/he-IL.module.js.map +0 -1
  79. package/dist/hr-HR.main.js +0 -9
  80. package/dist/hr-HR.main.js.map +0 -1
  81. package/dist/hr-HR.mjs +0 -11
  82. package/dist/hr-HR.module.js +0 -11
  83. package/dist/hr-HR.module.js.map +0 -1
  84. package/dist/hu-HU.main.js +0 -9
  85. package/dist/hu-HU.main.js.map +0 -1
  86. package/dist/hu-HU.mjs +0 -11
  87. package/dist/hu-HU.module.js +0 -11
  88. package/dist/hu-HU.module.js.map +0 -1
  89. package/dist/intlStrings.main.js +0 -108
  90. package/dist/intlStrings.main.js.map +0 -1
  91. package/dist/intlStrings.mjs +0 -110
  92. package/dist/intlStrings.module.js +0 -110
  93. package/dist/intlStrings.module.js.map +0 -1
  94. package/dist/it-IT.main.js +0 -9
  95. package/dist/it-IT.main.js.map +0 -1
  96. package/dist/it-IT.mjs +0 -11
  97. package/dist/it-IT.module.js +0 -11
  98. package/dist/it-IT.module.js.map +0 -1
  99. package/dist/ja-JP.main.js +0 -9
  100. package/dist/ja-JP.main.js.map +0 -1
  101. package/dist/ja-JP.mjs +0 -11
  102. package/dist/ja-JP.module.js +0 -11
  103. package/dist/ja-JP.module.js.map +0 -1
  104. package/dist/ko-KR.main.js +0 -9
  105. package/dist/ko-KR.main.js.map +0 -1
  106. package/dist/ko-KR.mjs +0 -11
  107. package/dist/ko-KR.module.js +0 -11
  108. package/dist/ko-KR.module.js.map +0 -1
  109. package/dist/lt-LT.main.js +0 -9
  110. package/dist/lt-LT.main.js.map +0 -1
  111. package/dist/lt-LT.mjs +0 -11
  112. package/dist/lt-LT.module.js +0 -11
  113. package/dist/lt-LT.module.js.map +0 -1
  114. package/dist/lv-LV.main.js +0 -9
  115. package/dist/lv-LV.main.js.map +0 -1
  116. package/dist/lv-LV.mjs +0 -11
  117. package/dist/lv-LV.module.js +0 -11
  118. package/dist/lv-LV.module.js.map +0 -1
  119. package/dist/nb-NO.main.js +0 -9
  120. package/dist/nb-NO.main.js.map +0 -1
  121. package/dist/nb-NO.mjs +0 -11
  122. package/dist/nb-NO.module.js +0 -11
  123. package/dist/nb-NO.module.js.map +0 -1
  124. package/dist/nl-NL.main.js +0 -9
  125. package/dist/nl-NL.main.js.map +0 -1
  126. package/dist/nl-NL.mjs +0 -11
  127. package/dist/nl-NL.module.js +0 -11
  128. package/dist/nl-NL.module.js.map +0 -1
  129. package/dist/pl-PL.main.js +0 -9
  130. package/dist/pl-PL.main.js.map +0 -1
  131. package/dist/pl-PL.mjs +0 -11
  132. package/dist/pl-PL.module.js +0 -11
  133. package/dist/pl-PL.module.js.map +0 -1
  134. package/dist/pt-BR.main.js +0 -9
  135. package/dist/pt-BR.main.js.map +0 -1
  136. package/dist/pt-BR.mjs +0 -11
  137. package/dist/pt-BR.module.js +0 -11
  138. package/dist/pt-BR.module.js.map +0 -1
  139. package/dist/pt-PT.main.js +0 -9
  140. package/dist/pt-PT.main.js.map +0 -1
  141. package/dist/pt-PT.mjs +0 -11
  142. package/dist/pt-PT.module.js +0 -11
  143. package/dist/pt-PT.module.js.map +0 -1
  144. package/dist/ro-RO.main.js +0 -9
  145. package/dist/ro-RO.main.js.map +0 -1
  146. package/dist/ro-RO.mjs +0 -11
  147. package/dist/ro-RO.module.js +0 -11
  148. package/dist/ro-RO.module.js.map +0 -1
  149. package/dist/ru-RU.main.js +0 -9
  150. package/dist/ru-RU.main.js.map +0 -1
  151. package/dist/ru-RU.mjs +0 -11
  152. package/dist/ru-RU.module.js +0 -11
  153. package/dist/ru-RU.module.js.map +0 -1
  154. package/dist/sk-SK.main.js +0 -9
  155. package/dist/sk-SK.main.js.map +0 -1
  156. package/dist/sk-SK.mjs +0 -11
  157. package/dist/sk-SK.module.js +0 -11
  158. package/dist/sk-SK.module.js.map +0 -1
  159. package/dist/sl-SI.main.js +0 -9
  160. package/dist/sl-SI.main.js.map +0 -1
  161. package/dist/sl-SI.mjs +0 -11
  162. package/dist/sl-SI.module.js +0 -11
  163. package/dist/sl-SI.module.js.map +0 -1
  164. package/dist/sr-SP.main.js +0 -9
  165. package/dist/sr-SP.main.js.map +0 -1
  166. package/dist/sr-SP.mjs +0 -11
  167. package/dist/sr-SP.module.js +0 -11
  168. package/dist/sr-SP.module.js.map +0 -1
  169. package/dist/sv-SE.main.js +0 -9
  170. package/dist/sv-SE.main.js.map +0 -1
  171. package/dist/sv-SE.mjs +0 -11
  172. package/dist/sv-SE.module.js +0 -11
  173. package/dist/sv-SE.module.js.map +0 -1
  174. package/dist/tag.9dd3cf2c.css +0 -270
  175. package/dist/tag.9dd3cf2c.css.map +0 -1
  176. package/dist/tags_vars_css.main.js +0 -86
  177. package/dist/tags_vars_css.main.js.map +0 -1
  178. package/dist/tags_vars_css.mjs +0 -88
  179. package/dist/tags_vars_css.module.js +0 -88
  180. package/dist/tags_vars_css.module.js.map +0 -1
  181. package/dist/tr-TR.main.js +0 -9
  182. package/dist/tr-TR.main.js.map +0 -1
  183. package/dist/tr-TR.mjs +0 -11
  184. package/dist/tr-TR.module.js +0 -11
  185. package/dist/tr-TR.module.js.map +0 -1
  186. package/dist/types.d.ts +0 -20
  187. package/dist/types.d.ts.map +0 -1
  188. package/dist/uk-UA.main.js +0 -9
  189. package/dist/uk-UA.main.js.map +0 -1
  190. package/dist/uk-UA.mjs +0 -11
  191. package/dist/uk-UA.module.js +0 -11
  192. package/dist/uk-UA.module.js.map +0 -1
  193. package/dist/zh-CN.main.js +0 -9
  194. package/dist/zh-CN.main.js.map +0 -1
  195. package/dist/zh-CN.mjs +0 -11
  196. package/dist/zh-CN.module.js +0 -11
  197. package/dist/zh-CN.module.js.map +0 -1
  198. package/dist/zh-TW.main.js +0 -9
  199. package/dist/zh-TW.main.js.map +0 -1
  200. package/dist/zh-TW.mjs +0 -11
  201. package/dist/zh-TW.module.js +0 -11
  202. package/dist/zh-TW.module.js.map +0 -1
  203. package/src/Tag.tsx +0 -87
  204. package/src/TagGroup.tsx +0 -278
package/src/TagGroup.tsx DELETED
@@ -1,278 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {ActionButton} from '@react-spectrum/button';
14
- import {AriaTagGroupProps, useTagGroup} from '@react-aria/tag';
15
- import {classNames, useDOMRef} from '@react-spectrum/utils';
16
- import {Collection, DOMRef, Node, SpectrumLabelableProps, StyleProps, Validation} from '@react-types/shared';
17
- import {Field} from '@react-spectrum/label';
18
- import {FocusRing, FocusScope} from '@react-aria/focus';
19
- // @ts-ignore
20
- import intlMessages from '../intl/*.json';
21
- import {ListCollection, useListState} from '@react-stately/list';
22
- import {ListKeyboardDelegate} from '@react-aria/selection';
23
- import {Provider, useProvider, useProviderProps} from '@react-spectrum/provider';
24
- import React, {JSX, ReactNode, useCallback, useEffect, useMemo, useRef, useState} from 'react';
25
- import styles from '@adobe/spectrum-css-temp/components/tags/vars.css';
26
- import {Tag} from './Tag';
27
- import {useFormProps} from '@react-spectrum/form';
28
- import {useId, useLayoutEffect, useResizeObserver, useValueEffect} from '@react-aria/utils';
29
- import {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
30
-
31
- const TAG_STYLES = {
32
- medium: {
33
- height: 24,
34
- margin: 4
35
- },
36
- large: {
37
- height: 30,
38
- margin: 5
39
- }
40
- };
41
-
42
- export interface SpectrumTagGroupProps<T> extends Omit<AriaTagGroupProps<T>, 'selectionMode' | 'disallowEmptySelection' | 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange' | 'selectionBehavior' | 'disabledKeys'>, StyleProps, Omit<SpectrumLabelableProps, 'isRequired' | 'necessityIndicator'>, Pick<Validation<any>, 'isInvalid' | 'validationState'> {
43
- /** The label to display on the action button. */
44
- actionLabel?: string,
45
- /** Handler that is called when the action button is pressed. */
46
- onAction?: () => void,
47
- /** Sets what the TagGroup should render when there are no tags to display. */
48
- renderEmptyState?: () => JSX.Element,
49
- /** Limit the number of rows initially shown. This will render a button that allows the user to expand to show all tags. */
50
- maxRows?: number
51
- }
52
-
53
- /** Tags allow users to categorize content. They can represent keywords or people, and are grouped to describe an item or a search request. */
54
- export const TagGroup = React.forwardRef(function TagGroup<T extends object>(props: SpectrumTagGroupProps<T>, ref: DOMRef<HTMLDivElement>) {
55
- props = useProviderProps(props);
56
- props = useFormProps(props);
57
- let {
58
- maxRows,
59
- children,
60
- actionLabel,
61
- onAction,
62
- labelPosition,
63
- renderEmptyState = () => stringFormatter.format('noTags')
64
- } = props;
65
- let domRef = useDOMRef(ref);
66
- let containerRef = useRef<HTMLDivElement>(null);
67
- let tagsRef = useRef<HTMLDivElement | null>(null);
68
- let {direction} = useLocale();
69
- let {scale} = useProvider();
70
- let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/tag');
71
- let [isCollapsed, setIsCollapsed] = useState(maxRows != null);
72
- let state = useListState(props);
73
- let [tagState, setTagState] = useValueEffect({visibleTagCount: state.collection.size, showCollapseButton: false});
74
- let keyboardDelegate = useMemo(() => {
75
- let collection = (isCollapsed
76
- ? new ListCollection([...state.collection].slice(0, tagState.visibleTagCount))
77
- : new ListCollection([...state.collection])) as Collection<Node<T>>;
78
- return new ListKeyboardDelegate({
79
- collection,
80
- ref: tagsRef,
81
- direction,
82
- orientation: 'horizontal'
83
- });
84
- }, [direction, isCollapsed, state.collection, tagState.visibleTagCount, tagsRef]) as ListKeyboardDelegate<T>;
85
- // Remove onAction from props so it doesn't make it into useGridList.
86
- delete props.onAction;
87
- let {gridProps, labelProps, descriptionProps, errorMessageProps} = useTagGroup({...props, keyboardDelegate}, state, tagsRef);
88
- let actionsId = useId();
89
- let actionsRef = useRef<HTMLDivElement>(null);
90
-
91
- let updateVisibleTagCount = useCallback(() => {
92
- if (maxRows && maxRows > 0) {
93
- let computeVisibleTagCount = () => {
94
- // Refs can be null at runtime.
95
- let currContainerRef: HTMLDivElement | null = containerRef.current;
96
- let currTagsRef: HTMLDivElement | null = tagsRef.current;
97
- let currActionsRef: HTMLDivElement | null = actionsRef.current;
98
- if (!currContainerRef || !currTagsRef || !currActionsRef || state.collection.size === 0) {
99
- return {
100
- visibleTagCount: 0,
101
- showCollapseButton: false
102
- };
103
- }
104
-
105
- // Count rows and show tags until we hit the maxRows.
106
- let tags = [...currTagsRef.children];
107
- let currY = -Infinity;
108
- let rowCount = 0;
109
- let index = 0;
110
- let tagWidths: number[] = [];
111
- for (let tag of tags) {
112
- let {width, y} = tag.getBoundingClientRect();
113
-
114
- if (y !== currY) {
115
- currY = y;
116
- rowCount++;
117
- }
118
-
119
- if (maxRows && rowCount > maxRows) {
120
- break;
121
- }
122
- tagWidths.push(width);
123
- index++;
124
- }
125
-
126
- // Remove tags until there is space for the collapse button and action button (if present) on the last row.
127
- let buttons = [...currActionsRef.children];
128
- if (maxRows && buttons.length > 0 && rowCount >= maxRows && currContainerRef.parentElement) {
129
- let buttonsWidth = buttons.reduce((acc, curr) => acc += curr.getBoundingClientRect().width, 0);
130
- buttonsWidth += TAG_STYLES[scale].margin * 2 * buttons.length;
131
- let end = direction === 'ltr' ? 'right' : 'left';
132
- let containerEnd = currContainerRef.parentElement.getBoundingClientRect()[end];
133
- let lastTagEnd = tags[index - 1]?.getBoundingClientRect()[end];
134
- lastTagEnd += TAG_STYLES[scale].margin;
135
- let availableWidth = containerEnd - lastTagEnd;
136
-
137
- while (availableWidth < buttonsWidth && index > 0) {
138
- availableWidth += tagWidths.pop()!;
139
- index--;
140
- }
141
- }
142
-
143
- return {
144
- visibleTagCount: Math.max(index, 1),
145
- showCollapseButton: index < state.collection.size
146
- };
147
- };
148
-
149
- setTagState(function *() {
150
- // Update to show all items.
151
- yield {visibleTagCount: state.collection.size, showCollapseButton: true};
152
-
153
- // Measure, and update to show the items until maxRows is reached.
154
- yield computeVisibleTagCount();
155
- });
156
- }
157
- }, [maxRows, setTagState, direction, scale, state.collection.size]);
158
-
159
- useResizeObserver({ref: containerRef, onResize: updateVisibleTagCount});
160
- // eslint-disable-next-line react-hooks/exhaustive-deps
161
- useLayoutEffect(updateVisibleTagCount, [children]);
162
-
163
- useEffect(() => {
164
- // Recalculate visible tags when fonts are loaded.
165
- document.fonts?.ready.then(() => updateVisibleTagCount());
166
- // eslint-disable-next-line react-hooks/exhaustive-deps
167
- }, []);
168
-
169
- let visibleTags = useMemo(() =>
170
- [...state.collection].slice(0, isCollapsed ? tagState.visibleTagCount : state.collection.size),
171
- [isCollapsed, state.collection, tagState.visibleTagCount]
172
- );
173
-
174
- let handlePressCollapse = () => {
175
- // Prevents button from losing focus if focusedKey got collapsed.
176
- state.selectionManager.setFocusedKey(null);
177
- setIsCollapsed(prevCollapsed => !prevCollapsed);
178
- };
179
-
180
- let showActions = tagState.showCollapseButton || (actionLabel && onAction);
181
- let isEmpty = state.collection.size === 0;
182
-
183
- let containerStyle = useMemo(() => {
184
- if (maxRows == null || !isCollapsed || isEmpty) {
185
- return undefined;
186
- }
187
- let maxHeight = (TAG_STYLES[scale].height + (TAG_STYLES[scale].margin * 2)) * maxRows;
188
- return {maxHeight, overflow: 'hidden'};
189
- }, [isCollapsed, maxRows, isEmpty, scale]);
190
-
191
- return (
192
- <FocusScope>
193
- <Field
194
- {...props}
195
- labelProps={labelProps}
196
- descriptionProps={descriptionProps}
197
- errorMessageProps={errorMessageProps}
198
- showErrorIcon
199
- ref={domRef}
200
- elementType="span"
201
- wrapperClassName={
202
- classNames(
203
- styles,
204
- 'spectrum-Tags-fieldWrapper',
205
- {
206
- 'spectrum-Tags-fieldWrapper--positionSide': labelPosition === 'side'
207
- }
208
- )
209
- }>
210
- <div
211
- ref={containerRef}
212
- style={containerStyle}
213
- className={
214
- classNames(
215
- styles,
216
- 'spectrum-Tags-container',
217
- {
218
- 'spectrum-Tags-container--empty': isEmpty
219
- }
220
- )
221
- }>
222
- <FocusRing focusRingClass={classNames(styles, 'focus-ring')}>
223
- <div
224
- ref={tagsRef}
225
- {...gridProps}
226
- className={classNames(styles, 'spectrum-Tags')}>
227
- {visibleTags.map(item => (
228
- <Tag
229
- {...item.props}
230
- key={item.key}
231
- item={item}
232
- state={state}>
233
- {item.rendered}
234
- </Tag>
235
- ))}
236
- {isEmpty && (
237
- <div className={classNames(styles, 'spectrum-Tags-empty-state')}>
238
- {renderEmptyState()}
239
- </div>
240
- )}
241
- </div>
242
- </FocusRing>
243
- {showActions && !isEmpty &&
244
- <Provider isDisabled={false}>
245
- <div
246
- role="group"
247
- ref={actionsRef}
248
- id={actionsId}
249
- aria-label={stringFormatter.format('actions')}
250
- aria-labelledby={`${gridProps.id} ${actionsId}`}
251
- className={classNames(styles, 'spectrum-Tags-actions')}>
252
- {tagState.showCollapseButton &&
253
- <ActionButton
254
- isQuiet
255
- onPress={handlePressCollapse}
256
- UNSAFE_className={classNames(styles, 'spectrum-Tags-actionButton')}>
257
- {isCollapsed ?
258
- stringFormatter.format('showAllButtonLabel', {tagCount: state.collection.size}) :
259
- stringFormatter.format('hideButtonLabel')
260
- }
261
- </ActionButton>
262
- }
263
- {actionLabel && onAction &&
264
- <ActionButton
265
- isQuiet
266
- onPress={() => onAction?.()}
267
- UNSAFE_className={classNames(styles, 'spectrum-Tags-actionButton')}>
268
- {actionLabel}
269
- </ActionButton>
270
- }
271
- </div>
272
- </Provider>
273
- }
274
- </div>
275
- </Field>
276
- </FocusScope>
277
- );
278
- }) as <T>(props: SpectrumTagGroupProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactNode;