@nectary/components 0.34.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 (76) 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.js +5 -6
  17. package/dialog/types.d.ts +3 -3
  18. package/dropdown/index.js +44 -28
  19. package/dropdown/types.d.ts +6 -4
  20. package/dropdown-checkbox-option/index.js +1 -1
  21. package/dropdown-checkbox-option/types.d.ts +0 -2
  22. package/dropdown-radio-option/index.js +1 -1
  23. package/dropdown-radio-option/types.d.ts +0 -2
  24. package/dropdown-text-option/index.js +1 -1
  25. package/dropdown-text-option/types.d.ts +0 -2
  26. package/horizontal-stepper-item/index.js +1 -1
  27. package/icon-button/index.js +67 -3
  28. package/icon-button/types.d.ts +6 -0
  29. package/icons/create-icon-class.js +1 -1
  30. package/icons-branded/create-icon-class.js +3 -7
  31. package/icons-branded/types.d.ts +3 -0
  32. package/icons-channel/create-icon-class.js +3 -7
  33. package/icons-channel/types.d.ts +3 -0
  34. package/input/index.d.ts +0 -1
  35. package/input/index.js +58 -5
  36. package/input/types.d.ts +8 -2
  37. package/link/index.js +81 -3
  38. package/link/types.d.ts +9 -0
  39. package/package.json +1 -1
  40. package/pagination/index.js +24 -8
  41. package/pagination/types.d.ts +3 -1
  42. package/popover/index.js +5 -6
  43. package/popover/types.d.ts +4 -3
  44. package/radio/index.js +36 -8
  45. package/radio/types.d.ts +3 -1
  46. package/radio-option/index.js +1 -1
  47. package/search/types.d.ts +0 -1
  48. package/segment-collapse/index.js +28 -12
  49. package/segment-collapse/types.d.ts +3 -1
  50. package/segmented-control/index.js +28 -23
  51. package/segmented-control/types.d.ts +3 -2
  52. package/segmented-control-option/index.js +59 -13
  53. package/segmented-control-option/types.d.ts +4 -0
  54. package/segmented-icon-control/index.js +27 -16
  55. package/segmented-icon-control/types.d.ts +5 -2
  56. package/segmented-icon-control-option/index.js +54 -12
  57. package/segmented-icon-control-option/types.d.ts +4 -0
  58. package/select/index.js +68 -9
  59. package/select/types.d.ts +8 -2
  60. package/tabs/index.js +32 -8
  61. package/tabs/types.d.ts +3 -2
  62. package/tabs-option/index.js +2 -2
  63. package/textarea/index.js +58 -4
  64. package/textarea/types.d.ts +7 -2
  65. package/tile-control/index.d.ts +11 -0
  66. package/tile-control/index.js +181 -0
  67. package/tile-control/types.d.ts +38 -0
  68. package/tile-control/types.js +1 -0
  69. package/tile-control-option/index.d.ts +11 -0
  70. package/tile-control-option/index.js +161 -0
  71. package/tile-control-option/types.d.ts +37 -0
  72. package/tile-control-option/types.js +1 -0
  73. package/time-picker/index.js +17 -3
  74. package/time-picker/types.d.ts +4 -2
  75. package/toggle/index.js +63 -5
  76. package/toggle/types.d.ts +3 -1
@@ -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 _$left, _$right, _$buttons, _$wrapper, _onValueChange, _onButtonClick, _clamp, _dispatchChangeEvent;
4
+ var _$left, _$right, _$buttons, _$wrapper, _onValueChange, _onButtonClick, _clamp, _dispatchChangeEvent, _onChangeReactHandler;
5
5
 
6
6
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
7
7
 
@@ -13,8 +13,8 @@ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(
13
13
 
14
14
  import '../icons/keyboard-arrow-left';
15
15
  import '../icons/keyboard-arrow-right';
16
- import { defineCustomElement, updateAttribute, getIntegerAttribute, setClass, NectaryElement, getRect } from '../utils';
17
- 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-body);color:var(--sinch-color-stormy-500)}.page.dots>span{display:none}.page.dots::after{content:"..."}.page.active{font:var(--sinch-font-emphasized-body);background-color:var(--sinch-color-snow-600);pointer-events:none;cursor:initial}.page.hidden{display:none}</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>';
16
+ import { defineCustomElement, updateAttribute, getIntegerAttribute, setClass, NectaryElement, getRect, getReactEventHandler } from '../utils';
17
+ 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-body);color:var(--sinch-color-stormy-500)}.page.dots>span{display:none}.page.dots::after{content:"..."}.page.active{font:var(--sinch-font-emphasized-body);background-color:var(--sinch-color-snow-600);pointer-events:none;cursor:initial}.page.hidden{display:none}</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>';
18
18
  const NUM_BUTTONS = 7;
19
19
  const MIDDLE_BTN_INDEX = Math.floor(NUM_BUTTONS / 2);
20
20
  const FIRST_BTN_INDEX = 0;
@@ -23,7 +23,7 @@ const DOTS_LEFT_INDEX = 1;
23
23
  const DOTS_RIGHT_INDEX = LAST_BTN_INDEX - 1;
24
24
  const template = document.createElement('template');
25
25
  template.innerHTML = templateHTML;
26
- defineCustomElement('sinch-pagination', (_$left = new WeakMap(), _$right = new WeakMap(), _$buttons = new WeakMap(), _$wrapper = new WeakMap(), _onValueChange = new WeakSet(), _onButtonClick = new WeakMap(), _clamp = new WeakSet(), _dispatchChangeEvent = new WeakSet(), class extends NectaryElement {
26
+ defineCustomElement('sinch-pagination', (_$left = new WeakMap(), _$right = new WeakMap(), _$buttons = new WeakMap(), _$wrapper = new WeakMap(), _onValueChange = new WeakSet(), _onButtonClick = new WeakMap(), _clamp = new WeakSet(), _dispatchChangeEvent = new WeakSet(), _onChangeReactHandler = new WeakMap(), class extends NectaryElement {
27
27
  constructor() {
28
28
  super();
29
29
 
@@ -92,6 +92,13 @@ defineCustomElement('sinch-pagination', (_$left = new WeakMap(), _$right = new W
92
92
  }
93
93
  });
94
94
 
95
+ _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
96
+ writable: true,
97
+ value: e => {
98
+ getReactEventHandler(this, 'on-change')?.(e);
99
+ }
100
+ });
101
+
95
102
  const shadowRoot = this.attachShadow();
96
103
  shadowRoot.appendChild(template.content.cloneNode(true));
97
104
 
@@ -108,10 +115,14 @@ defineCustomElement('sinch-pagination', (_$left = new WeakMap(), _$right = new W
108
115
  _classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this);
109
116
 
110
117
  _classPrivateFieldGet(this, _$wrapper).addEventListener('click', _classPrivateFieldGet(this, _onButtonClick));
118
+
119
+ this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
111
120
  }
112
121
 
113
122
  disconnectedCallback() {
114
123
  _classPrivateFieldGet(this, _$wrapper).removeEventListener('click', _classPrivateFieldGet(this, _onButtonClick));
124
+
125
+ this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
115
126
  }
116
127
 
117
128
  static get observedAttributes() {
@@ -217,14 +228,19 @@ function _onValueChange2() {
217
228
  _classPrivateFieldGet(this, _$right).disabled = isValueBad || value === max - 1;
218
229
  }
219
230
 
220
- function _clamp2(value, max) {
221
- return Math.max(0, Math.min(max - 1, value));
231
+ function _clamp2(value) {
232
+ const max = getIntegerAttribute(this, 'max', 0);
233
+ return Math.max(0, Math.min(max - 1, value)) + 1;
222
234
  }
223
235
 
224
236
  function _dispatchChangeEvent2(value) {
225
- const max = getIntegerAttribute(this, 'max', 0);
237
+ const detail = _classPrivateMethodGet(this, _clamp, _clamp2).call(this, value);
238
+
226
239
  this.dispatchEvent(new CustomEvent('change', {
227
- detail: _classPrivateMethodGet(this, _clamp, _clamp2).call(this, value, max) + 1,
240
+ detail,
228
241
  bubbles: true
229
242
  }));
243
+ this.dispatchEvent(new CustomEvent('-change', {
244
+ detail
245
+ }));
230
246
  }
@@ -7,11 +7,13 @@ export declare type TSinchPaginationElement = HTMLElement & {
7
7
  readonly nextButtonRect: TRect;
8
8
  nthButtonRect(index: number): TRect | null;
9
9
  addEventListener(type: 'change', listener: (e: CustomEvent<number>) => void): void;
10
+ addEventListener(type: '-change', listener: (e: CustomEvent<number>) => void): void;
10
11
  setAttribute(name: 'value', value: string): void;
11
12
  setAttribute(name: 'max', value: string): void;
12
13
  };
13
14
  export declare type TSinchPaginationReact = TSinchElementReact<TSinchPaginationElement> & {
14
15
  value: number;
15
16
  max: number;
16
- onChange: (event: SyntheticEvent<TSinchPaginationElement, CustomEvent<number>>) => void;
17
+ onChange?: (event: SyntheticEvent<TSinchPaginationElement, CustomEvent<number>>) => void;
18
+ 'on-change': (e: CustomEvent<number>) => void;
17
19
  };
package/popover/index.js CHANGED
@@ -159,8 +159,9 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
159
159
 
160
160
  _classPrivateFieldInitSpec(this, _onCloseReactHandler, {
161
161
  writable: true,
162
- value: () => {
162
+ value: e => {
163
163
  getReactEventHandler(this, 'onClose')?.();
164
+ getReactEventHandler(this, 'on-close')?.(e);
164
165
  }
165
166
  });
166
167
 
@@ -201,7 +202,7 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
201
202
 
202
203
  _classPrivateFieldGet(this, _$dialog).addEventListener('mousedown', _classPrivateFieldGet(this, _onBackdropMouseDown));
203
204
 
204
- this.addEventListener('close', _classPrivateFieldGet(this, _onCloseReactHandler));
205
+ this.addEventListener('-close', _classPrivateFieldGet(this, _onCloseReactHandler));
205
206
 
206
207
  _classPrivateFieldSet(this, _isConnected, true);
207
208
 
@@ -217,7 +218,7 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
217
218
 
218
219
  _classPrivateFieldGet(this, _$dialog).removeEventListener('mousedown', _classPrivateFieldGet(this, _onBackdropMouseDown));
219
220
 
220
- this.removeEventListener('close', _classPrivateFieldGet(this, _onCloseReactHandler));
221
+ this.removeEventListener('-close', _classPrivateFieldGet(this, _onCloseReactHandler));
221
222
 
222
223
  _classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
223
224
 
@@ -356,7 +357,5 @@ function _isOpen2() {
356
357
  }
357
358
 
358
359
  function _dispatchCloseEvent2() {
359
- this.dispatchEvent(new CustomEvent('close', {
360
- bubbles: true
361
- }));
360
+ this.dispatchEvent(new CustomEvent('-close'));
362
361
  }
@@ -1,5 +1,4 @@
1
1
  import type { TRect, TSinchElementReact } from '../types';
2
- import type { SyntheticEvent } from 'react';
3
2
  export declare type TSinchPopoverOrientation = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'bottom' | 'top';
4
3
  export declare type TSinchPopoverElement = HTMLElement & {
5
4
  /** Open/close state */
@@ -10,7 +9,7 @@ export declare type TSinchPopoverElement = HTMLElement & {
10
9
  modal: boolean;
11
10
  readonly popoverRect: TRect;
12
11
  /** Close event */
13
- addEventListener(type: 'close', listener: (e: CustomEvent<void>) => void): void;
12
+ addEventListener(type: '-close', listener: (e: CustomEvent<void>) => void): void;
14
13
  /** Open/close state */
15
14
  setAttribute(name: 'open', value: ''): void;
16
15
  /** Orientation, where it *points to* from origin */
@@ -28,5 +27,7 @@ export declare type TSinchPopoverReact = TSinchElementReact<TSinchPopoverElement
28
27
  /** Label that is used for a11y */
29
28
  'aria-label': string;
30
29
  /** Close event handler */
31
- onClose?: (event: SyntheticEvent<TSinchPopoverElement, CustomEvent<void>>) => void;
30
+ onClose?: () => void;
31
+ /** Close event handler */
32
+ 'on-close'?: (e: CustomEvent<void>) => void;
32
33
  };
package/radio/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
2
1
  import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
+ import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
3
 
4
- var _$slot, _onOptionKeyDown, _onSlotChange, _onOptionChange, _onValueChange, _dispatchChangeEvent, _getFirstOption, _getLastOption, _getNextOption, _getPrevOption, _getEnabledRadioElements, _findSelectedOption;
4
+ var _$slot, _onOptionKeyDown, _onSlotChange, _onOptionChange, _onValueChange, _dispatchChangeEvent, _getFirstOption, _getLastOption, _getNextOption, _getPrevOption, _getEnabledRadioElements, _findSelectedOption, _onChangeReactHandler;
5
5
 
6
6
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
7
7
 
@@ -11,11 +11,11 @@ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollect
11
11
 
12
12
  function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
13
13
 
14
- import { defineCustomElement, getAttribute, getBooleanAttribute, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
14
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
15
15
  const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:column;gap:8px;box-sizing:border-box;width:100%}</style><div id="wrapper"><slot></slot></div>';
16
16
  const template = document.createElement('template');
17
17
  template.innerHTML = templateHTML;
18
- defineCustomElement('sinch-radio', (_$slot = new WeakMap(), _onOptionKeyDown = new WeakMap(), _onSlotChange = new WeakMap(), _onOptionChange = new WeakMap(), _onValueChange = new WeakSet(), _dispatchChangeEvent = new WeakSet(), _getFirstOption = new WeakSet(), _getLastOption = new WeakSet(), _getNextOption = new WeakSet(), _getPrevOption = new WeakSet(), _getEnabledRadioElements = new WeakSet(), _findSelectedOption = new WeakSet(), class extends NectaryElement {
18
+ defineCustomElement('sinch-radio', (_$slot = new WeakMap(), _onOptionKeyDown = new WeakMap(), _onSlotChange = new WeakMap(), _onOptionChange = new WeakMap(), _onValueChange = new WeakSet(), _dispatchChangeEvent = new WeakSet(), _getFirstOption = new WeakSet(), _getLastOption = new WeakSet(), _getNextOption = new WeakSet(), _getPrevOption = new WeakSet(), _getEnabledRadioElements = new WeakSet(), _findSelectedOption = new WeakSet(), _onChangeReactHandler = new WeakMap(), class extends NectaryElement {
19
19
  constructor() {
20
20
  super();
21
21
 
@@ -95,18 +95,39 @@ defineCustomElement('sinch-radio', (_$slot = new WeakMap(), _onOptionKeyDown = n
95
95
  }
96
96
  });
97
97
 
98
+ _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
99
+ writable: true,
100
+ value: e => {
101
+ getReactEventHandler(this, 'on-change')?.(e);
102
+ }
103
+ });
104
+
98
105
  const shadowRoot = this.attachShadow();
99
106
  shadowRoot.appendChild(template.content.cloneNode(true));
100
- shadowRoot.addEventListener('keydown', _classPrivateFieldGet(this, _onOptionKeyDown));
101
- shadowRoot.addEventListener('change', _classPrivateFieldGet(this, _onOptionChange));
102
107
 
103
108
  _classPrivateFieldSet(this, _$slot, shadowRoot.querySelector('slot'));
104
-
105
- _classPrivateFieldGet(this, _$slot).addEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
106
109
  }
107
110
 
108
111
  connectedCallback() {
109
112
  this.setAttribute('role', 'radiogroup');
113
+
114
+ _classPrivateFieldGet(this, _$slot).addEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
115
+
116
+ _classPrivateFieldGet(this, _$slot).addEventListener('keydown', _classPrivateFieldGet(this, _onOptionKeyDown));
117
+
118
+ _classPrivateFieldGet(this, _$slot).addEventListener('option-change', _classPrivateFieldGet(this, _onOptionChange));
119
+
120
+ this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
121
+ }
122
+
123
+ disconnectedCallback() {
124
+ _classPrivateFieldGet(this, _$slot).removeEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
125
+
126
+ _classPrivateFieldGet(this, _$slot).removeEventListener('keydown', _classPrivateFieldGet(this, _onOptionKeyDown));
127
+
128
+ _classPrivateFieldGet(this, _$slot).removeEventListener('option-change', _classPrivateFieldGet(this, _onOptionChange));
129
+
130
+ this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
110
131
  }
111
132
 
112
133
  static get observedAttributes() {
@@ -126,6 +147,10 @@ defineCustomElement('sinch-radio', (_$slot = new WeakMap(), _onOptionKeyDown = n
126
147
  }
127
148
 
128
149
  attributeChangedCallback(name, oldVal, newVal) {
150
+ if (oldVal === newVal) {
151
+ return;
152
+ }
153
+
129
154
  switch (name) {
130
155
  case 'value':
131
156
  {
@@ -150,6 +175,9 @@ function _dispatchChangeEvent2(value) {
150
175
  detail: value,
151
176
  bubbles: true
152
177
  }));
178
+ this.dispatchEvent(new CustomEvent('-change', {
179
+ detail: value
180
+ }));
153
181
  }
154
182
 
155
183
  function _getFirstOption2() {
package/radio/types.d.ts CHANGED
@@ -3,10 +3,12 @@ import type { SyntheticEvent } from 'react';
3
3
  export declare type TSinchRadioElement = HTMLElement & {
4
4
  value: string;
5
5
  addEventListener(type: 'change', listener: (e: CustomEvent<boolean>) => void): void;
6
+ addEventListener(type: '-change', listener: (e: CustomEvent<boolean>) => void): void;
6
7
  setAttribute(name: 'value', value: string): void;
7
8
  };
8
9
  export declare type TSinchRadioReact = TSinchElementReact<TSinchRadioElement> & {
9
10
  value: string;
10
11
  'aria-label': string;
11
- onChange: (event: SyntheticEvent<TSinchRadioElement, CustomEvent<boolean>>) => void;
12
+ onChange?: (event: SyntheticEvent<TSinchRadioElement, CustomEvent<boolean>>) => void;
13
+ 'on-change'?: (e: CustomEvent<string>) => void;
12
14
  };
@@ -30,7 +30,7 @@ defineCustomElement('sinch-radio-option', (_$input = new WeakMap(), _$label = ne
30
30
  value: e => {
31
31
  e.stopPropagation();
32
32
  _classPrivateFieldGet(this, _$input).checked = false;
33
- this.dispatchEvent(new CustomEvent('change', {
33
+ this.dispatchEvent(new CustomEvent('option-change', {
34
34
  bubbles: true,
35
35
  detail: this.value
36
36
  }));
package/search/types.d.ts CHANGED
@@ -9,7 +9,6 @@ export declare type TSinchSearchElement = HTMLElement & {
9
9
  selectionEnd: HTMLInputElement['selectionEnd'];
10
10
  selectionDirection: HTMLInputElement['selectionDirection'];
11
11
  readonly dropdownRect: TRect;
12
- addEventListener(type: 'change', listener: (e: CustomEvent<string>) => void): void;
13
12
  setAttribute(name: 'value', value: string): void;
14
13
  setAttribute(name: 'label', value: string): void;
15
14
  setAttribute(name: 'placeholder', value: string): void;
@@ -1,8 +1,7 @@
1
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
1
  import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
3
2
  import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
4
3
 
5
- var _$button;
4
+ var _$button, _onClick, _onChangeReactHandler;
6
5
 
7
6
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
8
7
 
@@ -11,11 +10,11 @@ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollect
11
10
  import '../icons/expand-less';
12
11
  import '../icons/expand-more';
13
12
  import '../icon-button';
14
- import { defineCustomElement, getBooleanAttribute, isAttrTrue, NectaryElement, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
13
+ import { defineCustomElement, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
15
14
  const templateHTML = '<style>:host{display:block;--sinch-size-icon:32px}#up{display:block}#down{display:none}:host([value]:not([value=false])) #up{display:none}:host([value]:not([value=false])) #down{display:block}</style><sinch-icon-button id="button" small><sinch-icon-expand-less id="up" slot="icon"></sinch-icon-expand-less><sinch-icon-expand-more id="down" slot="icon"></sinch-icon-expand-more></sinch-icon-button>';
16
15
  const template = document.createElement('template');
17
16
  template.innerHTML = templateHTML;
18
- defineCustomElement('sinch-segment-collapse', (_$button = new WeakMap(), class extends NectaryElement {
17
+ defineCustomElement('sinch-segment-collapse', (_$button = new WeakMap(), _onClick = new WeakMap(), _onChangeReactHandler = new WeakMap(), class extends NectaryElement {
19
18
  constructor() {
20
19
  super();
21
20
 
@@ -24,12 +23,25 @@ defineCustomElement('sinch-segment-collapse', (_$button = new WeakMap(), class e
24
23
  value: void 0
25
24
  });
26
25
 
27
- _defineProperty(this, 'onClick', e => {
28
- e.stopPropagation();
29
- this.dispatchEvent(new CustomEvent('change', {
30
- detail: !this.value,
31
- bubbles: true
32
- }));
26
+ _classPrivateFieldInitSpec(this, _onClick, {
27
+ writable: true,
28
+ value: () => {
29
+ const detail = !this.value;
30
+ this.dispatchEvent(new CustomEvent('change', {
31
+ detail,
32
+ bubbles: true
33
+ }));
34
+ this.dispatchEvent(new CustomEvent('-change', {
35
+ detail
36
+ }));
37
+ }
38
+ });
39
+
40
+ _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
41
+ writable: true,
42
+ value: e => {
43
+ getReactEventHandler(this, 'on-change')?.(e);
44
+ }
33
45
  });
34
46
 
35
47
  const shadowRoot = this.attachShadow();
@@ -41,11 +53,15 @@ defineCustomElement('sinch-segment-collapse', (_$button = new WeakMap(), class e
41
53
  connectedCallback() {
42
54
  this.setAttribute('role', 'checkbox');
43
55
 
44
- _classPrivateFieldGet(this, _$button).addEventListener('click', this.onClick);
56
+ _classPrivateFieldGet(this, _$button).addEventListener('click', _classPrivateFieldGet(this, _onClick));
57
+
58
+ this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
45
59
  }
46
60
 
47
61
  disconnectedCallback() {
48
- _classPrivateFieldGet(this, _$button).removeEventListener('click', this.onClick);
62
+ _classPrivateFieldGet(this, _$button).removeEventListener('click', _classPrivateFieldGet(this, _onClick));
63
+
64
+ this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
49
65
  }
50
66
 
51
67
  static get observedAttributes() {
@@ -3,10 +3,12 @@ import type { SyntheticEvent } from 'react';
3
3
  export declare type TSinchSegmentExpandElement = HTMLElement & {
4
4
  value: boolean;
5
5
  addEventListener(type: 'change', listener: (e: CustomEvent<boolean>) => void): void;
6
+ addEventListener(type: '-change', listener: (e: CustomEvent<boolean>) => void): void;
6
7
  setAttribute(name: 'value', value: string): void;
7
8
  };
8
9
  export declare type TSinchSegmentExpandReact = TSinchElementReact<TSinchSegmentExpandElement> & {
9
10
  value: boolean;
10
11
  'aria-label': string;
11
- onChange: (e: SyntheticEvent<TSinchSegmentExpandElement, CustomEvent<boolean>>) => void;
12
+ onChange?: (e: SyntheticEvent<TSinchSegmentExpandElement, CustomEvent<boolean>>) => void;
13
+ 'on-change'?: (e: CustomEvent<boolean>) => void;
12
14
  };
@@ -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 _$slot, _$sh, _onSlotChange, _onOptionChange, _onValueChange, _dispatchChangeEvent;
4
+ var _$slot, _onSlotChange, _onOptionChange, _onValueChange, _onChangeReactHandler;
5
5
 
6
6
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
7
7
 
@@ -11,16 +11,14 @@ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollect
11
11
 
12
12
  function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
13
13
 
14
- import { defineCustomElement, getAttribute, getBooleanAttribute, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
14
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
15
15
  const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;width:100%;box-sizing:border-box}</style><div id="wrapper"><slot></slot></div>';
16
16
  const template = document.createElement('template');
17
17
  template.innerHTML = templateHTML;
18
- defineCustomElement('sinch-segmented-control', (_$slot = new WeakMap(), _$sh = new WeakMap(), _onSlotChange = new WeakMap(), _onOptionChange = new WeakMap(), _onValueChange = new WeakSet(), _dispatchChangeEvent = new WeakSet(), class extends NectaryElement {
18
+ defineCustomElement('sinch-segmented-control', (_$slot = new WeakMap(), _onSlotChange = new WeakMap(), _onOptionChange = new WeakMap(), _onValueChange = new WeakSet(), _onChangeReactHandler = new WeakMap(), class extends NectaryElement {
19
19
  constructor() {
20
20
  super();
21
21
 
22
- _classPrivateMethodInitSpec(this, _dispatchChangeEvent);
23
-
24
22
  _classPrivateMethodInitSpec(this, _onValueChange);
25
23
 
26
24
  _classPrivateFieldInitSpec(this, _$slot, {
@@ -28,11 +26,6 @@ defineCustomElement('sinch-segmented-control', (_$slot = new WeakMap(), _$sh = n
28
26
  value: void 0
29
27
  });
30
28
 
31
- _classPrivateFieldInitSpec(this, _$sh, {
32
- writable: true,
33
- value: void 0
34
- });
35
-
36
29
  _classPrivateFieldInitSpec(this, _onSlotChange, {
37
30
  writable: true,
38
31
  value: () => {
@@ -44,31 +37,46 @@ defineCustomElement('sinch-segmented-control', (_$slot = new WeakMap(), _$sh = n
44
37
  writable: true,
45
38
  value: e => {
46
39
  e.stopPropagation();
40
+ const detail = e.detail;
41
+ this.dispatchEvent(new CustomEvent('change', {
42
+ detail,
43
+ bubbles: true
44
+ }));
45
+ this.dispatchEvent(new CustomEvent('-change', {
46
+ detail
47
+ }));
48
+ }
49
+ });
47
50
 
48
- _classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, e.detail);
51
+ _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
52
+ writable: true,
53
+ value: e => {
54
+ getReactEventHandler(this, 'on-change')?.(e);
49
55
  }
50
56
  });
51
57
 
52
58
  const shadowRoot = this.attachShadow();
53
59
  shadowRoot.appendChild(template.content.cloneNode(true));
54
60
 
55
- _classPrivateFieldSet(this, _$sh, shadowRoot);
56
-
57
61
  _classPrivateFieldSet(this, _$slot, shadowRoot.querySelector('slot'));
58
62
  }
59
63
 
60
64
  connectedCallback() {
61
65
  this.setAttribute('role', 'tablist');
62
66
 
63
- _classPrivateFieldGet(this, _$sh).addEventListener('change', _classPrivateFieldGet(this, _onOptionChange));
67
+ _classPrivateFieldGet(this, _$slot).addEventListener('option-change', _classPrivateFieldGet(this, _onOptionChange));
64
68
 
65
69
  _classPrivateFieldGet(this, _$slot).addEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
70
+
71
+ this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
66
72
  }
67
73
 
68
74
  disconnectedCallback() {
69
- _classPrivateFieldGet(this, _$sh).removeEventListener('change', _classPrivateFieldGet(this, _onOptionChange));
75
+ _classPrivateFieldGet(this, _$slot).removeEventListener('option-change', _classPrivateFieldGet(this, _onOptionChange));
70
76
 
71
77
  _classPrivateFieldGet(this, _$slot).removeEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
78
+
79
+ this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
72
80
  }
73
81
 
74
82
  static get observedAttributes() {
@@ -88,6 +96,10 @@ defineCustomElement('sinch-segmented-control', (_$slot = new WeakMap(), _$sh = n
88
96
  }
89
97
 
90
98
  attributeChangedCallback(name, oldVal, newVal) {
99
+ if (oldVal === newVal) {
100
+ return;
101
+ }
102
+
91
103
  switch (name) {
92
104
  case 'value':
93
105
  {
@@ -103,13 +115,6 @@ defineCustomElement('sinch-segmented-control', (_$slot = new WeakMap(), _$sh = n
103
115
  function _onValueChange2(value) {
104
116
  for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements()) {
105
117
  const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
106
- updateBooleanAttribute($option, 'checked', isChecked);
118
+ updateBooleanAttribute($option, 'data-checked', isChecked);
107
119
  }
108
- }
109
-
110
- function _dispatchChangeEvent2(value) {
111
- this.dispatchEvent(new CustomEvent('change', {
112
- detail: value,
113
- bubbles: true
114
- }));
115
120
  }
@@ -2,11 +2,12 @@ import type { TSinchElementReact } from '../types';
2
2
  import type { SyntheticEvent } from 'react';
3
3
  export declare type TSinchSegmentedControlElement = HTMLElement & {
4
4
  value: string;
5
- addEventListener(type: 'change', listener: (e: CustomEvent<string>) => void): void;
5
+ addEventListener(type: '-change', listener: (e: CustomEvent<string>) => void): void;
6
6
  setAttribute(name: 'value', value: string): void;
7
7
  };
8
8
  export declare type TSinchSegmentedControlReact = TSinchElementReact<TSinchSegmentedControlElement> & {
9
9
  value: string;
10
10
  'aria-label': string;
11
- onChange: (event: SyntheticEvent<TSinchSegmentedControlElement, CustomEvent<string>>) => void;
11
+ onChange?: (event: SyntheticEvent<TSinchSegmentedControlElement, CustomEvent<string>>) => void;
12
+ 'on-change'?: (e: CustomEvent<string>) => void;
12
13
  };
@@ -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 _$button, _$label, _onClick;
4
+ var _$button, _$label, _onButtonClick, _onButtonFocus, _onButtonBlur, _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';
11
- const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;position:relative;flex-direction:row;align-items:center;gap:12px;width:100%;height:32px;padding:0 16px;box-sizing:border-box;border:1px solid var(--sinch-color-snow-600);border-left-width:0;border-right-width:0;color:var(--sinch-color-stormy-500);background-color:var(--sinch-color-snow-100);--sinch-color-icon:var(--sinch-color-stormy-500);--sinch-size-icon:16px}#wrapper:hover{background-color:var(--sinch-color-snow-500)}:host(:first-child) #wrapper{border-left-width:1px;border-top-left-radius:4px;border-bottom-left-radius:4px}:host(:last-child) #wrapper{border-right-width:1px;border-top-right-radius:4px;border-bottom-right-radius:4px}#content{font:var(--sinch-font-title-s);flex-shrink:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}:host([checked]:not([checked=false])) #wrapper{border-color:var(--sinch-color-stormy-500)}:host([checked]:not([checked=false]):not(:first-child)) #wrapper::before{content:"";width:1px;background-color:var(--sinch-color-stormy-500);position:absolute;left:0;top:-1px;bottom:-1px}:host([checked]:not([checked=false]):not(:last-child)) #wrapper::after{content:"";width:1px;background-color:var(--sinch-color-stormy-500);position:absolute;right:0;top:-1px;bottom:-1px}#button{all:initial;position:absolute;left:0;top:0;box-sizing:border-box;width:100%;height:100%;cursor:pointer;z-index:1}#button:disabled{cursor:unset}#button:focus::before{content:"";position:absolute;left:-3px;right:-3px;top:-4px;bottom:-4px;border-style:solid;border-color:var(--sinch-color-aqua-400);border-width:0}#button:focus-visible::before{border-width:2px}:host(:first-child) #button:focus::before{left:-4px;border-top-left-radius:6px;border-bottom-left-radius:6px}:host(:last-child) #button:focus::before{right:-4px;border-top-right-radius:6px;border-bottom-right-radius:6px}@supports not selector(:focus-visible){#button:focus::before{border-width:2px}}:host([disabled]:not([disabled=false])) #wrapper{background-color:var(--sinch-color-snow-100);color:var(--sinch-color-stormy-100);--sinch-color-icon:var(--sinch-color-stormy-100)}</style><div id="wrapper"><slot name="icon"></slot><label for="button" id="content"></label> <button id="button"></button></div>';
10
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
11
+ const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;position:relative;flex-direction:row;align-items:center;gap:12px;width:100%;height:32px;padding:0 16px;box-sizing:border-box;border:1px solid var(--sinch-color-snow-600);border-left-width:0;border-right-width:0;color:var(--sinch-color-stormy-500);background-color:var(--sinch-color-snow-100);--sinch-color-icon:var(--sinch-color-stormy-500);--sinch-size-icon:16px}#wrapper:hover{background-color:var(--sinch-color-snow-500)}:host(:first-child) #wrapper{border-left-width:1px;border-top-left-radius:4px;border-bottom-left-radius:4px}:host(:last-child) #wrapper{border-right-width:1px;border-top-right-radius:4px;border-bottom-right-radius:4px}#content{font:var(--sinch-font-title-s);flex-shrink:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}:host([data-checked]) #wrapper{border-color:var(--sinch-color-stormy-500)}:host([data-checked]:not(:first-child)) #wrapper::before{content:"";width:1px;background-color:var(--sinch-color-stormy-500);position:absolute;left:0;top:-1px;bottom:-1px}:host([data-checked]:not(:last-child)) #wrapper::after{content:"";width:1px;background-color:var(--sinch-color-stormy-500);position:absolute;right:0;top:-1px;bottom:-1px}#button{all:initial;position:absolute;left:0;top:0;box-sizing:border-box;width:100%;height:100%;cursor:pointer;z-index:1}#button:disabled{cursor:unset}#button:focus::before{content:"";position:absolute;left:-3px;right:-3px;top:-4px;bottom:-4px;border-style:solid;border-color:var(--sinch-color-aqua-400);border-width:0}#button:focus-visible::before{border-width:2px}:host(:first-child) #button:focus::before{left:-4px;border-top-left-radius:6px;border-bottom-left-radius:6px}:host(:last-child) #button:focus::before{right:-4px;border-top-right-radius:6px;border-bottom-right-radius:6px}@supports not selector(:focus-visible){#button:focus::before{border-width:2px}}:host([disabled]:not([disabled=false])) #wrapper{background-color:var(--sinch-color-snow-100);color:var(--sinch-color-stormy-100);--sinch-color-icon:var(--sinch-color-stormy-100)}</style><div id="wrapper"><slot name="icon"></slot><label for="button" id="content"></label><button id="button"></button></div>';
12
12
  const template = document.createElement('template');
13
13
  template.innerHTML = templateHTML;
14
- defineCustomElement('sinch-segmented-control-option', (_$button = new WeakMap(), _$label = new WeakMap(), _onClick = new WeakMap(), class extends NectaryElement {
14
+ defineCustomElement('sinch-segmented-control-option', (_$button = new WeakMap(), _$label = new WeakMap(), _onButtonClick = new WeakMap(), _onButtonFocus = new WeakMap(), _onButtonBlur = new WeakMap(), _onFocusReactHandler = new WeakMap(), _onBlurReactHandler = new WeakMap(), class extends NectaryElement {
15
15
  constructor() {
16
16
  super();
17
17
 
@@ -25,17 +25,45 @@ defineCustomElement('sinch-segmented-control-option', (_$button = new WeakMap(),
25
25
  value: void 0
26
26
  });
27
27
 
28
- _classPrivateFieldInitSpec(this, _onClick, {
28
+ _classPrivateFieldInitSpec(this, _onButtonClick, {
29
29
  writable: true,
30
30
  value: e => {
31
31
  e.stopPropagation();
32
- this.dispatchEvent(new CustomEvent('change', {
33
- bubbles: true,
34
- detail: this.value
32
+ this.dispatchEvent(new CustomEvent('option-change', {
33
+ detail: this.value,
34
+ bubbles: true
35
35
  }));
36
36
  }
37
37
  });
38
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
+
39
67
  const shadowRoot = this.attachShadow();
40
68
  shadowRoot.appendChild(template.content.cloneNode(true));
41
69
 
@@ -47,15 +75,29 @@ defineCustomElement('sinch-segmented-control-option', (_$button = new WeakMap(),
47
75
  connectedCallback() {
48
76
  this.setAttribute('role', 'tab');
49
77
 
50
- _classPrivateFieldGet(this, _$button).addEventListener('click', _classPrivateFieldGet(this, _onClick));
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));
51
86
  }
52
87
 
53
88
  disconnectedCallback() {
54
- _classPrivateFieldGet(this, _$button).removeEventListener('click', _classPrivateFieldGet(this, _onClick));
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));
55
97
  }
56
98
 
57
99
  static get observedAttributes() {
58
- return ['checked', 'disabled', 'text', 'value'];
100
+ return ['data-checked', 'disabled', 'text'];
59
101
  }
60
102
 
61
103
  set value(value) {
@@ -82,7 +124,11 @@ defineCustomElement('sinch-segmented-control-option', (_$button = new WeakMap(),
82
124
  return getAttribute(this, 'text', '');
83
125
  }
84
126
 
85
- attributeChangedCallback(name, _, newVal) {
127
+ attributeChangedCallback(name, oldVal, newVal) {
128
+ if (oldVal === newVal) {
129
+ return;
130
+ }
131
+
86
132
  switch (name) {
87
133
  case 'text':
88
134
  {
@@ -90,7 +136,7 @@ defineCustomElement('sinch-segmented-control-option', (_$button = new WeakMap(),
90
136
  break;
91
137
  }
92
138
 
93
- case 'checked':
139
+ case 'data-checked':
94
140
  {
95
141
  updateExplicitBooleanAttribute(this, 'aria-selected', isAttrTrue(newVal));
96
142
  break;