@kubex/zinc 1.1.170 → 1.1.171

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.
@@ -139,6 +139,55 @@ Button groups work with all button variants including colors and styles.
139
139
  </zn-button-group>
140
140
  ```
141
141
 
142
+ ### Panel Background
143
+
144
+ Use the `panel-bg` attribute to give every button in the group the icon button look: a panel background with a border, text-coloured labels and a tinted hover. Color variants tint the label and icon instead of filling the button.
145
+
146
+ ```html:preview
147
+ <zn-button-group panel-bg>
148
+ <zn-button icon="format_bold"></zn-button>
149
+ <zn-button icon="format_italic"></zn-button>
150
+ <zn-button icon="format_underlined"></zn-button>
151
+ </zn-button-group>
152
+
153
+ <br />
154
+ <br />
155
+
156
+ <zn-button-group panel-bg>
157
+ <zn-button icon="view_list">List</zn-button>
158
+ <zn-button icon="grid_view">Grid</zn-button>
159
+ <zn-button icon="delete" color="error">Delete</zn-button>
160
+ </zn-button-group>
161
+
162
+ <br />
163
+ <br />
164
+
165
+ <zn-button-group panel-bg gap>
166
+ <zn-button>Cancel</zn-button>
167
+ <zn-button>Save</zn-button>
168
+ </zn-button-group>
169
+ ```
170
+
171
+ Set `aria-pressed="true"` on the selected button to show it in its active colour, for segmented toggles.
172
+
173
+ ```html:preview
174
+ <zn-button-group panel-bg class="panel-bg-toggle">
175
+ <zn-button aria-pressed="false">Mine</zn-button>
176
+ <zn-button aria-pressed="true">Everyone</zn-button>
177
+ </zn-button-group>
178
+
179
+ <script type="module">
180
+ const group = document.querySelector('.panel-bg-toggle');
181
+ group.addEventListener('click', event => {
182
+ const clicked = event.target.closest('zn-button');
183
+ if (!clicked) return;
184
+ group.querySelectorAll('zn-button').forEach(button => {
185
+ button.setAttribute('aria-pressed', String(button === clicked));
186
+ });
187
+ });
188
+ </script>
189
+ ```
190
+
142
191
  ### With Icons
143
192
 
144
193
  Button groups work seamlessly with icon buttons.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubex/zinc",
3
- "version": "1.1.170",
3
+ "version": "1.1.171",
4
4
  "description": "A collection of web components for building web applications based off of @shoelace-style/Shoelace",
5
5
  "keywords": [
6
6
  "web components",
@@ -493,12 +493,12 @@
493
493
  }
494
494
 
495
495
  :host([data-zn-button-group__button--first]:not([data-zn-button-group__button--last])) .button {
496
- border-radius: 5px 0 0 5px !important;
496
+ border-radius: var(--zn-button-border-radius, var(--zn-border-radius)) 0 0 var(--zn-button-border-radius, var(--zn-border-radius)) !important;
497
497
  border-right: 0 !important;
498
498
  }
499
499
 
500
500
  :host([data-zn-button-group__button--last]:not([data-zn-button-group__button--first])) .button {
501
- border-radius: 0 5px 5px 0 !important;
501
+ border-radius: 0 var(--zn-button-border-radius, var(--zn-border-radius)) var(--zn-button-border-radius, var(--zn-border-radius)) 0 !important;
502
502
  border-left: 0 !important;
503
503
  }
504
504
 
@@ -513,12 +513,32 @@
513
513
  white-space: nowrap;
514
514
  }
515
515
 
516
- .button--panel-bg {
516
+ // The icon-button look on a regular button: color variants tint the ink only
517
+ @mixin panel-bg {
517
518
  background: rgb(var(--zn-panel));
518
519
  border-color: var(--zn-button-border-color, rgb(var(--zn-border-color)));
519
520
  color: rgb(var(--zn-text));
520
521
 
522
+ &.button--error, &.button--info, &.button--success, &.button--warning {
523
+ color: rgb(var(--btn-color));
524
+ }
525
+
521
526
  &:hover:not([disabled]), &:active:not([disabled]) {
522
527
  background: rgba(var(--zn-color-tab), 0.5);
523
528
  }
529
+
530
+ &[aria-pressed="true"] {
531
+ &, &:hover:not([disabled]), &:active:not([disabled]) {
532
+ background: rgba(var(--btn-color), 0.1);
533
+ color: rgb(var(--btn-color));
534
+ }
535
+ }
536
+ }
537
+
538
+ .button--panel-bg {
539
+ @include panel-bg;
540
+ }
541
+
542
+ :host([data-zn-button-group__button--panel-bg]) .button:not(.button--icon-button) {
543
+ @include panel-bg;
524
544
  }
@@ -1,5 +1,5 @@
1
1
  import {classMap} from "lit/directives/class-map.js";
2
- import {type CSSResultGroup, html, unsafeCSS} from 'lit';
2
+ import {type CSSResultGroup, html, type PropertyValues, unsafeCSS} from 'lit';
3
3
  import {property, query} from 'lit/decorators.js';
4
4
  import ZincElement from '../../internal/zinc-element';
5
5
 
@@ -30,18 +30,27 @@ export default class ZnButtonGroup extends ZincElement {
30
30
  @property({type: Boolean}) wrap = false;
31
31
  @property({type: Boolean}) start = false;
32
32
  @property({type: Boolean}) gap = false;
33
+ /** Gives every button in the group the icon-button look: panel background,
34
+ * border, text-colored ink and a tab-tint hover. */
35
+ @property({type: Boolean, attribute: 'panel-bg'}) panelBackground = false;
33
36
 
34
37
  @query('slot') defaultSlot: HTMLSlotElement;
35
38
 
39
+ protected updated(changed: PropertyValues<this>) {
40
+ if (changed.has('panelBackground')) {
41
+ this.handleSlotChange();
42
+ }
43
+ }
44
+
36
45
  private handleSlotChange() {
37
- if (this.direction === 'vertical') {
46
+ if (!this.defaultSlot) {
38
47
  return;
39
48
  }
40
49
 
41
50
  const allSlotted = [...this.defaultSlot.assignedElements({flatten: true})] as HTMLElement[];
42
51
 
43
52
  // Collect buttons from direct zn-button elements and from zn-dropdown wrappers
44
- const groupItems: {button: HTMLElement; wrapper?: HTMLElement}[] = [];
53
+ const groupItems: { button: HTMLElement; wrapper?: HTMLElement }[] = [];
45
54
  for (const el of allSlotted) {
46
55
  if (el.tagName === 'ZN-BUTTON') {
47
56
  groupItems.push({button: el});
@@ -53,6 +62,14 @@ export default class ZnButtonGroup extends ZincElement {
53
62
  }
54
63
  }
55
64
 
65
+ groupItems.forEach(({button}) => {
66
+ button.toggleAttribute('data-zn-button-group__button--panel-bg', this.panelBackground);
67
+ });
68
+
69
+ if (this.direction === 'vertical') {
70
+ return;
71
+ }
72
+
56
73
  groupItems.forEach(({button, wrapper}, index) => {
57
74
  button.toggleAttribute('data-zn-button-group__button--grow', this.grow);
58
75
 
@@ -7,4 +7,22 @@ describe('<zn-button-group>', () => {
7
7
 
8
8
  expect(el).to.exist;
9
9
  });
10
+
11
+ it('marks slotted buttons with panel-bg and clears it when removed', async () => {
12
+ const el = await fixture<HTMLElement & {panelBackground: boolean; updateComplete: Promise<boolean>}>(html`
13
+ <zn-button-group panel-bg>
14
+ <zn-button>One</zn-button>
15
+ <zn-button>Two</zn-button>
16
+ </zn-button-group>
17
+ `);
18
+ await el.updateComplete;
19
+ const buttons = [...el.querySelectorAll('zn-button')];
20
+
21
+ expect(buttons.every(b => b.hasAttribute('data-zn-button-group__button--panel-bg'))).to.be.true;
22
+
23
+ el.panelBackground = false;
24
+ await el.updateComplete;
25
+
26
+ expect(buttons.some(b => b.hasAttribute('data-zn-button-group__button--panel-bg'))).to.be.false;
27
+ });
10
28
  });