@nectary/components 5.30.0 → 5.31.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.
package/bundle.js
CHANGED
|
@@ -12599,7 +12599,7 @@ class SelectButton extends NectaryElement {
|
|
|
12599
12599
|
};
|
|
12600
12600
|
}
|
|
12601
12601
|
defineCustomElement("sinch-select-button", SelectButton);
|
|
12602
|
-
const templateHTML$i = '<style>:host{display:block}#wrapper{display:flex;position:relative;box-sizing:border-box;min-height:40px;padding:8px 16px;align-items:center;gap:10px;user-select:none;cursor:pointer;background-color:var(--sinch-comp-select-menu-color-default-background-initial);--sinch-global-color-text:var(--sinch-comp-select-menu-color-default-option-initial);--sinch-global-color-icon:var(--sinch-comp-select-menu-color-default-icon-initial);--sinch-global-size-icon:var(--sinch-comp-select-menu-size-icon)}#content{flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-select-menu-font-option)}#icon-check{display:none;margin-right:-6px}:host([data-checked]) #icon-check{display:block}:host([data-selected])>#wrapper{background-color:var(--sinch-comp-select-menu-color-default-background-selected)}:host(:hover)>#wrapper{background-color:var(--sinch-comp-select-menu-color-default-background-hover)}:host([disabled])>#wrapper{cursor:initial;pointer-events:none;background-color:var(--sinch-comp-select-menu-color-disabled-background-initial);--sinch-global-color-text:var(--sinch-comp-select-menu-color-disabled-option-initial);--sinch-global-color-icon:var(--sinch-comp-select-menu-color-disabled-icon-initial)}::slotted([slot=icon]){margin-left:-6px}::slotted([slot=content]){pointer-events:none;flex:1}</style><div id="wrapper"><slot name="icon"></slot><slot name="content"></slot><sinch-text id="content" type="m" ellipsis></sinch-text><sinch-icon icons-version="2" name="fa-check" id="icon-check"></sinch-icon></div>';
|
|
12602
|
+
const templateHTML$i = '<style>:host{display:block}#wrapper{display:flex;position:relative;box-sizing:border-box;min-height:40px;padding:8px 16px;align-items:center;gap:10px;user-select:none;cursor:pointer;background-color:var(--sinch-comp-select-menu-color-default-background-initial);--sinch-global-color-text:var(--sinch-comp-select-menu-color-default-option-initial);--sinch-global-color-icon:var(--sinch-comp-select-menu-color-default-icon-initial);--sinch-global-size-icon:var(--sinch-comp-select-menu-size-icon)}#content{flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-select-menu-font-option)}#icon-check{display:none;margin-right:-6px}:host([data-checked]:not([action])) #icon-check{display:block}:host([data-selected])>#wrapper{background-color:var(--sinch-comp-select-menu-color-default-background-selected)}:host(:hover)>#wrapper{background-color:var(--sinch-comp-select-menu-color-default-background-hover)}:host([disabled])>#wrapper{cursor:initial;pointer-events:none;background-color:var(--sinch-comp-select-menu-color-disabled-background-initial);--sinch-global-color-text:var(--sinch-comp-select-menu-color-disabled-option-initial);--sinch-global-color-icon:var(--sinch-comp-select-menu-color-disabled-icon-initial)}::slotted([slot=icon]){margin-left:-6px}::slotted([slot=content]){pointer-events:none;flex:1}</style><div id="wrapper"><slot name="icon"></slot><slot name="content"></slot><sinch-text id="content" type="m" ellipsis></sinch-text><sinch-icon icons-version="2" name="fa-check" id="icon-check"></sinch-icon></div>';
|
|
12603
12603
|
const template$i = document.createElement("template");
|
|
12604
12604
|
template$i.innerHTML = templateHTML$i;
|
|
12605
12605
|
class SelectMenuOption extends NectaryElement {
|
|
@@ -12665,6 +12665,12 @@ class SelectMenuOption extends NectaryElement {
|
|
|
12665
12665
|
get disabled() {
|
|
12666
12666
|
return getBooleanAttribute(this, "disabled");
|
|
12667
12667
|
}
|
|
12668
|
+
set action(isAction) {
|
|
12669
|
+
updateBooleanAttribute(this, "action", isAction);
|
|
12670
|
+
}
|
|
12671
|
+
get action() {
|
|
12672
|
+
return getBooleanAttribute(this, "action");
|
|
12673
|
+
}
|
|
12668
12674
|
matchesSearch(searchValue) {
|
|
12669
12675
|
return this.text.toLowerCase().includes(searchValue.toLowerCase());
|
|
12670
12676
|
}
|
|
@@ -12736,6 +12742,7 @@ class SelectMenu extends NectaryElement {
|
|
|
12736
12742
|
options
|
|
12737
12743
|
);
|
|
12738
12744
|
this.addEventListener("-change", this.#onChangeReactHandler, options);
|
|
12745
|
+
this.addEventListener("-action", this.#onActionReactHandler, options);
|
|
12739
12746
|
subscribeContext(
|
|
12740
12747
|
this,
|
|
12741
12748
|
"keydown",
|
|
@@ -12894,7 +12901,7 @@ class SelectMenu extends NectaryElement {
|
|
|
12894
12901
|
this.focus();
|
|
12895
12902
|
if (!isTargetEqual(e, this.#$listbox) && !getBooleanAttribute($elem, "disabled")) {
|
|
12896
12903
|
this.#selectOption($elem);
|
|
12897
|
-
this.#
|
|
12904
|
+
this.#handleDispatch($elem);
|
|
12898
12905
|
}
|
|
12899
12906
|
};
|
|
12900
12907
|
#onSearchChange = (e) => {
|
|
@@ -12959,7 +12966,7 @@ class SelectMenu extends NectaryElement {
|
|
|
12959
12966
|
const $option = this.#findSelectedOption();
|
|
12960
12967
|
if ($option !== null) {
|
|
12961
12968
|
e.preventDefault();
|
|
12962
|
-
this.#
|
|
12969
|
+
this.#handleDispatch($option);
|
|
12963
12970
|
}
|
|
12964
12971
|
break;
|
|
12965
12972
|
}
|
|
@@ -12975,6 +12982,13 @@ class SelectMenu extends NectaryElement {
|
|
|
12975
12982
|
}
|
|
12976
12983
|
}
|
|
12977
12984
|
}
|
|
12985
|
+
#handleDispatch = (option) => {
|
|
12986
|
+
if (getBooleanAttribute(option, "action")) {
|
|
12987
|
+
this.#dispatchActionEvent(option);
|
|
12988
|
+
} else {
|
|
12989
|
+
this.#dispatchChangeEvent(option);
|
|
12990
|
+
}
|
|
12991
|
+
};
|
|
12978
12992
|
#onOptionSlotChange = () => {
|
|
12979
12993
|
const searchable = this.searchable;
|
|
12980
12994
|
const options = this.#getOptionElements();
|
|
@@ -12990,7 +13004,7 @@ class SelectMenu extends NectaryElement {
|
|
|
12990
13004
|
if (this.multiple) {
|
|
12991
13005
|
const values = unpackCsv(csv);
|
|
12992
13006
|
for (const $option of this.#getOptionElements()) {
|
|
12993
|
-
const isChecked = !getBooleanAttribute($option, "disabled") && values.includes(getAttribute($option, "value", ""));
|
|
13007
|
+
const isChecked = !getBooleanAttribute($option, "disabled") && !getBooleanAttribute($option, "action") && values.includes(getAttribute($option, "value", ""));
|
|
12994
13008
|
updateBooleanAttribute($option, "data-checked", isChecked);
|
|
12995
13009
|
}
|
|
12996
13010
|
const formData = new FormData();
|
|
@@ -13001,7 +13015,7 @@ class SelectMenu extends NectaryElement {
|
|
|
13001
13015
|
} else {
|
|
13002
13016
|
const value = getFirstCsvValue(csv);
|
|
13003
13017
|
for (const $option of this.#getOptionElements()) {
|
|
13004
|
-
const isChecked = !getBooleanAttribute($option, "disabled") && value === getAttribute($option, "value", "");
|
|
13018
|
+
const isChecked = !getBooleanAttribute($option, "disabled") && !getBooleanAttribute($option, "action") && value === getAttribute($option, "value", "");
|
|
13005
13019
|
updateBooleanAttribute($option, "data-checked", isChecked);
|
|
13006
13020
|
}
|
|
13007
13021
|
setFormValue(this.#internals, value ?? "");
|
|
@@ -13090,7 +13104,7 @@ class SelectMenu extends NectaryElement {
|
|
|
13090
13104
|
const elements = this.#getOptionElements();
|
|
13091
13105
|
const value = this.multiple ? getFirstCsvValue(this.value) : this.value;
|
|
13092
13106
|
for (const $el of elements) {
|
|
13093
|
-
if (!getBooleanAttribute($el, "disabled") && getAttribute($el, "value") === value) {
|
|
13107
|
+
if (!getBooleanAttribute($el, "disabled") && !getBooleanAttribute($el, "action") && getAttribute($el, "value") === value) {
|
|
13094
13108
|
return $el;
|
|
13095
13109
|
}
|
|
13096
13110
|
}
|
|
@@ -13108,10 +13122,17 @@ class SelectMenu extends NectaryElement {
|
|
|
13108
13122
|
) : value;
|
|
13109
13123
|
this.dispatchEvent(new CustomEvent("-change", { detail: result }));
|
|
13110
13124
|
}
|
|
13125
|
+
#dispatchActionEvent($opt) {
|
|
13126
|
+
this.dispatchEvent(new CustomEvent("-action", { detail: $opt.value }));
|
|
13127
|
+
}
|
|
13111
13128
|
#onChangeReactHandler = (e) => {
|
|
13112
13129
|
getReactEventHandler(this, "on-change")?.(e);
|
|
13113
13130
|
getReactEventHandler(this, "onChange")?.(e);
|
|
13114
13131
|
};
|
|
13132
|
+
#onActionReactHandler = (e) => {
|
|
13133
|
+
getReactEventHandler(this, "on-action")?.(e);
|
|
13134
|
+
getReactEventHandler(this, "onAction")?.(e);
|
|
13135
|
+
};
|
|
13115
13136
|
#onSearchChangeReactHandler = (e) => {
|
|
13116
13137
|
getReactEventHandler(this, "on-search-change")?.(e);
|
|
13117
13138
|
getReactEventHandler(this, "onSearchChange")?.(e);
|
package/package.json
CHANGED
package/select-menu/index.js
CHANGED
|
@@ -71,6 +71,7 @@ class SelectMenu extends NectaryElement {
|
|
|
71
71
|
options
|
|
72
72
|
);
|
|
73
73
|
this.addEventListener("-change", this.#onChangeReactHandler, options);
|
|
74
|
+
this.addEventListener("-action", this.#onActionReactHandler, options);
|
|
74
75
|
subscribeContext(
|
|
75
76
|
this,
|
|
76
77
|
"keydown",
|
|
@@ -229,7 +230,7 @@ class SelectMenu extends NectaryElement {
|
|
|
229
230
|
this.focus();
|
|
230
231
|
if (!isTargetEqual(e, this.#$listbox) && !getBooleanAttribute($elem, "disabled")) {
|
|
231
232
|
this.#selectOption($elem);
|
|
232
|
-
this.#
|
|
233
|
+
this.#handleDispatch($elem);
|
|
233
234
|
}
|
|
234
235
|
};
|
|
235
236
|
#onSearchChange = (e) => {
|
|
@@ -294,7 +295,7 @@ class SelectMenu extends NectaryElement {
|
|
|
294
295
|
const $option = this.#findSelectedOption();
|
|
295
296
|
if ($option !== null) {
|
|
296
297
|
e.preventDefault();
|
|
297
|
-
this.#
|
|
298
|
+
this.#handleDispatch($option);
|
|
298
299
|
}
|
|
299
300
|
break;
|
|
300
301
|
}
|
|
@@ -310,6 +311,13 @@ class SelectMenu extends NectaryElement {
|
|
|
310
311
|
}
|
|
311
312
|
}
|
|
312
313
|
}
|
|
314
|
+
#handleDispatch = (option) => {
|
|
315
|
+
if (getBooleanAttribute(option, "action")) {
|
|
316
|
+
this.#dispatchActionEvent(option);
|
|
317
|
+
} else {
|
|
318
|
+
this.#dispatchChangeEvent(option);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
313
321
|
#onOptionSlotChange = () => {
|
|
314
322
|
const searchable = this.searchable;
|
|
315
323
|
const options = this.#getOptionElements();
|
|
@@ -325,7 +333,7 @@ class SelectMenu extends NectaryElement {
|
|
|
325
333
|
if (this.multiple) {
|
|
326
334
|
const values = unpackCsv(csv);
|
|
327
335
|
for (const $option of this.#getOptionElements()) {
|
|
328
|
-
const isChecked = !getBooleanAttribute($option, "disabled") && values.includes(getAttribute($option, "value", ""));
|
|
336
|
+
const isChecked = !getBooleanAttribute($option, "disabled") && !getBooleanAttribute($option, "action") && values.includes(getAttribute($option, "value", ""));
|
|
329
337
|
updateBooleanAttribute($option, "data-checked", isChecked);
|
|
330
338
|
}
|
|
331
339
|
const formData = new FormData();
|
|
@@ -336,7 +344,7 @@ class SelectMenu extends NectaryElement {
|
|
|
336
344
|
} else {
|
|
337
345
|
const value = getFirstCsvValue(csv);
|
|
338
346
|
for (const $option of this.#getOptionElements()) {
|
|
339
|
-
const isChecked = !getBooleanAttribute($option, "disabled") && value === getAttribute($option, "value", "");
|
|
347
|
+
const isChecked = !getBooleanAttribute($option, "disabled") && !getBooleanAttribute($option, "action") && value === getAttribute($option, "value", "");
|
|
340
348
|
updateBooleanAttribute($option, "data-checked", isChecked);
|
|
341
349
|
}
|
|
342
350
|
setFormValue(this.#internals, value ?? "");
|
|
@@ -425,7 +433,7 @@ class SelectMenu extends NectaryElement {
|
|
|
425
433
|
const elements = this.#getOptionElements();
|
|
426
434
|
const value = this.multiple ? getFirstCsvValue(this.value) : this.value;
|
|
427
435
|
for (const $el of elements) {
|
|
428
|
-
if (!getBooleanAttribute($el, "disabled") && getAttribute($el, "value") === value) {
|
|
436
|
+
if (!getBooleanAttribute($el, "disabled") && !getBooleanAttribute($el, "action") && getAttribute($el, "value") === value) {
|
|
429
437
|
return $el;
|
|
430
438
|
}
|
|
431
439
|
}
|
|
@@ -443,10 +451,17 @@ class SelectMenu extends NectaryElement {
|
|
|
443
451
|
) : value;
|
|
444
452
|
this.dispatchEvent(new CustomEvent("-change", { detail: result }));
|
|
445
453
|
}
|
|
454
|
+
#dispatchActionEvent($opt) {
|
|
455
|
+
this.dispatchEvent(new CustomEvent("-action", { detail: $opt.value }));
|
|
456
|
+
}
|
|
446
457
|
#onChangeReactHandler = (e) => {
|
|
447
458
|
getReactEventHandler(this, "on-change")?.(e);
|
|
448
459
|
getReactEventHandler(this, "onChange")?.(e);
|
|
449
460
|
};
|
|
461
|
+
#onActionReactHandler = (e) => {
|
|
462
|
+
getReactEventHandler(this, "on-action")?.(e);
|
|
463
|
+
getReactEventHandler(this, "onAction")?.(e);
|
|
464
|
+
};
|
|
450
465
|
#onSearchChangeReactHandler = (e) => {
|
|
451
466
|
getReactEventHandler(this, "on-search-change")?.(e);
|
|
452
467
|
getReactEventHandler(this, "onSearchChange")?.(e);
|
package/select-menu/types.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export type TSinchSelectMenuEvents = {
|
|
|
24
24
|
'-search-change'?: (e: CustomEvent<string>) => void;
|
|
25
25
|
/** Change value handler */
|
|
26
26
|
'-change'?: (e: CustomEvent<string>) => void;
|
|
27
|
+
/** Action option activated handler — detail is the action option's value */
|
|
28
|
+
'-action'?: (e: CustomEvent<string>) => void;
|
|
27
29
|
};
|
|
28
30
|
export type TSinchSelectMenuStyle = {
|
|
29
31
|
'--sinch-comp-select-menu-color-default-title-initial'?: string;
|
|
@@ -14,5 +14,7 @@ export declare class SelectMenuOption extends NectaryElement {
|
|
|
14
14
|
get text(): string;
|
|
15
15
|
set disabled(isDisabled: boolean);
|
|
16
16
|
get disabled(): boolean;
|
|
17
|
+
set action(isAction: boolean);
|
|
18
|
+
get action(): boolean;
|
|
17
19
|
matchesSearch(searchValue: string): boolean;
|
|
18
20
|
}
|
|
@@ -2,7 +2,7 @@ import "../icon/index.js";
|
|
|
2
2
|
import "../text/index.js";
|
|
3
3
|
import { isAttrEqual, updateBooleanAttribute, isAttrTrue, updateExplicitBooleanAttribute, updateAttribute, getAttribute, getBooleanAttribute } from "../utils/dom.js";
|
|
4
4
|
import { defineCustomElement, NectaryElement } from "../utils/element.js";
|
|
5
|
-
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;position:relative;box-sizing:border-box;min-height:40px;padding:8px 16px;align-items:center;gap:10px;user-select:none;cursor:pointer;background-color:var(--sinch-comp-select-menu-color-default-background-initial);--sinch-global-color-text:var(--sinch-comp-select-menu-color-default-option-initial);--sinch-global-color-icon:var(--sinch-comp-select-menu-color-default-icon-initial);--sinch-global-size-icon:var(--sinch-comp-select-menu-size-icon)}#content{flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-select-menu-font-option)}#icon-check{display:none;margin-right:-6px}:host([data-checked]) #icon-check{display:block}:host([data-selected])>#wrapper{background-color:var(--sinch-comp-select-menu-color-default-background-selected)}:host(:hover)>#wrapper{background-color:var(--sinch-comp-select-menu-color-default-background-hover)}:host([disabled])>#wrapper{cursor:initial;pointer-events:none;background-color:var(--sinch-comp-select-menu-color-disabled-background-initial);--sinch-global-color-text:var(--sinch-comp-select-menu-color-disabled-option-initial);--sinch-global-color-icon:var(--sinch-comp-select-menu-color-disabled-icon-initial)}::slotted([slot=icon]){margin-left:-6px}::slotted([slot=content]){pointer-events:none;flex:1}</style><div id="wrapper"><slot name="icon"></slot><slot name="content"></slot><sinch-text id="content" type="m" ellipsis></sinch-text><sinch-icon icons-version="2" name="fa-check" id="icon-check"></sinch-icon></div>';
|
|
5
|
+
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;position:relative;box-sizing:border-box;min-height:40px;padding:8px 16px;align-items:center;gap:10px;user-select:none;cursor:pointer;background-color:var(--sinch-comp-select-menu-color-default-background-initial);--sinch-global-color-text:var(--sinch-comp-select-menu-color-default-option-initial);--sinch-global-color-icon:var(--sinch-comp-select-menu-color-default-icon-initial);--sinch-global-size-icon:var(--sinch-comp-select-menu-size-icon)}#content{flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-select-menu-font-option)}#icon-check{display:none;margin-right:-6px}:host([data-checked]:not([action])) #icon-check{display:block}:host([data-selected])>#wrapper{background-color:var(--sinch-comp-select-menu-color-default-background-selected)}:host(:hover)>#wrapper{background-color:var(--sinch-comp-select-menu-color-default-background-hover)}:host([disabled])>#wrapper{cursor:initial;pointer-events:none;background-color:var(--sinch-comp-select-menu-color-disabled-background-initial);--sinch-global-color-text:var(--sinch-comp-select-menu-color-disabled-option-initial);--sinch-global-color-icon:var(--sinch-comp-select-menu-color-disabled-icon-initial)}::slotted([slot=icon]){margin-left:-6px}::slotted([slot=content]){pointer-events:none;flex:1}</style><div id="wrapper"><slot name="icon"></slot><slot name="content"></slot><sinch-text id="content" type="m" ellipsis></sinch-text><sinch-icon icons-version="2" name="fa-check" id="icon-check"></sinch-icon></div>';
|
|
6
6
|
const template = document.createElement("template");
|
|
7
7
|
template.innerHTML = templateHTML;
|
|
8
8
|
class SelectMenuOption extends NectaryElement {
|
|
@@ -68,6 +68,12 @@ class SelectMenuOption extends NectaryElement {
|
|
|
68
68
|
get disabled() {
|
|
69
69
|
return getBooleanAttribute(this, "disabled");
|
|
70
70
|
}
|
|
71
|
+
set action(isAction) {
|
|
72
|
+
updateBooleanAttribute(this, "action", isAction);
|
|
73
|
+
}
|
|
74
|
+
get action() {
|
|
75
|
+
return getBooleanAttribute(this, "action");
|
|
76
|
+
}
|
|
71
77
|
matchesSearch(searchValue) {
|
|
72
78
|
return this.text.toLowerCase().includes(searchValue.toLowerCase());
|
|
73
79
|
}
|
|
@@ -6,6 +6,8 @@ export type TSinchSelectMenuOptionProps = {
|
|
|
6
6
|
text: string;
|
|
7
7
|
/** Disabled state */
|
|
8
8
|
disabled?: boolean;
|
|
9
|
+
/** Marks this option as an action — activating it triggers an action event instead of changing the select value */
|
|
10
|
+
action?: boolean;
|
|
9
11
|
/** Label that is used for a11y */
|
|
10
12
|
'aria-label': string;
|
|
11
13
|
};
|