import { BNBChainIcon } from '@bnb-chain/icons'; import { Button, ComponentWithAs, FormErrorMessage, FormHelperText, FormLabel, Input, InputGroup, InputLeftElement, InputProps, InputRightElement, Skeleton, StackProps, useColorMode, VStack, } from '@chakra-ui/react'; import { ComponentStory, Meta } from '@storybook/react'; import { useEffect, useMemo, useState } from 'react'; import { useValidateURL, Validation } from '../../hooks'; import { theme } from '../../modules/theme'; import { FormControl, FormWarningMessage } from '../FormControl'; const INPUT_SIZES = ['sm', 'md', 'lg', 'xl'] as const; export default { title: 'Components/Atoms/Input', component: Input, } as Meta; const Stack = (props: StackProps) => { return ; }; const Template: ComponentStory = () => { return ( ); }; export const Default: ComponentStory> = Template.bind({}); export const Sizes = () => { return ( {INPUT_SIZES.map((it) => { return ( ); })} ); }; export const States = () => { return ( Disabled Input Helper text. Loading Input Helper text. Input With Warning Helper text. Warning message. Input With Error Helper text. Error message. ); }; export const WithLeftElement = () => { const { colorMode } = useColorMode(); return ( ); }; export const WithRightElement = () => { return ( ); }; export const WithValidation = () => { const [isPristine, setIsPristine] = useState(true); const [url, setURL] = useState<{ value: string; validation: Validation; }>({ value: '', validation: { isValid: false, }, }); const validate = useValidateURL(); useEffect(() => { if (!isPristine) { return; } setIsPristine(!url.value); }, [url.value, isPristine]); const isInvalid = useMemo(() => { return !isPristine && !!url.validation && !url.validation.isValid; }, [isPristine, url.validation]); return ( Label setURL({ value: evt.target.value, validation: validate({ value: evt.target.value }), }) } placeholder="Enter a URL" /> Helper text. {url.validation?.errors?.[0]} ); };