@kubex/zinc 1.0.14 → 1.0.15

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.
@@ -9,7 +9,17 @@ layout: component
9
9
 
10
10
  <zn-note color="gray">
11
11
  <span slot="caption">The caption</span>
12
- <span>The body</span>
12
+ <div slot="snippet">This is a short version of the below.</div>
13
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam, autem deleniti, dolore dolores ea enim fugit
14
+ harum incidunt minima numquam possimus praesentium quaerat quasi sequi sunt temporibus ut velit, veniam. Aut dolor
15
+ eius quae. Consequatur deleniti ipsum itaque pariatur ullam velit! Alias aut delectus dolores esse fuga iure laborum
16
+ magnam maiores minima, minus, natus placeat provident quasi ratione ullam ut? Fugit nisi placeat quidem suscipit
17
+ voluptatum? Adipisci aspernatur assumenda consequatur dolore ea esse exercitationem ipsum maiores minima neque saepe,
18
+ voluptates voluptatibus! A ab adipisci consequatur, esse eveniet itaque sed soluta! Aliquid animi blanditiis dolores
19
+ dolorum eum facere fugit harum id illo, laboriosam laborum libero magni minus natus nihil perspiciatis porro quae
20
+ quisquam, ratione rem repellat sequi sit suscipit voluptas voluptatum. Atque delectus eos fugit illo sit soluta
21
+ suscipit vero? At consectetur culpa dolor, dolores ea earum enim error et expedita iste laudantium nam necessitatibus
22
+ quaerat, quis sed tempora vel voluptatum?
13
23
  <span slot="date">
14
24
  <small>11/10/24</small>
15
25
  </span>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubex/zinc",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
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",
@@ -158,6 +158,7 @@ export default class ZnDataTable extends ZincElement {
158
158
  @property({attribute: 'data', type: Object, reflect: true}) data: any;
159
159
  @property({attribute: 'sort-column'}) sortColumn: string;
160
160
  @property({attribute: 'sort-direction'}) sortDirection: string = "asc";
161
+ @property({attribute: 'local-sort', type: Boolean}) localSort: boolean = false;
161
162
  @property({attribute: 'filter'}) filter: string = '';
162
163
  @property({attribute: 'wide-column'}) wideColumn: string;
163
164
  @property({attribute: 'key'}) key: string = 'id';
@@ -813,7 +814,13 @@ export default class ZnDataTable extends ZincElement {
813
814
  return () => {
814
815
  this.sortColumn = key;
815
816
  this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc';
816
- this._dataTask.run().then(r => r);
817
+
818
+ if (this.localSort) {
819
+ this._rows = this.sortLocalData(this._rows as Row[]);
820
+ this.requestUpdate();
821
+ } else {
822
+ this._dataTask.run().then(r => r);
823
+ }
817
824
  };
818
825
  }
819
826
 
@@ -1051,23 +1058,11 @@ export default class ZnDataTable extends ZincElement {
1051
1058
  }
1052
1059
 
1053
1060
  private getRows(data: Response): Row[] {
1054
- const sourceRows = data.rows;
1055
-
1056
- if (this.sortColumn) {
1057
- const headerKeys = Object.keys(this.headers);
1058
- const sortIndex = headerKeys.indexOf(this.sortColumn);
1059
-
1060
- sourceRows.sort((rowA: Row, rowB: Row) => {
1061
- const getCellForSort = (row: Row): Cell => {
1062
- const byHeading = row.cells.find((cell: Cell) => cell.column === this.sortColumn);
1063
- if (byHeading !== undefined) return byHeading as unknown as Cell;
1064
- return row.cells[sortIndex];
1065
- };
1066
-
1067
- const aVal = getCellForSort(rowA);
1068
- const bVal = getCellForSort(rowB);
1069
- return this.sortData(aVal, bVal);
1070
- });
1061
+ // Copy rows to avoid mutating original data
1062
+ const sourceRows = Array.isArray(data.rows) ? data.rows.slice() : [];
1063
+
1064
+ if (this.localSort && this.sortColumn) {
1065
+ return this.sortLocalData(sourceRows);
1071
1066
  }
1072
1067
 
1073
1068
  return sourceRows;
@@ -1136,6 +1131,25 @@ export default class ZnDataTable extends ZincElement {
1136
1131
  return aNormal < bNormal ? 1 : aNormal > bNormal ? -1 : 0;
1137
1132
  }
1138
1133
 
1134
+ private sortLocalData(rows: Row[]): Row[] {
1135
+ if (!this.sortColumn) return rows;
1136
+
1137
+ const headerKeys = Object.keys(this.headers);
1138
+ const sortIndex = headerKeys.indexOf(this.sortColumn);
1139
+
1140
+ const getCellForSort = (row: Row): Cell => {
1141
+ const byHeading = row.cells.find((cell: Cell) => cell.column === this.sortColumn);
1142
+ if (byHeading !== undefined) return byHeading as unknown as Cell;
1143
+ return row.cells[sortIndex];
1144
+ };
1145
+
1146
+ return rows.slice().sort((rowA: Row, rowB: Row) => {
1147
+ const aVal = getCellForSort(rowA);
1148
+ const bVal = getCellForSort(rowB);
1149
+ return this.sortData(aVal, bVal);
1150
+ });
1151
+ }
1152
+
1139
1153
  private loadingTable() {
1140
1154
  return html`
1141
1155
  <div class="table-container">
@@ -1,5 +1,5 @@
1
- import {property} from 'lit/decorators.js';
2
1
  import {type CSSResultGroup, html, unsafeCSS} from 'lit';
2
+ import {property} from 'lit/decorators.js';
3
3
  import ZincElement from '../../internal/zinc-element';
4
4
 
5
5
  import styles from './filter-container.scss';
@@ -5,6 +5,7 @@ import {property, state} from "lit/decorators.js";
5
5
  import ZincElement from '../../internal/zinc-element';
6
6
 
7
7
  import styles from './note.scss';
8
+ import {HasSlotController} from "../../internal/slot";
8
9
 
9
10
  /**
10
11
  * @summary Short summary of the component's intended use.
@@ -32,36 +33,19 @@ export default class ZnNote extends ZincElement {
32
33
  @property({reflect: true}) date: string = '';
33
34
  @property({type: HTMLElement, reflect: true}) body: string = '';
34
35
 
35
- // Number of lines at which the note body collapses; 0 disables collapsing
36
- @property({type: Number, attribute: 'collapse-at-lines', reflect: true}) collapseAtLines: number = 3;
36
+ private readonly hasSlotController = new HasSlotController(this, 'caption', 'date', '[default]', 'snippet', 'footer');
37
37
 
38
- // Internal state: whether the body is currently expanded
39
- @state() private expanded = false;
38
+ @state()
39
+ private expanded: boolean = false;
40
40
 
41
- private _toggleExpand = () => {
41
+ private _toggleExpand(): void {
42
42
  this.expanded = !this.expanded;
43
- this.updateComplete.then(() => this._measureOverflow());
44
- }
45
-
46
- private _measureOverflow() {
47
- const container = this.shadowRoot?.querySelector('.note__body-container') as HTMLElement | null;
48
- if (!container || this.collapseAtLines <= 0) {
49
- return;
50
- }
51
-
52
- container.style.setProperty('--note-collapse-lines', String(this.collapseAtLines));
53
- container.classList.toggle('note__body--clamped', !this.expanded);
54
- }
55
-
56
- protected firstUpdated() {
57
- this._measureOverflow();
58
- }
59
-
60
- protected updated() {
61
- this._measureOverflow();
62
43
  }
63
44
 
64
45
  protected render(): unknown {
46
+ const showExpandableButton: boolean = this.hasSlotController.test('snippet')
47
+ && this.hasSlotController.test('[default]');
48
+
65
49
  return html`
66
50
  <div class="${classMap({
67
51
  'note': true,
@@ -80,15 +64,18 @@ export default class ZnNote extends ZincElement {
80
64
  <slot name="date" class="note__header__date">
81
65
  <small>${this.date}</small>
82
66
  </slot>
83
- <slot name="action"></slot>
84
- </div>
85
- <div class="${classMap({
86
- 'note__body-container': true,
87
- 'note__body--clamped': this.collapseAtLines > 0 && !this.expanded
88
- })}" style="--note-collapse-lines: ${this.collapseAtLines}">
89
- <slot class="note__body"></slot>
90
67
  </div>
91
- ${this.collapseAtLines > 0 ? html`
68
+
69
+ ${this.expanded && showExpandableButton ?
70
+ html`
71
+ <slot class="note__body"></slot>` :
72
+ html`
73
+ <slot name="snippet" class="note__snippet"></slot>`}
74
+
75
+ ${!showExpandableButton ? html`
76
+ <slot class="note__body"></slot>` : ' '}
77
+
78
+ ${!showExpandableButton ? '' : html`
92
79
  <div class="note__toggle">
93
80
  <zn-button color="transparent"
94
81
  size="content"
@@ -97,8 +84,7 @@ export default class ZnNote extends ZincElement {
97
84
  aria-expanded="${String(this.expanded)}">
98
85
  ${this.expanded ? 'Show less' : 'Show more'}
99
86
  </zn-button>
100
- </div>
101
- ` : ''}
87
+ </div>`}
102
88
  <slot name="footer" class="note__footer"></slot>
103
89
  </div>
104
90
  `;
@@ -64,6 +64,14 @@ $colors: (
64
64
  padding: 0;
65
65
  }
66
66
 
67
+ &__body--clamped {
68
+ display: -webkit-box;
69
+ -webkit-box-orient: vertical;
70
+ -webkit-line-clamp: var(--note-collapse-lines, 0);
71
+ overflow: hidden;
72
+ text-overflow: ellipsis;
73
+ }
74
+
67
75
  @each $name, $color in $colors {
68
76
  &--#{'' + $name} {
69
77
  .note__header__caption {