wd-divider.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view :class="rootClass" :style="rootStyle">
  3. <slot v-if="!vertical"></slot>
  4. </view>
  5. </template>
  6. <script lang="ts">
  7. export default {
  8. name: 'wd-divider',
  9. options: {
  10. virtualHost: true,
  11. addGlobalClass: true,
  12. styleIsolation: 'shared'
  13. }
  14. }
  15. </script>
  16. <script lang="ts" setup>
  17. import { computed, useSlots, type CSSProperties } from 'vue'
  18. import { dividerProps } from './types'
  19. import { objToStyle } from '../common/util'
  20. const props = defineProps(dividerProps)
  21. const slots = useSlots()
  22. const rootStyle = computed(() => {
  23. const { color, customStyle } = props
  24. const style: CSSProperties = {}
  25. if (color) {
  26. style.color = color
  27. }
  28. return `${objToStyle(style)}${customStyle}`
  29. })
  30. const rootClass = computed(() => {
  31. const prefixCls = 'wd-divider'
  32. const classes: Record<string, boolean> = {
  33. [prefixCls]: true,
  34. ['is-dashed']: props.dashed,
  35. ['is-hairline']: props.hairline,
  36. [`${prefixCls}--vertical`]: props.vertical,
  37. [`${prefixCls}--center`]: !props.vertical && props.contentPosition === 'center' && !!slots.default,
  38. [`${prefixCls}--left`]: !props.vertical && props.contentPosition === 'left',
  39. [`${prefixCls}--right`]: !props.vertical && props.contentPosition === 'right',
  40. [props.customClass]: !!props.customClass
  41. }
  42. return classes
  43. })
  44. </script>
  45. <style lang="scss" scoped>
  46. @import './index.scss';
  47. </style>