Input
Input
Input is a special field which is used in order to receive data from the user. Used mostly in a variety of web-based forms. You can use material design version or default bootstrap style.
Default Input Types
Default Input example.
import React from "react";import { CDBInput, CDBContainer } from "cdbreact";export const Input = () => {return (<CDBContainer><CDBInput label="Username" /><CDBInput hint="Your e-mail" type="email" /><CDBInput type="number" /><CDBInput material type="text" /><CDBInput background type="text" /><CDBInput type="checkbox" /><CDBInput className="mt-5" type="textarea" /></CDBContainer>);};export default Input;
Input Sizing
import React from "react";import { CDBInput, CDBContainer } from "cdbreact";export const Input = () => {return (<CDBContainer><CDBInput label="Your e-mail" type="email" size="sm" /><CDBInput type="number" label="Your Number" size="lg" /></CDBContainer>);};export default Input;
Input with icons
import React from "react";import { CDBInput, CDBContainer } from "cdbreact";const Input = () => {return (<CDBContainer><CDBInput label="Username" type="text" icon="user"/><CDBInput label="Password" type="password" icon="bell"/></CDBContainer>);};export default Input;
Input with MD
import React from "react";import { CDBInput, CDBContainer } from "cdbreact";const Input = () => {return (<CDBContainer><CDBInput material label="Your e-mail" type="email" /><CDBInput material type="number" label="Your Number" /></CDBContainer>);};export default Input;
Placeholder
import React from "react";import { CDBInput, CDBContainer } from "cdbreact";const Input = () => {return (<CDBContainer><CDBInput hint="Your e-mail" type="email" /><CDBInput type="number" hint="Your Number" /></CDBContainer>);};export default Input;
Disabled Inputs
import React from "react";import { CDBInput, CDBContainer } from "cdbreact";const Input = () => {return (<CDBContainer><CDBInput hint="Your e-mail" type="email" disabled /><CDBInput hint="Your Number" type="number" disabled /></CDBContainer>);};export default Input;
Textarea
import React from "react";import { CDBInput, CDBContainer } from "cdbreact";const Input = () => {return (<CDBContainer><CDBInput label="Your name" type="textarea" /><CDBInputlabel="Your story"type="textarea"materialrows={5}cols={10}/></CDBContainer>);};export default Input;
Background
import React from "react";import { CDBInput, CDBContainer } from "cdbreact";const Input = () => {return (<CDBContainer><CDBInput hint="Your e-mail" type="email" background /><CDBInput type="number" hint="Your Number" background /></CDBContainer>);};export default Input;
API
In this section you will find advanced information about the Input component. You will find out which modules are required, what are the possibilities of configuring the component, and what events and methods you can use to work with it.
Contrast Input Import Statement
You need to import the Contrast Input component first before using it.
import { CDBInput } from "cdbreact";
API Reference: Contrast Input Properties
The table below shows the configuration options of the CDBInput component.
| Name | Type | Default | Description | Example |
|---|---|---|---|---|
| className | String | Adds custom classes | <CDBInput className="myClass" ... /> | |
| tag | String | div | Changes default input tag | <CDBInput tag="input" ... /> |
| containerClass | String | Adds custom class to wrapping div | <CDBInput containerClass="wrapper" ... /> | |
| error | String | Sets the error message for the labels data-error attribute | <CDBInput error="Ouch!" ... /> | |
| hint | String | Sets the placeholder for the Input | <CDBInput hint="Placeholder" ... /> | |
| value | Number, Boolean or String | The value of the input element (use with the controlled input) | <CDBInput value="I am controlled" onChange={this.handleChange} ... /> | |
| material | Boolean | false | Changes component styles for material theme | <CDBInput material .../> |
| valueDefault | Number or String | The default value of the input (use with the uncontrolled input) | <CDBInput valueDefault="I am uncontrolled" ... /> | |
| id | String | Required! Set the id of the input element | <CDBInput id="myId" ... /> | |
| label | String | Add label to the component; you can attach jsx elements (f.e. links) | <CDBInput label="My custom input" ... /> | |
| labelClass | String | Add custom class to label | <CDBInput labelClass="My custom label class" ... /> | |
| labelId | String | Sets custom id to label | <CDBInput labelId="myId" ... /> | |
| size | String | lg | Changes size of the component; available lg and sm | <CDBInput size="lg" ... /> |
| success | String | Sets the success message for the labels data-success attribute | <CDBInput success="Great!" ... /> | |
| type | String | text | The type of the input element | <CDBInput type="checkbox" ... /> |
| inputRef | Object or function | Allows to attach React Ref to the input component; accepts only Callback Ref | <CDBInput inputRef={ref => this.myRef = ref } .../> | |
| icon | String | Adds font awesome icon | <CDBInput icon="caret-right" ... /> | |
| iconBrand | String | Use this property to set brand icon (fab) | <CDBInput icon="twitter" iconBrand ... /> | |
| iconLight | String | Use this property to set light icon (fal) | <CDBInput icon="twitter" iconLight ... /> | |
| iconRegular | String | Use this property to set regular icon (far) | <CDBInput icon="twitter" iconRegular ... /> | |
| iconClass | String | Adds custom classes to icon element | <CDBInput icon="caret-right" iconClass="my-class" ... /> | |
| disable | Boolean | false | Disables Input component | <CDBInput disabled .../> |
| group | Boolean | false | Add .form-group class to the wrapping div | <CDBInput error .../> |
| filled | Boolean | false | Add filled-in style to checkbox/radio button | <CDBInput type="checkbox" filled .../> |
| validate | Boolean | false | Adds .validate class to the Input component | <CDBInput validate .../> |
| gap | Boolean | false | Creates gap inside checkbox/radio button | <CDBInput type="checkbox" gap .../> |