@kubex/zinc 1.0.13 → 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.
@@ -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 {
@@ -90,7 +90,9 @@ export default class ZnTile extends ZincElement {
90
90
  <div class="tile__left">
91
91
  <slot name="image" part="image" class="tile__image"></slot>
92
92
  <div class="tile__content">
93
- <p part="caption" class="tile__caption">${this.caption}</p>
93
+ <p part="caption" class="tile__caption">
94
+ <slot name="caption">${this.caption}</slot>
95
+ </p>
94
96
  <p part="description" class="tile__description">${this.description}</p>
95
97
  </div>
96
98
  </div>