@neovici/cosmoz-autocomplete 3.1.1 → 3.2.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/lib/autocomplete.css.js +18 -3
- package/lib/autocomplete.js +123 -56
- package/package.json +1 -1
package/lib/autocomplete.css.js
CHANGED
|
@@ -40,7 +40,7 @@ export default css`
|
|
|
40
40
|
}
|
|
41
41
|
.chip-clear {
|
|
42
42
|
margin: 2px 4px 2px -6px;
|
|
43
|
-
background-color: var(--cosmoz-autocomplete-chip-clear-bg-color, #
|
|
43
|
+
background-color: var(--cosmoz-autocomplete-chip-clear-bg-color, #81899b);
|
|
44
44
|
border-radius: 500px;
|
|
45
45
|
cursor: pointer;
|
|
46
46
|
width: 16px;
|
|
@@ -48,7 +48,9 @@ export default css`
|
|
|
48
48
|
stroke: var(--cosmoz-autocomplete-chip-bg-color, #cbcfdb);
|
|
49
49
|
display: block;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
|
|
52
|
+
.chip-clear svg,
|
|
53
|
+
.badge-clear svg {
|
|
52
54
|
display: block;
|
|
53
55
|
transform: translate(3.5px, 3.5px);
|
|
54
56
|
}
|
|
@@ -59,12 +61,25 @@ export default css`
|
|
|
59
61
|
font-weight: 500;
|
|
60
62
|
font-size: 12px;
|
|
61
63
|
line-height: 22px;
|
|
62
|
-
padding: 0
|
|
64
|
+
padding: 0 4px 0 6px;
|
|
65
|
+
gap: 4px;
|
|
63
66
|
border-radius: 90px;
|
|
64
67
|
text-align: center;
|
|
65
68
|
box-sizing: border-box;
|
|
69
|
+
/* fallback for unsupported min-content FF, Safari */
|
|
66
70
|
flex: 0.01 2 30px;
|
|
71
|
+
flex: 0 2 min-content;
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
}
|
|
75
|
+
.badge-clear {
|
|
76
|
+
background-color: var(--cosmoz-autocomplete-chip-clear-bg-color, #81899b);
|
|
77
|
+
border-radius: 500px;
|
|
67
78
|
cursor: pointer;
|
|
79
|
+
width: 16px;
|
|
80
|
+
height: 16px;
|
|
81
|
+
stroke: var(--cosmoz-autocomplete-chip-bg-color, #cbcfdb);
|
|
82
|
+
display: block;
|
|
68
83
|
}
|
|
69
84
|
|
|
70
85
|
slot {
|
package/lib/autocomplete.js
CHANGED
|
@@ -9,33 +9,75 @@ import { useAutocomplete } from './use-autocomplete';
|
|
|
9
9
|
import { listbox } from '../cosmoz-listbox';
|
|
10
10
|
import style from './autocomplete.css';
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const blank = () => nothing,
|
|
13
|
+
clear = html`
|
|
14
|
+
<svg
|
|
15
|
+
width="9"
|
|
16
|
+
height="8"
|
|
17
|
+
viewBox="0 0 9 8"
|
|
18
|
+
fill="none"
|
|
19
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
20
|
+
>
|
|
21
|
+
<line
|
|
22
|
+
x1="7.53033"
|
|
23
|
+
y1="0.994808"
|
|
24
|
+
x2="1.16637"
|
|
25
|
+
y2="7.35877"
|
|
26
|
+
stroke-width="1.5"
|
|
27
|
+
/>
|
|
28
|
+
<line
|
|
29
|
+
x1="7.46967"
|
|
30
|
+
y1="7.35882"
|
|
31
|
+
x2="1.10571"
|
|
32
|
+
y2="0.99486"
|
|
33
|
+
stroke-width="1.5"
|
|
34
|
+
/>
|
|
35
|
+
</svg>
|
|
36
|
+
`,
|
|
14
37
|
renderChip = (text, onClear, disabled, isOne) => html`
|
|
15
|
-
<div
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
<div
|
|
39
|
+
class="chip"
|
|
40
|
+
part="chip"
|
|
41
|
+
slot="suffix"
|
|
42
|
+
title=${text}
|
|
43
|
+
?data-one=${isOne}
|
|
44
|
+
>
|
|
45
|
+
<span class="chip-text" part="chip-text">${text}</span>
|
|
46
|
+
${(!disabled &&
|
|
47
|
+
html` <span class="chip-clear" part="chip-clear" @click=${onClear}>
|
|
48
|
+
${clear}
|
|
49
|
+
</span>`) ||
|
|
50
|
+
nothing}
|
|
24
51
|
</div>
|
|
25
52
|
`,
|
|
26
|
-
renderBadge =
|
|
53
|
+
renderBadge = ({ value, onDeselect }) => {
|
|
54
|
+
const len = value?.length;
|
|
55
|
+
return len > 0
|
|
56
|
+
? html`<div class="badge" slot="suffix" part="badge">
|
|
57
|
+
${len}
|
|
58
|
+
<span
|
|
59
|
+
class="badge-clear"
|
|
60
|
+
part="chip-clear"
|
|
61
|
+
@click=${() => onDeselect(value)}
|
|
62
|
+
>${clear}</span
|
|
63
|
+
>
|
|
64
|
+
</div>`
|
|
65
|
+
: nothing;
|
|
66
|
+
},
|
|
27
67
|
renderSelection = (value, isOne, onDeselect, textual, disabled) => {
|
|
28
68
|
if (isOne || value.length === 1) {
|
|
29
69
|
const val = value[0];
|
|
30
|
-
return val
|
|
70
|
+
return val
|
|
71
|
+
? renderChip(textual(val), () => onDeselect(val), disabled, isOne)
|
|
72
|
+
: nothing;
|
|
31
73
|
}
|
|
32
|
-
return renderBadge(value
|
|
74
|
+
return renderBadge({ value, onDeselect });
|
|
33
75
|
},
|
|
34
|
-
inputParts = ['input', 'label', 'line', 'error']
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
76
|
+
inputParts = ['input', 'label', 'line', 'error']
|
|
77
|
+
.map((part) => `${part}: input-${part}`)
|
|
78
|
+
.join(),
|
|
79
|
+
autocomplete = (props) => {
|
|
80
|
+
const {
|
|
39
81
|
invalid,
|
|
40
82
|
errorMessage,
|
|
41
83
|
label,
|
|
@@ -56,48 +98,77 @@ const
|
|
|
56
98
|
values$,
|
|
57
99
|
} = props,
|
|
58
100
|
host = useHost(),
|
|
59
|
-
|
|
60
101
|
isOne = limit == 1, // eslint-disable-line eqeqeq
|
|
61
102
|
isSingle = isOne && array(value)?.[0] != null,
|
|
62
|
-
anchor = useCallback(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
103
|
+
anchor = useCallback(
|
|
104
|
+
() => host.shadowRoot.querySelector('#input'),
|
|
105
|
+
[host, value]
|
|
106
|
+
),
|
|
107
|
+
suggestions = until(
|
|
108
|
+
items$.then(
|
|
109
|
+
(items) =>
|
|
110
|
+
((!isSingle || showSingle) &&
|
|
111
|
+
items.length &&
|
|
112
|
+
listbox({
|
|
113
|
+
...props,
|
|
114
|
+
anchor,
|
|
115
|
+
items,
|
|
116
|
+
multi: !isOne,
|
|
117
|
+
})) ||
|
|
118
|
+
nothing
|
|
119
|
+
)
|
|
120
|
+
);
|
|
69
121
|
|
|
70
|
-
return html`
|
|
71
|
-
|
|
122
|
+
return html` <style>
|
|
123
|
+
${style}
|
|
124
|
+
</style>
|
|
72
125
|
<cosmoz-input
|
|
73
|
-
id="input"
|
|
74
|
-
|
|
75
|
-
.
|
|
76
|
-
|
|
77
|
-
?
|
|
78
|
-
?
|
|
79
|
-
?
|
|
80
|
-
?
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
126
|
+
id="input"
|
|
127
|
+
part="input"
|
|
128
|
+
.label=${label}
|
|
129
|
+
.placeholder=${placeholder}
|
|
130
|
+
?no-label-float=${noLabelFloat}
|
|
131
|
+
?always-float-label=${isSingle || alwaysFloatLabel}
|
|
132
|
+
?readonly=${isSingle}
|
|
133
|
+
?disabled=${disabled}
|
|
134
|
+
?invalid=${until(
|
|
135
|
+
values$.then(
|
|
136
|
+
() => invalid,
|
|
137
|
+
() => true
|
|
138
|
+
),
|
|
139
|
+
invalid
|
|
140
|
+
)}
|
|
141
|
+
.errorMessage=${until(
|
|
142
|
+
values$.then(
|
|
143
|
+
() => errorMessage,
|
|
144
|
+
(e) => e.message
|
|
145
|
+
),
|
|
146
|
+
errorMessage
|
|
147
|
+
)}
|
|
148
|
+
.value=${live(text)}
|
|
149
|
+
@value-changed=${onText}
|
|
150
|
+
@focusin=${onFocus}
|
|
151
|
+
@focusout=${onFocus}
|
|
152
|
+
@click=${onClick}
|
|
86
153
|
autocomplete="off"
|
|
87
|
-
exportparts=${
|
|
154
|
+
exportparts=${inputParts}
|
|
88
155
|
>
|
|
89
156
|
<slot name="prefix" slot="prefix"></slot>
|
|
90
157
|
<slot name="suffix" slot="suffix"></slot>
|
|
91
|
-
${
|
|
92
|
-
${
|
|
158
|
+
${renderSelection(array(value), isOne, onDeselect, textual, disabled)}
|
|
159
|
+
${until(
|
|
160
|
+
values$.then(blank, blank),
|
|
161
|
+
html`<div slot="suffix" class="spinner"></div>`
|
|
162
|
+
)}
|
|
93
163
|
</cosmoz-input>
|
|
94
164
|
|
|
95
|
-
${
|
|
165
|
+
${suggestions}`;
|
|
96
166
|
},
|
|
97
|
-
Autocomplete = props =>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
167
|
+
Autocomplete = (props) =>
|
|
168
|
+
autocomplete({
|
|
169
|
+
...props,
|
|
170
|
+
...useAutocomplete(props),
|
|
171
|
+
}),
|
|
101
172
|
observedAttributes = [
|
|
102
173
|
'disabled',
|
|
103
174
|
'invalid',
|
|
@@ -111,11 +182,7 @@ const
|
|
|
111
182
|
'hide-empty',
|
|
112
183
|
'default-index',
|
|
113
184
|
'item-height',
|
|
114
|
-
'item-limit'
|
|
185
|
+
'item-limit',
|
|
115
186
|
];
|
|
116
187
|
|
|
117
|
-
export {
|
|
118
|
-
autocomplete,
|
|
119
|
-
Autocomplete,
|
|
120
|
-
observedAttributes
|
|
121
|
-
};
|
|
188
|
+
export { autocomplete, Autocomplete, observedAttributes };
|