'use client' import { PrimitiveIcon, UIIcon } from '@gluestack-ui/icon' import type { VariantProps } from '@gluestack-ui/nativewind-utils' import { tva } from '@gluestack-ui/nativewind-utils/tva' import { useStyleContext, withStyleContext } from '@gluestack-ui/nativewind-utils/withStyleContext' import { createRadio } from '@gluestack-ui/radio' import { cssInterop } from 'nativewind' import { Circle } from 'phosphor-react-native' import * as PhosphorIcons from 'phosphor-react-native' import React, { ReactNode } from 'react' import { Pressable, View, ViewProps } from 'react-native' import Text from '../text' const SCOPE = 'Radio' const IndicatorWrapper = React.forwardRef, ViewProps & { states?: any }>( function IndicatorWrapper({ ...props }, ref) { const { size: parentSize } = useStyleContext(SCOPE) return ( {props.states.active && ( )} ) }, ) const UIRadio = createRadio({ Root: withStyleContext(Pressable, SCOPE) as ReturnType>, Group: View, Icon: UIIcon, Indicator: IndicatorWrapper, 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 items-center justify-start', variants: { size: { md: 'gap-2', lg: 'gap-2', }, }, }) const radioGroupStyle = tva({ base: 'gap-2', }) const radioIconStyle = tva({ base: 'items-center justify-center rounded-full fill-selector-foreground', parentVariants: { size: { md: 'size-[var(--radio-icon-size)]', lg: 'size-[var(--lg-radio-icon-size)]', }, }, }) const radioIndicatorStyle = tva({ base: 'items-center justify-center rounded-full border-selector-border bg-selector-background data-[checked=true]:border-selector-border-active data-[checked=true]:bg-selector-accent-true data-[invalid=true]:border-destructive-border data-[active=true]:data-[checked=true]:bg-selector-accent-onTap data-[active=true]:data-[checked=true]:border-selector-border-active data-[active=true]:!border-selector-border-onTap data-[disabled=true]:border-disabled-border data-[disabled=true]:bg-disabled', parentVariants: { size: { md: 'size-[var(--radio-size)] border-[length:var(--radio-border-size)]', lg: 'size-[var(--lg-radio-size)] border-[length:var(--lg-radio-border-size)]', }, }, }) const radioLabelStyle = tva({ base: '', }) const radioOnTapStyle = tva({ base: 'absolute rounded-full bg-selector-accent-onTap opacity-5', parentVariants: { size: { lg: '-left-[calc(var(--lg-radio-onTap-size)/2-var(--lg-radio-size)/2)] -top-[calc(var(--lg-radio-onTap-size)/2-var(--lg-radio-size)/2)] size-[var(--lg-radio-onTap-size)]', md: '-left-[calc(var(--radio-onTap-size)/2-var(--radio-size)/2)] -top-[calc(var(--radio-onTap-size)/2-var(--radio-size)/2)] size-[var(--radio-onTap-size)]', }, }, }) type IRadioProps = Omit, 'context'> & VariantProps const RadioWrapper = React.forwardRef, IRadioProps>(function Radio( { className, size = 'md', ...props }, ref, ) { return }) type IRadioGroupProps = React.ComponentProps & VariantProps const RadioGroup = React.forwardRef, IRadioGroupProps>(function RadioGroup( { className, ...props }, ref, ) { return }) type IRadioIndicatorProps = React.ComponentProps & VariantProps const RadioIndicator = React.forwardRef, IRadioIndicatorProps>( function RadioIndicator({ className, ...props }, ref) { const { size } = useStyleContext(SCOPE) return ( ) }, ) type IRadioLabelProps = React.ComponentProps & VariantProps const RadioLabel = React.forwardRef, IRadioLabelProps>(function RadioLabel( { className, children, ...props }, ref, ) { const { size } = useStyleContext(SCOPE) return ( {typeof children === 'string' ? ( {children} ) : ( children )} ) }) type IRadioIconProps = React.ComponentProps & VariantProps & { height?: number width?: number weight?: PhosphorIcons.IconWeight } const RadioIcon = React.forwardRef, 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 ( ) }) const Radio: React.FC = ({ label, ...props }) => { return ( {label && {label}} ) } RadioWrapper.displayName = 'RadioWrapper' RadioGroup.displayName = 'RadioGroup' RadioIndicator.displayName = 'RadioIndicator' RadioLabel.displayName = 'RadioLabel' RadioIcon.displayName = 'RadioIcon' export { Radio, RadioWrapper, RadioGroup, RadioIndicator, RadioLabel, RadioIcon }