index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  3. import { use } from '../utils';
  4. import { emit, inherit } from '../utils/functional';
  5. import { routeProps, functionalRoute } from '../utils/router';
  6. import Loading from '../loading'; // Types
  7. var _use = use('button'),
  8. sfc = _use[0],
  9. bem = _use[1];
  10. function Button(h, props, slots, ctx) {
  11. var tag = props.tag,
  12. type = props.type,
  13. disabled = props.disabled,
  14. loading = props.loading,
  15. hairline = props.hairline,
  16. loadingText = props.loadingText;
  17. var onClick = function onClick(event) {
  18. if (!loading && !disabled) {
  19. emit(ctx, 'click', event);
  20. functionalRoute(ctx);
  21. }
  22. };
  23. var onTouchstart = function onTouchstart(event) {
  24. emit(ctx, 'touchstart', event);
  25. };
  26. var classes = [bem([type, props.size, {
  27. loading: loading,
  28. disabled: disabled,
  29. hairline: hairline,
  30. block: props.block,
  31. plain: props.plain,
  32. round: props.round,
  33. square: props.square,
  34. 'bottom-action': props.bottomAction
  35. }]), {
  36. 'van-hairline--surround': hairline
  37. }];
  38. return h(tag, _mergeJSXProps([{
  39. "class": classes,
  40. "attrs": {
  41. "type": props.nativeType,
  42. "disabled": disabled
  43. },
  44. "on": {
  45. "click": onClick,
  46. "touchstart": onTouchstart
  47. }
  48. }, inherit(ctx)]), [loading ? [h(Loading, {
  49. "attrs": {
  50. "size": props.loadingSize,
  51. "color": type === 'default' ? undefined : ''
  52. }
  53. }), loadingText && h("span", {
  54. "class": bem('loading-text')
  55. }, [loadingText])] : h("span", {
  56. "class": bem('text')
  57. }, [slots["default"] ? slots["default"]() : props.text])]);
  58. }
  59. Button.props = _extends({}, routeProps, {
  60. text: String,
  61. block: Boolean,
  62. plain: Boolean,
  63. round: Boolean,
  64. square: Boolean,
  65. loading: Boolean,
  66. hairline: Boolean,
  67. disabled: Boolean,
  68. nativeType: String,
  69. loadingText: String,
  70. bottomAction: Boolean,
  71. tag: {
  72. type: String,
  73. "default": 'button'
  74. },
  75. type: {
  76. type: String,
  77. "default": 'default'
  78. },
  79. size: {
  80. type: String,
  81. "default": 'normal'
  82. },
  83. loadingSize: {
  84. type: String,
  85. "default": '20px'
  86. }
  87. });
  88. export default sfc(Button);