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AAK,GAAG;OAC7D,YAAY,GAAG,CAAC,CAAA,qBACf,0DAAC,CAAA,GAAA,6BAAE;YAAG,GAAG,KAAK,KAAK;YAAE,KAAK,KAAK,GAAG;YAAE,MAAM;YAAM,OAAO;WACpD,KAAK,QAAQ,IAGjB,yBACC,0DAAC;QAAI,WAAW,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;OAChC,uBAKR,eAAe,CAAC,yBACf,0DAAC,CAAA,GAAA,kCAAO;QAAE,YAAY;qBACpB,0DAAC;QACC,MAAK;QACL,KAAK;QACL,IAAI;QACJ,cAAY,gBAAgB,MAAM,CAAC;QACnC,mBAAiB,GAAG,UAAU,EAAE,CAAC,CAAC,EAAE,WAAW;QAC/C,WAAW,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;OAC7B,SAAS,kBAAkB,kBAC1B,0DAAC,CAAA,GAAA,sCAAW;QACV,SAAA;QACA,SAAS;QACT,kBAAkB,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;OACpC,cACG,gBAAgB,MAAM,CAAC,sBAAsB;QAC3C,UAAU,MAAM,UAAU,CAAC,IAAI;IACjC,KACA,gBAAgB,MAAM,CAAC,qBAG9B,eAAe,0BACd,0DAAC,CAAA,GAAA,sCAAW;QACV,SAAA;QACA,SAAS,IAAM;QACf,kBAAkB,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;OACpC;AAUrB","sources":["packages/@adobe/react-spectrum/src/tag/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 '../button/ActionButton';\n\nimport {AriaTagGroupProps, useTagGroup} from 'react-aria/useTagGroup';\nimport {classNames} from '../utils/classNames';\nimport {\n  Collection,\n  DOMRef,\n  Node,\n  SpectrumLabelableProps,\n  StyleProps,\n  Validation\n} from '@react-types/shared';\nimport {Field} from '../label/Field';\nimport {FocusRing} from 'react-aria/FocusRing';\nimport {FocusScope} from 'react-aria/FocusScope';\nimport intlMessages from '../../intl/tag/*.json';\n// @ts-ignore\nimport {ListCollection} from 'react-stately/private/list/ListCollection';\nimport {ListKeyboardDelegate} from 'react-aria/ListKeyboardDelegate';\nimport {Provider, useProvider, useProviderProps} from '../provider/Provider';\nimport React, {JSX, ReactNode, useCallback, useEffect, useMemo, useRef, useState} from 'react';\nimport styles from '@adobe/spectrum-css-temp/components/tags/vars.css';\nimport {Tag} from './Tag';\nimport {useDOMRef} from '../utils/useDOMRef';\nimport {useFormProps} from '../form/Form';\nimport {useId} from 'react-aria/useId';\nimport {useLayoutEffect} from 'react-aria/private/utils/useLayoutEffect';\nimport {useListState} from 'react-stately/useListState';\nimport {useLocale} from 'react-aria/I18nProvider';\nimport {useLocalizedStringFormatter} from 'react-aria/useLocalizedStringFormatter';\nimport {useResizeObserver} from 'react-aria/private/utils/useResizeObserver';\nimport {useValueEffect} from 'react-aria/private/utils/useValueEffect';\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>\n  extends\n    Omit<\n      AriaTagGroupProps<T>,\n      | 'selectionMode'\n      | 'disallowEmptySelection'\n      | 'selectedKeys'\n      | 'defaultSelectedKeys'\n      | 'onSelectionChange'\n      | 'selectionBehavior'\n      | 'disabledKeys'\n    >,\n    StyleProps,\n    Omit<SpectrumLabelableProps, 'isRequired' | 'necessityIndicator'>,\n    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  /**\n   * Limit the number of rows initially shown. This will render a button that allows the user to\n   * expand to show all tags.\n   */\n  maxRows?: number;\n}\n\n/**\n * Tags allow users to categorize content. They can represent keywords or people, and are grouped to\n * describe an item or a search request.\n */\nexport const TagGroup = React.forwardRef(function TagGroup<T extends object>(\n  props: SpectrumTagGroupProps<T>,\n  ref: DOMRef<HTMLDivElement>\n) {\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<HTMLDivElement>(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({\n    visibleTagCount: state.collection.size,\n    showCollapseButton: false\n  });\n  let keyboardDelegate = useMemo(() => {\n    let collection = (\n      isCollapsed\n        ? new ListCollection([...state.collection].slice(0, tagState.visibleTagCount))\n        : new ListCollection([...state.collection])\n    ) as Collection<Node<T>>;\n    return new ListKeyboardDelegate({\n      collection,\n      ref: tagsRef,\n      direction,\n      orientation: 'horizontal'\n    });\n  }, [\n    direction,\n    isCollapsed,\n    state.collection,\n    tagState.visibleTagCount,\n    tagsRef\n  ]) 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(\n    {...props, keyboardDelegate},\n    state,\n    tagsRef\n  );\n  let actionsId = useId();\n  let actionsRef = useRef<HTMLDivElement>(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 (\n          maxRows &&\n          buttons.length > 0 &&\n          rowCount >= maxRows &&\n          currContainerRef.parentElement\n        ) {\n          let buttonsWidth = buttons.reduce(\n            (acc, curr) => (acc += curr.getBoundingClientRect().width),\n            0\n          );\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    () =>\n      [...state.collection].slice(\n        0,\n        isCollapsed ? tagState.visibleTagCount : state.collection.size\n      ),\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={classNames(styles, 'spectrum-Tags-fieldWrapper', {\n          'spectrum-Tags-fieldWrapper--positionSide': labelPosition === 'side'\n        })}>\n        <div\n          ref={containerRef}\n          style={containerStyle}\n          className={classNames(styles, 'spectrum-Tags-container', {\n            'spectrum-Tags-container--empty': isEmpty\n          })}>\n          <FocusRing focusRingClass={classNames(styles, 'focus-ring')}>\n            <div ref={tagsRef} {...gridProps} className={classNames(styles, 'spectrum-Tags')}>\n              {visibleTags.map(item => (\n                <Tag {...item.props} key={item.key} item={item} 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', {\n                          tagCount: state.collection.size\n                        })\n                      : stringFormatter.format('hideButtonLabel')}\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}) as <T>(props: SpectrumTagGroupProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactNode;\n"],"names":[],"version":3,"file":"TagGroup.cjs.map"}