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CAAC,CAAC;QACP,CAAC;QACD,GAAG,EAAE,kBAAM,CAAC,KAAK,CAAC;QAClB,WAAW,EAAE,qBAAqB;KACnC,CAAC,cApB0C,CAoBzC;IAEH,OAAO,CACL,8CAAK,GAAG,EAAE,GAAG,IAAM,QAAQ;QACzB,oBAAC,qBAAS,qBACR,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAC,SAAS,IACV,SAAS,IACb,SAAS,EAAE,8BAAkB,CAAC,UAAU,IACpC,cAAc,IAClB,SAAS,EAAE,eAAG,CAAC,UAAU,CAAC,IAAI,EAAE,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,SAAS,CAAC;YAEzD,KAAK;YACL,gBAAgB,KAAK,MAAM,IAAI,CAC9B,oBAAC,sBAAa,IACZ,SAAS,EAAE,eAAG,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,kBAAkB,CAAC,EAC9D,UAAU,EAAE,qBAAqB,EACjC,YAAY,EAAE,8BAA8B,EAC5C,SAAS,EAAE,iBAAiB,EAC5B,aAAa,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAChE,SAAS,EAAE,iBAAiB,GAC5B,CACH,CACS;QACX,mBAAmB;YAClB,cAAc,CAAC,KAAK,CAAC,GAAG,CACtB,UAAA,IAAI;gBACF,OAAA,CAAC,IAAI,CAAC,YAAY,KAAK,IAAI,IAAI,mBAAmB,KAAK,IAAI,CAAC,OAAO,CAAC;oBACpE,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC,OAAO,CAAC;YADnE,CACmE,CACtE,CACC,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AACF,iBAAS,CAAC,WAAW,GAAG,cAAc,CAAC","sourcesContent":["import * as React from 'react';\nimport { useControllableValue, useId } from '@fluentui/react-hooks';\nimport { classNamesFunction, css, divProperties, getNativeProps, getRTL, KeyCodes, warn } from '@fluentui/utilities';\nimport { CommandButton } from '../../Button';\nimport { useOverflow } from '../../utilities/useOverflow';\nimport { FocusZone, FocusZoneDirection } from '../../FocusZone';\nimport { DirectionalHint } from '../ContextualMenu/ContextualMenu.types';\nimport { Icon } from '../Icon/Icon';\nimport { PivotItem } from './PivotItem';\nimport type { IButton } from '../../Button';\nimport type { IFocusZone } from '../../FocusZone';\nimport type { IContextualMenuProps } from '../ContextualMenu/ContextualMenu.types';\nimport type { IPivot, IPivotProps, IPivotStyleProps, IPivotStyles } from './Pivot.types';\nimport type { IPivotItemProps } from './PivotItem.types';\n\nconst getClassNames = classNamesFunction<IPivotStyleProps, IPivotStyles>();\n\nconst COMPONENT_NAME = 'Pivot';\n\ntype PivotLinkCollection = {\n links: IPivotItemProps[];\n keyToIndexMapping: { [key: string]: number };\n keyToTabIdMapping: { [key: string]: string };\n};\n\nconst getTabId = (props: IPivotProps, pivotId: string, itemKey: string, index: number): string => {\n if (props.getTabId) {\n return props.getTabId(itemKey, index);\n }\n return pivotId + `-Tab${index}`;\n};\n\n// Gets the set of PivotLinks as array of IPivotItemProps\n// The set of Links is determined by child components of type PivotItem\nconst getLinkItems = (props: IPivotProps, pivotId: string): PivotLinkCollection => {\n const result: PivotLinkCollection = {\n links: [],\n keyToIndexMapping: {},\n keyToTabIdMapping: {},\n };\n\n React.Children.forEach(React.Children.toArray(props.children), (child: React.ReactNode, index: number) => {\n if (isPivotItem(child)) {\n // eslint-disable-next-line deprecation/deprecation\n const { linkText, ...pivotItemProps } = child.props;\n const itemKey = child.props.itemKey || index.toString();\n result.links.push({\n headerText: linkText,\n ...pivotItemProps,\n itemKey: itemKey,\n });\n result.keyToIndexMapping[itemKey] = index;\n result.keyToTabIdMapping[itemKey] = getTabId(props, pivotId, itemKey, index);\n } else if (child) {\n warn('The children of a Pivot component must be of type PivotItem to be rendered.');\n }\n });\n return result;\n};\n\nconst isPivotItem = (item: React.ReactNode): item is PivotItem => {\n return React.isValidElement(item) && (item.type as React.ComponentType)?.name === PivotItem.name;\n};\n\nexport const PivotBase: React.FunctionComponent<IPivotProps> = React.forwardRef<HTMLDivElement, IPivotProps>(\n (props, ref) => {\n const focusZoneRef = React.useRef<IFocusZone>(null);\n const overflowMenuButtonComponentRef = React.useRef<IButton>(null);\n const pivotId: string = useId('Pivot');\n\n const [selectedKey, setSelectedKey] = useControllableValue(props.selectedKey, props.defaultSelectedKey);\n\n const { componentRef, theme, linkSize, linkFormat, overflowBehavior, overflowAriaLabel, focusZoneProps } = props;\n\n let classNames: { [key in keyof IPivotStyles]: string };\n const nameProps = {\n 'aria-label': props['aria-label'],\n 'aria-labelledby': props['aria-labelledby'],\n };\n const divProps = getNativeProps<React.HTMLAttributes<HTMLDivElement>>(props, divProperties, [\n 'aria-label',\n 'aria-labelledby',\n ]);\n\n let linkCollection = getLinkItems(props, pivotId);\n\n React.useImperativeHandle(componentRef as React.RefObject<IPivot>, () => ({\n focus: () => {\n focusZoneRef.current?.focus();\n },\n }));\n\n const renderLinkContent = (link?: IPivotItemProps): JSX.Element | null => {\n if (!link) {\n return null;\n }\n\n const { itemCount, itemIcon, headerText } = link;\n return (\n <span className={classNames.linkContent}>\n {itemIcon !== undefined && (\n <span className={classNames.icon}>\n <Icon iconName={itemIcon} />\n </span>\n )}\n {headerText !== undefined && <span className={classNames.text}> {link.headerText}</span>}\n {itemCount !== undefined && <span className={classNames.count}> ({itemCount})</span>}\n </span>\n );\n };\n\n const renderPivotLink = (\n renderLinkCollection: PivotLinkCollection,\n link: IPivotItemProps,\n renderPivotLinkSelectedKey: string | null | undefined,\n className: string,\n ): JSX.Element => {\n const { itemKey, headerButtonProps, onRenderItemLink } = link;\n const tabId = renderLinkCollection.keyToTabIdMapping[itemKey!];\n let linkContent: JSX.Element | null;\n const isSelected: boolean = renderPivotLinkSelectedKey === itemKey;\n\n if (onRenderItemLink) {\n linkContent = onRenderItemLink(link, renderLinkContent);\n } else {\n linkContent = renderLinkContent(link);\n }\n\n let contentString = link.headerText || '';\n contentString += link.itemCount ? ' (' + link.itemCount + ')' : '';\n // Adding space supplementary for icon\n contentString += link.itemIcon ? ' xx' : '';\n\n const itemSemantics =\n link.role && link.role !== 'tab'\n ? {\n role: link.role,\n }\n : {\n role: 'tab',\n 'aria-selected': isSelected,\n };\n\n return (\n <CommandButton\n {...headerButtonProps}\n {...itemSemantics}\n id={tabId}\n key={itemKey}\n className={css(className, isSelected && classNames.linkIsSelected)}\n // eslint-disable-next-line react/jsx-no-bind\n onClick={(ev: React.MouseEvent<HTMLElement>) => onLinkClick(itemKey!, ev)}\n // eslint-disable-next-line react/jsx-no-bind\n onKeyDown={(ev: React.KeyboardEvent<HTMLElement>) => onKeyDown(itemKey!, ev)}\n aria-label={link.ariaLabel}\n name={link.headerText}\n keytipProps={link.keytipProps}\n data-content={contentString}\n >\n {linkContent}\n </CommandButton>\n );\n };\n\n const onLinkClick = (itemKey: string, ev: React.MouseEvent<HTMLElement>): void => {\n ev.preventDefault();\n updateSelectedItem(itemKey, ev);\n };\n\n const onKeyDown = (itemKey: string, ev: React.KeyboardEvent<HTMLElement>): void => {\n // eslint-disable-next-line deprecation/deprecation\n if (ev.which === KeyCodes.enter) {\n ev.preventDefault();\n updateSelectedItem(itemKey);\n }\n };\n\n const updateSelectedItem = (itemKey: string, ev?: React.MouseEvent<HTMLElement>): void => {\n setSelectedKey(itemKey);\n linkCollection = getLinkItems(props, pivotId);\n if (props.onLinkClick && linkCollection.keyToIndexMapping[itemKey] >= 0) {\n const selectedIndex = linkCollection.keyToIndexMapping[itemKey];\n const item = React.Children.toArray(props.children)[selectedIndex];\n if (isPivotItem(item)) {\n props.onLinkClick(item, ev);\n }\n }\n\n overflowMenuButtonComponentRef.current?.dismissMenu();\n };\n\n const renderPivotItem = (itemKey: string | undefined, isActive: boolean): JSX.Element | null => {\n if (props.headersOnly || !itemKey) {\n return null;\n }\n\n const index = linkCollection.keyToIndexMapping[itemKey];\n const selectedTabId = linkCollection.keyToTabIdMapping[itemKey];\n return (\n <div\n role=\"tabpanel\"\n hidden={!isActive}\n key={itemKey}\n aria-hidden={!isActive}\n aria-labelledby={selectedTabId}\n className={classNames.itemContainer}\n >\n {React.Children.toArray(props.children)[index]}\n </div>\n );\n };\n\n const isKeyValid = (itemKey: string | null | undefined): boolean => {\n return itemKey === null || (itemKey !== undefined && linkCollection.keyToIndexMapping[itemKey] !== undefined);\n };\n\n const getSelectedKey = () => {\n if (isKeyValid(selectedKey)) {\n return selectedKey;\n }\n if (linkCollection.links.length) {\n return linkCollection.links[0].itemKey;\n }\n return undefined;\n };\n\n classNames = getClassNames(props.styles!, {\n theme: theme!,\n linkSize,\n linkFormat,\n });\n\n const renderedSelectedKey = getSelectedKey();\n const renderedSelectedIndex = renderedSelectedKey ? linkCollection.keyToIndexMapping[renderedSelectedKey] : 0;\n\n const items = linkCollection.links.map(l =>\n renderPivotLink(linkCollection, l, renderedSelectedKey, classNames.link),\n );\n\n // The overflow menu starts empty and items[] is updated as the overflow items change\n const overflowMenuProps: IContextualMenuProps = React.useMemo(\n () => ({\n items: [],\n alignTargetEdge: true,\n directionalHint: DirectionalHint.bottomRightEdge,\n }),\n [],\n );\n\n const { menuButtonRef: overflowMenuButtonRef } = useOverflow({\n onOverflowItemsChanged: (overflowIndex, elements) => {\n // Set data-is-overflowing on each item\n elements.forEach(({ ele, isOverflowing }) => (ele.dataset.isOverflowing = `${isOverflowing}`));\n\n // Update the menu items\n overflowMenuProps.items = linkCollection.links\n .slice(overflowIndex)\n .filter(link => link.itemKey !== renderedSelectedKey)\n .map((link, index) => {\n link.role = 'menuitem';\n\n return {\n key: link.itemKey || `${overflowIndex + index}`,\n onRender: () => renderPivotLink(linkCollection, link, renderedSelectedKey, classNames.linkInMenu),\n };\n });\n },\n rtl: getRTL(theme),\n pinnedIndex: renderedSelectedIndex,\n });\n\n return (\n <div ref={ref} {...divProps}>\n <FocusZone\n componentRef={focusZoneRef}\n role=\"tablist\"\n {...nameProps}\n direction={FocusZoneDirection.horizontal}\n {...focusZoneProps}\n className={css(classNames.root, focusZoneProps?.className)}\n >\n {items}\n {overflowBehavior === 'menu' && (\n <CommandButton\n className={css(classNames.link, classNames.overflowMenuButton)}\n elementRef={overflowMenuButtonRef}\n componentRef={overflowMenuButtonComponentRef}\n menuProps={overflowMenuProps}\n menuIconProps={{ iconName: 'More', style: { color: 'inherit' } }}\n ariaLabel={overflowAriaLabel}\n />\n )}\n </FocusZone>\n {renderedSelectedKey &&\n linkCollection.links.map(\n link =>\n (link.alwaysRender === true || renderedSelectedKey === link.itemKey) &&\n renderPivotItem(link.itemKey, renderedSelectedKey === link.itemKey),\n )}\n </div>\n );\n },\n);\nPivotBase.displayName = COMPONENT_NAME;\n"]}
\No newline at end of file