index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports["default"] = void 0;
  5. var _babelHelperVueJsxMergeProps = _interopRequireDefault(require("@vue/babel-helper-vue-jsx-merge-props"));
  6. var _utils = require("../utils");
  7. var _loading = _interopRequireDefault(require("../loading"));
  8. var _shared = require("./shared");
  9. var _functional = require("../utils/functional");
  10. var _use = (0, _utils.use)('switch'),
  11. sfc = _use[0],
  12. bem = _use[1];
  13. function Switch(h, props, slots, ctx) {
  14. var value = props.value,
  15. loading = props.loading,
  16. disabled = props.disabled,
  17. activeValue = props.activeValue,
  18. inactiveValue = props.inactiveValue;
  19. var style = {
  20. fontSize: props.size,
  21. backgroundColor: value ? props.activeColor : props.inactiveColor
  22. };
  23. var onClick = function onClick() {
  24. if (!disabled && !loading) {
  25. var newValue = value === activeValue ? inactiveValue : activeValue;
  26. (0, _functional.emit)(ctx, 'input', newValue);
  27. (0, _functional.emit)(ctx, 'change', newValue);
  28. }
  29. };
  30. return h("div", (0, _babelHelperVueJsxMergeProps["default"])([{
  31. "class": bem({
  32. on: value === activeValue,
  33. disabled: disabled
  34. }),
  35. "style": style,
  36. "on": {
  37. "click": onClick
  38. }
  39. }, (0, _functional.inherit)(ctx)]), [h("div", {
  40. "class": bem('node')
  41. }, [loading && h(_loading["default"], {
  42. "class": bem('loading')
  43. })])]);
  44. }
  45. Switch.props = _shared.switchProps;
  46. var _default = sfc(Switch);
  47. exports["default"] = _default;