import React from 'react'; import PropTypes from 'prop-types'; import { Divider as BaseDivider, Heading as BaseHeading, SelectBaseProps } from '@splunk/react-ui/SelectBase'; import Option from './Option'; import { ComponentProps } from '../utils/types'; /** @public */ type SelectChangeHandler = (event: React.MouseEvent | React.KeyboardEvent, data: { name?: string; value: string | number | boolean; }) => void; /** @public */ type SelectFilterChangeHandler = (event: React.ChangeEvent | React.MouseEvent | React.KeyboardEvent, data: { keyword: string; }) => void; /** @public */ type SelectScrollBottomHandler = (event: React.UIEvent | React.KeyboardEvent | React.KeyboardEvent | null) => void; interface SelectPropsBase { /** * Whether or not to allow entered keyboard printable characters to match options. * Keymatching is disabled when using filtering or loading. */ allowKeyMatching?: boolean; /** * Whether or not to show the wait spinner when loading. It's recommended to set this to * `true` when loading may take more than one second. */ animateLoading?: boolean; /** * Change the style of the button or link. * * @deprecatedValue 'link' * The `link` value is deprecated and will be removed in a future major version. */ appearance?: 'default' | 'link' | 'subtle'; /** * Remove rounding from the right side of the toggle. */ append?: boolean; /** * `children` should be `Select.Option`, `Select.Header`, or `Select.Divider`. */ children?: React.ReactNode; /** * The default placement of the dropdown menu. It might be rendered in a different direction * depending upon the space available. This property is effective only when filter is enabled. */ defaultPlacement?: 'above' | 'below' | 'vertical'; /** * Set this property instead of value to keep the value uncontrolled. */ defaultValue?: string | number | boolean; /** * The id of the description. When placed in a ControlGroup, this is automatically set to the * ControlGroup's help component. */ describedBy?: string; /** * Prevents user interaction and adds disabled styling. * * If set to `dimmed`, the component is able to receive focus. * If set to `disabled`, the component is unable to receive focus (as a result of setting the html `disabled` attribute). */ disabled?: boolean | 'dimmed' | 'disabled'; /** * 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 button will turn red. */ error?: boolean; /** * Determines whether to show the filter box. When true, the children are automatically * filtered based on the label. When controlled, the parent component must provide a * onFilterChange callback and update the children. This can also be used to fetch new * results. */ filter?: boolean | 'controlled'; /** * 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. This property is not used when `labelText` is provided. */ labelledBy?: string; /** * Text presented in the label for this field. * This is used to supply this text along with the current value to a screen reader. */ labelText?: 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 other content, such as an error message, or * communicate a minimum number of characters to enter to see results. */ noOptionsMessage?: React.ReactNode; /** * A callback to receive the change events. * If value is set, this callback is required. This must set the value prop to retain the * change. */ onChange?: SelectChangeHandler; /** * A callback with the change event and value of the filter box. Providing this callback and * setting controlledFilter to true enables you to filter and update the children by other * criteria. */ onFilterChange?: SelectFilterChangeHandler; /** * 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?: SelectScrollBottomHandler; /** * If 'value' is undefined or doesn't match an item, the Button will display this text. */ placeholder?: string; /** * When used outside of a control group, it can be useful to include the label on the toggle. */ prefixLabel?: string; /** * Remove rounding from the left side of the toggle. */ prepend?: boolean; /** * See `repositionMode` on `Popover` for details. */ repositionMode?: 'none' | 'flip'; /** * Places this string after the selected label. */ suffixLabel?: string; /** * Value will be matched to one of the children to deduce the label and/or icon for the * toggle. */ value?: string | number | boolean; /** @private. */ virtualization?: number; /** @private */ toggle?: SelectBaseProps['toggle']; /** * Controls whether the `children` or `label` of the selected `Option` is rendered on the toggle button. */ toggleContent?: 'optionChildren' | 'optionLabel'; } interface SelectPropsBaseControlled extends SelectPropsBase { defaultValue?: never; onChange: SelectChangeHandler; value?: string | number | boolean; } interface SelectPropsBaseUncontrolled extends SelectPropsBase { defaultValue?: string | number | boolean; value?: never; } type SelectProps = ComponentProps; declare function Select({ allowKeyMatching, appearance, defaultPlacement, defaultValue, disabled, inline, noOptionsMessage, onChange, placeholder, toggleContent, value, ...otherProps }: SelectProps): React.JSX.Element; declare namespace Select { var propTypes: { allowKeyMatching: PropTypes.Requireable; animateLoading: PropTypes.Requireable; appearance: PropTypes.Requireable; append: PropTypes.Requireable; children: PropTypes.Requireable; defaultPlacement: PropTypes.Requireable; defaultValue: PropTypes.Requireable>; describedBy: PropTypes.Requireable; disabled: PropTypes.Requireable>; elementRef: PropTypes.Requireable; error: PropTypes.Requireable; filter: PropTypes.Requireable; footerMessage: PropTypes.Requireable; inline: PropTypes.Requireable; inputId: PropTypes.Requireable; inputRef: PropTypes.Requireable; isLoadingOptions: PropTypes.Requireable; labelledBy: PropTypes.Requireable; labelText: PropTypes.Requireable; loadingMessage: PropTypes.Requireable; menuStyle: PropTypes.Requireable; name: PropTypes.Requireable; noOptionsMessage: PropTypes.Requireable; onChange: PropTypes.Requireable<(...args: any[]) => any>; onClose: PropTypes.Requireable<(...args: any[]) => any>; onFilterChange: PropTypes.Requireable<(...args: any[]) => any>; onOpen: PropTypes.Requireable<(...args: any[]) => any>; onScroll: PropTypes.Requireable<(...args: any[]) => any>; onScrollBottom: PropTypes.Requireable<(...args: any[]) => any>; placeholder: PropTypes.Requireable; prefixLabel: PropTypes.Requireable; prepend: PropTypes.Requireable; repositionMode: PropTypes.Requireable; suffixLabel: PropTypes.Requireable; toggleContent: PropTypes.Requireable; /** @private. */ toggle: PropTypes.Requireable; value: PropTypes.Requireable>; /** @private. */ virtualization: PropTypes.Requireable; }; var Option: React.MemoExoticComponent<({ children, descriptionPosition, disabled, elementRef, label, ...otherProps }: import("./Option").OptionPropsBase & Omit, HTMLButtonElement>, "ref" | "css" | keyof import("./Option").OptionPropsBase>) => React.JSX.Element>; var Heading: typeof BaseHeading; var Divider: typeof BaseDivider; } export default Select; export { BaseDivider as Divider, BaseHeading as Heading, Option, SelectChangeHandler, SelectFilterChangeHandler, }; export type { SelectProps };