mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 20:52:00 +08:00
[ui][select] add errorMessage and placeholder
This commit is contained in:
@ -14,6 +14,9 @@ export default {
|
||||
control: { type: 'select' },
|
||||
options: SelectDisplays,
|
||||
},
|
||||
errorMessage: {
|
||||
control: 'text',
|
||||
},
|
||||
isLabelHidden: {
|
||||
control: 'boolean',
|
||||
},
|
||||
@ -23,6 +26,9 @@ export default {
|
||||
name: {
|
||||
control: 'text',
|
||||
},
|
||||
placeholder: {
|
||||
control: 'text',
|
||||
},
|
||||
},
|
||||
component: Select,
|
||||
title: 'Select',
|
||||
@ -181,28 +187,78 @@ export function Required() {
|
||||
const [value, setValue] = useState('apple');
|
||||
|
||||
return (
|
||||
<div className="space-x-4">
|
||||
<Select
|
||||
label="Select a fruit"
|
||||
options={[
|
||||
{
|
||||
label: 'Apple',
|
||||
value: 'apple',
|
||||
},
|
||||
{
|
||||
label: 'Banana',
|
||||
value: 'banana',
|
||||
},
|
||||
{
|
||||
label: 'Orange',
|
||||
value: 'orange',
|
||||
},
|
||||
]}
|
||||
required={true}
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
/>
|
||||
</div>
|
||||
<Select
|
||||
label="Select a fruit"
|
||||
options={[
|
||||
{
|
||||
label: 'Apple',
|
||||
value: 'apple',
|
||||
},
|
||||
{
|
||||
label: 'Banana',
|
||||
value: 'banana',
|
||||
},
|
||||
{
|
||||
label: 'Orange',
|
||||
value: 'orange',
|
||||
},
|
||||
]}
|
||||
required={true}
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function Placeholder() {
|
||||
return (
|
||||
<Select
|
||||
label="Select a fruit"
|
||||
options={[
|
||||
{
|
||||
label: 'Apple',
|
||||
value: 'apple',
|
||||
},
|
||||
{
|
||||
label: 'Banana',
|
||||
value: 'banana',
|
||||
},
|
||||
{
|
||||
label: 'Orange',
|
||||
value: 'orange',
|
||||
},
|
||||
]}
|
||||
placeholder="Select a fruit"
|
||||
required={true}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function Error() {
|
||||
const [value, setValue] = useState('banana');
|
||||
|
||||
return (
|
||||
<Select
|
||||
errorMessage={value !== 'apple' ? 'Must select apple' : undefined}
|
||||
label="Select a fruit"
|
||||
options={[
|
||||
{
|
||||
label: 'Apple',
|
||||
value: 'apple',
|
||||
},
|
||||
{
|
||||
label: 'Banana',
|
||||
value: 'banana',
|
||||
},
|
||||
{
|
||||
label: 'Orange',
|
||||
value: 'orange',
|
||||
},
|
||||
]}
|
||||
required={true}
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user