mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
feat(components): add RadioButton
This commit is contained in:
parent
acbb3ace96
commit
bf502f904f
7 changed files with 109 additions and 0 deletions
42
src/components/RadioButton/RadioButton.svelte
Normal file
42
src/components/RadioButton/RadioButton.svelte
Normal file
|
@ -0,0 +1,42 @@
|
|||
<script>
|
||||
let className = undefined;
|
||||
export { className as class };
|
||||
export let value = '';
|
||||
export let checked = false;
|
||||
export let disabled = false;
|
||||
export let id = Math.random();
|
||||
export let labelText = '';
|
||||
export let hideLabel = false;
|
||||
export let labelPosition = 'right';
|
||||
export let name = '';
|
||||
export let props = {};
|
||||
|
||||
import { cx } from '../../lib';
|
||||
|
||||
const _class = cx(
|
||||
'--radio-button-wrapper',
|
||||
labelPosition !== 'right' && `--radio-button-wrapper--label-${labelPosition}`,
|
||||
className
|
||||
);
|
||||
const _innerLabelClass = cx(hideLabel && '--visually-hidden');
|
||||
</script>
|
||||
|
||||
<div class={_class}>
|
||||
<input
|
||||
{...props}
|
||||
type="radio"
|
||||
class={cx('--radio-button')}
|
||||
on:change
|
||||
on:change={event => {
|
||||
value = event.target.value;
|
||||
}}
|
||||
{id}
|
||||
{name}
|
||||
{checked}
|
||||
{disabled}
|
||||
{value} />
|
||||
<label for={id} class={cx('--radio-button__label')}>
|
||||
<span class={cx('--radio-button__appearance')} />
|
||||
<span class={_innerLabelClass}>{labelText}</span>
|
||||
</label>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue