index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { VantComponent } from '../common/component';
  2. import { button } from '../mixins/button';
  3. import { openType } from '../mixins/open-type';
  4. import { canIUseFormFieldButton } from '../common/version';
  5. const mixins = [button, openType];
  6. if (canIUseFormFieldButton()) {
  7. mixins.push('wx://form-field-button');
  8. }
  9. VantComponent({
  10. mixins,
  11. classes: ['hover-class', 'loading-class'],
  12. data: {
  13. baseStyle: '',
  14. },
  15. props: {
  16. formType: String,
  17. icon: String,
  18. classPrefix: {
  19. type: String,
  20. value: 'van-icon',
  21. },
  22. plain: Boolean,
  23. block: Boolean,
  24. round: Boolean,
  25. square: Boolean,
  26. loading: Boolean,
  27. hairline: Boolean,
  28. disabled: Boolean,
  29. loadingText: String,
  30. customStyle: String,
  31. loadingType: {
  32. type: String,
  33. value: 'circular',
  34. },
  35. type: {
  36. type: String,
  37. value: 'default',
  38. },
  39. dataset: null,
  40. size: {
  41. type: String,
  42. value: 'normal',
  43. },
  44. loadingSize: {
  45. type: String,
  46. value: '20px',
  47. },
  48. color: {
  49. type: String,
  50. observer(color) {
  51. let style = '';
  52. if (color) {
  53. style += `color: ${this.data.plain ? color : 'white'};`;
  54. if (!this.data.plain) {
  55. // Use background instead of backgroundColor to make linear-gradient work
  56. style += `background: ${color};`;
  57. }
  58. // hide border when color is linear-gradient
  59. if (color.indexOf('gradient') !== -1) {
  60. style += 'border: 0;';
  61. } else {
  62. style += `border-color: ${color};`;
  63. }
  64. }
  65. if (style !== this.data.baseStyle) {
  66. this.setData({ baseStyle: style });
  67. }
  68. },
  69. },
  70. },
  71. methods: {
  72. onClick() {
  73. if (!this.data.loading) {
  74. this.$emit('click');
  75. }
  76. },
  77. noop() {},
  78. },
  79. });