@nectary/components 2.0.0 → 2.1.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/action-menu/index.js +5 -1
- 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 +2 -4
- 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 -19
- 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-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 -12
- package/input/utils.d.ts +0 -3
- package/input/utils.js +1 -6
- package/package.json +2 -3
- 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/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/select-button/index.js +23 -20
- package/select-menu/index.js +6 -3
- package/spinner/index.js +2 -9
- 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/time-picker/index.js +0 -3
- 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/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/pop/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, updateLiteralAttribute, getReactEventHandler, updateBooleanAttribute, NectaryElement, throttleAnimationFrame, isElementFocused, updateIntegerAttribute, getIntegerAttribute, getFirstFocusableElement, getFirstSlotElement, Context, subscribeContext, isTargetEqual } from '../utils';
|
|
2
2
|
const templateHTML = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:1;background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}#content{position:relative;z-index:1}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
|
|
3
|
-
import {
|
|
3
|
+
import { disableScroll, enableScroll, orientationValues } from './utils';
|
|
4
4
|
const template = document.createElement('template');
|
|
5
5
|
template.innerHTML = templateHTML;
|
|
6
6
|
defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
7
|
-
#$
|
|
7
|
+
#$targetWrapper;
|
|
8
8
|
#$focus;
|
|
9
9
|
#$dialog;
|
|
10
10
|
#resizeThrottle;
|
|
@@ -21,7 +21,7 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
21
21
|
super();
|
|
22
22
|
const shadowRoot = this.attachShadow();
|
|
23
23
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
24
|
-
this.#$
|
|
24
|
+
this.#$targetWrapper = shadowRoot.querySelector('#target');
|
|
25
25
|
this.#$focus = shadowRoot.querySelector('#focus');
|
|
26
26
|
this.#$dialog = shadowRoot.querySelector('#dialog');
|
|
27
27
|
this.#$targetSlot = shadowRoot.querySelector('slot[name="target"]');
|
|
@@ -119,9 +119,6 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
119
119
|
}
|
|
120
120
|
case 'orientation':
|
|
121
121
|
{
|
|
122
|
-
if ('production' !== 'production') {
|
|
123
|
-
assertOrientation(newVal);
|
|
124
|
-
}
|
|
125
122
|
if (this.#$dialog.open) {
|
|
126
123
|
this.#updateOrientation();
|
|
127
124
|
}
|
|
@@ -135,7 +132,7 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
135
132
|
item = getFirstSlotElement(this.#$targetOpenSlot, true);
|
|
136
133
|
}
|
|
137
134
|
if (item === null) {
|
|
138
|
-
return getRect(this.#$
|
|
135
|
+
return getRect(this.#$targetWrapper);
|
|
139
136
|
}
|
|
140
137
|
if (Reflect.has(item, 'footprintRect')) {
|
|
141
138
|
return item.footprintRect;
|
|
@@ -145,7 +142,7 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
145
142
|
#getFirstTargetElement(slot) {
|
|
146
143
|
const item = getFirstSlotElement(slot, true);
|
|
147
144
|
if (item === null) {
|
|
148
|
-
return this.#$
|
|
145
|
+
return this.#$targetWrapper;
|
|
149
146
|
}
|
|
150
147
|
return item;
|
|
151
148
|
}
|
|
@@ -163,7 +160,7 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
163
160
|
this.#$focus.removeAttribute('tabindex');
|
|
164
161
|
this.#$focus.removeAttribute('style');
|
|
165
162
|
this.#$dialog.showModal();
|
|
166
|
-
this.#$
|
|
163
|
+
this.#$targetWrapper.setAttribute('aria-expanded', 'true');
|
|
167
164
|
this.#updateOrientation();
|
|
168
165
|
if (this.modal) {
|
|
169
166
|
getFirstFocusableElement(this.#$contentSlot)?.focus();
|
|
@@ -175,9 +172,9 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
175
172
|
const marginTop = parseInt(targetElComputedStyle.marginTop);
|
|
176
173
|
const marginBottom = parseInt(targetElComputedStyle.marginBottom);
|
|
177
174
|
const targetRect = this.#getTargetRect();
|
|
178
|
-
this.#$
|
|
179
|
-
this.#$
|
|
180
|
-
this.#$
|
|
175
|
+
this.#$targetWrapper.style.setProperty('display', 'block');
|
|
176
|
+
this.#$targetWrapper.style.setProperty('width', `${targetRect.width + marginLeft + marginRight}px`);
|
|
177
|
+
this.#$targetWrapper.style.setProperty('height', `${targetRect.height + marginTop + marginBottom}px`);
|
|
181
178
|
this.#$targetOpenWrapper.style.setProperty('width', `${targetRect.width}px`);
|
|
182
179
|
this.#$targetOpenWrapper.style.setProperty('height', `${targetRect.height}px`);
|
|
183
180
|
this.#targetStyleValue = $targetEl.getAttribute('style');
|
|
@@ -221,26 +218,27 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
221
218
|
this.#dispatchContentVisibility(false);
|
|
222
219
|
this.#$targetOpenSlot.removeEventListener('keydown', this.#onTargetKeydown);
|
|
223
220
|
if (isNonModal) {
|
|
224
|
-
this.#targetActiveElement = null;
|
|
225
221
|
this.#$targetOpenSlot.addEventListener('blur', this.#captureActiveElement, true);
|
|
226
222
|
}
|
|
227
223
|
this.#$dialog.close();
|
|
228
|
-
this.#$
|
|
224
|
+
this.#$targetWrapper.setAttribute('aria-expanded', 'false');
|
|
229
225
|
if (isNonModal) {
|
|
230
226
|
this.#$targetOpenSlot.removeEventListener('blur', this.#captureActiveElement, true);
|
|
231
227
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
228
|
+
if (isNonModal) {
|
|
229
|
+
const targetEl = this.#getFirstTargetElement(this.#$targetOpenSlot);
|
|
230
|
+
targetEl.style.removeProperty('margin');
|
|
231
|
+
targetEl.style.removeProperty('position');
|
|
232
|
+
targetEl.style.removeProperty('transform');
|
|
233
|
+
if (this.#targetStyleValue !== null) {
|
|
234
|
+
targetEl.setAttribute('style', this.#targetStyleValue);
|
|
235
|
+
this.#targetStyleValue = null;
|
|
236
|
+
}
|
|
237
|
+
getFirstSlotElement(this.#$targetOpenSlot)?.setAttribute('slot', 'target');
|
|
238
|
+
this.#$targetWrapper.style.removeProperty('display');
|
|
239
|
+
this.#$targetWrapper.style.removeProperty('width');
|
|
240
|
+
this.#$targetWrapper.style.removeProperty('height');
|
|
239
241
|
}
|
|
240
|
-
getFirstSlotElement(this.#$targetOpenSlot)?.setAttribute('slot', 'target');
|
|
241
|
-
this.#$target.style.removeProperty('display');
|
|
242
|
-
this.#$target.style.removeProperty('width');
|
|
243
|
-
this.#$target.style.removeProperty('height');
|
|
244
242
|
if (this.#targetActiveElement !== null) {
|
|
245
243
|
if (!isElementFocused(this.#targetActiveElement)) {
|
|
246
244
|
this.#$targetSlot.addEventListener('focus', this.#stopEventPropagation, true);
|
package/pop/utils.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { TSinchPopOrientation } from './types';
|
|
2
2
|
export declare const orientationValues: readonly TSinchPopOrientation[];
|
|
3
|
-
type TAssertOrientation = (value: string | null) => asserts value is TSinchPopOrientation;
|
|
4
|
-
export declare const assertOrientation: TAssertOrientation;
|
|
5
3
|
export declare const disableScroll: () => void;
|
|
6
4
|
export declare const enableScroll: () => void;
|
|
7
|
-
export {};
|
package/pop/utils.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
export const orientationValues = ['top-left', 'top-right', 'bottom-left', 'bottom-right', 'bottom-stretch', 'bottom-center', 'top-stretch', 'top-center', 'center-left', 'center-right'];
|
|
2
|
-
export const assertOrientation = value => {
|
|
3
|
-
if (value === null || !orientationValues.includes(value)) {
|
|
4
|
-
throw new Error(`sinch-pop: invalid orientation attribute: ${value}`);
|
|
5
|
-
}
|
|
6
|
-
};
|
|
7
2
|
const bodyEl = document.body;
|
|
8
3
|
export const disableScroll = () => {
|
|
9
4
|
bodyEl.style.overflow = 'hidden';
|
package/popover/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../pop';
|
|
2
2
|
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, updateBooleanAttribute, NectaryElement, updateAttribute, getReactEventHandler, isAttrTrue, setClass, rectOverlap, subscribeContext } from '../utils';
|
|
3
3
|
const templateHTML = '<style>:host{display:contents}#content-wrapper{position:relative;padding-top:4px}:host([tip]) #content-wrapper{padding-top:12px;filter:drop-shadow(var(--sinch-comp-popover-shadow))}:host([orientation^=top]) #content-wrapper{padding-top:0;padding-bottom:4px}:host([orientation^=top][tip]) #content-wrapper{padding-top:0;padding-bottom:12px}#content{background-color:var(--sinch-comp-popover-color-default-background-initial);border:1px solid var(--sinch-comp-popover-color-default-border-initial);border-radius:var(--sinch-comp-popover-shape-radius);box-shadow:var(--sinch-comp-popover-shadow);overflow:hidden}:host([tip]) #content{box-shadow:none}#tip{position:absolute;left:50%;top:13px;transform:translateX(-50%) rotate(180deg);transform-origin:top center;fill:var(--sinch-comp-popover-color-default-background-initial);stroke:var(--sinch-comp-popover-color-default-border-initial);stroke-linecap:square;pointer-events:none;display:none}:host([orientation^=top]) #tip{transform:translateX(-50%) rotate(0);top:calc(100% - 13px)}:host([tip]) #tip:not(.hidden){display:block}</style><sinch-pop id="pop" inset="4"><slot name="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content"><slot name="content"></slot></div><svg id="tip" width="16" height="9" aria-hidden="true"><path d="m0 0 8 8 8 -8"/></svg></div></sinch-pop>';
|
|
4
|
-
import {
|
|
4
|
+
import { getPopOrientation, orientationValues } from './utils';
|
|
5
5
|
const TIP_SIZE = 16;
|
|
6
6
|
const template = document.createElement('template');
|
|
7
7
|
template.innerHTML = templateHTML;
|
|
@@ -45,9 +45,6 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
45
45
|
switch (name) {
|
|
46
46
|
case 'orientation':
|
|
47
47
|
{
|
|
48
|
-
if ('production' !== 'production') {
|
|
49
|
-
assertOrientation(newVal);
|
|
50
|
-
}
|
|
51
48
|
updateAttribute(this.#$pop, 'orientation', getPopOrientation(this.orientation));
|
|
52
49
|
if (this.#$pop.open) {
|
|
53
50
|
this.#updateTipOrientation();
|
package/popover/utils.d.ts
CHANGED
|
@@ -2,6 +2,3 @@ import type { TSinchPopoverOrientation } from './types';
|
|
|
2
2
|
import type { TSinchPopOrientation } from '../pop/types';
|
|
3
3
|
export declare const orientationValues: readonly TSinchPopoverOrientation[];
|
|
4
4
|
export declare const getPopOrientation: (orientation: TSinchPopoverOrientation) => TSinchPopOrientation;
|
|
5
|
-
type TAssertOrientation = (value: string | null) => asserts value is TSinchPopoverOrientation;
|
|
6
|
-
export declare const assertOrientation: TAssertOrientation;
|
|
7
|
-
export {};
|
package/popover/utils.js
CHANGED
|
@@ -7,9 +7,4 @@ export const getPopOrientation = orientation => {
|
|
|
7
7
|
return 'bottom-stretch';
|
|
8
8
|
}
|
|
9
9
|
return orientation;
|
|
10
|
-
};
|
|
11
|
-
export const assertOrientation = value => {
|
|
12
|
-
if (value === null || !orientationValues.includes(value)) {
|
|
13
|
-
throw new Error(`sinch-popover: invalid orientation attribute: ${value}`);
|
|
14
|
-
}
|
|
15
10
|
};
|
package/rich-text/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCustomElement, NectaryElement, getLiteralAttribute, updateLiteralAttribute, getAttribute, updateAttribute, parseMarkdown } from '../utils';
|
|
2
2
|
const templateHTML = '<style>:host{display:block;--sinch-comp-rich-text-font:var(--sinch-sys-font-body-m)}:host([size="s"]){--sinch-comp-rich-text-font:var(--sinch-sys-font-body-s)}:host([size=xs]){--sinch-comp-rich-text-font:var(--sinch-sys-font-body-xs)}:host([size=xxs]){--sinch-comp-rich-text-font:var(--sinch-sys-font-body-xxs)}#wrapper{font:var(--sinch-comp-rich-text-font);color:var(--sinch-global-color-text,var(--sinch-sys-color-text-default))}.em1{font-style:italic}.em2{font-weight:var(--sinch-ref-typography-font-weight-700)}.em3{font-style:italic;font-weight:var(--sinch-ref-typography-font-weight-700)}.strikethrough{text-decoration:line-through}.link{font:var(--sinch-comp-link-default-font-initial);color:var(--sinch-comp-link-color-default-text-initial);text-decoration:underline}.link:hover{color:var(--sinch-comp-link-color-default-text-hover);text-decoration:none}.code{font:var(--sinch-comp-code-tag-font-text);line-height:inherit;font-size:inherit;border:1px solid var(--sinch-comp-code-tag-color-default-border-initial);background-color:var(--sinch-comp-code-tag-color-default-background-initial);padding:0 .25em;border-radius:var(--sinch-comp-code-tag-shape-radius)}.paragraph{margin:0}.paragraph+.paragraph{margin-top:12px}</style><div id="wrapper"></div>';
|
|
3
|
-
import {
|
|
3
|
+
import { sizeValues } from './utils';
|
|
4
4
|
const template = document.createElement('template');
|
|
5
5
|
template.innerHTML = templateHTML;
|
|
6
6
|
defineCustomElement('sinch-rich-text', class extends NectaryElement {
|
|
@@ -27,17 +27,10 @@ defineCustomElement('sinch-rich-text', class extends NectaryElement {
|
|
|
27
27
|
updateAttribute(this, 'text', value);
|
|
28
28
|
}
|
|
29
29
|
static get observedAttributes() {
|
|
30
|
-
return ['
|
|
30
|
+
return ['text'];
|
|
31
31
|
}
|
|
32
32
|
attributeChangedCallback(name, _, newVal) {
|
|
33
33
|
switch (name) {
|
|
34
|
-
case 'size':
|
|
35
|
-
{
|
|
36
|
-
if ('production' !== 'production') {
|
|
37
|
-
assertSize(newVal);
|
|
38
|
-
}
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
34
|
case 'text':
|
|
42
35
|
{
|
|
43
36
|
this.#updateText(newVal);
|
package/rich-text/utils.d.ts
CHANGED
package/rich-text/utils.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
export const sizeValues = ['m', 's', 'xs', 'xxs'];
|
|
2
|
-
export const assertSize = value => {
|
|
3
|
-
if (value === null || !sizeValues.includes(value)) {
|
|
4
|
-
throw new Error(`sinch-rich-text: invalid "size" attribute: "${value}"`);
|
|
5
|
-
}
|
|
6
|
-
};
|
|
1
|
+
export const sizeValues = ['m', 's', 'xs', 'xxs'];
|
package/segment/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../title';
|
|
2
2
|
import { getTitleLevelFromType } from '../title/utils';
|
|
3
3
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute, updateLiteralAttribute } from '../utils';
|
|
4
|
-
import {
|
|
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';
|
|
7
7
|
const template = document.createElement('template');
|
|
@@ -63,9 +63,6 @@ defineCustomElement('sinch-segment', class extends NectaryElement {
|
|
|
63
63
|
}
|
|
64
64
|
case 'size':
|
|
65
65
|
{
|
|
66
|
-
if ('production' !== 'production') {
|
|
67
|
-
assertSize(newVal, 'sinch-segment');
|
|
68
|
-
}
|
|
69
66
|
const titleType = getTitleTypeFromSize(this.size);
|
|
70
67
|
updateAttribute(this.#$caption, 'level', getTitleLevelFromType(titleType));
|
|
71
68
|
break;
|
package/select-button/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import '../text';
|
|
2
2
|
import '../icon';
|
|
3
3
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getReactEventHandler, isAttrTrue, NectaryElement, setClass, subscribeContext, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute, updateLiteralAttribute, Context } from '../utils';
|
|
4
|
-
import {
|
|
5
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;gap:8px;box-sizing:border-box;width:100%;height:var(--sinch-local-size);padding:0 8px 0 12px;background-color:var(--sinch-comp-select-button-color-default-background-initial);border-radius:var(--sinch-local-shape-radius);--sinch-local-size:var(--sinch-comp-select-button-size-container-m);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-m);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-m);--sinch-global-color-icon:var(--sinch-comp-select-button-color-default-icon-initial)}:host([data-size="l"])>#wrapper{--sinch-local-size:var(--sinch-comp-select-button-size-container-l);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-l);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-l)}:host([data-size="m"])>#wrapper{--sinch-local-size:var(--sinch-comp-select-button-size-container-m);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-m);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-m)}:host([data-size="s"])>#wrapper{--sinch-local-size:var(--sinch-comp-select-button-size-container-s);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-s);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-s)}:host([data-size="l"]) #wrapper{padding:0 12px}:host([data-size="m"]) #wrapper{padding:0 8px 0 12px}:host([data-size="s"]) #wrapper{padding:0 4px 0 12px}:host([disabled]) #wrapper{--sinch-global-color-icon:var(--sinch-comp-select-button-color-disabled-icon-initial)}#text{flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-select-button-font-input);--sinch-global-color-text:var(--sinch-comp-select-button-color-default-text-initial)}#text:empty{display:none}#placeholder{display:none;flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-select-button-font-placeholder);--sinch-global-color-text:var(--sinch-comp-select-button-color-default-placeholder-initial)}#text:empty+#placeholder{display:block}#border{position:absolute;border:1px solid var(--sinch-comp-select-button-color-default-border-initial);border-radius:var(--sinch-local-shape-radius);inset:0;pointer-events:none}
|
|
4
|
+
import { DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
5
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;gap:8px;box-sizing:border-box;width:100%;height:var(--sinch-local-size);padding:0 8px 0 12px;background-color:var(--sinch-comp-select-button-color-default-background-initial);border-radius:var(--sinch-local-shape-radius);cursor:pointer;--sinch-local-size:var(--sinch-comp-select-button-size-container-m);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-m);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-m);--sinch-global-color-icon:var(--sinch-comp-select-button-color-default-icon-initial)}:host([data-size="l"])>#wrapper{--sinch-local-size:var(--sinch-comp-select-button-size-container-l);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-l);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-l)}:host([data-size="m"])>#wrapper{--sinch-local-size:var(--sinch-comp-select-button-size-container-m);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-m);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-m)}:host([data-size="s"])>#wrapper{--sinch-local-size:var(--sinch-comp-select-button-size-container-s);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-s);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-s)}:host([data-size="l"]) #wrapper{padding:0 12px}:host([data-size="m"]) #wrapper{padding:0 8px 0 12px}:host([data-size="s"]) #wrapper{padding:0 4px 0 12px}:host([disabled]) #wrapper{--sinch-global-color-icon:var(--sinch-comp-select-button-color-disabled-icon-initial);cursor:initial}#text{flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-select-button-font-input);--sinch-global-color-text:var(--sinch-comp-select-button-color-default-text-initial)}#text:empty{display:none}#placeholder{display:none;flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-select-button-font-placeholder);--sinch-global-color-text:var(--sinch-comp-select-button-color-default-placeholder-initial)}#text:empty+#placeholder{display:block}#border{position:absolute;border:1px solid var(--sinch-comp-select-button-color-default-border-initial);border-radius:var(--sinch-local-shape-radius);inset:0;pointer-events:none}:host(:focus-visible) #border{border-color:var(--sinch-comp-select-button-color-default-border-focus);border-width:2px}:host([invalid]) #border{border-color:var(--sinch-comp-select-button-color-invalid-border-initial)}:host([disabled]) #border{border-color:var(--sinch-comp-select-button-color-disabled-border-initial)}:host([disabled]) #text{--sinch-global-color-text:var(--sinch-comp-select-button-color-disabled-text-initial)}:host([disabled]) #placeholder{--sinch-global-color-text:var(--sinch-comp-select-button-color-disabled-placeholder-initial)}#left{display:flex;flex-direction:row;align-self:stretch;align-items:center;gap:4px;margin-left:-4px}#left.empty{display:none}#dropdown-icon{margin-left:-4px}</style><div id="wrapper" inert><div id="border"></div><div id="left"><slot name="left"></slot></div><slot name="icon"></slot><sinch-text id="text" type="m" ellipsis></sinch-text><sinch-text id="placeholder" type="m" ellipsis></sinch-text><sinch-icon id="dropdown-icon" name="keyboard_arrow_down"></sinch-icon></div>';
|
|
6
6
|
const template = document.createElement('template');
|
|
7
7
|
template.innerHTML = templateHTML;
|
|
8
8
|
defineCustomElement('sinch-select-button', class extends NectaryElement {
|
|
9
|
-
#$button;
|
|
10
9
|
#$text;
|
|
11
10
|
#$placeholder;
|
|
12
11
|
#$leftSlot;
|
|
@@ -17,10 +16,9 @@ defineCustomElement('sinch-select-button', class extends NectaryElement {
|
|
|
17
16
|
constructor() {
|
|
18
17
|
super();
|
|
19
18
|
const shadowRoot = this.attachShadow({
|
|
20
|
-
delegatesFocus:
|
|
19
|
+
delegatesFocus: false
|
|
21
20
|
});
|
|
22
21
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
23
|
-
this.#$button = shadowRoot.querySelector('#button');
|
|
24
22
|
this.#$text = shadowRoot.querySelector('#text');
|
|
25
23
|
this.#$placeholder = shadowRoot.querySelector('#placeholder');
|
|
26
24
|
this.#$leftSlot = shadowRoot.querySelector('slot[name="left"]');
|
|
@@ -34,14 +32,18 @@ defineCustomElement('sinch-select-button', class extends NectaryElement {
|
|
|
34
32
|
const {
|
|
35
33
|
signal
|
|
36
34
|
} = this.#controller;
|
|
37
|
-
this.
|
|
38
|
-
this
|
|
35
|
+
this.role = 'button';
|
|
36
|
+
this.tabIndex = 0;
|
|
37
|
+
this.addEventListener('click', this.#onButtonClick, {
|
|
39
38
|
signal
|
|
40
39
|
});
|
|
41
|
-
this
|
|
40
|
+
this.addEventListener('focus', this.#onButtonFocus, {
|
|
42
41
|
signal
|
|
43
42
|
});
|
|
44
|
-
this
|
|
43
|
+
this.addEventListener('blur', this.#onButtonBlur, {
|
|
44
|
+
signal
|
|
45
|
+
});
|
|
46
|
+
this.addEventListener('keydown', this.#onButtonKeydown, {
|
|
45
47
|
signal
|
|
46
48
|
});
|
|
47
49
|
this.addEventListener('-click', this.#onClickReactHandler, {
|
|
@@ -93,7 +95,6 @@ defineCustomElement('sinch-select-button', class extends NectaryElement {
|
|
|
93
95
|
case 'disabled':
|
|
94
96
|
{
|
|
95
97
|
const isDisabled = isAttrTrue(newVal);
|
|
96
|
-
this.#$button.disabled = isDisabled;
|
|
97
98
|
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
98
99
|
break;
|
|
99
100
|
}
|
|
@@ -104,9 +105,6 @@ defineCustomElement('sinch-select-button', class extends NectaryElement {
|
|
|
104
105
|
}
|
|
105
106
|
case 'data-size':
|
|
106
107
|
{
|
|
107
|
-
if ('production' !== 'production') {
|
|
108
|
-
assertSize(newVal, 'sinch-select-button');
|
|
109
|
-
}
|
|
110
108
|
this.#onSizeUpdate();
|
|
111
109
|
break;
|
|
112
110
|
}
|
|
@@ -145,12 +143,6 @@ defineCustomElement('sinch-select-button', class extends NectaryElement {
|
|
|
145
143
|
get focusable() {
|
|
146
144
|
return true;
|
|
147
145
|
}
|
|
148
|
-
focus() {
|
|
149
|
-
this.#$button.focus();
|
|
150
|
-
}
|
|
151
|
-
blur() {
|
|
152
|
-
this.#$button.blur();
|
|
153
|
-
}
|
|
154
146
|
#onContextSize = e => {
|
|
155
147
|
if (this.hasAttribute('size')) {
|
|
156
148
|
return;
|
|
@@ -183,8 +175,19 @@ defineCustomElement('sinch-select-button', class extends NectaryElement {
|
|
|
183
175
|
#onButtonBlur = () => {
|
|
184
176
|
this.dispatchEvent(new CustomEvent('-blur'));
|
|
185
177
|
};
|
|
178
|
+
#onButtonKeydown = e => {
|
|
179
|
+
switch (e.code) {
|
|
180
|
+
case 'Space':
|
|
181
|
+
case 'Enter':
|
|
182
|
+
{
|
|
183
|
+
this.click();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
186
187
|
#onButtonClick = () => {
|
|
187
|
-
this.
|
|
188
|
+
if (!this.disabled) {
|
|
189
|
+
this.dispatchEvent(new CustomEvent('-click'));
|
|
190
|
+
}
|
|
188
191
|
};
|
|
189
192
|
#onClickReactHandler = e => {
|
|
190
193
|
getReactEventHandler(this, 'on-click')?.(e);
|
package/select-menu/index.js
CHANGED
|
@@ -18,7 +18,9 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
|
|
|
18
18
|
#searchDebounce;
|
|
19
19
|
constructor() {
|
|
20
20
|
super();
|
|
21
|
-
const shadowRoot = this.attachShadow(
|
|
21
|
+
const shadowRoot = this.attachShadow({
|
|
22
|
+
delegatesFocus: false
|
|
23
|
+
});
|
|
22
24
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
23
25
|
this.#$optionSlot = shadowRoot.querySelector('slot');
|
|
24
26
|
this.#$listbox = shadowRoot.querySelector('#listbox');
|
|
@@ -32,8 +34,8 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
|
|
|
32
34
|
const options = {
|
|
33
35
|
signal: this.#controller.signal
|
|
34
36
|
};
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
+
this.role = 'listbox';
|
|
38
|
+
this.tabIndex = 0;
|
|
37
39
|
this.addEventListener('keydown', this.#onListboxKeyDown, options);
|
|
38
40
|
this.addEventListener('focus', this.#onFocus, options);
|
|
39
41
|
this.addEventListener('blur', this.#onListboxBlur, options);
|
|
@@ -118,6 +120,7 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
|
|
|
118
120
|
};
|
|
119
121
|
#onListboxClick = e => {
|
|
120
122
|
const $elem = e.target;
|
|
123
|
+
this.focus();
|
|
121
124
|
if (!getBooleanAttribute($elem, 'disabled')) {
|
|
122
125
|
this.#selectOption($elem);
|
|
123
126
|
}
|
package/spinner/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineCustomElement, getLiteralAttribute, NectaryElement, subscribeContext, updateAttribute, updateLiteralAttribute } from '../utils';
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
3
3
|
const templateHTML = '<style>@keyframes spinner{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}:host{display:block}#spinner-size-l,#spinner-size-m,#spinner-size-s{display:none;will-change:transform}:host([data-size="l"])>#spinner-size-l{display:block;animation:1s linear infinite spinner}:host([data-size="m"])>#spinner-size-m{display:block;animation:1s linear infinite spinner}:host([data-size="s"])>#spinner-size-s{display:block;animation:1s linear infinite spinner}.bg{opacity:.3;stroke:var(--sinch-global-color-icon,var(--sinch-sys-color-text-default))}.fg{stroke:var(--sinch-global-color-icon,var(--sinch-sys-color-text-default))}</style><svg id="spinner-size-l" width="50" height="50" fill="none"><circle class="bg" cx="25" cy="25" r="22" stroke-width="6"/><path class="fg" d="M25 3a22 22 0 0 1 22 22" stroke-width="6" stroke-linecap="round"/></svg><svg id="spinner-size-m" width="24" height="24" fill="none"><circle class="bg" cx="12" cy="12" r="9" stroke-width="4"/><path class="fg" d="M21 12a9 9 0 0 0-9-9" stroke-width="4" stroke-linecap="round"/></svg><svg id="spinner-size-s" width="16" height="16" fill="none"><circle class="bg" cx="8" cy="8" r="6" stroke-width="2"/><path class="fg" d="M14 8a6 6 0 0 0-6-6" stroke-width="2" stroke-linecap="round"/></svg>';
|
|
4
4
|
const template = document.createElement('template');
|
|
5
5
|
template.innerHTML = templateHTML;
|
|
@@ -20,7 +20,7 @@ defineCustomElement('sinch-spinner', class extends NectaryElement {
|
|
|
20
20
|
this.#controller.abort();
|
|
21
21
|
}
|
|
22
22
|
static get observedAttributes() {
|
|
23
|
-
return ['size'
|
|
23
|
+
return ['size'];
|
|
24
24
|
}
|
|
25
25
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
26
26
|
if (oldVal === newVal) {
|
|
@@ -32,13 +32,6 @@ defineCustomElement('sinch-spinner', class extends NectaryElement {
|
|
|
32
32
|
updateAttribute(this, 'data-size', newVal);
|
|
33
33
|
break;
|
|
34
34
|
}
|
|
35
|
-
case 'data-size':
|
|
36
|
-
{
|
|
37
|
-
if ('production' !== 'production') {
|
|
38
|
-
assertSize(newVal, 'sinch-spinner');
|
|
39
|
-
}
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
35
|
}
|
|
43
36
|
}
|
|
44
37
|
set size(size) {
|
package/tag/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../text';
|
|
2
2
|
import { defineCustomElement, getBooleanAttribute, getAttribute, updateBooleanAttribute, updateAttribute, NectaryElement, isAttrTrue } from '../utils';
|
|
3
3
|
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;flex-direction:row;align-items:center;gap:4px;width:100%;height:var(--sinch-comp-tag-size-container-m);padding:0 9px;border-radius:var(--sinch-comp-tag-shape-radius);background-color:var(--sinch-comp-tag-color-default-background);box-sizing:border-box;user-select:none;--sinch-global-color-text:var(--sinch-comp-tag-color-default-foreground);--sinch-global-color-icon:var(--sinch-comp-tag-color-default-foreground);--sinch-global-size-icon:var(--sinch-comp-tag-size-icon-m)}:host([small]) #wrapper{height:var(--sinch-comp-tag-size-container-s);padding:0 8px;--sinch-global-size-icon:var(--sinch-comp-tag-size-icon-s)}#text{flex:1;--sinch-comp-text-font:var(--sinch-comp-tag-font-size-m-label)}:host([small]) #text{--sinch-comp-text-font:var(--sinch-comp-tag-font-size-s-label)}::slotted(*){margin-left:-4px}</style><div id="wrapper"><slot name="icon"></slot><sinch-text id="text" type="s" ellipsis></sinch-text></div>';
|
|
4
|
-
import {
|
|
4
|
+
import { getTagColorBg, getTagColorFg } from './utils';
|
|
5
5
|
const template = document.createElement('template');
|
|
6
6
|
template.innerHTML = templateHTML;
|
|
7
7
|
defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
@@ -67,9 +67,6 @@ defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
|
67
67
|
}
|
|
68
68
|
const colorName = this.color;
|
|
69
69
|
if (colorName !== null && colorName.length > 0) {
|
|
70
|
-
if ('production' !== 'production') {
|
|
71
|
-
assertTagColor(this, colorName);
|
|
72
|
-
}
|
|
73
70
|
const bg = getTagColorBg(colorName);
|
|
74
71
|
const fg = getTagColorFg(colorName);
|
|
75
72
|
this.#$wrapper.style.setProperty('background-color', bg);
|
package/tag/utils.d.ts
CHANGED
package/tag/utils.js
CHANGED
|
@@ -3,9 +3,4 @@ export const getTagColorBg = id => {
|
|
|
3
3
|
};
|
|
4
4
|
export const getTagColorFg = id => {
|
|
5
5
|
return `var(--sinch-comp-tag-color-${id}-foreground)`;
|
|
6
|
-
};
|
|
7
|
-
export const assertTagColor = (root, id) => {
|
|
8
|
-
if (id === null || window.getComputedStyle(root).getPropertyValue(`--sinch-comp-tag-color-${id}-background`).length === 0) {
|
|
9
|
-
throw new Error(`Invalid sinch-tag color name: ${id}`);
|
|
10
|
-
}
|
|
11
6
|
};
|
package/text/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCustomElement, getBooleanAttribute, updateBooleanAttribute, NectaryElement, getLiteralAttribute, updateLiteralAttribute, isAttrTrue } from '../utils';
|
|
2
2
|
const templateHTML = '<style>:host{display:block;font:var(--sinch-comp-text-font);color:var(--sinch-global-color-text,var(--sinch-sys-color-text-default));--sinch-comp-text-font:var(--sinch-sys-font-body-m)}:host([inline]){display:inline}:host([type="s"]){--sinch-comp-text-font:var(--sinch-sys-font-body-s)}:host([type=xs]){--sinch-comp-text-font:var(--sinch-sys-font-body-xs)}:host([type=xxs]){--sinch-comp-text-font:var(--sinch-sys-font-body-xxs)}:host([type="m"][emphasized]){--sinch-comp-text-font:var(--sinch-sys-font-body-emphasize)}:host([type="s"][emphasized]){--sinch-comp-text-font:var(--sinch-sys-font-body-emphasize-s)}:host([ellipsis]){overflow:hidden;text-overflow:ellipsis;white-space:nowrap;--sinch-global-text-white-space:nowrap}</style><slot></slot>';
|
|
3
|
-
import {
|
|
3
|
+
import { typeValues } from './utils';
|
|
4
4
|
const template = document.createElement('template');
|
|
5
5
|
template.innerHTML = templateHTML;
|
|
6
6
|
defineCustomElement('sinch-text', class extends NectaryElement {
|
|
@@ -13,17 +13,10 @@ defineCustomElement('sinch-text', class extends NectaryElement {
|
|
|
13
13
|
this.#updateRole();
|
|
14
14
|
}
|
|
15
15
|
static get observedAttributes() {
|
|
16
|
-
return ['
|
|
16
|
+
return ['inline', 'ellipsis', 'emphasized'];
|
|
17
17
|
}
|
|
18
18
|
attributeChangedCallback(name, _, newVal) {
|
|
19
19
|
switch (name) {
|
|
20
|
-
case 'type':
|
|
21
|
-
{
|
|
22
|
-
if ('production' !== 'production') {
|
|
23
|
-
assertType(newVal);
|
|
24
|
-
}
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
20
|
case 'inline':
|
|
28
21
|
{
|
|
29
22
|
this.#updateRole();
|
package/text/utils.d.ts
CHANGED
package/text/utils.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
export const typeValues = ['m', 's', 'xs', 'xxs'];
|
|
2
|
-
export const assertType = value => {
|
|
3
|
-
if (value === null || !typeValues.includes(value)) {
|
|
4
|
-
throw new Error(`sinch-text: invalid "type" attribute: "${value}"`);
|
|
5
|
-
}
|
|
6
|
-
};
|
|
1
|
+
export const typeValues = ['m', 's', 'xs', 'xxs'];
|
package/time-picker/index.js
CHANGED
package/time-picker/utils.d.ts
CHANGED
package/time-picker/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const parseTime = value => {
|
|
2
|
-
if (value === '') {
|
|
2
|
+
if (value === '' || value === null) {
|
|
3
3
|
return {
|
|
4
4
|
hours: 0,
|
|
5
5
|
minutes: 0
|
|
@@ -7,19 +7,31 @@ export const parseTime = value => {
|
|
|
7
7
|
}
|
|
8
8
|
const timeParts = value.split(':');
|
|
9
9
|
if (timeParts.length < 3) {
|
|
10
|
-
|
|
10
|
+
return {
|
|
11
|
+
hours: 0,
|
|
12
|
+
minutes: 0
|
|
13
|
+
};
|
|
11
14
|
}
|
|
12
15
|
const hours = parseInt(timeParts[0]);
|
|
13
16
|
const minutes = parseInt(timeParts[1]);
|
|
14
17
|
const seconds = parseInt(timeParts[2]);
|
|
15
18
|
if (isNaN(hours) || hours > 23 || hours < 0) {
|
|
16
|
-
|
|
19
|
+
return {
|
|
20
|
+
hours: 0,
|
|
21
|
+
minutes: 0
|
|
22
|
+
};
|
|
17
23
|
}
|
|
18
24
|
if (isNaN(minutes) || minutes > 59 || minutes < 0) {
|
|
19
|
-
|
|
25
|
+
return {
|
|
26
|
+
hours: 0,
|
|
27
|
+
minutes: 0
|
|
28
|
+
};
|
|
20
29
|
}
|
|
21
30
|
if (isNaN(seconds) || seconds > 59 || seconds < 0) {
|
|
22
|
-
|
|
31
|
+
return {
|
|
32
|
+
hours: 0,
|
|
33
|
+
minutes: 0
|
|
34
|
+
};
|
|
23
35
|
}
|
|
24
36
|
return {
|
|
25
37
|
hours,
|
package/title/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCustomElement, getAttribute, updateAttribute, updateLiteralAttribute, getLiteralAttribute, NectaryElement, updateBooleanAttribute, getBooleanAttribute, isAttrTrue } from '../utils';
|
|
2
2
|
const templateHTML = '<style>:host{display:block;--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-m)}:host([type=xl]){--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-xl)}:host([type="l"]){--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-l)}:host([type="m"]){--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-m)}:host([type="s"]){--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-s)}:host([type=xs]){--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-xs)}#text{letter-spacing:-2%;color:var(--sinch-global-color-text,var(--sinch-sys-color-text-default));font:var(--sinch-comp-title-font)}:host([ellipsis]) #text{display:block;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}</style><span id="text"></span>';
|
|
3
|
-
import {
|
|
3
|
+
import { typeValues } from './utils';
|
|
4
4
|
const template = document.createElement('template');
|
|
5
5
|
template.innerHTML = templateHTML;
|
|
6
6
|
defineCustomElement('sinch-title', class extends NectaryElement {
|
|
@@ -15,7 +15,7 @@ defineCustomElement('sinch-title', class extends NectaryElement {
|
|
|
15
15
|
this.setAttribute('role', 'heading');
|
|
16
16
|
}
|
|
17
17
|
static get observedAttributes() {
|
|
18
|
-
return ['text', '
|
|
18
|
+
return ['text', 'level', 'ellipsis'];
|
|
19
19
|
}
|
|
20
20
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
21
21
|
if (oldVal === newVal) {
|
|
@@ -29,19 +29,9 @@ defineCustomElement('sinch-title', class extends NectaryElement {
|
|
|
29
29
|
}
|
|
30
30
|
case 'level':
|
|
31
31
|
{
|
|
32
|
-
if ('production' !== 'production') {
|
|
33
|
-
assertLevel(newVal);
|
|
34
|
-
}
|
|
35
32
|
updateAttribute(this, 'aria-level', newVal);
|
|
36
33
|
break;
|
|
37
34
|
}
|
|
38
|
-
case 'type':
|
|
39
|
-
{
|
|
40
|
-
if ('production' !== 'production') {
|
|
41
|
-
assertType(newVal);
|
|
42
|
-
}
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
35
|
case 'ellipsis':
|
|
46
36
|
{
|
|
47
37
|
updateBooleanAttribute(this, 'ellipsis', isAttrTrue(newVal));
|
package/title/utils.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
import type { TSinchTitleLevel, TSinchTitleType } from './types';
|
|
2
2
|
export declare const typeValues: readonly TSinchTitleType[];
|
|
3
|
-
export declare const levelValues: readonly TSinchTitleLevel[];
|
|
4
|
-
type TAssertLevel = (value: string | null) => asserts value is TSinchTitleLevel;
|
|
5
|
-
export declare const assertLevel: TAssertLevel;
|
|
6
|
-
type TAssertType = (value: string | null) => asserts value is TSinchTitleType;
|
|
7
|
-
export declare const assertType: TAssertType;
|
|
8
3
|
export declare const getTitleLevelFromType: (type: TSinchTitleType) => TSinchTitleLevel;
|
|
9
|
-
export declare const getTitleTypeFromLevel: (level: TSinchTitleLevel) => TSinchTitleType;
|
|
10
|
-
export {};
|