@nectary/components 0.33.0 → 0.35.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.
Files changed (91) hide show
  1. package/accordion/index.js +35 -10
  2. package/accordion/types.d.ts +3 -2
  3. package/accordion-item/index.js +8 -4
  4. package/action-menu/index.js +7 -8
  5. package/action-menu/types.d.ts +3 -3
  6. package/action-menu-option/index.js +23 -3
  7. package/action-menu-option/types.d.ts +2 -0
  8. package/alert/index.js +1 -1
  9. package/avatar/index.js +1 -1
  10. package/button/index.js +68 -4
  11. package/button/types.d.ts +6 -0
  12. package/checkbox/index.js +64 -6
  13. package/checkbox/types.d.ts +8 -2
  14. package/date-picker/index.js +37 -12
  15. package/date-picker/types.d.ts +4 -2
  16. package/dialog/index.d.ts +1 -0
  17. package/dialog/index.js +8 -12
  18. package/dialog/types.d.ts +3 -3
  19. package/dropdown/index.js +44 -28
  20. package/dropdown/types.d.ts +6 -4
  21. package/dropdown-checkbox-option/index.js +1 -1
  22. package/dropdown-checkbox-option/types.d.ts +0 -2
  23. package/dropdown-radio-option/index.js +1 -1
  24. package/dropdown-radio-option/types.d.ts +0 -2
  25. package/dropdown-text-option/index.js +1 -1
  26. package/dropdown-text-option/types.d.ts +0 -2
  27. package/horizontal-stepper/index.d.ts +13 -0
  28. package/horizontal-stepper/index.js +104 -0
  29. package/horizontal-stepper/types.d.ts +9 -0
  30. package/horizontal-stepper/types.js +1 -0
  31. package/horizontal-stepper-item/index.d.ts +13 -0
  32. package/horizontal-stepper-item/index.js +100 -0
  33. package/horizontal-stepper-item/types.d.ts +15 -0
  34. package/horizontal-stepper-item/types.js +1 -0
  35. package/horizontal-stepper-item/utils.d.ts +2 -0
  36. package/horizontal-stepper-item/utils.js +1 -0
  37. package/icon-button/index.js +67 -3
  38. package/icon-button/types.d.ts +6 -0
  39. package/icons/create-icon-class.js +1 -1
  40. package/icons/exclamation/index.d.ts +11 -0
  41. package/icons/exclamation/index.js +4 -0
  42. package/icons-branded/create-icon-class.js +3 -7
  43. package/icons-branded/types.d.ts +3 -0
  44. package/icons-channel/create-icon-class.js +3 -7
  45. package/icons-channel/types.d.ts +3 -0
  46. package/input/index.js +50 -19
  47. package/input/types.d.ts +8 -2
  48. package/link/index.js +81 -3
  49. package/link/types.d.ts +9 -0
  50. package/package.json +1 -1
  51. package/pagination/index.js +24 -8
  52. package/pagination/types.d.ts +3 -1
  53. package/popover/index.js +10 -13
  54. package/popover/types.d.ts +4 -3
  55. package/radio/index.js +36 -8
  56. package/radio/types.d.ts +3 -1
  57. package/radio-option/index.js +1 -1
  58. package/search/types.d.ts +0 -1
  59. package/segment-collapse/index.js +28 -12
  60. package/segment-collapse/types.d.ts +3 -1
  61. package/segmented-control/index.js +28 -23
  62. package/segmented-control/types.d.ts +3 -2
  63. package/segmented-control-option/index.js +59 -13
  64. package/segmented-control-option/types.d.ts +4 -0
  65. package/segmented-icon-control/index.js +27 -16
  66. package/segmented-icon-control/types.d.ts +5 -2
  67. package/segmented-icon-control-option/index.js +54 -12
  68. package/segmented-icon-control-option/types.d.ts +4 -0
  69. package/select/index.js +68 -9
  70. package/select/types.d.ts +41 -7
  71. package/stop-events/index.d.ts +1 -0
  72. package/stop-events/index.js +40 -0
  73. package/tabs/index.js +32 -8
  74. package/tabs/types.d.ts +3 -2
  75. package/tabs-option/index.js +2 -2
  76. package/textarea/index.js +58 -4
  77. package/textarea/types.d.ts +7 -2
  78. package/tile-control/index.d.ts +11 -0
  79. package/tile-control/index.js +181 -0
  80. package/tile-control/types.d.ts +38 -0
  81. package/tile-control/types.js +1 -0
  82. package/tile-control-option/index.d.ts +11 -0
  83. package/tile-control-option/index.js +161 -0
  84. package/tile-control-option/types.d.ts +37 -0
  85. package/tile-control-option/types.js +1 -0
  86. package/time-picker/index.js +17 -3
  87. package/time-picker/types.d.ts +4 -2
  88. package/toggle/index.js +63 -5
  89. package/toggle/types.d.ts +3 -1
  90. package/utils.d.ts +1 -0
  91. package/utils.js +3 -0
@@ -0,0 +1,181 @@
1
+ import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
+ import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
+
4
+ var _$slot, _onSlotChange, _onOptionChange, _onValueChange, _onSmallChange, _onChangeReactHandler;
5
+
6
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
7
+
8
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
9
+
10
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
11
+
12
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
13
+
14
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getCsvSet, getFirstCsvValue, getIntegerAttribute, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv, updateIntegerAttribute } from '../utils';
15
+ const templateHTML = '<style>:host{display:block;outline:0;--sinch-grid-num-columns:1}#wrapper{display:grid;grid-template-columns:repeat(var(--sinch-grid-num-columns),auto);gap:16px;width:fit-content}:host([small]:not([small=false])) #wrapper{gap:8px}:host([cols="2"]){--sinch-grid-num-columns:2}:host([cols="3"]){--sinch-grid-num-columns:3}:host([cols="4"]){--sinch-grid-num-columns:4}:host([cols="5"]){--sinch-grid-num-columns:5}:host([cols="6"]){--sinch-grid-num-columns:6}:host([cols="7"]){--sinch-grid-num-columns:7}:host([cols="8"]){--sinch-grid-num-columns:8}</style><div id="wrapper"><slot></slot></div>';
16
+ const template = document.createElement('template');
17
+ template.innerHTML = templateHTML;
18
+ defineCustomElement('sinch-tile-control', (_$slot = new WeakMap(), _onSlotChange = new WeakMap(), _onOptionChange = new WeakMap(), _onValueChange = new WeakSet(), _onSmallChange = new WeakSet(), _onChangeReactHandler = new WeakMap(), class extends NectaryElement {
19
+ constructor() {
20
+ super();
21
+
22
+ _classPrivateMethodInitSpec(this, _onSmallChange);
23
+
24
+ _classPrivateMethodInitSpec(this, _onValueChange);
25
+
26
+ _classPrivateFieldInitSpec(this, _$slot, {
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+
31
+ _classPrivateFieldInitSpec(this, _onSlotChange, {
32
+ writable: true,
33
+ value: () => {
34
+ _classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this, this.value);
35
+
36
+ _classPrivateMethodGet(this, _onSmallChange, _onSmallChange2).call(this);
37
+ }
38
+ });
39
+
40
+ _classPrivateFieldInitSpec(this, _onOptionChange, {
41
+ writable: true,
42
+ value: e => {
43
+ e.stopPropagation();
44
+ const $elem = e.target;
45
+ const value = e.detail;
46
+ const detail = this.multiple ? updateCsv(this.value, value, !getBooleanAttribute($elem, 'data-checked')) : value;
47
+ this.dispatchEvent(new CustomEvent('change', {
48
+ detail,
49
+ bubbles: true
50
+ }));
51
+ this.dispatchEvent(new CustomEvent('-change', {
52
+ detail
53
+ }));
54
+ }
55
+ });
56
+
57
+ _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
58
+ writable: true,
59
+ value: e => {
60
+ getReactEventHandler(this, 'on-change')?.(e);
61
+ }
62
+ });
63
+
64
+ const shadowRoot = this.attachShadow();
65
+ shadowRoot.appendChild(template.content.cloneNode(true));
66
+
67
+ _classPrivateFieldSet(this, _$slot, shadowRoot.querySelector('slot'));
68
+ }
69
+
70
+ connectedCallback() {
71
+ this.setAttribute('role', 'tablist');
72
+
73
+ _classPrivateFieldGet(this, _$slot).addEventListener('option-change', _classPrivateFieldGet(this, _onOptionChange));
74
+
75
+ _classPrivateFieldGet(this, _$slot).addEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
76
+
77
+ this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
78
+ }
79
+
80
+ disconnectedCallback() {
81
+ _classPrivateFieldGet(this, _$slot).removeEventListener('option-change', _classPrivateFieldGet(this, _onOptionChange));
82
+
83
+ _classPrivateFieldGet(this, _$slot).removeEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
84
+
85
+ this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
86
+ }
87
+
88
+ static get observedAttributes() {
89
+ return ['value', 'small', 'multiple'];
90
+ }
91
+
92
+ get nodeName() {
93
+ return 'select';
94
+ }
95
+
96
+ set value(value) {
97
+ updateAttribute(this, 'value', value);
98
+ }
99
+
100
+ get value() {
101
+ return getAttribute(this, 'value', '');
102
+ }
103
+
104
+ set small(isSmall) {
105
+ updateBooleanAttribute(this, 'small', isSmall);
106
+ }
107
+
108
+ get small() {
109
+ return getBooleanAttribute(this, 'small');
110
+ }
111
+
112
+ set multiple(isMultiple) {
113
+ updateBooleanAttribute(this, 'multiple', isMultiple);
114
+ }
115
+
116
+ get multiple() {
117
+ return getBooleanAttribute(this, 'multiple');
118
+ }
119
+
120
+ set cols(value) {
121
+ updateIntegerAttribute(this, 'cols', value);
122
+ }
123
+
124
+ get cols() {
125
+ return getIntegerAttribute(this, 'cols', 1);
126
+ }
127
+
128
+ attributeChangedCallback(name, oldVal, newVal) {
129
+ if (oldVal === newVal) {
130
+ return;
131
+ }
132
+
133
+ switch (name) {
134
+ case 'value':
135
+ {
136
+ _classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this, newVal ?? '');
137
+
138
+ break;
139
+ }
140
+
141
+ case 'small':
142
+ {
143
+ _classPrivateMethodGet(this, _onSmallChange, _onSmallChange2).call(this);
144
+
145
+ break;
146
+ }
147
+
148
+ case 'multiple':
149
+ {
150
+ _classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this, this.value);
151
+ }
152
+ }
153
+ }
154
+
155
+ }));
156
+
157
+ function _onValueChange2(csv) {
158
+ if (this.multiple) {
159
+ const values = getCsvSet(csv);
160
+
161
+ for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements()) {
162
+ const isChecked = !getBooleanAttribute($option, 'disabled') && values.has(getAttribute($option, 'value', ''));
163
+ updateBooleanAttribute($option, 'data-checked', isChecked);
164
+ }
165
+ } else {
166
+ const value = getFirstCsvValue(csv);
167
+
168
+ for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements()) {
169
+ const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
170
+ updateBooleanAttribute($option, 'data-checked', isChecked);
171
+ }
172
+ }
173
+ }
174
+
175
+ function _onSmallChange2() {
176
+ const isSmall = this.small;
177
+
178
+ for (const $opt of _classPrivateFieldGet(this, _$slot).assignedElements()) {
179
+ updateBooleanAttribute($opt, 'data-small', isSmall);
180
+ }
181
+ }
@@ -0,0 +1,38 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ import type { SyntheticEvent } from 'react';
3
+ export declare type TSinchTileControlElement = HTMLElement & {
4
+ /** Value */
5
+ value: string;
6
+ /** Small */
7
+ small: boolean;
8
+ /** Multiple */
9
+ multiple: boolean;
10
+ /** Number of columns from 1 to 8 */
11
+ cols: number;
12
+ /** Change value event */
13
+ addEventListener(type: '-change', listener: (e: CustomEvent<string>) => void): void;
14
+ /** Value */
15
+ setAttribute(name: 'value', value: string): void;
16
+ /** Small */
17
+ setAttribute(name: 'small', value: ''): void;
18
+ /** Multiple */
19
+ setAttribute(name: 'multiple', value: ''): void;
20
+ /** Number of columns from 1 to 8 */
21
+ setAttribute(name: 'cols', value: string): void;
22
+ };
23
+ export declare type TSinchTileControlReact = TSinchElementReact<TSinchTileControlElement> & {
24
+ /** Value */
25
+ value: string;
26
+ /** Multiple */
27
+ multiple?: boolean;
28
+ /** Small */
29
+ small?: boolean;
30
+ /** Number of columns from 1 to 8 */
31
+ cols: number;
32
+ /** Label that is used for a11y */
33
+ 'aria-label': string;
34
+ /** @deprecated Change value handler */
35
+ onChange?: (event: SyntheticEvent<TSinchTileControlElement, CustomEvent<string>>) => void;
36
+ /** Change value handler */
37
+ 'on-change'?: (e: CustomEvent<string>) => void;
38
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { TSinchTileControlOptionElement, TSinchTileControlOptionReact } from './types';
2
+ declare global {
3
+ namespace JSX {
4
+ interface IntrinsicElements {
5
+ 'sinch-tile-control-option': TSinchTileControlOptionReact;
6
+ }
7
+ }
8
+ interface HTMLElementTagNameMap {
9
+ 'sinch-tile-control-option': TSinchTileControlOptionElement;
10
+ }
11
+ }
@@ -0,0 +1,161 @@
1
+ import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
+ import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
+
4
+ var _$button, _$text, _onButtonClick, _onButtonFocus, _onButtonBlur, _onFocusReactHandler, _onBlurReactHandler;
5
+
6
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
7
+
8
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
9
+
10
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
11
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}button{all:initial;position:relative;display:flex;flex-direction:column;justify-content:space-between;box-sizing:border-box;width:88px;height:88px;padding:16px 8px 8px;border-radius:var(--sinch-shape-radius-l);background-color:var(--sinch-color-snow-100);box-shadow:var(--sinch-elevation-leve-1);cursor:pointer}:host([data-small])>button{width:64px;height:64px;border-radius:var(--sinch-shape-radius-m);padding:12px 4px 4px}button::before{content:"";position:absolute;left:0;top:0;bottom:0;right:0;border:1px solid var(--sinch-color-snow-700);border-radius:var(--sinch-shape-radius-l);pointer-events:none}:host([data-small])>button::before{border-radius:var(--sinch-shape-radius-m)}button:focus-visible::after{position:absolute;content:"";left:50%;top:50%;transform:translate(-50%,-50%);width:100%;height:100%;padding:2px;border:2px solid var(--sinch-color-aqua-400);border-radius:calc(var(--sinch-shape-radius-l) + 4px);pointer-events:none}:host([data-small])>button:focus-visible::after{border-radius:calc(var(--sinch-shape-radius-m) + 4px)}@supports not selector(:focus-visible){button:focus::after{position:absolute;content:"";left:50%;top:50%;transform:translate(-50%,-50%);width:100%;height:100%;padding:2px;border:2px solid var(--sinch-color-aqua-400);border-radius:calc(var(--sinch-shape-radius-l) + 4px)}:host([data-small])>button:focus::after{border-radius:calc(var(--sinch-shape-radius-m) + 4px)}}button:enabled:hover{background-color:var(--sinch-color-tropical-100)}button:enabled:hover::before{border-color:var(--sinch-color-tropical-100)}:host([data-checked])>button:enabled,button:enabled:active{box-shadow:var(--sinch-elevation-level-0)}:host([data-checked])>button:enabled::before,button:enabled:active::before{border-width:2px;border-color:var(--sinch-color-stormy-500)}button:disabled{cursor:initial}button:disabled>#icon,button:disabled>#text{opacity:.5}#text{display:inline-block;min-height:20px;text-align:center;font:var(--sinch-font-text-xs);color:var(--sinch-color-stormy-500);overflow:hidden;white-space:nowrap;text-overflow:ellipsis}#icon{width:32px;height:32px;align-self:center;--sinch-size-icon:32px;--sinch-color-icon:var(--sinch-color-stormy-500)}:host([data-small]) #icon{width:24px;height:24px;--sinch-size-icon:24px}button>*{pointer-events:none}</style><button><div id="icon"><slot name="icon"></slot></div><span id="text"></span></button>';
12
+ const template = document.createElement('template');
13
+ template.innerHTML = templateHTML;
14
+ defineCustomElement('sinch-tile-control-option', (_$button = new WeakMap(), _$text = new WeakMap(), _onButtonClick = new WeakMap(), _onButtonFocus = new WeakMap(), _onButtonBlur = new WeakMap(), _onFocusReactHandler = new WeakMap(), _onBlurReactHandler = new WeakMap(), class extends NectaryElement {
15
+ constructor() {
16
+ super();
17
+
18
+ _classPrivateFieldInitSpec(this, _$button, {
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+
23
+ _classPrivateFieldInitSpec(this, _$text, {
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+
28
+ _classPrivateFieldInitSpec(this, _onButtonClick, {
29
+ writable: true,
30
+ value: e => {
31
+ e.stopPropagation();
32
+ this.dispatchEvent(new CustomEvent('option-change', {
33
+ detail: this.value,
34
+ bubbles: true
35
+ }));
36
+ }
37
+ });
38
+
39
+ _classPrivateFieldInitSpec(this, _onButtonFocus, {
40
+ writable: true,
41
+ value: () => {
42
+ this.dispatchEvent(new CustomEvent('-focus'));
43
+ }
44
+ });
45
+
46
+ _classPrivateFieldInitSpec(this, _onButtonBlur, {
47
+ writable: true,
48
+ value: () => {
49
+ this.dispatchEvent(new CustomEvent('-blur'));
50
+ }
51
+ });
52
+
53
+ _classPrivateFieldInitSpec(this, _onFocusReactHandler, {
54
+ writable: true,
55
+ value: () => {
56
+ getReactEventHandler(this, 'on-focus')?.();
57
+ }
58
+ });
59
+
60
+ _classPrivateFieldInitSpec(this, _onBlurReactHandler, {
61
+ writable: true,
62
+ value: () => {
63
+ getReactEventHandler(this, 'on-blur')?.();
64
+ }
65
+ });
66
+
67
+ const shadowRoot = this.attachShadow();
68
+ shadowRoot.appendChild(template.content.cloneNode(true));
69
+
70
+ _classPrivateFieldSet(this, _$button, shadowRoot.querySelector('button'));
71
+
72
+ _classPrivateFieldSet(this, _$text, shadowRoot.querySelector('#text'));
73
+ }
74
+
75
+ connectedCallback() {
76
+ this.setAttribute('role', 'tab');
77
+
78
+ _classPrivateFieldGet(this, _$button).addEventListener('click', _classPrivateFieldGet(this, _onButtonClick));
79
+
80
+ _classPrivateFieldGet(this, _$button).addEventListener('focus', _classPrivateFieldGet(this, _onButtonFocus));
81
+
82
+ _classPrivateFieldGet(this, _$button).addEventListener('blur', _classPrivateFieldGet(this, _onButtonBlur));
83
+
84
+ this.addEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
85
+ this.addEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
86
+ }
87
+
88
+ disconnectedCallback() {
89
+ _classPrivateFieldGet(this, _$button).removeEventListener('click', _classPrivateFieldGet(this, _onButtonClick));
90
+
91
+ _classPrivateFieldGet(this, _$button).removeEventListener('focus', _classPrivateFieldGet(this, _onButtonFocus));
92
+
93
+ _classPrivateFieldGet(this, _$button).removeEventListener('blur', _classPrivateFieldGet(this, _onButtonBlur));
94
+
95
+ this.removeEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
96
+ this.removeEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
97
+ }
98
+
99
+ static get observedAttributes() {
100
+ return ['data-checked', 'text', 'disabled'];
101
+ }
102
+
103
+ attributeChangedCallback(name, oldVal, newVal) {
104
+ if (oldVal === newVal) {
105
+ return;
106
+ }
107
+
108
+ switch (name) {
109
+ case 'text':
110
+ {
111
+ _classPrivateFieldGet(this, _$text).textContent = newVal;
112
+ break;
113
+ }
114
+
115
+ case 'data-checked':
116
+ {
117
+ updateExplicitBooleanAttribute(this, 'aria-selected', isAttrTrue(newVal));
118
+ break;
119
+ }
120
+
121
+ case 'disabled':
122
+ {
123
+ _classPrivateFieldGet(this, _$button).disabled = isAttrTrue(newVal);
124
+ break;
125
+ }
126
+ }
127
+ }
128
+
129
+ set value(value) {
130
+ updateAttribute(this, 'value', value);
131
+ }
132
+
133
+ get value() {
134
+ return getAttribute(this, 'value', '');
135
+ }
136
+
137
+ set disabled(isDisabled) {
138
+ updateBooleanAttribute(this, 'disabled', isDisabled);
139
+ }
140
+
141
+ get disabled() {
142
+ return getBooleanAttribute(this, 'disabled');
143
+ }
144
+
145
+ set text(value) {
146
+ updateAttribute(this, 'text', value);
147
+ }
148
+
149
+ get text() {
150
+ return getAttribute(this, 'text', '');
151
+ }
152
+
153
+ focus() {
154
+ _classPrivateFieldGet(this, _$button).focus();
155
+ }
156
+
157
+ blur() {
158
+ _classPrivateFieldGet(this, _$button).blur();
159
+ }
160
+
161
+ }));
@@ -0,0 +1,37 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ export declare type TSinchTileControlOptionElement = HTMLElement & {
3
+ /** Value */
4
+ value: string;
5
+ /** Text content */
6
+ text: string;
7
+ /** Disabled */
8
+ disabled: boolean;
9
+ /** Small */
10
+ small: boolean;
11
+ /** Focus event */
12
+ addEventListener(type: '-focus', listener: (e: CustomEvent<void>) => void): void;
13
+ /** Blur event */
14
+ addEventListener(type: '-blur', listener: (e: CustomEvent<void>) => void): void;
15
+ /** Value */
16
+ setAttribute(name: 'value', value: string): void;
17
+ /** Text content */
18
+ setAttribute(attr: 'text', value: string): void;
19
+ /** Disabled */
20
+ setAttribute(name: 'disabled', value: ''): void;
21
+ /** Small */
22
+ setAttribute(name: 'small', value: ''): void;
23
+ };
24
+ export declare type TSinchTileControlOptionReact = TSinchElementReact<TSinchTileControlOptionElement> & {
25
+ /** Value */
26
+ value: string;
27
+ /** Text content */
28
+ text: string;
29
+ /** Label that is used for a11y */
30
+ 'aria-label': string;
31
+ /** Disabled */
32
+ disabled?: boolean;
33
+ /** Focus handler */
34
+ 'on-focus'?: (e: CustomEvent<void>) => void;
35
+ /** Blur handler */
36
+ 'on-blur'?: (e: CustomEvent<void>) => void;
37
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,7 @@
1
1
  import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
2
  import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
3
 
4
- var _$pickerHours, _$pickerMinutes, _$pickerTouch, _$needleHour, _$needleMinute, _$headerHours, _$headerHoursText, _$headerMinutes, _$headerMinutesText, _$ampm, _$submitButton, _hour, _minute, _getClickDegree, _onPickerClick, _render, _selectHour, _selectMinute, _onAmPmChange, _onSubmitButtonClick, _onHoursKeydown, _onMinutesKeydown;
4
+ var _$pickerHours, _$pickerMinutes, _$pickerTouch, _$needleHour, _$needleMinute, _$headerHours, _$headerHoursText, _$headerMinutes, _$headerMinutesText, _$ampm, _$submitButton, _hour, _minute, _getClickDegree, _onPickerClick, _render, _selectHour, _selectMinute, _onAmPmChange, _onSubmitButtonClick, _onHoursKeydown, _onMinutesKeydown, _onChangeReactHandler;
5
5
 
6
6
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
7
7
 
@@ -17,7 +17,7 @@ import '../icons/arrow-drop-up';
17
17
  import '../icons/arrow-drop-down';
18
18
  import '../segmented-control';
19
19
  import '../segmented-control-option';
20
- import { defineCustomElement, getAttribute, getBooleanAttribute, getRect, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute } from '../utils';
20
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, getRect, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute } from '../utils';
21
21
  const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:column;width:248px;padding:16px;box-sizing:border-box;gap:16px}#header{position:relative;width:100%;height:48px;font:var(--sinch-font-title-xl);line-height:48px}#footer{display:flex;justify-content:center;width:100%;height:32px}#picker{position:relative;width:216px;height:216px;border-radius:50%;box-sizing:border-box;border:1px solid var(--sinch-color-stormy-500)}#digit-minutes,#picker-hours{position:absolute;left:0;top:0;width:100%;height:100%;border-radius:50%}.digit-hour-12,.digit-hour-24,.digit-minute{position:absolute;width:28px;height:28px;font:var(--sinch-font-text-s);line-height:28px;text-align:center;color:var(--sinch-color-text-default);top:calc(50% - 14px);left:calc(50% - 14px);z-index:1;cursor:pointer}.digit-hour-24{font:var(--sinch-font-text-xs);line-height:28px;color:var(--sinch-color-text-muted)}.digit-minute{font:var(--sinch-font-text-xs);line-height:28px;color:var(--sinch-color-text-muted)}.digit-hour-12:hover,.digit-hour-24:hover,.digit-minute:hover{color:var(--sinch-color-tropical-500)}.digit-hour-12.selected,.digit-hour-24.selected,.digit-minute.selected{color:var(--sinch-color-tropical-500)}.digit-hour-12.selected{font-size:16px}.digit-hour-24.selected{font-size:16px}.digit-minute.selected{font-size:16px}#picker-touch{position:absolute;left:0;top:0;width:100%;height:100%;cursor:pointer;border-radius:50%}#needle-hour,#needle-minute,#picker-touch::after{background-color:var(--sinch-color-stormy-500)}#needle-hour,#needle-minute{position:absolute;transform-origin:bottom center;transform:rotate(0);bottom:50%;height:50px;transition-duration:.25s;transition-timing-function:ease-in-out;transition-property:transform height;z-index:2}@media (prefers-reduced-motion){#needle-hour,#needle-minute{transition:none}}#needle-hour{width:4px;left:calc(50% - 2px);border-radius:2px}#needle-minute{width:2px;left:calc(50% - 1px);border-radius:1px}#needle-minute:not(.selected)::after{content:"";position:absolute;transform:translateX(-50%);left:0;top:-16px;width:4px;height:4px;border-radius:50%;background-color:var(--sinch-color-tropical-500)}#picker-touch::after{content:"";position:absolute;top:50%;left:50%;width:12px;height:12px;border-radius:50%;transform:translate(-50%,-50%)}#header-hours,#header-minutes{position:absolute;padding:0 4px;width:50px;outline:0;--sinch-icon-size:24px}#header-hours{right:calc(50% + 8px);text-align:right}#header-minutes{left:calc(50% + 8px)}#header-hours::before,#header-minutes::before{content:"";display:none;position:absolute;border-radius:12px;left:50%;top:50%;width:100%;height:100%;transform:translate(-50%,-50%);padding:1px;border:1px solid var(--sinch-color-aqua-400)}#header-hours-down,#header-hours-up,#header-minutes-down,#header-minutes-up{display:none;position:absolute;left:50%;transform:translateX(-50%)}#header-hours-up,#header-minutes-up{top:-18px}#header-hours-down,#header-minutes-down{bottom:-18px}#header-hours:focus #header-hours-down,#header-hours:focus #header-hours-up,#header-hours:focus::before{display:block}#header-minutes:focus #header-minutes-down,#header-minutes:focus #header-minutes-up,#header-minutes:focus::before{display:block}#header-colon{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%)}#submit{position:absolute;right:0;top:50%;transform:translateY(-50%)}:host([ampm]) .digit-hour-24{display:none}:host(:not([ampm])) #footer{display:none}</style><div id="wrapper"><div id="header"><div id="header-hours" tabindex="0" role="meter" aria-valuemin="0" aria-valuemax="23" aria-valuenow="0" aria-valuetext="0"><span>00</span><sinch-icon-arrow-drop-up id="header-hours-up"></sinch-icon-arrow-drop-up><sinch-icon-arrow-drop-down id="header-hours-down"></sinch-icon-arrow-drop-down></div><div id="header-colon">&colon;</div><div id="header-minutes" tabindex="0" role="meter" aria-valuemin="0" aria-valuemax="59" aria-valuenow="0" aria-valuetext="0"><span>00</span><sinch-icon-arrow-drop-up id="header-minutes-up"></sinch-icon-arrow-drop-up><sinch-icon-arrow-drop-down id="header-minutes-down"></sinch-icon-arrow-drop-down></div><sinch-icon-button id="submit" small aria-label="Submit"><sinch-icon-done slot="icon"></sinch-icon-done></sinch-icon-button></div><div id="picker" aria-hidden="true"><div id="picker-hours"></div><div id="picker-minutes"></div><div id="picker-touch"><div id="needle-hour"></div><div id="needle-minute"></div></div></div><div id="footer"><sinch-segmented-control id="ampm"><sinch-segmented-control-option value="am" text="AM" aria-label="AM"></sinch-segmented-control-option><sinch-segmented-control-option value="pm" text="PM" aria-label="PM"></sinch-segmented-control-option></sinch-segmented-control></div></div>';
22
22
  import { getNeedleRotationDeg, getShortestCssDeg, hourToIndex, parseTime, stringifyHour, stringifyHourFace, stringifyMinute, stringifyTime } from './utils';
23
23
  const template = document.createElement('template');
@@ -32,7 +32,7 @@ const HOUR_24_RADIUS = HOUR_12_RADIUS - HOUR_24_DIGIT_SIZE;
32
32
  const NEEDLE_HOUR_12_LENGTH = HOUR_12_RADIUS;
33
33
  const NEEDLE_HOUR_24_LENGTH = HOUR_24_RADIUS;
34
34
  const NEEDLE_MINUTE_LENGTH = MINUTE_RADIUS;
35
- defineCustomElement('sinch-time-picker', (_$pickerHours = new WeakMap(), _$pickerMinutes = new WeakMap(), _$pickerTouch = new WeakMap(), _$needleHour = new WeakMap(), _$needleMinute = new WeakMap(), _$headerHours = new WeakMap(), _$headerHoursText = new WeakMap(), _$headerMinutes = new WeakMap(), _$headerMinutesText = new WeakMap(), _$ampm = new WeakMap(), _$submitButton = new WeakMap(), _hour = new WeakMap(), _minute = new WeakMap(), _getClickDegree = new WeakSet(), _onPickerClick = new WeakMap(), _render = new WeakSet(), _selectHour = new WeakSet(), _selectMinute = new WeakSet(), _onAmPmChange = new WeakMap(), _onSubmitButtonClick = new WeakMap(), _onHoursKeydown = new WeakMap(), _onMinutesKeydown = new WeakMap(), class extends NectaryElement {
35
+ defineCustomElement('sinch-time-picker', (_$pickerHours = new WeakMap(), _$pickerMinutes = new WeakMap(), _$pickerTouch = new WeakMap(), _$needleHour = new WeakMap(), _$needleMinute = new WeakMap(), _$headerHours = new WeakMap(), _$headerHoursText = new WeakMap(), _$headerMinutes = new WeakMap(), _$headerMinutesText = new WeakMap(), _$ampm = new WeakMap(), _$submitButton = new WeakMap(), _hour = new WeakMap(), _minute = new WeakMap(), _getClickDegree = new WeakSet(), _onPickerClick = new WeakMap(), _render = new WeakSet(), _selectHour = new WeakSet(), _selectMinute = new WeakSet(), _onAmPmChange = new WeakMap(), _onSubmitButtonClick = new WeakMap(), _onHoursKeydown = new WeakMap(), _onMinutesKeydown = new WeakMap(), _onChangeReactHandler = new WeakMap(), class extends NectaryElement {
36
36
  constructor() {
37
37
  super();
38
38
 
@@ -182,6 +182,9 @@ defineCustomElement('sinch-time-picker', (_$pickerHours = new WeakMap(), _$picke
182
182
  bubbles: true,
183
183
  detail: value
184
184
  }));
185
+ this.dispatchEvent(new CustomEvent('-change', {
186
+ detail: value
187
+ }));
185
188
  }
186
189
  });
187
190
 
@@ -235,6 +238,13 @@ defineCustomElement('sinch-time-picker', (_$pickerHours = new WeakMap(), _$picke
235
238
  }
236
239
  });
237
240
 
241
+ _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
242
+ writable: true,
243
+ value: e => {
244
+ getReactEventHandler(this, 'on-change')?.(e);
245
+ }
246
+ });
247
+
238
248
  const shadowRoot = this.attachShadow();
239
249
  shadowRoot.appendChild(template.content.cloneNode(true));
240
250
 
@@ -323,6 +333,8 @@ defineCustomElement('sinch-time-picker', (_$pickerHours = new WeakMap(), _$picke
323
333
  _classPrivateFieldGet(this, _$headerHours).addEventListener('keydown', _classPrivateFieldGet(this, _onHoursKeydown));
324
334
 
325
335
  _classPrivateFieldGet(this, _$headerMinutes).addEventListener('keydown', _classPrivateFieldGet(this, _onMinutesKeydown));
336
+
337
+ this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
326
338
  }
327
339
 
328
340
  disconnectedCallback() {
@@ -335,6 +347,8 @@ defineCustomElement('sinch-time-picker', (_$pickerHours = new WeakMap(), _$picke
335
347
  _classPrivateFieldGet(this, _$headerHours).removeEventListener('keydown', _classPrivateFieldGet(this, _onHoursKeydown));
336
348
 
337
349
  _classPrivateFieldGet(this, _$headerMinutes).removeEventListener('keydown', _classPrivateFieldGet(this, _onMinutesKeydown));
350
+
351
+ this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
338
352
  }
339
353
 
340
354
  static get observedAttributes() {
@@ -11,7 +11,7 @@ export declare type TSinchTimePickerElement = HTMLElement & {
11
11
  hourDigitRect(hour: number): TRect | null;
12
12
  minuteDigitRect(minute: number): TRect | null;
13
13
  /** Change value handler, return time in ISO 8601 format */
14
- addEventListener(type: 'change', listener: (e: CustomEvent<string>) => void): void;
14
+ addEventListener(type: '-change', listener: (e: CustomEvent<string>) => void): void;
15
15
  /** Time value in ISO 8601 format */
16
16
  setAttribute(name: 'value', value: string): void;
17
17
  /** AM/PM 12-hour clock system, `false` by default */
@@ -27,5 +27,7 @@ export declare type TSinchTimePickerReact = TSinchElementReact<TSinchTimePickerE
27
27
  /** Submit button label that is used for a11y */
28
28
  'submit-aria-label': string;
29
29
  /** Change value handler, return time in ISO 8601 format */
30
- onChange: (e: SyntheticEvent<TSinchTimePickerElement, CustomEvent<string>>) => void;
30
+ onChange?: (e: SyntheticEvent<TSinchTimePickerElement, CustomEvent<string>>) => void;
31
+ /** Change value handler, return time in ISO 8601 format */
32
+ 'on-change'?: (e: CustomEvent<string>) => void;
31
33
  };
package/toggle/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
2
  import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
3
 
4
- var _$input, _$label, _onInput;
4
+ var _$input, _$label, _onInput, _onCheckboxFocus, _onCheckboxBlur, _onChangeReactHandler, _onFocusReactHandler, _onBlurReactHandler;
5
5
 
6
6
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
7
7
 
8
8
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
9
9
 
10
- import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
10
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
11
11
  const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;flex-direction:row;box-sizing:border-box;width:100%;height:32px;font:var(--sinch-font-body);color:var(--sinch-color-text-default);text-align:initial}:host([small]:not([small=false])) #wrapper{font:var(--sinch-font-small-text)}#checkbox{all:initial;display:block;position:absolute;left:0;top:0;width:40px;height:20px;cursor:pointer;pointer-events:initial}#checkbox:disabled{cursor:initial}#knob-container{position:relative;box-sizing:border-box;align-self:center;width:40px;height:20px;border-radius:10px;pointer-events:none;padding:2px;background-color:var(--sinch-color-stormy-100);box-shadow:var(--sinch-elevation-level-1);overflow:hidden}:host([checked]:not([checked=false])) #knob-container{background-color:var(--sinch-color-tropical-500)}:host([small]:not([small=false])) #knob-container{width:32px;height:16px;border-radius:8px}#knob{position:relative;box-sizing:border-box;width:16px;height:16px;border-radius:50%;background-color:var(--sinch-color-snow-100);transform:translateX(0);transition:transform .1s ease-in-out}:host([checked]:not([checked=false])) #knob{transform:translateX(20px)}:host([small]:not([small=false])) #knob{width:12px;height:12px}:host([small]:not([small=false])[checked]:not([checked=false])) #knob{transform:translateX(16px)}#knob::after,#knob::before{color:var(--sinch-color-snow-100);text-transform:uppercase;font-size:8px;line-height:16px;display:none;position:absolute;top:0;padding:0 3px}#knob::before{content:"on";right:100%}#knob::after{content:"off";left:100%}:host([labeled]:not([labeled=false]):is(:not([small]),[small=false])) #knob::after,:host([labeled]:not([labeled=false]):is(:not([small]),[small=false])) #knob::before{display:block}@media (prefers-reduced-motion){#knob{transition:none}}#label{display:none;flex:1;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;padding-left:8px}:host([text]:not([text=""])) #label{display:block}:host([disabled]:not([disabled=false])) #label{color:var(--sinch-color-stormy-200)}:host([disabled]:not([disabled=false])) #knob-container{background-color:var(--sinch-color-snow-700)}:host([checked]:not([checked=false])[disabled]:not([disabled=false])) #knob-container{background-color:var(--sinch-color-tropical-100)}</style><div id="wrapper"><div id="knob-container"><div id="knob"></div><input id="checkbox" type="checkbox"></div><label for="checkbox" id="label"></label></div>';
12
12
  const template = document.createElement('template');
13
13
  template.innerHTML = templateHTML;
14
- defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new WeakMap(), _onInput = new WeakMap(), class extends NectaryElement {
14
+ defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new WeakMap(), _onInput = new WeakMap(), _onCheckboxFocus = new WeakMap(), _onCheckboxBlur = new WeakMap(), _onChangeReactHandler = new WeakMap(), _onFocusReactHandler = new WeakMap(), _onBlurReactHandler = new WeakMap(), class extends NectaryElement {
15
15
  constructor() {
16
16
  super();
17
17
 
@@ -37,6 +37,44 @@ defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new Weak
37
37
  detail: isChecked,
38
38
  bubbles: true
39
39
  }));
40
+ this.dispatchEvent(new CustomEvent('-change', {
41
+ detail: isChecked
42
+ }));
43
+ }
44
+ });
45
+
46
+ _classPrivateFieldInitSpec(this, _onCheckboxFocus, {
47
+ writable: true,
48
+ value: () => {
49
+ this.dispatchEvent(new CustomEvent('-focus'));
50
+ }
51
+ });
52
+
53
+ _classPrivateFieldInitSpec(this, _onCheckboxBlur, {
54
+ writable: true,
55
+ value: () => {
56
+ this.dispatchEvent(new CustomEvent('-blur'));
57
+ }
58
+ });
59
+
60
+ _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
61
+ writable: true,
62
+ value: e => {
63
+ getReactEventHandler(this, 'on-change')?.(e);
64
+ }
65
+ });
66
+
67
+ _classPrivateFieldInitSpec(this, _onFocusReactHandler, {
68
+ writable: true,
69
+ value: e => {
70
+ getReactEventHandler(this, 'on-focus')?.(e);
71
+ }
72
+ });
73
+
74
+ _classPrivateFieldInitSpec(this, _onBlurReactHandler, {
75
+ writable: true,
76
+ value: e => {
77
+ getReactEventHandler(this, 'on-blur')?.(e);
40
78
  }
41
79
  });
42
80
 
@@ -46,13 +84,33 @@ defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new Weak
46
84
  _classPrivateFieldSet(this, _$input, shadowRoot.querySelector('input'));
47
85
 
48
86
  _classPrivateFieldSet(this, _$label, shadowRoot.querySelector('label'));
49
-
50
- _classPrivateFieldGet(this, _$input).addEventListener('input', _classPrivateFieldGet(this, _onInput));
51
87
  }
52
88
 
53
89
  connectedCallback() {
54
90
  this.setAttribute('role', 'checkbox');
55
91
  this.setAttribute('aria-label', 'toggle');
92
+
93
+ _classPrivateFieldGet(this, _$input).addEventListener('input', _classPrivateFieldGet(this, _onInput));
94
+
95
+ _classPrivateFieldGet(this, _$input).addEventListener('focus', _classPrivateFieldGet(this, _onCheckboxFocus));
96
+
97
+ _classPrivateFieldGet(this, _$input).addEventListener('blur', _classPrivateFieldGet(this, _onCheckboxBlur));
98
+
99
+ this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
100
+ this.addEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
101
+ this.addEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
102
+ }
103
+
104
+ disconnectedCallback() {
105
+ _classPrivateFieldGet(this, _$input).removeEventListener('input', _classPrivateFieldGet(this, _onInput));
106
+
107
+ _classPrivateFieldGet(this, _$input).removeEventListener('focus', _classPrivateFieldGet(this, _onCheckboxFocus));
108
+
109
+ _classPrivateFieldGet(this, _$input).removeEventListener('blur', _classPrivateFieldGet(this, _onCheckboxBlur));
110
+
111
+ this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
112
+ this.removeEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
113
+ this.removeEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
56
114
  }
57
115
 
58
116
  static get observedAttributes() {
package/toggle/types.d.ts CHANGED
@@ -7,6 +7,7 @@ export declare type TSinchToggleElement = HTMLElement & {
7
7
  disabled: boolean;
8
8
  text: string | null;
9
9
  addEventListener(type: 'change', listener: (e: CustomEvent<boolean>) => void): void;
10
+ addEventListener(type: '-change', listener: (e: CustomEvent<boolean>) => void): void;
10
11
  setAttribute(name: 'checked', value: ''): void;
11
12
  setAttribute(name: 'small', value: ''): void;
12
13
  setAttribute(name: 'labeled', value: ''): void;
@@ -20,5 +21,6 @@ export declare type TSinchToggleReact = TSinchElementReact<TSinchToggleElement>
20
21
  disabled?: boolean;
21
22
  text?: string;
22
23
  'aria-label': string;
23
- onChange: (e: SyntheticEvent<TSinchToggleElement, CustomEvent<boolean>>) => void;
24
+ onChange?: (e: SyntheticEvent<TSinchToggleElement, CustomEvent<boolean>>) => void;
25
+ 'on-change'?: (e: CustomEvent<boolean>) => void;
24
26
  };