Skip to content

Commit c7dbbbc

Browse files
feat: forward width prop from Tooltip to Popover when variant="popover" (#1868)
* feat: add 'fit' width variant to Popover component Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * chore: add changeset for popover fit width variant Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * feat: forward width prop from Tooltip to Popover when variant='popover' Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * chore: add changeset for tooltip width prop forwarding Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 83230cf commit c7dbbbc

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@launchpad-ui/components': minor
3+
---
4+
5+
Forward `width` prop from Tooltip to Popover styles when `variant="popover"`

packages/components/src/Tooltip.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
ContextValue,
66
TooltipTriggerComponentProps,
77
} from 'react-aria-components';
8+
import type { PopoverProps } from './Popover';
89

910
import { cva } from 'class-variance-authority';
1011
import { createContext } from 'react';
@@ -20,6 +21,7 @@ import { useLPContextProps } from './utils';
2021

2122
interface TooltipProps extends AriaTooltipProps, VariantProps<typeof tooltipStyles> {
2223
ref?: Ref<HTMLDivElement>;
24+
width?: PopoverProps['width'];
2325
}
2426
interface TooltipTriggerProps extends TooltipTriggerComponentProps {}
2527

@@ -44,7 +46,7 @@ const tooltipStyles = cva(styles.base, {
4446
*/
4547
const Tooltip = ({ ref, ...props }: TooltipProps) => {
4648
[props, ref] = useLPContextProps(props, ref, TooltipContext);
47-
const { variant = 'default' } = props;
49+
const { variant = 'default', width = 'default' } = props;
4850

4951
return (
5052
<AriaTooltip
@@ -54,7 +56,13 @@ const Tooltip = ({ ref, ...props }: TooltipProps) => {
5456
{...props}
5557
ref={ref}
5658
className={composeRenderProps(props.className, (className, renderProps) =>
57-
tooltipStyles({ ...renderProps, variant, className }),
59+
variant === 'popover'
60+
? tooltipStyles({
61+
...renderProps,
62+
variant: null,
63+
className: popoverStyles({ width, className }),
64+
})
65+
: tooltipStyles({ ...renderProps, variant, className }),
5866
)}
5967
data-trigger={variant === 'popover' ? 'DialogTrigger' : undefined}
6068
/>

packages/components/stories/Tooltip.stories.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,17 @@ export const Popover: Story = {
8484
},
8585
play,
8686
};
87+
88+
export const PopoverFitWidth: Story = {
89+
render: (args) => {
90+
return (
91+
<TooltipTrigger>
92+
<Button>Trigger</Button>
93+
<Tooltip variant="popover" width="fit" {...args}>
94+
Message
95+
</Tooltip>
96+
</TooltipTrigger>
97+
);
98+
},
99+
play,
100+
};

0 commit comments

Comments
 (0)