@nectary/components 0.44.1 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/accordion-item/index.js +1 -1
- package/action-menu/index.js +3 -11
- package/alert/index.js +3 -1
- package/avatar/index.js +12 -13
- package/avatar/types.d.ts +4 -4
- package/avatar/utils.d.ts +1 -4
- package/avatar/utils.js +4 -7
- package/badge/index.js +9 -7
- package/badge/types.d.ts +4 -4
- package/badge/utils.d.ts +1 -4
- package/badge/utils.js +0 -6
- package/button/index.js +88 -23
- package/button/types.d.ts +12 -11
- package/button/utils.d.ts +4 -1
- package/button/utils.js +9 -1
- package/card-container/index.js +1 -1
- package/chat-block/index.js +1 -1
- package/chat-bubble/index.js +1 -1
- package/checkbox/index.js +4 -2
- package/chip/index.js +7 -6
- package/color-menu/index.js +9 -18
- package/color-swatch/index.js +5 -7
- package/date-picker/index.js +1 -1
- package/dialog/index.js +4 -7
- package/emoji/index.js +2 -6
- package/emoji-picker/index.js +6 -14
- package/field/index.js +1 -1
- package/file-status/index.js +4 -2
- package/flag/index.d.ts +11 -0
- package/flag/index.js +43 -0
- package/flag/types.d.ts +11 -0
- package/flag/types.js +1 -0
- package/flag/utils.d.ts +1 -0
- package/flag/utils.js +19 -0
- package/icon/index.js +1 -1
- package/icon-button/index.js +77 -9
- package/icon-button/types.d.ts +14 -6
- package/icon-button/utils.d.ts +5 -0
- package/icon-button/utils.js +9 -0
- package/icons/create-icon-class.js +1 -1
- package/inline-alert/index.js +3 -1
- package/input/index.d.ts +3 -0
- package/input/index.js +148 -71
- package/input/types.d.ts +7 -0
- package/link/index.js +1 -1
- package/package.json +2 -4
- package/pagination/index.js +1 -1
- package/pop/index.js +15 -37
- package/popover/index.js +7 -9
- package/radio-option/index.js +1 -1
- package/segment/index.js +10 -6
- package/segment/types.d.ts +4 -4
- package/segment/utils.d.ts +3 -5
- package/segment/utils.js +14 -4
- package/segment-collapse/index.js +1 -1
- package/segmented-control-option/index.js +1 -1
- package/segmented-icon-control-option/index.js +1 -1
- package/select-button/index.js +93 -28
- package/select-button/types.d.ts +8 -1
- package/select-menu/index.d.ts +5 -0
- package/select-menu/index.js +46 -17
- package/select-menu-option/index.d.ts +1 -0
- package/select-menu-option/index.js +3 -0
- package/select-menu-option/types.d.ts +1 -0
- package/spinner/index.js +52 -7
- package/spinner/types.d.ts +4 -5
- package/stop-events/index.js +9 -5
- package/table/index.js +1 -1
- package/tag/index.js +2 -6
- package/text/index.js +3 -1
- package/textarea/index.js +1 -1
- package/theme/button.css +146 -0
- package/{theme.css → theme/contextual.css} +3 -25
- package/theme/elevation.css +1 -1
- package/theme/flag.css +4 -0
- package/theme/fonts.css +0 -33
- package/theme/fonts.json +0 -33
- package/theme/icon-button.css +68 -0
- package/theme/index.css +4 -0
- package/theme/index.d.ts +21 -0
- package/theme/index.js +21 -0
- package/theme/input.css +7 -0
- package/theme/select-button.css +7 -0
- package/theme/shapes.css +4 -3
- package/theme/size.css +9 -0
- package/theme/spinner.css +7 -0
- package/theme/typography.css +7 -7
- package/tile-control-option/index.js +1 -1
- package/time-picker/index.js +1 -1
- package/title/index.js +7 -3
- package/toast/index.js +3 -1
- package/toggle/index.js +1 -1
- package/tooltip/index.js +8 -6
- package/utils/context.d.ts +14 -9
- package/utils/context.js +60 -26
- package/utils/countries.d.ts +5 -0
- package/utils/countries.js +2 -0
- package/utils/countries.json +998 -0
- package/utils/debounce.d.ts +4 -0
- package/utils/debounce.js +21 -0
- package/utils/element.d.ts +4 -0
- package/utils/element.js +10 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/size.d.ts +10 -0
- package/utils/size.js +19 -0
- package/utils/throttle.d.ts +2 -2
- package/utils/throttle.js +4 -9
- package/spinner/utils.d.ts +0 -2
- package/spinner/utils.js +0 -1
package/icon-button/index.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import '../tooltip';
|
|
2
|
-
import { defineCustomElement, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
3
|
-
|
|
2
|
+
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, getReactEventHandler, isAttrTrue, NectaryElement, subscribeContext, updateAttribute, updateBooleanAttribute, updateLiteralAttribute, Context, getAttribute } from '../utils';
|
|
3
|
+
import { assertSizeEx, DEFAULT_SIZE, sizeExValues } from '../utils/size';
|
|
4
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0;--sinch-size:var(--sinch-size-m);--sinch-size-icon:var(--sinch-icon-button-icon-size-m);--sinch-shape-radius:var(--sinch-shape-radius-m)}#button{all:initial;position:relative;display:flex;align-items:center;justify-content:center;width:var(--sinch-size);height:var(--sinch-size);cursor:pointer;contain:size;--sinch-color-icon:var(--sinch-icon-button-color-icon)}:host([data-size="l"]){--sinch-size:var(--sinch-size-l);--sinch-size-icon:var(--sinch-icon-button-icon-size-l);--sinch-shape-radius:var(--sinch-shape-radius-l)}:host([data-size="m"]){--sinch-size:var(--sinch-size-m);--sinch-size-icon:var(--sinch-icon-button-icon-size-m);--sinch-shape-radius:var(--sinch-shape-radius-m)}:host([data-size="s"]){--sinch-size:var(--sinch-size-s);--sinch-size-icon:var(--sinch-icon-button-icon-size-s);--sinch-shape-radius:var(--sinch-shape-radius-s)}:host([data-size=xs]){--sinch-size:var(--sinch-size-xs);--sinch-size-icon:var(--sinch-icon-button-icon-size-xs);--sinch-shape-radius:var(--sinch-shape-radius-xs)}:host([type=primary]){--sinch-icon-button-color-background:var(--sinch-icon-button-primary-color-background);--sinch-icon-button-color-background-hover:var(--sinch-icon-button-primary-color-background-hover);--sinch-icon-button-color-background-active:var(--sinch-icon-button-primary-color-background-active);--sinch-icon-button-color-background-disabled:var(--sinch-icon-button-primary-color-background-disabled);--sinch-icon-button-color-border:var(--sinch-icon-button-primary-color-border);--sinch-icon-button-color-border-hover:var(--sinch-icon-button-primary-color-border-hover);--sinch-icon-button-color-border-active:var(--sinch-icon-button-primary-color-border-active);--sinch-icon-button-color-border-disabled:var(--sinch-icon-button-primary-color-border-disabled);--sinch-icon-button-color-icon:var(--sinch-icon-button-primary-color-icon);--sinch-icon-button-color-icon-hover:var(--sinch-icon-button-primary-color-icon-hover);--sinch-icon-button-color-icon-active:var(--sinch-icon-button-primary-color-icon-active);--sinch-icon-button-color-icon-disabled:var(--sinch-icon-button-primary-color-icon-disabled);--sinch-icon-button-mix-blend-mode:var(--sinch-icon-button-primary-mix-blend-mode);--sinch-elevation-level:var(--sinch-elevation-level-1)}:host([type=secondary]){--sinch-icon-button-color-background:var(--sinch-icon-button-secondary-color-background);--sinch-icon-button-color-background-hover:var(--sinch-icon-button-secondary-color-background-hover);--sinch-icon-button-color-background-active:var(--sinch-icon-button-secondary-color-background-active);--sinch-icon-button-color-background-disabled:var(--sinch-icon-button-secondary-color-background-disabled);--sinch-icon-button-color-border:var(--sinch-icon-button-secondary-color-border);--sinch-icon-button-color-border-hover:var(--sinch-icon-button-secondary-color-border-hover);--sinch-icon-button-color-border-active:var(--sinch-icon-button-secondary-color-border-active);--sinch-icon-button-color-border-disabled:var(--sinch-icon-button-secondary-color-border-disabled);--sinch-icon-button-color-icon:var(--sinch-icon-button-secondary-color-icon);--sinch-icon-button-color-icon-hover:var(--sinch-icon-button-secondary-color-icon-hover);--sinch-icon-button-color-icon-active:var(--sinch-icon-button-secondary-color-icon-active);--sinch-icon-button-color-icon-disabled:var(--sinch-icon-button-secondary-color-icon-disabled);--sinch-icon-button-mix-blend-mode:var(--sinch-icon-button-secondary-mix-blend-mode);--sinch-elevation-level:var(--sinch-elevation-level-1)}:host([type=tertiary]){--sinch-icon-button-color-background:var(--sinch-icon-button-tertiary-color-background);--sinch-icon-button-color-background-hover:var(--sinch-icon-button-tertiary-color-background-hover);--sinch-icon-button-color-background-active:var(--sinch-icon-button-tertiary-color-background-active);--sinch-icon-button-color-background-disabled:var(--sinch-icon-button-tertiary-color-background-disabled);--sinch-icon-button-color-border:var(--sinch-icon-button-tertiary-color-border);--sinch-icon-button-color-border-hover:var(--sinch-icon-button-tertiary-color-border-hover);--sinch-icon-button-color-border-active:var(--sinch-icon-button-tertiary-color-border-active);--sinch-icon-button-color-border-disabled:var(--sinch-icon-button-tertiary-color-border-disabled);--sinch-icon-button-color-icon:var(--sinch-icon-button-tertiary-color-icon);--sinch-icon-button-color-icon-hover:var(--sinch-icon-button-tertiary-color-icon-hover);--sinch-icon-button-color-icon-active:var(--sinch-icon-button-tertiary-color-icon-active);--sinch-icon-button-color-icon-disabled:var(--sinch-icon-button-tertiary-color-icon-disabled);--sinch-icon-button-mix-blend-mode:var(--sinch-icon-button-tertiary-mix-blend-mode);--sinch-elevation-level:var(--sinch-elevation-level-0)}#button::before{content:"";position:absolute;inset:0;border-radius:var(--sinch-shape-radius);border:1px solid var(--sinch-icon-button-color-border);background-color:var(--sinch-icon-button-color-background);box-shadow:var(--sinch-elevation-level);pointer-events:none;mix-blend-mode:var(--sinch-icon-button-mix-blend-mode)}#button:focus-visible::after{content:"";position:absolute;inset:-3px;border:2px solid var(--sinch-color-border-focus);border-radius:calc(var(--sinch-shape-radius) + 3px);pointer-events:none}#button:disabled{cursor:initial;--sinch-color-icon:var(--sinch-icon-button-color-icon-disabled)}#button:disabled::before{background-color:var(--sinch-icon-button-color-background-disabled);border-color:var(--sinch-icon-button-color-border-disabled);box-shadow:var(--sinch-elevation-level-0)}#button:enabled:hover{--sinch-color-icon:var(--sinch-icon-button-color-icon-hover)}#button:enabled:hover::before{background-color:var(--sinch-icon-button-color-background-hover);border-color:var(--sinch-icon-button-color-border-hover)}#button:enabled:active{--sinch-color-icon:var(--sinch-icon-button-color-icon-active)}#button:enabled:active::before{background-color:var(--sinch-icon-button-color-background-active);border-color:var(--sinch-icon-button-color-border-active);box-shadow:var(--sinch-elevation-level-0)}#content{position:relative;display:flex;align-items:center;justify-content:center;width:100%;height:100%}#button *{pointer-events:none}</style><sinch-tooltip id="tooltip" inverted><button id="button"><div id="content"><slot name="icon"></slot></div></button></sinch-tooltip>';
|
|
5
|
+
import { assertType, typeValues } from './utils';
|
|
4
6
|
const template = document.createElement('template');
|
|
5
7
|
template.innerHTML = templateHTML;
|
|
6
8
|
defineCustomElement('sinch-icon-button', class extends NectaryElement {
|
|
7
9
|
#$button;
|
|
8
10
|
#$tooltip;
|
|
9
11
|
#controller = null;
|
|
12
|
+
#sizeContext;
|
|
10
13
|
constructor() {
|
|
11
14
|
super();
|
|
12
|
-
const shadowRoot = this.attachShadow(
|
|
15
|
+
const shadowRoot = this.attachShadow({
|
|
16
|
+
delegatesFocus: true
|
|
17
|
+
});
|
|
13
18
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
14
19
|
this.#$button = shadowRoot.querySelector('#button');
|
|
15
20
|
this.#$tooltip = shadowRoot.querySelector('#tooltip');
|
|
21
|
+
this.#sizeContext = new Context(this.#$button, 'size');
|
|
16
22
|
}
|
|
17
23
|
connectedCallback() {
|
|
24
|
+
super.connectedCallback();
|
|
18
25
|
this.#controller = new AbortController();
|
|
19
26
|
const options = {
|
|
20
27
|
signal: this.#controller.signal
|
|
@@ -26,14 +33,21 @@ defineCustomElement('sinch-icon-button', class extends NectaryElement {
|
|
|
26
33
|
this.addEventListener('-click', this.#onClickReactHandler, options);
|
|
27
34
|
this.addEventListener('-focus', this.#onFocusReactHandler, options);
|
|
28
35
|
this.addEventListener('-blur', this.#onBlurReactHandler, options);
|
|
36
|
+
subscribeContext(this, 'size', this.#onContextSize, this.#controller.signal);
|
|
37
|
+
this.#sizeContext.listen(this.#controller.signal);
|
|
38
|
+
this.#onSizeUpdate();
|
|
29
39
|
}
|
|
30
40
|
disconnectedCallback() {
|
|
41
|
+
super.disconnectedCallback();
|
|
31
42
|
this.#controller.abort();
|
|
32
43
|
}
|
|
33
44
|
static get observedAttributes() {
|
|
34
|
-
return ['disabled', 'aria-label'];
|
|
45
|
+
return ['type', 'size', 'disabled', 'aria-label', 'data-size'];
|
|
35
46
|
}
|
|
36
|
-
attributeChangedCallback(name,
|
|
47
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
48
|
+
if (oldVal === newVal) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
37
51
|
switch (name) {
|
|
38
52
|
case 'disabled':
|
|
39
53
|
{
|
|
@@ -47,19 +61,45 @@ defineCustomElement('sinch-icon-button', class extends NectaryElement {
|
|
|
47
61
|
updateAttribute(this.#$tooltip, 'text', newVal);
|
|
48
62
|
break;
|
|
49
63
|
}
|
|
64
|
+
case 'type':
|
|
65
|
+
{
|
|
66
|
+
if ('production' !== 'production') {
|
|
67
|
+
assertType(newVal);
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case 'size':
|
|
72
|
+
{
|
|
73
|
+
updateAttribute(this, 'data-size', newVal);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case 'data-size':
|
|
77
|
+
{
|
|
78
|
+
if ('production' !== 'production') {
|
|
79
|
+
assertSizeEx(newVal, 'sinch-icon-button');
|
|
80
|
+
}
|
|
81
|
+
this.#onSizeUpdate();
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
50
84
|
}
|
|
51
85
|
}
|
|
86
|
+
set type(value) {
|
|
87
|
+
updateLiteralAttribute(this, typeValues, 'type', value);
|
|
88
|
+
}
|
|
89
|
+
get type() {
|
|
90
|
+
return getLiteralAttribute(this, typeValues, 'type', 'tertiary');
|
|
91
|
+
}
|
|
52
92
|
set disabled(isDisabled) {
|
|
53
93
|
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
54
94
|
}
|
|
55
95
|
get disabled() {
|
|
56
96
|
return getBooleanAttribute(this, 'disabled');
|
|
57
97
|
}
|
|
58
|
-
set
|
|
59
|
-
|
|
98
|
+
set size(size) {
|
|
99
|
+
updateLiteralAttribute(this, sizeExValues, 'size', size);
|
|
60
100
|
}
|
|
61
|
-
get
|
|
62
|
-
return
|
|
101
|
+
get size() {
|
|
102
|
+
return getLiteralAttribute(this, sizeExValues, 'size', DEFAULT_SIZE);
|
|
63
103
|
}
|
|
64
104
|
get tooltipRect() {
|
|
65
105
|
return this.#$tooltip.tooltipRect;
|
|
@@ -73,6 +113,34 @@ defineCustomElement('sinch-icon-button', class extends NectaryElement {
|
|
|
73
113
|
blur() {
|
|
74
114
|
this.#$button.blur();
|
|
75
115
|
}
|
|
116
|
+
#onSizeUpdate() {
|
|
117
|
+
if (!this.isConnected) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const size = getAttribute(this, 'data-size', DEFAULT_SIZE);
|
|
121
|
+
this.#sizeContext.dispatch(size);
|
|
122
|
+
}
|
|
123
|
+
#onContextSize = e => {
|
|
124
|
+
if (this.hasAttribute('size')) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
switch (e.detail) {
|
|
128
|
+
case 'l':
|
|
129
|
+
{
|
|
130
|
+
this.setAttribute('data-size', 'm');
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
case 'm':
|
|
134
|
+
{
|
|
135
|
+
this.setAttribute('data-size', 's');
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
default:
|
|
139
|
+
{
|
|
140
|
+
this.setAttribute('data-size', 'xs');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
76
144
|
#onButtonClick = () => {
|
|
77
145
|
this.dispatchEvent(new CustomEvent('-click'));
|
|
78
146
|
};
|
package/icon-button/types.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { TRect, TSinchElementReact } from '../types';
|
|
2
|
+
import type { TSinchSizeEx } from '../utils/size';
|
|
3
|
+
export declare type TSinchIconButtonType = 'primary' | 'secondary' | 'tertiary';
|
|
2
4
|
export declare type TSinchIconButtonElement = HTMLElement & {
|
|
5
|
+
/** Type, `tertiary` by default */
|
|
6
|
+
type: TSinchIconButtonType;
|
|
7
|
+
/** Size, `m` by default */
|
|
8
|
+
size: TSinchSizeEx;
|
|
3
9
|
/** Disabled */
|
|
4
10
|
disabled: boolean;
|
|
5
|
-
/** Small */
|
|
6
|
-
small: boolean;
|
|
7
11
|
readonly tooltipRect: TRect;
|
|
8
12
|
/** Click event */
|
|
9
13
|
addEventListener(type: '-click', listener: (e: CustomEvent<void>) => void): void;
|
|
@@ -11,16 +15,20 @@ export declare type TSinchIconButtonElement = HTMLElement & {
|
|
|
11
15
|
addEventListener(type: '-focus', listener: (e: CustomEvent<void>) => void): void;
|
|
12
16
|
/** Blur event */
|
|
13
17
|
addEventListener(type: '-blur', listener: (e: CustomEvent<void>) => void): void;
|
|
18
|
+
/** Type, `tertiary` by default */
|
|
19
|
+
setAttribute(name: 'type', value: string): void;
|
|
20
|
+
/** Size, `m` by default */
|
|
21
|
+
setAttribute(name: 'size', value: string): void;
|
|
14
22
|
/** Disabled */
|
|
15
23
|
setAttribute(name: 'disabled', value: ''): void;
|
|
16
|
-
/** Small */
|
|
17
|
-
setAttribute(name: 'small', value: ''): void;
|
|
18
24
|
};
|
|
19
25
|
export declare type TSinchIconButtonReact = TSinchElementReact<TSinchIconButtonElement> & {
|
|
26
|
+
/** Type, `tertiary` by default */
|
|
27
|
+
type?: TSinchIconButtonType;
|
|
28
|
+
/** Size, `m` by default */
|
|
29
|
+
size?: TSinchSizeEx;
|
|
20
30
|
/** Disabled */
|
|
21
31
|
disabled?: boolean;
|
|
22
|
-
/** Small */
|
|
23
|
-
small?: boolean;
|
|
24
32
|
/** Label that is used for a11y */
|
|
25
33
|
'aria-label': string;
|
|
26
34
|
/** Click event handler */
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TSinchIconButtonType } from './types';
|
|
2
|
+
export declare const typeValues: readonly TSinchIconButtonType[];
|
|
3
|
+
declare type TAssertType = (value: string | null) => asserts value is TSinchIconButtonType;
|
|
4
|
+
export declare const assertType: TAssertType;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const typeValues = ['primary', 'secondary', 'tertiary'];
|
|
2
|
+
export const assertType = value => {
|
|
3
|
+
if (value === null || value.length === 0) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
if (!typeValues.includes(value)) {
|
|
7
|
+
throw new Error(`sinch-icon-button: invalid type attribute: ${value}`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NectaryElement, updateAttribute } from '../utils';
|
|
2
|
-
const iconStylesHtml = '<style>:host{display:inline-block;vertical-align:middle}svg{display:block;pointer-events:none;fill:var(--sinch-color-icon
|
|
2
|
+
const iconStylesHtml = '<style>:host{display:inline-block;vertical-align:middle}svg{display:block;pointer-events:none;fill:var(--sinch-color-icon,var(--sinch-color-stormy-500));height:var(--sinch-size-icon,24px)}</style>';
|
|
3
3
|
export const createIconClass = templateHTML => {
|
|
4
4
|
const template = document.createElement('template');
|
|
5
5
|
template.innerHTML = iconStylesHtml + templateHTML;
|
package/inline-alert/index.js
CHANGED
package/input/index.d.ts
CHANGED
package/input/index.js
CHANGED
|
@@ -1,57 +1,132 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import '../icon-button';
|
|
2
|
+
import '../icons/close';
|
|
3
|
+
import '../stop-events';
|
|
4
|
+
import { Context, defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getReactEventHandler, isAttrTrue, NectaryElement, setClass, subscribeContext, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute, updateLiteralAttribute } from '../utils';
|
|
5
|
+
import { assertSize, DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
6
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}:host([data-size="l"]){--sinch-size:var(--sinch-size-l);--sinch-size-icon:var(--sinch-input-icon-size-l);--sinch-shape-radius:var(--sinch-shape-radius-l)}:host([data-size="m"]){--sinch-size:var(--sinch-size-m);--sinch-size-icon:var(--sinch-input-icon-size-m);--sinch-shape-radius:var(--sinch-shape-radius-m)}:host([data-size="s"]){--sinch-size:var(--sinch-size-s);--sinch-size-icon:var(--sinch-input-icon-size-s);--sinch-shape-radius:var(--sinch-shape-radius-s)}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;box-sizing:border-box;border-radius:var(--sinch-shape-radius);width:100%;height:var(--sinch-size);background-color:var(--sinch-color-bg-primary-light)}#input{all:initial;flex:1;min-width:0;height:100%;padding:0 12px 0 40px;font:var(--sinch-font-text-m);color:var(--sinch-color-text-default)}:host([data-size="s"]) #input{padding-left:32px}#input::placeholder{font:var(--sinch-font-text-m);color:var(--sinch-color-text-muted);opacity:1}#border{position:absolute;border:1px solid var(--sinch-color-border-dark);border-radius:var(--sinch-shape-radius);inset:0;pointer-events:none}:host([invalid]:not([invalid=false]):not([disabled])) #border{border-color:var(--sinch-color-text-invalid)}#input:disabled{color:var(--sinch-color-text-disabled)}#input:disabled::placeholder{color:var(--sinch-color-text-disabled)}#input:disabled+#border{border-color:var(--sinch-color-border-disabled)}#input:focus+#border{border-color:var(--sinch-color-border-focus);border-width:2px}#input[type=password]{font-size:1.5em;letter-spacing:.1em}#icon-wrapper{position:relative;height:100%}#icon{position:absolute;display:flex;align-items:center;left:10px;top:0;bottom:0;pointer-events:none;--sinch-color-icon:var(--sinch-color-stormy-500)}:host([disabled]:not([disabled=false])) #icon{--sinch-color-icon:var(--sinch-color-border-disabled)}#icon-wrapper.empty{display:none}#icon-wrapper.empty~#input{padding-left:12px}#clear{display:none;--sinch-icon-button-color-icon:var(--sinch-color-text-muted)}#clear.active{display:block}:host([disabled]:not([disabled=false])) #clear{display:none}#wrapper:focus-within #clear{--sinch-icon-button-color-icon:var(--sinch-color-stormy-500)}#right{display:flex;flex-direction:row;align-self:stretch;align-items:center;gap:4px;padding-right:4px}#right.empty{display:none}#left{display:flex;flex-direction:row;align-self:stretch;align-items:center;gap:4px;padding-left:4px}#left.empty{display:none}</style><div id="wrapper"><div id="left"><slot name="left"></slot></div><div id="icon-wrapper"><div id="icon"><slot name="icon"></slot></div></div><input id="input" type="text"/><div id="border"></div><div id="right"><sinch-stop-events events="keydown"><sinch-icon-button id="clear" aria-label="Clear input value"><sinch-icon-close slot="icon"></sinch-icon-close></sinch-icon-button></sinch-stop-events><slot name="right"></slot></div></div>';
|
|
3
7
|
import { inputTypes } from './utils';
|
|
4
8
|
const template = document.createElement('template');
|
|
5
9
|
template.innerHTML = templateHTML;
|
|
6
10
|
defineCustomElement('sinch-input', class extends NectaryElement {
|
|
7
11
|
#$input;
|
|
12
|
+
#$clear;
|
|
8
13
|
#$iconSlot;
|
|
9
14
|
#$iconWrapper;
|
|
10
15
|
#$rightSlot;
|
|
11
16
|
#$rightWrapper;
|
|
17
|
+
#$leftSlot;
|
|
18
|
+
#$leftWrapper;
|
|
19
|
+
#$wrapper;
|
|
12
20
|
#cursorPos = null;
|
|
13
21
|
#isPendingDk = false;
|
|
22
|
+
#controller = null;
|
|
23
|
+
#sizeContext;
|
|
14
24
|
constructor() {
|
|
15
25
|
super();
|
|
16
|
-
const shadowRoot = this.attachShadow(
|
|
26
|
+
const shadowRoot = this.attachShadow({
|
|
27
|
+
delegatesFocus: true
|
|
28
|
+
});
|
|
17
29
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
18
30
|
this.#$input = shadowRoot.querySelector('#input');
|
|
19
31
|
this.#$iconSlot = shadowRoot.querySelector('slot[name="icon"]');
|
|
20
|
-
this.#$iconWrapper = shadowRoot.querySelector('#icon');
|
|
32
|
+
this.#$iconWrapper = shadowRoot.querySelector('#icon-wrapper');
|
|
21
33
|
this.#$rightSlot = shadowRoot.querySelector('slot[name="right"]');
|
|
22
34
|
this.#$rightWrapper = shadowRoot.querySelector('#right');
|
|
35
|
+
this.#$leftSlot = shadowRoot.querySelector('slot[name="left"]');
|
|
36
|
+
this.#$leftWrapper = shadowRoot.querySelector('#left');
|
|
37
|
+
this.#$clear = shadowRoot.querySelector('#clear');
|
|
38
|
+
this.#$wrapper = shadowRoot.querySelector('#wrapper');
|
|
39
|
+
this.#sizeContext = new Context(this.#$wrapper, 'size');
|
|
23
40
|
}
|
|
24
41
|
connectedCallback() {
|
|
42
|
+
super.connectedCallback();
|
|
25
43
|
this.setAttribute('role', 'textbox');
|
|
26
|
-
this
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.#$input.addEventListener('
|
|
31
|
-
this.#$input.addEventListener('
|
|
32
|
-
this.#$
|
|
33
|
-
this.#$
|
|
34
|
-
this.addEventListener('
|
|
35
|
-
this.addEventListener('
|
|
36
|
-
this.addEventListener('
|
|
44
|
+
this.#controller = new AbortController();
|
|
45
|
+
const options = {
|
|
46
|
+
signal: this.#controller.signal
|
|
47
|
+
};
|
|
48
|
+
this.#$input.addEventListener('input', this.#onInput, options);
|
|
49
|
+
this.#$input.addEventListener('compositionstart', this.#onCompositionStart, options);
|
|
50
|
+
this.#$input.addEventListener('mousedown', this.#onSelectionChange, options);
|
|
51
|
+
this.#$input.addEventListener('keydown', this.#onSelectionChange, options);
|
|
52
|
+
this.#$input.addEventListener('focus', this.#onInputFocus, options);
|
|
53
|
+
this.#$input.addEventListener('blur', this.#onInputBlur, options);
|
|
54
|
+
this.#$clear.addEventListener('click', this.#onClear, options);
|
|
55
|
+
this.#$iconSlot.addEventListener('slotchange', this.#onIconSlotChange, options);
|
|
56
|
+
this.#$leftSlot.addEventListener('slotchange', this.#onLeftSlotChange, options);
|
|
57
|
+
this.#$rightSlot.addEventListener('slotchange', this.#onRightSlotChange, options);
|
|
58
|
+
this.addEventListener('-change', this.#onChangeReactHandler, options);
|
|
59
|
+
this.addEventListener('-focus', this.#onFocusReactHandler, options);
|
|
60
|
+
this.addEventListener('-blur', this.#onBlurReactHandler, options);
|
|
61
|
+
this.#sizeContext.listen(this.#controller.signal);
|
|
62
|
+
subscribeContext(this, 'size', this.#onContextSize, this.#controller.signal);
|
|
37
63
|
this.#onIconSlotChange();
|
|
64
|
+
this.#onLeftSlotChange();
|
|
38
65
|
this.#onRightSlotChange();
|
|
66
|
+
this.#onSizeUpdate();
|
|
39
67
|
}
|
|
40
68
|
disconnectedCallback() {
|
|
41
|
-
|
|
42
|
-
this
|
|
43
|
-
this.#$input.removeEventListener('mousedown', this.#onSelectionChange);
|
|
44
|
-
this.#$input.removeEventListener('keydown', this.#onSelectionChange);
|
|
45
|
-
this.#$input.removeEventListener('focus', this.#onInputFocus);
|
|
46
|
-
this.#$input.removeEventListener('blur', this.#onInputBlur);
|
|
47
|
-
this.#$iconSlot.removeEventListener('slotchange', this.#onIconSlotChange);
|
|
48
|
-
this.#$rightSlot.removeEventListener('slotchange', this.#onRightSlotChange);
|
|
49
|
-
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
50
|
-
this.removeEventListener('-focus', this.#onFocusReactHandler);
|
|
51
|
-
this.removeEventListener('-blur', this.#onBlurReactHandler);
|
|
69
|
+
super.disconnectedCallback();
|
|
70
|
+
this.#controller.abort();
|
|
52
71
|
}
|
|
53
72
|
static get observedAttributes() {
|
|
54
|
-
return ['type', 'value', 'placeholder', 'invalid', 'disabled'];
|
|
73
|
+
return ['type', 'value', 'placeholder', 'invalid', 'disabled', 'size', 'data-size'];
|
|
74
|
+
}
|
|
75
|
+
attributeChangedCallback(name, _, newVal) {
|
|
76
|
+
switch (name) {
|
|
77
|
+
case 'type':
|
|
78
|
+
{
|
|
79
|
+
updateLiteralAttribute(this.#$input, inputTypes, 'type', newVal);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case 'value':
|
|
83
|
+
{
|
|
84
|
+
const nextVal = newVal ?? '';
|
|
85
|
+
const prevVal = this.#$input.value;
|
|
86
|
+
if (nextVal !== prevVal) {
|
|
87
|
+
const prevCursorPos = this.#$input.selectionEnd;
|
|
88
|
+
const isPrevCursorEnd = prevCursorPos === prevVal.length;
|
|
89
|
+
this.#$input.value = nextVal;
|
|
90
|
+
if (!isPrevCursorEnd) {
|
|
91
|
+
this.#$input.setSelectionRange(this.#cursorPos, this.#cursorPos);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
setClass(this.#$clear, 'active', nextVal.length > 0);
|
|
95
|
+
this.#onRightSlotChange();
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case 'placeholder':
|
|
99
|
+
{
|
|
100
|
+
this.#$input.placeholder = newVal ?? '';
|
|
101
|
+
updateAttribute(this, 'aria-placeholder', newVal);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case 'invalid':
|
|
105
|
+
{
|
|
106
|
+
updateExplicitBooleanAttribute(this, 'aria-invalid', isAttrTrue(newVal));
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'disabled':
|
|
110
|
+
{
|
|
111
|
+
const isDisabled = isAttrTrue(newVal);
|
|
112
|
+
this.#$input.disabled = isDisabled;
|
|
113
|
+
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case 'size':
|
|
117
|
+
{
|
|
118
|
+
updateAttribute(this, 'data-size', newVal);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
case 'data-size':
|
|
122
|
+
{
|
|
123
|
+
if ('production' !== 'production') {
|
|
124
|
+
assertSize(newVal, 'sinch-input');
|
|
125
|
+
}
|
|
126
|
+
this.#onSizeUpdate();
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
55
130
|
}
|
|
56
131
|
get nodeName() {
|
|
57
132
|
return 'input';
|
|
@@ -86,6 +161,12 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
86
161
|
get disabled() {
|
|
87
162
|
return getBooleanAttribute(this, 'disabled');
|
|
88
163
|
}
|
|
164
|
+
set size(size) {
|
|
165
|
+
updateLiteralAttribute(this, sizeValues, 'size', size);
|
|
166
|
+
}
|
|
167
|
+
get size() {
|
|
168
|
+
return getLiteralAttribute(this, sizeValues, 'size', DEFAULT_SIZE);
|
|
169
|
+
}
|
|
89
170
|
get selectionStart() {
|
|
90
171
|
return this.#$input.selectionStart;
|
|
91
172
|
}
|
|
@@ -104,47 +185,6 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
104
185
|
set selectionDirection(value) {
|
|
105
186
|
this.#$input.selectionDirection = value;
|
|
106
187
|
}
|
|
107
|
-
attributeChangedCallback(name, _, newVal) {
|
|
108
|
-
switch (name) {
|
|
109
|
-
case 'type':
|
|
110
|
-
{
|
|
111
|
-
updateLiteralAttribute(this.#$input, inputTypes, 'type', newVal);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
case 'value':
|
|
115
|
-
{
|
|
116
|
-
const nextVal = newVal ?? '';
|
|
117
|
-
const prevVal = this.#$input.value;
|
|
118
|
-
if (nextVal !== prevVal) {
|
|
119
|
-
const prevCursorPos = this.#$input.selectionEnd;
|
|
120
|
-
const isPrevCursorEnd = prevCursorPos === prevVal.length;
|
|
121
|
-
this.#$input.value = nextVal;
|
|
122
|
-
if (!isPrevCursorEnd) {
|
|
123
|
-
this.#$input.setSelectionRange(this.#cursorPos, this.#cursorPos);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
case 'placeholder':
|
|
129
|
-
{
|
|
130
|
-
this.#$input.placeholder = newVal ?? '';
|
|
131
|
-
updateAttribute(this, 'aria-placeholder', newVal);
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
case 'invalid':
|
|
135
|
-
{
|
|
136
|
-
updateExplicitBooleanAttribute(this, 'aria-invalid', isAttrTrue(newVal));
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
case 'disabled':
|
|
140
|
-
{
|
|
141
|
-
const isDisabled = isAttrTrue(newVal);
|
|
142
|
-
this.#$input.disabled = isDisabled;
|
|
143
|
-
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
188
|
get focusable() {
|
|
149
189
|
return true;
|
|
150
190
|
}
|
|
@@ -162,6 +202,25 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
162
202
|
};
|
|
163
203
|
#onInput = e => {
|
|
164
204
|
e.stopPropagation();
|
|
205
|
+
this.#handleInput();
|
|
206
|
+
};
|
|
207
|
+
#onContextSize = e => {
|
|
208
|
+
if (this.hasAttribute('size')) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
switch (e.detail) {
|
|
212
|
+
case 'l':
|
|
213
|
+
{
|
|
214
|
+
this.setAttribute('data-size', 'm');
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
default:
|
|
218
|
+
{
|
|
219
|
+
this.setAttribute('data-size', 's');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
#handleInput() {
|
|
165
224
|
const nextValue = this.#$input.value;
|
|
166
225
|
const prevValue = this.value;
|
|
167
226
|
if (prevValue !== nextValue) {
|
|
@@ -184,12 +243,18 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
184
243
|
detail: nextValue
|
|
185
244
|
}));
|
|
186
245
|
}
|
|
187
|
-
}
|
|
246
|
+
}
|
|
188
247
|
#onIconSlotChange = () => {
|
|
189
|
-
|
|
248
|
+
const isEmpty = this.#$iconSlot.assignedElements().length === 0;
|
|
249
|
+
setClass(this.#$iconWrapper, 'empty', isEmpty);
|
|
250
|
+
};
|
|
251
|
+
#onLeftSlotChange = () => {
|
|
252
|
+
const isEmpty = this.#$leftSlot.assignedElements().length === 0;
|
|
253
|
+
setClass(this.#$leftWrapper, 'empty', isEmpty);
|
|
190
254
|
};
|
|
191
255
|
#onRightSlotChange = () => {
|
|
192
|
-
|
|
256
|
+
const isEmpty = this.#$rightSlot.assignedElements().length === 0 && this.value.length === 0;
|
|
257
|
+
setClass(this.#$rightWrapper, 'empty', isEmpty);
|
|
193
258
|
};
|
|
194
259
|
#onInputFocus = () => {
|
|
195
260
|
this.dispatchEvent(new CustomEvent('-focus'));
|
|
@@ -197,6 +262,18 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
197
262
|
#onInputBlur = () => {
|
|
198
263
|
this.dispatchEvent(new CustomEvent('-blur'));
|
|
199
264
|
};
|
|
265
|
+
#onClear = () => {
|
|
266
|
+
this.#$input.value = '';
|
|
267
|
+
this.#$input.focus();
|
|
268
|
+
this.#handleInput();
|
|
269
|
+
};
|
|
270
|
+
#onSizeUpdate() {
|
|
271
|
+
if (!this.isConnected) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const size = this.getAttribute('data-size') ?? DEFAULT_SIZE;
|
|
275
|
+
this.#sizeContext.dispatch(size);
|
|
276
|
+
}
|
|
200
277
|
#onChangeReactHandler = e => {
|
|
201
278
|
getReactEventHandler(this, 'on-change')?.(e);
|
|
202
279
|
};
|
package/input/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TSinchElementReact } from '../types';
|
|
2
|
+
import type { TSinchSize } from '../utils/size';
|
|
2
3
|
import type { SyntheticEvent } from 'react';
|
|
3
4
|
export declare type TSinchInputType = 'text' | 'password';
|
|
4
5
|
export declare type TSinchInputElement = HTMLElement & {
|
|
@@ -12,6 +13,8 @@ export declare type TSinchInputElement = HTMLElement & {
|
|
|
12
13
|
invalid: boolean;
|
|
13
14
|
/** Disabled */
|
|
14
15
|
disabled: boolean;
|
|
16
|
+
/** Size, `m` by default */
|
|
17
|
+
size: TSinchSize;
|
|
15
18
|
selectionStart: number | null;
|
|
16
19
|
selectionEnd: number | null;
|
|
17
20
|
selectionDirection: 'forward' | 'backward' | 'none' | null;
|
|
@@ -31,6 +34,8 @@ export declare type TSinchInputElement = HTMLElement & {
|
|
|
31
34
|
setAttribute(name: 'invalid', value: ''): void;
|
|
32
35
|
/** Disabled */
|
|
33
36
|
setAttribute(name: 'disabled', value: ''): void;
|
|
37
|
+
/** Size, `m` by default */
|
|
38
|
+
setAttribute(name: 'size', value: TSinchSize): void;
|
|
34
39
|
};
|
|
35
40
|
export declare type TSinchInputReact = TSinchElementReact<TSinchInputElement> & {
|
|
36
41
|
/** Controlled value, doesn't change on its own and requres an onChange-value state loop */
|
|
@@ -45,6 +50,8 @@ export declare type TSinchInputReact = TSinchElementReact<TSinchInputElement> &
|
|
|
45
50
|
invalid?: boolean;
|
|
46
51
|
/** Disabled */
|
|
47
52
|
disabled?: boolean;
|
|
53
|
+
/** Size, `m` by default */
|
|
54
|
+
size?: TSinchSize;
|
|
48
55
|
/** @deprecated Change value handler */
|
|
49
56
|
onChange?: (e: SyntheticEvent<TSinchInputElement, CustomEvent<string>>) => void;
|
|
50
57
|
/** Change value handler */
|
package/link/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../icons/open-in-new';
|
|
2
2
|
import '../icons/arrow-forward';
|
|
3
3
|
import { defineCustomElement, getBooleanAttribute, getAttribute, updateBooleanAttribute, updateAttribute, NectaryElement, isAttrTrue, getReactEventHandler } from '../utils';
|
|
4
|
-
const templateHTML = '<style>:host{display:inline}a{font:var(--sinch-font-text-m);font-size:inherit;line-height:inherit;color:var(--sinch-color-tropical-500);border-radius:.5em;--sinch-size-icon:1em;--sinch-color-icon:var(--sinch-color-tropical-500)}a:hover{color:var(--sinch-color-tropical-600);--sinch-color-icon:var(--sinch-color-tropical-600)}a:focus-visible{outline:2px solid var(--sinch-color-border-focus);outline-offset:2px}
|
|
4
|
+
const templateHTML = '<style>:host{display:inline}a{font:var(--sinch-font-text-m);font-size:inherit;line-height:inherit;color:var(--sinch-color-tropical-500);border-radius:.5em;--sinch-size-icon:1em;--sinch-color-icon:var(--sinch-color-tropical-500)}a:hover{color:var(--sinch-color-tropical-600);--sinch-color-icon:var(--sinch-color-tropical-600)}a:focus-visible{outline:2px solid var(--sinch-color-border-focus);outline-offset:2px}#external-icon{display:none;margin-right:.2em;vertical-align:-.2em}#standalone-icon{display:none}:host([external]:not([external=false])) #external-icon{display:inline-block}:host([standalone]:not([standalone=false])){display:block}:host([standalone]:not([standalone=false])) a{display:block;font:var(--sinch-font-text-m);font-weight:var(--sinch-font-weight-emphasized);text-decoration:none;border-radius:var(--sinch-shape-radius-m);width:fit-content;--sinch-size-icon:24px}:host([standalone]:not([standalone=false])) #external-icon{margin-right:8px;vertical-align:-7px}:host([standalone]:not([standalone=false]):is([external=false],:not([external]))) #standalone-icon{display:inline-block;vertical-align:-7px;margin-left:8px}:host([disabled]:not([disabled=false])) a{color:var(--sinch-color-tropical-200);pointer-events:none;cursor:initial;--sinch-color-icon:var(--sinch-color-tropical-200)}</style><a referrerpolicy="no-referer" aria-hidden="true"><sinch-icon-open-in-new id="external-icon"></sinch-icon-open-in-new><span id="content"></span><sinch-icon-arrow-forward id="standalone-icon"></sinch-icon-arrow-forward></a>';
|
|
5
5
|
const template = document.createElement('template');
|
|
6
6
|
template.innerHTML = templateHTML;
|
|
7
7
|
defineCustomElement('sinch-link', class extends NectaryElement {
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nectary/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"**/*/*.css",
|
|
6
6
|
"**/*/*.json",
|
|
7
7
|
"**/*/*.js",
|
|
8
8
|
"**/*/*.d.ts",
|
|
9
|
-
"theme.css",
|
|
10
9
|
"types.d.ts",
|
|
11
10
|
"colors.json"
|
|
12
11
|
],
|
|
@@ -14,8 +13,7 @@
|
|
|
14
13
|
"build": "NODE_ENV=production babel . --extensions '.ts' --out-dir . && tsc --declaration --emitDeclarationOnly"
|
|
15
14
|
},
|
|
16
15
|
"dependencies": {
|
|
17
|
-
"@babel/runtime": "^7.19.0"
|
|
18
|
-
"dialog-polyfill": "^0.5.6"
|
|
16
|
+
"@babel/runtime": "^7.19.0"
|
|
19
17
|
},
|
|
20
18
|
"devDependencies": {
|
|
21
19
|
"@babel/cli": "^7.19.3",
|
package/pagination/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../icons/keyboard-arrow-left';
|
|
2
2
|
import '../icons/keyboard-arrow-right';
|
|
3
3
|
import { defineCustomElement, updateAttribute, getIntegerAttribute, setClass, NectaryElement, getRect, getReactEventHandler } from '../utils';
|
|
4
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;justify-content:center;gap:8px;width:100%;box-sizing:border-box}button{all:initial;width:28px;height:28px;box-sizing:border-box;cursor:pointer;text-align:center;contain:strict;--sinch-color-icon:var(--sinch-color-stormy-500)}button:disabled{--sinch-color-icon:var(--sinch-color-stormy-100);cursor:initial}button>*{pointer-events:none}.page{border-radius:50%;font:var(--sinch-font-
|
|
4
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;justify-content:center;gap:8px;width:100%;box-sizing:border-box}button{all:initial;width:28px;height:28px;box-sizing:border-box;cursor:pointer;text-align:center;contain:strict;--sinch-color-icon:var(--sinch-color-stormy-500)}button:disabled{--sinch-color-icon:var(--sinch-color-stormy-100);cursor:initial}button>*{pointer-events:none}.page{border-radius:50%;font:var(--sinch-font-text-m);color:var(--sinch-color-stormy-500)}.page.dots>span{display:none}.page.dots::after{content:"..."}.page.active{font-weight:var(--sinch-font-weight-emphasized);background-color:var(--sinch-color-snow-600);pointer-events:none;cursor:initial}.page.hidden{display:none}#left,#right{display:flex;padding:2px;--sinch-icon-size:24px}</style><div id="wrapper"><button id="left"><sinch-icon-keyboard-arrow-left></sinch-icon-keyboard-arrow-left></button><button class="page"><span>1</span></button><button class="page active"><span>2</span></button><button class="page"><span>3</span></button><button class="page"><span>4</span></button><button class="page"><span>5</span></button><button class="page dots"><span>6</span></button><button class="page"><span>20</span></button><button id="right"><sinch-icon-keyboard-arrow-right></sinch-icon-keyboard-arrow-right></button></div>';
|
|
5
5
|
const NUM_BUTTONS = 7;
|
|
6
6
|
const MIDDLE_BTN_INDEX = Math.floor(NUM_BUTTONS / 2);
|
|
7
7
|
const FIRST_BTN_INDEX = 0;
|