UNPKG

react-aria

Version:
1 lines 4.18 kB
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA6CM,SAAS,0CAAQ,KAAsB,EAAE,GAAuC;IACrF,IAAI,eACF,cAAc,cACd,OAAO,gBACP,YAAY,cACZ,UAAU,WACV,OAAO,cACP,UAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,YAA2B,CAAC;IAChC,IAAI,gBAAgB,KAClB,YAAY;QACV,MAAM;QACN,UAAU,CAAC,aAAa,IAAI;IAC9B;IAEF,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,sCAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,kCAAO,EAAE;iBACrC;sBACA;oBACA;iBACA;oBACA;aACA;IACF;IACA,IAAI,WAAW,CAAA,GAAA,wCAAa,EAAE,YAAY;QAAC,WAAW;IAAI;IAC1D,IAAI,sBAAsB,CAAA,GAAA,oCAAS,EAAE,gBAAgB;IACrD,IAAI,SAAS,CAAA,GAAA,mCAAQ;IACrB,IAAI,kBAAkB,CAAA,GAAA,sCAAW,EAAE;IAEnC,OAAO;mBACL;QACA,WAAW,CAAA,GAAA,oCAAS,EAAE,UAAU,iBAAiB;YAC/C,GAAG,mBAAmB;YACtB,GAAG,SAAS;YACZ,iBAAiB,cAAc;YAC/B,gBAAgB,KAAK,CAAC,eAAe;YACrC,SAAS,CAAC;gBACR,WAAW,OAAO,GAAG;gBACrB,CAAA,GAAA,yCAAc,EAAE,GAAG,QAAQ,MAAM,IAAI,EAAE,MAAM,aAAa;YAC5D;QACF;IACF;AACF","sources":["packages/react-aria/src/link/useLink.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 {\n AriaLabelingProps,\n DOMAttributes,\n FocusableElement,\n FocusableProps,\n LinkDOMProps,\n PressEvents,\n RefObject\n} from '@react-types/shared';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {handleLinkClick, useLinkProps, useRouter} from '../utils/openLink';\nimport {mergeProps} from '../utils/mergeProps';\nimport React from 'react';\nimport {useFocusable} from '../interactions/useFocusable';\nimport {usePress} from '../interactions/usePress';\n\nexport interface LinkProps extends PressEvents, FocusableProps {}\n\nexport interface AriaLinkProps extends LinkProps, LinkDOMProps, AriaLabelingProps {}\n\nexport interface AriaLinkOptions extends AriaLinkProps {\n /** Whether the link is disabled. */\n isDisabled?: boolean;\n /**\n * The HTML element used to render the link, e.g. 'a', or 'span'.\n *\n * @default 'a'\n */\n elementType?: string;\n}\n\nexport interface LinkAria {\n /** Props for the link element. */\n linkProps: DOMAttributes;\n /** Whether the link is currently pressed. */\n isPressed: boolean;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a link component.\n * A link allows a user to navigate to another page or resource within a web page\n * or application.\n */\nexport function useLink(props: AriaLinkOptions, ref: RefObject<FocusableElement | null>): LinkAria {\n let {\n elementType = 'a',\n onPress,\n onPressStart,\n onPressEnd,\n onClick,\n isDisabled,\n ...otherProps\n } = props;\n\n let linkProps: DOMAttributes = {};\n if (elementType !== 'a') {\n linkProps = {\n role: 'link',\n tabIndex: !isDisabled ? 0 : undefined\n };\n }\n let {focusableProps} = useFocusable(props, ref);\n let {pressProps, isPressed} = usePress({\n onPress,\n onPressStart,\n onPressEnd,\n onClick,\n isDisabled,\n ref\n });\n let domProps = filterDOMProps(otherProps, {labelable: true});\n let interactionHandlers = mergeProps(focusableProps, pressProps);\n let router = useRouter();\n let routerLinkProps = useLinkProps(props);\n\n return {\n isPressed, // Used to indicate press state for visual\n linkProps: mergeProps(domProps, routerLinkProps, {\n ...interactionHandlers,\n ...linkProps,\n 'aria-disabled': isDisabled || undefined,\n 'aria-current': props['aria-current'],\n onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {\n pressProps.onClick?.(e);\n handleLinkClick(e, router, props.href, props.routerOptions);\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"useLink.cjs.map"}