'use client'; import { createCheckbox } from '@gluestack-ui/core/checkbox/creator'; import { UIIcon } from '@gluestack-ui/core/icon/creator'; import type { VariantProps } from '@gluestack-ui/utils/nativewind-utils'; import { tva, withStyleContext } from '@gluestack-ui/utils/nativewind-utils'; import { styled } from 'nativewind'; import React from 'react'; import type { TextProps, ViewProps } from 'react-native'; import { Platform, Pressable, Text, View } from 'react-native'; const IndicatorWrapper = React.forwardRef< React.ComponentRef, ViewProps >(function IndicatorWrapper({ ...props }, ref) { return ; }); const LabelWrapper = React.forwardRef< React.ComponentRef, TextProps >(function LabelWrapper({ ...props }, ref) { return ; }); const StyledUIIcon = styled(UIIcon, { className: "style", }); const IconWrapper = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef >(function IconWrapper({ ...props }, ref) { return ; }); const SCOPE = 'CHECKBOX'; const UICheckbox = createCheckbox({ // @ts-expect-error : internal implementation for r-19/react-native-web Root: Platform.OS === 'web' ? withStyleContext(View, SCOPE) : withStyleContext(Pressable, SCOPE), Group: View, Icon: IconWrapper, Label: LabelWrapper, Indicator: IndicatorWrapper, }); const checkboxStyle = tva({ base: 'group/checkbox flex-row items-center justify-start gap-2 web:cursor-pointer data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50', }); const checkboxIndicatorStyle = tva({ base: 'justify-center items-center w-4 h-4 shrink-0 rounded border border-input dark:bg-input/30 shadow-xs web:outline-none web:data-[focus-visible=true]:ring-[3px] web:data-[focus-visible=true]:ring-ring/50 web:data-[focus-visible=true]:border-ring data-[checked=true]:bg-primary data-[checked=true]:border-primary dark:data-[checked=true]:bg-primary dark:data-[checked=true]:border-primary data-[invalid=true]:ring-destructive/20 data-[invalid=true]:border-destructive data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50', }); const checkboxLabelStyle = tva({ base: 'text-foreground text-sm font-medium font-body web:select-none web:cursor-pointer data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50', }); const checkboxIconStyle = tva({ base: 'text-primary-foreground fill-none h-3.5 w-3.5', }); const CheckboxGroup = UICheckbox.Group; type ICheckboxProps = React.ComponentPropsWithoutRef & VariantProps; const Checkbox = React.forwardRef< React.ComponentRef, ICheckboxProps >(function Checkbox({ className, ...props }, ref) { return ( ); }); type ICheckboxIndicatorProps = React.ComponentPropsWithoutRef< typeof UICheckbox.Indicator > & VariantProps; const CheckboxIndicator = React.forwardRef< React.ComponentRef, ICheckboxIndicatorProps >(function CheckboxIndicator({ className, ...props }, ref) { return ( ); }); type ICheckboxLabelProps = React.ComponentPropsWithoutRef< typeof UICheckbox.Label > & VariantProps; const CheckboxLabel = React.forwardRef< React.ComponentRef, ICheckboxLabelProps >(function CheckboxLabel({ className, ...props }, ref) { return ( ); }); type ICheckboxIconProps = React.ComponentPropsWithoutRef< typeof UICheckbox.Icon > & VariantProps; const CheckboxIcon = React.forwardRef< React.ComponentRef, ICheckboxIconProps >(function CheckboxIcon({ className, size, ...props }, ref) { if (typeof size === 'number') { return ( ); } else if ( (props.height !== undefined || props.width !== undefined) && size === undefined ) { return ( ); } return ( ); }); Checkbox.displayName = 'Checkbox'; CheckboxIndicator.displayName = 'CheckboxIndicator'; CheckboxLabel.displayName = 'CheckboxLabel'; CheckboxIcon.displayName = 'CheckboxIcon'; export { Checkbox, CheckboxGroup, CheckboxIcon, CheckboxIndicator, CheckboxLabel };