shoelace/src/components/radio-group/radio-group.ts

50 wiersze
1.4 KiB
TypeScript
Czysty Zwykły widok Historia

2021-07-10 00:45:44 +00:00
import { LitElement, html } from 'lit';
2021-05-27 21:00:43 +00:00
import { customElement, property } from 'lit/decorators.js';
2021-04-09 12:15:33 +00:00
import { classMap } from 'lit-html/directives/class-map';
2021-07-10 00:45:44 +00:00
import styles from './radio-group.styles';
2021-04-09 12:15:33 +00:00
/**
* @since 2.0
* @status stable
*
2021-06-25 20:25:46 +00:00
* @slot - The default slot where radio controls are placed.
* @slot label - The radio group label. Required for proper accessibility. Alternatively, you can use the label prop.
2021-04-09 12:15:33 +00:00
*
2021-06-25 20:25:46 +00:00
* @csspart base - The component's base wrapper.
* @csspart label - The radio group label.
2021-04-09 12:15:33 +00:00
*/
@customElement('sl-radio-group')
export default class SlRadioGroup extends LitElement {
2021-07-10 00:45:44 +00:00
static styles = styles;
2021-04-09 12:15:33 +00:00
/** The radio group label. Required for proper accessibility. Alternatively, you can use the label slot. */
2021-07-01 00:04:46 +00:00
@property() label = '';
2021-04-09 12:15:33 +00:00
/** Hides the fieldset and legend that surrounds the radio group. The label will still be read by screen readers. */
2021-07-01 00:04:46 +00:00
@property({ type: Boolean, attribute: 'no-fieldset' }) noFieldset = false;
2021-04-09 12:15:33 +00:00
render() {
return html`
<fieldset
part="base"
class=${classMap({
'radio-group': true,
'radio-group--no-fieldset': this.noFieldset
})}
role="radiogroup"
>
<legend part="label" class="radio-group__label">
<slot name="label">${this.label}</slot>
</legend>
<slot></slot>
</fieldset>
`;
}
}
declare global {
interface HTMLElementTagNameMap {
'sl-radio-group': SlRadioGroup;
}
}