'use client'; import React from 'react'; import { createRadio } from '@gluestack-ui/radio'; import { Pressable, View, Platform, Text } from 'react-native'; import { tva } from '@gluestack-ui/nativewind-utils/tva'; import { withStyleContext, useStyleContext, } from '@gluestack-ui/nativewind-utils/withStyleContext'; import { cssInterop } from 'nativewind'; import type { VariantProps } from '@gluestack-ui/nativewind-utils'; import { PrimitiveIcon, UIIcon } from '@gluestack-ui/icon'; const SCOPE = 'Radio'; const UIRadio = createRadio({ Root: (Platform.OS === 'web' ? withStyleContext(View, SCOPE) : withStyleContext(Pressable, SCOPE)) as ReturnType< typeof withStyleContext >, Group: View, Icon: UIIcon, Indicator: View, Label: Text, }); cssInterop(PrimitiveIcon, { className: { target: 'style', nativeStyleToProp: { height: true, width: true, fill: true, color: 'classNameColor', stroke: true, }, }, }); const radioStyle = tva({ base: 'group/radio flex-row justify-start items-center web:cursor-pointer data-[disabled=true]:web:cursor-not-allowed', variants: { size: { sm: 'gap-1.5', md: 'gap-2', lg: 'gap-2', }, }, }); const radioGroupStyle = tva({ base: 'gap-2', }); const radioIconStyle = tva({ base: 'rounded-full justify-center items-center text-primary-800 fill-primary-800', parentVariants: { size: { sm: 'h-[9px] w-[9px]', md: 'h-3 w-3', lg: 'h-4 w-4', }, }, }); const radioIndicatorStyle = tva({ base: 'justify-center items-center bg-transparent border-outline-400 border-2 rounded-full data-[focus-visible=true]:web:outline-2 data-[focus-visible=true]:web:outline-primary-700 data-[focus-visible=true]:web:outline data-[checked=true]:border-primary-600 data-[checked=true]:bg-transparent data-[hover=true]:border-outline-500 data-[hover=true]:bg-transparent data-[hover=true]:data-[checked=true]:bg-transparent data-[hover=true]:data-[checked=true]:border-primary-700 data-[hover=true]:data-[invalid=true]:border-error-700 data-[hover=true]:data-[disabled=true]:opacity-40 data-[hover=true]:data-[disabled=true]:border-outline-400 data-[hover=true]:data-[disabled=true]:data-[invalid=true]:border-error-400 data-[active=true]:bg-transparent data-[active=true]:border-primary-800 data-[invalid=true]:border-error-700 data-[disabled=true]:opacity-40 data-[disabled=true]:data-[checked=true]:border-outline-400 data-[disabled=true]:data-[checked=true]:bg-transparent data-[disabled=true]:data-[invalid=true]:border-error-400', parentVariants: { size: { sm: 'h-4 w-4', md: 'h-5 w-5', lg: 'h-6 w-6', }, }, }); const radioLabelStyle = tva({ base: 'text-typography-600 data-[checked=true]:text-typography-900 data-[hover=true]:text-typography-900 data-[hover=true]:data-[disabled=true]:text-typography-600 data-[hover=true]:data-[disabled=true]:data-[checked=true]:text-typography-900 data-[active=true]:text-typography-900 data-[active=true]:data-[checked=true]:text-typography-900 data-[disabled=true]:opacity-40 web:select-none', parentVariants: { size: { '2xs': 'text-2xs', 'xs': 'text-xs', 'sm': 'text-sm', 'md': 'text-base', 'lg': 'text-lg', 'xl': 'text-xl', '2xl': 'text-2xl', '3xl': 'text-3xl', '4xl': 'text-4xl', '5xl': 'text-5xl', '6xl': 'text-6xl', }, }, }); type IRadioProps = Omit, 'context'> & VariantProps; const Radio = React.forwardRef, IRadioProps>( function Radio({ className, size = 'md', ...props }, ref) { return ( ); } ); type IRadioGroupProps = React.ComponentProps & VariantProps; const RadioGroup = React.forwardRef< React.ComponentRef, IRadioGroupProps >(function RadioGroup({ className, ...props }, ref) { return ( ); }); type IRadioIndicatorProps = React.ComponentProps & VariantProps; const RadioIndicator = React.forwardRef< React.ComponentRef, IRadioIndicatorProps >(function RadioIndicator({ className, ...props }, ref) { const { size } = useStyleContext(SCOPE); return ( ); }); type IRadioLabelProps = React.ComponentProps & VariantProps; const RadioLabel = React.forwardRef< React.ComponentRef, IRadioLabelProps >(function RadioLabel({ className, ...props }, ref) { const { size } = useStyleContext(SCOPE); return ( ); }); type IRadioIconProps = React.ComponentProps & VariantProps & { height?: number; width?: number; }; const RadioIcon = React.forwardRef< React.ComponentRef, IRadioIconProps >(function RadioIcon({ className, size, ...props }, ref) { const { size: parentSize } = useStyleContext(SCOPE); if (typeof size === 'number') { return ( ); } else if ( (props.height !== undefined || props.width !== undefined) && size === undefined ) { return ( ); } return ( ); }); Radio.displayName = 'Radio'; RadioGroup.displayName = 'RadioGroup'; RadioIndicator.displayName = 'RadioIndicator'; RadioLabel.displayName = 'RadioLabel'; RadioIcon.displayName = 'RadioIcon'; export { Radio, RadioGroup, RadioIndicator, RadioLabel, RadioIcon };