UNPKG

@react-spectrum/s2

Version:
1 lines 5.35 kB
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA8BM,MAAM,0DAAc,CAAA,GAAA,oBAAY,EAA0E;AAEjH,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CC,MAAM,4CAAO,WAAW,GAAG,CAAA,GAAA,iBAAS,EAAE,SAAS,KAAK,KAAgB,EAAE,GAAoC;IAC/G,CAAC,OAAO,IAAI,GAAG,CAAA,GAAA,yCAAsB,EAAE,OAAO,KAAK;IACnD,IAAI,WAAC,UAAU,wBAAW,WAAW,WAAE,OAAO,gBAAE,YAAY,gBAAE,YAAY,oBAAE,mBAAmB,YAAI,MAAM,YAAE,QAAQ,EAAC,GAAG;IAEvH,IAAI,SAAS,CAAA,GAAA,sBAAc,EAAE;IAC7B,IAAI,aAAa,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,yCAAc,MAAM;IAChD,CAAC,UAAU,aAAa,GAAG,CAAA,GAAA,yCAAc,EAAE,UAAU;IAErD,CAAA,GAAA,sBAAc,EAAE;QACd,IAAI,OAAO,OAAO,EAChB,4CAA4C;QAC5C,OAAO,OAAO,CAAC,KAAK,GAAG;IAE3B,GAAG;QAAC;QAAQ;KAAW;IAEvB,qBACE,gBAAC,CAAA,GAAA,WAAM;QACJ,GAAG,KAAK;QACT,KAAK;QACL,OAAO;QACP,WAAW,CAAA,cAAe,mBAAmB,2BAAK;gBAAC,GAAG,WAAW;yBAAE;6BAAS;gBAAa,eAAe,CAAC,CAAC;yBAAa;8BAAS;4BAAc;YAAU,GAAG;kBAC1J;;AAGP","sources":["packages/@react-spectrum/s2/src/Link.tsx"],"sourcesContent":["/*\n * Copyright 2024 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 {baseColor, focusRing, style} from '../style' with {type: 'macro'};\nimport {ContextValue, LinkRenderProps, Link as RACLink, LinkProps as RACLinkProps} from 'react-aria-components';\nimport {createContext, forwardRef, ReactNode, useContext} from 'react';\nimport {FocusableRef, FocusableRefValue} from '@react-types/shared';\nimport {getAllowedOverrides, staticColor, StyleProps} from './style-utils' with {type: 'macro'};\nimport {SkeletonContext, useSkeletonText} from './Skeleton';\nimport {useFocusableRef} from '@react-spectrum/utils';\nimport {useLayoutEffect} from '@react-aria/utils';\nimport {useSpectrumContextProps} from './useSpectrumContextProps';\n\ninterface LinkStyleProps {\n /**\n * The [visual style](https://spectrum.adobe.com/page/link/#Options) of the link.\n * @default 'primary'\n */\n variant?: 'primary' | 'secondary',\n /** The static color style to apply. Useful when the link appears over a color background. */\n staticColor?: 'white' | 'black' | 'auto',\n /** Whether the link is on its own vs inside a longer string of text. */\n isStandalone?: boolean,\n /** Whether the link should be displayed with a quiet style. */\n isQuiet?: boolean\n}\n\nexport interface LinkProps extends Omit<RACLinkProps, 'isDisabled' | 'className' | 'style' | 'children' | 'onHover' | 'onHoverStart' | 'onHoverEnd' | 'onHoverChange' | 'onClick'>, StyleProps, LinkStyleProps {\n children: ReactNode\n}\n\nexport const LinkContext = createContext<ContextValue<Partial<LinkProps>, FocusableRefValue<HTMLAnchorElement>>>(null);\n\nconst link = style<LinkRenderProps & LinkStyleProps & {isSkeleton: boolean, isStaticColor: boolean}>({\n ...focusRing(),\n ...staticColor(),\n borderRadius: 'sm',\n font: {\n isStandalone: 'ui'\n },\n color: {\n variant: {\n primary: baseColor('accent'),\n secondary: baseColor('neutral') // TODO: should there be an option to inherit from the paragraph? What about hover states?\n },\n isStaticColor: 'transparent-overlay-1000',\n forcedColors: 'LinkText'\n },\n transition: 'default',\n fontWeight: {\n isStandalone: 'medium'\n },\n textDecoration: {\n default: 'underline',\n isStandalone: {\n // Inline links must always have an underline for accessibility.\n isQuiet: {\n default: 'none',\n isHovered: 'underline',\n isFocusVisible: 'underline'\n }\n }\n },\n outlineColor: {\n default: 'focus-ring',\n isStaticColor: 'transparent-overlay-1000',\n forcedColors: 'Highlight'\n },\n disableTapHighlight: true\n}, getAllowedOverrides());\n\n/**\n * Links allow users to navigate to a different location.\n * They can be presented inline inside a paragraph or as standalone text.\n */\nexport const Link = /*#__PURE__*/ forwardRef(function Link(props: LinkProps, ref: FocusableRef<HTMLAnchorElement>) {\n [props, ref] = useSpectrumContextProps(props, ref, LinkContext);\n let {variant = 'primary', staticColor, isQuiet, isStandalone, UNSAFE_style, UNSAFE_className = '', styles, children} = props;\n\n let domRef = useFocusableRef(ref);\n let isSkeleton = useContext(SkeletonContext) || false;\n [children, UNSAFE_style] = useSkeletonText(children, UNSAFE_style);\n\n useLayoutEffect(() => {\n if (domRef.current) {\n // TODO: should RAC Link pass through inert?\n domRef.current.inert = isSkeleton;\n }\n }, [domRef, isSkeleton]);\n\n return (\n <RACLink\n {...props}\n ref={domRef}\n style={UNSAFE_style}\n className={renderProps => UNSAFE_className + link({...renderProps, variant, staticColor, isStaticColor: !!staticColor, isQuiet, isStandalone, isSkeleton}, styles)}>\n {children}\n </RACLink>\n );\n});\n"],"names":[],"version":3,"file":"Link.mjs.map"}