button.vue 1010 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <button class="ui-button" :class="className" :style="style">
  3. <UIIcon :type="icon" v-if="icon" class="ui-button-icon" />
  4. <slot></slot>
  5. </button>
  6. </template>
  7. <script lang="ts" setup>
  8. import { defineProps, computed } from 'vue'
  9. import { normalizeUnitToStyle } from '@kankan/utils'
  10. // import UIIcon from '../../icon/src/icon.vue'
  11. import UIIcon from '@kankan/components/basic/icon'
  12. defineOptions({
  13. name: 'UIMessage',
  14. })
  15. const props = defineProps({
  16. type: {
  17. type: String,
  18. default: 'normal',
  19. },
  20. color: {
  21. type: String,
  22. },
  23. width: {
  24. type: [String, Number],
  25. },
  26. icon: {
  27. type: String,
  28. },
  29. })
  30. const custom = `customize`
  31. const className = computed(() => (props.color ? custom : props.type))
  32. const style = computed(() => {
  33. const style = {
  34. width: normalizeUnitToStyle(props.width),
  35. }
  36. if (className.value === custom) {
  37. style['--color'] = props.color
  38. }
  39. return style
  40. })
  41. </script>