// @flow import * as React from 'react'; import classNames from 'classnames'; import './Toggle.scss'; type Props = { className?: string, /** Description of the input */ description?: React.Node, inputProps?: Object, // @TODO: eventually get rid of this isDisabled?: boolean, // @TODO: eventually call this `disabled` /** Toggle state */ isOn?: boolean, // @TODO: eventually call this `checked` /** If set to true, the toggle will be aligned to the right */ isToggleRightAligned?: boolean, /** Label displayed for the input */ label: React.Node, /** Name of the input */ name?: string, /** blur callback function called with event as the argument */ onBlur?: (e: SyntheticInputEvent) => any, /** change callback function called with event as the argument */ onChange?: (e: SyntheticInputEvent) => any, /** optional value for the toggles checkbox */ value?: any, }; const Toggle = ({ className = '', description, inputProps = {}, isDisabled, isOn, isToggleRightAligned = false, label, name, onBlur, onChange, }: Props) => { const classes = classNames('toggle-container', className, { 'is-toggle-right-aligned': isToggleRightAligned, }); let toggleElements = [
,
{label}
, ]; if (isToggleRightAligned) { toggleElements = toggleElements.reverse(); } return (
{/* eslint-disable-next-line jsx-a11y/label-has-for */} {description ?
{description}
: null}
); }; export type ToggleProps = Props; export default Toggle;