index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  2. import { use } from '../utils';
  3. import Loading from '../loading';
  4. import { switchProps } from './shared';
  5. import { emit, inherit } from '../utils/functional'; // Types
  6. var _use = use('switch'),
  7. sfc = _use[0],
  8. bem = _use[1];
  9. function Switch(h, props, slots, ctx) {
  10. var value = props.value,
  11. loading = props.loading,
  12. disabled = props.disabled,
  13. activeValue = props.activeValue,
  14. inactiveValue = props.inactiveValue;
  15. var style = {
  16. fontSize: props.size,
  17. backgroundColor: value ? props.activeColor : props.inactiveColor
  18. };
  19. var onClick = function onClick() {
  20. if (!disabled && !loading) {
  21. var newValue = value === activeValue ? inactiveValue : activeValue;
  22. emit(ctx, 'input', newValue);
  23. emit(ctx, 'change', newValue);
  24. }
  25. };
  26. return h("div", _mergeJSXProps([{
  27. "class": bem({
  28. on: value === activeValue,
  29. disabled: disabled
  30. }),
  31. "style": style,
  32. "on": {
  33. "click": onClick
  34. }
  35. }, inherit(ctx)]), [h("div", {
  36. "class": bem('node')
  37. }, [loading && h(Loading, {
  38. "class": bem('loading')
  39. })])]);
  40. }
  41. Switch.props = switchProps;
  42. export default sfc(Switch);