vantui-edit
Version:
一套适用于Taro3及React的vantui组件库
76 lines (71 loc) • 3.79 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["checked", "loading", "disabled", "activeColor", "inactiveColor", "size", "activeValue", "inactiveValue", "onChange", "style", "className"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import { useCallback } from 'react';
import { View } from '@tarojs/components';
import * as utils from '../wxs/utils';
import VanLoading from '../loading/index';
import * as computed from './wxs';
import { jsx as _jsx } from "react/jsx-runtime";
export function Switch(props) {
var _props$checked = props.checked,
checked = _props$checked === void 0 ? false : _props$checked,
_props$loading = props.loading,
loading = _props$loading === void 0 ? false : _props$loading,
_props$disabled = props.disabled,
disabled = _props$disabled === void 0 ? false : _props$disabled,
_props$activeColor = props.activeColor,
activeColor = _props$activeColor === void 0 ? '#1989fa' : _props$activeColor,
_props$inactiveColor = props.inactiveColor,
inactiveColor = _props$inactiveColor === void 0 ? '#ffffff' : _props$inactiveColor,
_props$size = props.size,
size = _props$size === void 0 ? '60' : _props$size,
_props$activeValue = props.activeValue,
activeValue = _props$activeValue === void 0 ? true : _props$activeValue,
_props$inactiveValue = props.inactiveValue,
inactiveValue = _props$inactiveValue === void 0 ? false : _props$inactiveValue,
onChange = props.onChange,
style = props.style,
className = props.className,
others = _objectWithoutProperties(props, _excluded);
var onClick = useCallback(function (event) {
if (disabled || loading) {
return;
}
var value = checked === activeValue ? inactiveValue : activeValue;
Object.defineProperty(event, 'detail', {
value: value
});
onChange === null || onChange === void 0 ? void 0 : onChange(event);
}, [activeValue, checked, disabled, inactiveValue, loading, onChange]);
return /*#__PURE__*/_jsx(View, _objectSpread(_objectSpread({
className: utils.bem('switch', {
on: checked === activeValue,
disabled: disabled
}) + " ".concat(className),
style: utils.style([computed.rootStyle({
size: size,
checked: checked,
activeColor: activeColor,
inactiveColor: inactiveColor,
activeValue: activeValue
}), style])
}, others), {}, {
onClick: onClick,
children: /*#__PURE__*/_jsx(View, {
className: "van-switch__node node-class",
children: loading && /*#__PURE__*/_jsx(VanLoading, {
color: computed.loadingColor({
checked: checked,
activeColor: activeColor,
inactiveColor: inactiveColor,
activeValue: activeValue
}),
className: "van-switch__loading"
})
})
}));
}
export default Switch;