@nectary/components 4.8.1 → 4.8.2
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 +1 -1
- package/tag/index.d.ts +1 -0
- package/tag/index.js +18 -1
- package/tag/types.d.ts +6 -0
package/package.json
CHANGED
package/tag/index.d.ts
CHANGED
package/tag/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import '../text';
|
|
2
|
+
import '../tooltip';
|
|
2
3
|
import { defineCustomElement, getBooleanAttribute, getAttribute, updateBooleanAttribute, updateAttribute, NectaryElement, isAttrTrue, isAttrEqual } from '../utils';
|
|
3
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;flex-direction:row;align-items:center;gap:4px;width:100%;height:var(--sinch-comp-tag-size-container-m);padding:0 9px;border-radius:var(--sinch-comp-tag-shape-radius);background-color:var(--sinch-comp-tag-color-default-background);box-sizing:border-box;user-select:none;--sinch-global-color-text:var(--sinch-comp-tag-color-default-foreground);--sinch-global-color-icon:var(--sinch-comp-tag-color-default-foreground);--sinch-global-size-icon:var(--sinch-comp-tag-size-icon-m)}:host([small]) #wrapper{height:var(--sinch-comp-tag-size-container-s);padding:0 8px;--sinch-global-size-icon:var(--sinch-comp-tag-size-icon-s)}#text{flex:1;--sinch-comp-text-font:var(--sinch-comp-tag-font-size-m-label)}:host([small]) #text{--sinch-comp-text-font:var(--sinch-comp-tag-font-size-s-label)}::slotted(*){margin-left:-4px}</style><div id="wrapper"><slot name="icon"></slot><sinch-text id="text" type="s" ellipsis></sinch-text></div>';
|
|
4
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}:host([ellipsis]){display:inline}#wrapper{display:flex;flex-direction:row;align-items:center;gap:4px;width:100%;height:var(--sinch-comp-tag-size-container-m);padding:0 9px;border-radius:var(--sinch-comp-tag-shape-radius);background-color:var(--sinch-comp-tag-color-default-background);box-sizing:border-box;user-select:none;--sinch-global-color-text:var(--sinch-comp-tag-color-default-foreground);--sinch-global-color-icon:var(--sinch-comp-tag-color-default-foreground);--sinch-global-size-icon:var(--sinch-comp-tag-size-icon-m)}:host([small]) #wrapper{height:var(--sinch-comp-tag-size-container-s);padding:0 8px;--sinch-global-size-icon:var(--sinch-comp-tag-size-icon-s)}#text{flex:1;--sinch-comp-text-font:var(--sinch-comp-tag-font-size-m-label)}:host([small]) #text{--sinch-comp-text-font:var(--sinch-comp-tag-font-size-s-label)}::slotted(*){margin-left:-4px}</style><sinch-tooltip id="tooltip" type="fast"><div id="wrapper"><slot name="icon"></slot><sinch-text id="text" type="s" ellipsis></sinch-text></div></sinch-tooltip>';
|
|
4
5
|
import { getTagColorBg, getTagColorFg } from './utils';
|
|
5
6
|
const template = document.createElement('template');
|
|
6
7
|
template.innerHTML = templateHTML;
|
|
7
8
|
defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
8
9
|
#$text;
|
|
10
|
+
#$tooltip;
|
|
9
11
|
#$wrapper;
|
|
10
12
|
constructor() {
|
|
11
13
|
super();
|
|
@@ -13,10 +15,12 @@ defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
|
13
15
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
14
16
|
this.#$wrapper = shadowRoot.querySelector('#wrapper');
|
|
15
17
|
this.#$text = shadowRoot.querySelector('#text');
|
|
18
|
+
this.#$tooltip = shadowRoot.querySelector('#tooltip');
|
|
16
19
|
}
|
|
17
20
|
connectedCallback() {
|
|
18
21
|
super.connectedCallback();
|
|
19
22
|
this.#updateColor();
|
|
23
|
+
this.#updateEllipsisTooltip();
|
|
20
24
|
}
|
|
21
25
|
disconnectedCallback() {
|
|
22
26
|
super.disconnectedCallback();
|
|
@@ -32,6 +36,7 @@ defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
|
32
36
|
}
|
|
33
37
|
set text(value) {
|
|
34
38
|
updateAttribute(this, 'text', value);
|
|
39
|
+
updateAttribute(this.#$tooltip, 'text', value);
|
|
35
40
|
}
|
|
36
41
|
get small() {
|
|
37
42
|
return getBooleanAttribute(this, 'small');
|
|
@@ -55,6 +60,7 @@ defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
|
55
60
|
case 'text':
|
|
56
61
|
{
|
|
57
62
|
this.#$text.textContent = newVal;
|
|
63
|
+
this.#updateEllipsisTooltip();
|
|
58
64
|
break;
|
|
59
65
|
}
|
|
60
66
|
case 'small':
|
|
@@ -81,4 +87,15 @@ defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
|
81
87
|
this.#$wrapper.style.removeProperty('--sinch-global-color-icon');
|
|
82
88
|
}
|
|
83
89
|
}
|
|
90
|
+
#updateEllipsisTooltip() {
|
|
91
|
+
const ellipsis = getBooleanAttribute(this, 'ellipsis');
|
|
92
|
+
requestAnimationFrame(() => {
|
|
93
|
+
const hasOverflow = this.#$text.offsetWidth < this.#$text.scrollWidth;
|
|
94
|
+
if (ellipsis && hasOverflow) {
|
|
95
|
+
updateAttribute(this.#$tooltip, 'text', this.text);
|
|
96
|
+
} else {
|
|
97
|
+
updateAttribute(this.#$tooltip, 'text', '');
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
84
101
|
});
|
package/tag/types.d.ts
CHANGED
|
@@ -8,12 +8,16 @@ export type TSinchTagElement = HTMLElement & {
|
|
|
8
8
|
color: TSinchTagColor | null;
|
|
9
9
|
/** Small */
|
|
10
10
|
small: boolean;
|
|
11
|
+
/** Ellipsis */
|
|
12
|
+
ellipsis: boolean;
|
|
11
13
|
/** Text */
|
|
12
14
|
setAttribute(name: 'text', value: string): void;
|
|
13
15
|
/** Color, gray by default */
|
|
14
16
|
setAttribute(name: 'color', value: string): void;
|
|
15
17
|
/** Small */
|
|
16
18
|
setAttribute(name: 'small', value: ''): void;
|
|
19
|
+
/** Ellipsis */
|
|
20
|
+
setAttribute(name: 'ellipsis', value: ''): void;
|
|
17
21
|
};
|
|
18
22
|
export type TSinchTagReact = TSinchElementReact<TSinchTagElement> & {
|
|
19
23
|
/** Text */
|
|
@@ -22,6 +26,8 @@ export type TSinchTagReact = TSinchElementReact<TSinchTagElement> & {
|
|
|
22
26
|
color?: TSinchTagColor;
|
|
23
27
|
/** Small */
|
|
24
28
|
small?: boolean;
|
|
29
|
+
/** Ellipsis */
|
|
30
|
+
ellipsis?: boolean;
|
|
25
31
|
} & {
|
|
26
32
|
style?: {
|
|
27
33
|
'--sinch-comp-tag-size-container-m'?: string;
|