@neovici/cosmoz-autocomplete 7.0.0 → 7.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/dist/autocomplete/autocomplete.js +1 -0
- package/dist/autocomplete/chip.d.ts +2 -1
- package/dist/autocomplete/chip.js +2 -1
- package/dist/autocomplete/selection.js +1 -0
- package/dist/autocomplete/styles.css.js +8 -0
- package/dist/autocomplete/use-overflow.d.ts +3 -1
- package/dist/autocomplete/use-overflow.js +7 -5
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ interface ChipProps extends Props {
|
|
|
7
7
|
slot?: string;
|
|
8
8
|
className?: string;
|
|
9
9
|
content: unknown;
|
|
10
|
+
hidden?: boolean;
|
|
10
11
|
}
|
|
11
|
-
export declare const chip: ({ content, onClear, disabled, className, slot, }: ChipProps) => import("lit-html").TemplateResult<1>;
|
|
12
|
+
export declare const chip: ({ content, onClear, disabled, hidden, className, slot, }: ChipProps) => import("lit-html").TemplateResult<1>;
|
|
12
13
|
export {};
|
|
@@ -36,12 +36,13 @@ export const Chip = ({ onClear, disabled }) => html `
|
|
|
36
36
|
</span>`)}
|
|
37
37
|
`;
|
|
38
38
|
customElements.define('cosmoz-autocomplete-chip', component(Chip, { observedAttributes: ['disabled'] }));
|
|
39
|
-
export const chip = ({ content, onClear, disabled, className = 'chip', slot, }) => html `<cosmoz-autocomplete-chip
|
|
39
|
+
export const chip = ({ content, onClear, disabled, hidden, className = 'chip', slot, }) => html `<cosmoz-autocomplete-chip
|
|
40
40
|
class=${ifDefined(className)}
|
|
41
41
|
slot=${ifDefined(slot)}
|
|
42
42
|
part="chip"
|
|
43
43
|
exportparts="chip-text, chip-clear"
|
|
44
44
|
?disabled=${disabled}
|
|
45
|
+
?hidden=${hidden}
|
|
45
46
|
.onClear=${onClear}
|
|
46
47
|
title=${ifDefined(typeof content === 'string' ? content : undefined)}
|
|
47
48
|
>${content}</cosmoz-autocomplete-chip
|
|
@@ -3,6 +3,7 @@ export default css `
|
|
|
3
3
|
:host {
|
|
4
4
|
display: block;
|
|
5
5
|
position: relative;
|
|
6
|
+
min-width: 35px;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
cosmoz-input::part(control) {
|
|
@@ -41,6 +42,13 @@ export default css `
|
|
|
41
42
|
display: none;
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
:host([wrap]) cosmoz-input::part(control) {
|
|
46
|
+
flex-wrap: wrap;
|
|
47
|
+
}
|
|
48
|
+
:host([wrap]) .chip {
|
|
49
|
+
max-width: 100%;
|
|
50
|
+
}
|
|
51
|
+
|
|
44
52
|
slot {
|
|
45
53
|
display: contents !important;
|
|
46
54
|
}
|
|
@@ -9,8 +9,6 @@ const overflow = (host) => {
|
|
|
9
9
|
chip.hidden = false;
|
|
10
10
|
}
|
|
11
11
|
const input = host.shadowRoot.querySelector('cosmoz-input');
|
|
12
|
-
if (input.matches('[data-one]'))
|
|
13
|
-
return;
|
|
14
12
|
const limit = input.shadowRoot
|
|
15
13
|
?.querySelector('.control')
|
|
16
14
|
?.getBoundingClientRect();
|
|
@@ -30,17 +28,21 @@ const overflow = (host) => {
|
|
|
30
28
|
chips[i].hidden = true;
|
|
31
29
|
}
|
|
32
30
|
};
|
|
33
|
-
export const useOverflow = ({ value, active, }) => {
|
|
31
|
+
export const useOverflow = ({ value, active, wrap, limit, }) => {
|
|
34
32
|
const host = useHost();
|
|
33
|
+
// eslint-disable-next-line eqeqeq
|
|
34
|
+
const enabled = !(wrap || limit == 1);
|
|
35
35
|
const doRaf = useMemo(() => raf(() => overflow(host)), []);
|
|
36
36
|
const [width, setWidth] = useState(0);
|
|
37
37
|
useLayoutEffect(() => {
|
|
38
|
+
if (!enabled)
|
|
39
|
+
return;
|
|
38
40
|
const input = host.shadowRoot.querySelector('cosmoz-input');
|
|
39
41
|
const observer = new ResizeObserver((e) => {
|
|
40
42
|
setWidth(e[0].contentRect.width);
|
|
41
43
|
});
|
|
42
44
|
observer.observe(input);
|
|
43
45
|
return () => observer.disconnect();
|
|
44
|
-
}, []);
|
|
45
|
-
useLayoutEffect(() => doRaf(), [width, active, value]);
|
|
46
|
+
}, [enabled]);
|
|
47
|
+
useLayoutEffect(() => (enabled ? doRaf() : undefined), [enabled, width, active, value]);
|
|
46
48
|
};
|