@bigbinary/neetoui
Version:
neetoUI drives the experience at all neeto products
102 lines (99 loc) • 3.89 kB
JavaScript
import _extends from '@babel/runtime/helpers/extends';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default, { forwardRef } from 'react';
import classnames from 'classnames';
import { Check, Close } from '@bigbinary/neeto-icons';
import { u as useId } from './useId-Jj9hXm-g.js';
import '@babel/runtime/helpers/slicedToArray';
import 'react-router-dom';
import '@bigbinary/neeto-hotkeys';
import './overlayManager.js';
import { h as hyphenize, n as noop } from './index-Dxaw6gl9.js';
import '@babel/runtime/helpers/defineProperty';
import 'qs';
import Label from './Label.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '@bigbinary/neeto-cist';
import 'ramda';
import './en-CIkXIYyl.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'dayjs';
import 'dayjs/plugin/localeData';
import 'dayjs/plugin/utc';
import 'dayjs/plugin/weekday';
import 'dayjs/plugin/weekOfYear';
import './Button.js';
import './Spinner.js';
import './Tooltip.js';
import '@tippyjs/react';
import 'tippy.js';
import './Popover.js';
import './Typography.js';
var _excluded = ["label", "required", "className", "error", "onChange", "labelProps", "children"];
var Switch = /*#__PURE__*/forwardRef(function (_ref, ref) {
var _ref$label = _ref.label,
label = _ref$label === void 0 ? "" : _ref$label,
_ref$required = _ref.required,
required = _ref$required === void 0 ? false : _ref$required,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
_ref$error = _ref.error,
error = _ref$error === void 0 ? "" : _ref$error,
_ref$onChange = _ref.onChange,
onChange = _ref$onChange === void 0 ? noop : _ref$onChange,
labelProps = _ref.labelProps,
children = _ref.children,
otherProps = _objectWithoutProperties(_ref, _excluded);
var id = useId(otherProps.id);
var errorId = "error_".concat(id);
var checked = otherProps.checked,
disabled = otherProps.disabled;
var renderLabel = label || children;
return /*#__PURE__*/React__default.createElement("div", {
ref: ref,
className: classnames(["neeto-ui-switch__wrapper", className]),
"data-cy": "nui-switch-wrapper"
}, /*#__PURE__*/React__default.createElement("div", {
className: "neeto-ui-switch__container"
}, /*#__PURE__*/React__default.createElement("label", {
"data-cy": "nui-switch-item",
tabIndex: 0,
className: classnames("neeto-ui-switch__item", {
"neeto-ui-switch__item--checked": !!checked,
"neeto-ui-switch__item--disabled": disabled
})
}, /*#__PURE__*/React__default.createElement("input", _extends({
id: id,
onChange: onChange,
type: "checkbox"
}, otherProps)), /*#__PURE__*/React__default.createElement("span", {
"aria-hidden": "true",
"data-cy": "".concat(hyphenize(renderLabel), "-switch"),
className: classnames("neeto-ui-switch", {
"neeto-ui-switch--checked": !!checked
})
}, checked ? /*#__PURE__*/React__default.createElement(Check, {
"data-cy": "check-icon",
"data-testid": "check-icon",
size: "12",
strokeWidth: 4
}) : /*#__PURE__*/React__default.createElement(Close, {
"data-cy": "close-icon",
"data-testid": "close-icon",
size: "12",
strokeWidth: 3
}))), renderLabel && /*#__PURE__*/React__default.createElement(Label, _extends({
required: required,
htmlFor: id
}, labelProps, {
"data-cy": "".concat(hyphenize(renderLabel).replace(/[^a-z0-9-]/gi, ""), "-switch-label")
}), renderLabel)), !!error && /*#__PURE__*/React__default.createElement("p", {
className: "neeto-ui-input__error",
"data-cy": "".concat(hyphenize(renderLabel), "-switch-error"),
id: errorId
}, error));
});
Switch.displayName = "Switch";
export { Switch as default };
//# sourceMappingURL=Switch.js.map