@react-spectrum/s2
Version:
Spectrum 2 UI components in React
1 lines • 7.8 kB
Source Map (JSON)
{"mappings":"AC6CgB;EAAA;;;;EAAA;;;;;;EAAA;IAAA;;;;;;EAAA;;;;;;EAAA;;;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;;EAAA;;;;EA6DI;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;;AA7DJ;EAAA;;;;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;IAAA;;;;;;AAAA;EAAA;IAAA;;;;IAAA;;;;IAAA;;;;IAAA;;;;IAAA;;;;IAAA;;;;IAAA","sources":["aa7688246f893a38","packages/@react-spectrum/s2/src/Tooltip.tsx"],"sourcesContent":["@import \"98a0a1b80e895d38\";\n@import \"c07030e64bc8758c\";\n","/*\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 {\n Tooltip as AriaTooltip,\n TooltipProps as AriaTooltipProps,\n TooltipTrigger as AriaTooltipTrigger,\n TooltipTriggerComponentProps as AriaTooltipTriggerComponentProps,\n OverlayArrow,\n TooltipRenderProps,\n useLocale\n} from 'react-aria-components';\nimport {centerPadding, colorScheme, UnsafeStyles} from './style-utils' with {type: 'macro'};\nimport {ColorScheme} from '@react-types/provider';\nimport {ColorSchemeContext} from './Provider';\nimport {createContext, forwardRef, MutableRefObject, ReactNode, useCallback, useContext, useState} from 'react';\nimport {DOMRef} from '@react-types/shared';\nimport {style} from '../style' with {type: 'macro'};\nimport {useDOMRef} from '@react-spectrum/utils';\n\nexport interface TooltipTriggerProps extends Omit<AriaTooltipTriggerComponentProps, 'children' | 'closeDelay'>, Pick<AriaTooltipProps, 'shouldFlip' | 'containerPadding' | 'offset' | 'crossOffset'> {\n /** The content of the tooltip. */\n children: ReactNode,\n /**\n * The placement of the element with respect to its anchor element.\n *\n * @default 'top'\n */\n placement?: 'start' | 'end' | 'right' | 'left' | 'top' | 'bottom'\n}\n\nexport interface TooltipProps extends Omit<AriaTooltipProps, 'children' | 'className' | 'style' | 'triggerRef' | 'UNSTABLE_portalContainer' | 'isEntering' | 'isExiting' | 'placement' | 'containerPadding' | 'offset' | 'crossOffset' | 'shouldFlip' | 'arrowBoundaryOffset' | 'isOpen' | 'defaultOpen' | 'onOpenChange'>, UnsafeStyles {\n /** The content of the tooltip. */\n children: ReactNode\n}\n\nconst tooltip = style<TooltipRenderProps & {colorScheme: ColorScheme | 'light dark' | null}>({\n ...colorScheme(),\n justifyContent: 'center',\n alignItems: 'center',\n maxWidth: 160,\n minHeight: 24,\n boxSizing: 'border-box',\n font: 'ui-sm',\n color: {\n default: 'gray-25',\n forcedColors: 'ButtonText'\n },\n borderWidth: {\n forcedColors: 1\n },\n borderStyle: {\n forcedColors: 'solid'\n },\n borderColor: {\n forcedColors: 'transparent'\n },\n backgroundColor: 'neutral',\n borderRadius: 'default',\n paddingX: 'edge-to-text',\n paddingY: centerPadding(),\n margin: 8,\n transition: 'default',\n transitionDuration: 200,\n transitionTimingFunction: {\n isExiting: 'in'\n },\n translateX: {\n placement: {\n left: {\n isEntering: 4,\n isExiting: 4\n },\n right: {\n isEntering: -4,\n isExiting: -4\n }\n }\n },\n translateY: {\n placement: {\n top: {\n isEntering: 4,\n isExiting: 4\n },\n bottom: {\n isEntering: -4,\n isExiting: -4\n }\n }\n },\n opacity: {\n isEntering: 0,\n isExiting: 0\n }\n});\n\nconst arrowStyles = style<TooltipRenderProps>({\n display: 'block',\n fill: 'gray-800',\n width: 10,\n height: 5,\n rotate: {\n placement: {\n top: 0,\n bottom: '180deg',\n left: '-90deg',\n right: '90deg'\n }\n },\n translateX: {\n placement: {\n left: '-25%',\n right: '25%'\n }\n }\n});\n\nlet InternalTooltipTriggerContext = createContext<Partial<TooltipTriggerProps>>({});\n\n/**\n * Display container for Tooltip content. Has a directional arrow dependent on its placement.\n */\nexport const Tooltip = forwardRef(function Tooltip(props: TooltipProps, ref: DOMRef<HTMLDivElement>) {\n let {children, UNSAFE_style, UNSAFE_className = ''} = props;\n let domRef = useDOMRef(ref);\n let {\n containerPadding,\n crossOffset,\n offset,\n placement = 'top',\n shouldFlip\n } = useContext(InternalTooltipTriggerContext);\n let colorScheme = useContext(ColorSchemeContext);\n let {locale, direction} = useLocale();\n let [borderRadius, setBorderRadius] = useState(0);\n\n // TODO: should we pass through lang and dir props in RAC?\n let tooltipRef = useCallback((el: HTMLDivElement) => {\n (domRef as MutableRefObject<HTMLDivElement>).current = el;\n if (el) {\n el.lang = locale;\n el.dir = direction;\n let spectrumBorderRadius = typeof window !== 'undefined' ? window.getComputedStyle(el).borderRadius : '';\n if (spectrumBorderRadius !== '') {\n setBorderRadius(parseInt(spectrumBorderRadius, 10));\n }\n }\n }, [locale, direction, domRef]);\n\n return (\n <AriaTooltip\n {...props}\n arrowBoundaryOffset={borderRadius}\n containerPadding={containerPadding}\n crossOffset={crossOffset}\n offset={offset}\n placement={placement}\n shouldFlip={shouldFlip}\n ref={tooltipRef}\n style={UNSAFE_style}\n className={renderProps => UNSAFE_className + tooltip({...renderProps, colorScheme})}>\n {renderProps => (\n <>\n <OverlayArrow>\n <svg className={arrowStyles(renderProps)} xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 10 5\">\n <path d=\"M4.29289 4.29289L0 0H10L5.70711 4.29289C5.31658 4.68342 4.68342 4.68342 4.29289 4.29289Z\" />\n </svg>\n </OverlayArrow>\n {children}\n </>\n )}\n </AriaTooltip>\n );\n});\n\n/**\n * TooltipTrigger wraps around a trigger element and a Tooltip. It handles opening and closing\n * the Tooltip when the user hovers over or focuses the trigger, and positioning the Tooltip\n * relative to the trigger.\n */\nexport function TooltipTrigger(props: TooltipTriggerProps): ReactNode {\n let {\n containerPadding,\n crossOffset,\n offset,\n placement,\n shouldFlip,\n ...triggerProps\n } = props;\n\n return (\n <AriaTooltipTrigger {...triggerProps}>\n <InternalTooltipTriggerContext.Provider\n value={{\n containerPadding: containerPadding,\n crossOffset: crossOffset,\n offset: offset,\n placement: placement,\n shouldFlip: shouldFlip\n }}>\n {props.children}\n </InternalTooltipTriggerContext.Provider>\n </AriaTooltipTrigger>\n );\n}\n\n\n// This is purely so that storybook generates the types for both Menu and MenuTrigger\ninterface ICombined extends Omit<TooltipProps, 'placement'>, TooltipTriggerProps {}\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function CombinedTooltip(props: ICombined): ReactNode {\n return <div />;\n}\n"],"names":[],"version":3,"file":"Tooltip.css.map"}