Radio Components
Examples
<script>
import { Radio } from 'flowbite-svelte'
let radiooptions = [
{
id: 'country-option-1',
name: 'country',
value: 'USA',
checked: true,
label: 'United States'
},
{
id: 'country-option-2',
name: 'country',
label: 'Germany',
value: 'Germany'
},
{
id: 'country-option-3',
name: 'country',
label: 'Spain (disabled)',
value: 'Spain',
disabled: true
}
];
</script>
{#each radiooptions as option}
<Radio {...option} divClass="flex items-center mb-4"/>
{/each}
Radio label with a link
<script>
let radiooptions2 = [
{
id: 'country-option-1',
name: 'country',
value: 'USA',
checked: false,
label: 'Radio button with a <a href="#" class="text-blue-600 dark:text-blue-500 hover:underline">link inside</a>.'
}
];
</script>
{#each radiooptions2 as option}
<Radio {...option} />
{/each}
Helper text
For orders shipped from $25 in books or $29 in other categories
<script>
let radiooptions3 = [
{
id: 'country-option-1',
name: 'country',
value: 'USA',
checked: false,
label: 'Free shipping via Flowbite',
helper: 'For orders shipped from $25 in books or $29 in other categories'
}
];
</script>
{#each radiooptions3 as option}
<Radio {...option} />
{/each}
Inline
<script>
let radiooptions4 =[
{
id: 'inline-1',
name: 'inline',
value:'inline-1',
label: 'Inline 1',
},
{
id: 'inline-2',
name: 'inline',
value:'inline-2',
label: 'Inline 2',
},
{
id: 'inline-3',
name: 'inline',
value:'inline-3',
label: 'Inline 3',
},
{
id: 'inline-4',
name: 'inline',
value:'inline-4',
label: 'Inline 4 (disabled)',
disabled: true
}
]
</script>
<RadioInline>
{#each radiooptions4 as option}
<Radio {...option} />
{/each}
</RadioInline>
Colors
<script>
let radiooptions5 =[
{
id: 'red',
name: 'color',
value:'red',
label: 'Red',
color: 'red'
},
{
id: 'green',
name: 'color',
value:'green',
label: 'Green',
color:'green'
},
{
id: 'purple',
name: 'color',
value:'purple',
label: 'Purple',
color: 'purple'
},
{
id: 'teal',
name: 'color',
value:'teal',
label: 'Teal',
color: 'teal'
},
{
id: 'yellow',
name: 'color',
value:'yellow',
label: 'Yellow',
color: 'yellow'
},
{
id: 'orange',
name: 'color',
value:'orange',
label: 'Orange',
color: 'orange'
}
]
</script>
<RadioInline>
{#each radiooptions5 as option}
<Radio {...option} />
{/each}
</RadioInline>
Props
The component has the following props, type, and default values. See types page for type information.
Name | Type | Default |
---|---|---|
helper | string | |
id | string | |
value | string | |
label | string | |
group | number | string | |
divClass | string | 'flex items-center mr-4' |
inputClass | string | 'w-4 h-4 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600 bg-gray-100 border-gray-300 ' |
labelClass | string | 'block ml-2 text-sm font-medium text-gray-900 dark:text-gray-300' |
disabled | boolean | false |
name | string | '' |
divHelperClass | string | 'flex items-center h-5' |
labelHelperClass | string | 'font-medium text-gray-900 dark:text-gray-300' |
helperClass | string | 'text-xs font-normal text-gray-500 dark:text-gray-300' |
color | FormColorType | 'blue' |