@react-spectrum/tag 3.2.4 → 3.2.6

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.
@@ -0,0 +1,265 @@
1
+ import $jTkY3$intlStringsmodulejs from "./intlStrings.mjs";
2
+ import "./vars.0a7fe83c.css";
3
+ import $jTkY3$tags_vars_cssmodulejs from "./tags_vars_css.mjs";
4
+ import {Tag as $b5f5ee35d3b6b95c$export$3288d34c523a1192} from "./Tag.mjs";
5
+ import {ActionButton as $jTkY3$ActionButton} from "@react-spectrum/button";
6
+ import {useTagGroup as $jTkY3$useTagGroup} from "@react-aria/tag";
7
+ import {useDOMRef as $jTkY3$useDOMRef, classNames as $jTkY3$classNames} from "@react-spectrum/utils";
8
+ import {Field as $jTkY3$Field} from "@react-spectrum/label";
9
+ import {FocusScope as $jTkY3$FocusScope, FocusRing as $jTkY3$FocusRing} from "@react-aria/focus";
10
+ import {useListState as $jTkY3$useListState, ListCollection as $jTkY3$ListCollection} from "@react-stately/list";
11
+ import {ListKeyboardDelegate as $jTkY3$ListKeyboardDelegate} from "@react-aria/selection";
12
+ import {useProviderProps as $jTkY3$useProviderProps, useProvider as $jTkY3$useProvider, Provider as $jTkY3$Provider} from "@react-spectrum/provider";
13
+ import $jTkY3$react, {useRef as $jTkY3$useRef, useState as $jTkY3$useState, useMemo as $jTkY3$useMemo, useCallback as $jTkY3$useCallback, useEffect as $jTkY3$useEffect} from "react";
14
+ import {useFormProps as $jTkY3$useFormProps} from "@react-spectrum/form";
15
+ import {useValueEffect as $jTkY3$useValueEffect, useId as $jTkY3$useId, useResizeObserver as $jTkY3$useResizeObserver, useLayoutEffect as $jTkY3$useLayoutEffect} from "@react-aria/utils";
16
+ import {useLocale as $jTkY3$useLocale, useLocalizedStringFormatter as $jTkY3$useLocalizedStringFormatter} from "@react-aria/i18n";
17
+
18
+
19
+ function $parcel$interopDefault(a) {
20
+ return a && a.__esModule ? a.default : a;
21
+ }
22
+ /*
23
+ * Copyright 2020 Adobe. All rights reserved.
24
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
25
+ * you may not use this file except in compliance with the License. You may obtain a copy
26
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
27
+ *
28
+ * Unless required by applicable law or agreed to in writing, software distributed under
29
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
30
+ * OF ANY KIND, either express or implied. See the License for the specific language
31
+ * governing permissions and limitations under the License.
32
+ */
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+ const $880d112c7a588209$var$TAG_STYLES = {
48
+ medium: {
49
+ height: 24,
50
+ margin: 4
51
+ },
52
+ large: {
53
+ height: 30,
54
+ margin: 5
55
+ }
56
+ };
57
+ function $880d112c7a588209$var$TagGroup(props, ref) {
58
+ props = (0, $jTkY3$useProviderProps)(props);
59
+ props = (0, $jTkY3$useFormProps)(props);
60
+ let { maxRows: maxRows, children: children, actionLabel: actionLabel, onAction: onAction, labelPosition: labelPosition, renderEmptyState: renderEmptyState = ()=>stringFormatter.format('noTags') } = props;
61
+ let domRef = (0, $jTkY3$useDOMRef)(ref);
62
+ let containerRef = (0, $jTkY3$useRef)(null);
63
+ let tagsRef = (0, $jTkY3$useRef)(null);
64
+ let { direction: direction } = (0, $jTkY3$useLocale)();
65
+ let { scale: scale } = (0, $jTkY3$useProvider)();
66
+ let stringFormatter = (0, $jTkY3$useLocalizedStringFormatter)((0, ($parcel$interopDefault($jTkY3$intlStringsmodulejs))), '@react-spectrum/tag');
67
+ let [isCollapsed, setIsCollapsed] = (0, $jTkY3$useState)(maxRows != null);
68
+ let state = (0, $jTkY3$useListState)(props);
69
+ let [tagState, setTagState] = (0, $jTkY3$useValueEffect)({
70
+ visibleTagCount: state.collection.size,
71
+ showCollapseButton: false
72
+ });
73
+ let keyboardDelegate = (0, $jTkY3$useMemo)(()=>{
74
+ let collection = isCollapsed ? new (0, $jTkY3$ListCollection)([
75
+ ...state.collection
76
+ ].slice(0, tagState.visibleTagCount)) : new (0, $jTkY3$ListCollection)([
77
+ ...state.collection
78
+ ]);
79
+ return new (0, $jTkY3$ListKeyboardDelegate)({
80
+ collection: collection,
81
+ ref: domRef,
82
+ direction: direction,
83
+ orientation: 'horizontal'
84
+ });
85
+ }, [
86
+ direction,
87
+ isCollapsed,
88
+ state.collection,
89
+ tagState.visibleTagCount,
90
+ domRef
91
+ ]);
92
+ // Remove onAction from props so it doesn't make it into useGridList.
93
+ delete props.onAction;
94
+ let { gridProps: gridProps, labelProps: labelProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $jTkY3$useTagGroup)({
95
+ ...props,
96
+ keyboardDelegate: keyboardDelegate
97
+ }, state, tagsRef);
98
+ let actionsId = (0, $jTkY3$useId)();
99
+ let actionsRef = (0, $jTkY3$useRef)(null);
100
+ let updateVisibleTagCount = (0, $jTkY3$useCallback)(()=>{
101
+ if (maxRows && maxRows > 0) {
102
+ let computeVisibleTagCount = ()=>{
103
+ // Refs can be null at runtime.
104
+ let currContainerRef = containerRef.current;
105
+ let currTagsRef = tagsRef.current;
106
+ let currActionsRef = actionsRef.current;
107
+ if (!currContainerRef || !currTagsRef || !currActionsRef || state.collection.size === 0) return {
108
+ visibleTagCount: 0,
109
+ showCollapseButton: false
110
+ };
111
+ // Count rows and show tags until we hit the maxRows.
112
+ let tags = [
113
+ ...currTagsRef.children
114
+ ];
115
+ let currY = -Infinity;
116
+ let rowCount = 0;
117
+ let index = 0;
118
+ let tagWidths = [];
119
+ for (let tag of tags){
120
+ let { width: width, y: y } = tag.getBoundingClientRect();
121
+ if (y !== currY) {
122
+ currY = y;
123
+ rowCount++;
124
+ }
125
+ if (maxRows && rowCount > maxRows) break;
126
+ tagWidths.push(width);
127
+ index++;
128
+ }
129
+ // Remove tags until there is space for the collapse button and action button (if present) on the last row.
130
+ let buttons = [
131
+ ...currActionsRef.children
132
+ ];
133
+ if (maxRows && buttons.length > 0 && rowCount >= maxRows) {
134
+ var _tags_;
135
+ let buttonsWidth = buttons.reduce((acc, curr)=>acc += curr.getBoundingClientRect().width, 0);
136
+ buttonsWidth += $880d112c7a588209$var$TAG_STYLES[scale].margin * 2 * buttons.length;
137
+ let end = direction === 'ltr' ? 'right' : 'left';
138
+ let containerEnd = currContainerRef.parentElement.getBoundingClientRect()[end];
139
+ let lastTagEnd = (_tags_ = tags[index - 1]) === null || _tags_ === void 0 ? void 0 : _tags_.getBoundingClientRect()[end];
140
+ lastTagEnd += $880d112c7a588209$var$TAG_STYLES[scale].margin;
141
+ let availableWidth = containerEnd - lastTagEnd;
142
+ while(availableWidth < buttonsWidth && index > 0){
143
+ availableWidth += tagWidths.pop();
144
+ index--;
145
+ }
146
+ }
147
+ return {
148
+ visibleTagCount: Math.max(index, 1),
149
+ showCollapseButton: index < state.collection.size
150
+ };
151
+ };
152
+ setTagState(function*() {
153
+ // Update to show all items.
154
+ yield {
155
+ visibleTagCount: state.collection.size,
156
+ showCollapseButton: true
157
+ };
158
+ // Measure, and update to show the items until maxRows is reached.
159
+ yield computeVisibleTagCount();
160
+ });
161
+ }
162
+ }, [
163
+ maxRows,
164
+ setTagState,
165
+ direction,
166
+ scale,
167
+ state.collection.size
168
+ ]);
169
+ (0, $jTkY3$useResizeObserver)({
170
+ ref: containerRef,
171
+ onResize: updateVisibleTagCount
172
+ });
173
+ // eslint-disable-next-line react-hooks/exhaustive-deps
174
+ (0, $jTkY3$useLayoutEffect)(updateVisibleTagCount, [
175
+ children
176
+ ]);
177
+ (0, $jTkY3$useEffect)(()=>{
178
+ var // Recalculate visible tags when fonts are loaded.
179
+ _document_fonts;
180
+ (_document_fonts = document.fonts) === null || _document_fonts === void 0 ? void 0 : _document_fonts.ready.then(()=>updateVisibleTagCount());
181
+ // eslint-disable-next-line react-hooks/exhaustive-deps
182
+ }, []);
183
+ let visibleTags = (0, $jTkY3$useMemo)(()=>[
184
+ ...state.collection
185
+ ].slice(0, isCollapsed ? tagState.visibleTagCount : state.collection.size), [
186
+ isCollapsed,
187
+ state.collection,
188
+ tagState.visibleTagCount
189
+ ]);
190
+ let handlePressCollapse = ()=>{
191
+ // Prevents button from losing focus if focusedKey got collapsed.
192
+ state.selectionManager.setFocusedKey(null);
193
+ setIsCollapsed((prevCollapsed)=>!prevCollapsed);
194
+ };
195
+ let showActions = tagState.showCollapseButton || actionLabel && onAction;
196
+ let isEmpty = state.collection.size === 0;
197
+ let containerStyle = (0, $jTkY3$useMemo)(()=>{
198
+ if (maxRows == null || !isCollapsed || isEmpty) return undefined;
199
+ let maxHeight = ($880d112c7a588209$var$TAG_STYLES[scale].height + $880d112c7a588209$var$TAG_STYLES[scale].margin * 2) * maxRows;
200
+ return {
201
+ maxHeight: maxHeight,
202
+ overflow: 'hidden'
203
+ };
204
+ }, [
205
+ isCollapsed,
206
+ maxRows,
207
+ isEmpty,
208
+ scale
209
+ ]);
210
+ return /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$FocusScope), null, /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$Field), {
211
+ ...props,
212
+ labelProps: labelProps,
213
+ descriptionProps: descriptionProps,
214
+ errorMessageProps: errorMessageProps,
215
+ showErrorIcon: true,
216
+ ref: domRef,
217
+ elementType: "span",
218
+ wrapperClassName: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-fieldWrapper', {
219
+ 'spectrum-Tags-fieldWrapper--positionSide': labelPosition === 'side'
220
+ })
221
+ }, /*#__PURE__*/ (0, $jTkY3$react).createElement("div", {
222
+ ref: containerRef,
223
+ style: containerStyle,
224
+ className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-container', {
225
+ 'spectrum-Tags-container--empty': isEmpty
226
+ })
227
+ }, /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$FocusRing), {
228
+ focusRingClass: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'focus-ring')
229
+ }, /*#__PURE__*/ (0, $jTkY3$react).createElement("div", {
230
+ ref: tagsRef,
231
+ ...gridProps,
232
+ className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags')
233
+ }, visibleTags.map((item)=>/*#__PURE__*/ (0, $jTkY3$react).createElement((0, $b5f5ee35d3b6b95c$export$3288d34c523a1192), {
234
+ ...item.props,
235
+ key: item.key,
236
+ item: item,
237
+ state: state
238
+ }, item.rendered)), isEmpty && /*#__PURE__*/ (0, $jTkY3$react).createElement("div", {
239
+ className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-empty-state')
240
+ }, renderEmptyState()))), showActions && !isEmpty && /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$Provider), {
241
+ isDisabled: false
242
+ }, /*#__PURE__*/ (0, $jTkY3$react).createElement("div", {
243
+ role: "group",
244
+ ref: actionsRef,
245
+ id: actionsId,
246
+ "aria-label": stringFormatter.format('actions'),
247
+ "aria-labelledby": `${gridProps.id} ${actionsId}`,
248
+ className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-actions')
249
+ }, tagState.showCollapseButton && /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$ActionButton), {
250
+ isQuiet: true,
251
+ onPress: handlePressCollapse,
252
+ UNSAFE_className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-actionButton')
253
+ }, isCollapsed ? stringFormatter.format('showAllButtonLabel', {
254
+ tagCount: state.collection.size
255
+ }) : stringFormatter.format('hideButtonLabel')), actionLabel && onAction && /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$ActionButton), {
256
+ isQuiet: true,
257
+ onPress: ()=>onAction === null || onAction === void 0 ? void 0 : onAction(),
258
+ UNSAFE_className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-actionButton')
259
+ }, actionLabel))))));
260
+ }
261
+ /** Tags allow users to categorize content. They can represent keywords or people, and are grouped to describe an item or a search request. */ const $880d112c7a588209$export$67ea30858aaf75e3 = /*#__PURE__*/ (0, $jTkY3$react).forwardRef($880d112c7a588209$var$TagGroup);
262
+
263
+
264
+ export {$880d112c7a588209$export$67ea30858aaf75e3 as TagGroup};
265
+ //# sourceMappingURL=TagGroup.module.js.map
@@ -0,0 +1,265 @@
1
+ import $jTkY3$intlStringsmodulejs from "./intlStrings.module.js";
2
+ import "./vars.0a7fe83c.css";
3
+ import $jTkY3$tags_vars_cssmodulejs from "./tags_vars_css.module.js";
4
+ import {Tag as $b5f5ee35d3b6b95c$export$3288d34c523a1192} from "./Tag.module.js";
5
+ import {ActionButton as $jTkY3$ActionButton} from "@react-spectrum/button";
6
+ import {useTagGroup as $jTkY3$useTagGroup} from "@react-aria/tag";
7
+ import {useDOMRef as $jTkY3$useDOMRef, classNames as $jTkY3$classNames} from "@react-spectrum/utils";
8
+ import {Field as $jTkY3$Field} from "@react-spectrum/label";
9
+ import {FocusScope as $jTkY3$FocusScope, FocusRing as $jTkY3$FocusRing} from "@react-aria/focus";
10
+ import {useListState as $jTkY3$useListState, ListCollection as $jTkY3$ListCollection} from "@react-stately/list";
11
+ import {ListKeyboardDelegate as $jTkY3$ListKeyboardDelegate} from "@react-aria/selection";
12
+ import {useProviderProps as $jTkY3$useProviderProps, useProvider as $jTkY3$useProvider, Provider as $jTkY3$Provider} from "@react-spectrum/provider";
13
+ import $jTkY3$react, {useRef as $jTkY3$useRef, useState as $jTkY3$useState, useMemo as $jTkY3$useMemo, useCallback as $jTkY3$useCallback, useEffect as $jTkY3$useEffect} from "react";
14
+ import {useFormProps as $jTkY3$useFormProps} from "@react-spectrum/form";
15
+ import {useValueEffect as $jTkY3$useValueEffect, useId as $jTkY3$useId, useResizeObserver as $jTkY3$useResizeObserver, useLayoutEffect as $jTkY3$useLayoutEffect} from "@react-aria/utils";
16
+ import {useLocale as $jTkY3$useLocale, useLocalizedStringFormatter as $jTkY3$useLocalizedStringFormatter} from "@react-aria/i18n";
17
+
18
+
19
+ function $parcel$interopDefault(a) {
20
+ return a && a.__esModule ? a.default : a;
21
+ }
22
+ /*
23
+ * Copyright 2020 Adobe. All rights reserved.
24
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
25
+ * you may not use this file except in compliance with the License. You may obtain a copy
26
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
27
+ *
28
+ * Unless required by applicable law or agreed to in writing, software distributed under
29
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
30
+ * OF ANY KIND, either express or implied. See the License for the specific language
31
+ * governing permissions and limitations under the License.
32
+ */
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+ const $880d112c7a588209$var$TAG_STYLES = {
48
+ medium: {
49
+ height: 24,
50
+ margin: 4
51
+ },
52
+ large: {
53
+ height: 30,
54
+ margin: 5
55
+ }
56
+ };
57
+ function $880d112c7a588209$var$TagGroup(props, ref) {
58
+ props = (0, $jTkY3$useProviderProps)(props);
59
+ props = (0, $jTkY3$useFormProps)(props);
60
+ let { maxRows: maxRows, children: children, actionLabel: actionLabel, onAction: onAction, labelPosition: labelPosition, renderEmptyState: renderEmptyState = ()=>stringFormatter.format('noTags') } = props;
61
+ let domRef = (0, $jTkY3$useDOMRef)(ref);
62
+ let containerRef = (0, $jTkY3$useRef)(null);
63
+ let tagsRef = (0, $jTkY3$useRef)(null);
64
+ let { direction: direction } = (0, $jTkY3$useLocale)();
65
+ let { scale: scale } = (0, $jTkY3$useProvider)();
66
+ let stringFormatter = (0, $jTkY3$useLocalizedStringFormatter)((0, ($parcel$interopDefault($jTkY3$intlStringsmodulejs))), '@react-spectrum/tag');
67
+ let [isCollapsed, setIsCollapsed] = (0, $jTkY3$useState)(maxRows != null);
68
+ let state = (0, $jTkY3$useListState)(props);
69
+ let [tagState, setTagState] = (0, $jTkY3$useValueEffect)({
70
+ visibleTagCount: state.collection.size,
71
+ showCollapseButton: false
72
+ });
73
+ let keyboardDelegate = (0, $jTkY3$useMemo)(()=>{
74
+ let collection = isCollapsed ? new (0, $jTkY3$ListCollection)([
75
+ ...state.collection
76
+ ].slice(0, tagState.visibleTagCount)) : new (0, $jTkY3$ListCollection)([
77
+ ...state.collection
78
+ ]);
79
+ return new (0, $jTkY3$ListKeyboardDelegate)({
80
+ collection: collection,
81
+ ref: domRef,
82
+ direction: direction,
83
+ orientation: 'horizontal'
84
+ });
85
+ }, [
86
+ direction,
87
+ isCollapsed,
88
+ state.collection,
89
+ tagState.visibleTagCount,
90
+ domRef
91
+ ]);
92
+ // Remove onAction from props so it doesn't make it into useGridList.
93
+ delete props.onAction;
94
+ let { gridProps: gridProps, labelProps: labelProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $jTkY3$useTagGroup)({
95
+ ...props,
96
+ keyboardDelegate: keyboardDelegate
97
+ }, state, tagsRef);
98
+ let actionsId = (0, $jTkY3$useId)();
99
+ let actionsRef = (0, $jTkY3$useRef)(null);
100
+ let updateVisibleTagCount = (0, $jTkY3$useCallback)(()=>{
101
+ if (maxRows && maxRows > 0) {
102
+ let computeVisibleTagCount = ()=>{
103
+ // Refs can be null at runtime.
104
+ let currContainerRef = containerRef.current;
105
+ let currTagsRef = tagsRef.current;
106
+ let currActionsRef = actionsRef.current;
107
+ if (!currContainerRef || !currTagsRef || !currActionsRef || state.collection.size === 0) return {
108
+ visibleTagCount: 0,
109
+ showCollapseButton: false
110
+ };
111
+ // Count rows and show tags until we hit the maxRows.
112
+ let tags = [
113
+ ...currTagsRef.children
114
+ ];
115
+ let currY = -Infinity;
116
+ let rowCount = 0;
117
+ let index = 0;
118
+ let tagWidths = [];
119
+ for (let tag of tags){
120
+ let { width: width, y: y } = tag.getBoundingClientRect();
121
+ if (y !== currY) {
122
+ currY = y;
123
+ rowCount++;
124
+ }
125
+ if (maxRows && rowCount > maxRows) break;
126
+ tagWidths.push(width);
127
+ index++;
128
+ }
129
+ // Remove tags until there is space for the collapse button and action button (if present) on the last row.
130
+ let buttons = [
131
+ ...currActionsRef.children
132
+ ];
133
+ if (maxRows && buttons.length > 0 && rowCount >= maxRows) {
134
+ var _tags_;
135
+ let buttonsWidth = buttons.reduce((acc, curr)=>acc += curr.getBoundingClientRect().width, 0);
136
+ buttonsWidth += $880d112c7a588209$var$TAG_STYLES[scale].margin * 2 * buttons.length;
137
+ let end = direction === 'ltr' ? 'right' : 'left';
138
+ let containerEnd = currContainerRef.parentElement.getBoundingClientRect()[end];
139
+ let lastTagEnd = (_tags_ = tags[index - 1]) === null || _tags_ === void 0 ? void 0 : _tags_.getBoundingClientRect()[end];
140
+ lastTagEnd += $880d112c7a588209$var$TAG_STYLES[scale].margin;
141
+ let availableWidth = containerEnd - lastTagEnd;
142
+ while(availableWidth < buttonsWidth && index > 0){
143
+ availableWidth += tagWidths.pop();
144
+ index--;
145
+ }
146
+ }
147
+ return {
148
+ visibleTagCount: Math.max(index, 1),
149
+ showCollapseButton: index < state.collection.size
150
+ };
151
+ };
152
+ setTagState(function*() {
153
+ // Update to show all items.
154
+ yield {
155
+ visibleTagCount: state.collection.size,
156
+ showCollapseButton: true
157
+ };
158
+ // Measure, and update to show the items until maxRows is reached.
159
+ yield computeVisibleTagCount();
160
+ });
161
+ }
162
+ }, [
163
+ maxRows,
164
+ setTagState,
165
+ direction,
166
+ scale,
167
+ state.collection.size
168
+ ]);
169
+ (0, $jTkY3$useResizeObserver)({
170
+ ref: containerRef,
171
+ onResize: updateVisibleTagCount
172
+ });
173
+ // eslint-disable-next-line react-hooks/exhaustive-deps
174
+ (0, $jTkY3$useLayoutEffect)(updateVisibleTagCount, [
175
+ children
176
+ ]);
177
+ (0, $jTkY3$useEffect)(()=>{
178
+ var // Recalculate visible tags when fonts are loaded.
179
+ _document_fonts;
180
+ (_document_fonts = document.fonts) === null || _document_fonts === void 0 ? void 0 : _document_fonts.ready.then(()=>updateVisibleTagCount());
181
+ // eslint-disable-next-line react-hooks/exhaustive-deps
182
+ }, []);
183
+ let visibleTags = (0, $jTkY3$useMemo)(()=>[
184
+ ...state.collection
185
+ ].slice(0, isCollapsed ? tagState.visibleTagCount : state.collection.size), [
186
+ isCollapsed,
187
+ state.collection,
188
+ tagState.visibleTagCount
189
+ ]);
190
+ let handlePressCollapse = ()=>{
191
+ // Prevents button from losing focus if focusedKey got collapsed.
192
+ state.selectionManager.setFocusedKey(null);
193
+ setIsCollapsed((prevCollapsed)=>!prevCollapsed);
194
+ };
195
+ let showActions = tagState.showCollapseButton || actionLabel && onAction;
196
+ let isEmpty = state.collection.size === 0;
197
+ let containerStyle = (0, $jTkY3$useMemo)(()=>{
198
+ if (maxRows == null || !isCollapsed || isEmpty) return undefined;
199
+ let maxHeight = ($880d112c7a588209$var$TAG_STYLES[scale].height + $880d112c7a588209$var$TAG_STYLES[scale].margin * 2) * maxRows;
200
+ return {
201
+ maxHeight: maxHeight,
202
+ overflow: 'hidden'
203
+ };
204
+ }, [
205
+ isCollapsed,
206
+ maxRows,
207
+ isEmpty,
208
+ scale
209
+ ]);
210
+ return /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$FocusScope), null, /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$Field), {
211
+ ...props,
212
+ labelProps: labelProps,
213
+ descriptionProps: descriptionProps,
214
+ errorMessageProps: errorMessageProps,
215
+ showErrorIcon: true,
216
+ ref: domRef,
217
+ elementType: "span",
218
+ wrapperClassName: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-fieldWrapper', {
219
+ 'spectrum-Tags-fieldWrapper--positionSide': labelPosition === 'side'
220
+ })
221
+ }, /*#__PURE__*/ (0, $jTkY3$react).createElement("div", {
222
+ ref: containerRef,
223
+ style: containerStyle,
224
+ className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-container', {
225
+ 'spectrum-Tags-container--empty': isEmpty
226
+ })
227
+ }, /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$FocusRing), {
228
+ focusRingClass: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'focus-ring')
229
+ }, /*#__PURE__*/ (0, $jTkY3$react).createElement("div", {
230
+ ref: tagsRef,
231
+ ...gridProps,
232
+ className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags')
233
+ }, visibleTags.map((item)=>/*#__PURE__*/ (0, $jTkY3$react).createElement((0, $b5f5ee35d3b6b95c$export$3288d34c523a1192), {
234
+ ...item.props,
235
+ key: item.key,
236
+ item: item,
237
+ state: state
238
+ }, item.rendered)), isEmpty && /*#__PURE__*/ (0, $jTkY3$react).createElement("div", {
239
+ className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-empty-state')
240
+ }, renderEmptyState()))), showActions && !isEmpty && /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$Provider), {
241
+ isDisabled: false
242
+ }, /*#__PURE__*/ (0, $jTkY3$react).createElement("div", {
243
+ role: "group",
244
+ ref: actionsRef,
245
+ id: actionsId,
246
+ "aria-label": stringFormatter.format('actions'),
247
+ "aria-labelledby": `${gridProps.id} ${actionsId}`,
248
+ className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-actions')
249
+ }, tagState.showCollapseButton && /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$ActionButton), {
250
+ isQuiet: true,
251
+ onPress: handlePressCollapse,
252
+ UNSAFE_className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-actionButton')
253
+ }, isCollapsed ? stringFormatter.format('showAllButtonLabel', {
254
+ tagCount: state.collection.size
255
+ }) : stringFormatter.format('hideButtonLabel')), actionLabel && onAction && /*#__PURE__*/ (0, $jTkY3$react).createElement((0, $jTkY3$ActionButton), {
256
+ isQuiet: true,
257
+ onPress: ()=>onAction === null || onAction === void 0 ? void 0 : onAction(),
258
+ UNSAFE_className: (0, $jTkY3$classNames)((0, ($parcel$interopDefault($jTkY3$tags_vars_cssmodulejs))), 'spectrum-Tags-actionButton')
259
+ }, actionLabel))))));
260
+ }
261
+ /** Tags allow users to categorize content. They can represent keywords or people, and are grouped to describe an item or a search request. */ const $880d112c7a588209$export$67ea30858aaf75e3 = /*#__PURE__*/ (0, $jTkY3$react).forwardRef($880d112c7a588209$var$TagGroup);
262
+
263
+
264
+ export {$880d112c7a588209$export$67ea30858aaf75e3 as TagGroup};
265
+ //# sourceMappingURL=TagGroup.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;;AAoBD,MAAM,mCAAa;IACjB,QAAQ;QACN,QAAQ;QACR,QAAQ;IACV;IACA,OAAO;QACL,QAAQ;QACR,QAAQ;IACV;AACF;AAaA,SAAS,+BAA2B,KAA+B,EAAE,GAA2B;IAC9F,QAAQ,CAAA,GAAA,uBAAe,EAAE;IACzB,QAAQ,CAAA,GAAA,mBAAW,EAAE;IACrB,IAAI,WACF,OAAO,YACP,QAAQ,eACR,WAAW,YACX,QAAQ,iBACR,aAAa,oBACb,mBAAmB,IAAM,gBAAgB,MAAM,CAAC,WACjD,GAAG;IACJ,IAAI,SAAS,CAAA,GAAA,gBAAQ,EAAE;IACvB,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE;IAC1B,IAAI,UAAU,CAAA,G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A,GAAA,mBAAW;QACV,SAAA;QACA,SAAS;QACT,kBAAkB,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,sDAAK,GAAG;OACpC,cACC,gBAAgB,MAAM,CAAC,sBAAsB;QAAC,UAAU,MAAM,UAAU,CAAC,IAAI;IAAA,KAC7E,gBAAgB,MAAM,CAAC,qBAI5B,eAAe,0BACd,gCAAC,CAAA,GAAA,mBAAW;QACV,SAAA;QACA,SAAS,IAAM,qBAAA,+BAAA;QACf,kBAAkB,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,sDAAK,GAAG;OACpC;AAUrB;AAEA,4IAA4I,GAC5I,MAAM,0DAAY,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC","sources":["packages/@react-spectrum/tag/src/TagGroup.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ActionButton} from '@react-spectrum/button';\nimport {AriaTagGroupProps, useTagGroup} from '@react-aria/tag';\nimport {classNames, useDOMRef} from '@react-spectrum/utils';\nimport {Collection, DOMRef, Node, SpectrumLabelableProps, StyleProps, Validation} from '@react-types/shared';\nimport {Field} from '@react-spectrum/label';\nimport {FocusRing, FocusScope} from '@react-aria/focus';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {ListCollection, useListState} from '@react-stately/list';\nimport {ListKeyboardDelegate} from '@react-aria/selection';\nimport {Provider, useProvider, useProviderProps} from '@react-spectrum/provider';\nimport React, {JSX, ReactElement, useCallback, useEffect, useMemo, useRef, useState} from 'react';\nimport styles from '@adobe/spectrum-css-temp/components/tags/vars.css';\nimport {Tag} from './Tag';\nimport {useFormProps} from '@react-spectrum/form';\nimport {useId, useLayoutEffect, useResizeObserver, useValueEffect} from '@react-aria/utils';\nimport {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\n\nconst TAG_STYLES = {\n medium: {\n height: 24,\n margin: 4\n },\n large: {\n height: 30,\n margin: 5\n }\n};\n\nexport interface SpectrumTagGroupProps<T> extends Omit<AriaTagGroupProps<T>, 'selectionMode' | 'disallowEmptySelection' | 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange' | 'selectionBehavior' | 'disabledKeys'>, StyleProps, Omit<SpectrumLabelableProps, 'isRequired' | 'necessityIndicator'>, Pick<Validation<any>, 'isInvalid' | 'validationState'> {\n /** The label to display on the action button. */\n actionLabel?: string,\n /** Handler that is called when the action button is pressed. */\n onAction?: () => void,\n /** Sets what the TagGroup should render when there are no tags to display. */\n renderEmptyState?: () => JSX.Element,\n /** Limit the number of rows initially shown. This will render a button that allows the user to expand to show all tags. */\n maxRows?: number\n}\n\nfunction TagGroup<T extends object>(props: SpectrumTagGroupProps<T>, ref: DOMRef<HTMLDivElement>) {\n props = useProviderProps(props);\n props = useFormProps(props);\n let {\n maxRows,\n children,\n actionLabel,\n onAction,\n labelPosition,\n renderEmptyState = () => stringFormatter.format('noTags')\n } = props;\n let domRef = useDOMRef(ref);\n let containerRef = useRef(null);\n let tagsRef = useRef<HTMLDivElement | null>(null);\n let {direction} = useLocale();\n let {scale} = useProvider();\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/tag');\n let [isCollapsed, setIsCollapsed] = useState(maxRows != null);\n let state = useListState(props);\n let [tagState, setTagState] = useValueEffect({visibleTagCount: state.collection.size, showCollapseButton: false});\n let keyboardDelegate = useMemo(() => {\n let collection = (isCollapsed\n ? new ListCollection([...state.collection].slice(0, tagState.visibleTagCount))\n : new ListCollection([...state.collection])) as Collection<Node<T>>;\n return new ListKeyboardDelegate({\n collection,\n ref: domRef,\n direction,\n orientation: 'horizontal'\n });\n }, [direction, isCollapsed, state.collection, tagState.visibleTagCount, domRef]) as ListKeyboardDelegate<T>;\n // Remove onAction from props so it doesn't make it into useGridList.\n delete props.onAction;\n let {gridProps, labelProps, descriptionProps, errorMessageProps} = useTagGroup({...props, keyboardDelegate}, state, tagsRef);\n let actionsId = useId();\n let actionsRef = useRef(null);\n\n let updateVisibleTagCount = useCallback(() => {\n if (maxRows && maxRows > 0) {\n let computeVisibleTagCount = () => {\n // Refs can be null at runtime.\n let currContainerRef: HTMLDivElement | null = containerRef.current;\n let currTagsRef: HTMLDivElement | null = tagsRef.current;\n let currActionsRef: HTMLDivElement | null = actionsRef.current;\n if (!currContainerRef || !currTagsRef || !currActionsRef || state.collection.size === 0) {\n return {\n visibleTagCount: 0,\n showCollapseButton: false\n };\n }\n\n // Count rows and show tags until we hit the maxRows.\n let tags = [...currTagsRef.children];\n let currY = -Infinity;\n let rowCount = 0;\n let index = 0;\n let tagWidths: number[] = [];\n for (let tag of tags) {\n let {width, y} = tag.getBoundingClientRect();\n\n if (y !== currY) {\n currY = y;\n rowCount++;\n }\n\n if (maxRows && rowCount > maxRows) {\n break;\n }\n tagWidths.push(width);\n index++;\n }\n\n // Remove tags until there is space for the collapse button and action button (if present) on the last row.\n let buttons = [...currActionsRef.children];\n if (maxRows && buttons.length > 0 && rowCount >= maxRows) {\n let buttonsWidth = buttons.reduce((acc, curr) => acc += curr.getBoundingClientRect().width, 0);\n buttonsWidth += TAG_STYLES[scale].margin * 2 * buttons.length;\n let end = direction === 'ltr' ? 'right' : 'left';\n let containerEnd = currContainerRef.parentElement.getBoundingClientRect()[end];\n let lastTagEnd = tags[index - 1]?.getBoundingClientRect()[end];\n lastTagEnd += TAG_STYLES[scale].margin;\n let availableWidth = containerEnd - lastTagEnd;\n\n while (availableWidth < buttonsWidth && index > 0) {\n availableWidth += tagWidths.pop();\n index--;\n }\n }\n\n return {\n visibleTagCount: Math.max(index, 1),\n showCollapseButton: index < state.collection.size\n };\n };\n\n setTagState(function *() {\n // Update to show all items.\n yield {visibleTagCount: state.collection.size, showCollapseButton: true};\n\n // Measure, and update to show the items until maxRows is reached.\n yield computeVisibleTagCount();\n });\n }\n }, [maxRows, setTagState, direction, scale, state.collection.size]);\n\n useResizeObserver({ref: containerRef, onResize: updateVisibleTagCount});\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(updateVisibleTagCount, [children]);\n\n useEffect(() => {\n // Recalculate visible tags when fonts are loaded.\n document.fonts?.ready.then(() => updateVisibleTagCount());\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let visibleTags = useMemo(() =>\n [...state.collection].slice(0, isCollapsed ? tagState.visibleTagCount : state.collection.size),\n [isCollapsed, state.collection, tagState.visibleTagCount]\n );\n\n let handlePressCollapse = () => {\n // Prevents button from losing focus if focusedKey got collapsed.\n state.selectionManager.setFocusedKey(null);\n setIsCollapsed(prevCollapsed => !prevCollapsed);\n };\n\n let showActions = tagState.showCollapseButton || (actionLabel && onAction);\n let isEmpty = state.collection.size === 0;\n\n let containerStyle = useMemo(() => {\n if (maxRows == null || !isCollapsed || isEmpty) {\n return undefined;\n }\n let maxHeight = (TAG_STYLES[scale].height + (TAG_STYLES[scale].margin * 2)) * maxRows;\n return {maxHeight, overflow: 'hidden'};\n }, [isCollapsed, maxRows, isEmpty, scale]);\n\n return (\n <FocusScope>\n <Field\n {...props}\n labelProps={labelProps}\n descriptionProps={descriptionProps}\n errorMessageProps={errorMessageProps}\n showErrorIcon\n ref={domRef}\n elementType=\"span\"\n wrapperClassName={\n classNames(\n styles,\n 'spectrum-Tags-fieldWrapper',\n {\n 'spectrum-Tags-fieldWrapper--positionSide': labelPosition === 'side'\n }\n )\n }>\n <div\n ref={containerRef}\n style={containerStyle}\n className={\n classNames(\n styles,\n 'spectrum-Tags-container',\n {\n 'spectrum-Tags-container--empty': isEmpty\n }\n )\n }>\n <FocusRing focusRingClass={classNames(styles, 'focus-ring')}>\n <div\n ref={tagsRef}\n {...gridProps}\n className={classNames(styles, 'spectrum-Tags')}>\n {visibleTags.map(item => (\n <Tag\n {...item.props}\n key={item.key}\n item={item}\n state={state}>\n {item.rendered}\n </Tag>\n ))}\n {isEmpty && (\n <div className={classNames(styles, 'spectrum-Tags-empty-state')}>\n {renderEmptyState()}\n </div>\n )}\n </div>\n </FocusRing>\n {showActions && !isEmpty &&\n <Provider isDisabled={false}>\n <div\n role=\"group\"\n ref={actionsRef}\n id={actionsId}\n aria-label={stringFormatter.format('actions')}\n aria-labelledby={`${gridProps.id} ${actionsId}`}\n className={classNames(styles, 'spectrum-Tags-actions')}>\n {tagState.showCollapseButton &&\n <ActionButton\n isQuiet\n onPress={handlePressCollapse}\n UNSAFE_className={classNames(styles, 'spectrum-Tags-actionButton')}>\n {isCollapsed ?\n stringFormatter.format('showAllButtonLabel', {tagCount: state.collection.size}) :\n stringFormatter.format('hideButtonLabel')\n }\n </ActionButton>\n }\n {actionLabel && onAction &&\n <ActionButton\n isQuiet\n onPress={() => onAction?.()}\n UNSAFE_className={classNames(styles, 'spectrum-Tags-actionButton')}>\n {actionLabel}\n </ActionButton>\n }\n </div>\n </Provider>\n }\n </div>\n </Field>\n </FocusScope>\n );\n}\n\n/** Tags allow users to categorize content. They can represent keywords or people, and are grouped to describe an item or a search request. */\nconst _TagGroup = React.forwardRef(TagGroup) as <T>(props: SpectrumTagGroupProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;\nexport {_TagGroup as TagGroup};\n"],"names":[],"version":3,"file":"TagGroup.module.js.map"}