@nectary/components 0.39.0 → 0.40.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 (115) hide show
  1. package/accordion/index.js +47 -84
  2. package/accordion-item/index.js +26 -53
  3. package/action-menu/index.d.ts +0 -1
  4. package/action-menu/index.js +179 -223
  5. package/action-menu/types.d.ts +8 -18
  6. package/action-menu-option/index.d.ts +1 -0
  7. package/action-menu-option/index.js +51 -62
  8. package/action-menu-option/types.d.ts +9 -0
  9. package/action-menu-option/utils.d.ts +2 -0
  10. package/action-menu-option/utils.js +3 -0
  11. package/alert/index.js +6 -20
  12. package/avatar/index.js +12 -31
  13. package/avatar-badge/index.js +8 -22
  14. package/avatar-status/index.js +1 -1
  15. package/button/index.js +42 -92
  16. package/card/index.js +21 -59
  17. package/chat-avatar/index.js +8 -22
  18. package/chat-block/index.js +29 -69
  19. package/chat-bubble/index.js +6 -20
  20. package/checkbox/index.js +55 -107
  21. package/chip/index.d.ts +13 -0
  22. package/chip/index.js +137 -0
  23. package/chip/types.d.ts +38 -0
  24. package/color-menu/index.d.ts +13 -0
  25. package/color-menu/index.js +464 -0
  26. package/color-menu/types.d.ts +37 -0
  27. package/color-swatch/index.d.ts +13 -0
  28. package/color-swatch/index.js +59 -0
  29. package/color-swatch/types.d.ts +12 -0
  30. package/colors.json +57 -49
  31. package/date-picker/index.js +161 -292
  32. package/dialog/index.js +70 -142
  33. package/dropdown-checkbox-option/index.js +6 -20
  34. package/dropdown-radio-option/index.js +6 -20
  35. package/field/index.js +25 -63
  36. package/file-drop/index.js +123 -200
  37. package/file-picker/index.d.ts +0 -1
  38. package/file-picker/index.js +55 -108
  39. package/file-status/index.js +15 -39
  40. package/help-tooltip/index.js +1 -1
  41. package/horizontal-stepper/index.js +33 -59
  42. package/horizontal-stepper-item/index.js +13 -37
  43. package/icon-button/index.js +39 -84
  44. package/icons-channel/notify/index.d.ts +11 -0
  45. package/icons-channel/notify/index.js +4 -0
  46. package/illustrations/create-illustration-class.js +1 -1
  47. package/inline-alert/index.js +29 -81
  48. package/input/index.js +113 -222
  49. package/link/index.js +46 -96
  50. package/list-item/index.js +1 -1
  51. package/package.json +12 -14
  52. package/pagination/index.js +109 -163
  53. package/popover/index.js +224 -294
  54. package/progress/index.js +9 -28
  55. package/radio/index.js +103 -169
  56. package/radio-option/index.js +24 -48
  57. package/segment/index.js +49 -130
  58. package/segment-collapse/index.js +24 -49
  59. package/segmented-control/index.js +36 -73
  60. package/segmented-control-option/index.js +41 -87
  61. package/segmented-icon-control/index.js +47 -84
  62. package/segmented-icon-control-option/index.js +38 -79
  63. package/select-button/index.d.ts +13 -0
  64. package/select-button/index.js +153 -0
  65. package/select-button/types.d.ts +43 -0
  66. package/select-menu/index.d.ts +11 -0
  67. package/select-menu/index.js +346 -0
  68. package/select-menu/types.d.ts +29 -0
  69. package/select-menu/types.js +1 -0
  70. package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
  71. package/select-menu-option/index.js +76 -0
  72. package/{select-option → select-menu-option}/types.d.ts +8 -9
  73. package/stop-events/index.js +7 -20
  74. package/table-head-cell/index.js +7 -21
  75. package/tabs/index.js +103 -165
  76. package/tabs-option/index.js +20 -44
  77. package/tag/index.d.ts +0 -1
  78. package/tag/index.js +37 -38
  79. package/tag/types.d.ts +13 -7
  80. package/textarea/index.js +92 -167
  81. package/theme.css +80 -49
  82. package/tile-control/index.js +55 -96
  83. package/tile-control-option/index.js +40 -86
  84. package/time-picker/index.js +216 -368
  85. package/title/index.js +6 -20
  86. package/toast/index.js +32 -70
  87. package/toast-manager/index.js +141 -217
  88. package/toggle/index.js +54 -106
  89. package/types.d.ts +7 -0
  90. package/utils/colors.d.ts +10 -0
  91. package/utils/colors.js +121 -0
  92. package/{utils.d.ts → utils/index.d.ts} +17 -9
  93. package/{utils.js → utils/index.js} +96 -39
  94. package/vertical-stepper/index.js +29 -50
  95. package/vertical-stepper-item/index.js +13 -37
  96. package/dropdown/index.d.ts +0 -12
  97. package/dropdown/index.js +0 -415
  98. package/dropdown/types.d.ts +0 -32
  99. package/dropdown-text-option/index.js +0 -104
  100. package/dropdown-text-option/types.d.ts +0 -16
  101. package/select/index.d.ts +0 -13
  102. package/select/index.js +0 -316
  103. package/select/types.d.ts +0 -53
  104. package/select-option/index.d.ts +0 -11
  105. package/select-option/index.js +0 -8
  106. package/tag/utils.d.ts +0 -5
  107. package/tag/utils.js +0 -6
  108. package/tag-close/index.d.ts +0 -12
  109. package/tag-close/index.js +0 -42
  110. package/tag-close/types.d.ts +0 -5
  111. /package/{dropdown-text-option → chip}/types.js +0 -0
  112. /package/{dropdown → color-menu}/types.js +0 -0
  113. /package/{select-option → color-swatch}/types.js +0 -0
  114. /package/{select → select-button}/types.js +0 -0
  115. /package/{tag-close → select-menu-option}/types.js +0 -0
@@ -1,84 +1,28 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$slot, _onSlotChange, _onOptionChange, _onValueChange, _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
1
  import { defineCustomElement, getAttribute, getBooleanAttribute, getCsvSet, getFirstCsvValue, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv } from '../utils';
15
2
  const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row}</style><div id="wrapper"><slot></slot></div>';
16
3
  const template = document.createElement('template');
17
4
  template.innerHTML = templateHTML;
18
- defineCustomElement('sinch-segmented-icon-control', (_$slot = new WeakMap(), _onSlotChange = new WeakMap(), _onOptionChange = new WeakMap(), _onValueChange = new WeakSet(), _onChangeReactHandler = new WeakMap(), class extends NectaryElement {
5
+ defineCustomElement('sinch-segmented-icon-control', class extends NectaryElement {
6
+ #$slot;
7
+
19
8
  constructor() {
20
9
  super();
21
-
22
- _classPrivateMethodInitSpec(this, _onValueChange);
23
-
24
- _classPrivateFieldInitSpec(this, _$slot, {
25
- writable: true,
26
- value: void 0
27
- });
28
-
29
- _classPrivateFieldInitSpec(this, _onSlotChange, {
30
- writable: true,
31
- value: () => {
32
- _classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this, this.value);
33
- }
34
- });
35
-
36
- _classPrivateFieldInitSpec(this, _onOptionChange, {
37
- writable: true,
38
- value: e => {
39
- e.stopPropagation();
40
- const $elem = e.target;
41
- const value = e.detail;
42
- const detail = this.multiple ? updateCsv(this.value, value, !getBooleanAttribute($elem, 'data-checked')) : value;
43
- this.dispatchEvent(new CustomEvent('change', {
44
- detail,
45
- bubbles: true
46
- }));
47
- this.dispatchEvent(new CustomEvent('-change', {
48
- detail
49
- }));
50
- }
51
- });
52
-
53
- _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
54
- writable: true,
55
- value: e => {
56
- getReactEventHandler(this, 'on-change')?.(e);
57
- }
58
- });
59
-
60
10
  const shadowRoot = this.attachShadow();
61
11
  shadowRoot.appendChild(template.content.cloneNode(true));
62
-
63
- _classPrivateFieldSet(this, _$slot, shadowRoot.querySelector('slot'));
12
+ this.#$slot = shadowRoot.querySelector('slot');
64
13
  }
65
14
 
66
15
  connectedCallback() {
67
16
  this.setAttribute('role', 'tablist');
68
-
69
- _classPrivateFieldGet(this, _$slot).addEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
70
-
71
- _classPrivateFieldGet(this, _$slot).addEventListener('option-change', _classPrivateFieldGet(this, _onOptionChange));
72
-
73
- this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
17
+ this.#$slot.addEventListener('slotchange', this.#onSlotChange);
18
+ this.#$slot.addEventListener('option-change', this.#onOptionChange);
19
+ this.addEventListener('-change', this.#onChangeReactHandler);
74
20
  }
75
21
 
76
22
  disconnectedCallback() {
77
- _classPrivateFieldGet(this, _$slot).removeEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
78
-
79
- _classPrivateFieldGet(this, _$slot).removeEventListener('option-change', _classPrivateFieldGet(this, _onOptionChange));
80
-
81
- this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
23
+ this.#$slot.removeEventListener('slotchange', this.#onSlotChange);
24
+ this.#$slot.removeEventListener('option-change', this.#onOptionChange);
25
+ this.removeEventListener('-change', this.#onChangeReactHandler);
82
26
  }
83
27
 
84
28
  static get observedAttributes() {
@@ -113,29 +57,48 @@ defineCustomElement('sinch-segmented-icon-control', (_$slot = new WeakMap(), _on
113
57
  switch (name) {
114
58
  case 'value':
115
59
  {
116
- _classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this, newVal ?? '');
117
-
60
+ this.#onValueChange(newVal ?? '');
118
61
  break;
119
62
  }
120
63
  }
121
64
  }
122
65
 
123
- }));
124
-
125
- function _onValueChange2(csv) {
126
- if (this.multiple) {
127
- const values = getCsvSet(csv);
128
-
129
- for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements()) {
130
- const isChecked = !getBooleanAttribute($option, 'disabled') && values.has(getAttribute($option, 'value', ''));
131
- updateBooleanAttribute($option, 'data-checked', isChecked);
132
- }
133
- } else {
134
- const value = getFirstCsvValue(csv);
66
+ #onSlotChange = () => {
67
+ this.#onValueChange(this.value);
68
+ };
69
+ #onOptionChange = e => {
70
+ e.stopPropagation();
71
+ const $elem = e.target;
72
+ const value = e.detail;
73
+ const detail = this.multiple ? updateCsv(this.value, value, !getBooleanAttribute($elem, 'data-checked')) : value;
74
+ this.dispatchEvent(new CustomEvent('change', {
75
+ detail,
76
+ bubbles: true
77
+ }));
78
+ this.dispatchEvent(new CustomEvent('-change', {
79
+ detail
80
+ }));
81
+ };
82
+
83
+ #onValueChange(csv) {
84
+ if (this.multiple) {
85
+ const values = getCsvSet(csv);
86
+
87
+ for (const $option of this.#$slot.assignedElements()) {
88
+ const isChecked = !getBooleanAttribute($option, 'disabled') && values.has(getAttribute($option, 'value', ''));
89
+ updateBooleanAttribute($option, 'data-checked', isChecked);
90
+ }
91
+ } else {
92
+ const value = getFirstCsvValue(csv);
135
93
 
136
- for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements()) {
137
- const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
138
- updateBooleanAttribute($option, 'data-checked', isChecked);
94
+ for (const $option of this.#$slot.assignedElements()) {
95
+ const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
96
+ updateBooleanAttribute($option, 'data-checked', isChecked);
97
+ }
139
98
  }
140
99
  }
141
- }
100
+
101
+ #onChangeReactHandler = e => {
102
+ getReactEventHandler(this, 'on-change')?.(e);
103
+ };
104
+ });
@@ -1,92 +1,32 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$button, _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
1
  import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
11
- const templateHTML = '<style>:host{display:block;outline:0}#wrapper{position:relative;width:56px;height:32px;padding:3px 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:24px}#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}: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:-1px;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:-4px;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)}::slotted(*){display:block}</style><div id="wrapper"><slot name="icon"></slot><button id="button"></button></div>';
2
+ const templateHTML = '<style>:host{display:block;outline:0}#wrapper{position:relative;width:56px;height:32px;padding:3px 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:24px}#wrapper:hover{background-color:var(--sinch-color-snow-400)}: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}: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:-1px;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:-4px;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)}::slotted(*){display:block}</style><div id="wrapper"><slot name="icon"></slot><button id="button"></button></div>';
12
3
  const template = document.createElement('template');
13
4
  template.innerHTML = templateHTML;
14
- defineCustomElement('sinch-segmented-icon-control-option', (_$button = new WeakMap(), _onButtonClick = new WeakMap(), _onButtonFocus = new WeakMap(), _onButtonBlur = new WeakMap(), _onFocusReactHandler = new WeakMap(), _onBlurReactHandler = new WeakMap(), class extends NectaryElement {
5
+ defineCustomElement('sinch-segmented-icon-control-option', class extends NectaryElement {
6
+ #$button;
7
+
15
8
  constructor() {
16
9
  super();
17
-
18
- _classPrivateFieldInitSpec(this, _$button, {
19
- writable: true,
20
- value: void 0
21
- });
22
-
23
- _classPrivateFieldInitSpec(this, _onButtonClick, {
24
- writable: true,
25
- value: e => {
26
- e.stopPropagation();
27
- this.dispatchEvent(new CustomEvent('option-change', {
28
- detail: this.value,
29
- bubbles: true
30
- }));
31
- }
32
- });
33
-
34
- _classPrivateFieldInitSpec(this, _onButtonFocus, {
35
- writable: true,
36
- value: () => {
37
- this.dispatchEvent(new CustomEvent('-focus'));
38
- }
39
- });
40
-
41
- _classPrivateFieldInitSpec(this, _onButtonBlur, {
42
- writable: true,
43
- value: () => {
44
- this.dispatchEvent(new CustomEvent('-blur'));
45
- }
46
- });
47
-
48
- _classPrivateFieldInitSpec(this, _onFocusReactHandler, {
49
- writable: true,
50
- value: () => {
51
- getReactEventHandler(this, 'on-focus')?.();
52
- }
53
- });
54
-
55
- _classPrivateFieldInitSpec(this, _onBlurReactHandler, {
56
- writable: true,
57
- value: () => {
58
- getReactEventHandler(this, 'on-blur')?.();
59
- }
60
- });
61
-
62
10
  const shadowRoot = this.attachShadow();
63
11
  shadowRoot.appendChild(template.content.cloneNode(true));
64
-
65
- _classPrivateFieldSet(this, _$button, shadowRoot.querySelector('#button'));
12
+ this.#$button = shadowRoot.querySelector('#button');
66
13
  }
67
14
 
68
15
  connectedCallback() {
69
16
  this.setAttribute('role', 'tab');
70
-
71
- _classPrivateFieldGet(this, _$button).addEventListener('click', _classPrivateFieldGet(this, _onButtonClick));
72
-
73
- _classPrivateFieldGet(this, _$button).addEventListener('focus', _classPrivateFieldGet(this, _onButtonFocus));
74
-
75
- _classPrivateFieldGet(this, _$button).addEventListener('blur', _classPrivateFieldGet(this, _onButtonBlur));
76
-
77
- this.addEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
78
- this.addEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
17
+ this.#$button.addEventListener('click', this.#onButtonClick);
18
+ this.#$button.addEventListener('focus', this.#onButtonFocus);
19
+ this.#$button.addEventListener('blur', this.#onButtonBlur);
20
+ this.addEventListener('-focus', this.#onFocusReactHandler);
21
+ this.addEventListener('-blur', this.#onBlurReactHandler);
79
22
  }
80
23
 
81
24
  disconnectedCallback() {
82
- _classPrivateFieldGet(this, _$button).removeEventListener('click', _classPrivateFieldGet(this, _onButtonClick));
83
-
84
- _classPrivateFieldGet(this, _$button).removeEventListener('focus', _classPrivateFieldGet(this, _onButtonFocus));
85
-
86
- _classPrivateFieldGet(this, _$button).removeEventListener('blur', _classPrivateFieldGet(this, _onButtonBlur));
87
-
88
- this.removeEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
89
- this.removeEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
25
+ this.#$button.removeEventListener('click', this.#onButtonClick);
26
+ this.#$button.removeEventListener('focus', this.#onButtonFocus);
27
+ this.#$button.removeEventListener('blur', this.#onButtonBlur);
28
+ this.removeEventListener('-focus', this.#onFocusReactHandler);
29
+ this.removeEventListener('-blur', this.#onBlurReactHandler);
90
30
  }
91
31
 
92
32
  static get observedAttributes() {
@@ -119,18 +59,37 @@ defineCustomElement('sinch-segmented-icon-control-option', (_$button = new WeakM
119
59
 
120
60
  case 'disabled':
121
61
  {
122
- _classPrivateFieldGet(this, _$button).disabled = isAttrTrue(newVal);
62
+ this.#$button.disabled = isAttrTrue(newVal);
123
63
  break;
124
64
  }
125
65
  }
126
66
  }
127
67
 
128
68
  focus() {
129
- _classPrivateFieldGet(this, _$button).focus();
69
+ this.#$button.focus();
130
70
  }
131
71
 
132
72
  blur() {
133
- _classPrivateFieldGet(this, _$button).blur();
73
+ this.#$button.blur();
134
74
  }
135
75
 
136
- }));
76
+ #onButtonClick = e => {
77
+ e.stopPropagation();
78
+ this.dispatchEvent(new CustomEvent('option-change', {
79
+ detail: this.value,
80
+ bubbles: true
81
+ }));
82
+ };
83
+ #onButtonFocus = () => {
84
+ this.dispatchEvent(new CustomEvent('-focus'));
85
+ };
86
+ #onButtonBlur = () => {
87
+ this.dispatchEvent(new CustomEvent('-blur'));
88
+ };
89
+ #onFocusReactHandler = () => {
90
+ getReactEventHandler(this, 'on-focus')?.();
91
+ };
92
+ #onBlurReactHandler = () => {
93
+ getReactEventHandler(this, 'on-blur')?.();
94
+ };
95
+ });
@@ -0,0 +1,13 @@
1
+ import '../text';
2
+ import '../icons/keyboard-arrow-down';
3
+ import type { TSinchSelectButtonElement, TSinchSelectButtonReact } from './types';
4
+ declare global {
5
+ namespace JSX {
6
+ interface IntrinsicElements {
7
+ 'sinch-select-button': TSinchSelectButtonReact;
8
+ }
9
+ }
10
+ interface HTMLElementTagNameMap {
11
+ 'sinch-select-button': TSinchSelectButtonElement;
12
+ }
13
+ }
@@ -0,0 +1,153 @@
1
+ import '../text';
2
+ import '../icons/keyboard-arrow-down';
3
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
4
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;gap:8px;box-sizing:border-box;width:100%;height:48px;padding:0 12px;background-color:var(--sinch-color-snow-100);border-radius:var(--sinch-shape-radius-s);--sinch-size-icon:24px;--sinch-color-icon:var(--sinch-color-stormy-500)}#button{all:initial;cursor:pointer;position:absolute;left:0;top:0;width:100%;height:100%;z-index:1;border-radius:var(--sinch-shape-radius-s);border:1px solid var(--sinch-color-stormy-200);box-sizing:border-box}#text{flex:1;min-width:0;color:var(--sinch-color-text-muted)}:host([text]:not([text=""])) #text{color:var(--sinch-color-text-default)}#button:disabled{border-color:var(--sinch-color-snow-500);cursor:initial}#button:focus-visible{border-color:var(--sinch-color-stormy-600)}@supports not selector(:focus-visible){#button:focus{border-color:var(--sinch-color-stormy-600)}}:host([invalid]) #button:enabled{border-color:var(--sinch-color-text-invalid)}#button:disabled~#text{color:var(--sinch-color-stormy-100)}:host([disabled]) #wrapper{--sinch-color-icon:var(--sinch-color-stormy-100)}</style><div id="wrapper"><button id="button"></button><slot name="icon"></slot><sinch-text id="text" type="m" ellipsis></sinch-text><sinch-icon-keyboard-arrow-down></sinch-icon-keyboard-arrow-down></div>';
5
+ const template = document.createElement('template');
6
+ template.innerHTML = templateHTML;
7
+ defineCustomElement('sinch-select-button', class extends NectaryElement {
8
+ #$button;
9
+ #$text;
10
+ #controller = new AbortController();
11
+
12
+ constructor() {
13
+ super();
14
+ const shadowRoot = this.attachShadow();
15
+ shadowRoot.appendChild(template.content.cloneNode(true));
16
+ this.#$button = shadowRoot.querySelector('#button');
17
+ this.#$text = shadowRoot.querySelector('#text');
18
+ }
19
+
20
+ connectedCallback() {
21
+ const {
22
+ signal
23
+ } = this.#controller;
24
+ this.setAttribute('role', 'button');
25
+ this.#$button.addEventListener('click', this.#onButtonClick, {
26
+ signal
27
+ });
28
+ this.#$button.addEventListener('focus', this.#onButtonFocus, {
29
+ signal
30
+ });
31
+ this.#$button.addEventListener('blur', this.#onButtonBlur, {
32
+ signal
33
+ });
34
+ this.addEventListener('-click', this.#onClickReactHandler, {
35
+ signal
36
+ });
37
+ this.addEventListener('-focus', this.#onFocusReactHandler, {
38
+ signal
39
+ });
40
+ this.addEventListener('-blur', this.#onBlurReactHandler, {
41
+ signal
42
+ });
43
+ }
44
+
45
+ disconnectedCallback() {
46
+ this.#controller.abort();
47
+ }
48
+
49
+ static get observedAttributes() {
50
+ return ['text', 'placeholder', 'invalid', 'disabled'];
51
+ }
52
+
53
+ set text(value) {
54
+ updateAttribute(this, 'text', value);
55
+ }
56
+
57
+ get text() {
58
+ return getAttribute(this, 'text', '');
59
+ }
60
+
61
+ set placeholder(value) {
62
+ updateAttribute(this, 'placeholder', value);
63
+ }
64
+
65
+ get placeholder() {
66
+ return getAttribute(this, 'placeholder');
67
+ }
68
+
69
+ set invalid(isInvalid) {
70
+ updateBooleanAttribute(this, 'invalid', isInvalid);
71
+ }
72
+
73
+ get invalid() {
74
+ return getBooleanAttribute(this, 'invalid');
75
+ }
76
+
77
+ set disabled(isDisabled) {
78
+ updateBooleanAttribute(this, 'disabled', isDisabled);
79
+ }
80
+
81
+ get disabled() {
82
+ return getBooleanAttribute(this, 'disabled');
83
+ }
84
+
85
+ attributeChangedCallback(name, oldVal, newVal) {
86
+ if (oldVal === newVal) {
87
+ return;
88
+ }
89
+
90
+ switch (name) {
91
+ case 'text':
92
+ {
93
+ const value = newVal ?? '';
94
+ this.#$text.textContent = value.length > 0 ? value : this.placeholder;
95
+ break;
96
+ }
97
+
98
+ case 'placeholder':
99
+ {
100
+ const value = this.text;
101
+
102
+ if (value.length === 0) {
103
+ this.#$text.textContent = newVal ?? '';
104
+ }
105
+
106
+ break;
107
+ }
108
+
109
+ case 'invalid':
110
+ {
111
+ const isInvalid = isAttrTrue(newVal);
112
+ updateBooleanAttribute(this, 'invalid', isInvalid);
113
+ updateExplicitBooleanAttribute(this, 'aria-invalid', isInvalid);
114
+ break;
115
+ }
116
+
117
+ case 'disabled':
118
+ {
119
+ const isDisabled = isAttrTrue(newVal);
120
+ this.#$button.disabled = isDisabled;
121
+ updateBooleanAttribute(this, 'disabled', isDisabled);
122
+ break;
123
+ }
124
+ }
125
+ }
126
+
127
+ focus() {
128
+ this.#$button.focus();
129
+ }
130
+
131
+ blur() {
132
+ this.#$button.blur();
133
+ }
134
+
135
+ #onButtonFocus = () => {
136
+ this.dispatchEvent(new CustomEvent('-focus'));
137
+ };
138
+ #onButtonBlur = () => {
139
+ this.dispatchEvent(new CustomEvent('-blur'));
140
+ };
141
+ #onButtonClick = () => {
142
+ this.dispatchEvent(new CustomEvent('-click'));
143
+ };
144
+ #onClickReactHandler = e => {
145
+ getReactEventHandler(this, 'on-click')?.(e);
146
+ };
147
+ #onFocusReactHandler = () => {
148
+ getReactEventHandler(this, 'on-focus')?.();
149
+ };
150
+ #onBlurReactHandler = () => {
151
+ getReactEventHandler(this, 'on-blur')?.();
152
+ };
153
+ });
@@ -0,0 +1,43 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ export declare type TSinchSelectButtonElement = HTMLElement & {
3
+ /** Text */
4
+ text: string;
5
+ /** Text that appears in the text field when it has no text set */
6
+ placeholder: string;
7
+ /** Invalid state */
8
+ invalid: boolean;
9
+ /** Disabled */
10
+ disabled: boolean;
11
+ /** Click event */
12
+ addEventListener(type: '-click', listener: (e: CustomEvent<void>) => void): void;
13
+ /** Focus event */
14
+ addEventListener(type: '-focus', listener: (e: CustomEvent<void>) => void): void;
15
+ /** Blur event */
16
+ addEventListener(type: '-blur', listener: (e: CustomEvent<void>) => void): void;
17
+ /** Text */
18
+ setAttribute(name: 'text', value: string): void;
19
+ /** Text that appears in the text field when it has no value set */
20
+ setAttribute(name: 'placeholder', value: string): void;
21
+ /** Invalid state */
22
+ setAttribute(name: 'invalid', value: ''): void;
23
+ /** Disabled */
24
+ setAttribute(name: 'disabled', value: ''): void;
25
+ };
26
+ export declare type TSinchSelectButtonReact = TSinchElementReact<TSinchSelectButtonElement> & {
27
+ /** Text */
28
+ text: string;
29
+ /** Label that is used for a11y` */
30
+ 'aria-label': string;
31
+ /** Text that appears in the text field when it has no text set */
32
+ placeholder: string;
33
+ /** Invalid state */
34
+ invalid?: boolean;
35
+ /** Disabled */
36
+ disabled?: boolean;
37
+ /** Click handler */
38
+ 'on-click'?: (e: CustomEvent<void>) => void;
39
+ /** Focus handler */
40
+ 'on-focus'?: (e: CustomEvent<void>) => void;
41
+ /** Blur handler */
42
+ 'on-blur'?: (e: CustomEvent<void>) => void;
43
+ };
@@ -0,0 +1,11 @@
1
+ import type { TSinchSelectMenuElement, TSinchSelectMenuReact } from './types';
2
+ declare global {
3
+ namespace JSX {
4
+ interface IntrinsicElements {
5
+ 'sinch-select-menu': TSinchSelectMenuReact;
6
+ }
7
+ }
8
+ interface HTMLElementTagNameMap {
9
+ 'sinch-select-menu': TSinchSelectMenuElement;
10
+ }
11
+ }