@itwin/itwinui-react
Version:
A react component library for iTwinUI
67 lines (66 loc) • 1.64 kB
JavaScript
import * as React from 'react';
import cx from 'classnames';
import { Box, SvgCheckmark } from '../../utils/index.js';
export const ToggleSwitch = React.forwardRef((props, ref) => {
let {
disabled = false,
labelPosition = 'right',
label,
className,
style,
size = 'default',
labelProps = {},
icon: iconProp,
...rest
} = props;
let shouldShowIcon =
void 0 === iconProp || (null !== iconProp && 'small' !== size);
return React.createElement(
Box,
{
as: label ? 'label' : 'div',
className: cx(
'iui-toggle-switch-wrapper',
{
'iui-disabled': disabled,
'iui-label-on-right': label && 'right' === labelPosition,
'iui-label-on-left': label && 'left' === labelPosition,
},
className,
),
'data-iui-size': size,
style: style,
},
React.createElement(Box, {
as: 'input',
className: 'iui-toggle-switch',
type: 'checkbox',
role: 'switch',
disabled: disabled,
ref: ref,
...rest,
}),
shouldShowIcon &&
React.createElement(
Box,
{
as: 'span',
className: 'iui-toggle-switch-icon',
'aria-hidden': true,
},
iconProp || React.createElement(SvgCheckmark, null),
),
label &&
React.createElement(
Box,
{
as: 'span',
...labelProps,
className: cx('iui-toggle-switch-label', labelProps?.className),
},
label,
),
);
});
if ('development' === process.env.NODE_ENV)
ToggleSwitch.displayName = 'ToggleSwitch';