@itwin/itwinui-react
Version:
A react component library for iTwinUI
102 lines (101 loc) • 2.94 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', {
value: true,
});
Object.defineProperty(exports, 'Checkbox', {
enumerable: true,
get: function () {
return Checkbox;
},
});
const _interop_require_default = require('@swc/helpers/_/_interop_require_default');
const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
const _classnames = /*#__PURE__*/ _interop_require_default._(
require('classnames'),
);
const _react = /*#__PURE__*/ _interop_require_wildcard._(require('react'));
const _ProgressRadial = require('../ProgressIndicators/ProgressRadial.js');
const _index = require('../../utils/index.js');
const Checkbox = _react.forwardRef((props, ref) => {
let {
className,
disabled = false,
indeterminate = false,
label,
status,
variant = 'default',
isLoading = false,
wrapperProps = {},
labelProps = {},
style,
...rest
} = props;
let inputElementRef = _react.useRef(null);
let refs = (0, _index.useMergedRefs)(inputElementRef, ref);
_react.useEffect(() => {
if (inputElementRef.current) {
inputElementRef.current.indeterminate = indeterminate;
inputElementRef.current.checked = indeterminate
? false
: inputElementRef.current.checked;
}
});
let checkbox = _react.createElement(
_react.Fragment,
null,
_react.createElement(_index.Box, {
as: 'input',
className: (0, _classnames.default)(
'iui-checkbox',
{
'iui-checkbox-visibility': 'eyeball' === variant,
},
className,
),
style: style,
'data-iui-loading': isLoading ? 'true' : void 0,
disabled: disabled || isLoading,
type: 'checkbox',
ref: refs,
...rest,
}),
isLoading &&
_react.createElement(_ProgressRadial.ProgressRadial, {
size: 'x-small',
indeterminate: true,
}),
);
let { className: wrapperClassName, ...restWrapperProps } = wrapperProps;
let { className: labelClassName, ...restLabelProps } = labelProps;
return label
? _react.createElement(
_index.Box,
{
as: 'label',
className: (0, _classnames.default)(
'iui-checkbox-wrapper',
wrapperClassName,
),
'data-iui-disabled': disabled ? 'true' : void 0,
'data-iui-status': status,
'data-iui-loading': isLoading ? 'true' : void 0,
...restWrapperProps,
},
checkbox,
label &&
_react.createElement(
_index.Box,
{
as: 'span',
className: (0, _classnames.default)(
'iui-checkbox-label',
labelClassName,
),
...restLabelProps,
},
label,
),
)
: checkbox;
});
if ('development' === process.env.NODE_ENV) Checkbox.displayName = 'Checkbox';