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,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAC9B,SAAS,EACZ;aACH;YAED,iDAAiD;YACjD,IAAI,QAAQ,KAAK,QAAQ,EAAE;gBACzB,kBACE,IAAI,EAAE,QAAQ,EACd,QAAQ,UAAA,IACL,SAAS,EACZ;aACH;YAED,qEAAqE;YACrE,6BAAY,SAAS,KAAE,QAAQ,UAAA,IAAG;SACnC;QAED,mDAAmD;QACnD,kBAAS,MAAM,QAAA,EAAE,IAAI,MAAA,EAAE,QAAQ,UAAA,IAAK,SAAS,EAAG;IAClD,CAAC;IAEO,+BAAY,GAApB,UAAqB,KAAiB;QACpC,IAAI,KAAK,CAAC,EAAE,EAAE;YACZ,OAAO,KAAK,CAAC,EAAE,CAAC;SACjB;QAED,IAAI,KAAK,CAAC,IAAI,EAAE;YACd,OAAO,GAAG,CAAC;SACZ;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IACH,eAAC;AAAD,CAAC,AArID,CAA8B,KAAK,CAAC,SAAS,GAqI5C","sourcesContent":["import * as React from 'react';\nimport { classNamesFunction, initializeComponentRef } from '../../Utilities';\nimport { ILink, ILinkProps, ILinkStyleProps, ILinkStyles } from './Link.types';\nimport { KeytipData } from '../../KeytipData';\n\nconst getClassNames = classNamesFunction<ILinkStyleProps, ILinkStyles>();\n\nexport class LinkBase extends React.Component<ILinkProps, {}> implements ILink {\n private _link = React.createRef<HTMLAnchorElement | HTMLButtonElement | null>();\n\n constructor(props: ILinkProps) {\n super(props);\n\n initializeComponentRef(this);\n }\n\n public render(): JSX.Element {\n const { disabled, keytipProps } = this.props;\n\n if (keytipProps) {\n return (\n <KeytipData\n keytipProps={keytipProps}\n ariaDescribedBy={(this.props as { 'aria-describedby': string })['aria-describedby']}\n disabled={disabled}\n >\n {(keytipAttributes: any): JSX.Element => this._renderContent(keytipAttributes)}\n </KeytipData>\n );\n }\n\n return this._renderContent();\n }\n\n public focus() {\n const { current } = this._link;\n\n if (current && current.focus) {\n current.focus();\n }\n }\n\n private _renderContent = (keytipAttributes: any = {}): JSX.Element => {\n const { disabled, children, className, href, underline, theme, styles } = this.props;\n\n const classNames = getClassNames(styles!, {\n className,\n isButton: !href,\n isDisabled: disabled,\n isUnderlined: underline,\n theme: theme!,\n });\n\n const RootType = this._getRootType(this.props);\n\n return (\n <RootType\n {...keytipAttributes}\n {...this._adjustPropsForRootType(RootType, this.props)}\n className={classNames.root}\n onClick={this._onClick}\n ref={this._link}\n aria-disabled={disabled}\n >\n {children}\n </RootType>\n );\n };\n\n private _onClick = (ev: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement>) => {\n const { onClick, disabled } = this.props;\n\n if (disabled) {\n ev.preventDefault();\n } else if (onClick) {\n onClick(ev);\n }\n };\n\n private _adjustPropsForRootType(\n RootType: string | React.ComponentClass | React.FunctionComponent,\n props: ILinkProps & { getStyles?: any },\n ): Partial<ILinkProps> {\n // Deconstruct the props so we remove props like `as`, `theme` and `styles`\n // as those will always be removed. We also take some props that are optional\n // based on the RootType.\n const {\n children,\n as,\n disabled,\n target,\n href,\n theme,\n getStyles,\n styles,\n componentRef,\n keytipProps,\n underline,\n ...restProps\n } = props;\n\n // RootType will be a string if we're dealing with an html component\n if (typeof RootType === 'string') {\n // Remove the disabled prop for anchor elements\n if (RootType === 'a') {\n return {\n target,\n href: disabled ? undefined : href,\n ...restProps,\n };\n }\n\n // Add the type='button' prop for button elements\n if (RootType === 'button') {\n return {\n type: 'button',\n disabled,\n ...restProps,\n };\n }\n\n // Remove the target and href props for all other non anchor elements\n return { ...restProps, disabled };\n }\n\n // Retain all props except 'as' for ReactComponents\n return { target, href, disabled, ...restProps };\n }\n\n private _getRootType(props: ILinkProps): string | React.ComponentClass | React.FunctionComponent {\n if (props.as) {\n return props.as;\n }\n\n if (props.href) {\n return 'a';\n }\n\n return 'button';\n }\n}\n"]}
\No newline at end of file