@wavelengthusaf/web-components 1.0.2 → 1.1.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/README.md +5 -0
- package/dist/cjs/index.cjs +529 -5
- package/dist/cjs/index.d.cts +1163 -3
- package/dist/esm/index.d.ts +1163 -3
- package/dist/esm/index.js +527 -3
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,4 +1,62 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/mixins/StylingMixin.ts
|
|
2
|
+
function StylingMixin(Base) {
|
|
3
|
+
return class extends Base {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
// Use a specific ID for the injected style tag
|
|
7
|
+
this._mixinStyleTagId = "custom-mixin-styles";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Public setter to apply a style object to the component.
|
|
11
|
+
*/
|
|
12
|
+
set customStyles(styleObject) {
|
|
13
|
+
this.generateAndApplyStyles(styleObject);
|
|
14
|
+
}
|
|
15
|
+
toKebabCase(str) {
|
|
16
|
+
return str.replaceAll(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
createCssPropertiesString(ruleObject) {
|
|
19
|
+
return Object.entries(ruleObject).map(([prop, value]) => `${this.toKebabCase(prop)}: ${value};`).join(" ");
|
|
20
|
+
}
|
|
21
|
+
generateAndApplyStyles(styleObject) {
|
|
22
|
+
if (!this.shadowRoot) {
|
|
23
|
+
console.warn("StylingMixin: This component is missing a shadowRoot. Cannot apply nested styles.");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const baseStyles = {};
|
|
27
|
+
const nestedRules = [];
|
|
28
|
+
for (const key in styleObject) {
|
|
29
|
+
const value = styleObject[key];
|
|
30
|
+
if (typeof value === "object" && /^[&.#[\]]/.test(key)) {
|
|
31
|
+
const finalSelector = key.replace(/^&/, ":host");
|
|
32
|
+
const properties = this.createCssPropertiesString(value);
|
|
33
|
+
nestedRules.push(`${finalSelector} { ${properties} }`);
|
|
34
|
+
} else if (typeof value === "string" || typeof value === "number") {
|
|
35
|
+
baseStyles[key] = value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const prop in baseStyles) {
|
|
39
|
+
const kebabProp = this.toKebabCase(prop);
|
|
40
|
+
this.style.setProperty(kebabProp, baseStyles[prop]);
|
|
41
|
+
}
|
|
42
|
+
let cssString = "";
|
|
43
|
+
if (Object.keys(baseStyles).length > 0) {
|
|
44
|
+
cssString += `:host { ${this.createCssPropertiesString(baseStyles)} }
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
cssString += nestedRules.join("\n");
|
|
48
|
+
let styleEl = this.shadowRoot.getElementById(this._mixinStyleTagId);
|
|
49
|
+
if (!styleEl) {
|
|
50
|
+
styleEl = document.createElement("style");
|
|
51
|
+
styleEl.id = this._mixinStyleTagId;
|
|
52
|
+
this.shadowRoot.appendChild(styleEl);
|
|
53
|
+
}
|
|
54
|
+
styleEl.textContent = cssString;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/web-components/sample-component.ts
|
|
2
60
|
var template = document.createElement("template");
|
|
3
61
|
template.innerHTML = `
|
|
4
62
|
<style>
|
|
@@ -11,7 +69,7 @@ template.innerHTML = `
|
|
|
11
69
|
<slot></slot> <!-- Enables user-defined inner HTML -->
|
|
12
70
|
</div>
|
|
13
71
|
`;
|
|
14
|
-
var
|
|
72
|
+
var BaseSampleComponent = class extends HTMLElement {
|
|
15
73
|
// List of attributes to observe for changes
|
|
16
74
|
static get observedAttributes() {
|
|
17
75
|
return ["test-prop"];
|
|
@@ -36,6 +94,8 @@ var SampleComponent = class extends HTMLElement {
|
|
|
36
94
|
if (container) container.textContent = prop;
|
|
37
95
|
}
|
|
38
96
|
};
|
|
97
|
+
var SampleComponent = class extends StylingMixin(BaseSampleComponent) {
|
|
98
|
+
};
|
|
39
99
|
if (!customElements.get("sample-component")) {
|
|
40
100
|
customElements.define("sample-component", SampleComponent);
|
|
41
101
|
}
|
|
@@ -1159,7 +1219,7 @@ function getAncestor(el) {
|
|
|
1159
1219
|
const root = el.getRootNode();
|
|
1160
1220
|
return root instanceof ShadowRoot ? root.host : null;
|
|
1161
1221
|
}
|
|
1162
|
-
var
|
|
1222
|
+
var BaseWavelengthInput = class extends HTMLElement {
|
|
1163
1223
|
constructor() {
|
|
1164
1224
|
super();
|
|
1165
1225
|
this.placeholderStyleEl = document.createElement("style");
|
|
@@ -1633,7 +1693,9 @@ var WavelengthInput = class extends HTMLElement {
|
|
|
1633
1693
|
val ? this.setAttribute("clearable", "") : this.removeAttribute("clearable");
|
|
1634
1694
|
}
|
|
1635
1695
|
};
|
|
1636
|
-
|
|
1696
|
+
BaseWavelengthInput.formAssociated = true;
|
|
1697
|
+
var WavelengthInput = class extends StylingMixin(BaseWavelengthInput) {
|
|
1698
|
+
};
|
|
1637
1699
|
if (!customElements.get("wavelength-input")) {
|
|
1638
1700
|
customElements.define("wavelength-input", WavelengthInput);
|
|
1639
1701
|
}
|
|
@@ -1819,6 +1881,468 @@ if (!customElements.get("wavelength-date-picker")) {
|
|
|
1819
1881
|
customElements.define("wavelength-date-picker", WavelengthDatePicker);
|
|
1820
1882
|
}
|
|
1821
1883
|
|
|
1884
|
+
// src/web-components/wavelength-multi-select-autocomplete.ts
|
|
1885
|
+
var template4 = document.createElement("template");
|
|
1886
|
+
template4.innerHTML = `
|
|
1887
|
+
<style>
|
|
1888
|
+
.multi-select-container {
|
|
1889
|
+
background-color: white;
|
|
1890
|
+
border: 1px solid black;
|
|
1891
|
+
display: block;
|
|
1892
|
+
position: relative;
|
|
1893
|
+
width: 320px;
|
|
1894
|
+
min-height: 56px;
|
|
1895
|
+
border-radius: 8px;
|
|
1896
|
+
font-family: Inter, sans-serif;
|
|
1897
|
+
font-size: 14px;
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
.multi-select-input-wrapper {
|
|
1901
|
+
display: flex;
|
|
1902
|
+
flex-wrap: wrap;
|
|
1903
|
+
border-radius: 8px;
|
|
1904
|
+
cursor: text;
|
|
1905
|
+
min-height: 56px;
|
|
1906
|
+
height: auto;
|
|
1907
|
+
align-items: center;
|
|
1908
|
+
box-sizing: border-box;
|
|
1909
|
+
border: none;
|
|
1910
|
+
width: 100%;
|
|
1911
|
+
padding: 8px 52px 8px 15px;
|
|
1912
|
+
background-color: inherit;
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
.multi-select-input {
|
|
1916
|
+
flex: 1;
|
|
1917
|
+
border: none;
|
|
1918
|
+
min-width: 75px;
|
|
1919
|
+
outline: none;
|
|
1920
|
+
font-size: 14px;
|
|
1921
|
+
color: black;
|
|
1922
|
+
border-radius: 8px;
|
|
1923
|
+
align-self: stretch;
|
|
1924
|
+
background-color: inherit;
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
.multi-select-input::placeholder {
|
|
1928
|
+
opacity:0;
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
.multi-select-input:focus::placeholder {
|
|
1932
|
+
opacity: 50%;
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
.multi-select-label {
|
|
1936
|
+
position: absolute;
|
|
1937
|
+
font-size: 15px;
|
|
1938
|
+
cursor: text;
|
|
1939
|
+
pointer-events: none;
|
|
1940
|
+
color: #9b9b9b;
|
|
1941
|
+
font-family: montserrat, sans-serif;
|
|
1942
|
+
background-color: inherit;
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
|
|
1946
|
+
.multi-select-input:focus ~ .multi-select-label,
|
|
1947
|
+
.multi-select-label.move-to-top {
|
|
1948
|
+
position: absolute;
|
|
1949
|
+
top: -8px;
|
|
1950
|
+
left: 10px;
|
|
1951
|
+
font-size: 12px;
|
|
1952
|
+
color: black;
|
|
1953
|
+
background-color: inherit;
|
|
1954
|
+
height: 12px;
|
|
1955
|
+
padding: 0 4px;
|
|
1956
|
+
border-radius: 5px;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
.multi-select-input:focus ~ .multi-select-label {
|
|
1960
|
+
color: #009788;
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
.multi-select-chip {
|
|
1964
|
+
display: flex;
|
|
1965
|
+
align-items: center;
|
|
1966
|
+
background-color: #D0EEF0;
|
|
1967
|
+
color: black;
|
|
1968
|
+
border-radius: 8px;
|
|
1969
|
+
padding: 0 10px;
|
|
1970
|
+
margin: 2px;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
.multi-select-remove-button {
|
|
1974
|
+
display: flex;
|
|
1975
|
+
margin-left: 6px;
|
|
1976
|
+
border: none;
|
|
1977
|
+
background: transparent;
|
|
1978
|
+
cursor: pointer;
|
|
1979
|
+
font-size: 16px;
|
|
1980
|
+
border-radius: 50px;
|
|
1981
|
+
padding: 2px 0;
|
|
1982
|
+
line-height: 1;
|
|
1983
|
+
color: #26BABE;
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
.multi-select-remove-button:hover {
|
|
1987
|
+
color: #7dcdcd;
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
.multi-select-dropdown {
|
|
1991
|
+
position: absolute;
|
|
1992
|
+
top: 102%;
|
|
1993
|
+
left: 2%;
|
|
1994
|
+
right: 0;
|
|
1995
|
+
z-index: 10;
|
|
1996
|
+
border: 1px solid black;
|
|
1997
|
+
border-top: none;
|
|
1998
|
+
max-height: 150px;
|
|
1999
|
+
overflow-y: auto;
|
|
2000
|
+
list-style: none;
|
|
2001
|
+
margin: 0;
|
|
2002
|
+
padding: 10px 0;
|
|
2003
|
+
width: 96%;
|
|
2004
|
+
background-color: #EFFEFF;
|
|
2005
|
+
box-sizing: border-box;
|
|
2006
|
+
display: none;
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
|
|
2010
|
+
.multi-select-dropdown::-webkit-scrollbar {
|
|
2011
|
+
width: 8px;
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
.multi-select-dropdown::-webkit-scrollbar-track {
|
|
2015
|
+
background-color: #EFFEFF;
|
|
2016
|
+
height: 95%;
|
|
2017
|
+
border-radius: 25px;
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
.multi-select-dropdown::-webkit-scrollbar-thumb {
|
|
2021
|
+
background-color: gray;
|
|
2022
|
+
width: 6px;
|
|
2023
|
+
border-radius: 4px;
|
|
2024
|
+
height: 15px;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
|
|
2028
|
+
.multi-select-dropdown::-webkit-scrollbar-thumb:hover {
|
|
2029
|
+
background-color: darkgray;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
.multi-select-option-container {
|
|
2033
|
+
background-color: #EFFEFF;
|
|
2034
|
+
color: #26BABE;
|
|
2035
|
+
width: 100%;
|
|
2036
|
+
border: none;
|
|
2037
|
+
display: flex;
|
|
2038
|
+
align-items: center;
|
|
2039
|
+
column-gap: 15px;
|
|
2040
|
+
padding: 0 15px;
|
|
2041
|
+
cursor: pointer;
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
.multi-select-option-container:hover {
|
|
2045
|
+
background-color: #cdfdff;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
.multi-select-option {
|
|
2049
|
+
padding: 2px 8px;
|
|
2050
|
+
cursor: pointer;
|
|
2051
|
+
font-family: Inter, sans-serif;
|
|
2052
|
+
font-size: 14px;
|
|
2053
|
+
color: black;
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
.multi-select-icon-container {
|
|
2057
|
+
position: absolute;
|
|
2058
|
+
right: 10px;
|
|
2059
|
+
bottom: 0;
|
|
2060
|
+
display: flex;
|
|
2061
|
+
align-items: center;
|
|
2062
|
+
height: 100%;
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
.multi-select-clear {
|
|
2066
|
+
width: 20px;
|
|
2067
|
+
height: 20px;
|
|
2068
|
+
color: black;
|
|
2069
|
+
cursor: pointer;
|
|
2070
|
+
display: none;
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
.multi-select-clear:hover {
|
|
2074
|
+
color: #615b5b;
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
.multi-select-arrow {
|
|
2078
|
+
width: 24px;
|
|
2079
|
+
height: 24px;
|
|
2080
|
+
color: black;
|
|
2081
|
+
border-radius: 25px;
|
|
2082
|
+
cursor: pointer;
|
|
2083
|
+
display: flex;
|
|
2084
|
+
justify-content: center;
|
|
2085
|
+
align-items: center;
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
.multi-select-arrow.flipped {
|
|
2089
|
+
transform: rotate(180deg);
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
.multi-select-arrow:hover {
|
|
2093
|
+
background-color: #f3eeee;
|
|
2094
|
+
}
|
|
2095
|
+
</style>
|
|
2096
|
+
|
|
2097
|
+
<div class="multi-select-container" part="multi-select-container">
|
|
2098
|
+
<div class="multi-select-input-wrapper" part="multi-select-input-wrapper">
|
|
2099
|
+
<input type="text" class="multi-select-input" part="multi-select-input"/>
|
|
2100
|
+
<label class="multi-select-label" part="multi-select-label"></label>
|
|
2101
|
+
</div>
|
|
2102
|
+
<ul class="multi-select-dropdown" part="multi-select-dropdown"></ul>
|
|
2103
|
+
<div class="multi-select-icon-container">
|
|
2104
|
+
<span class="multi-select-clear" part="multi-select-clear">
|
|
2105
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 16 17" fill="none">
|
|
2106
|
+
<path d="M7.99967 1.8335C11.6863 1.8335 14.6663 4.8135 14.6663 8.50016C14.6663 12.1868 11.6863 15.1668 7.99967 15.1668C4.31301 15.1668 1.33301 12.1868 1.33301 8.50016C1.33301 4.8135 4.31301 1.8335 7.99967 1.8335ZM10.393 5.16683L7.99967 7.56016L5.60634 5.16683L4.66634 6.10683L7.05967 8.50016L4.66634 10.8935L5.60634 11.8335L7.99967 9.44016L10.393 11.8335L11.333 10.8935L8.93967 8.50016L11.333 6.10683L10.393 5.16683Z" fill="currentColor"/>
|
|
2107
|
+
</svg>
|
|
2108
|
+
</span>
|
|
2109
|
+
<span class="multi-select-arrow" part="multi-select-arrow">
|
|
2110
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="21" height="9.5" viewBox="0 0 14 7" fill="none">
|
|
2111
|
+
<path d="M7.00028 6.5C7.05852 6.5 13.0865 0.5 13.0003 0.5L1.00028 0.5C0.925699 0.5 6.94204 6.5 7.00028 6.5Z" fill="currentColor" stroke="black"/>
|
|
2112
|
+
</svg>
|
|
2113
|
+
</span>
|
|
2114
|
+
</div>
|
|
2115
|
+
</div>`;
|
|
2116
|
+
var BaseWavelengthMultiSelectAutocomplete = class extends HTMLElement {
|
|
2117
|
+
constructor() {
|
|
2118
|
+
super();
|
|
2119
|
+
// Public properties that will be accessed and modified
|
|
2120
|
+
this._options = [];
|
|
2121
|
+
this._selectedOptions = [];
|
|
2122
|
+
this._isOpen = false;
|
|
2123
|
+
this._inputValue = "";
|
|
2124
|
+
this._placeholder = "Select Options";
|
|
2125
|
+
this._internals = this.attachInternals();
|
|
2126
|
+
this._internals.role = "combobox";
|
|
2127
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
2128
|
+
shadow.appendChild(template4.content.cloneNode(true));
|
|
2129
|
+
this._container = this.shadowRoot.querySelector(".multi-select-container");
|
|
2130
|
+
this._inputWrapper = this.shadowRoot.querySelector(".multi-select-input-wrapper");
|
|
2131
|
+
this._input = this.shadowRoot.querySelector(".multi-select-input");
|
|
2132
|
+
this._label = this.shadowRoot.querySelector(".multi-select-label");
|
|
2133
|
+
this._dropdown = this.shadowRoot.querySelector(".multi-select-dropdown");
|
|
2134
|
+
this._clearBtn = this.shadowRoot.querySelector(".multi-select-clear");
|
|
2135
|
+
this._arrowBtn = this.shadowRoot.querySelector(".multi-select-arrow");
|
|
2136
|
+
this.addEventListeners();
|
|
2137
|
+
}
|
|
2138
|
+
// Define form-related properties
|
|
2139
|
+
get form() {
|
|
2140
|
+
return this._internals.form;
|
|
2141
|
+
}
|
|
2142
|
+
get name() {
|
|
2143
|
+
return this.getAttribute("name");
|
|
2144
|
+
}
|
|
2145
|
+
get type() {
|
|
2146
|
+
return this.localName;
|
|
2147
|
+
}
|
|
2148
|
+
get value() {
|
|
2149
|
+
return this._selectedOptions;
|
|
2150
|
+
}
|
|
2151
|
+
set value(options) {
|
|
2152
|
+
this._selectedOptions = options || [];
|
|
2153
|
+
this.dispatchEvent(new CustomEvent("change", { detail: { value: this._selectedOptions } }));
|
|
2154
|
+
this.renderChips();
|
|
2155
|
+
this.renderDropdown();
|
|
2156
|
+
this.updateLabelPosition();
|
|
2157
|
+
this.toggleClearButton();
|
|
2158
|
+
this._internals.setFormValue(JSON.stringify(this._selectedOptions));
|
|
2159
|
+
}
|
|
2160
|
+
set autocompleteOptions(options) {
|
|
2161
|
+
if (options) {
|
|
2162
|
+
this._options = options;
|
|
2163
|
+
this.render();
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
// Define which attributes to observe for changes
|
|
2167
|
+
static get observedAttributes() {
|
|
2168
|
+
return ["name", "placeholder", "label", "options"];
|
|
2169
|
+
}
|
|
2170
|
+
// React to attribute changes
|
|
2171
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
2172
|
+
if (newValue === null) return;
|
|
2173
|
+
if (name === "name") {
|
|
2174
|
+
this._input.name = newValue;
|
|
2175
|
+
this._internals.ariaLabel = newValue;
|
|
2176
|
+
} else if (name === "placeholder") {
|
|
2177
|
+
this._placeholder = newValue;
|
|
2178
|
+
this._input.placeholder = this._placeholder;
|
|
2179
|
+
} else if (name === "label") {
|
|
2180
|
+
this._placeholder = newValue;
|
|
2181
|
+
this._label.textContent = this._placeholder;
|
|
2182
|
+
} else if (name === "options") {
|
|
2183
|
+
this._options = JSON.parse(newValue);
|
|
2184
|
+
this.render();
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
// Fired when the component is added to the DOM
|
|
2188
|
+
connectedCallback() {
|
|
2189
|
+
this._placeholder = this.getAttribute("placeholder") || "Select Options";
|
|
2190
|
+
this._label.textContent = this._placeholder;
|
|
2191
|
+
this._input.placeholder = this._placeholder;
|
|
2192
|
+
this.render();
|
|
2193
|
+
}
|
|
2194
|
+
disconnectedCallback() {
|
|
2195
|
+
document.removeEventListener("mousedown", this.handleOutsideClick);
|
|
2196
|
+
}
|
|
2197
|
+
// --- Getter and Setter Methods ---
|
|
2198
|
+
get isOpen() {
|
|
2199
|
+
return this._isOpen;
|
|
2200
|
+
}
|
|
2201
|
+
set isOpen(value) {
|
|
2202
|
+
this._isOpen = value;
|
|
2203
|
+
if (value) {
|
|
2204
|
+
this._dropdown.style.display = "block";
|
|
2205
|
+
this._arrowBtn.classList.add("flipped");
|
|
2206
|
+
} else {
|
|
2207
|
+
this._dropdown.style.display = "none";
|
|
2208
|
+
this._arrowBtn.classList.remove("flipped");
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
// --- Event Handlers ---
|
|
2212
|
+
addEventListeners() {
|
|
2213
|
+
this._input.addEventListener("input", this.handleInput.bind(this));
|
|
2214
|
+
this._input.addEventListener("focus", () => {
|
|
2215
|
+
this.isOpen = true;
|
|
2216
|
+
this.updateLabelPosition();
|
|
2217
|
+
});
|
|
2218
|
+
this._arrowBtn.addEventListener("click", this.toggleDropdown.bind(this));
|
|
2219
|
+
this._clearBtn.addEventListener("click", this.clearSelection.bind(this));
|
|
2220
|
+
document.addEventListener("mousedown", this.handleOutsideClick.bind(this));
|
|
2221
|
+
this._container.addEventListener("mousedown", this.handleContainerClick.bind(this));
|
|
2222
|
+
}
|
|
2223
|
+
handleInput(e) {
|
|
2224
|
+
const target = e.target;
|
|
2225
|
+
this._inputValue = target.value;
|
|
2226
|
+
this.renderDropdown();
|
|
2227
|
+
this.updateLabelPosition();
|
|
2228
|
+
this.toggleClearButton();
|
|
2229
|
+
}
|
|
2230
|
+
toggleDropdown() {
|
|
2231
|
+
this.isOpen = !this.isOpen;
|
|
2232
|
+
if (this.isOpen) {
|
|
2233
|
+
this._input.focus();
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
handleContainerClick(e) {
|
|
2237
|
+
e.preventDefault();
|
|
2238
|
+
const target = e.target;
|
|
2239
|
+
if (this._container.contains(target) && !target.closest(".multi-select-arrow")) {
|
|
2240
|
+
this.isOpen = true;
|
|
2241
|
+
this._input.focus();
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
handleOutsideClick(e) {
|
|
2245
|
+
const path = e.composedPath();
|
|
2246
|
+
if (!path.includes(this._container)) {
|
|
2247
|
+
this.isOpen = false;
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
handleOptionClick(option) {
|
|
2251
|
+
const isSelected = this._selectedOptions.some((opt) => opt.value === option.value);
|
|
2252
|
+
if (isSelected) {
|
|
2253
|
+
this.value = this._selectedOptions.filter((opt) => opt.value !== option.value);
|
|
2254
|
+
} else {
|
|
2255
|
+
this.value = [...this._selectedOptions, option];
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
handleRemoveChip(option) {
|
|
2259
|
+
this.value = this._selectedOptions.filter((opt) => opt.value !== option.value);
|
|
2260
|
+
}
|
|
2261
|
+
toggleClearButton() {
|
|
2262
|
+
if (this._selectedOptions.length > 0 || this._inputValue.length > 0) {
|
|
2263
|
+
this._clearBtn.style.display = "block";
|
|
2264
|
+
} else {
|
|
2265
|
+
this._clearBtn.style.display = "none";
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
clearSelection() {
|
|
2269
|
+
this.value = [];
|
|
2270
|
+
this._inputValue = "";
|
|
2271
|
+
this._input.value = "";
|
|
2272
|
+
this.updateLabelPosition();
|
|
2273
|
+
this.toggleClearButton();
|
|
2274
|
+
this.renderDropdown();
|
|
2275
|
+
}
|
|
2276
|
+
updateLabelPosition() {
|
|
2277
|
+
const shouldMoveLabel = this._input === document.activeElement || this._inputValue !== "" || this._selectedOptions.length > 0;
|
|
2278
|
+
this._label.classList.toggle("move-to-top", shouldMoveLabel);
|
|
2279
|
+
}
|
|
2280
|
+
// --- Rendering Methods ---
|
|
2281
|
+
renderChips() {
|
|
2282
|
+
for (const chip of this._inputWrapper.querySelectorAll(".multi-select-chip")) {
|
|
2283
|
+
chip.remove();
|
|
2284
|
+
}
|
|
2285
|
+
for (const opt of this._selectedOptions) {
|
|
2286
|
+
const chip = document.createElement("div");
|
|
2287
|
+
chip.className = "multi-select-chip";
|
|
2288
|
+
chip.innerHTML = `
|
|
2289
|
+
${opt.label}
|
|
2290
|
+
<span class="multi-select-remove-button">
|
|
2291
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 12 13" fill="none">
|
|
2292
|
+
<path d="M6 1.5C8.765 1.5 11 3.735 11 6.5C11 9.265 8.765 11.5 6 11.5C3.235 11.5 1 9.265 1 6.5C1 3.735 3.235 1.5 6 1.5ZM7.795 4L6 5.795L4.205 4L3.5 4.705L5.295 6.5L3.5 8.295L4.205 9L6 7.205L7.795 9L8.5 8.295L6.705 6.5L8.5 4.705L7.795 4Z" fill="currentColor"/>
|
|
2293
|
+
</svg>
|
|
2294
|
+
</span>
|
|
2295
|
+
`;
|
|
2296
|
+
_optionalChain([chip, 'access', _57 => _57.querySelector, 'call', _58 => _58(".multi-select-remove-button"), 'optionalAccess', _59 => _59.addEventListener, 'call', _60 => _60("click", (e) => {
|
|
2297
|
+
e.stopPropagation();
|
|
2298
|
+
this.handleRemoveChip(opt);
|
|
2299
|
+
})]);
|
|
2300
|
+
this._inputWrapper.insertBefore(chip, this._input);
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
renderDropdown() {
|
|
2304
|
+
this._dropdown.innerHTML = "";
|
|
2305
|
+
const filteredOptions = this._options.filter((option) => option.label.toLowerCase().includes(this._inputValue.toLowerCase()));
|
|
2306
|
+
for (const option of filteredOptions) {
|
|
2307
|
+
const optionEl = document.createElement("button");
|
|
2308
|
+
optionEl.className = "multi-select-option-container";
|
|
2309
|
+
optionEl.part = optionEl.className;
|
|
2310
|
+
optionEl.type = "button";
|
|
2311
|
+
const isSelected = this._selectedOptions.some((opt) => opt.value === option.value);
|
|
2312
|
+
const checkboxSVG = `<svg
|
|
2313
|
+
width="12"
|
|
2314
|
+
height="12"
|
|
2315
|
+
viewBox="0 0 12 12"
|
|
2316
|
+
fill="none"
|
|
2317
|
+
xmlns="http://www.w3.org/2000/svg">
|
|
2318
|
+
${isSelected ? '<path d="M10 0C11.1046 1.28851e-07 12 0.895431 12 2V10C12 11.1046 11.1046 12 10 12H2C0.895431 12 3.22133e-08 11.1046 0 10V2C1.28853e-07 0.895431 0.895431 3.22128e-08 2 0H10ZM9.71484 1.90039C9.53032 1.90039 9.35197 1.96718 9.21387 2.08691L9.15723 2.1416L5.22168 6.33984C5.07629 6.4949 4.84861 6.54114 4.6543 6.45508L3.02246 5.72949C2.49487 5.49523 1.90067 5.88175 1.90039 6.45898C1.90039 6.69837 2.00809 6.92556 2.19336 7.07715L4.52148 8.98145C5.21201 9.54635 6.24003 9.38775 6.72754 8.64062L10.3535 3.08008C10.6632 2.60431 10.363 1.98415 9.8252 1.9082L9.71484 1.90039Z" fill="currentColor"/>' : '<rect x="0.5" y="0.5" width="11" height="11" rx="1.5" stroke="currentColor"/>'}
|
|
2319
|
+
</svg>`;
|
|
2320
|
+
optionEl.innerHTML = `
|
|
2321
|
+
${checkboxSVG}
|
|
2322
|
+
<span class="multi-select-option" part="multi-select-option">${option.label}</span>
|
|
2323
|
+
`;
|
|
2324
|
+
optionEl.addEventListener("click", () => this.handleOptionClick(option));
|
|
2325
|
+
this._dropdown.appendChild(optionEl);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
render() {
|
|
2329
|
+
this.renderChips();
|
|
2330
|
+
this.renderDropdown();
|
|
2331
|
+
this.updateLabelPosition();
|
|
2332
|
+
this.toggleClearButton();
|
|
2333
|
+
this._internals.setFormValue(JSON.stringify(this.value));
|
|
2334
|
+
}
|
|
2335
|
+
};
|
|
2336
|
+
// Required for form association
|
|
2337
|
+
BaseWavelengthMultiSelectAutocomplete.formAssociated = true;
|
|
2338
|
+
var WavelengthMultiSelectAutocomplete = class extends StylingMixin(BaseWavelengthMultiSelectAutocomplete) {
|
|
2339
|
+
};
|
|
2340
|
+
customElements.define("wavelength-multi-select-autocomplete", WavelengthMultiSelectAutocomplete);
|
|
2341
|
+
|
|
2342
|
+
|
|
2343
|
+
|
|
2344
|
+
|
|
2345
|
+
|
|
1822
2346
|
|
|
1823
2347
|
|
|
1824
2348
|
|
|
@@ -1827,5 +2351,5 @@ if (!customElements.get("wavelength-date-picker")) {
|
|
|
1827
2351
|
|
|
1828
2352
|
|
|
1829
2353
|
|
|
1830
|
-
exports.SampleComponent = SampleComponent; exports.WavelengthBanner = WavelengthBanner; exports.WavelengthButton = WavelengthButton; exports.WavelengthDatePicker = WavelengthDatePicker; exports.WavelengthForm = WavelengthForm; exports.WavelengthInput = WavelengthInput; exports.WavelengthProgressBar = WavelengthProgressBar; exports.WavelengthTitleBar = WavelengthTitleBar;
|
|
2354
|
+
exports.BaseSampleComponent = BaseSampleComponent; exports.BaseWavelengthInput = BaseWavelengthInput; exports.BaseWavelengthMultiSelectAutocomplete = BaseWavelengthMultiSelectAutocomplete; exports.SampleComponent = SampleComponent; exports.WavelengthBanner = WavelengthBanner; exports.WavelengthButton = WavelengthButton; exports.WavelengthDatePicker = WavelengthDatePicker; exports.WavelengthForm = WavelengthForm; exports.WavelengthInput = WavelengthInput; exports.WavelengthMultiSelectAutocomplete = WavelengthMultiSelectAutocomplete; exports.WavelengthProgressBar = WavelengthProgressBar; exports.WavelengthTitleBar = WavelengthTitleBar;
|
|
1831
2355
|
//# sourceMappingURL=index.cjs.map
|