Input

The `Input` component is a component that is used to get user input in a text field.

Import#

import { Input } from "@nature-ui/core";

Usage#

Here's a basic usage example of the Input component:

<Input placeholder="Basic usage" />

Changing the size of the Input#

The Input component comes in four sizes. The default is md.

  • sm (32px)
  • md (40px)
  • lg (48px)
<Stack col>
<Input placeholder="small size" size="sm" />
<Input placeholder="medium size" size="md" />
<Input placeholder="large size" size="lg" />
</Stack>

Changing the appearance of the input#

The input component comes in 4 variants: outline, unstyled, flushed, and filled. Pass the variant prop and set it to one of these values.

<Stack col>
<Input variant="outline" placeholder="Outline" />
<Input variant="filled" placeholder="Filled" />
<Input variant="flushed" placeholder="Flushed" />
<Input variant="unstyled" placeholder="Unstyled" />
</Stack>

Left and Right Addons#

Add the addonLeft and addonRight to include an addon on the left and or right of the input element.

<Stack col>
<Input
placeholder="your-website"
defaultValue="divinehycenth"
addonLeft="https://"
addonRight=".com"
/>
<Input
placeholder="Phone number..."
type="number"
addonLeft="+234"
size="sm"
/>
</Stack>

Addons also accept JSX Elements.#

<Stack col>
<Input
placeholder="Phone number"
type="tel"
addonLeft={<PhoneIcon className="text-gray-400" />}
/>
<Input
placeholder="Enter amount"
type="number"
addonLeft="$"
addonRight={<CheckIcon color="green" />}
/>
</Stack>

Password Input Example#

function PasswordInput() {
const [show, setShow] = React.useState(false);
const handleClick = () => setShow(!show);
return (
<Input
placeholder="Enter password"
type={show ? "text" : "password"}
addonRight={
<button variant="link" onClick={handleClick}>
{show ? "Hide" : "Show"}
</button>
}
/>
);
}

Controlled InputGroup#

function Example() {
const [value, setValue] = React.useState("Starting...");
const handleChange = (event) => setValue(event.target.value);
return (
<>
<Input
value={value}
onChange={handleChange}
placeholder="Controlled input"
/>
<pre>{JSON.stringify(value, null, 2)}</pre>
</>
);
}

Props#

The Input component composes Box so you can pass all Box props, and React.InputHTMLAttributes.

NameTypeDefaultDescription
asReact.ElementTypeinputThe component to use in place of input.
aria-labelstringAccessibility label to use, in scenarios where the input has no visible label. A11y: It's usefult for screen readers.
aria-describedbystringAccessibility label to use, in scenarios where the input has no visible label. A11y: It's usefult for screen readers.
isDisabledbooleanfalseIf true, the input will be disabled. This sets aria-disabled=true and you can style this state by passing _disabled prop.
isInvalidbooleanfalseIf true, the input will indicate an error. This sets aria-invalid=true and you can style this state by passing _invalid prop.
isRequiredbooleanfalseIf true, the input element will be required.
isFullWidthbooleanfalseIf true, the input element will span the full width of it's parent.
isReadOnlybooleanfalseIf true, prevents the value of the input from being edited.
sizesm, md, lgmdThe visual size of the input element.
variantoutline, unstyled, flushed, filledoutlineThe variant of the input style to use.