Skip to content

Commit

Permalink
enh(sparkles) - forwardRef Chip and Tooltip (#9244)
Browse files Browse the repository at this point in the history
* enh: turn Tooltip and Chip into forwardRefs

* chore: bump sparkles version
  • Loading branch information
aubin-tchoi authored Dec 10, 2024
1 parent d03679b commit 9d43958
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 41 deletions.
41 changes: 10 additions & 31 deletions sparkle/src/components/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,18 @@ const chipVariants = cva("s-inline-flex s-box-border s-items-center", {
},
});

export function Chip({
size,
color,
label,
children,
className,
isBusy,
icon,
}: ChipProps) {
return (
const Chip = React.forwardRef<HTMLDivElement, ChipProps>(
(
{ size, color, label, children, className, isBusy, icon }: ChipProps,
ref
) => (
<div
className={cn(
chipVariants({ size, background: color, text: color }),
className
)}
aria-label={label}
ref={ref}
>
{icon && <Icon visual={icon} size={size as IconProps["size"]} />}
{label && (
Expand All @@ -107,26 +103,9 @@ export function Chip({
)}
{children}
</div>
);
}
)
);

interface ListChipProps {
children: ReactNode;
className?: string;
isWrapping?: boolean;
}
Chip.displayName = "Chip";

Chip.List = function ({ children, className, isWrapping }: ListChipProps) {
return (
<div className={cn("s-flex", className)}>
<div
className={cn(
"s-flex s-flex-row s-gap-2",
isWrapping ? "s-flex-wrap" : ""
)}
>
{children}
</div>
</div>
);
};
export { Chip };
20 changes: 10 additions & 10 deletions sparkle/src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ interface TooltipProps extends TooltipContentProps {
triggerAsChild?: boolean;
}

function Tooltip({
trigger,
tooltipTriggerAsChild = false,
label,
...props
}: TooltipProps) {
return (
const Tooltip = React.forwardRef<HTMLDivElement, TooltipProps>(
(
{ trigger, tooltipTriggerAsChild = false, label, ...props }: TooltipProps,
ref
) => (
<TooltipProvider>
<TooltipRoot>
<TooltipTrigger asChild={tooltipTriggerAsChild}>
{trigger}
</TooltipTrigger>
<TooltipContent {...props}>{label}</TooltipContent>
<TooltipContent {...props} ref={ref}>
{label}
</TooltipContent>
</TooltipRoot>
</TooltipProvider>
);
}
)
);

TooltipContent.displayName = TooltipPrimitive.Content.displayName;

Expand Down

0 comments on commit 9d43958

Please sign in to comment.