-
Notifications
You must be signed in to change notification settings - Fork 18
/
rh-accordion.ts
61 lines (48 loc) · 2.09 KB
/
rh-accordion.ts
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
import { html, type TemplateResult } from 'lit';
import { classMap } from 'lit/directives/class-map.js';
import { customElement } from 'lit/decorators/custom-element.js';
import { property } from 'lit/decorators/property.js';
import { observed } from '@patternfly/pfe-core/decorators/observed.js';
import { colorContextConsumer, type ColorTheme } from '../../lib/context/color/consumer.js';
import { colorContextProvider, type ColorPalette } from '../../lib/context/color/provider.js';
import { BaseAccordion } from '@patternfly/elements/pf-accordion/BaseAccordion.js';
import styles from './rh-accordion.css';
import './rh-accordion-header.js';
import './rh-accordion-panel.js';
/**
* An accordion is a stacked list of panels which allows users to expand or collapse information when selected. They feature panels that consist of a section text label and a caret icon that collapses or expands to reveal more information.
*
* @summary Expands or collapses a stacked list of panels
*
* @fires {AccordionExpandEvent} expand - when a panel expands
* @fires {AccordionCollapseEvent} collapse - when a panel collapses
*
*
* @slot
* Place the `rh-accordion-header` and `rh-accordion-panel` elements here.
*
*/
@customElement('rh-accordion')
export class RhAccordion extends BaseAccordion {
static readonly version = '{{version}}';
static readonly styles = [...BaseAccordion.styles, styles];
@colorContextConsumer() private on?: ColorTheme;
@colorContextProvider()
@property({ reflect: true, attribute: 'color-palette' }) colorPalette?: ColorPalette;
@observed(function largeChanged(this: RhAccordion) {
[...this.headers, ...this.panels].forEach(el => el.toggleAttribute('large', this.large));
})
@property({ reflect: true, type: Boolean }) large = false;
@property({ reflect: true, type: Boolean }) bordered = true;
override render(): TemplateResult {
const { on = '' } = this;
return html`
<div id="container" class="${classMap({ [on]: !!on })}">${super.render()}</div>
`;
}
}
declare global {
interface HTMLElementTagNameMap {
'rh-accordion': RhAccordion;
}
}