@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
@@ -1,72 +1,30 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$firstName, _$lastName, _$timeStamp, _$bubbleSlot, _onBubbleSlotChange, _updateBubbleTypes;
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 { typeValues } from '../chat-bubble/utils';
15
2
  import { defineCustomElement, getAttribute, getLiteralAttribute, NectaryElement, updateAttribute, updateLiteralAttribute } from '../utils';
16
3
  const templateHTML = '<style>:host{display:block;outline:0}#wrapper{position:relative;display:flex;flex-direction:column;gap:4px;align-items:flex-end;padding-left:72px}#stamp{display:flex;gap:4px;margin:0;font:var(--sinch-font-extra-small-text);color:var(--sinch-color-stormy-400)}#avatar{display:none;position:absolute;left:0;top:24px}:host([type=customer])>#wrapper{align-items:flex-start}:host([type=customer]) #avatar{display:block}</style><div id="wrapper"><div id="avatar"><slot name="avatar"></slot></div><p id="stamp"><span id="firstname"></span><span id="lastname"></span>&bull;<span id="time"></span></p><slot name="bubble"></slot></div>';
17
4
  const template = document.createElement('template');
18
5
  template.innerHTML = templateHTML;
19
- defineCustomElement('sinch-chat-block', (_$firstName = new WeakMap(), _$lastName = new WeakMap(), _$timeStamp = new WeakMap(), _$bubbleSlot = new WeakMap(), _onBubbleSlotChange = new WeakMap(), _updateBubbleTypes = new WeakSet(), class extends NectaryElement {
6
+ defineCustomElement('sinch-chat-block', class extends NectaryElement {
7
+ #$firstName;
8
+ #$lastName;
9
+ #$timeStamp;
10
+ #$bubbleSlot;
11
+
20
12
  constructor() {
21
13
  super();
22
-
23
- _classPrivateMethodInitSpec(this, _updateBubbleTypes);
24
-
25
- _classPrivateFieldInitSpec(this, _$firstName, {
26
- writable: true,
27
- value: void 0
28
- });
29
-
30
- _classPrivateFieldInitSpec(this, _$lastName, {
31
- writable: true,
32
- value: void 0
33
- });
34
-
35
- _classPrivateFieldInitSpec(this, _$timeStamp, {
36
- writable: true,
37
- value: void 0
38
- });
39
-
40
- _classPrivateFieldInitSpec(this, _$bubbleSlot, {
41
- writable: true,
42
- value: void 0
43
- });
44
-
45
- _classPrivateFieldInitSpec(this, _onBubbleSlotChange, {
46
- writable: true,
47
- value: () => {
48
- _classPrivateMethodGet(this, _updateBubbleTypes, _updateBubbleTypes2).call(this);
49
- }
50
- });
51
-
52
14
  const shadowRoot = this.attachShadow();
53
15
  shadowRoot.appendChild(template.content.cloneNode(true));
54
-
55
- _classPrivateFieldSet(this, _$firstName, shadowRoot.querySelector('#firstname'));
56
-
57
- _classPrivateFieldSet(this, _$lastName, shadowRoot.querySelector('#lastname'));
58
-
59
- _classPrivateFieldSet(this, _$timeStamp, shadowRoot.querySelector('#time'));
60
-
61
- _classPrivateFieldSet(this, _$bubbleSlot, shadowRoot.querySelector('slot[name="bubble"]'));
16
+ this.#$firstName = shadowRoot.querySelector('#firstname');
17
+ this.#$lastName = shadowRoot.querySelector('#lastname');
18
+ this.#$timeStamp = shadowRoot.querySelector('#time');
19
+ this.#$bubbleSlot = shadowRoot.querySelector('slot[name="bubble"]');
62
20
  }
63
21
 
64
22
  connectedCallback() {
65
- _classPrivateFieldGet(this, _$bubbleSlot).addEventListener('slotchange', _classPrivateFieldGet(this, _onBubbleSlotChange));
23
+ this.#$bubbleSlot.addEventListener('slotchange', this.#onBubbleSlotChange);
66
24
  }
67
25
 
68
26
  disconnectedCallback() {
69
- _classPrivateFieldGet(this, _$bubbleSlot).removeEventListener('slotchange', _classPrivateFieldGet(this, _onBubbleSlotChange));
27
+ this.#$bubbleSlot.removeEventListener('slotchange', this.#onBubbleSlotChange);
70
28
  }
71
29
 
72
30
  static get observedAttributes() {
@@ -77,26 +35,25 @@ defineCustomElement('sinch-chat-block', (_$firstName = new WeakMap(), _$lastName
77
35
  switch (name) {
78
36
  case 'firstname':
79
37
  {
80
- _classPrivateFieldGet(this, _$firstName).textContent = newVal;
38
+ this.#$firstName.textContent = newVal;
81
39
  break;
82
40
  }
83
41
 
84
42
  case 'lastname':
85
43
  {
86
- _classPrivateFieldGet(this, _$lastName).textContent = newVal;
44
+ this.#$lastName.textContent = newVal;
87
45
  break;
88
46
  }
89
47
 
90
48
  case 'timestamp':
91
49
  {
92
- _classPrivateFieldGet(this, _$timeStamp).textContent = newVal;
50
+ this.#$timeStamp.textContent = newVal;
93
51
  break;
94
52
  }
95
53
 
96
54
  case 'type':
97
55
  {
98
- _classPrivateMethodGet(this, _updateBubbleTypes, _updateBubbleTypes2).call(this);
99
-
56
+ this.#updateBubbleTypes();
100
57
  break;
101
58
  }
102
59
  }
@@ -115,7 +72,7 @@ defineCustomElement('sinch-chat-block', (_$firstName = new WeakMap(), _$lastName
115
72
  }
116
73
 
117
74
  get firstName() {
118
- return getAttribute(this, 'firstname', null);
75
+ return getAttribute(this, 'firstname');
119
76
  }
120
77
 
121
78
  set lastName(value) {
@@ -123,7 +80,7 @@ defineCustomElement('sinch-chat-block', (_$firstName = new WeakMap(), _$lastName
123
80
  }
124
81
 
125
82
  get lastName() {
126
- return getAttribute(this, 'lastname', null);
83
+ return getAttribute(this, 'lastname');
127
84
  }
128
85
 
129
86
  set timestamp(value) {
@@ -131,15 +88,18 @@ defineCustomElement('sinch-chat-block', (_$firstName = new WeakMap(), _$lastName
131
88
  }
132
89
 
133
90
  get timestamp() {
134
- return getAttribute(this, 'timestamp', null);
91
+ return getAttribute(this, 'timestamp');
135
92
  }
136
93
 
137
- }));
94
+ #onBubbleSlotChange = () => {
95
+ this.#updateBubbleTypes();
96
+ };
138
97
 
139
- function _updateBubbleTypes2() {
140
- const typeValue = getAttribute(this, 'type');
98
+ #updateBubbleTypes() {
99
+ const typeValue = getAttribute(this, 'type');
100
+ this.#$bubbleSlot.assignedElements().forEach(el => {
101
+ updateAttribute(el, 'data-type', typeValue);
102
+ });
103
+ }
141
104
 
142
- _classPrivateFieldGet(this, _$bubbleSlot).assignedElements().forEach(el => {
143
- updateAttribute(el, 'data-type', typeValue);
144
- });
145
- }
105
+ });
@@ -1,12 +1,3 @@
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
1
  import '../icons/query-builder';
11
2
  import '../icons/check';
12
3
  import '../icons/done-all';
@@ -16,19 +7,14 @@ const templateHTML = '<style>:host{display:block;outline:0}#wrapper{position:rel
16
7
  import { statusValues, typeValues } from './utils';
17
8
  const template = document.createElement('template');
18
9
  template.innerHTML = templateHTML;
19
- defineCustomElement('sinch-chat-bubble', (_$text = new WeakMap(), class extends NectaryElement {
10
+ defineCustomElement('sinch-chat-bubble', class extends NectaryElement {
11
+ #$text;
12
+
20
13
  constructor() {
21
14
  super();
22
-
23
- _classPrivateFieldInitSpec(this, _$text, {
24
- writable: true,
25
- value: void 0
26
- });
27
-
28
15
  const shadowRoot = this.attachShadow();
29
16
  shadowRoot.appendChild(template.content.cloneNode(true));
30
-
31
- _classPrivateFieldSet(this, _$text, shadowRoot.querySelector('#text'));
17
+ this.#$text = shadowRoot.querySelector('#text');
32
18
  }
33
19
 
34
20
  static get observedAttributes() {
@@ -39,7 +25,7 @@ defineCustomElement('sinch-chat-bubble', (_$text = new WeakMap(), class extends
39
25
  switch (name) {
40
26
  case 'text':
41
27
  {
42
- _classPrivateFieldGet(this, _$text).textContent = newVal;
28
+ this.#$text.textContent = newVal;
43
29
  break;
44
30
  }
45
31
  }
@@ -65,4 +51,4 @@ defineCustomElement('sinch-chat-bubble', (_$text = new WeakMap(), class extends
65
51
  return getLiteralAttribute(this, statusValues, 'status', null);
66
52
  }
67
53
 
68
- }));
54
+ });
package/checkbox/index.js CHANGED
@@ -1,115 +1,36 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$input, _$label, _onCheckboxInput, _onCheckboxFocus, _onCheckboxBlur, _onChangeReactHandler, _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{--sinch-color-checkbox-circle:var(--sinch-color-transparent);--sinch-color-checkbox-background:var(--sinch-color-snow-100);--sinch-color-checkbox-border:var(--sinch-color-stormy-300);--sinch-color-checkbox-circle-checked:var(--sinch-color-transparent);--sinch-color-checkbox-background-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-border-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-circle-hover:var(--sinch-color-snow-500);--sinch-color-checkbox-background-hover:var(--sinch-color-snow-100);--sinch-color-checkbox-border-hover:var(--sinch-color-stormy-300);--sinch-color-checkbox-circle-hover-checked:var(--sinch-color-tropical-100);--sinch-color-checkbox-background-hover-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-border-hover-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-circle-focus:var(--sinch-color-snow-800);--sinch-color-checkbox-background-focus:var(--sinch-color-snow-100);--sinch-color-checkbox-border-focus:var(--sinch-color-stormy-300);--sinch-color-checkbox-circle-focus-checked:var(--sinch-color-tropical-200);--sinch-color-checkbox-background-focus-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-border-focus-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-circle-active:var(--sinch-color-stormy-100);--sinch-color-checkbox-background-active:var(--sinch-color-snow-100);--sinch-color-checkbox-border-active:var(--sinch-color-stormy-300);--sinch-color-checkbox-circle-active-checked:var(--sinch-color-tropical-300);--sinch-color-checkbox-background-active-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-border-active-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-circle-disabled:var(--sinch-color-transparent);--sinch-color-checkbox-background-disabled:var(--sinch-color-snow-100);--sinch-color-checkbox-border-disabled:var(--sinch-color-stormy-100);--sinch-color-checkbox-circle-disabled-checked:var(--sinch-color-transparent);--sinch-color-checkbox-background-disabled-checked:var(--sinch-color-stormy-100);--sinch-color-checkbox-border-disabled-checked:var(--sinch-color-stormy-100);--sinch-color-checkbox-text:var(--sinch-color-text-default);--sinch-color-checkbox-text-disabled:var(--sinch-color-stormy-200);display:inline-block;vertical-align:middle;outline:0}:host([invalid]:not([invalid=false])){--sinch-color-checkbox-border:var(--sinch-color-raspberry-500);--sinch-color-checkbox-background-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-hover:var(--sinch-color-raspberry-500);--sinch-color-checkbox-circle-hover-checked:var(--sinch-color-raspberry-100);--sinch-color-checkbox-background-hover-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-hover-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-focus:var(--sinch-color-raspberry-500);--sinch-color-checkbox-circle-focus-checked:var(--sinch-color-raspberry-200);--sinch-color-checkbox-background-focus-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-focus-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-active:var(--sinch-color-raspberry-500);--sinch-color-checkbox-circle-active-checked:var(--sinch-color-raspberry-300);--sinch-color-checkbox-background-active-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-active-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-disabled:var(--sinch-color-raspberry-200);--sinch-color-checkbox-background-disabled-checked:var(--sinch-color-raspberry-200);--sinch-color-checkbox-border-disabled-checked:var(--sinch-color-raspberry-200);--sinch-color-checkbox-text:var(--sinch-color-text-invalid);--sinch-color-checkbox-text-disabled:var(--sinch-color-raspberry-200)}#wrapper{display:flex;flex-direction:row;box-sizing:border-box;width:100%;height:32px}#checkbox{all:initial;display:block;width:32px;height:32px;cursor:pointer}#checkbox:disabled{cursor:initial}#icon-container{position:relative;width:32px;height:32px}#checkbox::before{content:"";position:absolute;top:0;left:0;width:32px;height:32px;border-radius:16px;pointer-events:none;background-color:var(--sinch-color-checkbox-circle);transition:background-color .1s linear}#checkbox::after{content:"";position:absolute;top:7px;left:7px;width:18px;height:18px;border-radius:var(--sinch-shape-radius-xs);pointer-events:none;background-color:var(--sinch-color-checkbox-background);border:2px solid var(--sinch-color-checkbox-border);transition:background-color .1s linear;box-sizing:border-box}#icon-checkmark{position:absolute;left:9px;top:10px;transition:opacity .1s linear;opacity:0;pointer-events:none}#icon-indeterminate{position:absolute;left:10px;top:15px;transition:opacity .1s linear;opacity:0;pointer-events:none}@media (prefers-reduced-motion){#checkbox::after,#checkbox::before,#icon-checkmark,#icon-indeterminate{transition:none}}#label{display:none;flex:1;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;padding-left:6px;font:var(--sinch-font-body);color:var(--sinch-color-checkbox-text)}:host([text]:not([text=""])) #label{display:block}:host([disabled]:not([disabled=false])) #label{color:var(--sinch-color-checkbox-text-disabled)}:host(:is(:not([indeterminate]),[indeterminate=false])) #checkbox:checked~#icon-checkmark{opacity:1}:host([indeterminate]:not([indeterminate=false])) #checkbox:checked~#icon-indeterminate{opacity:1}#checkbox:checked::before{background-color:var(--sinch-color-checkbox-circle-checked)}#checkbox:checked::after{background-color:var(--sinch-color-checkbox-background-checked);border-color:var(--sinch-color-checkbox-border-checked)}#checkbox:focus::before{background-color:var(--sinch-color-checkbox-circle-focus)}#checkbox:focus::after{background-color:var(--sinch-color-checkbox-background-focus);border-color:var(--sinch-color-checkbox-border-focus)}#checkbox:hover::before{background-color:var(--sinch-color-checkbox-circle-hover)}#checkbox:hover::after{background-color:var(--sinch-color-checkbox-background-hover);border-color:var(--sinch-color-checkbox-border-hover)}#checkbox:active::before{background-color:var(--sinch-color-checkbox-circle-active)}#checkbox:active::after{background-color:var(--sinch-color-checkbox-background-active);border-color:var(--sinch-color-checkbox-border-active)}#checkbox:disabled::before{background-color:var(--sinch-color-checkbox-circle-disabled)}#checkbox:disabled::after{background-color:var(--sinch-color-checkbox-background-disabled);border-color:var(--sinch-color-checkbox-border-disabled)}#checkbox:focus:checked::before{background-color:var(--sinch-color-checkbox-circle-focus-checked)}#checkbox:focus:checked::after{background-color:var(--sinch-color-checkbox-background-focus-checked);border-color:var(--sinch-color-checkbox-border-focus-checked)}#checkbox:hover:checked::before{background-color:var(--sinch-color-checkbox-circle-hover-checked)}#checkbox:hover:checked::after{background-color:var(--sinch-color-checkbox-background-hover-checked);border-color:var(--sinch-color-checkbox-border-hover-checked)}#checkbox:active:checked::before{background-color:var(--sinch-color-checkbox-circle-active-checked)}#checkbox:active:checked::after{background-color:var(--sinch-color-checkbox-background-active-checked);border-color:var(--sinch-color-checkbox-border-active-checked)}#checkbox:disabled:checked::before{background-color:var(--sinch-color-checkbox-circle-disabled-checked)}#checkbox:disabled:checked::after{background-color:var(--sinch-color-checkbox-background-disabled-checked);border-color:var(--sinch-color-checkbox-border-disabled-checked)}</style><div id="wrapper"><div id="icon-container"><input id="checkbox" type="checkbox"/><svg id="icon-checkmark" width="14" height="11" aria-hidden="true"><path d="M14 1.99999L12.59 0.579987L4.98995 8.17L1.49997 4.5L0.0799694 5.91L4.98995 11L14 1.99999Z" fill="white"/></svg><svg id="icon-indeterminate" width="12" height="2" aria-hidden="true"><line y1="1" x2="12" y2="1" stroke="white" stroke-width="2"/></svg></div><label for="checkbox" id="label"></label></div>';
2
+ const templateHTML = '<style>:host{--sinch-color-checkbox-circle:var(--sinch-color-transparent);--sinch-color-checkbox-background:var(--sinch-color-snow-100);--sinch-color-checkbox-border:var(--sinch-color-stormy-300);--sinch-color-checkbox-circle-checked:var(--sinch-color-transparent);--sinch-color-checkbox-background-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-border-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-circle-hover:var(--sinch-color-snow-500);--sinch-color-checkbox-background-hover:var(--sinch-color-snow-100);--sinch-color-checkbox-border-hover:var(--sinch-color-stormy-300);--sinch-color-checkbox-circle-hover-checked:var(--sinch-color-tropical-100);--sinch-color-checkbox-background-hover-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-border-hover-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-circle-focus:var(--sinch-color-snow-700);--sinch-color-checkbox-background-focus:var(--sinch-color-snow-100);--sinch-color-checkbox-border-focus:var(--sinch-color-stormy-300);--sinch-color-checkbox-circle-focus-checked:var(--sinch-color-tropical-200);--sinch-color-checkbox-background-focus-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-border-focus-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-circle-active:var(--sinch-color-stormy-100);--sinch-color-checkbox-background-active:var(--sinch-color-snow-100);--sinch-color-checkbox-border-active:var(--sinch-color-stormy-300);--sinch-color-checkbox-circle-active-checked:var(--sinch-color-tropical-300);--sinch-color-checkbox-background-active-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-border-active-checked:var(--sinch-color-tropical-500);--sinch-color-checkbox-circle-disabled:var(--sinch-color-transparent);--sinch-color-checkbox-background-disabled:var(--sinch-color-snow-100);--sinch-color-checkbox-border-disabled:var(--sinch-color-stormy-100);--sinch-color-checkbox-circle-disabled-checked:var(--sinch-color-transparent);--sinch-color-checkbox-background-disabled-checked:var(--sinch-color-stormy-100);--sinch-color-checkbox-border-disabled-checked:var(--sinch-color-stormy-100);--sinch-color-checkbox-text:var(--sinch-color-text-default);--sinch-color-checkbox-text-disabled:var(--sinch-color-text-disabled);display:inline-block;vertical-align:middle;outline:0}:host([invalid]:not([invalid=false])){--sinch-color-checkbox-border:var(--sinch-color-raspberry-500);--sinch-color-checkbox-background-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-hover:var(--sinch-color-raspberry-500);--sinch-color-checkbox-circle-hover-checked:var(--sinch-color-raspberry-100);--sinch-color-checkbox-background-hover-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-hover-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-focus:var(--sinch-color-raspberry-500);--sinch-color-checkbox-circle-focus-checked:var(--sinch-color-raspberry-200);--sinch-color-checkbox-background-focus-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-focus-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-active:var(--sinch-color-raspberry-500);--sinch-color-checkbox-circle-active-checked:var(--sinch-color-raspberry-300);--sinch-color-checkbox-background-active-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-active-checked:var(--sinch-color-raspberry-500);--sinch-color-checkbox-border-disabled:var(--sinch-color-raspberry-200);--sinch-color-checkbox-background-disabled-checked:var(--sinch-color-raspberry-200);--sinch-color-checkbox-border-disabled-checked:var(--sinch-color-raspberry-200);--sinch-color-checkbox-text:var(--sinch-color-text-invalid);--sinch-color-checkbox-text-disabled:var(--sinch-color-raspberry-200)}#wrapper{display:flex;flex-direction:row;box-sizing:border-box;width:100%;height:32px}#checkbox{all:initial;display:block;width:32px;height:32px;cursor:pointer}#checkbox:disabled{cursor:initial}#icon-container{position:relative;width:32px;height:32px}#checkbox::before{content:"";position:absolute;top:0;left:0;width:32px;height:32px;border-radius:16px;pointer-events:none;background-color:var(--sinch-color-checkbox-circle);transition:background-color .1s linear}#checkbox::after{content:"";position:absolute;top:7px;left:7px;width:18px;height:18px;border-radius:var(--sinch-shape-radius-xs);pointer-events:none;background-color:var(--sinch-color-checkbox-background);border:2px solid var(--sinch-color-checkbox-border);transition:background-color .1s linear;box-sizing:border-box}#icon-checkmark{position:absolute;left:9px;top:10px;transition:opacity .1s linear;opacity:0;pointer-events:none}#icon-indeterminate{position:absolute;left:10px;top:15px;transition:opacity .1s linear;opacity:0;pointer-events:none}@media (prefers-reduced-motion){#checkbox::after,#checkbox::before,#icon-checkmark,#icon-indeterminate{transition:none}}#label{display:none;flex:1;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;padding-left:6px;font:var(--sinch-font-body);color:var(--sinch-color-checkbox-text)}:host([text]:not([text=""])) #label{display:block}:host([disabled]:not([disabled=false])) #label{color:var(--sinch-color-checkbox-text-disabled)}:host(:is(:not([indeterminate]),[indeterminate=false])) #checkbox:checked~#icon-checkmark{opacity:1}:host([indeterminate]:not([indeterminate=false])) #checkbox:checked~#icon-indeterminate{opacity:1}#checkbox:checked::before{background-color:var(--sinch-color-checkbox-circle-checked)}#checkbox:checked::after{background-color:var(--sinch-color-checkbox-background-checked);border-color:var(--sinch-color-checkbox-border-checked)}#checkbox:focus::before{background-color:var(--sinch-color-checkbox-circle-focus)}#checkbox:focus::after{background-color:var(--sinch-color-checkbox-background-focus);border-color:var(--sinch-color-checkbox-border-focus)}#checkbox:hover::before{background-color:var(--sinch-color-checkbox-circle-hover)}#checkbox:hover::after{background-color:var(--sinch-color-checkbox-background-hover);border-color:var(--sinch-color-checkbox-border-hover)}#checkbox:active::before{background-color:var(--sinch-color-checkbox-circle-active)}#checkbox:active::after{background-color:var(--sinch-color-checkbox-background-active);border-color:var(--sinch-color-checkbox-border-active)}#checkbox:disabled::before{background-color:var(--sinch-color-checkbox-circle-disabled)}#checkbox:disabled::after{background-color:var(--sinch-color-checkbox-background-disabled);border-color:var(--sinch-color-checkbox-border-disabled)}#checkbox:focus:checked::before{background-color:var(--sinch-color-checkbox-circle-focus-checked)}#checkbox:focus:checked::after{background-color:var(--sinch-color-checkbox-background-focus-checked);border-color:var(--sinch-color-checkbox-border-focus-checked)}#checkbox:hover:checked::before{background-color:var(--sinch-color-checkbox-circle-hover-checked)}#checkbox:hover:checked::after{background-color:var(--sinch-color-checkbox-background-hover-checked);border-color:var(--sinch-color-checkbox-border-hover-checked)}#checkbox:active:checked::before{background-color:var(--sinch-color-checkbox-circle-active-checked)}#checkbox:active:checked::after{background-color:var(--sinch-color-checkbox-background-active-checked);border-color:var(--sinch-color-checkbox-border-active-checked)}#checkbox:disabled:checked::before{background-color:var(--sinch-color-checkbox-circle-disabled-checked)}#checkbox:disabled:checked::after{background-color:var(--sinch-color-checkbox-background-disabled-checked);border-color:var(--sinch-color-checkbox-border-disabled-checked)}</style><div id="wrapper"><div id="icon-container"><input id="checkbox" type="checkbox"/><svg id="icon-checkmark" width="14" height="11" aria-hidden="true"><path d="M14 1.99999L12.59 0.579987L4.98995 8.17L1.49997 4.5L0.0799694 5.91L4.98995 11L14 1.99999Z" fill="white"/></svg><svg id="icon-indeterminate" width="12" height="2" aria-hidden="true"><line y1="1" x2="12" y2="1" stroke="white" stroke-width="2"/></svg></div><label for="checkbox" id="label"></label></div>';
12
3
  const template = document.createElement('template');
13
4
  template.innerHTML = templateHTML;
14
- defineCustomElement('sinch-checkbox', (_$input = new WeakMap(), _$label = new WeakMap(), _onCheckboxInput = new WeakMap(), _onCheckboxFocus = new WeakMap(), _onCheckboxBlur = new WeakMap(), _onChangeReactHandler = new WeakMap(), _onFocusReactHandler = new WeakMap(), _onBlurReactHandler = new WeakMap(), class extends NectaryElement {
5
+ defineCustomElement('sinch-checkbox', class extends NectaryElement {
6
+ #$input;
7
+ #$label;
8
+
15
9
  constructor() {
16
10
  super();
17
-
18
- _classPrivateFieldInitSpec(this, _$input, {
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, _onCheckboxInput, {
29
- writable: true,
30
- value: e => {
31
- e.stopPropagation();
32
-
33
- const isChecked = _classPrivateFieldGet(this, _$input).checked;
34
-
35
- _classPrivateFieldGet(this, _$input).checked = this.checked;
36
- this.dispatchEvent(new CustomEvent('change', {
37
- detail: isChecked,
38
- bubbles: true
39
- }));
40
- this.dispatchEvent(new CustomEvent('-change', {
41
- detail: isChecked
42
- }));
43
- }
44
- });
45
-
46
- _classPrivateFieldInitSpec(this, _onCheckboxFocus, {
47
- writable: true,
48
- value: () => {
49
- this.dispatchEvent(new CustomEvent('-focus'));
50
- }
51
- });
52
-
53
- _classPrivateFieldInitSpec(this, _onCheckboxBlur, {
54
- writable: true,
55
- value: () => {
56
- this.dispatchEvent(new CustomEvent('-blur'));
57
- }
58
- });
59
-
60
- _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
61
- writable: true,
62
- value: e => {
63
- getReactEventHandler(this, 'on-change')?.(e);
64
- }
65
- });
66
-
67
- _classPrivateFieldInitSpec(this, _onFocusReactHandler, {
68
- writable: true,
69
- value: e => {
70
- getReactEventHandler(this, 'on-focus')?.(e);
71
- }
72
- });
73
-
74
- _classPrivateFieldInitSpec(this, _onBlurReactHandler, {
75
- writable: true,
76
- value: e => {
77
- getReactEventHandler(this, 'on-blur')?.(e);
78
- }
79
- });
80
-
81
11
  const shadowRoot = this.attachShadow();
82
12
  shadowRoot.appendChild(template.content.cloneNode(true));
83
-
84
- _classPrivateFieldSet(this, _$input, shadowRoot.querySelector('input'));
85
-
86
- _classPrivateFieldSet(this, _$label, shadowRoot.querySelector('label'));
13
+ this.#$input = shadowRoot.querySelector('input');
14
+ this.#$label = shadowRoot.querySelector('label');
87
15
  }
88
16
 
89
17
  connectedCallback() {
90
18
  this.setAttribute('role', 'checkbox');
91
-
92
- _classPrivateFieldGet(this, _$input).addEventListener('input', _classPrivateFieldGet(this, _onCheckboxInput));
93
-
94
- _classPrivateFieldGet(this, _$input).addEventListener('focus', _classPrivateFieldGet(this, _onCheckboxFocus));
95
-
96
- _classPrivateFieldGet(this, _$input).addEventListener('blur', _classPrivateFieldGet(this, _onCheckboxBlur));
97
-
98
- this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
99
- this.addEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
100
- this.addEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
19
+ this.#$input.addEventListener('input', this.#onCheckboxInput);
20
+ this.#$input.addEventListener('focus', this.#onCheckboxFocus);
21
+ this.#$input.addEventListener('blur', this.#onCheckboxBlur);
22
+ this.addEventListener('-change', this.#onChangeReactHandler);
23
+ this.addEventListener('-focus', this.#onFocusReactHandler);
24
+ this.addEventListener('-blur', this.#onBlurReactHandler);
101
25
  }
102
26
 
103
27
  disconnectedCallback() {
104
- _classPrivateFieldGet(this, _$input).removeEventListener('input', _classPrivateFieldGet(this, _onCheckboxInput));
105
-
106
- _classPrivateFieldGet(this, _$input).removeEventListener('focus', _classPrivateFieldGet(this, _onCheckboxFocus));
107
-
108
- _classPrivateFieldGet(this, _$input).removeEventListener('blur', _classPrivateFieldGet(this, _onCheckboxBlur));
109
-
110
- this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
111
- this.removeEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
112
- this.removeEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
28
+ this.#$input.removeEventListener('input', this.#onCheckboxInput);
29
+ this.#$input.removeEventListener('focus', this.#onCheckboxFocus);
30
+ this.#$input.removeEventListener('blur', this.#onCheckboxBlur);
31
+ this.removeEventListener('-change', this.#onChangeReactHandler);
32
+ this.removeEventListener('-focus', this.#onFocusReactHandler);
33
+ this.removeEventListener('-blur', this.#onBlurReactHandler);
113
34
  }
114
35
 
115
36
  static get observedAttributes() {
@@ -161,21 +82,21 @@ defineCustomElement('sinch-checkbox', (_$input = new WeakMap(), _$label = new We
161
82
  }
162
83
 
163
84
  get text() {
164
- return getAttribute(this, 'text', null);
85
+ return getAttribute(this, 'text');
165
86
  }
166
87
 
167
88
  attributeChangedCallback(name, _, newVal) {
168
89
  switch (name) {
169
90
  case 'text':
170
91
  {
171
- _classPrivateFieldGet(this, _$label).textContent = newVal;
92
+ this.#$label.textContent = newVal;
172
93
  break;
173
94
  }
174
95
 
175
96
  case 'checked':
176
97
  {
177
98
  const isChecked = isAttrTrue(newVal);
178
- _classPrivateFieldGet(this, _$input).checked = isChecked;
99
+ this.#$input.checked = isChecked;
179
100
  updateExplicitBooleanAttribute(this, 'aria-checked', isChecked);
180
101
  break;
181
102
  }
@@ -183,19 +104,50 @@ defineCustomElement('sinch-checkbox', (_$input = new WeakMap(), _$label = new We
183
104
  case 'disabled':
184
105
  {
185
106
  const isDisabled = isAttrTrue(newVal);
186
- _classPrivateFieldGet(this, _$input).disabled = isDisabled;
107
+ this.#$input.disabled = isDisabled;
187
108
  updateBooleanAttribute(this, 'disabled', isDisabled);
188
109
  break;
189
110
  }
190
111
  }
191
112
  }
192
113
 
193
- focus() {
194
- _classPrivateFieldGet(this, _$input).focus();
114
+ get focusable() {
115
+ return true;
195
116
  }
196
117
 
197
- blur() {
198
- _classPrivateFieldGet(this, _$input).blur();
118
+ focus() {
119
+ this.#$input.focus();
199
120
  }
200
121
 
201
- }));
122
+ blur() {
123
+ this.#$input.blur();
124
+ }
125
+
126
+ #onCheckboxInput = e => {
127
+ e.stopPropagation();
128
+ const isChecked = this.#$input.checked;
129
+ this.#$input.checked = this.checked;
130
+ this.dispatchEvent(new CustomEvent('change', {
131
+ detail: isChecked,
132
+ bubbles: true
133
+ }));
134
+ this.dispatchEvent(new CustomEvent('-change', {
135
+ detail: isChecked
136
+ }));
137
+ };
138
+ #onCheckboxFocus = () => {
139
+ this.dispatchEvent(new CustomEvent('-focus'));
140
+ };
141
+ #onCheckboxBlur = () => {
142
+ this.dispatchEvent(new CustomEvent('-blur'));
143
+ };
144
+ #onChangeReactHandler = e => {
145
+ getReactEventHandler(this, 'on-change')?.(e);
146
+ };
147
+ #onFocusReactHandler = e => {
148
+ getReactEventHandler(this, 'on-focus')?.(e);
149
+ };
150
+ #onBlurReactHandler = e => {
151
+ getReactEventHandler(this, 'on-blur')?.(e);
152
+ };
153
+ });
@@ -0,0 +1,13 @@
1
+ import '../text';
2
+ import '../icons/cancel';
3
+ import type { TSinchChipElement, TSinchChipReact } from './types';
4
+ declare global {
5
+ namespace JSX {
6
+ interface IntrinsicElements {
7
+ 'sinch-chip': TSinchChipReact;
8
+ }
9
+ }
10
+ interface HTMLElementTagNameMap {
11
+ 'sinch-chip': TSinchChipElement;
12
+ }
13
+ }
package/chip/index.js ADDED
@@ -0,0 +1,140 @@
1
+ import '../text';
2
+ import '../icons/cancel';
3
+ import { defineCustomElement, getBooleanAttribute, getAttribute, updateBooleanAttribute, updateAttribute, NectaryElement, getReactEventHandler } from '../utils';
4
+ import { NO_COLOR } from '../utils/colors';
5
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#button{all:initial;position:relative;display:flex;flex-direction:row;align-items:center;gap:4px;width:100%;height:24px;padding:0 5px 0 9px;border-radius:12px;background-color:var(--sinch-color-snow-500);color:var(--sinch-color-text-default);box-sizing:border-box;cursor:pointer;--sinch-color-icon:var(--sinch-color-stormy-500);--sinch-size-icon:16px}#button:focus-visible::after{content:"";position:absolute;inset:-4px;border-radius:16px;border:2px solid var(--sinch-color-border-focus);pointer-events:none}@supports not selector(:focus-visible){#button:focus::after{content:"";position:absolute;inset:-4px;border-radius:16px;border:2px solid var(--sinch-color-border-focus);pointer-events:none}:host([small]:not([small=false])) #button:focus::after{border-radius:14px}}#text{flex:1}:host([small]:not([small=false])) #button{height:20px;border-radius:10px;padding:0 3px 0 7px}:host([small]:not([small=false])) #button:focus-visible::after{border-radius:14px}::slotted(*){margin-left:-4px}</style><button id="button"><slot name="icon"></slot><sinch-text id="text" type="xs" ellipsis></sinch-text><sinch-icon-cancel id="close"></sinch-icon-cancel></button>';
6
+ const template = document.createElement('template');
7
+ template.innerHTML = templateHTML;
8
+ defineCustomElement('sinch-chip', class extends NectaryElement {
9
+ #$text;
10
+ #$button;
11
+ #controller = null;
12
+
13
+ constructor() {
14
+ super();
15
+ const shadowRoot = this.attachShadow();
16
+ shadowRoot.appendChild(template.content.cloneNode(true));
17
+ this.#$button = shadowRoot.querySelector('#button');
18
+ this.#$text = shadowRoot.querySelector('#text');
19
+ }
20
+
21
+ connectedCallback() {
22
+ this.#controller = new AbortController();
23
+ const {
24
+ signal
25
+ } = this.#controller;
26
+ this.setAttribute('role', 'button');
27
+ this.#$button.addEventListener('click', this.#onButtonClick, {
28
+ signal
29
+ });
30
+ this.#$button.addEventListener('focus', this.#onButtonFocus, {
31
+ signal
32
+ });
33
+ this.#$button.addEventListener('blur', this.#onButtonBlur, {
34
+ signal
35
+ });
36
+ this.addEventListener('-click', this.#onClickReactHandler, {
37
+ signal
38
+ });
39
+ this.addEventListener('-focus', this.#onFocusReactHandler, {
40
+ signal
41
+ });
42
+ this.addEventListener('-blur', this.#onBlurReactHandler, {
43
+ signal
44
+ });
45
+ this.#updateColor();
46
+ }
47
+
48
+ disconnectedCallback() {
49
+ this.#controller.abort();
50
+ }
51
+
52
+ get color() {
53
+ return getAttribute(this, 'color');
54
+ }
55
+
56
+ set color(value) {
57
+ updateAttribute(this, 'color', value);
58
+ }
59
+
60
+ get text() {
61
+ return getAttribute(this, 'text', '');
62
+ }
63
+
64
+ set text(value) {
65
+ updateAttribute(this, 'text', value);
66
+ }
67
+
68
+ get small() {
69
+ return getBooleanAttribute(this, 'small');
70
+ }
71
+
72
+ set small(isSmall) {
73
+ updateBooleanAttribute(this, 'small', isSmall);
74
+ }
75
+
76
+ static get observedAttributes() {
77
+ return ['text', 'color'];
78
+ }
79
+
80
+ attributeChangedCallback(name, _, newVal) {
81
+ switch (name) {
82
+ case 'color':
83
+ {
84
+ this.#updateColor();
85
+ break;
86
+ }
87
+
88
+ case 'text':
89
+ {
90
+ this.#$text.textContent = newVal;
91
+ break;
92
+ }
93
+ }
94
+ }
95
+
96
+ #updateColor() {
97
+ const colorName = this.color ?? NO_COLOR;
98
+
99
+ if (colorName !== NO_COLOR) {
100
+ this.#$button.style.setProperty('background-color', `var(--sinch-color-map-${colorName}-bg)`);
101
+ this.#$button.style.setProperty('color', `var(--sinch-color-map-${colorName}-fg)`);
102
+ this.#$button.style.setProperty('--sinch-color-icon', `var(--sinch-color-map-${colorName}-fg)`);
103
+ } else {
104
+ this.#$button.style.removeProperty('background-color');
105
+ this.#$button.style.removeProperty('color');
106
+ this.#$button.style.removeProperty('--sinch-color-icon');
107
+ }
108
+ }
109
+
110
+ get focusable() {
111
+ return true;
112
+ }
113
+
114
+ focus() {
115
+ this.#$button.focus();
116
+ }
117
+
118
+ blur() {
119
+ this.#$button.blur();
120
+ }
121
+
122
+ #onButtonClick = () => {
123
+ this.dispatchEvent(new CustomEvent('-click'));
124
+ };
125
+ #onButtonFocus = () => {
126
+ this.dispatchEvent(new CustomEvent('-focus'));
127
+ };
128
+ #onButtonBlur = () => {
129
+ this.dispatchEvent(new CustomEvent('-blur'));
130
+ };
131
+ #onFocusReactHandler = () => {
132
+ getReactEventHandler(this, 'on-focus')?.();
133
+ };
134
+ #onBlurReactHandler = () => {
135
+ getReactEventHandler(this, 'on-blur')?.();
136
+ };
137
+ #onClickReactHandler = e => {
138
+ getReactEventHandler(this, 'on-click')?.(e);
139
+ };
140
+ });
@@ -0,0 +1,37 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ export declare type TSinchChipElement = HTMLElement & {
3
+ /** Text */
4
+ text: string;
5
+ /** Color, gray by default */
6
+ color: string | null;
7
+ /** Small */
8
+ small: boolean;
9
+ /** Click event */
10
+ addEventListener(type: '-click', listener: (e: CustomEvent<void>) => void): void;
11
+ /** Focus event */
12
+ addEventListener(type: '-focus', listener: (e: CustomEvent<void>) => void): void;
13
+ /** Blur event */
14
+ addEventListener(type: '-blur', listener: (e: CustomEvent<void>) => void): void;
15
+ /** Text */
16
+ setAttribute(name: 'text', value: string): void;
17
+ /** Color, gray by default */
18
+ setAttribute(name: 'color', value: string): void;
19
+ /** Small */
20
+ setAttribute(name: 'small', value: ''): void;
21
+ };
22
+ export declare type TSinchChipReact = TSinchElementReact<TSinchChipElement> & {
23
+ /** Text */
24
+ text: string;
25
+ /** Color, gray by default */
26
+ color?: string;
27
+ /** Small */
28
+ small?: boolean;
29
+ /** Click event handler */
30
+ 'on-click'?: (e: CustomEvent<void>) => void;
31
+ /** Focus event handler */
32
+ 'on-focus'?: (e: CustomEvent<void>) => void;
33
+ /** Blur event handler */
34
+ 'on-blur'?: (e: CustomEvent<void>) => void;
35
+ /** Label that is used for a11y` */
36
+ 'aria-label': string;
37
+ };
@@ -0,0 +1,14 @@
1
+ import '../color-swatch';
2
+ import '../tooltip';
3
+ import '../icons/check';
4
+ import type { TSinchSelectMenuElement, TSinchSelectMenuReact } from './types';
5
+ declare global {
6
+ namespace JSX {
7
+ interface IntrinsicElements {
8
+ 'sinch-color-menu': TSinchSelectMenuReact;
9
+ }
10
+ }
11
+ interface HTMLElementTagNameMap {
12
+ 'sinch-color-menu': TSinchSelectMenuElement;
13
+ }
14
+ }