@kubex/zinc 1.1.7 → 1.1.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubex/zinc",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
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",
@@ -1,9 +1,9 @@
1
- import {property} from 'lit/decorators.js';
1
+ import {classMap} from "lit/directives/class-map.js";
2
2
  import {type CSSResultGroup, html, unsafeCSS} from 'lit';
3
+ import {property} from 'lit/decorators.js';
3
4
  import ZincElement from '../../internal/zinc-element';
4
5
 
5
6
  import styles from './reveal.scss';
6
- import {classMap} from "lit/directives/class-map.js";
7
7
 
8
8
  /**
9
9
  * @summary Short summary of the component's intended use.
@@ -39,10 +39,27 @@ export default class ZnReveal extends ZincElement {
39
39
 
40
40
  @property() revealed: string = '';
41
41
 
42
+ @property({type: Number, attribute: 'hide-delay'}) hideDelay: number = 150;
43
+
42
44
  private _isRevealed: boolean = false;
43
45
  private _isToggled: boolean = false;
46
+ private _hideTimer?: ReturnType<typeof setTimeout>;
47
+
48
+ disconnectedCallback() {
49
+ super.disconnectedCallback();
50
+ this._clearHideTimer();
51
+ }
52
+
53
+ private _clearHideTimer() {
54
+ if (this._hideTimer) {
55
+ clearTimeout(this._hideTimer);
56
+ this._hideTimer = undefined;
57
+ }
58
+ }
44
59
 
45
60
  protected handleToggleReveal() {
61
+ this._clearHideTimer();
62
+
46
63
  if (this.duration) {
47
64
  this._isRevealed = true;
48
65
  this._isToggled = true;
@@ -63,16 +80,20 @@ export default class ZnReveal extends ZincElement {
63
80
 
64
81
  protected handleMouseEnter() {
65
82
  // handle hover only while hovered
83
+ this._clearHideTimer();
66
84
  this._isRevealed = true;
67
85
  this.requestUpdate();
68
86
  }
69
87
 
70
88
  protected handleMouseLeave() {
71
- if (this._isToggled) {
72
- return;
73
- }
74
- this._isRevealed = false;
75
- this.requestUpdate();
89
+ if (this._isToggled) return;
90
+
91
+ this._clearHideTimer();
92
+ this._hideTimer = setTimeout(() => {
93
+ this._hideTimer = undefined;
94
+ this._isRevealed = false;
95
+ this.requestUpdate();
96
+ }, this.hideDelay);
76
97
  }
77
98
 
78
99
  render() {
@@ -85,7 +106,8 @@ export default class ZnReveal extends ZincElement {
85
106
  @click="${this.handleToggleReveal}"
86
107
  @mouseenter="${this.handleMouseEnter}"
87
108
  @mouseleave="${this.handleMouseLeave}">
88
- ${this._isRevealed ? this.revealed : this.initial}
109
+ <span class="reveal__text reveal__text--initial">${this.initial}</span>
110
+ <span class="reveal__text reveal__text--revealed">${this.revealed}</span>
89
111
  </div>
90
112
  `;
91
113
  }
@@ -7,10 +7,40 @@
7
7
 
8
8
 
9
9
  .reveal {
10
+ display: inline-grid;
11
+ grid-template-areas: "stack";
12
+ align-items: center;
13
+ overflow: hidden;
10
14
  }
11
15
 
12
- .reveal--revealed{
13
- // reveal is showing
16
+ .reveal__text {
17
+ grid-area: stack;
18
+ line-height: 1.4;
19
+ transition: opacity 0.2s ease,
20
+ transform 0.2s ease;
21
+ will-change: opacity, transform;
22
+ }
23
+
24
+ .reveal__text--initial {
25
+ opacity: 1;
26
+ transform: translateY(0);
27
+ }
28
+
29
+ .reveal__text--revealed {
30
+ opacity: 0;
31
+ transform: translateY(0.5em);
32
+ }
33
+
34
+ .reveal--revealed {
35
+ .reveal__text--initial {
36
+ opacity: 0;
37
+ transform: translateY(-0.5em);
38
+ }
39
+
40
+ .reveal__text--revealed {
41
+ opacity: 1;
42
+ transform: translateY(0);
43
+ }
14
44
  }
15
45
 
16
46
  .reveal--toggled {