Skip to content

Demos

Empty

<Field.String onChange={(value) => console.log('onChange', value)} />

Placeholder

<Field.String
placeholder="Enter a text..."
onChange={(value) => console.log('onChange', value)}
/>

Label

<Field.String
label="Label text"
onChange={(value) => console.log('onChange', value)}
/>

Label and value

<Field.String
label="Label text"
value="foo"
onChange={(value) => console.log('onChange', value)}
/>

Horizontal layout

<Field.String
label="Label text"
value="foo"
layout="horizontal"
onChange={(value) => console.log('onChange', value)}
/>

Widths

<Field.String
label="Default width (property omitted)"
value="foo"
onChange={(value) => console.log('onChange', value)}
/>
<Field.String
label="Medium"
value="foo"
width="medium"
onChange={(value) => console.log('onChange', value)}
/>
<Field.String
label="Large"
value="foo"
width="large"
onChange={(value) => console.log('onChange', value)}
/>
<Field.String
label="Stretch"
value="foo"
width="stretch"
onChange={(value) => console.log('onChange', value)}
/>

Icons

<Field.String
label="Icon left"
value="foo"
leftIcon="check"
onChange={(value) => console.log('onChange', value)}
/>
<Field.String
label="Icon right"
value="foo"
rightIcon="loupe"
onChange={(value) => console.log('onChange', value)}
/>

Character counter

 0
<Field.String
onChange={(value) => console.log('onChange', value)}
characterCounter
/>
3
<Field.String
label="Label text"
value="foo"
onChange={(value) => console.log('onChange', value)}
characterCounter
/>
3/16
<Field.String
label="Label text"
value="foo"
onChange={(value) => console.log('onChange', value)}
maxLength={16}
characterCounter
/>

Clear

<Field.String
value="foo"
onChange={(value) => console.log('onChange', value)}
clear
/>

Disabled

<Field.String
value="foo"
label="Label text"
onChange={(value) => console.log('onChange', value)}
disabled
/>

Info

Useful information (?)
<Field.String
value="foo"
label="Label text"
onChange={(value) => console.log('onChange', value)}
info="Useful information (?)"
/>

Warning

I'm warning you...
<Field.String
value="foo"
label="Label text"
onChange={(value) => console.log('onChange', value)}
warning={new FormError("I'm warning you...")}
/>

Error

This is what is wrong...
<Field.String
value="foo"
label="Label text"
onChange={(value) => console.log('onChange', value)}
error={new FormError('This is what is wrong...')}
/>

Validation - Required

<Field.String
value="foo"
label="Label text"
onChange={(value) => console.log('onChange', value)}
required
/>

Validation - Minimum length

<Field.String
value="foo"
label="Label text (minimum 8 characters)"
onChange={(value) => console.log('onChange', value)}
minLength={8}
/>

Validation - Maximum length and custom error message

<Field.String
value="foo"
label="Label text (maximum 8 characters)"
onChange={(value) => console.log('onChange', value)}
maxLength={8}
errorMessages={{
maxLength: "You can't write THAT long.. Max 8 chars!",
}}
/>

Validation - Pattern

<Field.String
value="foo"
label="Label text"
onChange={(value) => console.log('onChange', value)}
pattern="^foo123"
/>

Synchronous external validator (called on every change)

<Field.String
value="foo"
label="Label text (minimum 4 characters)"
validator={(value) =>
value.length < 4 ? new FormError('At least 4 characters') : undefined
}
onChange={(value) => console.log('onChange', value)}
/>

Asynchronous external validator (called on every change)

<Field.String
value="foo"
label="Label text (minimum 4 characters)"
validator={(value) =>
new Promise((resolve) =>
setTimeout(
() =>
resolve(
value.length < 5
? new FormError('At least 5 characters')
: undefined
),
1500
)
)
}
onChange={(value) => console.log('onChange', value)}
/>

Synchronous external validator (called on blur)

<Field.String
value="foo"
label="Label text (minimum 4 characters)"
onBlurValidator={(value) =>
value.length < 4 ? new FormError('At least 4 characters') : undefined
}
onChange={(value) => console.log('onChange', value)}
/>

Asynchronous external validator (called on blur)

<Field.String
value="foo"
label="Label text (minimum 4 characters)"
onBlurValidator={(value) =>
new Promise((resolve) =>
setTimeout(
() =>
resolve(
value.length < 5
? new FormError('At least 5 characters')
: undefined
),
1500
)
)
}
onChange={(value) => console.log('onChange', value)}
/>

Multiline, empty

<Field.String
onChange={(value) => console.log('onChange', value)}
multiline
/>

Multiline, placeholder

<Field.String
placeholder="Enter text here"
onChange={(value) => console.log('onChange', value)}
multiline
/>

Multiline, label & value

<Field.String
value="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis in tempus odio, nec interdum orci. Integer vehicula ipsum et risus finibus, vitae commodo ex luctus. Nam viverra sollicitudin dictum. Vivamus maximus dignissim lorem, vitae viverra erat dapibus a."
label="Label text"
onChange={(value) => console.log('onChange', value)}
multiline
/>