File tree Expand file tree Collapse file tree 3 files changed +82
-0
lines changed
packages/utah-design-system/src Expand file tree Collapse file tree 3 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ import type { Meta } from '@storybook/react-vite' ;
2+ import { PrinterIcon , SaveIcon } from 'lucide-react' ;
3+ import { TooltipTrigger , type TooltipProps } from 'react-aria-components' ;
4+ import { Button } from './Button' ;
5+ import { Tooltip } from './Tooltip' ;
6+
7+ const meta : Meta < typeof Tooltip > = {
8+ component : Tooltip ,
9+ parameters : {
10+ layout : 'centered' ,
11+ } ,
12+ argTypes : { } ,
13+ args : { } ,
14+ } ;
15+
16+ export default meta ;
17+
18+ export const Example = ( args : TooltipProps ) => (
19+ < div className = "flex gap-2" >
20+ < TooltipTrigger >
21+ < Button variant = "secondary" className = "px-2" >
22+ < SaveIcon className = "h-5 w-5" />
23+ </ Button >
24+ < Tooltip { ...args } > Save</ Tooltip >
25+ </ TooltipTrigger >
26+ < TooltipTrigger >
27+ < Button variant = "secondary" className = "px-2" >
28+ < PrinterIcon className = "h-5 w-5" />
29+ </ Button >
30+ < Tooltip { ...args } > Print</ Tooltip >
31+ </ TooltipTrigger >
32+ </ div >
33+ ) ;
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import {
3+ Tooltip as AriaTooltip ,
4+ type TooltipProps as AriaTooltipProps ,
5+ OverlayArrow ,
6+ composeRenderProps ,
7+ } from 'react-aria-components' ;
8+ import { tv } from 'tailwind-variants' ;
9+
10+ export interface TooltipProps extends Omit < AriaTooltipProps , 'children' > {
11+ children : React . ReactNode ;
12+ }
13+
14+ const styles = tv ( {
15+ base : 'group rounded-lg border border-slate-800 bg-slate-700 px-3 py-1 text-sm text-white shadow-[inset_0_1px_0_0_theme(colors.gray.600)] drop-shadow-lg will-change-transform dark:border-white/10 dark:bg-slate-600 dark:shadow-none' ,
16+ variants : {
17+ isEntering : {
18+ true : 'duration-200 ease-out animate-in fade-in placement-left:slide-in-from-right-0.5 placement-right:slide-in-from-left-0.5 placement-top:slide-in-from-bottom-0.5 placement-bottom:slide-in-from-top-0.5' ,
19+ } ,
20+ isExiting : {
21+ true : 'duration-150 ease-in animate-out fade-out placement-left:slide-out-to-right-0.5 placement-right:slide-out-to-left-0.5 placement-top:slide-out-to-bottom-0.5 placement-bottom:slide-out-to-top-0.5' ,
22+ } ,
23+ } ,
24+ } ) ;
25+
26+ export function Tooltip ( { children, ...props } : TooltipProps ) {
27+ return (
28+ < AriaTooltip
29+ { ...props }
30+ offset = { 10 }
31+ className = { composeRenderProps ( props . className , ( className , renderProps ) =>
32+ styles ( { ...renderProps , className } ) ,
33+ ) }
34+ >
35+ < OverlayArrow >
36+ < svg
37+ width = { 8 }
38+ height = { 8 }
39+ viewBox = "0 0 8 8"
40+ className = "fill-slate-700 stroke-gray-800 group-placement-left:-rotate-90 group-placement-right:rotate-90 group-placement-bottom:rotate-180 dark:fill-slate-600 dark:stroke-white/10 forced-colors:fill-[Canvas] forced-colors:stroke-[ButtonBorder]"
41+ >
42+ < path d = "M0 0 L4 4 L8 0" />
43+ </ svg >
44+ </ OverlayArrow >
45+ { children }
46+ </ AriaTooltip >
47+ ) ;
48+ }
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ export * from './components/TextArea';
3131export * from './components/TextField' ;
3232export * from './components/ToggleButton' ;
3333export * from './components/ToggleButtonGroup' ;
34+ export * from './components/Tooltip' ;
3435export * from './components/UtahIdLogin' ;
3536export * from './contexts/FirebaseAnalyticsProvider' ;
3637export * from './contexts/FirebaseAppProvider' ;
You can’t perform that action at this time.
0 commit comments