import React from 'react'; import PropTypes from 'prop-types'; import { ComponentProps } from '../utils/types'; /** @public */ type SwitchClickHandler = (event: React.MouseEvent, data: { selected: boolean; value?: any; }) => void; /** @public */ type SwitchCheckboxWithSomeClickHandler = (event: React.MouseEvent, data: { selected: boolean | 'some'; value?: any; }) => void; interface SwitchPropsBase { /** * Determines if the component renders as a checkbox or toggle. * * @deprecatedValue 'checkbox'. Consider using the `Checkbox` component instead. * The 'checkbox' value is deprecated and will be removed in a future major version. */ appearance?: 'checkbox' | 'toggle'; children?: React.ReactNode; /** * 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 only when appearance is 'checkbox'. */ error?: boolean; /** * If `Switch` is not provided children as the label, an id can be provided for the control. * Set a label's for attribute to this id to link the two elements. */ id?: string; /** * Make the control an inline block with variable width. */ inline?: boolean; /** * If `Switch` is not provided children as the label, an id can be provided to * another element. */ labelledBy?: string; onClick?: SwitchClickHandler | SwitchCheckboxWithSomeClickHandler; /** @private. */ required?: boolean; /** * 'some' is only valid when appearance is 'checkbox'. The current value of `selected` is * passed to the onClick handler. */ selected?: boolean | 'some'; /** * @deprecated This prop is deprecated and will be removed in the next major version. * The customized content presented to screen readers when selected. */ selectedLabel?: string; /** * @deprecated This prop is deprecated and will be removed in the next major version. * The customized content presented to screen readers when selected="some". */ someSelectedLabel?: string; /** * A React ref which is set to the toggle when the component mounts and null when it unmounts. */ toggleRef?: React.Ref; /** * @deprecated This prop is deprecated and will be removed in the next major version. * The customized content presented to screen readers when unselected. */ unselectedLabel?: string; /** * The `value` is used as an identifier and is passed to the `onClick` handler. This is * useful when managing a group of switches with a single `onClick` handler. */ value?: any; } interface SwitchCheckboxWithSomePropsBase extends SwitchPropsBase { appearance?: 'checkbox'; onClick?: SwitchCheckboxWithSomeClickHandler; selected?: boolean | 'some'; error?: boolean; } interface SwitchNoSomePropsBase extends SwitchPropsBase { onClick?: SwitchClickHandler; selected?: boolean; error?: never; } type SwitchProps = ComponentProps; /** * `Switch` is a basic form control with an on/off state. */ declare function Switch({ appearance, children, describedBy, disabled, elementRef, error, id, inline, labelledBy, onClick, required, selected, selectedLabel, someSelectedLabel, role, tabIndex, toggleRef, unselectedLabel, value, ...otherProps }: SwitchProps): React.JSX.Element; declare namespace Switch { var propTypes: { appearance: PropTypes.Requireable; children: PropTypes.Requireable; describedBy: PropTypes.Requireable; disabled: PropTypes.Requireable; elementRef: PropTypes.Requireable; error: PropTypes.Requireable; id: PropTypes.Requireable; inline: PropTypes.Requireable; labelledBy: PropTypes.Requireable; onClick: PropTypes.Requireable<(...args: any[]) => any>; /** @private. */ required: PropTypes.Requireable; selected: PropTypes.Requireable; selectedLabel: PropTypes.Requireable; toggleRef: PropTypes.Requireable; someSelectedLabel: PropTypes.Requireable; unselectedLabel: PropTypes.Requireable; value: PropTypes.Requireable; }; } export default Switch; export { SwitchClickHandler, SwitchCheckboxWithSomeClickHandler };