UNPKG

@itwin/itwinui-react

Version:

A react component library for iTwinUI

95 lines (94 loc) 2.75 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true, }); Object.defineProperty(exports, 'ToggleSwitch', { enumerable: true, get: function () { return ToggleSwitch; }, }); const _interop_require_default = require('@swc/helpers/_/_interop_require_default'); const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard'); const _react = /*#__PURE__*/ _interop_require_wildcard._(require('react')); const _classnames = /*#__PURE__*/ _interop_require_default._( require('classnames'), ); const _index = require('../../utils/index.js'); const ToggleSwitch = _react.forwardRef((props, ref) => { let { disabled = false, labelPosition = 'right', label, className, style, size = 'default', labelProps = {}, wrapperProps, icon: iconProp, ...rest } = props; let { consistentPropsSpread } = (0, _index.useFutureFlag)('ToggleSwitch') || {}; let shouldApplyClassNameAndStyleOnInput = null != wrapperProps || consistentPropsSpread; let shouldShowIcon = void 0 === iconProp || (null !== iconProp && 'small' !== size); return _react.createElement( _index.Box, { as: label ? 'label' : 'div', style: shouldApplyClassNameAndStyleOnInput ? void 0 : style, ...wrapperProps, className: (0, _classnames.default)( 'iui-toggle-switch-wrapper', { 'iui-disabled': disabled, 'iui-label-on-right': label && 'right' === labelPosition, 'iui-label-on-left': label && 'left' === labelPosition, }, shouldApplyClassNameAndStyleOnInput ? void 0 : className, wrapperProps?.className, ), 'data-iui-size': size, }, _react.createElement(_index.Box, { as: 'input', type: 'checkbox', role: 'switch', style: shouldApplyClassNameAndStyleOnInput ? style : void 0, ...rest, className: (0, _classnames.default)( 'iui-toggle-switch', shouldApplyClassNameAndStyleOnInput ? className : void 0, ), disabled: disabled, ref: ref, }), shouldShowIcon && _react.createElement( _index.Box, { as: 'span', className: 'iui-toggle-switch-icon', 'aria-hidden': true, }, iconProp || _react.createElement(_index.SvgCheckmark, null), ), label && _react.createElement( _index.Box, { as: 'span', ...labelProps, className: (0, _classnames.default)( 'iui-toggle-switch-label', labelProps?.className, ), }, label, ), ); }); if ('development' === process.env.NODE_ENV) ToggleSwitch.displayName = 'ToggleSwitch';