@nectary/components 2.0.0 → 2.1.1
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 -4
- package/action-menu/index.js +5 -1
- package/action-menu-option/index.js +2 -4
- package/alert/index.js +2 -9
- package/alert/utils.d.ts +0 -3
- package/alert/utils.js +1 -6
- package/avatar/index.js +4 -20
- package/avatar/utils.d.ts +0 -4
- package/avatar/utils.js +0 -13
- package/badge/index.js +2 -8
- package/badge/utils.d.ts +0 -3
- package/badge/utils.js +1 -6
- package/button/index.js +25 -27
- package/button/utils.d.ts +0 -3
- package/button/utils.js +1 -9
- package/chat-bubble/index.d.ts +0 -1
- package/chat-bubble/index.js +1 -2
- package/checkbox/index.js +6 -9
- package/chip/index.js +22 -19
- package/chip/utils.d.ts +0 -1
- package/chip/utils.js +0 -5
- package/color-menu/index.js +6 -3
- package/color-swatch/index.js +1 -4
- package/color-swatch/utils.d.ts +0 -1
- package/color-swatch/utils.js +0 -5
- package/date-picker/index.js +1 -27
- package/date-picker/utils.d.ts +0 -8
- package/date-picker/utils.js +0 -20
- package/dialog/index.js +1 -2
- package/emoji-picker/index.js +7 -14
- package/file-picker/index.js +11 -9
- package/file-status/index.js +2 -9
- package/file-status/utils.d.ts +0 -3
- package/file-status/utils.js +1 -6
- package/help-tooltip/index.d.ts +0 -1
- package/help-tooltip/index.js +1 -2
- package/icon/index.js +1 -1
- package/icon-button/index.js +23 -27
- package/icon-button/utils.d.ts +0 -3
- package/icon-button/utils.js +1 -9
- package/inline-alert/index.js +2 -9
- package/inline-alert/utils.d.ts +0 -3
- package/inline-alert/utils.js +1 -6
- package/input/index.js +10 -16
- package/input/utils.d.ts +0 -3
- package/input/utils.js +1 -6
- package/package.json +2 -3
- package/pagination/index.js +0 -4
- package/pagination/types.d.ts +0 -1
- package/pop/index.js +23 -25
- package/pop/utils.d.ts +0 -3
- package/pop/utils.js +0 -5
- package/popover/index.js +1 -4
- package/popover/utils.d.ts +0 -3
- package/popover/utils.js +0 -5
- package/radio/index.js +0 -4
- package/radio/types.d.ts +0 -1
- package/rich-text/index.js +2 -9
- package/rich-text/utils.d.ts +0 -3
- package/rich-text/utils.js +1 -6
- package/segment/index.js +1 -4
- package/segment-collapse/index.js +0 -4
- package/segment-collapse/types.d.ts +0 -1
- package/segmented-control/index.js +0 -4
- package/segmented-icon-control/index.js +0 -4
- package/select-button/index.js +23 -20
- package/select-menu/index.js +6 -3
- package/skeleton/index.js +45 -9
- package/skeleton-item/index.js +1 -28
- package/spinner/index.js +2 -9
- package/tabs/index.js +0 -4
- package/tag/index.js +1 -4
- package/tag/utils.d.ts +0 -1
- package/tag/utils.js +0 -5
- package/text/index.js +2 -9
- package/text/utils.d.ts +0 -3
- package/text/utils.js +1 -6
- package/textarea/index.js +0 -4
- package/tile-control/index.js +0 -4
- package/time-picker/index.js +1 -9
- package/time-picker/utils.d.ts +1 -1
- package/time-picker/utils.js +17 -5
- package/title/index.js +2 -12
- package/title/utils.d.ts +0 -7
- package/title/utils.js +1 -29
- package/toast/index.js +2 -9
- package/toast/utils.d.ts +0 -3
- package/toast/utils.js +1 -6
- package/toggle/index.js +0 -4
- package/toggle/types.d.ts +0 -1
- package/tooltip/index.js +1 -7
- package/tooltip/utils.d.ts +0 -5
- package/tooltip/utils.js +0 -10
- package/utils/dom.js +0 -5
- package/utils/element.js +2 -2
- package/utils/size.d.ts +0 -5
- package/utils/size.js +1 -17
package/accordion/index.js
CHANGED
|
@@ -56,10 +56,6 @@ defineCustomElement('sinch-accordion', class extends NectaryElement {
|
|
|
56
56
|
const $elem = e.target;
|
|
57
57
|
const value = e.detail;
|
|
58
58
|
const result = this.multiple ? updateCsv(this.value, value, !getBooleanAttribute($elem, 'data-checked')) : getBooleanAttribute($elem, 'data-checked') ? '' : value;
|
|
59
|
-
this.dispatchEvent(new CustomEvent('change', {
|
|
60
|
-
detail: result,
|
|
61
|
-
bubbles: true
|
|
62
|
-
}));
|
|
63
59
|
this.dispatchEvent(new CustomEvent('-change', {
|
|
64
60
|
detail: result
|
|
65
61
|
}));
|
package/action-menu/index.js
CHANGED
|
@@ -10,7 +10,9 @@ defineCustomElement('sinch-action-menu', class extends NectaryElement {
|
|
|
10
10
|
#controller = null;
|
|
11
11
|
constructor() {
|
|
12
12
|
super();
|
|
13
|
-
const shadowRoot = this.attachShadow(
|
|
13
|
+
const shadowRoot = this.attachShadow({
|
|
14
|
+
delegatesFocus: false
|
|
15
|
+
});
|
|
14
16
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
15
17
|
this.#$optionSlot = shadowRoot.querySelector('slot');
|
|
16
18
|
this.#$listbox = shadowRoot.querySelector('#listbox');
|
|
@@ -65,6 +67,7 @@ defineCustomElement('sinch-action-menu', class extends NectaryElement {
|
|
|
65
67
|
this.#selectOption(null);
|
|
66
68
|
};
|
|
67
69
|
#onListboxClick = e => {
|
|
70
|
+
this.focus();
|
|
68
71
|
if (isSinchActionMenuOption(e.target)) {
|
|
69
72
|
this.#selectOption(e.target);
|
|
70
73
|
}
|
|
@@ -87,6 +90,7 @@ defineCustomElement('sinch-action-menu', class extends NectaryElement {
|
|
|
87
90
|
#handleKeydown(e) {
|
|
88
91
|
switch (e.code) {
|
|
89
92
|
case 'Enter':
|
|
93
|
+
case 'Space':
|
|
90
94
|
{
|
|
91
95
|
const $opt = this.#findSelectedOption();
|
|
92
96
|
if ($opt !== null) {
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import '../text';
|
|
2
2
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
3
|
-
const templateHTML = '<style>:host{display:block}#wrapper{all:initial;display:flex;position:relative;box-sizing:border-box;height:40px;width:100%;padding:8px 16px;align-items:center;gap:10px;user-select:none;
|
|
3
|
+
const templateHTML = '<style>:host{display:block;cursor:pointer}:host([disabled]){cursor:initial}#wrapper{all:initial;display:flex;position:relative;box-sizing:border-box;height:40px;width:100%;padding:8px 16px;align-items:center;gap:10px;user-select:none;background-color:var(--sinch-comp-action-menu-color-default-background-initial);--sinch-global-color-text:var(--sinch-comp-action-menu-color-default-text-initial);--sinch-global-color-icon:var(--sinch-comp-action-menu-color-default-icon-initial);--sinch-global-size-icon:var(--sinch-comp-action-menu-size-icon)}:host([data-selected])>#wrapper{background-color:var(--sinch-comp-action-menu-color-default-background-selected)}:host(:hover)>#wrapper{background-color:var(--sinch-comp-action-menu-color-default-background-hover)}:host([disabled])>#wrapper{pointer-events:none;background-color:var(--sinch-comp-action-menu-color-disabled-background-initial);--sinch-global-color-text:var(--sinch-comp-action-menu-color-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-action-menu-color-disabled-icon-initial)}#content{flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-action-menu-font-option)}::slotted(*){margin-left:-6px}</style><div id="wrapper" inert><slot name="icon"></slot><sinch-text id="content" type="m" ellipsis></sinch-text></div>';
|
|
4
4
|
const template = document.createElement('template');
|
|
5
5
|
template.innerHTML = templateHTML;
|
|
6
6
|
defineCustomElement('sinch-action-menu-option', class ActionMenuOption extends NectaryElement {
|
|
7
|
-
#$wrapper;
|
|
8
7
|
#$content;
|
|
9
8
|
#controller = null;
|
|
10
9
|
constructor() {
|
|
11
10
|
super();
|
|
12
11
|
const shadowRoot = this.attachShadow();
|
|
13
12
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
14
|
-
this.#$wrapper = shadowRoot.querySelector('#wrapper');
|
|
15
13
|
this.#$content = shadowRoot.querySelector('#content');
|
|
16
14
|
}
|
|
17
15
|
connectedCallback() {
|
|
@@ -20,7 +18,7 @@ defineCustomElement('sinch-action-menu-option', class ActionMenuOption extends N
|
|
|
20
18
|
signal
|
|
21
19
|
} = this.#controller;
|
|
22
20
|
this.setAttribute('role', 'option');
|
|
23
|
-
this
|
|
21
|
+
this.addEventListener('mousedown', this.#onMouseDown, {
|
|
24
22
|
signal
|
|
25
23
|
});
|
|
26
24
|
this.addEventListener('-click', this.#onClickReactHandler, {
|
package/alert/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import '../rich-text';
|
|
|
3
3
|
import '../text';
|
|
4
4
|
import { defineCustomElement, getAttribute, getLiteralAttribute, updateAttribute, updateLiteralAttribute, NectaryElement } from '../utils';
|
|
5
5
|
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:row;gap:8px;align-items:center;padding:8px 16px;box-sizing:border-box;width:100%;min-height:48px}:host([type=warn]) #wrapper{background-color:var(--sinch-comp-alert-color-warning-default-background)}:host([type=error]) #wrapper{background-color:var(--sinch-comp-alert-color-error-default-background)}:host([type=info]) #wrapper{background-color:var(--sinch-comp-alert-color-info-default-background)}#icon-error,#icon-info,#icon-warn{display:none}#icon-warn{--sinch-global-color-icon:var(--sinch-comp-alert-color-warning-default-icon)}#icon-error{--sinch-global-color-icon:var(--sinch-comp-alert-color-error-default-icon)}#icon-info{--sinch-global-color-icon:var(--sinch-comp-alert-color-info-default-icon)}:host([type=error]) #icon-error,:host([type=info]) #icon-info,:host([type=warn]) #icon-warn{display:block}#text{display:flex;flex-direction:column;gap:8px;flex:1;min-width:0;--sinch-comp-rich-text-font:var(--sinch-comp-alert-font-body)}:host([type=warn]) #text{--sinch-global-color-text:var(--sinch-comp-alert-color-warning-default-text)}:host([type=error]) #text{--sinch-global-color-text:var(--sinch-comp-alert-color-error-default-text)}:host([type=info]) #text{--sinch-global-color-text:var(--sinch-comp-alert-color-info-default-text)}</style><div id="wrapper"><sinch-icon id="icon-info" name="info"></sinch-icon><sinch-icon id="icon-warn" name="report_problem"></sinch-icon><sinch-icon id="icon-error" name="report"></sinch-icon><sinch-rich-text id="text"></sinch-rich-text><slot name="action"></slot><slot name="close"></slot></div>';
|
|
6
|
-
import {
|
|
6
|
+
import { typeValues } from './utils';
|
|
7
7
|
const template = document.createElement('template');
|
|
8
8
|
template.innerHTML = templateHTML;
|
|
9
9
|
defineCustomElement('sinch-alert', class extends NectaryElement {
|
|
@@ -34,17 +34,10 @@ defineCustomElement('sinch-alert', class extends NectaryElement {
|
|
|
34
34
|
updateAttribute(this, 'text', value);
|
|
35
35
|
}
|
|
36
36
|
static get observedAttributes() {
|
|
37
|
-
return ['text'
|
|
37
|
+
return ['text'];
|
|
38
38
|
}
|
|
39
39
|
attributeChangedCallback(name, _, newVal) {
|
|
40
40
|
switch (name) {
|
|
41
|
-
case 'type':
|
|
42
|
-
{
|
|
43
|
-
if ('production' !== 'production') {
|
|
44
|
-
assertType(newVal);
|
|
45
|
-
}
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
41
|
case 'text':
|
|
49
42
|
{
|
|
50
43
|
updateAttribute(this.#$text, 'text', newVal);
|
package/alert/utils.d.ts
CHANGED
package/alert/utils.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
export const typeValues = ['info', 'warn', 'error'];
|
|
2
|
-
export const assertType = value => {
|
|
3
|
-
if (value === null || !typeValues.includes(value)) {
|
|
4
|
-
throw new Error(`sinch-alert: invalid type attribute: ${value}`);
|
|
5
|
-
}
|
|
6
|
-
};
|
|
1
|
+
export const typeValues = ['info', 'warn', 'error'];
|
package/avatar/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineCustomElement, getAttribute, getLiteralAttribute, NectaryElement, updateAttribute, updateLiteralAttribute } from '../utils';
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
3
3
|
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;width:var(--sinch-local-size);height:var(--sinch-local-size);background-color:var(--sinch-comp-avatar-border-color-default-initial);border-radius:var(--sinch-comp-avatar-shape-radius);--sinch-local-size:var(--sinch-comp-avatar-size-m)}:host([size="l"]) #wrapper{--sinch-local-size:var(--sinch-comp-avatar-size-l)}:host([size="s"]) #wrapper{--sinch-local-size:var(--sinch-comp-avatar-size-s)}#text{display:block;width:100%;height:100%;font:var(--sinch-comp-avatar-container-font-size-m-text);line-height:calc(var(--sinch-local-size) - 2px);text-transform:uppercase;text-align:center}:host([size="l"]) #text{font:var(--sinch-comp-avatar-container-font-size-l-text);line-height:calc(var(--sinch-local-size) - 2px)}:host([size="s"]) #text{font:var(--sinch-comp-avatar-container-font-size-s-text);line-height:calc(var(--sinch-local-size) - 2px)}#circle{position:relative;width:calc(100% - 2px);height:calc(100% - 2px);left:1px;top:1px;border-radius:50%;-webkit-mask:linear-gradient(#fff,#000);mask:linear-gradient(#fff,#000);background-color:var(--sinch-comp-avatar-container-color-default-background);color:var(--sinch-comp-avatar-container-color-default-foreground)}#image{display:none;position:absolute;left:0;top:0;width:100%;height:100%;object-fit:contain}:host([src]:not([src=""])) #image{display:block}#status-wrapper{position:absolute;left:calc(85% - 5px);top:calc(85% - 5px);width:10px;height:10px;padding:1px;box-sizing:border-box;border-radius:50%;background-color:var(--sinch-comp-avatar-border-color-default-initial);display:none;pointer-events:none}#status{width:8px;height:8px;border-radius:50%}:host([status=away]) #status-wrapper,:host([status=busy]) #status-wrapper,:host([status=offline]) #status-wrapper,:host([status=online]) #status-wrapper{display:block}:host([status=online]) #status{background-color:var(--sinch-comp-avatar-status-color-online-default-background)}:host([status=away]) #status{background-color:var(--sinch-comp-avatar-status-color-away-default-background)}:host([status=busy]) #status{background-color:var(--sinch-comp-avatar-status-color-busy-default-background)}:host([status=offline]) #status{background-color:var(--sinch-comp-avatar-status-color-offline-default-background)}</style><div id="wrapper"><div id="circle"><span id="text"></span><img id="image" alt=""/></div><div id="status-wrapper"><div id="status"></div></div></div>';
|
|
4
|
-
import {
|
|
4
|
+
import { getAvatarColorBg, getAvatarColorFg, statusValues } from './utils';
|
|
5
5
|
const template = document.createElement('template');
|
|
6
6
|
template.innerHTML = templateHTML;
|
|
7
7
|
defineCustomElement('sinch-avatar', class extends NectaryElement {
|
|
@@ -51,7 +51,7 @@ defineCustomElement('sinch-avatar', class extends NectaryElement {
|
|
|
51
51
|
updateLiteralAttribute(this, statusValues, 'status', value);
|
|
52
52
|
}
|
|
53
53
|
static get observedAttributes() {
|
|
54
|
-
return ['alt', 'src', '
|
|
54
|
+
return ['alt', 'src', 'color'];
|
|
55
55
|
}
|
|
56
56
|
attributeChangedCallback(name, _, newVal) {
|
|
57
57
|
switch (name) {
|
|
@@ -66,23 +66,10 @@ defineCustomElement('sinch-avatar', class extends NectaryElement {
|
|
|
66
66
|
this.#$image.src = newVal ?? '';
|
|
67
67
|
break;
|
|
68
68
|
}
|
|
69
|
-
case 'size':
|
|
70
|
-
{
|
|
71
|
-
if ('production' !== 'production') {
|
|
72
|
-
assertSize(newVal, 'sinch-avatar');
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
case 'status':
|
|
77
|
-
{
|
|
78
|
-
if ('production' !== 'production') {
|
|
79
|
-
assertStatus(newVal);
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
69
|
case 'color':
|
|
84
70
|
{
|
|
85
71
|
this.#updateColor();
|
|
72
|
+
break;
|
|
86
73
|
}
|
|
87
74
|
}
|
|
88
75
|
}
|
|
@@ -92,9 +79,6 @@ defineCustomElement('sinch-avatar', class extends NectaryElement {
|
|
|
92
79
|
}
|
|
93
80
|
const colorName = this.color;
|
|
94
81
|
if (colorName !== null && colorName.length > 0) {
|
|
95
|
-
if ('production' !== 'production') {
|
|
96
|
-
assertAvatarColor(this, colorName);
|
|
97
|
-
}
|
|
98
82
|
const bg = getAvatarColorBg(colorName);
|
|
99
83
|
const fg = getAvatarColorFg(colorName);
|
|
100
84
|
this.#$circle.style.setProperty('background-color', bg);
|
package/avatar/utils.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import type { TSinchAvatarStatus } from './types';
|
|
2
2
|
export declare const statusValues: readonly TSinchAvatarStatus[];
|
|
3
|
-
type TAssertStatus = (value: string | null) => asserts value is TSinchAvatarStatus;
|
|
4
|
-
export declare const assertStatus: TAssertStatus;
|
|
5
3
|
export declare const getAvatarColorBg: (id: string) => string;
|
|
6
4
|
export declare const getAvatarColorFg: (id: string) => string;
|
|
7
|
-
export declare const assertAvatarColor: (root: Element, id: string | null) => void;
|
|
8
|
-
export {};
|
package/avatar/utils.js
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
export const statusValues = ['online', 'busy', 'away', 'offline'];
|
|
2
|
-
export const assertStatus = value => {
|
|
3
|
-
if (value === null || value.length === 0) {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
if (!statusValues.includes(value)) {
|
|
7
|
-
throw new Error(`sinch-avatar: invalid status attribute: ${value}`);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
2
|
export const getAvatarColorBg = id => {
|
|
11
3
|
return `var(--sinch-comp-avatar-container-color-${id}-background)`;
|
|
12
4
|
};
|
|
13
5
|
export const getAvatarColorFg = id => {
|
|
14
6
|
return `var(--sinch-comp-avatar-container-color-${id}-foreground)`;
|
|
15
|
-
};
|
|
16
|
-
export const assertAvatarColor = (root, id) => {
|
|
17
|
-
if (id === null || window.getComputedStyle(root).getPropertyValue(`--sinch-comp-avatar-container-color-${id}-background`).length === 0) {
|
|
18
|
-
throw new Error(`Invalid sinch-avatar color name: ${id}`);
|
|
19
|
-
}
|
|
20
7
|
};
|
package/badge/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute, updateLiteralAttribute } from '../utils';
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
3
3
|
const templateHTML = '<style>:host{display:inline-flex;flex-direction:column;position:relative}#badge-wrapper{position:absolute;left:0;top:0;width:fit-content;border-radius:var(--sinch-comp-badge-shape-radius);padding:1px;pointer-events:none;background-color:var(--sinch-comp-badge-color-border)}#badge{box-sizing:border-box;color:var(--sinch-comp-badge-color-text);background-color:var(--sinch-comp-badge-color-background);width:20px;height:20px;border-radius:var(--sinch-comp-badge-shape-radius)}#badge.long{width:fit-content;padding:0 5px}#text{display:block;width:100%;height:100%;text-align:center;font:var(--sinch-comp-badge-font-size-l);line-height:20px;text-rendering:optimizelegibility}:host([size="m"]) #badge-wrapper{left:calc(100% - 8px);top:-8px}:host([size="m"]) #badge{width:14px;height:14px}:host([size="m"]) #badge.long{width:fit-content;padding:0 3px}:host([size="m"]) #text{font:var(--sinch-comp-badge-font-size-m);line-height:14px}:host([size="s"]) #badge{width:8px;height:8px;padding:0}:host([size="s"]) #text{display:none}:host([hidden]) #badge-wrapper{display:none}</style><slot id="slot"></slot><div id="badge-wrapper"><div id="badge"><span id="text"></span></div></div>';
|
|
4
|
-
import {
|
|
4
|
+
import { modeValues } from './utils';
|
|
5
5
|
const template = document.createElement('template');
|
|
6
6
|
template.innerHTML = templateHTML;
|
|
7
7
|
defineCustomElement('sinch-badge', class extends NectaryElement {
|
|
@@ -42,17 +42,11 @@ defineCustomElement('sinch-badge', class extends NectaryElement {
|
|
|
42
42
|
}
|
|
43
43
|
case 'size':
|
|
44
44
|
{
|
|
45
|
-
if ('production' !== 'production') {
|
|
46
|
-
assertSize(newVal, 'sinch-badge');
|
|
47
|
-
}
|
|
48
45
|
this.#updatePosition();
|
|
49
46
|
break;
|
|
50
47
|
}
|
|
51
48
|
case 'mode':
|
|
52
49
|
{
|
|
53
|
-
if ('production' !== 'production') {
|
|
54
|
-
assertMode(newVal);
|
|
55
|
-
}
|
|
56
50
|
this.#updatePosition();
|
|
57
51
|
break;
|
|
58
52
|
}
|
package/badge/utils.d.ts
CHANGED
package/badge/utils.js
CHANGED
package/button/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineCustomElement, getBooleanAttribute, getAttribute, isAttrTrue, updateBooleanAttribute, updateAttribute, NectaryElement, getReactEventHandler, getLiteralAttribute, updateLiteralAttribute, Context, subscribeContext } from '../utils';
|
|
2
|
-
import {
|
|
3
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#button{all:initial;display:block;position:relative;width:100%;height:var(--sinch-local-size);cursor:pointer;--sinch-local-size:var(--sinch-comp-button-size-container-m);--sinch-global-size-icon:var(--sinch-comp-button-size-icon-m);--sinch-local-font:var(--sinch-comp-button-font-size-m-text);--sinch-local-shape-radius:var(--sinch-comp-button-shape-radius-size-m);--sinch-global-color-icon:var(--sinch-local-color-icon)}#button:disabled{cursor:initial}:host([data-size="l"])>#button{--sinch-local-size:var(--sinch-comp-button-size-container-l);--sinch-global-size-icon:var(--sinch-comp-button-size-icon-l);--sinch-local-shape-radius:var(--sinch-comp-button-shape-radius-size-l);--sinch-local-font:var(--sinch-comp-button-font-size-l-text)}:host([data-size="m"])>#button{--sinch-local-size:var(--sinch-comp-button-size-container-m);--sinch-global-size-icon:var(--sinch-comp-button-size-icon-m);--sinch-local-shape-radius:var(--sinch-comp-button-shape-radius-size-m);--sinch-local-font:var(--sinch-comp-button-font-size-m-text)}:host([data-size="s"])>#button{--sinch-local-size:var(--sinch-comp-button-size-container-s);--sinch-global-size-icon:var(--sinch-comp-button-size-icon-s);--sinch-local-shape-radius:var(--sinch-comp-button-shape-radius-size-s);--sinch-local-font:var(--sinch-comp-button-font-size-s-text)}:host([type=primary])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-primary-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-primary-default-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-primary-default-text-initial);--sinch-local-color-icon:var(--sinch-comp-button-color-primary-default-icon-initial);--sinch-local-color-outline-focus:var(--sinch-comp-button-color-primary-default-outilne-focus);--sinch-local-shadow:var(--sinch-comp-button-shadow-primary-initial)}:host([type=secondary])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-secondary-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-secondary-default-border-initial);--sinch-local-color-outline-focus:var(--sinch-comp-button-color-secondary-default-outline-focus);--sinch-local-color-text:var(--sinch-comp-button-color-secondary-default-text-initial);--sinch-local-color-icon:var(--sinch-comp-button-color-secondary-default-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-secondary-initial)}:host([type=tertiary])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-tertiary-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-tertiary-default-border-initial);--sinch-local-color-outline-focus:var(--sinch-comp-button-color-tertiary-default-outline-focus);--sinch-local-color-text:var(--sinch-comp-button-color-tertiary-default-text-initial);--sinch-local-color-icon:var(--sinch-comp-button-color-tertiary-default-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-tertiary-initial)}:host([type=cta-primary])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-cta-primary-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-cta-primary-default-border-initial);--sinch-local-color-outline-focus:var(--sinch-comp-button-color-cta-primary-default-outline-focus);--sinch-local-color-text:var(--sinch-comp-button-color-cta-primary-default-text-initial);--sinch-local-color-icon:var(--sinch-comp-button-color-cta-primary-default-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-primary-initial)}:host([type=cta-secondary])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-cta-secondary-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-cta-secondary-default-border-initial);--sinch-local-color-outline-focus:var(--sinch-comp-button-color-cta-secondary-default-outline-focus);--sinch-local-color-text:var(--sinch-comp-button-color-cta-secondary-default-text-initial);--sinch-local-color-icon:var(--sinch-comp-button-color-cta-secondary-default-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-secondary-initial)}:host([type=destructive])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-danger-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-danger-default-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-danger-default-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-danger-default-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-destructive-initial)}:host([type=primary])>#button:disabled{--sinch-local-color-background:var(--sinch-comp-button-color-primary-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-primary-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-primary-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-primary-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-primary-disabled)}:host([type=secondary])>#button:disabled{--sinch-local-color-background:var(--sinch-comp-button-color-secondary-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-secondary-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-secondary-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-secondary-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-secondary-disabled)}:host([type=tertiary])>#button:disabled{--sinch-local-color-background:var(--sinch-comp-button-color-tertiary-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-tertiary-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-tertiary-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-tertiary-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-tertiary-disabled)}:host([type=cta-primary])>#button:disabled{--sinch-local-color-background:var(--sinch-comp-button-color-cta-primary-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-cta-primary-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-cta-primary-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-cta-primary-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-primary-disabled)}:host([type=cta-secondary])>#button:disabled{--sinch-local-color-background:var(--sinch-comp-button-color-cta-secondary-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-cta-secondary-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-cta-secondary-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-cta-secondary-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-secondary-disabled)}:host([type=destructive])>#button:disabled{--sinch-local-color-background:var(--sinch-comp-button-color-danger-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-danger-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-danger-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-danger-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-danger-disabled)}:host([type=primary])>#button:focus{--sinch-local-shadow:var(--sinch-comp-button-shadow-primary-focus)}:host([type=secondary])>#button:focus{--sinch-local-shadow:var(--sinch-comp-button-shadow-secondary-focus)}:host([type=tertiary])>#button:focus{--sinch-local-shadow:var(--sinch-comp-button-shadow-tertiary-focus)}:host([type=cta-primary])>#button:focus{--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-primary-focus)}:host([type=cta-secondary])>#button:focus{--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-secondary-focus)}:host([type=destructive])>#button:focus{--sinch-local-shadow:var(--sinch-comp-button-shadow-destructive-focus)}:host([type=primary])>#button:enabled:hover{--sinch-local-color-background:var(--sinch-comp-button-color-primary-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-primary-hover)}:host([type=primary])>#button:enabled:active{--sinch-local-color-background:var(--sinch-comp-button-color-primary-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-primary-active)}:host([type=secondary])>#button:enabled:hover{--sinch-local-color-background:var(--sinch-comp-button-color-secondary-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-secondary-hover)}:host([type=secondary])>#button:enabled:active{--sinch-local-color-background:var(--sinch-comp-button-color-secondary-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-secondary-active)}:host([type=tertiary])>#button:enabled:hover{--sinch-local-color-background:var(--sinch-comp-button-color-tertiary-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-tertiary-hover)}:host([type=tertiary])>#button:enabled:active{--sinch-local-color-background:var(--sinch-comp-button-color-tertiary-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-tertiary-active)}:host([type=cta-primary])>#button:enabled:hover{--sinch-local-color-background:var(--sinch-comp-button-color-cta-primary-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-primary-hover)}:host([type=cta-primary])>#button:enabled:active{--sinch-local-color-background:var(--sinch-comp-button-color-cta-primary-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-primary-active)}:host([type=cta-secondary])>#button:enabled:hover{--sinch-local-color-background:var(--sinch-comp-button-color-cta-secondary-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-secondary-hover)}:host([type=cta-secondary])>#button:enabled:active{--sinch-local-color-background:var(--sinch-comp-button-color-cta-secondary-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-secondary-active)}:host([type=destructive])>#button:enabled:hover{--sinch-local-color-background:var(--sinch-comp-button-color-danger-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-danger-hover)}:host([type=destructive])>#button:enabled:active{--sinch-local-color-background:var(--sinch-comp-button-color-danger-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-danger-active)}#button::before{content:"";position:absolute;inset:0;background-color:var(--sinch-local-color-background);border:1px solid var(--sinch-local-color-border);border-radius:var(--sinch-local-shape-radius);box-shadow:var(--sinch-local-shadow);pointer-events:none}#button:active::before{border-width:2px}#button:focus-visible::after{position:absolute;content:"";inset:-3px;border:2px solid var(--sinch-local-color-outline-focus);border-radius:calc(var(--sinch-local-shape-radius) + 3px);pointer-events:none}#content{position:relative;display:flex;align-items:center;justify-content:center;gap:.75em;width:100%;height:100%;padding:0 1em;box-sizing:border-box;pointer-events:none}#text{font:var(--sinch-local-font);color:var(--sinch-local-color-text);overflow:hidden;white-space:nowrap;text-overflow:ellipsis;flex-shrink:1;min-width:0}</style><button id="button"><div id="content"><slot name="left-icon"></slot><span id="text"></span><slot name="right-icon"></slot></div></button>';
|
|
4
|
-
import {
|
|
2
|
+
import { DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
3
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0;cursor:pointer}:host([disabled]){cursor:initial}#button{all:initial;display:block;position:relative;width:100%;height:var(--sinch-local-size);--sinch-local-size:var(--sinch-comp-button-size-container-m);--sinch-global-size-icon:var(--sinch-comp-button-size-icon-m);--sinch-local-font:var(--sinch-comp-button-font-size-m-text);--sinch-local-shape-radius:var(--sinch-comp-button-shape-radius-size-m);--sinch-global-color-icon:var(--sinch-local-color-icon)}:host([data-size="l"])>#button{--sinch-local-size:var(--sinch-comp-button-size-container-l);--sinch-global-size-icon:var(--sinch-comp-button-size-icon-l);--sinch-local-shape-radius:var(--sinch-comp-button-shape-radius-size-l);--sinch-local-font:var(--sinch-comp-button-font-size-l-text)}:host([data-size="m"])>#button{--sinch-local-size:var(--sinch-comp-button-size-container-m);--sinch-global-size-icon:var(--sinch-comp-button-size-icon-m);--sinch-local-shape-radius:var(--sinch-comp-button-shape-radius-size-m);--sinch-local-font:var(--sinch-comp-button-font-size-m-text)}:host([data-size="s"])>#button{--sinch-local-size:var(--sinch-comp-button-size-container-s);--sinch-global-size-icon:var(--sinch-comp-button-size-icon-s);--sinch-local-shape-radius:var(--sinch-comp-button-shape-radius-size-s);--sinch-local-font:var(--sinch-comp-button-font-size-s-text)}:host([type=primary])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-primary-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-primary-default-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-primary-default-text-initial);--sinch-local-color-icon:var(--sinch-comp-button-color-primary-default-icon-initial);--sinch-local-color-outline-focus:var(--sinch-comp-button-color-primary-default-outilne-focus);--sinch-local-shadow:var(--sinch-comp-button-shadow-primary-initial)}:host([type=secondary])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-secondary-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-secondary-default-border-initial);--sinch-local-color-outline-focus:var(--sinch-comp-button-color-secondary-default-outline-focus);--sinch-local-color-text:var(--sinch-comp-button-color-secondary-default-text-initial);--sinch-local-color-icon:var(--sinch-comp-button-color-secondary-default-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-secondary-initial)}:host([type=tertiary])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-tertiary-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-tertiary-default-border-initial);--sinch-local-color-outline-focus:var(--sinch-comp-button-color-tertiary-default-outline-focus);--sinch-local-color-text:var(--sinch-comp-button-color-tertiary-default-text-initial);--sinch-local-color-icon:var(--sinch-comp-button-color-tertiary-default-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-tertiary-initial)}:host([type=cta-primary])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-cta-primary-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-cta-primary-default-border-initial);--sinch-local-color-outline-focus:var(--sinch-comp-button-color-cta-primary-default-outline-focus);--sinch-local-color-text:var(--sinch-comp-button-color-cta-primary-default-text-initial);--sinch-local-color-icon:var(--sinch-comp-button-color-cta-primary-default-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-primary-initial)}:host([type=cta-secondary])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-cta-secondary-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-cta-secondary-default-border-initial);--sinch-local-color-outline-focus:var(--sinch-comp-button-color-cta-secondary-default-outline-focus);--sinch-local-color-text:var(--sinch-comp-button-color-cta-secondary-default-text-initial);--sinch-local-color-icon:var(--sinch-comp-button-color-cta-secondary-default-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-secondary-initial)}:host([type=destructive])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-danger-default-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-danger-default-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-danger-default-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-danger-default-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-destructive-initial)}:host([type=primary]:focus-visible)>#button{--sinch-local-shadow:var(--sinch-comp-button-shadow-primary-focus)}:host([type=secondary]:focus-visible)>#button{--sinch-local-shadow:var(--sinch-comp-button-shadow-secondary-focus)}:host([type=tertiary]:focus-visible)>#button{--sinch-local-shadow:var(--sinch-comp-button-shadow-tertiary-focus)}:host([type=cta-primary]:focus-visible)>#button{--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-primary-focus)}:host([type=cta-secondary]:focus-visible)>#button{--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-secondary-focus)}:host([type=destructive]:focus-visible)>#button{--sinch-local-shadow:var(--sinch-comp-button-shadow-destructive-focus)}:host([type=primary]:hover)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-primary-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-primary-hover)}:host([type=primary]:active)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-primary-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-primary-active)}:host([type=secondary]:hover)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-secondary-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-secondary-hover)}:host([type=secondary]:active)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-secondary-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-secondary-active)}:host([type=tertiary]:hover)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-tertiary-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-tertiary-hover)}:host([type=tertiary]:active)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-tertiary-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-tertiary-active)}:host([type=cta-primary]:hover)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-cta-primary-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-primary-hover)}:host([type=cta-primary]:active)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-cta-primary-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-primary-active)}:host([type=cta-secondary]:hover)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-cta-secondary-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-secondary-hover)}:host([type=cta-secondary]:active)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-cta-secondary-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-secondary-active)}:host([type=destructive]:hover)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-danger-default-background-hover);--sinch-local-shadow:var(--sinch-comp-button-shadow-danger-hover)}:host([type=destructive]:active)>#button{--sinch-local-color-background:var(--sinch-comp-button-color-danger-default-background-active);--sinch-local-shadow:var(--sinch-comp-button-shadow-danger-active)}:host([type=primary][disabled])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-primary-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-primary-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-primary-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-primary-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-primary-disabled)}:host([type=secondary][disabled])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-secondary-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-secondary-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-secondary-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-secondary-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-secondary-disabled)}:host([type=tertiary][disabled])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-tertiary-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-tertiary-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-tertiary-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-tertiary-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-tertiary-disabled)}:host([type=cta-primary][disabled])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-cta-primary-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-cta-primary-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-cta-primary-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-cta-primary-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-primary-disabled)}:host([type=cta-secondary][disabled])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-cta-secondary-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-cta-secondary-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-cta-secondary-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-cta-secondary-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-cta-secondary-disabled)}:host([type=destructive][disabled])>#button{--sinch-local-color-background:var(--sinch-comp-button-color-danger-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-button-color-danger-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-button-color-danger-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-button-color-danger-disabled-icon-initial);--sinch-local-shadow:var(--sinch-comp-button-shadow-danger-disabled)}#button::before{content:"";position:absolute;inset:0;background-color:var(--sinch-local-color-background);border:1px solid var(--sinch-local-color-border);border-radius:var(--sinch-local-shape-radius);box-shadow:var(--sinch-local-shadow);pointer-events:none}:host(:not([disabled]):active) #button::before{border-width:2px}:host(:focus-visible) #button::after{position:absolute;content:"";inset:-3px;border:2px solid var(--sinch-local-color-outline-focus);border-radius:calc(var(--sinch-local-shape-radius) + 3px);pointer-events:none}#content{position:relative;display:flex;align-items:center;justify-content:center;gap:.75em;width:100%;height:100%;padding:0 1em;box-sizing:border-box;pointer-events:none}#text{font:var(--sinch-local-font);color:var(--sinch-local-color-text);overflow:hidden;white-space:nowrap;text-overflow:ellipsis;flex-shrink:1;min-width:0}</style><div id="button" inert><div id="content"><slot name="left-icon"></slot><span id="text"></span><slot name="right-icon"></slot></div></div>';
|
|
4
|
+
import { typeValues } from './utils';
|
|
5
5
|
const template = document.createElement('template');
|
|
6
6
|
template.innerHTML = templateHTML;
|
|
7
7
|
defineCustomElement('sinch-button', class extends NectaryElement {
|
|
@@ -12,7 +12,7 @@ defineCustomElement('sinch-button', class extends NectaryElement {
|
|
|
12
12
|
constructor() {
|
|
13
13
|
super();
|
|
14
14
|
const shadowRoot = this.attachShadow({
|
|
15
|
-
delegatesFocus:
|
|
15
|
+
delegatesFocus: false
|
|
16
16
|
});
|
|
17
17
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
18
18
|
this.#$button = shadowRoot.querySelector('#button');
|
|
@@ -25,14 +25,18 @@ defineCustomElement('sinch-button', class extends NectaryElement {
|
|
|
25
25
|
const {
|
|
26
26
|
signal
|
|
27
27
|
} = this.#controller;
|
|
28
|
-
this.
|
|
29
|
-
this
|
|
28
|
+
this.role = 'button';
|
|
29
|
+
this.tabIndex = 0;
|
|
30
|
+
this.addEventListener('click', this.#onButtonClick, {
|
|
30
31
|
signal
|
|
31
32
|
});
|
|
32
|
-
this
|
|
33
|
+
this.addEventListener('focus', this.#onButtonFocus, {
|
|
33
34
|
signal
|
|
34
35
|
});
|
|
35
|
-
this
|
|
36
|
+
this.addEventListener('blur', this.#onButtonBlur, {
|
|
37
|
+
signal
|
|
38
|
+
});
|
|
39
|
+
this.addEventListener('keydown', this.#onButtonKeydown, {
|
|
36
40
|
signal
|
|
37
41
|
});
|
|
38
42
|
this.addEventListener('-click', this.#onClickReactHandler, {
|
|
@@ -53,7 +57,7 @@ defineCustomElement('sinch-button', class extends NectaryElement {
|
|
|
53
57
|
this.#controller.abort();
|
|
54
58
|
}
|
|
55
59
|
static get observedAttributes() {
|
|
56
|
-
return ['text', 'disabled', 'size', '
|
|
60
|
+
return ['text', 'disabled', 'size', 'data-size'];
|
|
57
61
|
}
|
|
58
62
|
attributeChangedCallback(name, _, newVal) {
|
|
59
63
|
switch (name) {
|
|
@@ -65,17 +69,9 @@ defineCustomElement('sinch-button', class extends NectaryElement {
|
|
|
65
69
|
case 'disabled':
|
|
66
70
|
{
|
|
67
71
|
const isDisabled = isAttrTrue(newVal);
|
|
68
|
-
this.#$button.disabled = isDisabled;
|
|
69
72
|
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
70
73
|
break;
|
|
71
74
|
}
|
|
72
|
-
case 'type':
|
|
73
|
-
{
|
|
74
|
-
if ('production' !== 'production') {
|
|
75
|
-
assertType(newVal);
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
75
|
case 'size':
|
|
80
76
|
{
|
|
81
77
|
updateAttribute(this, 'data-size', newVal);
|
|
@@ -83,9 +79,6 @@ defineCustomElement('sinch-button', class extends NectaryElement {
|
|
|
83
79
|
}
|
|
84
80
|
case 'data-size':
|
|
85
81
|
{
|
|
86
|
-
if ('production' !== 'production') {
|
|
87
|
-
assertSize(newVal, 'sinch-button');
|
|
88
|
-
}
|
|
89
82
|
this.#onSizeUpdate();
|
|
90
83
|
break;
|
|
91
84
|
}
|
|
@@ -118,12 +111,6 @@ defineCustomElement('sinch-button', class extends NectaryElement {
|
|
|
118
111
|
get focusable() {
|
|
119
112
|
return true;
|
|
120
113
|
}
|
|
121
|
-
focus() {
|
|
122
|
-
this.#$button.focus();
|
|
123
|
-
}
|
|
124
|
-
blur() {
|
|
125
|
-
this.#$button.blur();
|
|
126
|
-
}
|
|
127
114
|
#onSizeUpdate() {
|
|
128
115
|
if (!this.isConnected) {
|
|
129
116
|
return;
|
|
@@ -147,8 +134,19 @@ defineCustomElement('sinch-button', class extends NectaryElement {
|
|
|
147
134
|
}
|
|
148
135
|
}
|
|
149
136
|
};
|
|
137
|
+
#onButtonKeydown = e => {
|
|
138
|
+
switch (e.code) {
|
|
139
|
+
case 'Space':
|
|
140
|
+
case 'Enter':
|
|
141
|
+
{
|
|
142
|
+
this.click();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
150
146
|
#onButtonClick = () => {
|
|
151
|
-
this.
|
|
147
|
+
if (!this.disabled) {
|
|
148
|
+
this.dispatchEvent(new CustomEvent('-click'));
|
|
149
|
+
}
|
|
152
150
|
};
|
|
153
151
|
#onButtonFocus = () => {
|
|
154
152
|
this.dispatchEvent(new CustomEvent('-focus'));
|
package/button/utils.d.ts
CHANGED
package/button/utils.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export const typeValues = ['primary', 'secondary', 'tertiary', 'cta-primary', 'cta-secondary', 'destructive'];
|
|
2
|
-
export const assertType = value => {
|
|
3
|
-
if (value === null || value.length === 0) {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
if (!typeValues.includes(value)) {
|
|
7
|
-
throw new Error(`sinch-button: invalid type attribute: ${value}`);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
1
|
+
export const typeValues = ['primary', 'secondary', 'tertiary', 'cta-primary', 'cta-secondary', 'destructive'];
|
package/chat-bubble/index.d.ts
CHANGED
package/chat-bubble/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import '../icon';
|
|
2
1
|
import { defineCustomElement, getAttribute, getLiteralAttribute, NectaryElement, updateAttribute, updateLiteralAttribute } from '../utils';
|
|
3
|
-
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{position:relative;padding:12px 16px;border-radius:16px;max-width:595px;box-sizing:border-box}:host([data-type=customer])>#wrapper{background-color:var(--sinch-sys-color-container-contrast-primary-default);border-top-left-radius:0}:host([data-type=agent-prev])>#wrapper{background-color:var(--sinch-sys-color-container-contrast-primary-active);border-top-right-radius:0}:host([data-type=agent])>#wrapper{background-color:var(--sinch-sys-color-container-complement-primary-hover);border-top-right-radius:0}#text{--sinch-global-color-text:var(--sinch-sys-color-text-default)}#icon-error,#icon-received,#icon-seen,#icon-sending,#icon-sent{display:none;position:absolute;right:16px;bottom:12px
|
|
2
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{position:relative;padding:12px 16px;border-radius:16px;max-width:595px;box-sizing:border-box}:host([data-type=customer])>#wrapper{background-color:var(--sinch-sys-color-container-contrast-primary-default);border-top-left-radius:0}:host([data-type=agent-prev])>#wrapper{background-color:var(--sinch-sys-color-container-contrast-primary-active);border-top-right-radius:0}:host([data-type=agent])>#wrapper{background-color:var(--sinch-sys-color-container-complement-primary-hover);border-top-right-radius:0}#text{--sinch-global-color-text:var(--sinch-sys-color-text-default)}#icon-error,#icon-received,#icon-seen,#icon-sending,#icon-sent{display:none;position:absolute;right:16px;bottom:12px;height:16px}#icon-sending{fill:var(--sinch-sys-color-text-default)}#icon-sent{fill:var(--sinch-sys-color-text-default)}#icon-received{fill:var(--sinch-sys-color-text-default)}#icon-seen{fill:var(--sinch-sys-color-feedback-success-contrast)}#icon-error{fill:var(--sinch-sys-color-feedback-invalid-contrast)}:host([status=error]) #icon-error,:host([status=received]) #icon-received,:host([status=seen]) #icon-seen,:host([status=sending]) #icon-sending,:host([status=sent]) #icon-sent{display:block}:host([status]:not([status=""])) #wrapper{padding-right:42px}</style><div id="wrapper"><sinch-text id="text" type="m"></sinch-text><svg id="icon-sending" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2ZM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8Zm-.22-13h-.06c-.4 0-.72.32-.72.72v4.72c0 .35.18.68.49.86l4.15 2.49c.34.2.78.1.98-.24a.71.71 0 0 0-.25-.99l-3.87-2.3V7.72c0-.4-.32-.72-.72-.72Z"/></svg><svg id="icon-sent" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9 16.17 5.53 12.7a.996.996 0 1 0-1.41 1.41l4.18 4.18c.39.39 1.02.39 1.41 0L20.29 7.71a.996.996 0 1 0-1.41-1.41L9 16.17Z"/></svg><svg id="icon-received" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M17.3 6.3a.996.996 0 0 0-1.41 0l-5.64 5.64 1.41 1.41L17.3 7.7c.38-.38.38-1.02 0-1.4Zm4.24-.01-9.88 9.88-3.48-3.47a.996.996 0 1 0-1.41 1.41l4.18 4.18c.39.39 1.02.39 1.41 0L22.95 7.71a.996.996 0 0 0 0-1.41h-.01a.975.975 0 0 0-1.4-.01ZM1.12 14.12 5.3 18.3c.39.39 1.02.39 1.41 0l.7-.7-4.88-4.9a.996.996 0 0 0-1.41 0c-.39.39-.39 1.03 0 1.42Z"/></svg><svg id="icon-seen" id="icon-received" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M17.3 6.3a.996.996 0 0 0-1.41 0l-5.64 5.64 1.41 1.41L17.3 7.7c.38-.38.38-1.02 0-1.4Zm4.24-.01-9.88 9.88-3.48-3.47a.996.996 0 1 0-1.41 1.41l4.18 4.18c.39.39 1.02.39 1.41 0L22.95 7.71a.996.996 0 0 0 0-1.41h-.01a.975.975 0 0 0-1.4-.01ZM1.12 14.12 5.3 18.3c.39.39 1.02.39 1.41 0l.7-.7-4.88-4.9a.996.996 0 0 0-1.41 0c-.39.39-.39 1.03 0 1.42Z"/></svg><svg id="icon-error" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 7c.55 0 1 .45 1 1v4c0 .55-.45 1-1 1s-1-.45-1-1V8c0-.55.45-1 1-1Zm-.01-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2ZM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8Zm1-3h-2v-2h2v2Z"/></svg></div>';
|
|
4
3
|
import { statusValues, typeValues } from './utils';
|
|
5
4
|
const template = document.createElement('template');
|
|
6
5
|
template.innerHTML = templateHTML;
|
package/checkbox/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
2
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;flex-direction:row;box-sizing:border-box;width:100%;--sinch-local-size:24px;--sinch-local-color-background:var(--sinch-comp-checkbox-color-default-background-initial);--sinch-local-color-background-hover:var(--sinch-comp-checkbox-color-default-background-hover);--sinch-local-color-background-active:var(--sinch-comp-checkbox-color-default-background-active);--sinch-local-color-border:var(--sinch-comp-checkbox-color-default-border-initial);--sinch-local-color-border-hover:var(--sinch-comp-checkbox-color-default-border-hover);--sinch-local-color-border-active:var(--sinch-comp-checkbox-color-default-border-active);--sinch-local-color-text:var(--sinch-comp-checkbox-color-default-text-initial)}:host([invalid])>#wrapper{--sinch-local-color-background:var(--sinch-comp-checkbox-color-invalid-background-initial);--sinch-local-color-background-hover:var(--sinch-comp-checkbox-color-invalid-background-hover);--sinch-local-color-background-active:var(--sinch-comp-checkbox-color-invalid-background-active);--sinch-local-color-border:var(--sinch-comp-checkbox-color-invalid-border-initial);--sinch-local-color-border-hover:var(--sinch-comp-checkbox-color-invalid-border-hover);--sinch-local-color-border-active:var(--sinch-comp-checkbox-color-invalid-border-active);--sinch-local-color-text:var(--sinch-comp-checkbox-color-invalid-text-initial)}:host([checked])>#wrapper{--sinch-local-color-background:var(--sinch-comp-checkbox-color-checked-background-initial);--sinch-local-color-background-hover:var(--sinch-comp-checkbox-color-checked-background-hover);--sinch-local-color-background-active:var(--sinch-comp-checkbox-color-checked-background-active);--sinch-local-color-border:var(--sinch-comp-checkbox-color-checked-border-initial);--sinch-local-color-border-hover:var(--sinch-comp-checkbox-color-checked-border-hover);--sinch-local-color-border-active:var(--sinch-comp-checkbox-color-checked-border-active)}:host([disabled])>#wrapper{--sinch-local-color-background:var(--sinch-comp-checkbox-color-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-checkbox-color-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-checkbox-color-disabled-text-initial)}:host([disabled][checked])>#wrapper{--sinch-local-color-background:var(--sinch-comp-checkbox-color-checked-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-checkbox-color-checked-disabled-border-initial)}#checkbox{all:initial;display:block;width:var(--sinch-local-size);height:var(--sinch-local-size);cursor:pointer}#checkbox:disabled{cursor:initial}#icon-container{position:relative;width:var(--sinch-local-size);height:var(--sinch-local-size);align-self:flex-start}#checkbox::before{content:"";position:absolute;top:0;left:0;width:var(--sinch-local-size);height:var(--sinch-local-size);border:2px solid var(--sinch-comp-checkbox-color-default-outline-focus);border-radius:calc(var(--sinch-comp-checkbox-shape-radius) + 3px);transition:opacity .1s linear;opacity:0;box-sizing:border-box;pointer-events:none}#checkbox:focus-visible::before{opacity:1}#checkbox::after{content:"";position:absolute;width:18px;height:18px;inset:0;margin:auto;background-color:var(--sinch-local-color-background);border:
|
|
2
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;flex-direction:row;box-sizing:border-box;width:100%;--sinch-local-size:24px;--sinch-local-color-background:var(--sinch-comp-checkbox-color-default-background-initial);--sinch-local-color-background-hover:var(--sinch-comp-checkbox-color-default-background-hover);--sinch-local-color-background-active:var(--sinch-comp-checkbox-color-default-background-active);--sinch-local-color-border:var(--sinch-comp-checkbox-color-default-border-initial);--sinch-local-color-border-hover:var(--sinch-comp-checkbox-color-default-border-hover);--sinch-local-color-border-active:var(--sinch-comp-checkbox-color-default-border-active);--sinch-local-color-text:var(--sinch-comp-checkbox-color-default-text-initial)}:host([invalid])>#wrapper{--sinch-local-color-background:var(--sinch-comp-checkbox-color-invalid-background-initial);--sinch-local-color-background-hover:var(--sinch-comp-checkbox-color-invalid-background-hover);--sinch-local-color-background-active:var(--sinch-comp-checkbox-color-invalid-background-active);--sinch-local-color-border:var(--sinch-comp-checkbox-color-invalid-border-initial);--sinch-local-color-border-hover:var(--sinch-comp-checkbox-color-invalid-border-hover);--sinch-local-color-border-active:var(--sinch-comp-checkbox-color-invalid-border-active);--sinch-local-color-text:var(--sinch-comp-checkbox-color-invalid-text-initial)}:host([checked])>#wrapper{--sinch-local-color-background:var(--sinch-comp-checkbox-color-checked-background-initial);--sinch-local-color-background-hover:var(--sinch-comp-checkbox-color-checked-background-hover);--sinch-local-color-background-active:var(--sinch-comp-checkbox-color-checked-background-active);--sinch-local-color-border:var(--sinch-comp-checkbox-color-checked-border-initial);--sinch-local-color-border-hover:var(--sinch-comp-checkbox-color-checked-border-hover);--sinch-local-color-border-active:var(--sinch-comp-checkbox-color-checked-border-active)}:host([disabled])>#wrapper{--sinch-local-color-background:var(--sinch-comp-checkbox-color-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-checkbox-color-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-checkbox-color-disabled-text-initial)}:host([disabled][checked])>#wrapper{--sinch-local-color-background:var(--sinch-comp-checkbox-color-checked-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-checkbox-color-checked-disabled-border-initial)}#checkbox{all:initial;display:block;width:var(--sinch-local-size);height:var(--sinch-local-size);cursor:pointer}#checkbox:disabled{cursor:initial}#icon-container{position:relative;width:var(--sinch-local-size);height:var(--sinch-local-size);align-self:flex-start}#checkbox::before{content:"";position:absolute;top:0;left:0;width:var(--sinch-local-size);height:var(--sinch-local-size);border:2px solid var(--sinch-comp-checkbox-color-default-outline-focus);border-radius:calc(var(--sinch-comp-checkbox-shape-radius) + 3px);transition:opacity .1s linear;opacity:0;box-sizing:border-box;pointer-events:none}#checkbox:focus-visible::before{opacity:1}#checkbox::after{content:"";position:absolute;width:18px;height:18px;inset:0;margin:auto;background-color:var(--sinch-local-color-background);border:1px solid var(--sinch-local-color-border);border-radius:var(--sinch-comp-checkbox-shape-radius);transition:background-color .1s linear;box-sizing:border-box;pointer-events:none}#checkbox:enabled:hover::after{background-color:var(--sinch-local-color-background-hover);border-color:var(--sinch-local-color-border-hover)}#checkbox:enabled:active::after{background-color:var(--sinch-local-color-background-active);border-color:var(--sinch-local-color-border-active)}#icon-checkmark,#icon-indeterminate{position:absolute;left:4px;top:4px;width:16px;height:16px;transition:opacity .1s linear;opacity:0;pointer-events:none;fill:var(--sinch-sys-color-container-main-default)}@media (prefers-reduced-motion){#checkbox::after,#checkbox::before,#icon-checkmark,#icon-indeterminate{transition:none}}#label{display:none;flex:1;align-self:center;padding-left:7px;font:var(--sinch-comp-checkbox-font-label);color:var(--sinch-local-color-text);cursor:pointer}:host([disabled]) #label{cursor:initial}:host([text]:not([text=""])) #label{display:block}:host(:not([indeterminate])) #checkbox:checked~#icon-checkmark{opacity:1}:host([indeterminate]) #checkbox:checked~#icon-indeterminate{opacity:1}</style><div id="wrapper"><div id="icon-container"><input id="checkbox" type="checkbox"/><svg id="icon-checkmark" viewBox="0 0 24 24" aria-hidden="true"><path d="M9 16.17 5.53 12.7a.996.996 0 1 0-1.41 1.41l4.18 4.18c.39.39 1.02.39 1.41 0L20.29 7.71a.996.996 0 1 0-1.41-1.41L9 16.17Z"/></svg><svg id="icon-indeterminate" viewBox="0 0 24 24" aria-hidden="true"><path d="M18 13H6c-.55 0-1-.45-1-1s.45-1 1-1h12c.55 0 1 .45 1 1s-.45 1-1 1Z"/></svg></div><label for="checkbox" id="label"></label></div>';
|
|
3
3
|
const template = document.createElement('template');
|
|
4
4
|
template.innerHTML = templateHTML;
|
|
5
5
|
defineCustomElement('sinch-checkbox', class extends NectaryElement {
|
|
@@ -7,9 +7,7 @@ defineCustomElement('sinch-checkbox', class extends NectaryElement {
|
|
|
7
7
|
#$label;
|
|
8
8
|
constructor() {
|
|
9
9
|
super();
|
|
10
|
-
const shadowRoot = this.attachShadow(
|
|
11
|
-
delegatesFocus: true
|
|
12
|
-
});
|
|
10
|
+
const shadowRoot = this.attachShadow();
|
|
13
11
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
14
12
|
this.#$input = shadowRoot.querySelector('input');
|
|
15
13
|
this.#$label = shadowRoot.querySelector('label');
|
|
@@ -34,7 +32,10 @@ defineCustomElement('sinch-checkbox', class extends NectaryElement {
|
|
|
34
32
|
static get observedAttributes() {
|
|
35
33
|
return ['checked', 'disabled', 'text', 'invalid', 'indeterminate'];
|
|
36
34
|
}
|
|
37
|
-
attributeChangedCallback(name,
|
|
35
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
36
|
+
if (newVal === oldVal) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
38
39
|
switch (name) {
|
|
39
40
|
case 'text':
|
|
40
41
|
{
|
|
@@ -107,10 +108,6 @@ defineCustomElement('sinch-checkbox', class extends NectaryElement {
|
|
|
107
108
|
e.stopPropagation();
|
|
108
109
|
const isChecked = this.#$input.checked;
|
|
109
110
|
this.#$input.checked = this.checked;
|
|
110
|
-
this.dispatchEvent(new CustomEvent('change', {
|
|
111
|
-
detail: isChecked,
|
|
112
|
-
bubbles: true
|
|
113
|
-
}));
|
|
114
111
|
this.dispatchEvent(new CustomEvent('-change', {
|
|
115
112
|
detail: isChecked
|
|
116
113
|
}));
|
package/chip/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import '../text';
|
|
2
2
|
import '../icon';
|
|
3
3
|
import { defineCustomElement, getBooleanAttribute, getAttribute, updateBooleanAttribute, updateAttribute, NectaryElement, getReactEventHandler, isAttrTrue } from '../utils';
|
|
4
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#button{all:initial;position:relative;display:flex;flex-direction:row;align-items:center;gap:4px;width:100%;height:var(--sinch-comp-chip-size-container-m);padding:0 5px 0 9px;border-radius:var(--sinch-comp-chip-shape-radius);background-color:var(--sinch-comp-chip-color-neutral-default-background-initial);box-sizing:border-box
|
|
5
|
-
import {
|
|
4
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0;cursor:pointer}#button{all:initial;position:relative;display:flex;flex-direction:row;align-items:center;gap:4px;width:100%;height:var(--sinch-comp-chip-size-container-m);padding:0 5px 0 9px;border-radius:var(--sinch-comp-chip-shape-radius);background-color:var(--sinch-comp-chip-color-neutral-default-background-initial);box-sizing:border-box;--sinch-global-color-text:var(--sinch-comp-chip-color-neutral-default-foreground-initial);--sinch-global-color-icon:var(--sinch-comp-chip-color-neutral-default-foreground-initial);--sinch-global-size-icon:var(--sinch-comp-chip-size-icon-m)}:host(:focus-visible)>#button::after{content:"";position:absolute;inset:-4px;border-radius:calc(var(--sinch-comp-chip-shape-radius) + 4px);border:2px solid var(--sinch-comp-chip-color-outiline-focus);pointer-events:none}#text{flex:1;--sinch-comp-text-font:var(--sinch-comp-chip-font-size-m-label)}:host([small]) #button{height:var(--sinch-comp-chip-size-container-s);padding:0 3px 0 7px;--sinch-global-size-icon:var(--sinch-comp-chip-size-icon-s)}:host([small]) #text{--sinch-comp-text-font:var(--sinch-comp-chip-font-size-s-label)}::slotted(*){margin-left:-4px}</style><div id="button" inert><slot name="icon"></slot><sinch-text id="text" type="xs" ellipsis></sinch-text><sinch-icon id="icon-close" name="cancel"></sinch-icon></div>';
|
|
5
|
+
import { getChipColorBg, getChipColorFg } from './utils';
|
|
6
6
|
const template = document.createElement('template');
|
|
7
7
|
template.innerHTML = templateHTML;
|
|
8
8
|
defineCustomElement('sinch-chip', class extends NectaryElement {
|
|
@@ -12,7 +12,7 @@ defineCustomElement('sinch-chip', class extends NectaryElement {
|
|
|
12
12
|
constructor() {
|
|
13
13
|
super();
|
|
14
14
|
const shadowRoot = this.attachShadow({
|
|
15
|
-
delegatesFocus:
|
|
15
|
+
delegatesFocus: false
|
|
16
16
|
});
|
|
17
17
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
18
18
|
this.#$button = shadowRoot.querySelector('#button');
|
|
@@ -24,14 +24,18 @@ defineCustomElement('sinch-chip', class extends NectaryElement {
|
|
|
24
24
|
const {
|
|
25
25
|
signal
|
|
26
26
|
} = this.#controller;
|
|
27
|
-
this.
|
|
28
|
-
this
|
|
27
|
+
this.role = 'button';
|
|
28
|
+
this.tabIndex = 0;
|
|
29
|
+
this.addEventListener('click', this.#onClick, {
|
|
29
30
|
signal
|
|
30
31
|
});
|
|
31
|
-
this
|
|
32
|
+
this.addEventListener('focus', this.#onFocus, {
|
|
32
33
|
signal
|
|
33
34
|
});
|
|
34
|
-
this
|
|
35
|
+
this.addEventListener('blur', this.#onBlur, {
|
|
36
|
+
signal
|
|
37
|
+
});
|
|
38
|
+
this.addEventListener('keydown', this.#onKeydown, {
|
|
35
39
|
signal
|
|
36
40
|
});
|
|
37
41
|
this.addEventListener('-click', this.#onClickReactHandler, {
|
|
@@ -98,9 +102,6 @@ defineCustomElement('sinch-chip', class extends NectaryElement {
|
|
|
98
102
|
}
|
|
99
103
|
const colorName = this.color;
|
|
100
104
|
if (colorName !== null && colorName.length > 0) {
|
|
101
|
-
if ('production' !== 'production') {
|
|
102
|
-
assertChipColor(this, colorName);
|
|
103
|
-
}
|
|
104
105
|
const bg = getChipColorBg(colorName);
|
|
105
106
|
const fg = getChipColorFg(colorName);
|
|
106
107
|
this.#$button.style.setProperty('background-color', bg);
|
|
@@ -115,19 +116,21 @@ defineCustomElement('sinch-chip', class extends NectaryElement {
|
|
|
115
116
|
get focusable() {
|
|
116
117
|
return true;
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
#onKeydown = e => {
|
|
120
|
+
switch (e.code) {
|
|
121
|
+
case 'Space':
|
|
122
|
+
{
|
|
123
|
+
this.click();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
#onClick = () => {
|
|
125
128
|
this.dispatchEvent(new CustomEvent('-click'));
|
|
126
129
|
};
|
|
127
|
-
#
|
|
130
|
+
#onFocus = () => {
|
|
128
131
|
this.dispatchEvent(new CustomEvent('-focus'));
|
|
129
132
|
};
|
|
130
|
-
#
|
|
133
|
+
#onBlur = () => {
|
|
131
134
|
this.dispatchEvent(new CustomEvent('-blur'));
|
|
132
135
|
};
|
|
133
136
|
#onFocusReactHandler = () => {
|
package/chip/utils.d.ts
CHANGED
package/chip/utils.js
CHANGED
|
@@ -3,9 +3,4 @@ export const getChipColorBg = id => {
|
|
|
3
3
|
};
|
|
4
4
|
export const getChipColorFg = id => {
|
|
5
5
|
return `var(--sinch-comp-chip-color-${id}-default-foreground-initial)`;
|
|
6
|
-
};
|
|
7
|
-
export const assertChipColor = (root, id) => {
|
|
8
|
-
if (id === null || window.getComputedStyle(root).getPropertyValue(`--sinch-comp-chip-color-${id}-default-background-initial`).length === 0) {
|
|
9
|
-
throw new Error(`Invalid sinch-chip color name: ${id}`);
|
|
10
|
-
}
|
|
11
6
|
};
|