@box/combobox-with-api 2.2.7 → 2.2.8
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/esm/lib/components/combobox-with-api/combobox-with-api-container.js +1 -1
- package/dist/esm/lib/components/combobox-with-api/combobox-with-api.js +1 -1
- package/dist/types/lib/components/combobox-with-api/combobox-with-api-container.d.ts +6 -1
- package/dist/types/lib/components/combobox-with-api/combobox-with-api.d.ts +6 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ComboboxWithApi}from"./combobox-with-api.js";import{useCallback,useEffect,useMemo,useState}from"react";import{jsx}from"react/jsx-runtime";import _debounce from"lodash/debounce";var abortErrorName=`AbortError`,ComboboxWithApiContainer=props=>{let{debounceTime=250,defaultOptions,fetcher,includeTextInputOption=!1,onInputValueChange,...rest}=props,[isLoading,setIsLoading]=useState(!1),[isError,setIsError]=useState(!1),[isEmpty,setIsEmpty]=useState(!1),[queryValue,setQueryValue]=useState(``),[fetchedOptions,setFetchedOptions]=useState([]),debouncedSetQueryValue=useMemo(()=>_debounce(setQueryValue,debounceTime),[debounceTime]),handleOnInputValueChange=inputVal=>{debouncedSetQueryValue(inputVal),onInputValueChange?.(inputVal)},fetchOptions=useCallback(async queryVal=>{let trimmedValue=queryVal.trim();if(trimmedValue){setIsError(!1),setIsLoading(!0);try{let data=await fetcher(trimmedValue);(!(data.length>0)||typeof data[0]==`string`)&&includeTextInputOption?setFetchedOptions([trimmedValue.toLocaleLowerCase(),...data]):(setIsEmpty(data?.length===0),setFetchedOptions(data))}catch(err){err?.name!==abortErrorName&&setIsError(!0)}finally{setIsLoading(!1)}}},[fetcher,includeTextInputOption]),onTryAgain=()=>{fetchOptions(queryValue)};useEffect(()=>(queryValue.trim().length?fetchOptions(queryValue):(setFetchedOptions([]),setIsEmpty(!1)),()=>debouncedSetQueryValue.cancel()),[debouncedSetQueryValue,fetchOptions,queryValue]);let options=useMemo(()=>{let hasQuery=queryValue.trim().length>0;return defaultOptions?.length>0&&!hasQuery?defaultOptions:fetchedOptions},[queryValue,defaultOptions,fetchedOptions]);return jsx(ComboboxWithApi,{...rest,isEmpty,isError,isLoading,loading:isLoading,onInputValueChange:handleOnInputValueChange,onTryAgain,options})};export{ComboboxWithApiContainer};
|
|
1
|
+
import{ComboboxWithApi}from"./combobox-with-api.js";import{forwardRef,useCallback,useEffect,useMemo,useState}from"react";import{jsx}from"react/jsx-runtime";import _debounce from"lodash/debounce";var abortErrorName=`AbortError`,ComboboxWithApiContainer=forwardRef((props,forwardedRef)=>{let{debounceTime=250,defaultOptions,fetcher,includeTextInputOption=!1,onInputValueChange,...rest}=props,[isLoading,setIsLoading]=useState(!1),[isError,setIsError]=useState(!1),[isEmpty,setIsEmpty]=useState(!1),[queryValue,setQueryValue]=useState(``),[fetchedOptions,setFetchedOptions]=useState([]),debouncedSetQueryValue=useMemo(()=>_debounce(setQueryValue,debounceTime),[debounceTime]),handleOnInputValueChange=inputVal=>{debouncedSetQueryValue(inputVal),onInputValueChange?.(inputVal)},fetchOptions=useCallback(async queryVal=>{let trimmedValue=queryVal.trim();if(trimmedValue){setIsError(!1),setIsLoading(!0);try{let data=await fetcher(trimmedValue);(!(data.length>0)||typeof data[0]==`string`)&&includeTextInputOption?setFetchedOptions([trimmedValue.toLocaleLowerCase(),...data]):(setIsEmpty(data?.length===0),setFetchedOptions(data))}catch(err){err?.name!==abortErrorName&&setIsError(!0)}finally{setIsLoading(!1)}}},[fetcher,includeTextInputOption]),onTryAgain=()=>{fetchOptions(queryValue)};useEffect(()=>(queryValue.trim().length?fetchOptions(queryValue):(setFetchedOptions([]),setIsEmpty(!1)),()=>debouncedSetQueryValue.cancel()),[debouncedSetQueryValue,fetchOptions,queryValue]);let options=useMemo(()=>{let hasQuery=queryValue.trim().length>0;return defaultOptions?.length>0&&!hasQuery?defaultOptions:fetchedOptions},[queryValue,defaultOptions,fetchedOptions]);return jsx(ComboboxWithApi,{...rest,isEmpty,isError,isLoading,loading:isLoading,onInputValueChange:handleOnInputValueChange,onTryAgain,options,ref:forwardedRef})});export{ComboboxWithApiContainer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as ComboboxWithApiError}from"../../../../chunks/combobox-with-api-error.js";import{Combobox}from"@box/blueprint-web";import{useMemo}from"react";import{jsx}from"react/jsx-runtime";import _uniqBy from"lodash/uniqBy";var ComboboxWithApi=props=>{let{isEmpty,isError,isLoading,noResultMessage,onTryAgain,options,value,...rest}=props,combinedOptions=useMemo(()=>Array.isArray(value)?_uniqBy([...options,...value].reverse(),item=>(typeof item==`string`?item:item.value).toLocaleLowerCase().trim()).reverse():options,[options,value]),noResultMessageFromState;return noResultMessageFromState=isError&&!isLoading?jsx(ComboboxWithApiError,{onTryAgain}):isEmpty&&noResultMessage&&!isLoading?noResultMessage:void 0,jsx(Combobox,{...rest,hideSelectedOptions:!0,loading:isLoading,noResultMessage:noResultMessageFromState,options:combinedOptions,value})};export{ComboboxWithApi};
|
|
1
|
+
import{t as ComboboxWithApiError}from"../../../../chunks/combobox-with-api-error.js";import{Combobox}from"@box/blueprint-web";import{forwardRef,useMemo}from"react";import{jsx}from"react/jsx-runtime";import _uniqBy from"lodash/uniqBy";var ComboboxWithApi=forwardRef((props,forwardedRef)=>{let{isEmpty,isError,isLoading,noResultMessage,onTryAgain,options,value,...rest}=props,combinedOptions=useMemo(()=>Array.isArray(value)?_uniqBy([...options,...value].reverse(),item=>(typeof item==`string`?item:item.value).toLocaleLowerCase().trim()).reverse():options,[options,value]),noResultMessageFromState;return noResultMessageFromState=isError&&!isLoading?jsx(ComboboxWithApiError,{onTryAgain}):isEmpty&&noResultMessage&&!isLoading?noResultMessage:void 0,jsx(Combobox,{...rest,hideSelectedOptions:!0,loading:isLoading,noResultMessage:noResultMessageFromState,options:combinedOptions,value,ref:forwardedRef})});export{ComboboxWithApi};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { ForwardedRef } from 'react';
|
|
1
2
|
import { OptionValue } from '@box/blueprint-web';
|
|
2
3
|
import { ComboboxWithApiContainerProps } from './types';
|
|
3
|
-
|
|
4
|
+
declare const ComboboxWithApiContainerInner: <Multiple extends boolean, FreeInput extends boolean, T extends OptionValue>(props: ComboboxWithApiContainerProps<Multiple, FreeInput, T>, forwardedRef: ForwardedRef<HTMLInputElement>) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare const ComboboxWithApiContainer: <Multiple extends boolean, FreeInput extends boolean, T extends OptionValue>(props: ComboboxWithApiContainerProps<Multiple, FreeInput, T> & {
|
|
6
|
+
ref?: ForwardedRef<HTMLInputElement>;
|
|
7
|
+
}) => ReturnType<typeof ComboboxWithApiContainerInner>;
|
|
8
|
+
export {};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { ForwardedRef } from 'react';
|
|
1
2
|
import { OptionValue } from '@box/blueprint-web';
|
|
2
3
|
import { ComboboxWithApiProps } from './types';
|
|
3
|
-
|
|
4
|
+
declare const ComboboxWithApiInner: <Multiple extends boolean, FreeInput extends boolean, T extends OptionValue>(props: ComboboxWithApiProps<Multiple, FreeInput, T>, forwardedRef: ForwardedRef<HTMLInputElement>) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare const ComboboxWithApi: <Multiple extends boolean, FreeInput extends boolean, T extends OptionValue>(props: ComboboxWithApiProps<Multiple, FreeInput, T> & {
|
|
6
|
+
ref?: ForwardedRef<HTMLInputElement>;
|
|
7
|
+
}) => ReturnType<typeof ComboboxWithApiInner>;
|
|
8
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/combobox-with-api",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.8",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@ariakit/react": "0.4.21",
|
|
6
|
-
"@box/blueprint-web": "^16.
|
|
7
|
-
"@box/blueprint-web-assets": "^5.6.
|
|
6
|
+
"@box/blueprint-web": "^16.18.0",
|
|
7
|
+
"@box/blueprint-web-assets": "^5.6.8",
|
|
8
8
|
"lodash": "^4.17.15",
|
|
9
9
|
"react": "^17.0.0 || ^18.0.0",
|
|
10
10
|
"react-dom": "^17.0.0 || ^18.0.0",
|
|
11
11
|
"react-intl": "^6.4.2"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@box/tree": "^2.2.
|
|
14
|
+
"@box/tree": "^2.2.8",
|
|
15
15
|
"react-accessible-treeview": "2.9.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@box/blueprint-web": "^16.
|
|
19
|
-
"@box/blueprint-web-assets": "^5.6.
|
|
20
|
-
"@box/storybook-utils": "^1.2.
|
|
18
|
+
"@box/blueprint-web": "^16.18.0",
|
|
19
|
+
"@box/blueprint-web-assets": "^5.6.8",
|
|
20
|
+
"@box/storybook-utils": "^1.2.8",
|
|
21
21
|
"react": "^18.3.0",
|
|
22
22
|
"react-dom": "^18.3.0"
|
|
23
23
|
},
|