Skip to content

Commit

Permalink
migrate to passing a textAs prop
Browse files Browse the repository at this point in the history
  • Loading branch information
evanfrawley committed Aug 13, 2024
1 parent ad96a37 commit 85fc6ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
27 changes: 15 additions & 12 deletions apps/playground/app/sink/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,21 @@ export default function Sink() {
</Button>
</Tooltip>

<Tooltip content={
<DataList.Root my="1">
<DataList.Item>
<DataList.Label style={{ color: 'var(--gray-5)'}}>Name</DataList.Label>
<DataList.Value style={{ color: 'var(--gray-1)'}}>Susan Kare</DataList.Value>
</DataList.Item>
<DataList.Item>
<DataList.Label style={{ color: 'var(--gray-5)'}}>Email</DataList.Label>
<DataList.Value style={{ color: 'var(--gray-1)'}}>[email protected]</DataList.Value>
</DataList.Item>
</DataList.Root>
}>
<Tooltip
textAs="div"
content={
<DataList.Root my="1">
<DataList.Item>
<DataList.Label style={{ color: 'var(--gray-5)'}}>Name</DataList.Label>
<DataList.Value style={{ color: 'var(--gray-1)'}}>Susan Kare</DataList.Value>
</DataList.Item>
<DataList.Item>
<DataList.Label style={{ color: 'var(--gray-5)'}}>Email</DataList.Label>
<DataList.Value style={{ color: 'var(--gray-1)'}}>[email protected]</DataList.Value>
</DataList.Item>
</DataList.Root>
}
>
<Button variant="solid" size="1">
Non-string ReactNode
</Button>
Expand Down
3 changes: 3 additions & 0 deletions packages/radix-ui-themes/src/components/tooltip.props.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { widthPropDefs } from '../props/width.props.js';
import { textPropDefs } from './text.props.js';

import type { PropDef, GetPropDefTypes } from '../props/prop-def.js';

Expand All @@ -7,11 +8,13 @@ const tooltipPropDefs = {
width: widthPropDefs.width,
minWidth: widthPropDefs.minWidth,
maxWidth: { ...widthPropDefs.maxWidth, default: '360px' },
textAs: textPropDefs['as']
} satisfies {
width: PropDef<string>;
minWidth: PropDef<string>;
maxWidth: PropDef<string>;
content: PropDef<React.ReactNode>;
textAs: PropDef<string>;
};

type TooltipOwnProps = GetPropDefTypes<typeof tooltipPropDefs & typeof widthPropDefs>;
Expand Down
11 changes: 4 additions & 7 deletions packages/radix-ui-themes/src/components/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Tooltip = React.forwardRef<TooltipElement, TooltipProps>((props, forwarded
content,
container,
forceMount,
textAs,
...tooltipContentProps
} = extractProps(props, tooltipPropDefs);
const rootProps = { open, defaultOpen, onOpenChange, delayDuration, disableHoverableContent };
Expand All @@ -47,13 +48,9 @@ const Tooltip = React.forwardRef<TooltipElement, TooltipProps>((props, forwarded
ref={forwardedRef}
className={classNames('rt-TooltipContent', className)}
>
{typeof content === 'string' ? (
<Text as="p" className="rt-TooltipText" size="1">
{content}
</Text>
) : (
<>{content}</>
)}
<Text as={textAs ?? 'p'} className="rt-TooltipText" size="1">
{content}
</Text>
<TooltipPrimitive.Arrow className="rt-TooltipArrow" />
</TooltipPrimitive.Content>
</Theme>
Expand Down

0 comments on commit 85fc6ac

Please sign in to comment.