forked from GeekyAnts/NativeBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added example for other form elements
- Loading branch information
Showing
9 changed files
with
315 additions
and
30 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
example/storybook/stories/communityIntegration/ReactHookForm/NumberInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
VStack, | ||
Button, | ||
FormControl, | ||
FormLabel, | ||
FormErrorMessage, | ||
NumberInput, | ||
NumberInputField, | ||
NumberInputStepper, | ||
NumberIncrementStepper, | ||
NumberDecrementStepper, | ||
} from 'native-base'; | ||
import React from 'react'; | ||
import { useForm, Controller } from 'react-hook-form'; | ||
|
||
interface IFormInput { | ||
version: boolean; | ||
} | ||
|
||
export default function () { | ||
const { control, handleSubmit, errors } = useForm<IFormInput>(); | ||
const onSubmit = (data: IFormInput) => { | ||
console.log('submiting with ', data); | ||
}; | ||
return ( | ||
<VStack width="80%" space={4}> | ||
<FormControl isRequired isInvalid={'version' in errors}> | ||
<FormLabel>Current Native Base Version:</FormLabel> | ||
<Controller | ||
control={control} | ||
render={({ onChange, value }) => ( | ||
<NumberInput | ||
onChange={(value: any) => onChange(value)} | ||
defaultValue={value} | ||
> | ||
<NumberInputField /> | ||
<NumberInputStepper> | ||
<NumberIncrementStepper /> | ||
<NumberDecrementStepper /> | ||
</NumberInputStepper> | ||
</NumberInput> | ||
)} | ||
name="version" | ||
rules={{ required: 'Field is required' }} | ||
defaultValue={3} | ||
/> | ||
<FormErrorMessage>{errors.version?.message}</FormErrorMessage> | ||
</FormControl> | ||
<Button onPress={handleSubmit(onSubmit)} colorScheme="pink"> | ||
Submit | ||
</Button> | ||
</VStack> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
example/storybook/stories/communityIntegration/ReactHookForm/PinInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
VStack, | ||
Button, | ||
FormControl, | ||
FormLabel, | ||
FormErrorMessage, | ||
PinInput, | ||
PinInputField, | ||
} from 'native-base'; | ||
import React from 'react'; | ||
import { useForm, Controller } from 'react-hook-form'; | ||
|
||
interface IFormInput { | ||
otp: string; | ||
} | ||
|
||
export default function () { | ||
const { control, handleSubmit, errors } = useForm<IFormInput>(); | ||
const onSubmit = (data: IFormInput) => { | ||
console.log('submiting with ', data); | ||
}; | ||
return ( | ||
<VStack width="80%" space={4}> | ||
<FormControl isRequired isInvalid={'otp' in errors}> | ||
<FormLabel>OTP:</FormLabel> | ||
<Controller | ||
control={control} | ||
render={({ onChange, value }) => ( | ||
<PinInput onChange={(value: any) => onChange(value)} value={value}> | ||
<PinInputField /> | ||
<PinInputField /> | ||
<PinInputField /> | ||
<PinInputField /> | ||
</PinInput> | ||
)} | ||
name="otp" | ||
rules={{ required: 'Field is required', minLength: 4, maxLength: 4 }} | ||
/> | ||
<FormErrorMessage>{errors.otp?.message}</FormErrorMessage> | ||
</FormControl> | ||
<Button onPress={handleSubmit(onSubmit)} colorScheme="pink"> | ||
Submit | ||
</Button> | ||
</VStack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
example/storybook/stories/communityIntegration/ReactHookForm/Select.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { | ||
VStack, | ||
Button, | ||
FormControl, | ||
FormLabel, | ||
FormErrorMessage, | ||
Select, | ||
Icon, | ||
} from 'native-base'; | ||
import React from 'react'; | ||
import { useForm, Controller } from 'react-hook-form'; | ||
|
||
interface IFormInput { | ||
language: number; | ||
} | ||
|
||
export default function () { | ||
const { control, handleSubmit, errors } = useForm<IFormInput>(); | ||
const onSubmit = (data: IFormInput) => { | ||
console.log('submiting with ', data); | ||
}; | ||
return ( | ||
<VStack width="80%" space={4}> | ||
<FormControl isRequired isInvalid={'language' in errors}> | ||
<FormLabel>Fav language:</FormLabel> | ||
<Controller | ||
control={control} | ||
render={({ onChange, value }) => ( | ||
<Select | ||
placeholder="Pick language" | ||
selectedValue={value} | ||
width={150} | ||
onValueChange={(itemValue: string) => { | ||
onChange(itemValue); | ||
}} | ||
selectedItemBg={'teal.400'} | ||
dropdownOpenIcon={ | ||
<Icon name="arrow-drop-up" type="MaterialIcons" size={6} /> | ||
} | ||
dropdownCloseIcon={ | ||
<Icon name="arrow-drop-down" type="MaterialIcons" size={6} /> | ||
} | ||
> | ||
<Select.Item label="JavaScript" value="js" /> | ||
<Select.Item label="TypeScript" value="ts" /> | ||
<Select.Item label="Java" value="java" /> | ||
</Select> | ||
)} | ||
name="language" | ||
rules={{ required: 'Field is required' }} | ||
defaultValue="js" | ||
/> | ||
<FormErrorMessage>{errors.language?.message}</FormErrorMessage> | ||
</FormControl> | ||
<Button onPress={handleSubmit(onSubmit)} colorScheme="pink"> | ||
Submit | ||
</Button> | ||
</VStack> | ||
); | ||
} |
49 changes: 49 additions & 0 deletions
49
example/storybook/stories/communityIntegration/ReactHookForm/Slider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
VStack, | ||
Button, | ||
FormControl, | ||
FormLabel, | ||
FormErrorMessage, | ||
Slider, | ||
SliderTrack, | ||
SliderFilledTrack, | ||
SliderThumb, | ||
} from 'native-base'; | ||
import React from 'react'; | ||
import { useForm, Controller } from 'react-hook-form'; | ||
|
||
interface IFormInput { | ||
like: number; | ||
} | ||
|
||
export default function () { | ||
const { control, handleSubmit, errors } = useForm<IFormInput>(); | ||
const onSubmit = (data: IFormInput) => { | ||
console.log('submiting with ', data); | ||
}; | ||
return ( | ||
<VStack width="80%" space={4}> | ||
<FormControl isRequired isInvalid={'like' in errors}> | ||
<FormLabel>Amount you like NativeBase</FormLabel> | ||
<Controller | ||
control={control} | ||
render={({ onChange, value }) => ( | ||
<Slider onChange={(value) => onChange(value)} defaultValue={value}> | ||
<SliderTrack> | ||
<SliderFilledTrack /> | ||
</SliderTrack> | ||
<SliderThumb /> | ||
</Slider> | ||
)} | ||
name="like" | ||
rules={{ required: 'Field is required', minLength: 3 }} | ||
defaultValue={100} | ||
/> | ||
<FormErrorMessage>{errors.like?.message}</FormErrorMessage> | ||
</FormControl> | ||
<Button onPress={handleSubmit(onSubmit)} colorScheme="pink"> | ||
Submit | ||
</Button> | ||
</VStack> | ||
); | ||
} |
43 changes: 43 additions & 0 deletions
43
example/storybook/stories/communityIntegration/ReactHookForm/Switch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
VStack, | ||
Button, | ||
FormControl, | ||
FormLabel, | ||
FormErrorMessage, | ||
Switch, | ||
} from 'native-base'; | ||
import React from 'react'; | ||
import { useForm, Controller } from 'react-hook-form'; | ||
|
||
interface IFormInput { | ||
rememberMe: boolean; | ||
} | ||
|
||
export default function () { | ||
const { control, handleSubmit, errors } = useForm<IFormInput>(); | ||
const onSubmit = (data: IFormInput) => { | ||
console.log('submiting with ', data); | ||
}; | ||
return ( | ||
<VStack width="80%" space={4}> | ||
<FormControl isInvalid={'rememberMe' in errors}> | ||
<FormLabel>Remenber me:</FormLabel> | ||
<Controller | ||
control={control} | ||
render={({ onChange, value }) => ( | ||
<Switch | ||
onToggle={(value: boolean) => onChange(value)} | ||
isChecked={value} | ||
/> | ||
)} | ||
name="rememberMe" | ||
defaultValue={true} | ||
/> | ||
<FormErrorMessage>{errors.rememberMe?.message}</FormErrorMessage> | ||
</FormControl> | ||
<Button onPress={handleSubmit(onSubmit)} colorScheme="pink"> | ||
Submit | ||
</Button> | ||
</VStack> | ||
); | ||
} |
45 changes: 45 additions & 0 deletions
45
example/storybook/stories/communityIntegration/ReactHookForm/Textarea.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
VStack, | ||
Button, | ||
FormControl, | ||
FormLabel, | ||
FormErrorMessage, | ||
TextArea, | ||
} from 'native-base'; | ||
import React from 'react'; | ||
import { useForm, Controller } from 'react-hook-form'; | ||
|
||
interface IFormInput { | ||
thought: string; | ||
} | ||
|
||
export default function () { | ||
const { control, handleSubmit, errors } = useForm<IFormInput>(); | ||
const onSubmit = (data: IFormInput) => { | ||
console.log('submiting with ', data); | ||
}; | ||
return ( | ||
<VStack width="80%" space={4}> | ||
<FormControl isRequired isInvalid={'thought' in errors}> | ||
<FormLabel>What do you think?</FormLabel> | ||
<Controller | ||
control={control} | ||
render={({ onChange, value }) => ( | ||
<TextArea | ||
placeholder="TextArea" | ||
onChangeText={(value) => onChange(value)} | ||
defaultValue={value} | ||
/> | ||
)} | ||
name="thought" | ||
rules={{ required: 'Field is required', minLength: 3 }} | ||
defaultValue="I love Nativebase." | ||
/> | ||
<FormErrorMessage>{errors.thought?.message}</FormErrorMessage> | ||
</FormControl> | ||
<Button onPress={handleSubmit(onSubmit)} colorScheme="pink"> | ||
Submit | ||
</Button> | ||
</VStack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters