2021-03-24 10:21:21 -04:00
|
|
|
import { LitElement, html, unsafeCSS } from 'lit';
|
|
|
|
|
import { customElement, property } from 'lit/decorators';
|
2021-02-26 09:09:13 -05:00
|
|
|
import styles from 'sass:./button-group.scss';
|
2020-08-06 09:07:24 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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.
|
|
|
|
|
*/
|
2021-03-18 09:04:23 -04:00
|
|
|
@customElement('sl-button-group')
|
2021-03-08 19:14:32 -05:00
|
|
|
export default class SlButtonGroup extends LitElement {
|
2021-03-06 12:01:39 -05:00
|
|
|
static styles = unsafeCSS(styles);
|
2020-08-06 09:07:24 -04:00
|
|
|
|
2020-09-04 17:11:25 -04:00
|
|
|
/** A label to use for the button group's `aria-label` attribute. */
|
2021-03-06 12:01:39 -05:00
|
|
|
@property() label: string;
|
2020-08-06 09:07:24 -04:00
|
|
|
|
|
|
|
|
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() {
|
2021-02-26 09:09:13 -05:00
|
|
|
return html`
|
|
|
|
|
<div
|
|
|
|
|
part="base"
|
|
|
|
|
class="button-group"
|
|
|
|
|
aria-label=${this.label}
|
2021-03-06 12:01:39 -05:00
|
|
|
@focusout=${this.handleBlur}
|
|
|
|
|
@focusin=${this.handleFocus}
|
2021-02-26 09:09:13 -05:00
|
|
|
>
|
2021-03-06 12:01:39 -05:00
|
|
|
<slot></slot>
|
2020-08-06 09:07:24 -04:00
|
|
|
</div>
|
2021-02-26 09:09:13 -05:00
|
|
|
`;
|
2020-08-06 09:07:24 -04:00
|
|
|
}
|
|
|
|
|
}
|
2021-03-12 15:07:38 +01:00
|
|
|
|
2021-03-12 09:09:08 -05:00
|
|
|
declare global {
|
|
|
|
|
interface HTMLElementTagNameMap {
|
|
|
|
|
'sl-button-group': SlButtonGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|