import * as RadioGroupPrimitive from "@radix-ui/react-radio-group"; import { cva, VariantProps } from "class-variance-authority"; import * as React from "react"; import { Icon } from "@sparkle/components/Icon"; import { Label } from "@sparkle/components/Label"; import { Tooltip } from "@sparkle/components/Tooltip"; import { cn } from "@sparkle/lib/utils"; export const radioStyles = cva( cn( "s-aspect-square s-rounded-full s-border s-transition s-duration-200 s-ease-in-out", "s-border-border-dark dark:s-border-primary-500", "s-bg-background dark:s-bg-background-night", "s-text-foreground dark:s-text-foreground-night", "s-flex s-items-center s-justify-center", "focus-visible:s-outline-none focus-visible:s-ring-2 focus-visible:s-ring-offset-2 focus-visible:s-ring-ring", "hover:s-border-highlight hover:s-bg-highlight-50 dark:hover:s-bg-highlight-100-night hover:dark:s-border-highlight", "disabled:s-cursor-not-allowed disabled:s-opacity-50 disabled:s-border-border-dark disabled:dark:s-border-border-dark-night disabled:s-bg-background dark:disabled:s-bg-background-night", "checked:s-ring-0", "checked:s-bg-highlight-500 dark:checked:s-bg-highlight-500-night" ), { variants: { size: { xs: "s-h-4 s-w-4", sm: "s-h-5 s-w-5", }, }, defaultVariants: { size: "xs", }, } ); export const radioIndicatorStyles = cva( "s-bg-primary dark:s-bg-primary-night s-flex s-items-center s-justify-center s-rounded-full", { variants: { size: { xs: "s-h-2 s-w-2", sm: "s-h-2.5 s-w-2.5", }, }, defaultVariants: { size: "xs", }, } ); const RadioGroup = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => { return ( ); }); RadioGroup.displayName = RadioGroupPrimitive.Root.displayName; interface RadioGroupItemProps extends Omit< React.ComponentPropsWithoutRef, "children" >, VariantProps { tooltipMessage?: string; label: string; labelProps?: Omit, "children">; icon?: React.ComponentType; } const RadioGroupItem = React.forwardRef< React.ElementRef, RadioGroupItemProps >( ( { tooltipMessage, className, icon, size, label, labelProps, id, ...props }, ref ) => { const renderIcon = (visual: React.ComponentType, extraClass = "") => ( ); const item = ( ); const wrappedItem = (
{tooltipMessage ? ( ) : ( item )} {icon && renderIcon(icon)}
); return
{wrappedItem}
; } ); type IconPosition = "start" | "center" | "end"; interface RadioGroupCustomItemProps extends React.ComponentPropsWithoutRef, VariantProps { iconPosition?: IconPosition; customItem: React.ReactNode; children?: React.ReactNode; } const RadioGroupCustomItem = React.forwardRef< React.ElementRef, RadioGroupCustomItemProps >( ( { className, size, customItem, iconPosition = "center", children, id, ...props }, ref ) => { const item = ( ); return (
{item} {customItem}
{children}
); } ); export { RadioGroup, RadioGroupCustomItem, RadioGroupItem };