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AAE,EAAE,CAAC,CAAC;aAClC;SACF;IACH,CAAC;IAEO,kCAAc,GAAtB,UAAuB,KAAkB;QAC/B,IAAA,mBAAK,CAAW;QACxB,IAAM,WAAW,GAAY,KAAK,CAAC,QAAQ,KAAK,aAAa,CAAC,KAAK,CAAC;QACpE,IAAM,UAAU,GAAY,KAAK,CAAC,UAAU,KAAK,eAAe,CAAC,IAAI,CAAC;QAEtE,OAAO,aAAa,CAAC,KAAK,CAAC,MAAO,EAAE;YAClC,KAAK,EAAE,KAAM;YACb,WAAW,aAAA;YACX,UAAU,YAAA;SACX,CAAC,CAAC;IACL,CAAC;IACH,gBAAC;AAAD,CAAC,AA/SD,CAA+B,KAAK,CAAC,SAAS,GA+S7C;;AAED,SAAS,YAAY,CAAC,IAAqB;IACzC,sEAAsE;IACtE,yGAAyG;IACzG,uFAAuF;IACvF,OAAO,CACL,CAAC,CAAC,IAAI;QACN,OAAO,IAAI,KAAK,QAAQ;QACxB,CAAC,CAAE,IAA2B,CAAC,IAAI;QACnC,uDAAuD;QACrD,IAA2B,CAAC,IAAY,CAAC,IAAI,KAAM,SAAiB,CAAC,IAAI,CAC5E,CAAC;AACJ,CAAC","sourcesContent":["import * as React from 'react';\nimport {\n warnDeprecations,\n KeyCodes,\n getId,\n getNativeProps,\n divProperties,\n classNamesFunction,\n warn,\n initializeComponentRef,\n css,\n} from '../../Utilities';\nimport { CommandButton } from '../../Button';\nimport { IPivotProps, IPivotStyleProps, IPivotStyles } from './Pivot.types';\nimport { IPivotItemProps } from './PivotItem.types';\nimport { FocusZone, FocusZoneDirection, IFocusZoneProps } from '../../FocusZone';\nimport { PivotItem } from './PivotItem';\nimport { PivotLinkFormat } from './Pivot.types';\nimport { PivotLinkSize } from './Pivot.types';\nimport { Icon } from '../../Icon';\n\nconst getClassNames = classNamesFunction<IPivotStyleProps, IPivotStyles>();\nconst PivotName = 'Pivot';\n\nexport interface IPivotState {\n selectedKey: string | undefined;\n}\n\ntype PivotLinkCollection = {\n links: IPivotItemProps[];\n keyToIndexMapping: { [key: string]: number };\n keyToTabIdMapping: { [key: string]: string };\n};\n\n/**\n * Usage:\n *\n * <Pivot>\n * <PivotItem headerText=\"Foo\">\n * <Label>Pivot #1</Label>\n * </PivotItem>\n * <PivotItem headerText=\"Bar\">\n * <Label>Pivot #2</Label>\n * </PivotItem>\n * <PivotItem headerText=\"Bas\">\n * <Label>Pivot #3</Label>\n * </PivotItem>\n * </Pivot>\n */\nexport class PivotBase extends React.Component<IPivotProps, IPivotState> {\n private _pivotId: string;\n private _focusZone = React.createRef<FocusZone>();\n private _classNames: { [key in keyof IPivotStyles]: string };\n\n constructor(props: IPivotProps) {\n super(props);\n\n initializeComponentRef(this);\n\n if (process.env.NODE_ENV !== 'production') {\n warnDeprecations(PivotName, props, {\n initialSelectedKey: 'defaultSelectedKey',\n initialSelectedIndex: 'defaultSelectedIndex',\n });\n }\n\n this._pivotId = getId(PivotName);\n const links: IPivotItemProps[] = this._getPivotLinks(props).links;\n\n // eslint-disable-next-line deprecation/deprecation\n const { defaultSelectedKey = props.initialSelectedKey, defaultSelectedIndex = props.initialSelectedIndex } = props;\n\n let selectedKey: string | undefined;\n\n if (defaultSelectedKey) {\n selectedKey = defaultSelectedKey;\n } else if (typeof defaultSelectedIndex === 'number') {\n selectedKey = links[defaultSelectedIndex].itemKey!;\n } else if (links.length) {\n selectedKey = links[0].itemKey!;\n }\n\n this.state = {\n selectedKey,\n };\n }\n\n /**\n * Sets focus to the first pivot tab.\n */\n public focus(): void {\n if (this._focusZone.current) {\n this._focusZone.current.focus();\n }\n }\n\n public render(): JSX.Element {\n const { focusZoneProps } = this.props;\n const linkCollection = this._getPivotLinks(this.props);\n const selectedKey = this._getSelectedKey(linkCollection);\n\n const divProps = getNativeProps<React.HTMLAttributes<HTMLDivElement>>(this.props, divProperties);\n\n this._classNames = this._getClassNames(this.props);\n\n return (\n <div role=\"toolbar\" {...divProps}>\n {this._renderPivotLinks(linkCollection, selectedKey, focusZoneProps)}\n {selectedKey &&\n linkCollection.links.map(\n (link) =>\n (link.alwaysRender === true || selectedKey === link.itemKey) &&\n this._renderPivotItem(linkCollection, link.itemKey, selectedKey === link.itemKey),\n )}\n </div>\n );\n }\n\n private _getSelectedKey(linkCollection: PivotLinkCollection) {\n const { selectedKey: propsSelectedKey } = this.props;\n\n if (this._isKeyValid(linkCollection, propsSelectedKey) || propsSelectedKey === null) {\n return propsSelectedKey;\n }\n\n const { selectedKey: stateSelectedKey } = this.state;\n if (this._isKeyValid(linkCollection, stateSelectedKey)) {\n return stateSelectedKey;\n }\n\n if (linkCollection.links.length) {\n return linkCollection.links[0].itemKey;\n }\n\n return undefined;\n }\n\n /**\n * Renders the set of links to route between pivots\n */\n private _renderPivotLinks(\n linkCollection: PivotLinkCollection,\n selectedKey: string | null | undefined,\n focusZoneProps: IFocusZoneProps | undefined,\n ): JSX.Element {\n const items = linkCollection.links.map((l) => this._renderPivotLink(linkCollection, l, selectedKey));\n\n return (\n <FocusZone\n role=\"tablist\"\n componentRef={this._focusZone}\n direction={FocusZoneDirection.horizontal}\n {...focusZoneProps}\n className={css(this._classNames.root, focusZoneProps?.className)}\n >\n {items}\n </FocusZone>\n );\n }\n\n private _renderPivotLink = (\n linkCollection: PivotLinkCollection,\n link: IPivotItemProps,\n selectedKey: string | null | undefined,\n ): JSX.Element => {\n const { itemKey, headerButtonProps } = link;\n const tabId = linkCollection.keyToTabIdMapping[itemKey!];\n const { onRenderItemLink } = link;\n let linkContent: JSX.Element | null;\n const isSelected: boolean = selectedKey === itemKey;\n\n if (onRenderItemLink) {\n linkContent = onRenderItemLink(link, this._renderLinkContent);\n } else {\n linkContent = this._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 return (\n <CommandButton\n {...headerButtonProps}\n id={tabId}\n key={itemKey}\n className={isSelected ? this._classNames.linkIsSelected : this._classNames.link}\n // eslint-disable-next-line react/jsx-no-bind\n onClick={this._onLinkClick.bind(this, itemKey)}\n // eslint-disable-next-line react/jsx-no-bind\n onKeyDown={this._onKeyDown.bind(this, itemKey)}\n aria-label={link.ariaLabel}\n role=\"tab\"\n aria-selected={isSelected}\n name={link.headerText}\n keytipProps={link.keytipProps}\n data-content={contentString}\n >\n {linkContent}\n </CommandButton>\n );\n };\n\n private _renderLinkContent = (link: IPivotItemProps): JSX.Element => {\n const { itemCount, itemIcon, headerText } = link;\n const classNames = this._classNames;\n\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 /**\n * Renders a Pivot Item\n */\n private _renderPivotItem(\n linkCollection: PivotLinkCollection,\n itemKey: string | undefined,\n isActive: boolean,\n ): JSX.Element | null {\n if (this.props.headersOnly || !itemKey) {\n return null;\n }\n\n const index = linkCollection.keyToIndexMapping[itemKey];\n const selectedTabId = linkCollection.keyToTabIdMapping[itemKey];\n\n return (\n <div\n role=\"tabpanel\"\n hidden={!isActive}\n key={itemKey}\n aria-hidden={!isActive}\n aria-labelledby={selectedTabId}\n className={this._classNames.itemContainer}\n >\n {React.Children.toArray(this.props.children)[index]}\n </div>\n );\n }\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\n */\n private _getPivotLinks(props: IPivotProps): PivotLinkCollection {\n const result: PivotLinkCollection = {\n links: [],\n keyToIndexMapping: {},\n keyToTabIdMapping: {},\n };\n\n React.Children.map(React.Children.toArray(props.children), (child: React.ReactChild, index: number) => {\n if (_isPivotItem(child)) {\n const pivotItem = child;\n const { linkText, ...pivotItemProps } = pivotItem.props;\n const itemKey = pivotItem.props.itemKey || index.toString();\n\n result.links.push({\n // Use linkText (deprecated) if headerText is not provided\n headerText: linkText,\n ...pivotItemProps,\n itemKey: itemKey,\n });\n result.keyToIndexMapping[itemKey] = index;\n result.keyToTabIdMapping[itemKey] = this._getTabId(itemKey, index);\n } else {\n warn('The children of a Pivot component must be of type PivotItem to be rendered.');\n }\n });\n\n return result;\n }\n\n /**\n * Generates the Id for the tab button.\n */\n private _getTabId(itemKey: string, index: number): string {\n if (this.props.getTabId) {\n return this.props.getTabId(itemKey, index);\n }\n\n return this._pivotId + `-Tab${index}`;\n }\n\n /**\n * whether the key exists in the pivot items.\n */\n private _isKeyValid(linkCollection: PivotLinkCollection, itemKey: string | null | undefined): boolean {\n return itemKey !== undefined && itemKey !== null && linkCollection.keyToIndexMapping[itemKey] !== undefined;\n }\n\n /**\n * Handles the onClick event on PivotLinks\n */\n private _onLinkClick(itemKey: string, ev: React.MouseEvent<HTMLElement>): void {\n ev.preventDefault();\n this._updateSelectedItem(itemKey, ev);\n }\n\n /**\n * Handle the onKeyDown event on the PivotLinks\n */\n private _onKeyDown(itemKey: string, ev: React.KeyboardEvent<HTMLElement>): void {\n if (ev.which === KeyCodes.enter) {\n ev.preventDefault();\n this._updateSelectedItem(itemKey);\n }\n }\n\n /**\n * Updates the state with the new selected index\n */\n private _updateSelectedItem(itemKey: string, ev?: React.MouseEvent<HTMLElement>): void {\n this.setState({\n selectedKey: itemKey,\n });\n\n const linkCollection = this._getPivotLinks(this.props);\n\n if (this.props.onLinkClick && linkCollection.keyToIndexMapping[itemKey] >= 0) {\n const index = linkCollection.keyToIndexMapping[itemKey];\n\n // React.Element<any> cannot directly convert to PivotItem.\n const item = React.Children.toArray(this.props.children)[index];\n\n if (_isPivotItem(item)) {\n this.props.onLinkClick(item, ev);\n }\n }\n }\n\n private _getClassNames(props: IPivotProps): { [key in keyof IPivotStyles]: string } {\n const { theme } = props;\n const rootIsLarge: boolean = props.linkSize === PivotLinkSize.large;\n const rootIsTabs: boolean = props.linkFormat === PivotLinkFormat.tabs;\n\n return getClassNames(props.styles!, {\n theme: theme!,\n rootIsLarge,\n rootIsTabs,\n });\n }\n}\n\nfunction _isPivotItem(item: React.ReactNode): item is PivotItem {\n // In theory, we should be able to just check item.type === PivotItem.\n // However, under certain unclear circumstances (see https://github.com/microsoft/fluentui/issues/10785),\n // the object identity is different despite the function implementation being the same.\n return (\n !!item &&\n typeof item === 'object' &&\n !!(item as React.ReactElement).type &&\n // Casting as an any to avoid [ object Object ] errors.\n ((item as React.ReactElement).type as any).name === (PivotItem as any).name\n );\n}\n"]}
\No newline at end of file