-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathtoggle-button.js
34 lines (32 loc) · 1.07 KB
/
toggle-button.js
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
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
/**
* @module ToggleButton
* `ToggleButton` components are used to expand and collapse content with a toggle.
*
* @example
* <ToggleButton @isOpen={{this.showOptions}} @openLabel="Show stuff" @closedLabel="Hide the stuff" @onClick={{fn (mut this.showOptions) (not this.showOptions)}} />
* {{#if this.showOptions}}
* <div>
* <p>
* I will be toggled!
* </p>
* </div>
* {{/if}}
*
* @param {boolean} isOpen - determines whether to show open or closed label
* @param {function} onClick - fired when button is clicked
* @param {string} [openLabel=Hide options] - The message to display when the toggle is open.
* @param {string} [closedLabel=More options] - The message to display when the toggle is closed.
*/
export default class ToggleButtonComponent extends Component {
get openLabel() {
return this.args.openLabel || 'Hide options';
}
get closedLabel() {
return this.args.closedLabel || 'More options';
}
}