const Example = () => {
return <Input shadow={2} _light={{
bg: 'coolGray.100'
}} _dark={{
bg: 'coolGray.800'
}} placeholder="Enter your name" />;
};
The Input component allows a user to provide input in a text field.
const Example = () => {
return <Box alignItems="center">
<Input mx="3" placeholder="Input" w="75%" maxWidth="300px" />
</Box>;
};
const Example = () => {
return <Center>
<Stack mt={3} space={4} w="75%" maxW="300px">
<Input size="xs" placeholder="xs Input" />
<Input size="sm" placeholder="sm Input" />
<Input size="md" placeholder="md Input" />
<Input size="lg" placeholder="lg Input" />
<Input size="xl" placeholder="xl Input" />
<Input size="2xl" placeholder="2xl Input" />
</Stack>
</Center>;
};
const Example = () => {
return <Center>
<Stack space={4} w="75%" maxW="300px">
<Input variant="outline" placeholder="Outline" />
<Input variant="filled" placeholder="Filled" />
<Input variant="underlined" placeholder="Underlined" />
<Input variant="unstyled" placeholder="Unstyled" />
<Input variant="rounded" placeholder="Round" />
</Stack>
</Center>;
};
const Example = () => {
return <Stack alignItems="center">
<InputGroup w={{
base: "70%",
md: "285"
}}>
<InputLeftAddon children={"https://"} />
<Input w={{
base: "70%",
md: "100%"
}} placeholder="nativebase" />
<InputRightAddon children={".io"} />
</InputGroup>
</Stack>;
};
const Example = () => {
const [show, setShow] = React.useState(false);
return <Stack space={4} w="100%" alignItems="center">
<Input w={{
base: "75%",
md: "25%"
}} InputLeftElement={<Icon as={<MaterialIcons name="person" />} size={5} ml="2" color="muted.400" />} placeholder="Name" />
<Input w={{
base: "75%",
md: "25%"
}} type={show ? "text" : "password"} InputRightElement={<Icon as={<MaterialIcons name={show ? "visibility" : "visibility-off"} />} size={5} mr="2" color="muted.400" onPress={() => setShow(!show)} />} placeholder="Password" />
</Stack>;
};
const Example = () => {
const [show, setShow] = React.useState(false);
const handleClick = () => setShow(!show);
return <Box alignItems="center">
<Input type={show ? "text" : "password"} w="75%" maxW="300px" py="0" InputRightElement={<Button size="xs" rounded="none" w="1/6" h="full" onPress={handleClick}>
{show ? "Hide" : "Show"}
</Button>} placeholder="Password" />
</Box>;
};
const Example = () => {
const [value, setValue] = React.useState("");
const handleChange = text => setValue(text);
return <Box alignItems="center">
<Input value={value} w="75%" maxW="300px" onChangeText={handleChange} placeholder="Value Controlled Input" />
</Box>;
};
const Example = () => {
return <Box alignItems="center">
<FormControl isInvalid w="75%" maxW="300px">
<FormControl.Label>Password</FormControl.Label>
<Input placeholder="Enter password" />
<FormControl.ErrorMessage leftIcon={<WarningOutlineIcon size="xs" />}>
Try different from previous passwords.
</FormControl.ErrorMessage>
</FormControl>
</Box>;
};
Input implements
,
,
,
,
,
,
,
,
,
If true, the input will indicate an error.
The variant of the input style to use.
If true, the input will be disabled.
If true, the input will be hovered.
If true, the input will be focused.
This will set aria-required="true" on web when passed in formcontrol.
If true, prevents the value of the input from being edited.
If true, the input element will span the full width of its parent
If given, adds the provided element to the left of the input.
If given, adds the provided element to the left of the input.
If given, adds the provided element to the right of the input.
If given, adds the provided element to the right of the input.
Using the type password, user can mask the input.
Ref to be passed to Icon's wrapper Box
Passed props will be applied on hovered state.
Passed props will be applied on focused state.
Passed props will be applied on disabled state.
Passed props will be applied on readOnly state.
Passed props will be applied on invalid state.
InputGroup implements
,
,
,
,
,
,
,
,
,
The variant of the input style to use.
The size of the input.
Type: ResponsiveValue<number | "full" | "sm" | "6" | "2xs" | "8" | "xs" | "12" | "md" | "16" | "xl" | "24" | "32" | "2" | "0.5" | "4" | "3" | "lg" | "1" | "2xl" | "10" | "20" | "64" | "0" | "px" | "container" | ... 28 more ... | (string & {})>
NativeBase ships with a default theme for each component. Check out the default theme of the input
.
Info:
We can easily extend the input component theme using extendTheme function as described in the documentation .