kopia lustrzana https://github.com/shoelace-style/shoelace
43 wiersze
1.0 KiB
TypeScript
43 wiersze
1.0 KiB
TypeScript
import { LitElement, customElement, html, property, unsafeCSS } from 'lit-element';
|
|
import styles from 'sass:./button-group.scss';
|
|
|
|
/**
|
|
* @since 2.0
|
|
* @status stable
|
|
*
|
|
* @slot - One or more `<sl-button>` elements to display in the button group.
|
|
*
|
|
* @part base - The component's base wrapper.
|
|
*/
|
|
@customElement('sl-button-group')
|
|
export class SlButtonGroup extends LitElement {
|
|
static styles = unsafeCSS(styles);
|
|
|
|
/** A label to use for the button group's `aria-label` attribute. */
|
|
@property() label: string;
|
|
|
|
handleFocus(event: CustomEvent) {
|
|
const button = event.target as HTMLElement;
|
|
button.classList.add('sl-focus');
|
|
}
|
|
|
|
handleBlur(event: CustomEvent) {
|
|
const button = event.target as HTMLElement;
|
|
button.classList.remove('sl-focus');
|
|
}
|
|
|
|
render() {
|
|
return html`
|
|
<div
|
|
part="base"
|
|
class="button-group"
|
|
aria-label=${this.label}
|
|
@focusout=${this.handleBlur}
|
|
@focusin=${this.handleFocus}
|
|
>
|
|
<slot></slot>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|