-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtoggle-button.ts
More file actions
103 lines (89 loc) · 2.76 KB
/
toggle-button.ts
File metadata and controls
103 lines (89 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { LitElement, html } from 'lit';
import { property, query } from 'lit/decorators.js';
import { themes } from '../../theming/theming-decorator.js';
import { addKeyboardFocusRing } from '../common/controllers/focus-ring.js';
import { registerComponent } from '../common/definitions/register.js';
import { partMap } from '../common/part-map.js';
import { styles } from './themes/button.base.css.js';
import { all } from './themes/button.js';
import { styles as shared } from './themes/shared/button/button.common.css.js';
/**
* The `igc-toggle-button` wraps a native button element and exposes additional `value` and `selected` properties.
* It is used in the context of an `igc-button-group` to facilitate the creation of group/toolbar like UX behaviors.
*
* @element igc-toggle-button
*
* @slot Renders the label/content of the button.
*
* @csspart toggle - The native button element.
*/
@themes(all)
export default class IgcToggleButtonComponent extends LitElement {
public static override styles = [styles, shared];
public static readonly tagName = 'igc-toggle-button';
public static override shadowRootOptions = {
...LitElement.shadowRootOptions,
delegatesFocus: true,
};
/* blazorSuppress */
public static register(): void {
registerComponent(IgcToggleButtonComponent);
}
private readonly _focusRingManager = addKeyboardFocusRing(this);
@query('[part="toggle"]', true)
private readonly _nativeButton!: HTMLButtonElement;
/**
* The value attribute of the control.
* @attr
*/
@property()
public value!: string;
/**
* Determines whether the button is selected.
* @attr
*/
@property({ type: Boolean, reflect: true })
public selected = false;
/**
* Determines whether the button is disabled.
* @attr
*/
@property({ type: Boolean, reflect: true })
public disabled = false;
/* alternateName: focusComponent */
/** Sets focus on the button. */
public override focus(options?: FocusOptions): void {
this._nativeButton.focus(options);
}
/* alternateName: blurComponent */
/** Removes focus from the button. */
public override blur(): void {
this._nativeButton.blur();
}
/** Simulates a mouse click on the element. */
public override click(): void {
this._nativeButton.click();
}
protected override render() {
return html`
<button
part=${partMap({
toggle: true,
focused: this._focusRingManager.focused,
})}
type="button"
?disabled=${this.disabled}
.ariaLabel=${this.ariaLabel}
aria-pressed=${this.selected}
aria-disabled=${this.disabled}
>
<slot></slot>
</button>
`;
}
}
declare global {
interface HTMLElementTagNameMap {
'igc-toggle-button': IgcToggleButtonComponent;
}
}