@nectary/components 1.2.0 → 1.2.2

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.
package/colors.json CHANGED
@@ -73,9 +73,9 @@
73
73
  "colorCeltic700": "#003B7E",
74
74
  "colorCeltic400": "#2071CE",
75
75
  "colorCeltic200": "#D5E5F8",
76
- "colorJasper700": "#882024",
77
- "colorJasper400": "#D13D42",
78
- "colorJasper200": "#FBD5D5",
76
+ "colorJasper700": "#B71C1C",
77
+ "colorJasper400": "#F44336",
78
+ "colorJasper200": "#FFCDD2",
79
79
  "colorPumpkin700": "#9C2E00",
80
80
  "colorPumpkin400": "#F35B1C",
81
81
  "colorPumpkin200": "#FFE8D6",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",
package/pop/index.js CHANGED
@@ -13,7 +13,7 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
13
13
  #$contentSlot;
14
14
  #$targetOpenWrapper;
15
15
  #targetActiveElement = null;
16
- #controller = null;
16
+ #controller;
17
17
  #keydownContext;
18
18
  #visibilityContext;
19
19
  #targetStyleValue = null;
@@ -31,10 +31,13 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
31
31
  this.#resizeThrottle = throttleAnimationFrame(this.#updateOrientation);
32
32
  this.#keydownContext = new Context(this.#$contentSlot, 'keydown');
33
33
  this.#visibilityContext = new Context(this.#$contentSlot, 'visibility');
34
+ this.#controller = new AbortController();
34
35
  }
35
36
  connectedCallback() {
36
37
  super.connectedCallback();
37
- this.#controller = new AbortController();
38
+ if (this.#controller === null) {
39
+ this.#controller = new AbortController();
40
+ }
38
41
  const {
39
42
  signal
40
43
  } = this.#controller;
@@ -58,6 +61,8 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
58
61
  disconnectedCallback() {
59
62
  super.disconnectedCallback();
60
63
  this.#controller.abort();
64
+ this.#controller = null;
65
+ this.#resizeThrottle.cancel();
61
66
  this.#onCollapse();
62
67
  }
63
68
  static get observedAttributes() {
@@ -102,7 +107,9 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
102
107
  {
103
108
  if (isAttrTrue(newVal)) {
104
109
  requestAnimationFrame(() => {
105
- this.#onExpand();
110
+ if (this.isConnected && getBooleanAttribute(this, 'open')) {
111
+ this.#onExpand();
112
+ }
106
113
  });
107
114
  } else {
108
115
  this.#onCollapse();
@@ -186,9 +193,11 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
186
193
  this.#$targetOpenSlot.removeEventListener('focus', this.#stopEventPropagation, true);
187
194
  if (!isElementFocused(this.#targetActiveElement)) {
188
195
  requestAnimationFrame(() => {
189
- this.#$targetOpenSlot.addEventListener('focus', this.#stopEventPropagation, true);
190
- this.#targetActiveElement.focus();
191
- this.#$targetOpenSlot.removeEventListener('focus', this.#stopEventPropagation, true);
196
+ if (this.isConnected && this.#isOpen()) {
197
+ this.#$targetOpenSlot.addEventListener('focus', this.#stopEventPropagation, true);
198
+ this.#targetActiveElement.focus();
199
+ this.#$targetOpenSlot.removeEventListener('focus', this.#stopEventPropagation, true);
200
+ }
192
201
  });
193
202
  }
194
203
  }
@@ -196,7 +205,7 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
196
205
  disableScroll();
197
206
  window.addEventListener('resize', this.#onResize);
198
207
  requestAnimationFrame(() => {
199
- if (this.#isOpen()) {
208
+ if (this.isConnected && this.#isOpen()) {
200
209
  this.#$contentSlot.addEventListener('slotchange', this.#onContentSlotChange);
201
210
  }
202
211
  });
@@ -238,9 +247,11 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
238
247
  if (!isElementFocused(this.#targetActiveElement)) {
239
248
  const $targetEl = this.#targetActiveElement;
240
249
  requestAnimationFrame(() => {
241
- this.#$targetSlot.addEventListener('focus', this.#stopEventPropagation, true);
242
- $targetEl.focus();
243
- this.#$targetSlot.removeEventListener('focus', this.#stopEventPropagation, true);
250
+ if (this.isConnected && !this.#isOpen()) {
251
+ this.#$targetSlot.addEventListener('focus', this.#stopEventPropagation, true);
252
+ $targetEl.focus();
253
+ this.#$targetSlot.removeEventListener('focus', this.#stopEventPropagation, true);
254
+ }
244
255
  });
245
256
  }
246
257
  this.#targetActiveElement = null;
@@ -2,10 +2,10 @@ import '../input';
2
2
  import '../icon-button';
3
3
  import '../icon';
4
4
  import '../text';
5
- import { attrValueToPixels, defineCustomElement, getAttribute, getBooleanAttribute, unpackCsv, getFirstCsvValue, getIntegerAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv, updateExplicitBooleanAttribute, updateIntegerAttribute, debounceTimeout, setClass, subscribeContext, getCssVar } from '../utils';
5
+ import { attrValueToPixels, defineCustomElement, getAttribute, getBooleanAttribute, unpackCsv, getFirstCsvValue, getIntegerAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv, updateExplicitBooleanAttribute, updateIntegerAttribute, debounceTimeout, setClass, subscribeContext, getCssVar, hasClass } from '../utils';
6
6
  const templateHTML = '<style>:host{display:block;outline:0}#listbox{overflow-y:auto}#search{display:none;margin:10px}#search.active{display:block}#not-found{display:none;width:100%;height:30px;align-items:center;justify-content:center;margin-bottom:10px;color:var(--sinch-color-text-muted);pointer-events:none;user-select:none}#not-found.active{display:flex}::slotted(.hidden){display:none}</style><sinch-input id="search" size="s" placeholder="Search"><sinch-icon id="icon-search" slot="icon"></sinch-icon></sinch-input><div id="not-found"><sinch-text type="m">No results</sinch-text></div><div id="listbox" role="presentation"><slot></slot></div>';
7
7
  const ITEM_HEIGHT = 40;
8
- const NUM_ITEMS_SEARCH = 20;
8
+ const NUM_ITEMS_SEARCH = 7;
9
9
  const template = document.createElement('template');
10
10
  template.innerHTML = templateHTML;
11
11
  defineCustomElement('sinch-select-menu', class extends NectaryElement {
@@ -29,35 +29,23 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
29
29
  }
30
30
  connectedCallback() {
31
31
  this.#controller = new AbortController();
32
- const {
33
- signal
34
- } = this.#controller;
32
+ const options = {
33
+ signal: this.#controller.signal
34
+ };
35
35
  this.setAttribute('role', 'listbox');
36
36
  this.setAttribute('tabindex', '0');
37
- this.addEventListener('keydown', this.#onListboxKeyDown, {
38
- signal
39
- });
40
- this.addEventListener('blur', this.#onListboxBlur, {
41
- signal
42
- });
43
- this.#$listbox.addEventListener('mousedown', this.#onListboxMousedown, {
44
- signal
45
- });
46
- this.#$listbox.addEventListener('click', this.#onListboxClick, {
47
- signal
48
- });
49
- this.#$search.addEventListener('-change', this.#onSearchChange, {
50
- signal
51
- });
52
- this.#$optionSlot.addEventListener('slotchange', this.#onOptionSlotChange, {
53
- signal
54
- });
55
- this.addEventListener('-change', this.#onChangeReactHandler, {
56
- signal
57
- });
58
- subscribeContext(this, 'keydown', this.#onContextKeyDown, signal);
59
- subscribeContext(this, 'visibility', this.#onContextVisibility, signal);
37
+ this.addEventListener('keydown', this.#onListboxKeyDown, options);
38
+ this.addEventListener('focus', this.#onFocus, options);
39
+ this.addEventListener('blur', this.#onListboxBlur, options);
40
+ this.#$listbox.addEventListener('mousedown', this.#onListboxMousedown, options);
41
+ this.#$listbox.addEventListener('click', this.#onListboxClick, options);
42
+ this.#$search.addEventListener('-change', this.#onSearchChange, options);
43
+ this.#$optionSlot.addEventListener('slotchange', this.#onOptionSlotChange, options);
44
+ this.addEventListener('-change', this.#onChangeReactHandler, options);
45
+ subscribeContext(this, 'keydown', this.#onContextKeyDown, this.#controller.signal);
46
+ subscribeContext(this, 'visibility', this.#onContextVisibility, this.#controller.signal);
60
47
  updateAttribute(this.#$iconSearch, 'name', getCssVar(this, '--sinch-select-menu-icon-search'));
48
+ this.#onOptionSlotChange();
61
49
  }
62
50
  disconnectedCallback() {
63
51
  this.#controller.abort();
@@ -66,24 +54,6 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
66
54
  static get observedAttributes() {
67
55
  return ['value', 'rows', 'multiple'];
68
56
  }
69
- set value(value) {
70
- updateAttribute(this, 'value', value);
71
- }
72
- get value() {
73
- return getAttribute(this, 'value', '');
74
- }
75
- set rows(value) {
76
- updateIntegerAttribute(this, 'rows', value);
77
- }
78
- get rows() {
79
- return getIntegerAttribute(this, 'rows', null);
80
- }
81
- set multiple(isMultiple) {
82
- updateBooleanAttribute(this, 'multiple', isMultiple);
83
- }
84
- get multiple() {
85
- return getBooleanAttribute(this, 'multiple');
86
- }
87
57
  attributeChangedCallback(name, oldVal, newVal) {
88
58
  if (oldVal === newVal) {
89
59
  return;
@@ -110,6 +80,33 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
110
80
  }
111
81
  }
112
82
  }
83
+ set value(value) {
84
+ updateAttribute(this, 'value', value);
85
+ }
86
+ get value() {
87
+ return getAttribute(this, 'value', '');
88
+ }
89
+ set rows(value) {
90
+ updateIntegerAttribute(this, 'rows', value);
91
+ }
92
+ get rows() {
93
+ return getIntegerAttribute(this, 'rows', null);
94
+ }
95
+ set multiple(isMultiple) {
96
+ updateBooleanAttribute(this, 'multiple', isMultiple);
97
+ }
98
+ get multiple() {
99
+ return getBooleanAttribute(this, 'multiple');
100
+ }
101
+ get focusable() {
102
+ return true;
103
+ }
104
+ #onFocus = () => {
105
+ const isSearchActive = hasClass(this.#$search, 'active');
106
+ if (isSearchActive) {
107
+ this.#$search.focus();
108
+ }
109
+ };
113
110
  #onListboxMousedown = e => {
114
111
  const $elem = e.target;
115
112
  if (!getBooleanAttribute($elem, 'disabled')) {
@@ -147,6 +144,7 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
147
144
  #onContextVisibility = e => {
148
145
  if (e.detail) {
149
146
  this.#selectOption(this.#findCheckedOption());
147
+ this.#onFocus();
150
148
  } else {
151
149
  this.#selectOption(null);
152
150
  }
@@ -306,7 +304,4 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
306
304
  #onChangeReactHandler = e => {
307
305
  getReactEventHandler(this, 'on-change')?.(e);
308
306
  };
309
- get focusable() {
310
- return true;
311
- }
312
307
  });
@@ -18,6 +18,8 @@
18
18
  --sinch-color-swatch-color-light-violet-fg: var(--sinch-color-violet-700);
19
19
  --sinch-color-swatch-color-light-yellow-bg: var(--sinch-color-bolt-200);
20
20
  --sinch-color-swatch-color-light-yellow-fg: var(--sinch-color-bolt-700);
21
+ --sinch-color-swatch-color-light-red-bg: var(--sinch-color-jasper-200);
22
+ --sinch-color-swatch-color-light-red-fg: var(--sinch-color-jasper-700);
21
23
  --sinch-color-swatch-color-dark-blue-bg: var(--sinch-color-night-700);
22
24
  --sinch-color-swatch-color-dark-blue-fg: var(--sinch-color-night-200);
23
25
  --sinch-color-swatch-color-dark-brown-bg: var(--sinch-color-mud-700);
@@ -34,6 +36,8 @@
34
36
  --sinch-color-swatch-color-dark-violet-fg: var(--sinch-color-violet-200);
35
37
  --sinch-color-swatch-color-dark-yellow-bg: var(--sinch-color-bolt-700);
36
38
  --sinch-color-swatch-color-dark-yellow-fg: var(--sinch-color-bolt-200);
39
+ --sinch-color-swatch-color-dark-red-bg: var(--sinch-color-jasper-700);
40
+ --sinch-color-swatch-color-dark-red-fg: var(--sinch-color-jasper-200);
37
41
  --sinch-color-swatch-color-blue-bg: var(--sinch-color-night-400);
38
42
  --sinch-color-swatch-color-blue-fg: var(--sinch-color-snow-100);
39
43
  --sinch-color-swatch-color-brown-bg: var(--sinch-color-mud-400);
@@ -50,6 +54,8 @@
50
54
  --sinch-color-swatch-color-violet-fg: var(--sinch-color-stormy-500);
51
55
  --sinch-color-swatch-color-yellow-bg: var(--sinch-color-bolt-400);
52
56
  --sinch-color-swatch-color-yellow-fg: var(--sinch-color-stormy-500);
57
+ --sinch-color-swatch-color-red-bg: var(--sinch-color-jasper-400);
58
+ --sinch-color-swatch-color-red-fg: var(--sinch-color-stormy-500);
53
59
  --sinch-color-swatch-color-skin-tone-0-bg: var(--sinch-color-skin-tone-0);
54
60
  --sinch-color-swatch-color-skin-tone-0-fg: var(--sinch-color-stormy-500);
55
61
  --sinch-color-swatch-color-skin-tone-10-bg: var(--sinch-color-skin-tone-10);
package/theme/colors.js CHANGED
@@ -1,4 +1,4 @@
1
- export const lightColorNames = ['light-violet', 'light-blue', 'light-green', 'light-yellow', 'light-orange', 'light-pink', 'light-brown', 'light-gray'].join(',');
2
- export const darkColorNames = ['dark-violet', 'dark-blue', 'dark-green', 'dark-yellow', 'dark-orange', 'dark-pink', 'dark-brown', 'dark-gray'].join(',');
3
- export const vibrantColorNames = ['violet', 'blue', 'green', 'yellow', 'orange', 'pink', 'brown', 'gray'].join(',');
1
+ export const lightColorNames = ['light-violet', 'light-blue', 'light-green', 'light-yellow', 'light-orange', 'light-red', 'light-pink', 'light-brown', 'light-gray'].join(',');
2
+ export const darkColorNames = ['dark-violet', 'dark-blue', 'dark-green', 'dark-yellow', 'dark-orange', 'dark-red', 'dark-pink', 'dark-brown', 'dark-gray'].join(',');
3
+ export const vibrantColorNames = ['violet', 'blue', 'green', 'yellow', 'orange', 'red', 'pink', 'brown', 'gray'].join(',');
4
4
  export const skinToneColorNames = ['skin-tone-0', 'skin-tone-10', 'skin-tone-20', 'skin-tone-30', 'skin-tone-40', 'skin-tone-50'].join(',');
package/theme/palette.css CHANGED
@@ -74,9 +74,9 @@
74
74
  --sinch-color-celtic-700: #003B7E;
75
75
  --sinch-color-celtic-400: #2071CE;
76
76
  --sinch-color-celtic-200: #D5E5F8;
77
- --sinch-color-jasper-700: #882024;
78
- --sinch-color-jasper-400: #D13D42;
79
- --sinch-color-jasper-200: #FBD5D5;
77
+ --sinch-color-jasper-700: #B71C1C;
78
+ --sinch-color-jasper-400: #F44336;
79
+ --sinch-color-jasper-200: #FFCDD2;
80
80
  --sinch-color-pumpkin-700: #9C2E00;
81
81
  --sinch-color-pumpkin-400: #F35B1C;
82
82
  --sinch-color-pumpkin-200: #FFE8D6;
package/utils/dom.d.ts CHANGED
@@ -25,6 +25,7 @@ export declare function getIntegerAttribute($element: Element, attrName: string)
25
25
  export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: null): number | null;
26
26
  export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: number): number;
27
27
  export declare const setClass: (elem: Element, name: string, isSet: boolean) => void;
28
+ export declare const hasClass: (elem: Element, name: string) => boolean;
28
29
  export declare const getCssVar: (element: Element, variableName: string) => string | null;
29
30
  export declare const getCssVars: (element: Element, variableNames: string[]) => (string | null)[];
30
31
  export declare const cloneNode: (el: Element, deep: boolean) => Element;
package/utils/dom.js CHANGED
@@ -122,6 +122,9 @@ export function getIntegerAttribute($element, attrName, defaultValue) {
122
122
  export const setClass = (elem, name, isSet) => {
123
123
  isSet ? elem.classList.add(name) : elem.classList.remove(name);
124
124
  };
125
+ export const hasClass = (elem, name) => {
126
+ return elem.classList.contains(name);
127
+ };
125
128
  export const getCssVar = (element, variableName) => {
126
129
  const result = getComputedStyle(element).getPropertyValue(variableName).trim();
127
130
  return result === '' ? null : result;