2021-04-09 12:15:33 +00:00
|
|
|
import { LitElement, html, unsafeCSS } 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';
|
|
|
|
import styles from 'sass:./radio-group.scss';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 2.0
|
|
|
|
* @status stable
|
|
|
|
*
|
2021-06-24 22:24:54 +00:00
|
|
|
* @slot default 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-24 22:24:54 +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 {
|
|
|
|
static styles = unsafeCSS(styles);
|
|
|
|
|
|
|
|
/** The radio group label. Required for proper accessibility. Alternatively, you can use the label slot. */
|
|
|
|
@property() label = '';
|
|
|
|
|
|
|
|
/** Hides the fieldset and legend that surrounds the radio group. The label will still be read by screen readers. */
|
|
|
|
@property({ type: Boolean, attribute: 'no-fieldset' }) noFieldset = false;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|