button.vue 874 B

123456789101112131415161718192021222324252627282930313233
  1. <template>
  2. <button class="ui-button" :class="className" :style="style">
  3. <UIIcon v-if="icon" :type="icon" class="ui-button-icon" />
  4. <slot />
  5. </button>
  6. </template>
  7. <script lang="ts" setup>
  8. import { computed, defineProps } from 'vue'
  9. import { normalizeUnitToStyle } from '@kankan-components/utils'
  10. import UIIcon from '@kankan-components/components/basic/icon'
  11. import { buttonProps } from './button'
  12. defineOptions({
  13. name: 'UiButton',
  14. })
  15. const props = defineProps(buttonProps)
  16. const custom = `customize`
  17. const className = computed(() => (props.color ? custom : props.type))
  18. const style = computed(() => {
  19. const style = {
  20. width: props.width ? normalizeUnitToStyle(props.width) : 'auto',
  21. '--color': '',
  22. }
  23. if (className.value === custom) {
  24. style['--color'] = props.color || ''
  25. }
  26. return style
  27. })
  28. </script>