@nectary/components 0.41.0 → 0.42.0
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/accordion/index.js +0 -16
- package/accordion/types.d.ts +9 -1
- package/accordion-item/index.js +0 -24
- package/accordion-item/types.d.ts +18 -3
- package/action-menu/index.js +1 -45
- package/action-menu-option/index.js +0 -18
- package/alert/index.js +0 -10
- package/alert/types.d.ts +6 -0
- package/avatar/index.js +57 -20
- package/avatar/types.d.ts +25 -7
- package/avatar/utils.d.ts +10 -2
- package/avatar/utils.js +23 -2
- package/badge/index.d.ts +11 -0
- package/badge/index.js +140 -0
- package/badge/types.d.ts +38 -0
- package/badge/utils.d.ts +11 -0
- package/badge/utils.js +23 -0
- package/button/index.js +0 -18
- package/card/index.js +0 -16
- package/card/types.d.ts +15 -3
- package/card-container/index.js +0 -1
- package/chat/index.js +0 -1
- package/chat-block/index.js +0 -19
- package/chat-block/types.d.ts +16 -4
- package/chat-bubble/index.js +0 -9
- package/chat-bubble/types.d.ts +6 -0
- package/checkbox/index.js +0 -23
- package/chip/index.js +16 -25
- package/chip/utils.d.ts +3 -0
- package/chip/utils.js +11 -0
- package/color-menu/index.js +8 -86
- package/color-menu/utils.js +0 -4
- package/color-swatch/index.js +17 -17
- package/color-swatch/types.d.ts +2 -2
- package/color-swatch/utils.d.ts +3 -0
- package/color-swatch/utils.js +11 -0
- package/date-picker/index.js +1 -50
- package/date-picker/utils.js +0 -7
- package/dialog/index.js +1 -17
- package/field/index.js +0 -19
- package/file-drop/index.js +0 -40
- package/file-drop/utils.js +0 -6
- package/file-picker/index.js +0 -17
- package/file-picker/utils.js +0 -1
- package/file-status/index.js +0 -12
- package/grid/index.js +0 -1
- package/grid-item/index.js +0 -9
- package/help-tooltip/index.js +0 -14
- package/horizontal-stepper/index.js +0 -12
- package/horizontal-stepper-item/index.js +0 -14
- package/icon-button/index.js +0 -15
- package/icons/create-icon-class.js +0 -2
- package/icons-branded/create-icon-class.js +0 -8
- package/icons-channel/create-icon-class.js +0 -6
- package/illustrations/create-illustration-class.js +0 -11
- package/inline-alert/index.js +0 -14
- package/input/index.js +0 -37
- package/link/index.js +0 -25
- package/list/index.js +0 -2
- package/list-item/index.js +0 -2
- package/logo/create-logo-class.js +0 -9
- package/package.json +1 -1
- package/pagination/index.js +0 -31
- package/pop/index.js +64 -68
- package/pop/utils.js +0 -1
- package/popover/index.js +0 -33
- package/popover/utils.js +0 -2
- package/progress/index.js +0 -10
- package/radio/index.js +0 -30
- package/radio-option/index.js +0 -20
- package/segment/index.js +0 -15
- package/segment-collapse/index.js +0 -13
- package/segmented-control/index.js +0 -12
- package/segmented-control-option/index.js +0 -18
- package/segmented-icon-control/index.js +0 -16
- package/segmented-icon-control-option/index.js +0 -14
- package/select-button/index.js +0 -23
- package/select-menu/index.js +1 -63
- package/select-menu-option/index.js +0 -14
- package/spinner/index.js +0 -4
- package/stop-events/index.js +0 -5
- package/table/index.js +0 -2
- package/table-body/index.js +0 -2
- package/table-cell/index.js +0 -4
- package/table-head/index.js +0 -2
- package/table-head-cell/index.js +0 -11
- package/table-row/index.js +0 -6
- package/tabs/index.js +0 -30
- package/tabs-option/index.js +0 -19
- package/tag/index.js +18 -21
- package/tag/utils.d.ts +3 -0
- package/tag/utils.js +11 -0
- package/text/index.js +1 -12
- package/textarea/index.js +0 -40
- package/{utils → theme}/colors.d.ts +0 -1
- package/{utils → theme}/colors.js +0 -1
- package/theme.css +13 -209
- package/tile-control/index.js +0 -24
- package/tile-control-option/index.js +0 -18
- package/time-picker/index.js +2 -51
- package/time-picker/utils.js +0 -18
- package/title/index.js +1 -12
- package/title/utils.js +0 -5
- package/toast/index.js +0 -19
- package/toast-manager/index.js +0 -27
- package/toggle/index.js +0 -23
- package/tooltip/index.js +0 -27
- package/tooltip/utils.js +0 -4
- package/utils/animation.js +0 -20
- package/utils/context.js +0 -6
- package/utils/index.d.ts +1 -0
- package/utils/index.js +11 -52
- package/vertical-stepper/index.js +0 -12
- package/vertical-stepper-item/index.js +0 -14
- package/avatar-badge/index.d.ts +0 -11
- package/avatar-badge/index.js +0 -38
- package/avatar-badge/types.d.ts +0 -8
- package/avatar-status/index.d.ts +0 -11
- package/avatar-status/index.js +0 -37
- package/avatar-status/types.d.ts +0 -9
- package/avatar-status/types.js +0 -1
- package/avatar-status/utils.d.ts +0 -5
- package/avatar-status/utils.js +0 -6
- package/chat-avatar/index.d.ts +0 -12
- package/chat-avatar/index.js +0 -52
- package/chat-avatar/types.d.ts +0 -12
- package/chat-avatar/types.js +0 -1
- /package/{avatar-badge → badge}/types.js +0 -0
package/table-body/index.js
CHANGED
|
@@ -8,9 +8,7 @@ defineCustomElement('sinch-table-body', class extends NectaryElement {
|
|
|
8
8
|
const shadowRoot = this.attachShadow();
|
|
9
9
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
connectedCallback() {
|
|
13
12
|
this.setAttribute('role', 'rowgroup');
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
});
|
package/table-cell/index.js
CHANGED
|
@@ -9,17 +9,13 @@ defineCustomElement('sinch-table-cell', class extends NectaryElement {
|
|
|
9
9
|
const shadowRoot = this.attachShadow();
|
|
10
10
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
11
11
|
}
|
|
12
|
-
|
|
13
12
|
connectedCallback() {
|
|
14
13
|
this.setAttribute('role', 'cell');
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
set align(value) {
|
|
18
16
|
updateLiteralAttribute(this, alignValues, 'align', value);
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
get align() {
|
|
22
19
|
return getLiteralAttribute(this, alignValues, 'align', 'start');
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
});
|
package/table-head/index.js
CHANGED
|
@@ -8,9 +8,7 @@ defineCustomElement('sinch-table-head', class extends NectaryElement {
|
|
|
8
8
|
const shadowRoot = this.attachShadow();
|
|
9
9
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
connectedCallback() {
|
|
13
12
|
this.setAttribute('role', 'rowgroup');
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
});
|
package/table-head-cell/index.js
CHANGED
|
@@ -5,23 +5,19 @@ const template = document.createElement('template');
|
|
|
5
5
|
template.innerHTML = templateHTML;
|
|
6
6
|
defineCustomElement('sinch-table-head-cell', class extends NectaryElement {
|
|
7
7
|
#$text;
|
|
8
|
-
|
|
9
8
|
constructor() {
|
|
10
9
|
super();
|
|
11
10
|
const shadowRoot = this.attachShadow();
|
|
12
11
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
13
12
|
this.#$text = shadowRoot.querySelector('#text');
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
connectedCallback() {
|
|
17
15
|
this.setAttribute('role', 'columnheader');
|
|
18
16
|
this.setAttribute('scope', 'col');
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
static get observedAttributes() {
|
|
22
19
|
return ['text'];
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
26
22
|
switch (name) {
|
|
27
23
|
case 'text':
|
|
@@ -31,29 +27,22 @@ defineCustomElement('sinch-table-head-cell', class extends NectaryElement {
|
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
set text(value) {
|
|
36
31
|
updateAttribute(this, 'text', value);
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
get text() {
|
|
40
34
|
return getAttribute(this, 'text');
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
set align(value) {
|
|
44
37
|
updateLiteralAttribute(this, alignValues, 'align', value);
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
get align() {
|
|
48
40
|
return getLiteralAttribute(this, alignValues, 'align', 'start');
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
set fit(isFit) {
|
|
52
43
|
updateBooleanAttribute(this, 'fit', isFit);
|
|
53
44
|
}
|
|
54
|
-
|
|
55
45
|
get fit() {
|
|
56
46
|
return getBooleanAttribute(this, 'fit');
|
|
57
47
|
}
|
|
58
|
-
|
|
59
48
|
});
|
package/table-row/index.js
CHANGED
|
@@ -8,25 +8,19 @@ defineCustomElement('sinch-table-row', class extends NectaryElement {
|
|
|
8
8
|
const shadowRoot = this.attachShadow();
|
|
9
9
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
connectedCallback() {
|
|
13
12
|
this.setAttribute('role', 'row');
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
set sticky(isSticky) {
|
|
17
15
|
updateBooleanAttribute(this, 'sticky', isSticky);
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
get sticky() {
|
|
21
18
|
return getBooleanAttribute(this, 'sticky');
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
set selected(isSelected) {
|
|
25
21
|
updateBooleanAttribute(this, 'selected', isSelected);
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
get selected() {
|
|
29
24
|
return getBooleanAttribute(this, 'selected');
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
});
|
package/tabs/index.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
2
|
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;height:44px;width:100%;box-sizing:border-box}</style><div id="wrapper"><slot></slot></div>';
|
|
3
|
-
|
|
4
3
|
const findSelectedOption = elements => {
|
|
5
4
|
return elements.find(el => el.checked) ?? null;
|
|
6
5
|
};
|
|
7
|
-
|
|
8
6
|
const template = document.createElement('template');
|
|
9
7
|
template.innerHTML = templateHTML;
|
|
10
8
|
defineCustomElement('sinch-tabs', class extends NectaryElement {
|
|
11
9
|
#$slot;
|
|
12
|
-
|
|
13
10
|
constructor() {
|
|
14
11
|
super();
|
|
15
12
|
const shadowRoot = this.attachShadow();
|
|
16
13
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
17
14
|
this.#$slot = shadowRoot.querySelector('slot');
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
connectedCallback() {
|
|
21
17
|
this.setAttribute('role', 'tablist');
|
|
22
18
|
this.#$slot.addEventListener('keydown', this.#onOptionKeyDown);
|
|
@@ -24,30 +20,24 @@ defineCustomElement('sinch-tabs', class extends NectaryElement {
|
|
|
24
20
|
this.#$slot.addEventListener('slotchange', this.#onSlotChange);
|
|
25
21
|
this.addEventListener('-change', this.#onChangeReactHandler);
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
disconnectedCallback() {
|
|
29
24
|
this.#$slot.removeEventListener('keydown', this.#onOptionKeyDown);
|
|
30
25
|
this.#$slot.removeEventListener('option-change', this.#onOptionChange);
|
|
31
26
|
this.#$slot.removeEventListener('slotchange', this.#onSlotChange);
|
|
32
27
|
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
static get observedAttributes() {
|
|
36
30
|
return ['value'];
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
get nodeName() {
|
|
40
33
|
return 'select';
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
set value(value) {
|
|
44
36
|
updateAttribute(this, 'value', value);
|
|
45
37
|
}
|
|
46
|
-
|
|
47
38
|
get value() {
|
|
48
39
|
return getAttribute(this, 'value', '');
|
|
49
40
|
}
|
|
50
|
-
|
|
51
41
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
52
42
|
switch (name) {
|
|
53
43
|
case 'value':
|
|
@@ -57,7 +47,6 @@ defineCustomElement('sinch-tabs', class extends NectaryElement {
|
|
|
57
47
|
}
|
|
58
48
|
}
|
|
59
49
|
}
|
|
60
|
-
|
|
61
50
|
#onOptionKeyDown = e => {
|
|
62
51
|
switch (e.code) {
|
|
63
52
|
case 'ArrowUp':
|
|
@@ -65,26 +54,21 @@ defineCustomElement('sinch-tabs', class extends NectaryElement {
|
|
|
65
54
|
{
|
|
66
55
|
e.preventDefault();
|
|
67
56
|
const $option = this.#getPrevOption();
|
|
68
|
-
|
|
69
57
|
if ($option !== null) {
|
|
70
58
|
$option.focus();
|
|
71
59
|
this.#dispatchChangeEvent($option.value);
|
|
72
60
|
}
|
|
73
|
-
|
|
74
61
|
break;
|
|
75
62
|
}
|
|
76
|
-
|
|
77
63
|
case 'ArrowDown':
|
|
78
64
|
case 'ArrowRight':
|
|
79
65
|
{
|
|
80
66
|
e.preventDefault();
|
|
81
67
|
const $option = this.#getNextOption();
|
|
82
|
-
|
|
83
68
|
if ($option !== null) {
|
|
84
69
|
$option.focus();
|
|
85
70
|
this.#dispatchChangeEvent($option.value);
|
|
86
71
|
}
|
|
87
|
-
|
|
88
72
|
break;
|
|
89
73
|
}
|
|
90
74
|
}
|
|
@@ -96,14 +80,12 @@ defineCustomElement('sinch-tabs', class extends NectaryElement {
|
|
|
96
80
|
e.stopPropagation();
|
|
97
81
|
this.#dispatchChangeEvent(e.detail);
|
|
98
82
|
};
|
|
99
|
-
|
|
100
83
|
#onValueChange(value) {
|
|
101
84
|
for (const $option of this.#$slot.assignedElements()) {
|
|
102
85
|
const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
|
|
103
86
|
updateBooleanAttribute($option, 'checked', isChecked);
|
|
104
87
|
}
|
|
105
88
|
}
|
|
106
|
-
|
|
107
89
|
#dispatchChangeEvent(value) {
|
|
108
90
|
this.dispatchEvent(new CustomEvent('change', {
|
|
109
91
|
detail: value,
|
|
@@ -113,55 +95,43 @@ defineCustomElement('sinch-tabs', class extends NectaryElement {
|
|
|
113
95
|
detail: value
|
|
114
96
|
}));
|
|
115
97
|
}
|
|
116
|
-
|
|
117
98
|
#getFirstOption() {
|
|
118
99
|
for (const $option of this.#$slot.assignedElements()) {
|
|
119
100
|
if ($option.disabled !== true) {
|
|
120
101
|
return $option;
|
|
121
102
|
}
|
|
122
103
|
}
|
|
123
|
-
|
|
124
104
|
return null;
|
|
125
105
|
}
|
|
126
|
-
|
|
127
106
|
#getLastOption() {
|
|
128
107
|
for (const $option of this.#$slot.assignedElements().reverse()) {
|
|
129
108
|
if ($option.disabled !== true) {
|
|
130
109
|
return $option;
|
|
131
110
|
}
|
|
132
111
|
}
|
|
133
|
-
|
|
134
112
|
return null;
|
|
135
113
|
}
|
|
136
|
-
|
|
137
114
|
#getNextOption() {
|
|
138
115
|
const $options = this.#getEnabledRadioElements();
|
|
139
116
|
const $selectedOption = findSelectedOption($options);
|
|
140
117
|
const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
|
|
141
|
-
|
|
142
118
|
if (currentIndex < 0) {
|
|
143
119
|
return this.#getFirstOption();
|
|
144
120
|
}
|
|
145
|
-
|
|
146
121
|
return $options[(currentIndex + 1) % $options.length];
|
|
147
122
|
}
|
|
148
|
-
|
|
149
123
|
#getPrevOption() {
|
|
150
124
|
const $options = this.#getEnabledRadioElements();
|
|
151
125
|
const $selectedOption = findSelectedOption($options);
|
|
152
126
|
const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
|
|
153
|
-
|
|
154
127
|
if (currentIndex < 0) {
|
|
155
128
|
return this.#getLastOption();
|
|
156
129
|
}
|
|
157
|
-
|
|
158
130
|
return $options[(currentIndex - 1 + $options.length) % $options.length];
|
|
159
131
|
}
|
|
160
|
-
|
|
161
132
|
#getEnabledRadioElements() {
|
|
162
133
|
return this.#$slot.assignedElements().filter(opt => opt.disabled !== true);
|
|
163
134
|
}
|
|
164
|
-
|
|
165
135
|
#onChangeReactHandler = e => {
|
|
166
136
|
getReactEventHandler(this, 'on-change')?.(e);
|
|
167
137
|
};
|
package/tabs-option/index.js
CHANGED
|
@@ -5,7 +5,6 @@ template.innerHTML = templateHTML;
|
|
|
5
5
|
defineCustomElement('sinch-tabs-option', class extends NectaryElement {
|
|
6
6
|
#$button;
|
|
7
7
|
#$label;
|
|
8
|
-
|
|
9
8
|
constructor() {
|
|
10
9
|
super();
|
|
11
10
|
const shadowRoot = this.attachShadow();
|
|
@@ -13,52 +12,40 @@ defineCustomElement('sinch-tabs-option', class extends NectaryElement {
|
|
|
13
12
|
this.#$button = shadowRoot.querySelector('#button');
|
|
14
13
|
this.#$label = shadowRoot.querySelector('#content');
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
connectedCallback() {
|
|
18
16
|
this.setAttribute('role', 'tab');
|
|
19
17
|
this.#$button.addEventListener('click', this.#onClick);
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
disconnectedCallback() {
|
|
23
20
|
this.#$button.removeEventListener('click', this.#onClick);
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
static get observedAttributes() {
|
|
27
23
|
return ['checked', 'disabled', 'text', 'value'];
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
set checked(isChecked) {
|
|
31
26
|
updateBooleanAttribute(this, 'checked', isChecked);
|
|
32
27
|
}
|
|
33
|
-
|
|
34
28
|
get checked() {
|
|
35
29
|
return getBooleanAttribute(this, 'checked');
|
|
36
30
|
}
|
|
37
|
-
|
|
38
31
|
set value(value) {
|
|
39
32
|
updateAttribute(this, 'value', value);
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
get value() {
|
|
43
35
|
return getAttribute(this, 'value', '');
|
|
44
36
|
}
|
|
45
|
-
|
|
46
37
|
set disabled(isDisabled) {
|
|
47
38
|
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
48
39
|
}
|
|
49
|
-
|
|
50
40
|
get disabled() {
|
|
51
41
|
return getBooleanAttribute(this, 'disabled');
|
|
52
42
|
}
|
|
53
|
-
|
|
54
43
|
set text(value) {
|
|
55
44
|
updateAttribute(this, 'text', value);
|
|
56
45
|
}
|
|
57
|
-
|
|
58
46
|
get text() {
|
|
59
47
|
return getAttribute(this, 'text', '');
|
|
60
48
|
}
|
|
61
|
-
|
|
62
49
|
attributeChangedCallback(name, _, newVal) {
|
|
63
50
|
switch (name) {
|
|
64
51
|
case 'text':
|
|
@@ -66,13 +53,11 @@ defineCustomElement('sinch-tabs-option', class extends NectaryElement {
|
|
|
66
53
|
this.#$label.textContent = newVal;
|
|
67
54
|
break;
|
|
68
55
|
}
|
|
69
|
-
|
|
70
56
|
case 'checked':
|
|
71
57
|
{
|
|
72
58
|
updateExplicitBooleanAttribute(this, 'aria-selected', isAttrTrue(newVal));
|
|
73
59
|
break;
|
|
74
60
|
}
|
|
75
|
-
|
|
76
61
|
case 'disabled':
|
|
77
62
|
{
|
|
78
63
|
const isDisabled = isAttrTrue(newVal);
|
|
@@ -82,19 +67,15 @@ defineCustomElement('sinch-tabs-option', class extends NectaryElement {
|
|
|
82
67
|
}
|
|
83
68
|
}
|
|
84
69
|
}
|
|
85
|
-
|
|
86
70
|
get focusable() {
|
|
87
71
|
return true;
|
|
88
72
|
}
|
|
89
|
-
|
|
90
73
|
focus() {
|
|
91
74
|
this.#$button.focus();
|
|
92
75
|
}
|
|
93
|
-
|
|
94
76
|
blur() {
|
|
95
77
|
this.#$button.blur();
|
|
96
78
|
}
|
|
97
|
-
|
|
98
79
|
#onClick = e => {
|
|
99
80
|
e.stopPropagation();
|
|
100
81
|
this.dispatchEvent(new CustomEvent('option-change', {
|
package/tag/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import '../text';
|
|
2
2
|
import { defineCustomElement, getBooleanAttribute, getAttribute, updateBooleanAttribute, updateAttribute, NectaryElement } from '../utils';
|
|
3
|
-
|
|
4
|
-
|
|
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:24px;padding:0 9px;border-radius:12px;background-color:var(--sinch-tag-color-default-bg);color:var(--sinch-tag-color-default-fg);box-sizing:border-box;--sinch-color-icon:var(--sinch-tag-color-default-fg);--sinch-size-icon:16px}#text{flex:1}:host([small]:not([small=false])) #wrapper{height:20px;border-radius:10px;padding:0 8px}::slotted(*){margin-left:-4px}</style><div id="wrapper"><slot name="icon"></slot><sinch-text id="text" type="xs" ellipsis></sinch-text></div>';
|
|
4
|
+
import { assertTagColor, getTagColorBg, getTagColorFg } from './utils';
|
|
5
5
|
const template = document.createElement('template');
|
|
6
6
|
template.innerHTML = templateHTML;
|
|
7
7
|
defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
8
8
|
#$text;
|
|
9
9
|
#$wrapper;
|
|
10
|
-
|
|
10
|
+
#isConnected = false;
|
|
11
11
|
constructor() {
|
|
12
12
|
super();
|
|
13
13
|
const shadowRoot = this.attachShadow();
|
|
@@ -15,39 +15,34 @@ defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
|
15
15
|
this.#$wrapper = shadowRoot.querySelector('#wrapper');
|
|
16
16
|
this.#$text = shadowRoot.querySelector('#text');
|
|
17
17
|
}
|
|
18
|
-
|
|
19
18
|
connectedCallback() {
|
|
19
|
+
this.#isConnected = true;
|
|
20
20
|
this.#updateColor();
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
disconnectedCallback() {
|
|
23
|
+
this.#isConnected = false;
|
|
24
|
+
}
|
|
23
25
|
get color() {
|
|
24
26
|
return getAttribute(this, 'color');
|
|
25
27
|
}
|
|
26
|
-
|
|
27
28
|
set color(value) {
|
|
28
29
|
updateAttribute(this, 'color', value);
|
|
29
30
|
}
|
|
30
|
-
|
|
31
31
|
get text() {
|
|
32
32
|
return getAttribute(this, 'text', '');
|
|
33
33
|
}
|
|
34
|
-
|
|
35
34
|
set text(value) {
|
|
36
35
|
updateAttribute(this, 'text', value);
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
get small() {
|
|
40
38
|
return getBooleanAttribute(this, 'small');
|
|
41
39
|
}
|
|
42
|
-
|
|
43
40
|
set small(isSmall) {
|
|
44
41
|
updateBooleanAttribute(this, 'small', isSmall);
|
|
45
42
|
}
|
|
46
|
-
|
|
47
43
|
static get observedAttributes() {
|
|
48
44
|
return ['text', 'color'];
|
|
49
45
|
}
|
|
50
|
-
|
|
51
46
|
attributeChangedCallback(name, _, newVal) {
|
|
52
47
|
switch (name) {
|
|
53
48
|
case 'color':
|
|
@@ -55,7 +50,6 @@ defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
|
55
50
|
this.#updateColor();
|
|
56
51
|
break;
|
|
57
52
|
}
|
|
58
|
-
|
|
59
53
|
case 'text':
|
|
60
54
|
{
|
|
61
55
|
this.#$text.textContent = newVal;
|
|
@@ -63,19 +57,22 @@ defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
|
63
57
|
}
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
|
-
|
|
67
60
|
#updateColor() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
this
|
|
61
|
+
if (!this.#isConnected) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const colorName = this.color;
|
|
65
|
+
if (colorName !== null && colorName.length > 0) {
|
|
66
|
+
assertTagColor(this, colorName);
|
|
67
|
+
const bg = getTagColorBg(colorName);
|
|
68
|
+
const fg = getTagColorFg(colorName);
|
|
69
|
+
this.#$wrapper.style.setProperty('background-color', bg);
|
|
70
|
+
this.#$wrapper.style.setProperty('color', fg);
|
|
71
|
+
this.#$wrapper.style.setProperty('--sinch-color-icon', fg);
|
|
74
72
|
} else {
|
|
75
73
|
this.#$wrapper.style.removeProperty('background-color');
|
|
76
74
|
this.#$wrapper.style.removeProperty('color');
|
|
77
75
|
this.#$wrapper.style.removeProperty('--sinch-color-icon');
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
|
-
|
|
81
78
|
});
|
package/tag/utils.d.ts
ADDED
package/tag/utils.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const getTagColorBg = id => {
|
|
2
|
+
return `var(--sinch-tag-color-${id}-bg)`;
|
|
3
|
+
};
|
|
4
|
+
export const getTagColorFg = id => {
|
|
5
|
+
return `var(--sinch-tag-color-${id}-fg)`;
|
|
6
|
+
};
|
|
7
|
+
export const assertTagColor = (root, id) => {
|
|
8
|
+
if (id === null || window.getComputedStyle(root).getPropertyValue(`--sinch-tag-color-${id}-bg`).length === 0) {
|
|
9
|
+
throw new Error(`Invalid sinch-tag color name: ${id}`);
|
|
10
|
+
}
|
|
11
|
+
};
|
package/text/index.js
CHANGED
|
@@ -10,47 +10,38 @@ defineCustomElement('sinch-text', class extends NectaryElement {
|
|
|
10
10
|
const shadowRoot = this.attachShadow();
|
|
11
11
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
connectedCallback() {
|
|
15
14
|
this.setAttribute('role', getBooleanAttribute(this, 'inline') ? 'text' : 'paragraph');
|
|
15
|
+
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
get type() {
|
|
19
19
|
return getLiteralAttribute(this, typeValues, 'type');
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
set type(value) {
|
|
23
22
|
updateLiteralAttribute(this, typeValues, 'type', value);
|
|
24
23
|
}
|
|
25
|
-
|
|
26
24
|
set inline(isInline) {
|
|
27
25
|
updateBooleanAttribute(this, 'inline', isInline);
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
get inline() {
|
|
31
28
|
return getBooleanAttribute(this, 'inline');
|
|
32
29
|
}
|
|
33
|
-
|
|
34
30
|
set ellipsis(isEllipsis) {
|
|
35
31
|
updateBooleanAttribute(this, 'ellipsis', isEllipsis);
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
get ellipsis() {
|
|
39
34
|
return getBooleanAttribute(this, 'ellipsis');
|
|
40
35
|
}
|
|
41
|
-
|
|
42
36
|
set emphasized(isEmphasized) {
|
|
43
37
|
updateBooleanAttribute(this, 'emphasized', isEmphasized);
|
|
44
38
|
}
|
|
45
|
-
|
|
46
39
|
get emphasized() {
|
|
47
40
|
return getBooleanAttribute(this, 'emphasized');
|
|
48
41
|
}
|
|
49
|
-
|
|
50
42
|
static get observedAttributes() {
|
|
51
43
|
return ['type', 'inline'];
|
|
52
44
|
}
|
|
53
|
-
|
|
54
45
|
attributeChangedCallback(name, _, newVal) {
|
|
55
46
|
switch (name) {
|
|
56
47
|
case 'type':
|
|
@@ -58,7 +49,6 @@ defineCustomElement('sinch-text', class extends NectaryElement {
|
|
|
58
49
|
assertType(newVal);
|
|
59
50
|
break;
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
case 'inline':
|
|
63
53
|
{
|
|
64
54
|
this.setAttribute('role', isAttrTrue(newVal) ? 'text' : 'paragraph');
|
|
@@ -66,5 +56,4 @@ defineCustomElement('sinch-text', class extends NectaryElement {
|
|
|
66
56
|
}
|
|
67
57
|
}
|
|
68
58
|
}
|
|
69
|
-
|
|
70
59
|
});
|