index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <view
  3. class="m-card"
  4. :style="{
  5. padding: `${padding}px`,
  6. background: `${bgColor}`,
  7. }"
  8. :class="[`${rounded ? 'rounded-12px' : ''}`, `${spaceClass}`]"
  9. >
  10. <slot></slot>
  11. </view>
  12. </template>
  13. <script setup lang="ts">
  14. defineOptions({ name: 'MCard' })
  15. const props = withDefaults(
  16. defineProps<{
  17. bgColor?: string
  18. rounded?: boolean
  19. padding?: number | string
  20. border?: boolean
  21. space?: boolean
  22. justify?: 'start' | 'end' | 'center' | 'between' | 'around' | 'evenly'
  23. direction?: 'vertical' | 'horizontal'
  24. align?: 'center'
  25. }>(),
  26. {
  27. bgColor: 'var(--bg-card)',
  28. padding: 16,
  29. rounded: true,
  30. border: false,
  31. space: false,
  32. direction: 'vertical',
  33. align: 'center',
  34. justify: 'start',
  35. }
  36. )
  37. const spaceClass = computed(() => {
  38. if (props.space) {
  39. let cls = `flex gap-8px items-${props.align}`
  40. if (props.direction === 'vertical') {
  41. cls = cls + ' flex-col'
  42. }
  43. if (props.justify) {
  44. cls = cls + ` justify-${props.justify}`
  45. }
  46. return cls
  47. } else {
  48. return ''
  49. }
  50. })
  51. </script>
  52. <style scoped lang="scss">
  53. .m-card {
  54. @apply my-12px bg-bg-card;
  55. box-shadow: 0px 0px 10px rgba(0, 0, 0, 20%);
  56. }
  57. </style>