Skip to content

Commit

Permalink
refactor: slightly DRY tooltip component
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpyon committed Oct 26, 2023
1 parent a91379c commit a15d186
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions packages/sanity/src/ui/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export interface TooltipProps extends UITooltipProps {
ref?: React.ForwardedRef<HTMLDivElement>
}

const TOOLTIP_DELAY_PROPS = {
open: 500,
}

/**
* Studio UI <Tooltip>.
*
Expand All @@ -20,16 +24,20 @@ export const Tooltip = forwardRef(function Tooltip(
) {
const {content, ...rest} = props

if (typeof content === 'string') {
return (
<UITooltip
content={<Text size={1} weight="medium">{content}</Text>}
delay={{open: 500}}
ref={ref}
{...rest}
/>
)
}

return <UITooltip delay={{open: 500}} ref={ref} content={content} {...rest} />
return (
<UITooltip
content={
typeof content === 'string' || typeof content === 'number' ? (
<Text size={1} weight="medium">
{content}
</Text>
) : (
content
)
}
delay={TOOLTIP_DELAY_PROPS}
ref={ref}
{...rest}
/>
)
})

0 comments on commit a15d186

Please sign in to comment.