@nectary/components 5.58.0 → 5.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle.js +82 -39
- package/package.json +1 -1
- package/rich-textarea/utils.js +22 -1
- package/toggle/index.d.ts +1 -0
- package/toggle/index.js +23 -9
- package/toggle/types.d.ts +3 -1
- package/utils/dom.js +38 -30
package/bundle.js
CHANGED
|
@@ -175,28 +175,42 @@ const composedContains = (container, node) => {
|
|
|
175
175
|
const isAttrEqual = (oldVal, newVal) => {
|
|
176
176
|
return oldVal === newVal || newVal === null && oldVal === "false" || newVal === "" && oldVal === "true";
|
|
177
177
|
};
|
|
178
|
+
const isScrollableOverflow = (value) => {
|
|
179
|
+
return value === "auto" || value === "scroll";
|
|
180
|
+
};
|
|
181
|
+
const isScrollableElement = (element) => {
|
|
182
|
+
if (element.scrollHeight <= element.clientHeight && element.scrollWidth <= element.clientWidth) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
const style = getComputedStyle(element);
|
|
186
|
+
return isScrollableOverflow(style.overflow) || isScrollableOverflow(style.overflowY) || isScrollableOverflow(style.overflowX);
|
|
187
|
+
};
|
|
188
|
+
const nextFlatTreeAncestor = (element) => {
|
|
189
|
+
const slot = element.assignedSlot;
|
|
190
|
+
if (slot != null) {
|
|
191
|
+
return slot;
|
|
192
|
+
}
|
|
193
|
+
const parent = element.parentElement;
|
|
194
|
+
if (parent != null) {
|
|
195
|
+
return parent;
|
|
196
|
+
}
|
|
197
|
+
const root = element.getRootNode();
|
|
198
|
+
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
199
|
+
return root.host;
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
};
|
|
178
203
|
const getScrollableParents = (node) => {
|
|
179
204
|
const scrollableParents = [];
|
|
180
205
|
if (node == null) {
|
|
181
206
|
return scrollableParents;
|
|
182
207
|
}
|
|
183
|
-
let current = node
|
|
208
|
+
let current = node;
|
|
184
209
|
while (current != null) {
|
|
185
|
-
|
|
186
|
-
if ((current.scrollHeight > current.clientHeight || current.scrollWidth > current.clientWidth) && (computedStyle.overflow === "auto" || computedStyle.overflow === "scroll" || computedStyle.overflowY === "auto" || computedStyle.overflowY === "scroll" || computedStyle.overflowX === "auto" || computedStyle.overflowX === "scroll")) {
|
|
210
|
+
if (current !== node && isScrollableElement(current)) {
|
|
187
211
|
scrollableParents.push(current);
|
|
188
212
|
}
|
|
189
|
-
|
|
190
|
-
if (parent != null) {
|
|
191
|
-
current = parent;
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
const root = current.getRootNode();
|
|
195
|
-
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
196
|
-
current = root.host;
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
break;
|
|
213
|
+
current = nextFlatTreeAncestor(current);
|
|
200
214
|
}
|
|
201
215
|
scrollableParents.push(document);
|
|
202
216
|
return scrollableParents;
|
|
@@ -209,33 +223,27 @@ const createScopedElement = (anchor, tag) => {
|
|
|
209
223
|
}
|
|
210
224
|
return document.createElement(tag);
|
|
211
225
|
};
|
|
226
|
+
const establishesFixedContainingBlock = (contain) => {
|
|
227
|
+
return contain.split(/\s+/).some((value) => {
|
|
228
|
+
return value === "layout" || value === "paint" || value === "content" || value === "strict";
|
|
229
|
+
});
|
|
230
|
+
};
|
|
212
231
|
const isTransformedElement = (element) => {
|
|
213
232
|
if (element == null) {
|
|
214
233
|
return false;
|
|
215
234
|
}
|
|
216
235
|
const style = getComputedStyle(element);
|
|
217
236
|
const backdropFilter = style.getPropertyValue("backdrop-filter");
|
|
218
|
-
|
|
237
|
+
const contentVisibility = style.getPropertyValue("content-visibility");
|
|
238
|
+
return style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || backdropFilter !== "" && backdropFilter !== "none" || establishesFixedContainingBlock(style.getPropertyValue("contain")) || contentVisibility === "auto" || contentVisibility === "hidden";
|
|
219
239
|
};
|
|
220
240
|
const getTransformedAncestor = (node) => {
|
|
221
241
|
let current = node;
|
|
222
242
|
while (current != null) {
|
|
223
|
-
if (current !== node) {
|
|
224
|
-
|
|
225
|
-
return current;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
const parent = current.parentElement;
|
|
229
|
-
if (parent != null) {
|
|
230
|
-
current = parent;
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
const root = current.getRootNode();
|
|
234
|
-
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
235
|
-
current = root.host;
|
|
236
|
-
continue;
|
|
243
|
+
if (current !== node && isTransformedElement(current)) {
|
|
244
|
+
return current;
|
|
237
245
|
}
|
|
238
|
-
|
|
246
|
+
current = nextFlatTreeAncestor(current);
|
|
239
247
|
}
|
|
240
248
|
return null;
|
|
241
249
|
};
|
|
@@ -14821,6 +14829,17 @@ const createParseVisitor = (doc) => {
|
|
|
14821
14829
|
let $currentBlock = null;
|
|
14822
14830
|
const listsStack = [];
|
|
14823
14831
|
let isFirstListItem = false;
|
|
14832
|
+
const dropTrailingEmptyParagraphs = () => {
|
|
14833
|
+
let $last = $root.lastChild;
|
|
14834
|
+
while (isParagraph($last) && $last.childNodes.length === 0) {
|
|
14835
|
+
const $removed = $last;
|
|
14836
|
+
$removed.remove();
|
|
14837
|
+
$last = $root.lastChild;
|
|
14838
|
+
if ($currentBlock === $removed) {
|
|
14839
|
+
$currentBlock = null;
|
|
14840
|
+
}
|
|
14841
|
+
}
|
|
14842
|
+
};
|
|
14824
14843
|
return {
|
|
14825
14844
|
escaped(char) {
|
|
14826
14845
|
const $inline = createInlineWithText(char, doc);
|
|
@@ -14874,6 +14893,9 @@ const createParseVisitor = (doc) => {
|
|
|
14874
14893
|
$currentBlock.appendChild($link);
|
|
14875
14894
|
},
|
|
14876
14895
|
list(isOrdered) {
|
|
14896
|
+
if (listsStack.length === 0) {
|
|
14897
|
+
dropTrailingEmptyParagraphs();
|
|
14898
|
+
}
|
|
14877
14899
|
listsStack.push({
|
|
14878
14900
|
isOrdered,
|
|
14879
14901
|
$parentBlock: $currentBlock
|
|
@@ -14901,8 +14923,15 @@ const createParseVisitor = (doc) => {
|
|
|
14901
14923
|
if (listsStack.length > 0 && $currentBlock !== null) {
|
|
14902
14924
|
return;
|
|
14903
14925
|
}
|
|
14926
|
+
dropTrailingEmptyParagraphs();
|
|
14927
|
+
const followsParagraph = isParagraph($root.lastChild);
|
|
14928
|
+
if (followsParagraph) {
|
|
14929
|
+
$root.appendChild(createActuallyEmptyParagraph(doc));
|
|
14930
|
+
}
|
|
14904
14931
|
const $p = createActuallyEmptyParagraph(doc);
|
|
14905
|
-
|
|
14932
|
+
if (!followsParagraph) {
|
|
14933
|
+
markParagraphAsBlock($p);
|
|
14934
|
+
}
|
|
14906
14935
|
$currentBlock = $p;
|
|
14907
14936
|
$root.appendChild($p);
|
|
14908
14937
|
},
|
|
@@ -18896,16 +18925,19 @@ class ToastManager extends NectaryElement {
|
|
|
18896
18925
|
};
|
|
18897
18926
|
}
|
|
18898
18927
|
defineCustomElement("sinch-toast-manager", ToastManager);
|
|
18899
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;gap:8px;width:100%;height:var(--sinch-local-size);cursor:pointer;user-select:none;--sinch-local-size:20px}:host([small]) #wrapper{--sinch-local-size:16px}:host([disabled]) #wrapper{cursor:initial}#knob-container{position:relative;width:40px;height:var(--sinch-local-size);border-radius:calc(var(--sinch-local-size) * .5);background-color:var(--sinch-comp-toggle-color-default-background-initial);pointer-events:none;transition:background-color .15s ease-in-out}:host([small]) #knob-container{width:32px;height:var(--sinch-local-size)}:host([checked]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-background-initial)}:host([disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-disabled-background-initial)}:host([checked][disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-disabled-background-initial)}#knob{position:relative;width:16px;height:16px;left:2px;top:2px;border-radius:50%;background-color:var(--sinch-comp-toggle-color-default-knob-background-initial);box-shadow:var(--sinch-comp-toggle-shadow-knob-default);transform:translateX(0);transition:transform .15s ease-in-out;will-change:transform}:host([small]) #knob{width:12px;height:12px}:host([disabled]) #knob-container>#knob{box-shadow:var(--sinch-comp-toggle-shadow-knob-disabled)}:host([checked]) #knob-container>#knob{transform:translateX(20px)}:host([small][checked]) #knob-container>#knob{transform:translateX(16px)}#knob::after,#knob::before{font:var(--sinch-comp-toggle-font-size-m-inside-text);color:var(--sinch-comp-toggle-color-default-text-inside-initial);text-transform:uppercase;position:absolute;top:0;padding:0 1px;opacity:0;transition:opacity .15s ease-in-out;user-select:none}#knob::before{content:"on";right:100%}#knob::after{content:"off";left:100%}:host([labeled]:not([small]):not([checked])) #knob::after{opacity:1}:host([labeled]:not([small])[checked]) #knob::before{opacity:1}@media (prefers-reduced-motion){#knob,#knob-container,#knob::after,#knob::before{transition:none}}#outline{display:none;position:absolute;left:-3px;top:-3px;right:-3px;bottom:-3px;border:2px solid var(--sinch-comp-toggle-color-default-outline-focus);border-radius:17px;pointer-events:none}:host(:focus-visible) #outline{display:block}#label{flex:1;min-width:0;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:var(--sinch-comp-toggle-font-size-m-label);color:var(--sinch-comp-toggle-color-default-label-initial)}#label:empty{display:none}:host([small]) #label{font:var(--sinch-comp-toggle-font-size-s-label)}:host([disabled]) #label{color:var(--sinch-comp-toggle-color-disabled-label-initial)}</style><div id="wrapper"><div id="knob-container"><div id="outline"></div><div id="knob"></div></div><span id="label"></span></div>';
|
|
18928
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;gap:8px;width:100%;height:var(--sinch-local-size);cursor:pointer;user-select:none;--sinch-local-size:20px}:host([small]) #wrapper{--sinch-local-size:16px}:host([disabled]) #wrapper{cursor:initial}#knob-container{position:relative;width:40px;height:var(--sinch-local-size);border-radius:calc(var(--sinch-local-size) * .5);background-color:var(--sinch-comp-toggle-color-default-background-initial);pointer-events:none;transition:background-color .15s ease-in-out}:host([small]) #knob-container{width:32px;height:var(--sinch-local-size)}:host([checked]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-background-initial)}:host([disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-disabled-background-initial)}:host([checked][disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-disabled-background-initial)}#knob{position:relative;width:16px;height:16px;left:2px;top:2px;border-radius:50%;background-color:var(--sinch-comp-toggle-color-default-knob-background-initial);box-shadow:var(--sinch-comp-toggle-shadow-knob-default);transform:translateX(0);transition:transform .15s ease-in-out;will-change:transform}:host([small]) #knob{width:12px;height:12px}:host([disabled]) #knob-container>#knob{box-shadow:var(--sinch-comp-toggle-shadow-knob-disabled)}:host([checked]) #knob-container>#knob{transform:translateX(20px)}:host([small][checked]) #knob-container>#knob{transform:translateX(16px)}#knob::after,#knob::before{font:var(--sinch-comp-toggle-font-size-m-inside-text);color:var(--sinch-comp-toggle-color-default-text-inside-initial);text-transform:uppercase;position:absolute;top:0;padding:0 1px;opacity:0;transition:opacity .15s ease-in-out;user-select:none}#knob::before{content:"on";content:"on"/"";right:100%}#knob::after{content:"off";content:"off"/"";left:100%}:host([labeled]:not([small]):not([checked])) #knob::after{opacity:1}:host([labeled]:not([small])[checked]) #knob::before{opacity:1}@media (prefers-reduced-motion){#knob,#knob-container,#knob::after,#knob::before{transition:none}}#outline{display:none;position:absolute;left:-3px;top:-3px;right:-3px;bottom:-3px;border:2px solid var(--sinch-comp-toggle-color-default-outline-focus);border-radius:17px;pointer-events:none}:host(:focus-visible) #outline{display:block}#label{flex:1;min-width:0;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:var(--sinch-comp-toggle-font-size-m-label);color:var(--sinch-comp-toggle-color-default-label-initial)}#label:empty{display:none}:host([small]) #label{font:var(--sinch-comp-toggle-font-size-s-label)}:host([disabled]) #label{color:var(--sinch-comp-toggle-color-disabled-label-initial)}</style><div id="wrapper"><div id="knob-container"><div id="outline"></div><div id="knob"></div></div><span id="label"></span></div>';
|
|
18900
18929
|
const template = document.createElement("template");
|
|
18901
18930
|
template.innerHTML = templateHTML;
|
|
18902
18931
|
class Toggle extends NectaryElement {
|
|
18903
18932
|
#$label;
|
|
18904
18933
|
#controller = null;
|
|
18934
|
+
#internals;
|
|
18935
|
+
static formAssociated = true;
|
|
18905
18936
|
constructor() {
|
|
18906
18937
|
super();
|
|
18907
18938
|
const shadowRoot = this.attachShadow();
|
|
18908
18939
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
18940
|
+
this.#internals = this.attachInternals();
|
|
18909
18941
|
this.#$label = shadowRoot.querySelector("#label");
|
|
18910
18942
|
}
|
|
18911
18943
|
connectedCallback() {
|
|
@@ -18913,6 +18945,9 @@ class Toggle extends NectaryElement {
|
|
|
18913
18945
|
const { signal } = this.#controller;
|
|
18914
18946
|
const options = { signal };
|
|
18915
18947
|
this.setAttribute("role", "checkbox");
|
|
18948
|
+
this.#internals.role = "checkbox";
|
|
18949
|
+
this.#syncChecked();
|
|
18950
|
+
this.#syncDisabled();
|
|
18916
18951
|
this.addEventListener("click", this.#onClick, options);
|
|
18917
18952
|
this.addEventListener("keydown", this.#onKeydown, options);
|
|
18918
18953
|
this.addEventListener("focus", this.#onFocus, options);
|
|
@@ -18945,16 +18980,11 @@ class Toggle extends NectaryElement {
|
|
|
18945
18980
|
break;
|
|
18946
18981
|
}
|
|
18947
18982
|
case "checked": {
|
|
18948
|
-
|
|
18949
|
-
updateExplicitBooleanAttribute(this, "aria-checked", isChecked);
|
|
18950
|
-
updateBooleanAttribute(this, name, isChecked);
|
|
18983
|
+
this.#syncChecked();
|
|
18951
18984
|
break;
|
|
18952
18985
|
}
|
|
18953
18986
|
case "disabled": {
|
|
18954
|
-
|
|
18955
|
-
this.#updateTabIndex();
|
|
18956
|
-
updateExplicitBooleanAttribute(this, "aria-disabled", isDisabled);
|
|
18957
|
-
updateBooleanAttribute(this, name, isDisabled);
|
|
18987
|
+
this.#syncDisabled();
|
|
18958
18988
|
break;
|
|
18959
18989
|
}
|
|
18960
18990
|
case "small":
|
|
@@ -19014,6 +19044,19 @@ class Toggle extends NectaryElement {
|
|
|
19014
19044
|
}
|
|
19015
19045
|
}
|
|
19016
19046
|
};
|
|
19047
|
+
#syncChecked() {
|
|
19048
|
+
const isChecked = this.checked;
|
|
19049
|
+
updateExplicitBooleanAttribute(this, "aria-checked", isChecked);
|
|
19050
|
+
this.#internals.ariaChecked = isChecked.toString();
|
|
19051
|
+
updateBooleanAttribute(this, "checked", isChecked);
|
|
19052
|
+
}
|
|
19053
|
+
#syncDisabled() {
|
|
19054
|
+
const isDisabled = this.disabled;
|
|
19055
|
+
this.#updateTabIndex();
|
|
19056
|
+
updateExplicitBooleanAttribute(this, "aria-disabled", isDisabled);
|
|
19057
|
+
this.#internals.ariaDisabled = isDisabled.toString();
|
|
19058
|
+
updateBooleanAttribute(this, "disabled", isDisabled);
|
|
19059
|
+
}
|
|
19017
19060
|
#updateTabIndex() {
|
|
19018
19061
|
this.tabIndex = this.disabled ? -1 : 0;
|
|
19019
19062
|
}
|
package/package.json
CHANGED
package/rich-textarea/utils.js
CHANGED
|
@@ -1794,6 +1794,17 @@ const createParseVisitor = (doc) => {
|
|
|
1794
1794
|
let $currentBlock = null;
|
|
1795
1795
|
const listsStack = [];
|
|
1796
1796
|
let isFirstListItem = false;
|
|
1797
|
+
const dropTrailingEmptyParagraphs = () => {
|
|
1798
|
+
let $last = $root.lastChild;
|
|
1799
|
+
while (isParagraph($last) && $last.childNodes.length === 0) {
|
|
1800
|
+
const $removed = $last;
|
|
1801
|
+
$removed.remove();
|
|
1802
|
+
$last = $root.lastChild;
|
|
1803
|
+
if ($currentBlock === $removed) {
|
|
1804
|
+
$currentBlock = null;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
};
|
|
1797
1808
|
return {
|
|
1798
1809
|
escaped(char) {
|
|
1799
1810
|
const $inline = createInlineWithText(char, doc);
|
|
@@ -1847,6 +1858,9 @@ const createParseVisitor = (doc) => {
|
|
|
1847
1858
|
$currentBlock.appendChild($link);
|
|
1848
1859
|
},
|
|
1849
1860
|
list(isOrdered) {
|
|
1861
|
+
if (listsStack.length === 0) {
|
|
1862
|
+
dropTrailingEmptyParagraphs();
|
|
1863
|
+
}
|
|
1850
1864
|
listsStack.push({
|
|
1851
1865
|
isOrdered,
|
|
1852
1866
|
$parentBlock: $currentBlock
|
|
@@ -1874,8 +1888,15 @@ const createParseVisitor = (doc) => {
|
|
|
1874
1888
|
if (listsStack.length > 0 && $currentBlock !== null) {
|
|
1875
1889
|
return;
|
|
1876
1890
|
}
|
|
1891
|
+
dropTrailingEmptyParagraphs();
|
|
1892
|
+
const followsParagraph = isParagraph($root.lastChild);
|
|
1893
|
+
if (followsParagraph) {
|
|
1894
|
+
$root.appendChild(createActuallyEmptyParagraph(doc));
|
|
1895
|
+
}
|
|
1877
1896
|
const $p = createActuallyEmptyParagraph(doc);
|
|
1878
|
-
|
|
1897
|
+
if (!followsParagraph) {
|
|
1898
|
+
markParagraphAsBlock($p);
|
|
1899
|
+
}
|
|
1879
1900
|
$currentBlock = $p;
|
|
1880
1901
|
$root.appendChild($p);
|
|
1881
1902
|
},
|
package/toggle/index.d.ts
CHANGED
package/toggle/index.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { isAttrEqual, updateBooleanAttribute, isAttrTrue,
|
|
1
|
+
import { isAttrEqual, updateBooleanAttribute, isAttrTrue, getBooleanAttribute, updateAttribute, getAttribute, updateExplicitBooleanAttribute } from "../utils/dom.js";
|
|
2
2
|
import { defineCustomElement, NectaryElement } from "../utils/element.js";
|
|
3
3
|
import { getReactEventHandler } from "../utils/get-react-event-handler.js";
|
|
4
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;gap:8px;width:100%;height:var(--sinch-local-size);cursor:pointer;user-select:none;--sinch-local-size:20px}:host([small]) #wrapper{--sinch-local-size:16px}:host([disabled]) #wrapper{cursor:initial}#knob-container{position:relative;width:40px;height:var(--sinch-local-size);border-radius:calc(var(--sinch-local-size) * .5);background-color:var(--sinch-comp-toggle-color-default-background-initial);pointer-events:none;transition:background-color .15s ease-in-out}:host([small]) #knob-container{width:32px;height:var(--sinch-local-size)}:host([checked]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-background-initial)}:host([disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-disabled-background-initial)}:host([checked][disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-disabled-background-initial)}#knob{position:relative;width:16px;height:16px;left:2px;top:2px;border-radius:50%;background-color:var(--sinch-comp-toggle-color-default-knob-background-initial);box-shadow:var(--sinch-comp-toggle-shadow-knob-default);transform:translateX(0);transition:transform .15s ease-in-out;will-change:transform}:host([small]) #knob{width:12px;height:12px}:host([disabled]) #knob-container>#knob{box-shadow:var(--sinch-comp-toggle-shadow-knob-disabled)}:host([checked]) #knob-container>#knob{transform:translateX(20px)}:host([small][checked]) #knob-container>#knob{transform:translateX(16px)}#knob::after,#knob::before{font:var(--sinch-comp-toggle-font-size-m-inside-text);color:var(--sinch-comp-toggle-color-default-text-inside-initial);text-transform:uppercase;position:absolute;top:0;padding:0 1px;opacity:0;transition:opacity .15s ease-in-out;user-select:none}#knob::before{content:"on";right:100%}#knob::after{content:"off";left:100%}:host([labeled]:not([small]):not([checked])) #knob::after{opacity:1}:host([labeled]:not([small])[checked]) #knob::before{opacity:1}@media (prefers-reduced-motion){#knob,#knob-container,#knob::after,#knob::before{transition:none}}#outline{display:none;position:absolute;left:-3px;top:-3px;right:-3px;bottom:-3px;border:2px solid var(--sinch-comp-toggle-color-default-outline-focus);border-radius:17px;pointer-events:none}:host(:focus-visible) #outline{display:block}#label{flex:1;min-width:0;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:var(--sinch-comp-toggle-font-size-m-label);color:var(--sinch-comp-toggle-color-default-label-initial)}#label:empty{display:none}:host([small]) #label{font:var(--sinch-comp-toggle-font-size-s-label)}:host([disabled]) #label{color:var(--sinch-comp-toggle-color-disabled-label-initial)}</style><div id="wrapper"><div id="knob-container"><div id="outline"></div><div id="knob"></div></div><span id="label"></span></div>';
|
|
4
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;gap:8px;width:100%;height:var(--sinch-local-size);cursor:pointer;user-select:none;--sinch-local-size:20px}:host([small]) #wrapper{--sinch-local-size:16px}:host([disabled]) #wrapper{cursor:initial}#knob-container{position:relative;width:40px;height:var(--sinch-local-size);border-radius:calc(var(--sinch-local-size) * .5);background-color:var(--sinch-comp-toggle-color-default-background-initial);pointer-events:none;transition:background-color .15s ease-in-out}:host([small]) #knob-container{width:32px;height:var(--sinch-local-size)}:host([checked]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-background-initial)}:host([disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-disabled-background-initial)}:host([checked][disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-disabled-background-initial)}#knob{position:relative;width:16px;height:16px;left:2px;top:2px;border-radius:50%;background-color:var(--sinch-comp-toggle-color-default-knob-background-initial);box-shadow:var(--sinch-comp-toggle-shadow-knob-default);transform:translateX(0);transition:transform .15s ease-in-out;will-change:transform}:host([small]) #knob{width:12px;height:12px}:host([disabled]) #knob-container>#knob{box-shadow:var(--sinch-comp-toggle-shadow-knob-disabled)}:host([checked]) #knob-container>#knob{transform:translateX(20px)}:host([small][checked]) #knob-container>#knob{transform:translateX(16px)}#knob::after,#knob::before{font:var(--sinch-comp-toggle-font-size-m-inside-text);color:var(--sinch-comp-toggle-color-default-text-inside-initial);text-transform:uppercase;position:absolute;top:0;padding:0 1px;opacity:0;transition:opacity .15s ease-in-out;user-select:none}#knob::before{content:"on";content:"on"/"";right:100%}#knob::after{content:"off";content:"off"/"";left:100%}:host([labeled]:not([small]):not([checked])) #knob::after{opacity:1}:host([labeled]:not([small])[checked]) #knob::before{opacity:1}@media (prefers-reduced-motion){#knob,#knob-container,#knob::after,#knob::before{transition:none}}#outline{display:none;position:absolute;left:-3px;top:-3px;right:-3px;bottom:-3px;border:2px solid var(--sinch-comp-toggle-color-default-outline-focus);border-radius:17px;pointer-events:none}:host(:focus-visible) #outline{display:block}#label{flex:1;min-width:0;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:var(--sinch-comp-toggle-font-size-m-label);color:var(--sinch-comp-toggle-color-default-label-initial)}#label:empty{display:none}:host([small]) #label{font:var(--sinch-comp-toggle-font-size-s-label)}:host([disabled]) #label{color:var(--sinch-comp-toggle-color-disabled-label-initial)}</style><div id="wrapper"><div id="knob-container"><div id="outline"></div><div id="knob"></div></div><span id="label"></span></div>';
|
|
5
5
|
const template = document.createElement("template");
|
|
6
6
|
template.innerHTML = templateHTML;
|
|
7
7
|
class Toggle extends NectaryElement {
|
|
8
8
|
#$label;
|
|
9
9
|
#controller = null;
|
|
10
|
+
#internals;
|
|
11
|
+
static formAssociated = true;
|
|
10
12
|
constructor() {
|
|
11
13
|
super();
|
|
12
14
|
const shadowRoot = this.attachShadow();
|
|
13
15
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
16
|
+
this.#internals = this.attachInternals();
|
|
14
17
|
this.#$label = shadowRoot.querySelector("#label");
|
|
15
18
|
}
|
|
16
19
|
connectedCallback() {
|
|
@@ -18,6 +21,9 @@ class Toggle extends NectaryElement {
|
|
|
18
21
|
const { signal } = this.#controller;
|
|
19
22
|
const options = { signal };
|
|
20
23
|
this.setAttribute("role", "checkbox");
|
|
24
|
+
this.#internals.role = "checkbox";
|
|
25
|
+
this.#syncChecked();
|
|
26
|
+
this.#syncDisabled();
|
|
21
27
|
this.addEventListener("click", this.#onClick, options);
|
|
22
28
|
this.addEventListener("keydown", this.#onKeydown, options);
|
|
23
29
|
this.addEventListener("focus", this.#onFocus, options);
|
|
@@ -50,16 +56,11 @@ class Toggle extends NectaryElement {
|
|
|
50
56
|
break;
|
|
51
57
|
}
|
|
52
58
|
case "checked": {
|
|
53
|
-
|
|
54
|
-
updateExplicitBooleanAttribute(this, "aria-checked", isChecked);
|
|
55
|
-
updateBooleanAttribute(this, name, isChecked);
|
|
59
|
+
this.#syncChecked();
|
|
56
60
|
break;
|
|
57
61
|
}
|
|
58
62
|
case "disabled": {
|
|
59
|
-
|
|
60
|
-
this.#updateTabIndex();
|
|
61
|
-
updateExplicitBooleanAttribute(this, "aria-disabled", isDisabled);
|
|
62
|
-
updateBooleanAttribute(this, name, isDisabled);
|
|
63
|
+
this.#syncDisabled();
|
|
63
64
|
break;
|
|
64
65
|
}
|
|
65
66
|
case "small":
|
|
@@ -119,6 +120,19 @@ class Toggle extends NectaryElement {
|
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
};
|
|
123
|
+
#syncChecked() {
|
|
124
|
+
const isChecked = this.checked;
|
|
125
|
+
updateExplicitBooleanAttribute(this, "aria-checked", isChecked);
|
|
126
|
+
this.#internals.ariaChecked = isChecked.toString();
|
|
127
|
+
updateBooleanAttribute(this, "checked", isChecked);
|
|
128
|
+
}
|
|
129
|
+
#syncDisabled() {
|
|
130
|
+
const isDisabled = this.disabled;
|
|
131
|
+
this.#updateTabIndex();
|
|
132
|
+
updateExplicitBooleanAttribute(this, "aria-disabled", isDisabled);
|
|
133
|
+
this.#internals.ariaDisabled = isDisabled.toString();
|
|
134
|
+
updateBooleanAttribute(this, "disabled", isDisabled);
|
|
135
|
+
}
|
|
122
136
|
#updateTabIndex() {
|
|
123
137
|
this.tabIndex = this.disabled ? -1 : 0;
|
|
124
138
|
}
|
package/toggle/types.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ export type TSinchToggleProps = {
|
|
|
5
5
|
labeled?: boolean;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
text?: string;
|
|
8
|
-
|
|
8
|
+
/** Id a label's for attribute can point at */
|
|
9
|
+
id?: string;
|
|
10
|
+
'aria-label'?: string;
|
|
9
11
|
};
|
|
10
12
|
export type TSinchToggleEvents = {
|
|
11
13
|
'-change'?: (e: CustomEvent<boolean>) => void;
|
package/utils/dom.js
CHANGED
|
@@ -185,28 +185,42 @@ const composedContains = (container, node) => {
|
|
|
185
185
|
const isAttrEqual = (oldVal, newVal) => {
|
|
186
186
|
return oldVal === newVal || newVal === null && oldVal === "false" || newVal === "" && oldVal === "true";
|
|
187
187
|
};
|
|
188
|
+
const isScrollableOverflow = (value) => {
|
|
189
|
+
return value === "auto" || value === "scroll";
|
|
190
|
+
};
|
|
191
|
+
const isScrollableElement = (element) => {
|
|
192
|
+
if (element.scrollHeight <= element.clientHeight && element.scrollWidth <= element.clientWidth) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
const style = getComputedStyle(element);
|
|
196
|
+
return isScrollableOverflow(style.overflow) || isScrollableOverflow(style.overflowY) || isScrollableOverflow(style.overflowX);
|
|
197
|
+
};
|
|
198
|
+
const nextFlatTreeAncestor = (element) => {
|
|
199
|
+
const slot = element.assignedSlot;
|
|
200
|
+
if (slot != null) {
|
|
201
|
+
return slot;
|
|
202
|
+
}
|
|
203
|
+
const parent = element.parentElement;
|
|
204
|
+
if (parent != null) {
|
|
205
|
+
return parent;
|
|
206
|
+
}
|
|
207
|
+
const root = element.getRootNode();
|
|
208
|
+
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
209
|
+
return root.host;
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
};
|
|
188
213
|
const getScrollableParents = (node) => {
|
|
189
214
|
const scrollableParents = [];
|
|
190
215
|
if (node == null) {
|
|
191
216
|
return scrollableParents;
|
|
192
217
|
}
|
|
193
|
-
let current = node
|
|
218
|
+
let current = node;
|
|
194
219
|
while (current != null) {
|
|
195
|
-
|
|
196
|
-
if ((current.scrollHeight > current.clientHeight || current.scrollWidth > current.clientWidth) && (computedStyle.overflow === "auto" || computedStyle.overflow === "scroll" || computedStyle.overflowY === "auto" || computedStyle.overflowY === "scroll" || computedStyle.overflowX === "auto" || computedStyle.overflowX === "scroll")) {
|
|
220
|
+
if (current !== node && isScrollableElement(current)) {
|
|
197
221
|
scrollableParents.push(current);
|
|
198
222
|
}
|
|
199
|
-
|
|
200
|
-
if (parent != null) {
|
|
201
|
-
current = parent;
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
const root = current.getRootNode();
|
|
205
|
-
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
206
|
-
current = root.host;
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
break;
|
|
223
|
+
current = nextFlatTreeAncestor(current);
|
|
210
224
|
}
|
|
211
225
|
scrollableParents.push(document);
|
|
212
226
|
return scrollableParents;
|
|
@@ -219,33 +233,27 @@ const createScopedElement = (anchor, tag) => {
|
|
|
219
233
|
}
|
|
220
234
|
return document.createElement(tag);
|
|
221
235
|
};
|
|
236
|
+
const establishesFixedContainingBlock = (contain) => {
|
|
237
|
+
return contain.split(/\s+/).some((value) => {
|
|
238
|
+
return value === "layout" || value === "paint" || value === "content" || value === "strict";
|
|
239
|
+
});
|
|
240
|
+
};
|
|
222
241
|
const isTransformedElement = (element) => {
|
|
223
242
|
if (element == null) {
|
|
224
243
|
return false;
|
|
225
244
|
}
|
|
226
245
|
const style = getComputedStyle(element);
|
|
227
246
|
const backdropFilter = style.getPropertyValue("backdrop-filter");
|
|
228
|
-
|
|
247
|
+
const contentVisibility = style.getPropertyValue("content-visibility");
|
|
248
|
+
return style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || backdropFilter !== "" && backdropFilter !== "none" || establishesFixedContainingBlock(style.getPropertyValue("contain")) || contentVisibility === "auto" || contentVisibility === "hidden";
|
|
229
249
|
};
|
|
230
250
|
const getTransformedAncestor = (node) => {
|
|
231
251
|
let current = node;
|
|
232
252
|
while (current != null) {
|
|
233
|
-
if (current !== node) {
|
|
234
|
-
|
|
235
|
-
return current;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
const parent = current.parentElement;
|
|
239
|
-
if (parent != null) {
|
|
240
|
-
current = parent;
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
const root = current.getRootNode();
|
|
244
|
-
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
245
|
-
current = root.host;
|
|
246
|
-
continue;
|
|
253
|
+
if (current !== node && isTransformedElement(current)) {
|
|
254
|
+
return current;
|
|
247
255
|
}
|
|
248
|
-
|
|
256
|
+
current = nextFlatTreeAncestor(current);
|
|
249
257
|
}
|
|
250
258
|
return null;
|
|
251
259
|
};
|