@nectary/components 2.2.1 → 2.2.3
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 +21 -16
- package/accordion-item/index.js +9 -17
- package/action-menu/index.js +6 -9
- package/action-menu-option/index.js +3 -7
- package/alert/index.js +12 -12
- package/avatar/index.js +26 -23
- package/badge/index.js +2 -2
- package/button/index.js +6 -4
- package/card/index.js +6 -6
- package/checkbox/index.js +3 -3
- package/chip/index.js +2 -2
- package/code-tag/index.js +6 -9
- package/color-menu/index.js +10 -17
- package/color-menu-option/index.d.ts +0 -1
- package/color-menu-option/index.js +2 -6
- package/color-swatch/index.js +9 -9
- package/date-picker/index.js +0 -3
- package/dialog/index.js +16 -10
- package/dialog/types.d.ts +2 -0
- package/emoji/index.js +3 -0
- package/field/index.js +4 -4
- package/file-drop/index.js +21 -19
- package/file-picker/index.js +18 -18
- package/file-status/index.js +8 -5
- package/flag/index.js +3 -0
- package/help-tooltip/index.d.ts +1 -0
- package/help-tooltip/index.js +2 -1
- package/horizontal-stepper/index.js +1 -4
- package/horizontal-stepper-item/index.js +0 -3
- package/icon-button/index.js +5 -6
- package/input/index.js +8 -5
- package/link/index.js +2 -2
- package/package.json +1 -1
- package/pagination/index.js +2 -6
- package/pop/index.js +5 -4
- package/popover/index.js +2 -2
- package/progress/index.js +4 -4
- package/progress-stepper/index.js +1 -4
- package/progress-stepper-item/index.js +5 -5
- package/radio/index.js +28 -24
- package/radio-option/index.js +12 -34
- package/rich-text/index.js +12 -12
- package/segment/index.js +5 -2
- package/segmented-control/index.js +42 -21
- package/segmented-control-option/index.js +23 -30
- package/segmented-icon-control/index.js +46 -26
- package/segmented-icon-control-option/index.js +25 -32
- package/select-button/index.js +3 -4
- package/select-menu/index.js +0 -3
- package/select-menu-option/index.js +2 -2
- package/skeleton/index.js +0 -3
- package/spinner/index.js +0 -3
- package/table-head-cell/index.js +2 -2
- package/table-row/index.js +2 -2
- package/tabs/index.js +7 -7
- package/tabs-icon-option/index.js +2 -2
- package/tabs-option/index.js +2 -2
- package/tag/index.js +5 -2
- package/text/index.js +5 -2
- package/textarea/index.js +12 -6
- package/tile-control/index.js +2 -2
- package/tile-control-option/index.js +0 -3
- package/time-picker/index.js +3 -4
- package/title/index.js +4 -4
- package/toast/index.js +0 -3
- package/toggle/index.js +2 -2
- package/tooltip/index.js +1 -1
- package/utils/dom.d.ts +1 -0
- package/utils/dom.js +5 -2
- package/vertical-stepper/index.js +1 -4
- package/vertical-stepper-item/index.js +0 -3
package/progress/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../text';
|
|
2
|
-
import { defineCustomElement, updateAttribute, NectaryElement, updateBooleanAttribute, getIntegerAttribute, getBooleanAttribute, attrValueToInteger, isAttrTrue } from '../utils';
|
|
2
|
+
import { defineCustomElement, updateAttribute, NectaryElement, updateBooleanAttribute, getIntegerAttribute, getBooleanAttribute, attrValueToInteger, isAttrTrue, isAttrEqual } from '../utils';
|
|
3
3
|
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;align-items:center;height:24px}#bar,#progress{height:8px;border-radius:4px}#progress{background-color:var(--sinch-comp-progress-color-default-background-initial);flex:1;min-width:0}#bar{background-color:var(--sinch-comp-progress-color-default-bar-initial);width:0}#text{display:none;width:46px;--sinch-global-color-text:var(--sinch-comp-progress-color-default-text-initial)}:host([detailed]) #text{display:block}</style><div id="wrapper"><sinch-text id="text" type="m"></sinch-text><div id="progress"><div id="bar"></div></div></div>';
|
|
4
4
|
const template = document.createElement('template');
|
|
5
5
|
template.innerHTML = templateHTML;
|
|
@@ -20,9 +20,6 @@ defineCustomElement('sinch-progress', class extends NectaryElement {
|
|
|
20
20
|
return ['value', 'detailed'];
|
|
21
21
|
}
|
|
22
22
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
23
|
-
if (oldVal === newVal) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
23
|
switch (name) {
|
|
27
24
|
case 'value':
|
|
28
25
|
{
|
|
@@ -38,6 +35,9 @@ defineCustomElement('sinch-progress', class extends NectaryElement {
|
|
|
38
35
|
}
|
|
39
36
|
case 'detailed':
|
|
40
37
|
{
|
|
38
|
+
if (isAttrEqual(oldVal, newVal)) {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
41
|
updateBooleanAttribute(this, name, isAttrTrue(newVal));
|
|
42
42
|
break;
|
|
43
43
|
}
|
|
@@ -40,10 +40,7 @@ defineCustomElement('sinch-progress-stepper', class extends NectaryElement {
|
|
|
40
40
|
static get observedAttributes() {
|
|
41
41
|
return ['value', 'progressvalue'];
|
|
42
42
|
}
|
|
43
|
-
attributeChangedCallback(name,
|
|
44
|
-
if (oldVal === newVal) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
43
|
+
attributeChangedCallback(name, _, newVal) {
|
|
47
44
|
switch (name) {
|
|
48
45
|
case 'value':
|
|
49
46
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../text';
|
|
2
|
-
import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
2
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrEqual, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
3
3
|
const templateHTML = '<style>:host{display:block;outline:0}#button{position:relative;display:flex;flex-direction:column;gap:4px;width:100%;height:100%;padding:8px 4px 4px;box-sizing:border-box;cursor:pointer;border-radius:var(--sinch-comp-progress-stepper-step-shape-radius)}:host([data-status=inactive])>#button{cursor:not-allowed}:host([data-status=incomplete]:hover)>#button{background-color:var(--sinch-comp-progress-stepper-step-color-incomplete-background-hover)}:host([data-status=complete]:hover)>#button{background-color:var(--sinch-comp-progress-stepper-step-color-complete-background-hover)}:host([data-status=invalid]:hover)>#button{background-color:var(--sinch-comp-progress-stepper-step-color-invalid-background-hover)}#outline{position:absolute;inset:-2px;border:2px solid var(--sinch-comp-progress-stepper-step-color-outline-focus);border-radius:calc(var(--sinch-comp-progress-stepper-step-shape-radius) + 2px);pointer-events:none;opacity:0}:host(:focus-visible) #outline{opacity:1}#text{flex-shrink:1;flex-basis:auto;min-width:0;transform:translate(0,0);will-change:transform;transition:transform .25s ease-out;padding-right:24px}:host([data-status=incomplete]) #text{--sinch-global-color-text:var(--sinch-comp-progress-stepper-step-color-incomplete-label-default);--sinch-comp-text-font:var(--sinch-comp-progress-stepper-step-font-incomplete-label)}:host([data-status=complete]) #text{--sinch-global-color-text:var(--sinch-comp-progress-stepper-step-color-complete-label-default);--sinch-comp-text-font:var(--sinch-comp-progress-stepper-step-font-complete-label)}:host([data-status=inactive]) #text{--sinch-global-color-text:var(--sinch-comp-progress-stepper-step-color-inactive-label-default);--sinch-comp-text-font:var(--sinch-comp-progress-stepper-step-font-inactive-label)}:host([invalid]) #text{--sinch-global-color-text:var(--sinch-comp-progress-stepper-step-color-invalid-label-default);--sinch-comp-text-font:var(--sinch-comp-progress-stepper-step-font-invalid-label);transform:translate(24px,0)}:host([data-status=incomplete][data-checked]) #text{--sinch-global-color-text:var(--sinch-comp-progress-stepper-step-color-incomplete-current-label-default);--sinch-comp-text-font:var(--sinch-comp-progress-stepper-step-font-incomplete-current-label)}:host([data-status=complete][data-checked]) #text{--sinch-global-color-text:var(--sinch-comp-progress-stepper-step-color-complete-current-label-default);--sinch-comp-text-font:var(--sinch-comp-progress-stepper-step-font-complete-current-label)}:host([invalid][data-checked]) #text{--sinch-global-color-text:var(--sinch-comp-progress-stepper-step-color-invalid-label-default);--sinch-comp-text-font:var(--sinch-comp-progress-stepper-step-font-invalid-current-label)}#icon-error{position:absolute;left:0;top:4px;pointer-events:none;opacity:0;transition:opacity .25s ease-in-out;--sinch-global-color-icon:var(--sinch-comp-progress-stepper-step-color-invalid-icon-default);--sinch-global-size-icon:16px}:host([invalid]) #icon-error{opacity:1}#progress{height:8px;border-radius:4px;transition:background-color .25s ease-in-out}:host([data-status=incomplete]) #progress{background-color:var(--sinch-comp-progress-stepper-step-color-incomplete-progress-background)}:host([data-status=complete]) #progress{background-color:var(--sinch-comp-progress-stepper-step-color-complete-progress-background)}:host([data-status=inactive]) #progress{background-color:var(--sinch-comp-progress-stepper-step-color-inactive-progress-background)}:host([invalid]) #progress{background-color:var(--sinch-comp-progress-stepper-step-color-invalid-progress-background)}#bar{width:8px;height:8px;border-radius:4px;opacity:0;transition:width .25s ease-in-out,opacity .25s ease-in-out}:host([data-status=incomplete]) #bar{background-color:var(--sinch-comp-progress-stepper-step-color-incomplete-progress-bar)}:host([data-status=complete]) #bar{background-color:var(--sinch-comp-progress-stepper-step-color-complete-progress-bar);width:100%}:host([data-status=complete]:not([invalid])) #bar,:host([data-status=incomplete]:not([invalid])) #bar{opacity:1}#label-bar{position:relative}</style><div id="button"><div id="progress"><div id="bar"></div></div><div id="label-bar"><sinch-icon id="icon-error" name="report_problem" aria-hidden="true"></sinch-icon><sinch-text id="text" type="m"></sinch-text></div><div id="outline"></div></div>';
|
|
4
4
|
import { ATTR_PROGRESS_STEPPER_ITEM_ACTIVE_DESCENDANT, ATTR_PROGRESS_STEPPER_ITEM_CHECKED, ATTR_PROGRESS_STEPPER_ITEM_STATUS, isProgressStepperItemActive, isProgressStepperItemActiveDescendant } from './utils';
|
|
5
5
|
const template = document.createElement('template');
|
|
@@ -22,9 +22,6 @@ defineCustomElement('sinch-progress-stepper-item', class extends NectaryElement
|
|
|
22
22
|
return ['text', 'invalid', ATTR_PROGRESS_STEPPER_ITEM_STATUS, ATTR_PROGRESS_STEPPER_ITEM_CHECKED, ATTR_PROGRESS_STEPPER_ITEM_ACTIVE_DESCENDANT];
|
|
23
23
|
}
|
|
24
24
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
25
|
-
if (oldVal === newVal) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
25
|
switch (name) {
|
|
29
26
|
case 'text':
|
|
30
27
|
{
|
|
@@ -48,9 +45,12 @@ defineCustomElement('sinch-progress-stepper-item', class extends NectaryElement
|
|
|
48
45
|
}
|
|
49
46
|
case 'invalid':
|
|
50
47
|
{
|
|
48
|
+
if (isAttrEqual(oldVal, newVal)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
51
|
const isInvalid = isAttrTrue(newVal);
|
|
52
|
-
updateBooleanAttribute(this, 'invalid', isInvalid);
|
|
53
52
|
updateExplicitBooleanAttribute(this, 'aria-invalid', isInvalid);
|
|
53
|
+
updateBooleanAttribute(this, 'invalid', isInvalid);
|
|
54
54
|
break;
|
|
55
55
|
}
|
|
56
56
|
}
|
package/radio/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
1
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, getTargetByAttribute, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
2
|
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:column;gap:8px;box-sizing:border-box;width:100%}</style><div id="wrapper"><slot></slot></div>';
|
|
3
3
|
const template = document.createElement('template');
|
|
4
4
|
template.innerHTML = templateHTML;
|
|
5
5
|
defineCustomElement('sinch-radio', class extends NectaryElement {
|
|
6
6
|
#$slot;
|
|
7
|
+
#controller = null;
|
|
7
8
|
constructor() {
|
|
8
9
|
super();
|
|
9
10
|
const shadowRoot = this.attachShadow();
|
|
@@ -11,17 +12,22 @@ defineCustomElement('sinch-radio', class extends NectaryElement {
|
|
|
11
12
|
this.#$slot = shadowRoot.querySelector('slot');
|
|
12
13
|
}
|
|
13
14
|
connectedCallback() {
|
|
14
|
-
this
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
this.#controller = new AbortController();
|
|
16
|
+
const {
|
|
17
|
+
signal
|
|
18
|
+
} = this.#controller;
|
|
19
|
+
const options = {
|
|
20
|
+
signal
|
|
21
|
+
};
|
|
22
|
+
this.role = 'radiogroup';
|
|
23
|
+
this.#$slot.addEventListener('slotchange', this.#onSlotChange, options);
|
|
24
|
+
this.#$slot.addEventListener('keydown', this.#onOptionKeyDown, options);
|
|
25
|
+
this.#$slot.addEventListener('click', this.#onOptionClick, options);
|
|
26
|
+
this.addEventListener('-change', this.#onChangeReactHandler, options);
|
|
19
27
|
}
|
|
20
28
|
disconnectedCallback() {
|
|
21
|
-
this
|
|
22
|
-
this
|
|
23
|
-
this.#$slot.removeEventListener('option-change', this.#onOptionChange);
|
|
24
|
-
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
29
|
+
this.#controller.abort();
|
|
30
|
+
this.#controller = null;
|
|
25
31
|
}
|
|
26
32
|
static get observedAttributes() {
|
|
27
33
|
return ['value', 'invalid'];
|
|
@@ -39,9 +45,6 @@ defineCustomElement('sinch-radio', class extends NectaryElement {
|
|
|
39
45
|
return getBooleanAttribute(this, 'invalid');
|
|
40
46
|
}
|
|
41
47
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
42
|
-
if (oldVal === newVal) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
48
|
switch (name) {
|
|
46
49
|
case 'value':
|
|
47
50
|
{
|
|
@@ -64,7 +67,7 @@ defineCustomElement('sinch-radio', class extends NectaryElement {
|
|
|
64
67
|
const $option = this.#getPrevOption();
|
|
65
68
|
if ($option !== null) {
|
|
66
69
|
$option.focus();
|
|
67
|
-
|
|
70
|
+
$option.click();
|
|
68
71
|
}
|
|
69
72
|
break;
|
|
70
73
|
}
|
|
@@ -75,7 +78,7 @@ defineCustomElement('sinch-radio', class extends NectaryElement {
|
|
|
75
78
|
const $option = this.#getNextOption();
|
|
76
79
|
if ($option !== null) {
|
|
77
80
|
$option.focus();
|
|
78
|
-
|
|
81
|
+
$option.click();
|
|
79
82
|
}
|
|
80
83
|
break;
|
|
81
84
|
}
|
|
@@ -84,9 +87,15 @@ defineCustomElement('sinch-radio', class extends NectaryElement {
|
|
|
84
87
|
#onSlotChange = () => {
|
|
85
88
|
this.#onValueChange(this.value);
|
|
86
89
|
};
|
|
87
|
-
#
|
|
88
|
-
e
|
|
89
|
-
|
|
90
|
+
#onOptionClick = e => {
|
|
91
|
+
const target = getTargetByAttribute(e, 'value');
|
|
92
|
+
if (target === null || target.hasAttribute('disabled')) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const value = getAttribute(target, 'value');
|
|
96
|
+
this.dispatchEvent(new CustomEvent('-change', {
|
|
97
|
+
detail: value
|
|
98
|
+
}));
|
|
90
99
|
};
|
|
91
100
|
#onValueChange(value) {
|
|
92
101
|
for (const $option of this.#$slot.assignedElements()) {
|
|
@@ -94,11 +103,6 @@ defineCustomElement('sinch-radio', class extends NectaryElement {
|
|
|
94
103
|
updateBooleanAttribute($option, 'checked', isChecked);
|
|
95
104
|
}
|
|
96
105
|
}
|
|
97
|
-
#dispatchChangeEvent(value) {
|
|
98
|
-
this.dispatchEvent(new CustomEvent('-change', {
|
|
99
|
-
detail: value
|
|
100
|
-
}));
|
|
101
|
-
}
|
|
102
106
|
#getFirstOption() {
|
|
103
107
|
for (const $option of this.#$slot.assignedElements()) {
|
|
104
108
|
if ($option.disabled !== true) {
|
|
@@ -134,7 +138,7 @@ defineCustomElement('sinch-radio', class extends NectaryElement {
|
|
|
134
138
|
return $options[(currentIndex - 1 + $options.length) % $options.length];
|
|
135
139
|
}
|
|
136
140
|
#getEnabledRadioElements() {
|
|
137
|
-
return this.#$slot.assignedElements().filter(el => el.disabled
|
|
141
|
+
return this.#$slot.assignedElements().filter(el => !el.hasAttribute('disabled'));
|
|
138
142
|
}
|
|
139
143
|
#findSelectedOption(elements) {
|
|
140
144
|
return elements.find(el => el.checked) ?? null;
|
package/radio-option/index.js
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
|
-
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;box-sizing:border-box;width:100
|
|
1
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrEqual, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
2
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;box-sizing:border-box;width:100%;min-height:24px;--sinch-local-color-background:var(--sinch-comp-radio-color-default-background-initial);--sinch-local-color-background-hover:var(--sinch-comp-radio-color-default-background-hover);--sinch-local-color-background-active:var(--sinch-comp-radio-color-default-background-active);--sinch-local-color-border:var(--sinch-comp-radio-color-default-border-initial);--sinch-local-color-border-hover:var(--sinch-comp-radio-color-default-border-hover);--sinch-local-color-border-active:var(--sinch-comp-radio-color-default-border-active);--sinch-local-color-knob:var(--sinch-comp-radio-color-checked-knob-initial);--sinch-local-color-knob-hover:var(--sinch-comp-radio-color-checked-knob-hover);--sinch-local-color-knob-active:var(--sinch-comp-radio-color-checked-knob-active);--sinch-local-color-text:var(--sinch-comp-radio-color-default-label-initial)}:host([data-invalid])>#wrapper{--sinch-local-color-border:var(--sinch-comp-radio-color-invalid-border-initial);--sinch-local-color-border-hover:var(--sinch-comp-radio-color-invalid-border-hover);--sinch-local-color-border-active:var(--sinch-comp-radio-color-invalid-border-active);--sinch-local-color-text:var(--sinch-comp-radio-color-invalid-label-initial)}:host([checked])>#wrapper{--sinch-local-color-border:var(--sinch-comp-radio-color-checked-border-initial);--sinch-local-color-border-hover:var(--sinch-comp-radio-color-checked-border-hover);--sinch-local-color-border-active:var(--sinch-comp-radio-color-checked-border-active)}:host([disabled])>#wrapper{--sinch-local-color-background:var(--sinch-comp-radio-color-disabled-background-initial);--sinch-local-color-border:var(--sinch-comp-radio-color-disabled-border-initial);--sinch-local-color-text:var(--sinch-comp-radio-color-disabled-label-initial)}:host([disabled][checked])>#wrapper{--sinch-local-color-border:var(--sinch-comp-radio-color-checked-disabled-border-initial);--sinch-local-color-knob:var(--sinch-comp-radio-color-checked-disabled-knob-initial);--sinch-local-color-text:var(--sinch-comp-radio-color-checked-disabled-label-initial)}#input{all:initial;display:block;width:18px;height:18px;cursor:pointer}:host([disabled]) #input{cursor:initial}#input-wrapper{position:relative;width:18px;height:18px;align-self:flex-start;margin-top:3px}#input::before{content:"";position:absolute;inset:-3px;border:2px solid var(--sinch-comp-radio-color-default-outline-focus);border-radius:50%;transition:opacity .1s linear;opacity:0;box-sizing:border-box;pointer-events:none}:host(:focus-visible) #input::before{opacity:1}#input::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:50%;box-sizing:border-box;pointer-events:none}:host(:hover:not([disabled])) #input::after{background-color:var(--sinch-local-color-background-hover);border-color:var(--sinch-local-color-border-hover)}:host(:active:not([disabled])) #input::after{background-color:var(--sinch-local-color-background-active);border-color:var(--sinch-local-color-border-active)}#knob{position:absolute;width:10px;height:10px;inset:0;margin:auto;border-radius:50%;transition:opacity .1s linear;opacity:0;background-color:var(--sinch-local-color-knob);pointer-events:none}:host([checked]) #knob{opacity:1}:host(:hover:not([disabled])) #knob{background-color:var(--sinch-local-color-knob-hover)}:host(:active:not([disabled])) #knob{background-color:var(--sinch-local-color-knob-active)}@media (prefers-reduced-motion){#input::after,#input::before,#knob{transition:none}}#label{flex:1;align-self:center;padding-left:8px;font:var(--sinch-comp-radio-font-label);color:var(--sinch-local-color-text);cursor:pointer}#label:empty{display:none}:host([disabled]) #label{cursor:initial}</style><div id="wrapper"><div id="input-wrapper"><div id="input"></div><div id="knob"></div></div><span id="label"></span></div>';
|
|
3
3
|
const template = document.createElement('template');
|
|
4
4
|
template.innerHTML = templateHTML;
|
|
5
5
|
defineCustomElement('sinch-radio-option', class extends NectaryElement {
|
|
6
|
-
#$input;
|
|
7
6
|
#$label;
|
|
8
7
|
constructor() {
|
|
9
8
|
super();
|
|
10
9
|
const shadowRoot = this.attachShadow();
|
|
11
10
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
12
|
-
this.#$
|
|
13
|
-
this.#$label = shadowRoot.querySelector('label');
|
|
11
|
+
this.#$label = shadowRoot.querySelector('#label');
|
|
14
12
|
}
|
|
15
13
|
connectedCallback() {
|
|
16
|
-
this.
|
|
17
|
-
this
|
|
18
|
-
}
|
|
19
|
-
disconnectedCallback() {
|
|
20
|
-
this.#$input.removeEventListener('input', this.#onInput);
|
|
14
|
+
this.role = 'radio';
|
|
15
|
+
this.tabIndex = 0;
|
|
21
16
|
}
|
|
17
|
+
disconnectedCallback() {}
|
|
22
18
|
static get observedAttributes() {
|
|
23
|
-
return ['checked', 'disabled', 'text', '
|
|
19
|
+
return ['checked', 'disabled', 'text', 'data-invalid'];
|
|
24
20
|
}
|
|
25
21
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
26
|
-
if (oldVal
|
|
22
|
+
if (isAttrEqual(oldVal, newVal)) {
|
|
27
23
|
return;
|
|
28
24
|
}
|
|
29
25
|
switch (name) {
|
|
@@ -34,14 +30,15 @@ defineCustomElement('sinch-radio-option', class extends NectaryElement {
|
|
|
34
30
|
}
|
|
35
31
|
case 'checked':
|
|
36
32
|
{
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
const isChecked = isAttrTrue(newVal);
|
|
34
|
+
updateExplicitBooleanAttribute(this, 'aria-checked', isChecked);
|
|
35
|
+
updateBooleanAttribute(this, 'checked', isChecked);
|
|
39
36
|
break;
|
|
40
37
|
}
|
|
41
38
|
case 'disabled':
|
|
42
39
|
{
|
|
43
40
|
const isDisabled = isAttrTrue(newVal);
|
|
44
|
-
this
|
|
41
|
+
updateExplicitBooleanAttribute(this, 'aria-disabled', isDisabled);
|
|
45
42
|
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
46
43
|
break;
|
|
47
44
|
}
|
|
@@ -50,11 +47,6 @@ defineCustomElement('sinch-radio-option', class extends NectaryElement {
|
|
|
50
47
|
updateBooleanAttribute(this, 'data-invalid', isAttrTrue(newVal));
|
|
51
48
|
break;
|
|
52
49
|
}
|
|
53
|
-
case 'value':
|
|
54
|
-
{
|
|
55
|
-
this.#$input.value = newVal ?? '';
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
50
|
}
|
|
59
51
|
}
|
|
60
52
|
set checked(isChecked) {
|
|
@@ -84,18 +76,4 @@ defineCustomElement('sinch-radio-option', class extends NectaryElement {
|
|
|
84
76
|
get focusable() {
|
|
85
77
|
return true;
|
|
86
78
|
}
|
|
87
|
-
focus() {
|
|
88
|
-
this.#$input.focus();
|
|
89
|
-
}
|
|
90
|
-
blur() {
|
|
91
|
-
this.#$input.blur();
|
|
92
|
-
}
|
|
93
|
-
#onInput = e => {
|
|
94
|
-
e.stopPropagation();
|
|
95
|
-
this.#$input.checked = false;
|
|
96
|
-
this.dispatchEvent(new CustomEvent('option-change', {
|
|
97
|
-
bubbles: true,
|
|
98
|
-
detail: this.value
|
|
99
|
-
}));
|
|
100
|
-
};
|
|
101
79
|
});
|
package/rich-text/index.js
CHANGED
|
@@ -14,18 +14,6 @@ defineCustomElement('sinch-rich-text', class extends NectaryElement {
|
|
|
14
14
|
connectedCallback() {
|
|
15
15
|
this.setAttribute('role', 'paragraph');
|
|
16
16
|
}
|
|
17
|
-
get size() {
|
|
18
|
-
return getLiteralAttribute(this, sizeValues, 'size', 'm');
|
|
19
|
-
}
|
|
20
|
-
set size(value) {
|
|
21
|
-
updateLiteralAttribute(this, sizeValues, 'size', value);
|
|
22
|
-
}
|
|
23
|
-
get text() {
|
|
24
|
-
return getAttribute(this, 'text', '');
|
|
25
|
-
}
|
|
26
|
-
set text(value) {
|
|
27
|
-
updateAttribute(this, 'text', value);
|
|
28
|
-
}
|
|
29
17
|
static get observedAttributes() {
|
|
30
18
|
return ['text'];
|
|
31
19
|
}
|
|
@@ -38,6 +26,18 @@ defineCustomElement('sinch-rich-text', class extends NectaryElement {
|
|
|
38
26
|
}
|
|
39
27
|
}
|
|
40
28
|
}
|
|
29
|
+
get size() {
|
|
30
|
+
return getLiteralAttribute(this, sizeValues, 'size', 'm');
|
|
31
|
+
}
|
|
32
|
+
set size(value) {
|
|
33
|
+
updateLiteralAttribute(this, sizeValues, 'size', value);
|
|
34
|
+
}
|
|
35
|
+
get text() {
|
|
36
|
+
return getAttribute(this, 'text', '');
|
|
37
|
+
}
|
|
38
|
+
set text(value) {
|
|
39
|
+
updateAttribute(this, 'text', value);
|
|
40
|
+
}
|
|
41
41
|
#updateText(text) {
|
|
42
42
|
if (text === null) {
|
|
43
43
|
this.#wrapper.innerHTML = '';
|
package/segment/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '../title';
|
|
2
2
|
import { getTitleLevelFromType } from '../title/utils';
|
|
3
|
-
import { defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute, updateLiteralAttribute } from '../utils';
|
|
3
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getRect, isAttrEqual, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute, updateLiteralAttribute } from '../utils';
|
|
4
4
|
import { DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
5
5
|
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:column;gap:12px;width:100%;height:100%;border:1px solid var(--sinch-comp-segment-color-default-border-initial);border-radius:var(--sinch-comp-segment-shape-radius);box-sizing:border-box;background-color:var(--sinch-comp-segment-color-default-background-initial);padding:8px 0 16px}#header{display:flex;flex-direction:row;align-items:center;height:48px;gap:8px;padding:0 24px}#icon{--sinch-global-size-icon:32px}#caption{min-width:1em;--sinch-comp-title-font:var(--sinch-comp-segment-font-size-m-title)}:host([size="l"]) #caption{--sinch-comp-title-font:var(--sinch-comp-segment-font-size-l-title)}:host([size="s"]) #caption{--sinch-comp-title-font:var(--sinch-comp-segment-font-size-s-title)}#info{display:flex;flex-direction:row;align-items:center;gap:8px;margin-left:auto;align-self:stretch}#info.empty{display:none}#preview{flex:1;flex-basis:auto;height:48px;min-width:0;overflow:hidden;margin-left:24px}#preview.empty{display:none}#info.empty+#collapse{margin-left:auto}#collapse.empty{display:none}#preview:not(.empty)+#info.empty+#collapse:not(.empty),#preview:not(.empty)+#info:not(.empty){margin-left:24px}#content-wrapper{flex:1;min-height:0;overflow-y:auto;padding:4px 24px}#action{display:flex;flex-direction:row;justify-content:flex-end;gap:16px;padding:0 24px}#action.empty{display:none}:host([collapsed]) :is(#content-wrapper,#action){display:none}:host([collapsed]) #wrapper{padding-bottom:8px}::slotted([slot=icon]){margin-right:8px}</style><div id="wrapper"><div id="header"><slot id="icon" name="icon"></slot><sinch-title id="caption" level="3" type="m" ellipsis></sinch-title><div id="preview"><slot name="preview"></slot></div><div id="info"><slot name="info"></slot></div><div id="collapse"><slot name="collapse"></slot></div></div><div id="content-wrapper"><slot name="content"></slot></div><div id="action"><slot name="action"></slot></div></div>';
|
|
6
6
|
import { getTitleTypeFromSize } from './utils';
|
|
@@ -49,7 +49,7 @@ defineCustomElement('sinch-segment', class extends NectaryElement {
|
|
|
49
49
|
static get observedAttributes() {
|
|
50
50
|
return ['caption', 'collapsed', 'size'];
|
|
51
51
|
}
|
|
52
|
-
attributeChangedCallback(name,
|
|
52
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
53
53
|
switch (name) {
|
|
54
54
|
case 'caption':
|
|
55
55
|
{
|
|
@@ -58,6 +58,9 @@ defineCustomElement('sinch-segment', class extends NectaryElement {
|
|
|
58
58
|
}
|
|
59
59
|
case 'collapsed':
|
|
60
60
|
{
|
|
61
|
+
if (isAttrEqual(oldVal, newVal)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
61
64
|
updateBooleanAttribute(this, name, isAttrTrue(newVal));
|
|
62
65
|
break;
|
|
63
66
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
|
-
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;width:100%;box-sizing:border-box}</style><div id="wrapper"><slot></slot></div>';
|
|
1
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, getTargetByAttribute, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;width:100%;box-sizing:border-box;position:relative;z-index:0}</style><div id="wrapper"><slot></slot></div>';
|
|
3
3
|
const template = document.createElement('template');
|
|
4
4
|
template.innerHTML = templateHTML;
|
|
5
5
|
defineCustomElement('sinch-segmented-control', class extends NectaryElement {
|
|
6
6
|
#$slot;
|
|
7
|
+
#controller = null;
|
|
7
8
|
constructor() {
|
|
8
9
|
super();
|
|
9
10
|
const shadowRoot = this.attachShadow();
|
|
@@ -11,29 +12,27 @@ defineCustomElement('sinch-segmented-control', class extends NectaryElement {
|
|
|
11
12
|
this.#$slot = shadowRoot.querySelector('slot');
|
|
12
13
|
}
|
|
13
14
|
connectedCallback() {
|
|
14
|
-
this
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
this.#controller = new AbortController();
|
|
16
|
+
const {
|
|
17
|
+
signal
|
|
18
|
+
} = this.#controller;
|
|
19
|
+
const options = {
|
|
20
|
+
signal
|
|
21
|
+
};
|
|
22
|
+
this.role = 'tablist';
|
|
23
|
+
this.#$slot.addEventListener('slotchange', this.#onSlotChange, options);
|
|
24
|
+
this.#$slot.addEventListener('click', this.#onOptionClick, options);
|
|
25
|
+
this.#$slot.addEventListener('keydown', this.#onOptionKeydown, options);
|
|
17
26
|
this.addEventListener('-change', this.#onChangeReactHandler);
|
|
18
27
|
}
|
|
19
28
|
disconnectedCallback() {
|
|
20
|
-
this
|
|
21
|
-
this
|
|
22
|
-
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
29
|
+
this.#controller.abort();
|
|
30
|
+
this.#controller = null;
|
|
23
31
|
}
|
|
24
32
|
static get observedAttributes() {
|
|
25
33
|
return ['value'];
|
|
26
34
|
}
|
|
27
|
-
set value(value) {
|
|
28
|
-
updateAttribute(this, 'value', value);
|
|
29
|
-
}
|
|
30
|
-
get value() {
|
|
31
|
-
return getAttribute(this, 'value', '');
|
|
32
|
-
}
|
|
33
35
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
34
|
-
if (oldVal === newVal) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
36
|
switch (name) {
|
|
38
37
|
case 'value':
|
|
39
38
|
{
|
|
@@ -42,16 +41,38 @@ defineCustomElement('sinch-segmented-control', class extends NectaryElement {
|
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
}
|
|
44
|
+
set value(value) {
|
|
45
|
+
updateAttribute(this, 'value', value);
|
|
46
|
+
}
|
|
47
|
+
get value() {
|
|
48
|
+
return getAttribute(this, 'value', '');
|
|
49
|
+
}
|
|
45
50
|
#onSlotChange = () => {
|
|
46
51
|
this.#onValueChange(this.value);
|
|
47
52
|
};
|
|
48
|
-
#
|
|
49
|
-
e
|
|
50
|
-
|
|
53
|
+
#onOptionClick = e => {
|
|
54
|
+
const target = getTargetByAttribute(e, 'value');
|
|
55
|
+
if (target === null || getBooleanAttribute(target, 'disabled')) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const value = getAttribute(target, 'value', '');
|
|
51
59
|
this.dispatchEvent(new CustomEvent('-change', {
|
|
52
|
-
detail
|
|
60
|
+
detail: value
|
|
53
61
|
}));
|
|
54
62
|
};
|
|
63
|
+
#onOptionKeydown = e => {
|
|
64
|
+
switch (e.code) {
|
|
65
|
+
case 'Space':
|
|
66
|
+
case 'Enter':
|
|
67
|
+
{
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
const target = getTargetByAttribute(e, 'value');
|
|
70
|
+
if (target !== null) {
|
|
71
|
+
target.click();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
55
76
|
#onValueChange(value) {
|
|
56
77
|
for (const $option of this.#$slot.assignedElements()) {
|
|
57
78
|
const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
2
|
-
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;gap:12px;width:100%;height:32px;padding:0 16px;box-sizing:border-box;color:var(--sinch-local-color-text);background-color:var(--sinch-local-color-background);--sinch-local-color-text:var(--sinch-comp-segmented-control-color-default-text-initial);--sinch-local-shape-radius:var(--sinch-comp-segmented-control-shape-radius);--sinch-local-color-border:var(--sinch-comp-segmented-control-color-default-border-initial);--sinch-local-color-background:var(--sinch-comp-segmented-control-color-default-background-initial);--sinch-global-color-icon:var(--sinch-comp-segmented-control-color-default-icon-initial);--sinch-global-size-icon:var(--sinch-comp-segmented-control-size-icon)}
|
|
1
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrEqual, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
2
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;gap:12px;width:100%;height:32px;padding:0 16px;box-sizing:border-box;color:var(--sinch-local-color-text);background-color:var(--sinch-local-color-background);cursor:pointer;--sinch-local-color-text:var(--sinch-comp-segmented-control-color-default-text-initial);--sinch-local-shape-radius:var(--sinch-comp-segmented-control-shape-radius);--sinch-local-color-border:var(--sinch-comp-segmented-control-color-default-border-initial);--sinch-local-color-background:var(--sinch-comp-segmented-control-color-default-background-initial);--sinch-global-color-icon:var(--sinch-comp-segmented-control-color-default-icon-initial);--sinch-global-size-icon:var(--sinch-comp-segmented-control-size-icon)}:host(:hover){--sinch-local-color-background:var(--sinch-comp-segmented-control-color-default-background-hover)}:host(:first-child) #wrapper{border-top-left-radius:var(--sinch-local-shape-radius);border-bottom-left-radius:var(--sinch-local-shape-radius)}:host(:last-child) #wrapper{border-top-right-radius:var(--sinch-local-shape-radius);border-bottom-right-radius:var(--sinch-local-shape-radius)}:host([data-checked]) #wrapper{--sinch-local-color-text:var(--sinch-comp-segmented-control-color-checked-text-initial);--sinch-global-color-icon:var(--sinch-comp-segmented-control-color-checked-icon-initial);--sinch-local-color-border:var(--sinch-comp-segmented-control-color-checked-border-initial);--sinch-local-color-background:var(--sinch-comp-segmented-control-color-checked-background-initial)}:host([disabled]) #wrapper{--sinch-local-color-text:var(--sinch-comp-segmented-control-color-disabled-text-initial);--sinch-global-color-icon:var(--sinch-comp-segmented-control-color-disabled-icon-initial);--sinch-local-color-border:var(--sinch-comp-segmented-control-color-disabled-border-initial);--sinch-local-color-background:var(--sinch-comp-segmented-control-color-disabled-background-initial)}#border{position:absolute;inset:0;border:1px solid var(--sinch-local-color-border);pointer-events:none;box-sizing:border-box}:host(:first-child) #border{border-top-left-radius:var(--sinch-local-shape-radius);border-bottom-left-radius:var(--sinch-local-shape-radius)}:host(:last-child) #border{border-top-right-radius:var(--sinch-local-shape-radius);border-bottom-right-radius:var(--sinch-local-shape-radius)}:host(:not(:first-child)) #border{border-left-width:0}:host([data-checked]) #border{border-width:2px}:host([data-checked]:not(:first-child)) #border{left:-1px}#outline{display:none;position:absolute;inset:-3px;border:2px solid var(--sinch-comp-segmented-control-color-default-outline-focus);pointer-events:none;box-sizing:border-box;z-index:1}:host(:focus-visible) #outline{display:block}:host(:first-child) #outline{border-top-left-radius:calc(var(--sinch-local-shape-radius) + 3px);border-bottom-left-radius:calc(var(--sinch-local-shape-radius) + 3px)}:host(:last-child) #outline{border-top-right-radius:calc(var(--sinch-local-shape-radius) + 3px);border-bottom-right-radius:calc(var(--sinch-local-shape-radius) + 3px)}:host(:not(:first-child)) #outline{left:-4px}#content{font:var(--sinch-comp-segmented-control-font-label);flex-shrink:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;pointer-events:none}::slotted(*){display:block;pointer-events:none}</style><div id="wrapper"><slot name="icon"></slot><span id="content"></span><div id="border"></div><div id="outline"></div></div>';
|
|
3
3
|
const template = document.createElement('template');
|
|
4
4
|
template.innerHTML = templateHTML;
|
|
5
5
|
defineCustomElement('sinch-segmented-control-option', class extends NectaryElement {
|
|
6
|
-
#$button;
|
|
7
6
|
#$label;
|
|
7
|
+
#controller = null;
|
|
8
8
|
constructor() {
|
|
9
9
|
super();
|
|
10
10
|
const shadowRoot = this.attachShadow();
|
|
11
11
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
12
|
-
this.#$button = shadowRoot.querySelector('#button');
|
|
13
12
|
this.#$label = shadowRoot.querySelector('#content');
|
|
14
13
|
}
|
|
15
14
|
connectedCallback() {
|
|
16
|
-
this
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
this.#controller = new AbortController();
|
|
16
|
+
const {
|
|
17
|
+
signal
|
|
18
|
+
} = this.#controller;
|
|
19
|
+
const options = {
|
|
20
|
+
signal
|
|
21
|
+
};
|
|
22
|
+
this.role = 'tab';
|
|
23
|
+
this.addEventListener('focus', this.#onButtonFocus, options);
|
|
24
|
+
this.addEventListener('blur', this.#onButtonBlur, options);
|
|
20
25
|
this.addEventListener('-focus', this.#onFocusReactHandler);
|
|
21
26
|
this.addEventListener('-blur', this.#onBlurReactHandler);
|
|
27
|
+
this.#updateTabIndex();
|
|
22
28
|
}
|
|
23
29
|
disconnectedCallback() {
|
|
24
|
-
this
|
|
25
|
-
this
|
|
26
|
-
this.#$button.removeEventListener('blur', this.#onButtonBlur);
|
|
27
|
-
this.removeEventListener('-focus', this.#onFocusReactHandler);
|
|
28
|
-
this.removeEventListener('-blur', this.#onBlurReactHandler);
|
|
30
|
+
this.#controller.abort();
|
|
31
|
+
this.#controller = null;
|
|
29
32
|
}
|
|
30
33
|
static get observedAttributes() {
|
|
31
34
|
return ['data-checked', 'disabled', 'text'];
|
|
32
35
|
}
|
|
33
36
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
34
|
-
if (oldVal === newVal) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
37
|
switch (name) {
|
|
38
38
|
case 'text':
|
|
39
39
|
{
|
|
@@ -47,8 +47,11 @@ defineCustomElement('sinch-segmented-control-option', class extends NectaryEleme
|
|
|
47
47
|
}
|
|
48
48
|
case 'disabled':
|
|
49
49
|
{
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
if (isAttrEqual(oldVal, newVal)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.#updateTabIndex();
|
|
54
|
+
updateBooleanAttribute(this, name, isAttrTrue(newVal));
|
|
52
55
|
break;
|
|
53
56
|
}
|
|
54
57
|
}
|
|
@@ -74,19 +77,9 @@ defineCustomElement('sinch-segmented-control-option', class extends NectaryEleme
|
|
|
74
77
|
get focusable() {
|
|
75
78
|
return true;
|
|
76
79
|
}
|
|
77
|
-
|
|
78
|
-
this
|
|
79
|
-
}
|
|
80
|
-
blur() {
|
|
81
|
-
this.#$button.blur();
|
|
80
|
+
#updateTabIndex() {
|
|
81
|
+
this.tabIndex = this.disabled ? -1 : 0;
|
|
82
82
|
}
|
|
83
|
-
#onButtonClick = e => {
|
|
84
|
-
e.stopPropagation();
|
|
85
|
-
this.dispatchEvent(new CustomEvent('option-change', {
|
|
86
|
-
detail: this.value,
|
|
87
|
-
bubbles: true
|
|
88
|
-
}));
|
|
89
|
-
};
|
|
90
83
|
#onButtonFocus = () => {
|
|
91
84
|
this.dispatchEvent(new CustomEvent('-focus'));
|
|
92
85
|
};
|