@nectary/components 0.39.0 → 0.41.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 (142) hide show
  1. package/accordion/index.js +47 -84
  2. package/accordion-item/index.js +30 -53
  3. package/action-menu/index.d.ts +0 -1
  4. package/action-menu/index.js +177 -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 +52 -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 +46 -92
  16. package/button/types.d.ts +1 -1
  17. package/card/index.js +21 -59
  18. package/chat-avatar/index.js +8 -22
  19. package/chat-block/index.js +29 -69
  20. package/chat-bubble/index.js +6 -20
  21. package/checkbox/index.js +59 -107
  22. package/chip/index.d.ts +13 -0
  23. package/chip/index.js +140 -0
  24. package/chip/types.d.ts +37 -0
  25. package/color-menu/index.d.ts +14 -0
  26. package/color-menu/index.js +450 -0
  27. package/color-menu/types.d.ts +36 -0
  28. package/color-menu/utils.d.ts +1 -0
  29. package/color-menu/utils.js +15 -0
  30. package/color-swatch/index.d.ts +13 -0
  31. package/color-swatch/index.js +60 -0
  32. package/color-swatch/types.d.ts +11 -0
  33. package/colors.json +61 -49
  34. package/date-picker/index.js +162 -293
  35. package/dialog/index.js +70 -142
  36. package/field/index.js +44 -65
  37. package/file-drop/index.js +123 -200
  38. package/file-picker/index.d.ts +0 -1
  39. package/file-picker/index.js +55 -108
  40. package/file-status/index.js +15 -39
  41. package/help-tooltip/index.js +11 -28
  42. package/horizontal-stepper/index.js +33 -59
  43. package/horizontal-stepper-item/index.js +13 -37
  44. package/icon-button/index.d.ts +1 -0
  45. package/icon-button/index.js +51 -85
  46. package/icon-button/types.d.ts +16 -2
  47. package/icons-channel/notify/index.d.ts +11 -0
  48. package/icons-channel/notify/index.js +4 -0
  49. package/illustrations/create-illustration-class.js +1 -1
  50. package/inline-alert/index.js +29 -81
  51. package/input/index.js +117 -222
  52. package/link/index.js +51 -97
  53. package/list-item/index.js +1 -1
  54. package/package.json +12 -14
  55. package/pagination/index.js +113 -163
  56. package/pop/index.d.ts +11 -0
  57. package/pop/index.js +391 -0
  58. package/pop/types.d.ts +35 -0
  59. package/pop/utils.d.ts +7 -0
  60. package/pop/utils.js +18 -0
  61. package/popover/index.d.ts +1 -0
  62. package/popover/index.js +105 -314
  63. package/popover/types.d.ts +8 -1
  64. package/popover/utils.d.ts +5 -0
  65. package/popover/utils.js +17 -1
  66. package/progress/index.js +9 -28
  67. package/radio/index.js +103 -169
  68. package/radio-option/index.js +28 -48
  69. package/segment/index.js +49 -130
  70. package/segment-collapse/index.js +28 -49
  71. package/segmented-control/index.js +36 -73
  72. package/segmented-control-option/index.js +45 -87
  73. package/segmented-icon-control/index.js +47 -84
  74. package/segmented-icon-control-option/index.js +42 -79
  75. package/select-button/index.d.ts +13 -0
  76. package/select-button/index.js +158 -0
  77. package/select-button/types.d.ts +43 -0
  78. package/select-menu/index.d.ts +11 -0
  79. package/select-menu/index.js +345 -0
  80. package/select-menu/types.d.ts +29 -0
  81. package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
  82. package/select-menu-option/index.js +76 -0
  83. package/{select-option → select-menu-option}/types.d.ts +8 -9
  84. package/stop-events/index.js +7 -20
  85. package/table-head-cell/index.js +7 -21
  86. package/tabs/index.js +103 -165
  87. package/tabs-option/index.js +24 -44
  88. package/tag/index.d.ts +0 -1
  89. package/tag/index.js +35 -38
  90. package/tag/types.d.ts +12 -7
  91. package/textarea/index.js +96 -167
  92. package/theme.css +146 -49
  93. package/tile-control/index.js +55 -96
  94. package/tile-control-option/index.js +45 -87
  95. package/time-picker/index.js +216 -368
  96. package/title/index.js +6 -20
  97. package/toast/index.js +32 -70
  98. package/toast-manager/index.js +141 -217
  99. package/toggle/index.js +59 -107
  100. package/tooltip/index.d.ts +2 -0
  101. package/tooltip/index.js +160 -17
  102. package/tooltip/types.d.ts +13 -0
  103. package/tooltip/utils.d.ts +5 -0
  104. package/tooltip/utils.js +25 -1
  105. package/utils/animation.d.ts +17 -0
  106. package/utils/animation.js +142 -0
  107. package/utils/colors.d.ts +5 -0
  108. package/utils/colors.js +5 -0
  109. package/utils/context.d.ts +15 -0
  110. package/utils/context.js +57 -0
  111. package/{utils.d.ts → utils/index.d.ts} +15 -11
  112. package/{utils.js → utils/index.js} +104 -48
  113. package/vertical-stepper/index.js +29 -50
  114. package/vertical-stepper-item/index.js +13 -37
  115. package/dropdown/index.d.ts +0 -12
  116. package/dropdown/index.js +0 -415
  117. package/dropdown/types.d.ts +0 -32
  118. package/dropdown-checkbox-option/index.d.ts +0 -11
  119. package/dropdown-checkbox-option/index.js +0 -88
  120. package/dropdown-checkbox-option/types.d.ts +0 -15
  121. package/dropdown-radio-option/index.d.ts +0 -11
  122. package/dropdown-radio-option/index.js +0 -88
  123. package/dropdown-radio-option/types.d.ts +0 -15
  124. package/dropdown-text-option/index.js +0 -104
  125. package/dropdown-text-option/types.d.ts +0 -16
  126. package/select/index.d.ts +0 -13
  127. package/select/index.js +0 -316
  128. package/select/types.d.ts +0 -53
  129. package/select-option/index.d.ts +0 -11
  130. package/select-option/index.js +0 -8
  131. package/tag/utils.d.ts +0 -5
  132. package/tag/utils.js +0 -6
  133. package/tag-close/index.d.ts +0 -12
  134. package/tag-close/index.js +0 -42
  135. package/tag-close/types.d.ts +0 -5
  136. /package/{dropdown-checkbox-option → chip}/types.js +0 -0
  137. /package/{dropdown-radio-option → color-menu}/types.js +0 -0
  138. /package/{dropdown-text-option → color-swatch}/types.js +0 -0
  139. /package/{dropdown → pop}/types.js +0 -0
  140. /package/{select-option → select-button}/types.js +0 -0
  141. /package/{tag-close → select-menu}/types.js +0 -0
  142. /package/{select → select-menu-option}/types.js +0 -0
package/tabs/index.js CHANGED
@@ -1,16 +1,3 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$slot, _onOptionKeyDown, _onSlotChange, _onOptionChange, _onValueChange, _dispatchChangeEvent, _getFirstOption, _getLastOption, _getNextOption, _getPrevOption, _getEnabledRadioElements, _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, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
15
2
  const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;height:44px;width:100%;box-sizing:border-box}</style><div id="wrapper"><slot></slot></div>';
16
3
 
@@ -20,117 +7,29 @@ const findSelectedOption = elements => {
20
7
 
21
8
  const template = document.createElement('template');
22
9
  template.innerHTML = templateHTML;
23
- defineCustomElement('sinch-tabs', (_$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(), _onChangeReactHandler = new WeakMap(), class extends NectaryElement {
10
+ defineCustomElement('sinch-tabs', class extends NectaryElement {
11
+ #$slot;
12
+
24
13
  constructor() {
25
14
  super();
26
-
27
- _classPrivateMethodInitSpec(this, _getEnabledRadioElements);
28
-
29
- _classPrivateMethodInitSpec(this, _getPrevOption);
30
-
31
- _classPrivateMethodInitSpec(this, _getNextOption);
32
-
33
- _classPrivateMethodInitSpec(this, _getLastOption);
34
-
35
- _classPrivateMethodInitSpec(this, _getFirstOption);
36
-
37
- _classPrivateMethodInitSpec(this, _dispatchChangeEvent);
38
-
39
- _classPrivateMethodInitSpec(this, _onValueChange);
40
-
41
- _classPrivateFieldInitSpec(this, _$slot, {
42
- writable: true,
43
- value: void 0
44
- });
45
-
46
- _classPrivateFieldInitSpec(this, _onOptionKeyDown, {
47
- writable: true,
48
- value: e => {
49
- switch (e.code) {
50
- case 'ArrowUp':
51
- case 'ArrowLeft':
52
- {
53
- e.preventDefault();
54
-
55
- const $option = _classPrivateMethodGet(this, _getPrevOption, _getPrevOption2).call(this);
56
-
57
- if ($option !== null) {
58
- $option.focus();
59
-
60
- _classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, $option.value);
61
- }
62
-
63
- break;
64
- }
65
-
66
- case 'ArrowDown':
67
- case 'ArrowRight':
68
- {
69
- e.preventDefault();
70
-
71
- const $option = _classPrivateMethodGet(this, _getNextOption, _getNextOption2).call(this);
72
-
73
- if ($option !== null) {
74
- $option.focus();
75
-
76
- _classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, $option.value);
77
- }
78
-
79
- break;
80
- }
81
- }
82
- }
83
- });
84
-
85
- _classPrivateFieldInitSpec(this, _onSlotChange, {
86
- writable: true,
87
- value: () => {
88
- _classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this, this.value);
89
- }
90
- });
91
-
92
- _classPrivateFieldInitSpec(this, _onOptionChange, {
93
- writable: true,
94
- value: e => {
95
- e.stopPropagation();
96
-
97
- _classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, e.detail);
98
- }
99
- });
100
-
101
- _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
102
- writable: true,
103
- value: e => {
104
- getReactEventHandler(this, 'on-change')?.(e);
105
- }
106
- });
107
-
108
15
  const shadowRoot = this.attachShadow();
109
16
  shadowRoot.appendChild(template.content.cloneNode(true));
110
-
111
- _classPrivateFieldSet(this, _$slot, shadowRoot.querySelector('slot'));
17
+ this.#$slot = shadowRoot.querySelector('slot');
112
18
  }
113
19
 
114
20
  connectedCallback() {
115
21
  this.setAttribute('role', 'tablist');
116
-
117
- _classPrivateFieldGet(this, _$slot).addEventListener('keydown', _classPrivateFieldGet(this, _onOptionKeyDown));
118
-
119
- _classPrivateFieldGet(this, _$slot).addEventListener('option-change', _classPrivateFieldGet(this, _onOptionChange));
120
-
121
- _classPrivateFieldGet(this, _$slot).addEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
122
-
123
- this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
22
+ this.#$slot.addEventListener('keydown', this.#onOptionKeyDown);
23
+ this.#$slot.addEventListener('option-change', this.#onOptionChange);
24
+ this.#$slot.addEventListener('slotchange', this.#onSlotChange);
25
+ this.addEventListener('-change', this.#onChangeReactHandler);
124
26
  }
125
27
 
126
28
  disconnectedCallback() {
127
- _classPrivateFieldGet(this, _$slot).removeEventListener('keydown', _classPrivateFieldGet(this, _onOptionKeyDown));
128
-
129
- _classPrivateFieldGet(this, _$slot).removeEventListener('option-change', _classPrivateFieldGet(this, _onOptionChange));
130
-
131
- _classPrivateFieldGet(this, _$slot).removeEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
132
-
133
- this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
29
+ this.#$slot.removeEventListener('keydown', this.#onOptionKeyDown);
30
+ this.#$slot.removeEventListener('option-change', this.#onOptionChange);
31
+ this.#$slot.removeEventListener('slotchange', this.#onSlotChange);
32
+ this.removeEventListener('-change', this.#onChangeReactHandler);
134
33
  }
135
34
 
136
35
  static get observedAttributes() {
@@ -153,78 +52,117 @@ defineCustomElement('sinch-tabs', (_$slot = new WeakMap(), _onOptionKeyDown = ne
153
52
  switch (name) {
154
53
  case 'value':
155
54
  {
156
- _classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this, newVal);
157
-
55
+ this.#onValueChange(newVal);
158
56
  break;
159
57
  }
160
58
  }
161
59
  }
162
60
 
163
- }));
61
+ #onOptionKeyDown = e => {
62
+ switch (e.code) {
63
+ case 'ArrowUp':
64
+ case 'ArrowLeft':
65
+ {
66
+ e.preventDefault();
67
+ const $option = this.#getPrevOption();
68
+
69
+ if ($option !== null) {
70
+ $option.focus();
71
+ this.#dispatchChangeEvent($option.value);
72
+ }
164
73
 
165
- function _onValueChange2(value) {
166
- for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements()) {
167
- const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
168
- updateBooleanAttribute($option, 'checked', isChecked);
169
- }
170
- }
171
-
172
- function _dispatchChangeEvent2(value) {
173
- this.dispatchEvent(new CustomEvent('change', {
174
- detail: value,
175
- bubbles: true
176
- }));
177
- this.dispatchEvent(new CustomEvent('-change', {
178
- detail: value
179
- }));
180
- }
181
-
182
- function _getFirstOption2() {
183
- for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements()) {
184
- if ($option.disabled !== true) {
185
- return $option;
74
+ break;
75
+ }
76
+
77
+ case 'ArrowDown':
78
+ case 'ArrowRight':
79
+ {
80
+ e.preventDefault();
81
+ const $option = this.#getNextOption();
82
+
83
+ if ($option !== null) {
84
+ $option.focus();
85
+ this.#dispatchChangeEvent($option.value);
86
+ }
87
+
88
+ break;
89
+ }
90
+ }
91
+ };
92
+ #onSlotChange = () => {
93
+ this.#onValueChange(this.value);
94
+ };
95
+ #onOptionChange = e => {
96
+ e.stopPropagation();
97
+ this.#dispatchChangeEvent(e.detail);
98
+ };
99
+
100
+ #onValueChange(value) {
101
+ for (const $option of this.#$slot.assignedElements()) {
102
+ const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
103
+ updateBooleanAttribute($option, 'checked', isChecked);
186
104
  }
187
105
  }
188
106
 
189
- return null;
190
- }
107
+ #dispatchChangeEvent(value) {
108
+ this.dispatchEvent(new CustomEvent('change', {
109
+ detail: value,
110
+ bubbles: true
111
+ }));
112
+ this.dispatchEvent(new CustomEvent('-change', {
113
+ detail: value
114
+ }));
115
+ }
191
116
 
192
- function _getLastOption2() {
193
- for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements().reverse()) {
194
- if ($option.disabled !== true) {
195
- return $option;
117
+ #getFirstOption() {
118
+ for (const $option of this.#$slot.assignedElements()) {
119
+ if ($option.disabled !== true) {
120
+ return $option;
121
+ }
196
122
  }
123
+
124
+ return null;
197
125
  }
198
126
 
199
- return null;
200
- }
127
+ #getLastOption() {
128
+ for (const $option of this.#$slot.assignedElements().reverse()) {
129
+ if ($option.disabled !== true) {
130
+ return $option;
131
+ }
132
+ }
201
133
 
202
- function _getNextOption2() {
203
- const $options = _classPrivateMethodGet(this, _getEnabledRadioElements, _getEnabledRadioElements2).call(this);
134
+ return null;
135
+ }
204
136
 
205
- const $selectedOption = findSelectedOption($options);
206
- const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
137
+ #getNextOption() {
138
+ const $options = this.#getEnabledRadioElements();
139
+ const $selectedOption = findSelectedOption($options);
140
+ const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
207
141
 
208
- if (currentIndex < 0) {
209
- return _classPrivateMethodGet(this, _getFirstOption, _getFirstOption2).call(this);
210
- }
142
+ if (currentIndex < 0) {
143
+ return this.#getFirstOption();
144
+ }
211
145
 
212
- return $options[(currentIndex + 1) % $options.length];
213
- }
146
+ return $options[(currentIndex + 1) % $options.length];
147
+ }
214
148
 
215
- function _getPrevOption2() {
216
- const $options = _classPrivateMethodGet(this, _getEnabledRadioElements, _getEnabledRadioElements2).call(this);
149
+ #getPrevOption() {
150
+ const $options = this.#getEnabledRadioElements();
151
+ const $selectedOption = findSelectedOption($options);
152
+ const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
217
153
 
218
- const $selectedOption = findSelectedOption($options);
219
- const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
154
+ if (currentIndex < 0) {
155
+ return this.#getLastOption();
156
+ }
220
157
 
221
- if (currentIndex < 0) {
222
- return _classPrivateMethodGet(this, _getLastOption, _getLastOption2).call(this);
158
+ return $options[(currentIndex - 1 + $options.length) % $options.length];
223
159
  }
224
160
 
225
- return $options[(currentIndex - 1 + $options.length) % $options.length];
226
- }
161
+ #getEnabledRadioElements() {
162
+ return this.#$slot.assignedElements().filter(opt => opt.disabled !== true);
163
+ }
227
164
 
228
- function _getEnabledRadioElements2() {
229
- return _classPrivateFieldGet(this, _$slot).assignedElements().filter(opt => opt.disabled !== true);
230
- }
165
+ #onChangeReactHandler = e => {
166
+ getReactEventHandler(this, 'on-change')?.(e);
167
+ };
168
+ });
@@ -1,57 +1,26 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$button, _$label, _onClick;
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, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
11
2
  const templateHTML = '<style>:host{display:block;outline:0}:host()>*{pointer-events:none}#wrapper{display:flex;flex-direction:row;align-items:center;gap:12px;position:relative;width:100%;height:42px;padding:8px 20px;box-sizing:border-box;box-shadow:0 1px 0 0 var(--sinch-color-stormy-100);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}#content{font:var(--sinch-font-title-s);flex-shrink:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}:host([checked]:not([checked=false])) #wrapper{box-shadow:0 2px 0 0 var(--sinch-color-stormy-500)}#button{all:initial;position:absolute;left:0;top:0;box-sizing:border-box;width:100%;height:100%;cursor:pointer}#button:disabled{cursor:unset}:host([disabled]:not([disabled=false])) #wrapper{color:var(--sinch-color-stormy-100);--sinch-color-icon:var(--sinch-color-stormy-100)}</style><div id="wrapper"><slot name="icon"></slot><label for="input" id="content"></label><button id="button" type="radio"/></div>';
12
3
  const template = document.createElement('template');
13
4
  template.innerHTML = templateHTML;
14
- defineCustomElement('sinch-tabs-option', (_$button = new WeakMap(), _$label = new WeakMap(), _onClick = new WeakMap(), class extends NectaryElement {
5
+ defineCustomElement('sinch-tabs-option', class extends NectaryElement {
6
+ #$button;
7
+ #$label;
8
+
15
9
  constructor() {
16
10
  super();
17
-
18
- _classPrivateFieldInitSpec(this, _$button, {
19
- writable: true,
20
- value: void 0
21
- });
22
-
23
- _classPrivateFieldInitSpec(this, _$label, {
24
- writable: true,
25
- value: void 0
26
- });
27
-
28
- _classPrivateFieldInitSpec(this, _onClick, {
29
- writable: true,
30
- value: e => {
31
- e.stopPropagation();
32
- this.dispatchEvent(new CustomEvent('option-change', {
33
- bubbles: true,
34
- detail: this.value
35
- }));
36
- }
37
- });
38
-
39
11
  const shadowRoot = this.attachShadow();
40
12
  shadowRoot.appendChild(template.content.cloneNode(true));
41
-
42
- _classPrivateFieldSet(this, _$button, shadowRoot.querySelector('#button'));
43
-
44
- _classPrivateFieldSet(this, _$label, shadowRoot.querySelector('#content'));
13
+ this.#$button = shadowRoot.querySelector('#button');
14
+ this.#$label = shadowRoot.querySelector('#content');
45
15
  }
46
16
 
47
17
  connectedCallback() {
48
18
  this.setAttribute('role', 'tab');
49
-
50
- _classPrivateFieldGet(this, _$button).addEventListener('click', _classPrivateFieldGet(this, _onClick));
19
+ this.#$button.addEventListener('click', this.#onClick);
51
20
  }
52
21
 
53
22
  disconnectedCallback() {
54
- _classPrivateFieldGet(this, _$button).removeEventListener('click', _classPrivateFieldGet(this, _onClick));
23
+ this.#$button.removeEventListener('click', this.#onClick);
55
24
  }
56
25
 
57
26
  static get observedAttributes() {
@@ -94,7 +63,7 @@ defineCustomElement('sinch-tabs-option', (_$button = new WeakMap(), _$label = ne
94
63
  switch (name) {
95
64
  case 'text':
96
65
  {
97
- _classPrivateFieldGet(this, _$label).textContent = newVal;
66
+ this.#$label.textContent = newVal;
98
67
  break;
99
68
  }
100
69
 
@@ -107,19 +76,30 @@ defineCustomElement('sinch-tabs-option', (_$button = new WeakMap(), _$label = ne
107
76
  case 'disabled':
108
77
  {
109
78
  const isDisabled = isAttrTrue(newVal);
110
- _classPrivateFieldGet(this, _$button).disabled = isDisabled;
79
+ this.#$button.disabled = isDisabled;
111
80
  updateBooleanAttribute(this, 'disabled', isDisabled);
112
81
  break;
113
82
  }
114
83
  }
115
84
  }
116
85
 
86
+ get focusable() {
87
+ return true;
88
+ }
89
+
117
90
  focus() {
118
- _classPrivateFieldGet(this, _$button).focus();
91
+ this.#$button.focus();
119
92
  }
120
93
 
121
94
  blur() {
122
- _classPrivateFieldGet(this, _$button).blur();
95
+ this.#$button.blur();
123
96
  }
124
97
 
125
- }));
98
+ #onClick = e => {
99
+ e.stopPropagation();
100
+ this.dispatchEvent(new CustomEvent('option-change', {
101
+ bubbles: true,
102
+ detail: this.value
103
+ }));
104
+ };
105
+ });
package/tag/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import '../icons/cancel';
2
1
  import '../text';
3
2
  import type { TSinchTagElement, TSinchTagReact } from './types';
4
3
  declare global {
package/tag/index.js CHANGED
@@ -1,40 +1,31 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$text;
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 '../icons/cancel';
11
1
  import '../text';
12
- import { defineCustomElement, getBooleanAttribute, getAttribute, getLiteralAttribute, updateBooleanAttribute, updateAttribute, updateLiteralAttribute, NectaryElement } from '../utils';
13
- const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;gap:4px;width:100%;height:24px;padding:2px 8px;border-radius:12px;font:var(--sinch-font-extra-small-text);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-600);box-sizing:border-box;--sinch-color-icon:var(--sinch-color-stormy-400);--sinch-size-icon:16px}:host([category=candy])>#wrapper{background-color:var(--sinch-color-candy-200)}:host([category=bolt])>#wrapper{background-color:var(--sinch-color-bolt-200)}:host([category=aqua])>#wrapper{background-color:var(--sinch-color-aqua-200)}:host([category=grass])>#wrapper{background-color:var(--sinch-color-grass-200)}:host([category=berry])>#wrapper{background-color:var(--sinch-color-berry-200)}:host([category=orange])>#wrapper{background-color:var(--sinch-color-orange-200)}:host([category=night])>#wrapper{background-color:var(--sinch-color-night-200)}:host([category=mud])>#wrapper{background-color:var(--sinch-color-mud-200)}:host([category=dirt])>#wrapper{background-color:var(--sinch-color-dirt-200)}:host([inverted]:not([inverted=false]))>#wrapper{background-color:var(--sinch-color-stormy-500);color:var(--sinch-color-snow-100);--sinch-color-icon:var(--sinch-color-snow-100)}:host([small]:not([small=false])) #wrapper{height:20px;border-radius:10px;padding:0 8px;--sinch-size-icon:14px}#text{flex:1}</style><div id="wrapper"><slot name="icon"></slot><sinch-text id="text" type="xs" ellipsis></sinch-text><slot name="close"></slot></div>';
14
- import { assertCategoryValue, categoryValues } from './utils';
2
+ import { defineCustomElement, getBooleanAttribute, getAttribute, updateBooleanAttribute, updateAttribute, NectaryElement } from '../utils';
3
+ import { NO_COLOR } from '../utils/colors';
4
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;flex-direction:row;align-items:center;gap:4px;width:100%;height:24px;padding:0 9px;border-radius:12px;background-color:var(--sinch-color-snow-500);color:var(--sinch-color-text-default);box-sizing:border-box;--sinch-color-icon:var(--sinch-color-stormy-500);--sinch-size-icon:16px}#text{flex:1}:host([small]:not([small=false])) #wrapper{height:20px;border-radius:10px;padding:0 8px}::slotted(*){margin-left:-4px}</style><div id="wrapper"><slot name="icon"></slot><sinch-text id="text" type="xs" ellipsis></sinch-text></div>';
15
5
  const template = document.createElement('template');
16
6
  template.innerHTML = templateHTML;
17
- defineCustomElement('sinch-tag', (_$text = new WeakMap(), class extends NectaryElement {
7
+ defineCustomElement('sinch-tag', class extends NectaryElement {
8
+ #$text;
9
+ #$wrapper;
10
+
18
11
  constructor() {
19
12
  super();
20
-
21
- _classPrivateFieldInitSpec(this, _$text, {
22
- writable: true,
23
- value: void 0
24
- });
25
-
26
13
  const shadowRoot = this.attachShadow();
27
14
  shadowRoot.appendChild(template.content.cloneNode(true));
15
+ this.#$wrapper = shadowRoot.querySelector('#wrapper');
16
+ this.#$text = shadowRoot.querySelector('#text');
17
+ }
28
18
 
29
- _classPrivateFieldSet(this, _$text, shadowRoot.querySelector('#text'));
19
+ connectedCallback() {
20
+ this.#updateColor();
30
21
  }
31
22
 
32
- get category() {
33
- return getLiteralAttribute(this, categoryValues, 'category', null);
23
+ get color() {
24
+ return getAttribute(this, 'color');
34
25
  }
35
26
 
36
- set category(value) {
37
- updateLiteralAttribute(this, categoryValues, 'category', value);
27
+ set color(value) {
28
+ updateAttribute(this, 'color', value);
38
29
  }
39
30
 
40
31
  get text() {
@@ -45,14 +36,6 @@ defineCustomElement('sinch-tag', (_$text = new WeakMap(), class extends NectaryE
45
36
  updateAttribute(this, 'text', value);
46
37
  }
47
38
 
48
- get inverted() {
49
- return getBooleanAttribute(this, 'inverted');
50
- }
51
-
52
- set inverted(isInverted) {
53
- updateBooleanAttribute(this, 'inverted', isInverted);
54
- }
55
-
56
39
  get small() {
57
40
  return getBooleanAttribute(this, 'small');
58
41
  }
@@ -62,23 +45,37 @@ defineCustomElement('sinch-tag', (_$text = new WeakMap(), class extends NectaryE
62
45
  }
63
46
 
64
47
  static get observedAttributes() {
65
- return ['text', 'category'];
48
+ return ['text', 'color'];
66
49
  }
67
50
 
68
51
  attributeChangedCallback(name, _, newVal) {
69
52
  switch (name) {
70
- case 'category':
53
+ case 'color':
71
54
  {
72
- assertCategoryValue(newVal);
55
+ this.#updateColor();
73
56
  break;
74
57
  }
75
58
 
76
59
  case 'text':
77
60
  {
78
- _classPrivateFieldGet(this, _$text).textContent = newVal;
61
+ this.#$text.textContent = newVal;
79
62
  break;
80
63
  }
81
64
  }
82
65
  }
83
66
 
84
- }));
67
+ #updateColor() {
68
+ const colorName = this.color ?? NO_COLOR;
69
+
70
+ if (colorName !== NO_COLOR) {
71
+ this.#$wrapper.style.setProperty('background-color', `var(--sinch-color-map-${colorName}-bg)`);
72
+ this.#$wrapper.style.setProperty('color', `var(--sinch-color-map-${colorName}-fg)`);
73
+ this.#$wrapper.style.setProperty('--sinch-color-icon', `var(--sinch-color-map-${colorName}-fg)`);
74
+ } else {
75
+ this.#$wrapper.style.removeProperty('background-color');
76
+ this.#$wrapper.style.removeProperty('color');
77
+ this.#$wrapper.style.removeProperty('--sinch-color-icon');
78
+ }
79
+ }
80
+
81
+ });
package/tag/types.d.ts CHANGED
@@ -1,18 +1,23 @@
1
1
  import type { TSinchElementReact } from '../types';
2
- export declare type TSinchTagCategory = 'candy' | 'bolt' | 'aqua' | 'grass' | 'berry' | 'orange' | 'night' | 'mud' | 'dirt';
3
2
  export declare type TSinchTagElement = HTMLElement & {
4
- category: TSinchTagCategory | null;
3
+ /** Text */
5
4
  text: string;
6
- inverted: boolean;
5
+ /** Color, gray by default */
6
+ color: string | null;
7
+ /** Small */
7
8
  small: boolean;
8
- setAttribute(name: 'category', value: TSinchTagCategory): void;
9
+ /** Text */
9
10
  setAttribute(name: 'text', value: string): void;
10
- setAttribute(name: 'inverted', value: ''): void;
11
+ /** Color, gray by default */
12
+ setAttribute(name: 'color', value: string): void;
13
+ /** Small */
11
14
  setAttribute(name: 'small', value: ''): void;
12
15
  };
13
16
  export declare type TSinchTagReact = TSinchElementReact<TSinchTagElement> & {
14
- category?: TSinchTagCategory;
17
+ /** Text */
15
18
  text: string;
16
- inverted?: boolean;
19
+ /** Color, gray by default */
20
+ color?: string;
21
+ /** Small */
17
22
  small?: boolean;
18
23
  };