import React from 'react'; import PropTypes from 'prop-types'; import { Divider, Heading } from '@splunk/react-ui/Menu'; import Option from './Option'; import { ComponentProps } from '../utils/types'; /** @public */ type ComboBoxChangeHandler = (event: React.ChangeEvent | React.MouseEvent | React.KeyboardEvent, data: { name?: string; value: string; }) => void; /** @public */ type ComboBoxScrollBottomHandler = (event: React.UIEvent | React.KeyboardEvent | null) => void; /** @public */ type ComboBoxBlurHandler = (event: React.FocusEvent, data: { name?: string; value: string; }) => void; /** @public */ type ComboBoxFocusHandler = (event: React.FocusEvent, data: { name?: string; value: string; }) => void; interface ComboBoxPropsBase { animateLoading?: boolean; /** Append removes rounded borders and border from the right side. */ append?: boolean; /** All children must be instances of `ComboBox.Option`. */ children?: React.ReactNode; /** If true, this component will not handle filtering. The parent must update the * Options based on the onChange value. */ controlledFilter?: boolean; /** * The default placement of the dropdown menu. It might be rendered in a different direction * depending upon the space available. */ defaultPlacement?: 'above' | 'below' | 'vertical'; /** The initial value of the input. Only applicable in uncontrolled mode. */ defaultValue?: string; /** * The id of the description. When placed in a ControlGroup, this is automatically set to the * ControlGroup's help component. */ describedBy?: string; disabled?: boolean; /** * A React ref which is set to the DOM element when the component mounts and null when it unmounts. */ elementRef?: React.Ref; /** * Highlight the field as having an error. The border and text will turn red. */ error?: boolean; /** * The footer message can show additional information, such as a truncation message. */ footerMessage?: React.ReactNode; /** Make the control an inline block with variable width. */ inline?: boolean; /** * An id for the input, which may be necessary for accessibility, such as for aria * attributes. */ inputId?: string; /** * A React ref which is set to the input element when the component mounts and null when it unmounts. */ inputRef?: React.Ref; isLoadingOptions?: boolean; /** * The id of the label. When placed in a ControlGroup, this is automatically set to the * ControlGroup's label. */ labelledBy?: string; /** * The loading message to show when isLoadingOptions. */ loadingMessage?: React.ReactNode; menuStyle?: React.CSSProperties; /** The name is returned with onChange events, which can be used to identify the * control when multiple controls share an onChange callback. */ name?: string; /** * The noOptionsMessage is shown when there are no children and it's not loading, such as when * there are no Options matching the filter. This can be customized to the type of content, * for example: "No matching dashboards". You can insert content such as an error message or * communicate a minimum number of characters to enter to see results. */ noOptionsMessage?: React.ReactNode; onBlur?: ComboBoxBlurHandler; onChange?: ComboBoxChangeHandler; onFocus?: ComboBoxFocusHandler; onKeyDown?: React.KeyboardEventHandler; onSelect?: React.ReactEventHandler; /** * A callback function invoked when the popover closes. */ onClose?: () => void; /** * A callback function invoked when the popover opens. */ onOpen?: () => void; /** * A callback function invoked when the menu is scrolled. */ onScroll?: React.UIEventHandler; /** * A callback function for loading additional list items. * Called when the list is scrolled to the bottom or all items in the list are visible. * This is called with an event argument if this is the result of a scroll. * * This should be set this to `null` when all items are loaded. */ onScrollBottom?: ComboBoxScrollBottomHandler; placeholder?: string; /** Prepend removes rounded borders from the left side. */ prepend?: boolean; /** The value of the input. Only applicable in controlled mode. */ value?: string; /** * @private Experimental. Use a virtualized `ResultsMenu` variant which will only render at most * `virtualization * 3` options in the DOM at any given time, and will have a type of infinite scroll behavior. * @throws if `virtualization` is defined but less than 2 */ virtualization?: number; } interface ComboBoxPropsBaseControlled extends ComboBoxPropsBase { defaultValue?: never; onChange: ComboBoxChangeHandler; value?: string; } interface ComboBoxPropsBaseUncontrolled extends ComboBoxPropsBase { defaultValue?: string; value?: never; } type ComboBoxProps = ComponentProps; /** * `ComboBox` allows the user to select a predefined string or enter a new value. Unlike `Select` * and `Multiselect`, `Option` value must always be a string. */ declare function ComboBox({ animateLoading, append, children, controlledFilter, defaultPlacement, defaultValue, describedBy, disabled, elementRef, error, footerMessage, inline, inputId, inputRef, isLoadingOptions, labelledBy, loadingMessage, menuStyle, name, noOptionsMessage, onBlur, onChange, onClose, onFocus, onKeyDown, onOpen, onScroll, onScrollBottom, onSelect, placeholder, prepend, value: valueProp, virtualization, ...otherProps }: ComboBoxProps): React.JSX.Element; declare namespace ComboBox { var Divider: typeof import("@splunk/react-ui/Menu").Divider; var Heading: typeof import("@splunk/react-ui/Menu").Heading; var Option: typeof import("./Option").default; var propTypes: { animateLoading: PropTypes.Requireable; append: PropTypes.Requireable; children: PropTypes.Requireable; controlledFilter: PropTypes.Requireable; defaultPlacement: PropTypes.Requireable; defaultValue: PropTypes.Requireable; describedBy: PropTypes.Requireable; disabled: PropTypes.Requireable; elementRef: PropTypes.Requireable; error: PropTypes.Requireable; footerMessage: PropTypes.Requireable; inline: PropTypes.Requireable; inputId: PropTypes.Requireable; inputRef: PropTypes.Requireable; isLoadingOptions: PropTypes.Requireable; labelledBy: PropTypes.Requireable; loadingMessage: PropTypes.Requireable; menuStyle: PropTypes.Requireable; name: PropTypes.Requireable; noOptionsMessage: PropTypes.Requireable; onBlur: PropTypes.Requireable<(...args: any[]) => any>; onChange: PropTypes.Requireable<(...args: any[]) => any>; onClose: PropTypes.Requireable<(...args: any[]) => any>; onFocus: PropTypes.Requireable<(...args: any[]) => any>; onKeyDown: PropTypes.Requireable<(...args: any[]) => any>; onOpen: PropTypes.Requireable<(...args: any[]) => any>; onScroll: PropTypes.Requireable<(...args: any[]) => any>; onScrollBottom: PropTypes.Requireable<(...args: any[]) => any>; onSelect: PropTypes.Requireable<(...args: any[]) => any>; placeholder: PropTypes.Requireable; prepend: PropTypes.Requireable; value: PropTypes.Requireable; /** @private. */ virtualization: PropTypes.Requireable; }; } export default ComboBox; export { ComboBoxBlurHandler, ComboBoxChangeHandler, ComboBoxFocusHandler, ComboBoxProps, ComboBoxScrollBottomHandler, Option, Divider, Heading, };