'use client'; import { createButton } from '@gluestack-ui/core/button/creator'; import { UIIcon } from '@gluestack-ui/core/icon/creator'; import { tva, useStyleContext, withStyleContext, type VariantProps, } from '@gluestack-ui/utils/nativewind-utils'; import { styled } from 'nativewind'; import React from 'react'; import { ActivityIndicator, Pressable, Text, View } from 'react-native'; const SCOPE = 'BUTTON'; const Root = withStyleContext(Pressable, SCOPE); const StyledUIIcon = styled(UIIcon, { className: "style", }); const UIButton = createButton({ Root: Root, Text, Group: View, Spinner: ActivityIndicator, Icon: StyledUIIcon, }); const buttonStyle = tva({ base: 'rounded-md flex-row items-center justify-center data-[focus-visible=true]:web:outline-none data-[focus-visible=true]:web:ring-2 data-[disabled=true]:opacity-40 gap-2 h-fit', variants: { variant: { default: 'bg-primary data-[hover=true]:bg-primary/90 data-[active=true]:bg-primary/90', destructive: 'bg-destructive data-[hover=true]:bg-destructive/90 data-[active=true]:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60', outline: 'border border-border bg-background shadow-xs data-[hover=true]:bg-accent data-[active=true]:bg-accent dark:bg-input/[0.045] dark:border-border/90 dark:data-[hover=true]:bg-input/[0.075] dark:data-[active=true]:bg-input/[0.075]', secondary: 'bg-secondary text-secondary-foreground data-[hover=true]:bg-secondary/80 data-[active=true]:bg-secondary/80', ghost: 'data-[hover=true]:bg-accent data-[active=true]:bg-accent dark:data-[hover=true]:bg-accent/50 dark:data-[active=true]:bg-accent/50', link: 'text-primary underline-offset-4 data-[hover=true]:underline data-[active=true]:underline', }, size: { default: 'px-4 py-2', sm: 'min-h-8 rounded-md px-3 text-xs', lg: 'min-h-10 rounded-md px-8', icon: 'min-h-9 min-w-9', }, }, }); const buttonTextStyle = tva({ base: 'web:select-none font-sans', parentVariants: { variant: { default: 'text-primary-foreground', destructive: 'text-white', outline: 'text-foreground data-[hover=true]:text-accent-foreground data-[active=true]:text-accent-foreground', secondary: 'text-secondary-foreground', ghost: 'text-foreground ', link: 'text-primary data-[hover=true]:underline data-[active=true]:underline', }, size: { default: 'text-sm', sm: 'text-xs', lg: 'text-sm', icon: 'text-sm', }, }, }); const buttonSpinnerStyle = tva({ base: '', parentVariants: { size: { default: 'h-4 w-4', sm: 'h-3 w-3', lg: 'h-5 w-5', icon: 'h-4 w-4', }, }, }); const buttonIconStyle = tva({ base: 'fill-none pointer-events-none shrink-0', parentVariants: { variant: { default: 'text-primary-foreground', destructive: 'text-white', outline: 'text-foreground data-[hover=true]:text-accent-foreground data-[active=true]:text-accent-foreground', secondary: 'text-secondary-foreground', ghost: 'text-foreground data-[hover=true]:text-accent-foreground data-[active=true]:text-accent-foreground', link: 'text-primary', }, size: { default: 'h-4 w-4', sm: 'h-3 w-3', lg: 'h-5 w-5', icon: 'h-4 w-4', }, }, }); const buttonGroupStyle = tva({ base: '', variants: { space: { 'xs': 'gap-1', 'sm': 'gap-2', 'md': 'gap-3', 'lg': 'gap-4', 'xl': 'gap-5', '2xl': 'gap-6', '3xl': 'gap-7', '4xl': 'gap-8', }, isAttached: { true: 'gap-0', }, flexDirection: { 'row': 'flex-row', 'column': 'flex-col', 'row-reverse': 'flex-row-reverse', 'column-reverse': 'flex-col-reverse', }, }, }); type IButtonProps = Omit< React.ComponentPropsWithoutRef, 'context' > & VariantProps & { className?: string }; const Button = React.forwardRef< React.ElementRef, IButtonProps >(({ className, variant = 'default', size = 'default', ...props }, ref) => { return ( ); }); type IButtonTextProps = React.ComponentPropsWithoutRef & VariantProps & { className?: string }; const ButtonText = React.forwardRef< React.ElementRef, IButtonTextProps >(({ className, size, ...props }, ref) => { const { size: parentSize, variant: parentVariant } = useStyleContext(SCOPE); return ( ); }); const ButtonSpinner = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => { const { size: parentSize } = useStyleContext(SCOPE); return ; }); type IButtonIcon = React.ComponentPropsWithoutRef & VariantProps & { className?: string | undefined; as?: React.ElementType; height?: number; width?: number; }; const ButtonIcon = React.forwardRef< React.ElementRef, IButtonIcon >(({ className, size, ...props }, ref) => { const { size: parentSize, variant: parentVariant } = useStyleContext(SCOPE); if (typeof size === 'number') { return ( ); } else if ( (props.height !== undefined || props.width !== undefined) && size === undefined ) { return ( ); } return ( ); }); type IButtonGroupProps = React.ComponentPropsWithoutRef & VariantProps; const ButtonGroup = React.forwardRef< React.ElementRef, IButtonGroupProps >( ( { className, space = 'md', isAttached = false, flexDirection = 'column', ...props }, ref ) => { return ( ); } ); Button.displayName = 'Button'; ButtonText.displayName = 'ButtonText'; ButtonSpinner.displayName = 'ButtonSpinner'; ButtonIcon.displayName = 'ButtonIcon'; ButtonGroup.displayName = 'ButtonGroup'; export { Button, ButtonGroup, ButtonIcon, ButtonSpinner, ButtonText };