Skip to content

Instantly share code, notes, and snippets.

@nitin42
Created August 27, 2017 07:12
Show Gist options
  • Save nitin42/bcbd15c852912d4736a3472ccdd9cbe5 to your computer and use it in GitHub Desktop.
Save nitin42/bcbd15c852912d4736a3472ccdd9cbe5 to your computer and use it in GitHub Desktop.
Flow typed definitions for downshift
// @flow
type A11yOptionsStatusMessageOptions = {
highlightedIndex: number,
highlightedValue: any,
inputValue: string,
isOpen: boolean,
itemToString: (item: any) => string,
previousResultCount: number,
resultCount: number,
selectedItem: any,
}
type ChangeOptions = {
selectedItem: any,
previousItem: any,
}
type StateChangeOptions = {
highlightedIndex: number,
inputValue: string,
isOpen: boolean,
selectedItem: any,
}
type GetRootPropsOptions = {
refKey: string,
}
type GetItemPropsOptions = {
index: number,
item: any,
}
type ControllerStateAndHelpers = {
getRootProps: (options: GetRootPropsOptions) => any,
getButtonProps: (options: GetButtonPropsOptions) => any,
getLabelProps: (options: GetLabelPropsOptions) => any,
getInputProps: (options: GetInputPropsOptions) => any,
getItemProps: (options: GetItemPropsOptions) => any,
openMenu: () => void,
closeMenu: () => void,
toggleMenu: () => void,
selectItem: (item: any) => void,
selectItemAtIndex: (index: number) => void,
selectHighlightedItem: (index: number) => void,
setHighlightedItem: (index: number) => void,
clearSelection: () => void,
highlightedIndex: number,
inputValue: string,
isOpen: boolean,
selectedItem: any,
}
class GetInputPropsOptions extends React$Element<*> {}
class GetLabelPropsOptions extends React$Element<*> {}
class GetButtonPropsOptions extends React$Element<*> {
clearSelection: () => void
closeMenu: () => void
openMenu: () => void
selectHighlightedItem: () => void
selectItem: (item: any) => void
selectItemAtIndex: (index: number) => void
setHighlightedIndex: (index: number) => void
toggleMenu: (state: boolean) => void
highlightedIndex: number
inputValue: string
isOpen: boolean
selectedItem: any
}
type ChildrenFunction = (options: ControllerStateAndHelpers) => React$Node<*>
type downshiftProps = {
children: ChildrenFunction,
defaultHighlightedIndex?: number,
defaultSelectedItem?: any,
defaultInputValue?: string,
defaultIsOpen?: boolean,
getA11yStatusMessage?: (options: A11yOptionsStatusMessageOptions) => any,
itemToString?: (item: any) => any,
onChange?: (options: ChangeOptions) => void,
onStateChange?: (options: StateChangeOptions) => void,
onClick?: Function,
selectedItem?: any,
isOpen?: boolean,
inputValue?: string,
highlightedIndex?: number,
}
class Downshift extends React$Component {
props: downshiftProps
}
declare module 'downshift' {
declare export default Downshift
}
@nitin42
Copy link
Author

nitin42 commented Aug 28, 2017

Oh! I'll update it. Thanks 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment