@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.
@@ -81,5 +81,6 @@ const autocomplete = (props) => {
81
81
  'default-index',
82
82
  'item-height',
83
83
  'item-limit',
84
+ 'wrap'
84
85
  ];
85
86
  export { autocomplete, Autocomplete, observedAttributes };
@@ -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
@@ -12,5 +12,6 @@ export const selection = ({ value: values, onDeselect, textual, disabled, }) =>
12
12
  className: 'badge',
13
13
  disabled: true,
14
14
  slot: 'control',
15
+ hidden: true,
15
16
  }),
16
17
  ];
@@ -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
  }
@@ -1,4 +1,6 @@
1
- export declare const useOverflow: <I>({ value, active, }: {
1
+ export declare const useOverflow: <I>({ value, active, wrap, limit, }: {
2
2
  value: I[];
3
3
  active?: boolean | undefined;
4
+ wrap?: boolean | undefined;
5
+ limit?: number | undefined;
4
6
  }) => void;
@@ -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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-autocomplete",
3
- "version": "7.0.0",
3
+ "version": "7.1.0",
4
4
  "description": "A autocomplete input web component",
5
5
  "keywords": [
6
6
  "lit-html",