carbon-components-svelte
Version:
Svelte implementation of the Carbon Design System
85 lines (69 loc) • 1.93 kB
TypeScript
import { SvelteComponentTyped } from "svelte";
import type { SvelteHTMLElements } from "svelte/elements";
type $RestProps = SvelteHTMLElements["div"];
type $Props<Value extends string | number = string | number> = {
/**
* Specify the value of the radio button.
* @default ""
*/
value?: Value;
/**
* Set to `true` to check the radio button.
* @default false
*/
checked?: boolean;
/**
* Set to `true` to disable the radio button
* @default false
*/
disabled?: boolean;
/**
* Set to `true` to mark the field as required
* @default false
*/
required?: boolean;
/**
* Specify the label position.
* @default "right"
*/
labelPosition?: "right" | "left";
/**
* Specify the label text
* @default ""
*/
labelText?: string;
/**
* Set to `true` to visually hide the label text
* @default false
*/
hideLabel?: boolean;
/**
* Set an id for the input element
* @default `ccs-${Math.random().toString(36)}`
*/
id?: string;
/**
* Specify a name attribute for the radio button input.
* When multiple standalone RadioButton components share the same `name`,
* they form an implicit group and their `checked` state will be synchronized.
* @default undefined
*/
name?: string;
/**
* Obtain a reference to the input HTML element.
* @default null
*/
ref?: null | HTMLInputElement;
labelChildren?: (this: void) => void;
[key: `data-${string}`]: unknown;
};
export type RadioButtonProps<Value extends string | number = string | number> = Omit<$RestProps, keyof $Props<Value>> & $Props<Value>;
export default class RadioButton<Value extends string | number = string | number> extends SvelteComponentTyped<
RadioButtonProps<Value>,
{
blur: WindowEventMap["blur"];
change: WindowEventMap["change"];
focus: WindowEventMap["focus"];
},
{ labelChildren: Record<string, never> }
> {}