@teipublisher/pb-components 1.42.7 → 1.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,183 +1,184 @@
1
- import { LitElement, html, css } from 'lit-element';
2
- import { pbMixin } from './pb-mixin.js';
3
- import '@polymer/iron-icon';
4
- import '@polymer/iron-icons';
5
- import '@polymer/iron-collapse';
6
-
7
-
8
- /**
9
- * A collapsible block: in collapsed state it only shows a header and expands if clicked.
10
- * The header should go into slot `collapse-trigger`, the content into `collapse-content`.
11
- * Example:
12
- *
13
- * ```html
14
- * <pb-collapse>
15
- * <div slot="collapse-trigger">
16
- * Metadata
17
- * </div>
18
- * <pb-view slot="collapse-content" src="document1" subscribe="transcription" xpath="//teiHeader"></pb-view>
19
- * </pb-collapse>
20
- * ```
21
- *
22
- * @slot collapse-trigger - trigger toggling collapsed content on/off
23
- * @slot collapse-content - content to be collapsed
24
- * @cssprop [--pb-collapse-icon-padding=0 4px 0 0] - padding in px for the "caret-down" icon left to the collapsible item
25
- * @fires pb-collapse-open - Fires opening the collapsed section
26
- */
27
- export class PbCollapse extends pbMixin(LitElement) {
28
- static get properties() {
29
- return {
30
- ...super.properties,
31
- /**
32
- * @deprecated
33
- * Corresponds to the iron-collapse's horizontal property.
34
- */
35
- horizontal: {
36
- type: Boolean
37
- },
38
- /**
39
- * Corresponds to the iron-collapse's noAnimation property.
40
- *
41
- */
42
- noAnimation: {
43
- type: Boolean,
44
- attribute: 'no-animation'
45
- },
46
- /**
47
- * Whether currently expanded.
48
- *
49
- */
50
- opened: {
51
- type: Boolean
52
- },
53
- /**
54
- * By default, an open collapse is closed if another pb-collapse is expanded on the same event channel.
55
- * Set to true to keep multiple pb-collapse open at the same time.
56
- */
57
- toggles: {
58
- type: Boolean
59
- },
60
- /**
61
- * The iron-icon when collapsed. Value must be one of the icons defined by iron-icons
62
- */
63
- expandIcon: {
64
- type: String,
65
- attribute: 'expand-icon'
66
- },
67
- /**
68
- * The icon when expanded.
69
- */
70
- collapseIcon: {
71
- type: String,
72
- attribute: 'collapse-icon'
73
- },
74
- /**
75
- * Whether to hide the expand/collapse icon.
76
- */
77
- noIcons: {
78
- type: Boolean,
79
- attribute: 'no-icons'
80
- }
81
- };
82
- }
83
-
84
- constructor() {
85
- super();
86
- this.horizontal = false;
87
- this.noAnimation = false;
88
- this.opened = false;
89
- this.expandIcon = 'icons:expand-more';
90
- this.collapseIcon = 'icons:expand-less';
91
- this.noIcons = false;
92
- this.toggles = false;
93
- }
94
-
95
- connectedCallback() {
96
- super.connectedCallback();
97
- this.addEventListener('pb-collapse-open', () => {
98
- this.open();
99
- });
100
- if (this.toggles) {
101
- this.subscribeTo('pb-collapse-open', (ev) => {
102
- if (!ev.detail || ev.detail._source === this) {
103
- return;
104
- }
105
- for (const collapse of this.querySelectorAll('pb-collapse')) {
106
- if (collapse === ev.detail._source) {
107
- return;
108
- }
109
- }
110
- this.close();
111
- });
112
- }
113
- }
114
-
115
- /**
116
- * opens the collapsible section
117
- */
118
- open() {
119
- if (this.opened) {
120
- return;
121
- }
122
- this.opened = true;
123
-
124
- this.emitTo('pb-collapse-open', this);
125
- }
126
-
127
- /**
128
- * closes the collapsible section
129
- */
130
- close() {
131
- if (this.opened) {
132
- this.opened = false;
133
- }
134
- }
135
-
136
- /**
137
- * toggles the collapsible state
138
- */
139
- toggle() {
140
- this.opened = !this.opened;
141
- if (this.opened) {
142
- this.emitTo('pb-collapse-open', this.data);
143
- }
144
- }
145
-
146
- render() {
147
- return html`
148
- <div id="trigger" @click="${this.toggle}" class="collapse-trigger">
149
- ${
150
- !this.noIcons ?
151
- html`<iron-icon icon="${this.opened ? this.collapseIcon : this.expandIcon}"></iron-icon>` :
152
- null
153
- }
154
- <slot id="collapseTrigger" name="collapse-trigger"></slot>
155
- </div>
156
- <iron-collapse id="collapse" horizontal="${this.horizontal}" no-animation="${this.noAnimation}" .opened="${this.opened}">
157
- <slot name="collapse-content"></slot>
158
- </iron-collapse>
159
- `;
160
- }
161
-
162
- static get styles() {
163
- return css`
164
- :host {
165
- display: block;
166
- }
167
-
168
- #trigger {
169
- display: table-row;
170
- }
171
-
172
- #trigger iron-icon {
173
- display: table-cell;
174
- padding: var(--pb-collapse-icon-padding, 0 4px 0 0);
175
- }
176
-
177
- slot[name="collapse-trigger"] {
178
- display: table-cell;
179
- }
180
- `;
181
- }
182
- }
1
+ import { LitElement, html, css } from 'lit-element';
2
+ import { pbMixin } from './pb-mixin.js';
3
+ import { themableMixin } from "./theming.js";
4
+ import '@polymer/iron-icon';
5
+ import '@polymer/iron-icons';
6
+ import '@polymer/iron-collapse';
7
+
8
+
9
+ /**
10
+ * A collapsible block: in collapsed state it only shows a header and expands if clicked.
11
+ * The header should go into slot `collapse-trigger`, the content into `collapse-content`.
12
+ * Example:
13
+ *
14
+ * ```html
15
+ * <pb-collapse>
16
+ * <div slot="collapse-trigger">
17
+ * Metadata
18
+ * </div>
19
+ * <pb-view slot="collapse-content" src="document1" subscribe="transcription" xpath="//teiHeader"></pb-view>
20
+ * </pb-collapse>
21
+ * ```
22
+ *
23
+ * @slot collapse-trigger - trigger toggling collapsed content on/off
24
+ * @slot collapse-content - content to be collapsed
25
+ * @cssprop [--pb-collapse-icon-padding=0 4px 0 0] - padding in px for the "caret-down" icon left to the collapsible item
26
+ * @fires pb-collapse-open - Fires opening the collapsed section
27
+ */
28
+ export class PbCollapse extends themableMixin(pbMixin(LitElement)) {
29
+ static get properties() {
30
+ return {
31
+ ...super.properties,
32
+ /**
33
+ * @deprecated
34
+ * Corresponds to the iron-collapse's horizontal property.
35
+ */
36
+ horizontal: {
37
+ type: Boolean
38
+ },
39
+ /**
40
+ * Corresponds to the iron-collapse's noAnimation property.
41
+ *
42
+ */
43
+ noAnimation: {
44
+ type: Boolean,
45
+ attribute: 'no-animation'
46
+ },
47
+ /**
48
+ * Whether currently expanded.
49
+ *
50
+ */
51
+ opened: {
52
+ type: Boolean
53
+ },
54
+ /**
55
+ * By default, an open collapse is closed if another pb-collapse is expanded on the same event channel.
56
+ * Set to true to keep multiple pb-collapse open at the same time.
57
+ */
58
+ toggles: {
59
+ type: Boolean
60
+ },
61
+ /**
62
+ * The iron-icon when collapsed. Value must be one of the icons defined by iron-icons
63
+ */
64
+ expandIcon: {
65
+ type: String,
66
+ attribute: 'expand-icon'
67
+ },
68
+ /**
69
+ * The icon when expanded.
70
+ */
71
+ collapseIcon: {
72
+ type: String,
73
+ attribute: 'collapse-icon'
74
+ },
75
+ /**
76
+ * Whether to hide the expand/collapse icon.
77
+ */
78
+ noIcons: {
79
+ type: Boolean,
80
+ attribute: 'no-icons'
81
+ }
82
+ };
83
+ }
84
+
85
+ constructor() {
86
+ super();
87
+ this.horizontal = false;
88
+ this.noAnimation = false;
89
+ this.opened = false;
90
+ this.expandIcon = 'icons:expand-more';
91
+ this.collapseIcon = 'icons:expand-less';
92
+ this.noIcons = false;
93
+ this.toggles = false;
94
+ }
95
+
96
+ connectedCallback() {
97
+ super.connectedCallback();
98
+ this.addEventListener('pb-collapse-open', () => {
99
+ this.open();
100
+ });
101
+ if (this.toggles) {
102
+ this.subscribeTo('pb-collapse-open', (ev) => {
103
+ if (!ev.detail || ev.detail._source === this) {
104
+ return;
105
+ }
106
+ for (const collapse of this.querySelectorAll('pb-collapse')) {
107
+ if (collapse === ev.detail._source) {
108
+ return;
109
+ }
110
+ }
111
+ this.close();
112
+ });
113
+ }
114
+ }
115
+
116
+ /**
117
+ * opens the collapsible section
118
+ */
119
+ open() {
120
+ if (this.opened) {
121
+ return;
122
+ }
123
+ this.opened = true;
124
+
125
+ this.emitTo('pb-collapse-open', this);
126
+ }
127
+
128
+ /**
129
+ * closes the collapsible section
130
+ */
131
+ close() {
132
+ if (this.opened) {
133
+ this.opened = false;
134
+ }
135
+ }
136
+
137
+ /**
138
+ * toggles the collapsible state
139
+ */
140
+ toggle() {
141
+ this.opened = !this.opened;
142
+ if (this.opened) {
143
+ this.emitTo('pb-collapse-open', this.data);
144
+ }
145
+ }
146
+
147
+ render() {
148
+ return html`
149
+ <div id="trigger" @click="${this.toggle}" class="collapse-trigger">
150
+ ${
151
+ !this.noIcons ?
152
+ html`<iron-icon icon="${this.opened ? this.collapseIcon : this.expandIcon}"></iron-icon>` :
153
+ null
154
+ }
155
+ <slot id="collapseTrigger" name="collapse-trigger"></slot>
156
+ </div>
157
+ <iron-collapse id="collapse" horizontal="${this.horizontal}" no-animation="${this.noAnimation}" .opened="${this.opened}">
158
+ <slot name="collapse-content"></slot>
159
+ </iron-collapse>
160
+ `;
161
+ }
162
+
163
+ static get styles() {
164
+ return css`
165
+ :host {
166
+ display: block;
167
+ }
168
+
169
+ #trigger {
170
+ display: table-row;
171
+ }
172
+
173
+ #trigger iron-icon {
174
+ display: table-cell;
175
+ padding: var(--pb-collapse-icon-padding, 0 4px 0 0);
176
+ }
177
+
178
+ slot[name="collapse-trigger"] {
179
+ display: table-cell;
180
+ }
181
+ `;
182
+ }
183
+ }
183
184
  customElements.define('pb-collapse', PbCollapse);