Tailwind CSS
(uses HTML5 implementation)Github repo: https://github.com/concrete-form/html5
info
You need to configure Tailwind on top of HTML5 implementation.
tip
Take a look at the Flowbite demo : Flowbite demo - codesandbox
Controls
<Input />
import Form from '@concrete-form/react-hook-form'
import Input from '@concrete-form/html5/Input'
const Demo = () => (
<Form>
<Input name="demo" placeholder="I'm an input" className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
{ /* example from https://tailwindcss-forms.vercel.app/ (simple) */ }
</Form>
)
<Autocomplete />
note
There is no rich autocomplete feature in HTML5. This control should be avoided when using Tailwind CSS.
import Form from '@concrete-form/react-hook-form'
import Autocomplete from '@concrete-form/html5/Autocomplete'
const Demo = () => (
<Form>
<Autocomplete name="demo" placeholder="I'm a boring autocomplete field" className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
{ /* example from https://tailwindcss-forms.vercel.app/ (simple) */ }
</Form>
)
<DateTime />
import Form from '@concrete-form/react-hook-form'
import DateTime from '@concrete-form/html5/DateTime'
const Demo = () => (
<Form>
date: <DateTime name="date" type="date" className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
time: <DateTime name="time" type="time" className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
datetime: <DateTime name="datetime" type="datetime" className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
{ /* example from https://tailwindcss-forms.vercel.app/ (simple) */ }
</Form>
)
<FileInput />
import Form from '@concrete-form/react-hook-form'
import FileInput from '@concrete-form/html5/FileInput'
const Demo = () => (
<Form>
<FileInput name="demo" className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
{ /* example from https://tailwindcss-forms.vercel.app/ (simple) */ }
</Form>
)
<Select />
import Form from '@concrete-form/react-hook-form'
import Select from '@concrete-form/html5/Select'
const Demo = () => (
<Form>
String options :
<Select name="select1" options={['foo', 'bar', 'baz', 'biz']} className="mt-1 mb-2 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
Multiple select :
<Select name="select2" options={['foo', 'bar', 'baz', 'biz']} multiple className="mt-1 mb-2 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
Labelled options :
<Select name="select3" options={[
{ label: 'First option', value: 'foo' },
'bar',
{ label: 'Third option', value: 'baz', props: { disabled: true } },
]} className="mt-1 mb-2 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
Groups (allowEmpty) :
<Select name="select4" allowEmpty options={[
'foo',
{ group: 'Group 1', options: ['bar', 'baz'] }
]} className="mt-1 mb-2 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
Childrens (allowEmpty) :
<Select name="select5" allowEmpty className="mt-1 mb-2 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
<option value="foo">Foo</option>
<option value="bar">Bar</option>
<option value="baz">Baz</option>
</Select>
{ /* example from https://tailwindcss-forms.vercel.app/ (simple) */ }
</Form>
)
<SingleCheckbox />
import Form from '@concrete-form/react-hook-form'
import SingleCheckbox from '@concrete-form/html5/SingleCheckbox'
const Demo = () => (
<Form>
<SingleCheckbox name="demo" label={(
<>I accept the <a href="#void">terms and conditions</a>.</>
)} className="rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300 focus:ring focus:ring-offset-0 focus:ring-indigo-200 focus:ring-opacity-50 " />
{ /* example from https://tailwindcss-forms.vercel.app/ (simple) */ }
</Form>
)
<Slider />
import Form from '@concrete-form/react-hook-form'
import Slider from '@concrete-form/html5/Slider'
const Demo = () => (
<Form>
<Slider name="demo" min={10} max={90} label="Label of the slider" className="w-full h-3 bg-gray-200 rounded-lg cursor-pointer" />
{ /* example from https://flowbite.com/docs/forms/range/ */ }
</Form>
)
<Textarea />
import Form from '@concrete-form/react-hook-form'
import Textarea from '@concrete-form/html5/Textarea'
const Demo = () => (
<Form>
<Textarea name="demo" placeholder="I'm a textarea" className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 " />
{ /* example from https://tailwindcss-forms.vercel.app/ (simple) */ }
</Form>
)
<ToggleSwitch />
note
Default toggle switch styles are provided by @concrete-form/html5
import Form from '@concrete-form/react-hook-form'
import ToggleSwitch from '@concrete-form/html5/ToggleSwitch'
const Demo = () => (
<Form>
<ToggleSwitch name="demo" label="I'm a toggle switch" />
<ToggleSwitch name="disabled" disabled label="I'm a disabled toggle switch" />
<ToggleSwitch name="disabled-active" disabled label="I'm a disabled + active toggle switch" />
</Form>
)
}
Control Groups
<CheckboxGroup />
import Form from '@concrete-form/react-hook-form'
import CheckboxGroup from '@concrete-form/html5/CheckboxGroup'
const Demo = () => (
<Form>
Vertical :
<CheckboxGroup name="demo-vertical" options={['foo', 'bar', 'baz']} className="rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300 focus:ring focus:ring-offset-0 focus:ring-indigo-200 focus:ring-opacity-50" />
<br /> Horizontal :
<CheckboxGroup name="demo-horizontal" orientation="horizontal" options={[
{ label: <span className="text-pink-500">Foo</span>, value: 'foo' },
'bar',
{ label: 'baz', value: 'baz', props: { disabled: true } },
]} className="ml-4 rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300 focus:ring focus:ring-offset-0 focus:ring-indigo-200 focus:ring-opacity-50" />
{ /* example from https://tailwindcss-forms.vercel.app/ (simple) */ }
</Form>
)
<RadioGroup />
import Form from '@concrete-form/react-hook-form'
import RadioGroup from '@concrete-form/html5/RadioGroup'
const Demo = () => (
<Form>
Vertical :
<RadioGroup name="demo-vertical" options={['foo', 'bar', 'baz']} className="rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300 focus:ring focus:ring-offset-0 focus:ring-indigo-200 focus:ring-opacity-50" />
<br /> Horizontal :
<RadioGroup name="demo-horizontal" orientation="horizontal" options={[
{ label: <span className="text-pink-500">Foo</span>, value: 'foo' },
'bar',
{ label: 'baz', value: 'baz', props: { disabled: true } },
]} className="ml-4 rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300 focus:ring focus:ring-offset-0 focus:ring-indigo-200 focus:ring-opacity-50" />
{ /* example from https://tailwindcss-forms.vercel.app/ (simple) */ }
</Form>
)
Form Controls
<SubmitButton />
import Form from '@concrete-form/react-hook-form'
import SubmitButton from '@concrete-form/html5/SubmitButton'
const wait = delay => new Promise(resolve => setTimeout(resolve, delay))
const spinner = <svg aria-hidden="true" class="w-4 h-4 ml-2 text-gray-200 animate-spin fill-blue-400" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
</svg>
// example from https://flowbite.com/docs/components/spinner/
const Demo = () => (
<Form onSubmit={() => wait(3000)}>
<SubmitButton loadingComponent={spinner} className="text-white bg-blue-700 hover:bg-blue-800 disabled:bg-blue-400 font-medium rounded-md text-sm px-5 py-2.5 mr-2 mb-2">Submit</SubmitButton>
{ /* Example from https://flowbite.com/docs/components/buttons/ */ }
</Form>
)
Layout
<LabelledControl />
import Form from '@concrete-form/react-hook-form'
import LabelledControl from '@concrete-form/html5/LabelledControl'
import Input from '@concrete-form/html5/Input'
import RadioGroup from '@concrete-form/html5/RadioGroup'
import SingleCheckbox from '@concrete-form/html5/SingleCheckbox'
const Demo = () => (
<Form>
<LabelledControl label="Label linked to the control" labelPosition="left">
<Input name="demo-single" className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" />
</LabelledControl>
<LabelledControl label="Label NOT linked to the controls group" labelPosition="left">
<RadioGroup name="demo-group" options={['foo', 'bar', 'baz']} className="rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300 focus:ring focus:ring-offset-0 focus:ring-indigo-200 focus:ring-opacity-50" />
</LabelledControl>
<LabelledControl label="Label NOT linked to boolean controls" labelPosition="left">
<SingleCheckbox name="demo-bool" label="THIS is the real label" className="rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300 focus:ring focus:ring-offset-0 focus:ring-indigo-200 focus:ring-opacity-50 " />
</LabelledControl>
{ /* examples from https://tailwindcss-forms.vercel.app/ (simple) */ }
</Form>
)