UNPKG

react-aria

Version:
1 lines 3.48 kB
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA6CM,SAAS,0CACd,KAA8B,EAC9B,GAAuC;IAEvC,IAAI,aACF,SAAS,cACT,UAAU,EACV,gBAAgB,WAAW,eAC3B,cAAc,KACd,GAAG,YACJ,GAAG;IAEJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,yCAAM,EAAE;QAAC,YAAY,cAAc;qBAAW;QAAa,GAAG,UAAU;IAAA,GAAG;IAC7F,IAAI,YAAY,WAAW,IAAI,CAAC;IAChC,IAAI,YAA2B,CAAC;IAEhC,IAAI,CAAC,WACH,YAAY;IAGd,IAAI,WAAW;QACb,SAAS,CAAC,eAAe,GAAG,eAAe;QAC3C,2DAA2D;QAC3D,oEAAoE;QACpE,UAAU,QAAQ,GAAG,MAAM,SAAS,GAAG,KAAK;IAC9C;IAEA,OAAO;QACL,WAAW;YACT,iBAAiB;YACjB,GAAG,SAAS;QACd;IACF;AACF","sources":["packages/react-aria/src/breadcrumbs/useBreadcrumbItem.ts"],"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 {AriaLinkProps, useLink} from '../link/useLink';\nimport {\n DOMAttributes,\n DOMProps,\n FocusableElement,\n LinkDOMProps,\n RefObject\n} from '@react-types/shared';\nimport {ReactNode} from 'react';\n\nexport interface BreadcrumbItemProps extends AriaLinkProps, LinkDOMProps {\n /** Whether the breadcrumb item represents the current page. */\n isCurrent?: boolean;\n /**\n * The type of current location the breadcrumb item represents, if `isCurrent` is true.\n *\n * @default 'page'\n */\n 'aria-current'?: 'page' | 'step' | 'location' | 'date' | 'time' | boolean | 'true' | 'false';\n /** Whether the breadcrumb item is disabled. */\n isDisabled?: boolean;\n /** The contents of the breadcrumb item. */\n children: ReactNode;\n}\n\nexport interface AriaBreadcrumbItemProps extends BreadcrumbItemProps, DOMProps {\n /**\n * The HTML element used to render the breadcrumb link, e.g. 'a', or 'span'.\n *\n * @default 'a'\n */\n elementType?: string;\n}\n\nexport interface BreadcrumbItemAria {\n /** Props for the breadcrumb item link element. */\n itemProps: DOMAttributes;\n}\n\n/**\n * Provides the behavior and accessibility implementation for an in a breadcrumbs component.\n * See `useBreadcrumbs` for details about breadcrumbs.\n */\nexport function useBreadcrumbItem(\n props: AriaBreadcrumbItemProps,\n ref: RefObject<FocusableElement | null>\n): BreadcrumbItemAria {\n let {\n isCurrent,\n isDisabled,\n 'aria-current': ariaCurrent,\n elementType = 'a',\n ...otherProps\n } = props;\n\n let {linkProps} = useLink({isDisabled: isDisabled || isCurrent, elementType, ...otherProps}, ref);\n let isHeading = /^h[1-6]$/.test(elementType);\n let itemProps: DOMAttributes = {};\n\n if (!isHeading) {\n itemProps = linkProps;\n }\n\n if (isCurrent) {\n itemProps['aria-current'] = ariaCurrent || 'page';\n // isCurrent sets isDisabled === true for the current item,\n // so we have to restore the tabIndex in order to support autoFocus.\n itemProps.tabIndex = props.autoFocus ? -1 : undefined;\n }\n\n return {\n itemProps: {\n 'aria-disabled': isDisabled,\n ...itemProps\n }\n };\n}\n"],"names":[],"version":3,"file":"useBreadcrumbItem.mjs.map"}