@purpurds/autocomplete 5.34.4 → 6.0.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/LICENSE.txt +3 -3
- package/dist/autocomplete.cjs.js +12 -12
- package/dist/autocomplete.cjs.js.map +1 -1
- package/dist/autocomplete.d.ts +7 -7
- package/dist/autocomplete.d.ts.map +1 -1
- package/dist/autocomplete.es.js +180 -203
- package/dist/autocomplete.es.js.map +1 -1
- package/dist/metadata.js +1 -1
- package/dist/useAutocomplete.d.ts +3 -3
- package/dist/useAutocomplete.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/autocomplete.tsx +9 -6
- package/src/useAutocomplete.ts +4 -4
package/dist/metadata.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentPropsWithRef, ReactNode } from 'react';
|
|
2
2
|
import { ListboxItemProps, ListboxProps } from '@purpurds/listbox';
|
|
3
3
|
|
|
4
|
-
export type
|
|
4
|
+
export type AutocompleteOption = {
|
|
5
5
|
label: string;
|
|
6
6
|
id: string;
|
|
7
7
|
value?: string;
|
|
@@ -12,7 +12,7 @@ export type InputProps = Omit<ComponentPropsWithRef<"input">, "onFocus" | "onMou
|
|
|
12
12
|
onFocus: (event: React.FocusEvent<HTMLInputElement> | undefined) => void;
|
|
13
13
|
onMouseDown: (event: React.MouseEvent<HTMLInputElement> | undefined) => void;
|
|
14
14
|
};
|
|
15
|
-
export type
|
|
15
|
+
export type UseAutocompleteResult<T extends AutocompleteOption> = {
|
|
16
16
|
combobox?: boolean;
|
|
17
17
|
highlightFirstOption?: boolean;
|
|
18
18
|
defaultInputValue?: string;
|
|
@@ -33,7 +33,7 @@ export type UseAutocompleteOptions<T extends Option> = {
|
|
|
33
33
|
selectedOption?: T;
|
|
34
34
|
["data-testid"]?: string;
|
|
35
35
|
};
|
|
36
|
-
export declare const useAutocomplete: <T extends
|
|
36
|
+
export declare const useAutocomplete: <T extends AutocompleteOption>({ combobox, highlightFirstOption, defaultInputValue, inputValue, filterOption, id, listboxLabel, listboxMaxHeight, onInputBlur, onInputChange, onInputFocus, onInputKeyDown, onInputMouseDown, openOnFocus, noOptionsText, onSelect, options, selectedOption, ["data-testid"]: dataTestid, }: UseAutocompleteResult<T>) => {
|
|
37
37
|
id: string;
|
|
38
38
|
inputProps: InputProps;
|
|
39
39
|
internalRef: import('react').MutableRefObject<HTMLDivElement | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutocomplete.d.ts","sourceRoot":"","sources":["../src/useAutocomplete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIxE,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"useAutocomplete.d.ts","sourceRoot":"","sources":["../src/useAutocomplete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIxE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC,GAAG;IACzF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,GAAG,SAAS,KAAK,IAAI,CAAC;IACzE,WAAW,EAAE,CAAC,KAAK,EAAE,KA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;AAEF,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,kBAAkB,gSAoBzD,qBAAqB,CAAC,CAAC,CAAC;;;;;;;;kCAyLY,CAAC,SAAS,MAAM,KAAG,gBAAgB;;CAqDzE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purpurds/autocomplete",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "./dist/autocomplete.cjs.js",
|
|
6
6
|
"types": "./dist/autocomplete.d.ts",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"source": "src/autocomplete.tsx",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"classnames": "~2.5.0",
|
|
19
|
-
"@purpurds/
|
|
20
|
-
"@purpurds/
|
|
21
|
-
"@purpurds/
|
|
22
|
-
"@purpurds/paragraph": "
|
|
23
|
-
"@purpurds/
|
|
24
|
-
"@purpurds/
|
|
25
|
-
"@purpurds/
|
|
19
|
+
"@purpurds/heading": "6.0.0",
|
|
20
|
+
"@purpurds/listbox": "6.0.0",
|
|
21
|
+
"@purpurds/notification": "6.0.0",
|
|
22
|
+
"@purpurds/paragraph": "6.0.0",
|
|
23
|
+
"@purpurds/icon": "6.0.0",
|
|
24
|
+
"@purpurds/tokens": "6.0.0",
|
|
25
|
+
"@purpurds/text-field": "6.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@rushstack/eslint-patch": "~1.10.0",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"typescript": "^5.6.3",
|
|
49
49
|
"vite": "5.4.8",
|
|
50
50
|
"vitest": "^2.1.2",
|
|
51
|
-
"@purpurds/button": "
|
|
51
|
+
"@purpurds/button": "6.0.0",
|
|
52
|
+
"@purpurds/icon": "6.0.0",
|
|
52
53
|
"@purpurds/component-rig": "1.0.0",
|
|
53
|
-
"@purpurds/search-field": "
|
|
54
|
-
"@purpurds/icon": "5.34.4"
|
|
54
|
+
"@purpurds/search-field": "6.0.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build:dev": "vite",
|
package/src/autocomplete.tsx
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { ComponentPropsWithRef, ForwardedRef, ReactNode } from "react";
|
|
2
2
|
import React, { cloneElement, forwardRef } from "react";
|
|
3
|
-
import { IconChevronDown } from "@purpurds/icon";
|
|
3
|
+
import { IconChevronDown } from "@purpurds/icon/chevron-down";
|
|
4
4
|
import { Listbox } from "@purpurds/listbox";
|
|
5
5
|
import { isTextField } from "@purpurds/text-field";
|
|
6
6
|
import c from "classnames/bind";
|
|
7
7
|
|
|
8
8
|
import styles from "./autocomplete.module.scss";
|
|
9
|
-
import type {
|
|
9
|
+
import type { AutocompleteOption, UseAutocompleteResult } from "./useAutocomplete";
|
|
10
10
|
import { useAutocomplete } from "./useAutocomplete";
|
|
11
11
|
import type { Prettify } from "./utils";
|
|
12
12
|
|
|
13
13
|
const cx = c.bind(styles);
|
|
14
14
|
|
|
15
|
-
type AutocompleteProps<T extends
|
|
16
|
-
|
|
15
|
+
type AutocompleteProps<T extends AutocompleteOption> = Prettify<
|
|
16
|
+
UseAutocompleteResult<T> & {
|
|
17
17
|
className?: string;
|
|
18
18
|
/**
|
|
19
19
|
* Render the input. `props` are native input props
|
|
@@ -28,7 +28,7 @@ type AutocompleteProps<T extends Option> = Prettify<
|
|
|
28
28
|
|
|
29
29
|
const rootClassName = "purpur-autocomplete";
|
|
30
30
|
|
|
31
|
-
const AutocompleteComponent = <T extends
|
|
31
|
+
const AutocompleteComponent = <T extends AutocompleteOption>(
|
|
32
32
|
{ className, renderInput, renderOption, ...useAutocompleteProps }: AutocompleteProps<T>,
|
|
33
33
|
ref: ForwardedRef<HTMLDivElement>
|
|
34
34
|
) => {
|
|
@@ -116,5 +116,8 @@ const AutocompleteComponent = <T extends Option>(
|
|
|
116
116
|
export const Autocomplete = forwardRef(AutocompleteComponent);
|
|
117
117
|
Autocomplete.displayName = "Autocomplete";
|
|
118
118
|
|
|
119
|
-
export type {
|
|
119
|
+
export type {
|
|
120
|
+
AutocompleteOption,
|
|
121
|
+
UseAutocompleteResult as UseAutocompleteOptions,
|
|
122
|
+
} from "./useAutocomplete";
|
|
120
123
|
export { useAutocomplete } from "./useAutocomplete";
|
package/src/useAutocomplete.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ListboxItemProps, ListboxProps } from "@purpurds/listbox";
|
|
|
4
4
|
|
|
5
5
|
import { useMutableRefObject, useOnClickOutside } from "./utils";
|
|
6
6
|
|
|
7
|
-
export type
|
|
7
|
+
export type AutocompleteOption = {
|
|
8
8
|
label: string;
|
|
9
9
|
id: string;
|
|
10
10
|
value?: string;
|
|
@@ -17,7 +17,7 @@ export type InputProps = Omit<ComponentPropsWithRef<"input">, "onFocus" | "onMou
|
|
|
17
17
|
onMouseDown: (event: React.MouseEvent<HTMLInputElement> | undefined) => void;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export type
|
|
20
|
+
export type UseAutocompleteResult<T extends AutocompleteOption> = {
|
|
21
21
|
/*
|
|
22
22
|
* Set to get combobox features. Use in combination with `noOptionsText` and Purpur TextField.
|
|
23
23
|
*/
|
|
@@ -93,7 +93,7 @@ export type UseAutocompleteOptions<T extends Option> = {
|
|
|
93
93
|
["data-testid"]?: string;
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
export const useAutocomplete = <T extends
|
|
96
|
+
export const useAutocomplete = <T extends AutocompleteOption>({
|
|
97
97
|
combobox,
|
|
98
98
|
highlightFirstOption,
|
|
99
99
|
defaultInputValue,
|
|
@@ -113,7 +113,7 @@ export const useAutocomplete = <T extends Option>({
|
|
|
113
113
|
options,
|
|
114
114
|
selectedOption,
|
|
115
115
|
["data-testid"]: dataTestid,
|
|
116
|
-
}:
|
|
116
|
+
}: UseAutocompleteResult<T>) => {
|
|
117
117
|
const [internalInputValue, setInternalInputValue] = useState(
|
|
118
118
|
((typeof inputValue === "string" ? inputValue : defaultInputValue) || selectedOption?.label) ??
|
|
119
119
|
""
|