index.js 861B

123456789101112131415161718192021222324252627282930
  1. import { VantComponent } from '../common/component';
  2. import { RED, BLUE, GREEN } from '../common/color';
  3. const DEFAULT_COLOR = '#999';
  4. const COLOR_MAP = {
  5. danger: RED,
  6. primary: BLUE,
  7. success: GREEN
  8. };
  9. VantComponent({
  10. props: {
  11. size: String,
  12. type: String,
  13. mark: Boolean,
  14. color: String,
  15. plain: Boolean,
  16. round: Boolean,
  17. textColor: String
  18. },
  19. computed: {
  20. style() {
  21. const color = this.data.color || COLOR_MAP[this.data.type] || DEFAULT_COLOR;
  22. const key = this.data.plain ? 'color' : 'background-color';
  23. const style = { [key]: color };
  24. if (this.data.textColor) {
  25. style.color = this.data.textColor;
  26. }
  27. return Object.keys(style).map(key => `${key}: ${style[key]}`).join(';');
  28. }
  29. }
  30. });