@szhsin/react-autocomplete
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -11,10 +11,13 @@ 'use strict'; | ||
const inputRef = react.useRef(); | ||
const [inputValue, setInputValueBase] = react.useState(''); | ||
const [isOpen, setOpenBase] = react.useState(false); | ||
const [focusIndex, setfocusIndex] = react.useState(-1); | ||
const [inputValue, setInputValue] = react.useState(''); | ||
const [isOpen, setOpen] = react.useState(false); | ||
const [focusIndex, setFocusIndex] = react.useState(-1); | ||
const [instance] = react.useState({}); | ||
const state = { | ||
inputValue: [inputValue, setInputValueBase], | ||
focusIndex: [focusIndex, setfocusIndex], | ||
isOpen: [isOpen, setOpenBase] | ||
inputValue, | ||
setInputValue, | ||
focusIndex, | ||
setFocusIndex, | ||
isOpen, | ||
setOpen | ||
}; | ||
@@ -28,7 +31,5 @@ const { | ||
} = (feature == null ? void 0 : feature({ | ||
state, | ||
props: { | ||
items, | ||
onChange | ||
} | ||
items, | ||
onChange, | ||
...state | ||
})) || {}; | ||
@@ -72,3 +73,3 @@ const getInputProps = () => ({ | ||
getProps, | ||
state | ||
...state | ||
}; | ||
@@ -78,11 +79,10 @@ }; | ||
const autocomplete = () => ({ | ||
props: { | ||
items, | ||
onChange | ||
}, | ||
state: { | ||
inputValue: [inputValue, setInputValue], | ||
focusIndex: [focusIndex, setfocusIndex], | ||
isOpen: [isOpen, setOpen] | ||
} | ||
items, | ||
onChange, | ||
inputValue, | ||
setInputValue, | ||
focusIndex, | ||
setFocusIndex, | ||
isOpen, | ||
setOpen | ||
}) => { | ||
@@ -96,3 +96,3 @@ const updateAndCloseList = value => { | ||
setOpen(false); | ||
setfocusIndex(-1); | ||
setFocusIndex(-1); | ||
} | ||
@@ -108,3 +108,3 @@ }; | ||
setInputValue(value); | ||
setfocusIndex(-1); | ||
setFocusIndex(-1); | ||
setOpen(true); | ||
@@ -119,3 +119,3 @@ onChange(value); | ||
const traverseItems = itemIndex => { | ||
setfocusIndex(itemIndex); | ||
setFocusIndex(itemIndex); | ||
setInputValue(items[itemIndex]); | ||
@@ -122,0 +122,0 @@ }; |
const autocomplete = () => ({ | ||
props: { | ||
items, | ||
onChange | ||
}, | ||
state: { | ||
inputValue: [inputValue, setInputValue], | ||
focusIndex: [focusIndex, setfocusIndex], | ||
isOpen: [isOpen, setOpen] | ||
} | ||
items, | ||
onChange, | ||
inputValue, | ||
setInputValue, | ||
focusIndex, | ||
setFocusIndex, | ||
isOpen, | ||
setOpen | ||
}) => { | ||
@@ -19,3 +18,3 @@ const updateAndCloseList = value => { | ||
setOpen(false); | ||
setfocusIndex(-1); | ||
setFocusIndex(-1); | ||
} | ||
@@ -31,3 +30,3 @@ }; | ||
setInputValue(value); | ||
setfocusIndex(-1); | ||
setFocusIndex(-1); | ||
setOpen(true); | ||
@@ -42,3 +41,3 @@ onChange(value); | ||
const traverseItems = itemIndex => { | ||
setfocusIndex(itemIndex); | ||
setFocusIndex(itemIndex); | ||
setInputValue(items[itemIndex]); | ||
@@ -45,0 +44,0 @@ }; |
@@ -9,10 +9,13 @@ import { useRef, useState } from 'react'; | ||
const inputRef = useRef(); | ||
const [inputValue, setInputValueBase] = useState(''); | ||
const [isOpen, setOpenBase] = useState(false); | ||
const [focusIndex, setfocusIndex] = useState(-1); | ||
const [inputValue, setInputValue] = useState(''); | ||
const [isOpen, setOpen] = useState(false); | ||
const [focusIndex, setFocusIndex] = useState(-1); | ||
const [instance] = useState({}); | ||
const state = { | ||
inputValue: [inputValue, setInputValueBase], | ||
focusIndex: [focusIndex, setfocusIndex], | ||
isOpen: [isOpen, setOpenBase] | ||
inputValue, | ||
setInputValue, | ||
focusIndex, | ||
setFocusIndex, | ||
isOpen, | ||
setOpen | ||
}; | ||
@@ -26,7 +29,5 @@ const { | ||
} = (feature == null ? void 0 : feature({ | ||
state, | ||
props: { | ||
items, | ||
onChange | ||
} | ||
items, | ||
onChange, | ||
...state | ||
})) || {}; | ||
@@ -70,3 +71,3 @@ const getInputProps = () => ({ | ||
getProps, | ||
state | ||
...state | ||
}; | ||
@@ -73,0 +74,0 @@ }; |
{ | ||
"name": "@szhsin/react-autocomplete", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "Zheng Song", |
@@ -1,6 +0,8 @@ | ||
/// <reference types="react" /> | ||
export interface AutocompleteState { | ||
inputValue: [string, React.Dispatch<React.SetStateAction<string>>]; | ||
focusIndex: [number, React.Dispatch<React.SetStateAction<number>>]; | ||
isOpen: [boolean, React.Dispatch<React.SetStateAction<boolean>>]; | ||
inputValue: string; | ||
setInputValue: (value: string) => void; | ||
focusIndex: number; | ||
setFocusIndex: (value: number) => void; | ||
isOpen: boolean; | ||
setOpen: (value: boolean) => void; | ||
} | ||
@@ -11,5 +13,3 @@ interface ContextualProps { | ||
} | ||
export interface Contextual { | ||
state: AutocompleteState; | ||
props: ContextualProps; | ||
export interface Contextual extends ContextualProps, AutocompleteState { | ||
} | ||
@@ -16,0 +16,0 @@ type FeatureEventHandler<E> = (event: E) => void; |
import type { InputHTMLAttributes, HTMLAttributes } from 'react'; | ||
import { AutocompleteProps, AutocompleteState } from '../common'; | ||
import type { AutocompleteProps } from '../common'; | ||
interface GetProps { | ||
@@ -10,5 +10,10 @@ input: [never, InputHTMLAttributes<HTMLInputElement>]; | ||
declare const useAutocomplete: ({ feature, items, onChange }: AutocompleteProps) => { | ||
inputValue: string; | ||
setInputValue: (value: string) => void; | ||
focusIndex: number; | ||
setFocusIndex: (value: number) => void; | ||
isOpen: boolean; | ||
setOpen: (value: boolean) => void; | ||
getProps: <T extends keyof GetProps>(elementType: T, option?: GetProps[T][0] | undefined) => GetProps[T][1]; | ||
state: AutocompleteState; | ||
}; | ||
export { useAutocomplete }; |
export { useAutocomplete } from './hooks/useAutocomplete'; | ||
export { autocomplete } from './features/autocomplete'; | ||
export type { AutocompleteProps, AutocompleteState } from './common'; | ||
export type { AutocompleteProps, AutocompleteState, Feature } from './common'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
343
11811