|
44 | 44 | </component>
|
45 | 45 | </template>
|
46 | 46 |
|
47 |
| -<script lang="ts"> |
48 |
| -import {computed, defineComponent, PropType} from 'vue' |
49 |
| -import type {Alignment, ColorVariant} from '../../types' |
| 47 | +<script setup lang="ts"> |
| 48 | +// import type {BCardProps} from '@/types/components' |
| 49 | +import type {Alignment, ColorVariant, TextColorVariant} from '@/types' |
| 50 | +import {computed} from 'vue' |
50 | 51 |
|
51 |
| -export default defineComponent({ |
52 |
| - name: 'BCard', |
53 |
| - props: { |
54 |
| - align: {type: String as PropType<Alignment>, required: false}, |
55 |
| - bgVariant: {type: String as PropType<ColorVariant>, required: false}, |
56 |
| - bodyBgVariant: {type: String as PropType<ColorVariant>, required: false}, |
57 |
| - bodyClass: {type: [Array, Object, String], required: false}, |
58 |
| - bodyTag: {type: String, default: 'div'}, |
59 |
| - bodyTextVariant: {type: String as PropType<ColorVariant>, required: false}, |
60 |
| - borderVariant: {type: String as PropType<ColorVariant>, required: false}, |
61 |
| - footer: {type: String, required: false}, |
62 |
| - footerBgVariant: {type: String as PropType<ColorVariant>, required: false}, |
63 |
| - footerBorderVariant: {type: String as PropType<ColorVariant>, required: false}, |
64 |
| - footerClass: {type: [Array, Object, String], required: false}, |
65 |
| - footerHtml: {type: String, default: ''}, |
66 |
| - footerTag: {type: String, default: 'div'}, |
67 |
| - footerTextVariant: {type: String as PropType<ColorVariant>, required: false}, |
68 |
| - header: {type: String, required: false}, |
69 |
| - headerBgVariant: {type: String as PropType<ColorVariant>, required: false}, |
70 |
| - headerBorderVariant: {type: String as PropType<ColorVariant>, required: false}, |
71 |
| - headerClass: {type: [Array, Object, String], required: false}, |
72 |
| - headerHtml: {type: String, default: ''}, |
73 |
| - headerTag: {type: String, default: 'div'}, |
74 |
| - headerTextVariant: {type: String as PropType<ColorVariant>, required: false}, |
75 |
| - imgAlt: {type: String, required: false}, |
76 |
| - imgBottom: {type: Boolean, default: false}, |
77 |
| - imgEnd: {type: Boolean, default: false}, |
78 |
| - imgHeight: {type: [String, Number], required: false}, |
79 |
| - imgLeft: {type: Boolean, default: false}, |
80 |
| - imgRight: {type: Boolean, default: false}, |
81 |
| - imgSrc: {type: String, required: false}, |
82 |
| - imgStart: {type: Boolean, default: false}, |
83 |
| - imgTop: {type: Boolean, default: false}, |
84 |
| - imgWidth: {type: [String, Number], required: false}, |
85 |
| - noBody: {type: Boolean, default: false}, |
86 |
| - overlay: {type: Boolean, default: false}, |
87 |
| - subTitle: {type: String, required: false}, |
88 |
| - subTitleTag: {type: String, default: 'h6'}, |
89 |
| - subTitleTextVariant: {type: String as PropType<ColorVariant>, default: 'muted'}, |
90 |
| - tag: {type: String, default: 'div'}, |
91 |
| - textVariant: {type: String as PropType<ColorVariant>, required: false}, |
92 |
| - title: {type: String, required: false}, |
93 |
| - titleTag: {type: String, default: 'h4'}, |
94 |
| - }, |
95 |
| - setup(props) { |
96 |
| - const classes = computed(() => ({ |
97 |
| - [`text-${props.align}`]: props.align, |
98 |
| - [`text-${props.textVariant}`]: props.textVariant, |
99 |
| - [`bg-${props.bgVariant}`]: props.bgVariant, |
100 |
| - [`border-${props.borderVariant}`]: props.borderVariant, |
101 |
| - 'flex-row': props.imgLeft || props.imgStart, |
102 |
| - 'flex-row-reverse': props.imgEnd || props.imgRight, |
103 |
| - })) |
| 52 | +interface BCardProps { |
| 53 | + align?: Alignment |
| 54 | + bgVariant?: ColorVariant |
| 55 | + bodyBgVariant?: ColorVariant |
| 56 | + bodyClass?: Array<string> | Record<string, unknown> | string // TODO record<string, unknown> can be replaced as a known object |
| 57 | + bodyTag?: string // Above todo, also Array can be explicit |
| 58 | + bodyTextVariant?: ColorVariant |
| 59 | + borderVariant?: ColorVariant |
| 60 | + footer?: string |
| 61 | + footerBgVariant?: ColorVariant |
| 62 | + footerBorderVariant?: ColorVariant |
| 63 | + footerClass?: Array<string> | Record<string, unknown> | string |
| 64 | + footerHtml?: string |
| 65 | + footerTag?: string |
| 66 | + footerTextVariant?: ColorVariant |
| 67 | + header?: string |
| 68 | + headerBgVariant?: ColorVariant |
| 69 | + headerBorderVariant?: ColorVariant |
| 70 | + headerClass?: Array<string> | Record<string, unknown> | string |
| 71 | + headerHtml?: string |
| 72 | + headerTag?: string |
| 73 | + headerTextVariant?: ColorVariant |
| 74 | + imgAlt?: string |
| 75 | + imgBottom?: boolean |
| 76 | + imgEnd?: boolean |
| 77 | + imgHeight?: string | number |
| 78 | + imgLeft?: boolean |
| 79 | + imgRight?: boolean |
| 80 | + imgSrc?: string |
| 81 | + imgStart?: boolean |
| 82 | + imgTop?: boolean |
| 83 | + imgWidth?: string | number |
| 84 | + noBody?: boolean |
| 85 | + overlay?: boolean |
| 86 | + subTitle?: string |
| 87 | + subTitleTag?: string |
| 88 | + subTitleTextVariant?: TextColorVariant |
| 89 | + tag?: string |
| 90 | + textVariant?: TextColorVariant |
| 91 | + title?: string |
| 92 | + titleTag?: string |
| 93 | +} |
104 | 94 |
|
105 |
| - const bodyClasses = computed(() => ({ |
106 |
| - 'card-body': !props.noBody, |
107 |
| - 'card-img-overlay': props.overlay, |
108 |
| - [`bg-${props.bodyBgVariant}`]: props.bodyBgVariant, |
109 |
| - [`text-${props.bodyTextVariant}`]: props.bodyTextVariant, |
110 |
| - })) |
| 95 | +const props = withDefaults(defineProps<BCardProps>(), { |
| 96 | + bodyTag: 'div', |
| 97 | + footerHtml: '', |
| 98 | + footerTag: 'div', |
| 99 | + headerHtml: '', |
| 100 | + headerTag: 'div', |
| 101 | + imgBottom: false, |
| 102 | + imgEnd: false, |
| 103 | + imgLeft: false, |
| 104 | + imgRight: false, |
| 105 | + imgStart: false, |
| 106 | + imgTop: false, |
| 107 | + noBody: false, |
| 108 | + overlay: false, |
| 109 | + subTitleTag: 'h6', |
| 110 | + subTitleTextVariant: 'muted', |
| 111 | + tag: 'div', |
| 112 | + titleTag: 'h4', |
| 113 | +}) |
111 | 114 |
|
112 |
| - const footerClasses = computed(() => ({ |
113 |
| - [`bg-${props.footerBgVariant}`]: props.footerBgVariant, |
114 |
| - [`border-${props.footerBorderVariant}`]: props.footerBorderVariant, |
115 |
| - [`text-${props.footerTextVariant}`]: props.footerTextVariant, |
116 |
| - })) |
| 115 | +const classes = computed(() => ({ |
| 116 | + [`text-${props.align}`]: props.align, |
| 117 | + [`text-${props.textVariant}`]: props.textVariant, |
| 118 | + [`bg-${props.bgVariant}`]: props.bgVariant, |
| 119 | + [`border-${props.borderVariant}`]: props.borderVariant, |
| 120 | + 'flex-row': props.imgLeft || props.imgStart, |
| 121 | + 'flex-row-reverse': props.imgEnd || props.imgRight, |
| 122 | +})) |
117 | 123 |
|
118 |
| - const headerClasses = computed(() => ({ |
119 |
| - [`bg-${props.headerBgVariant}`]: props.headerBgVariant, |
120 |
| - [`border-${props.headerBorderVariant}`]: props.headerBorderVariant, |
121 |
| - [`text-${props.headerTextVariant}`]: props.headerTextVariant, |
122 |
| - })) |
| 124 | +const bodyClasses = computed(() => ({ |
| 125 | + 'card-body': !props.noBody, |
| 126 | + 'card-img-overlay': props.overlay, |
| 127 | + [`bg-${props.bodyBgVariant}`]: props.bodyBgVariant, |
| 128 | + [`text-${props.bodyTextVariant}`]: props.bodyTextVariant, |
| 129 | +})) |
123 | 130 |
|
124 |
| - const imgClasses = computed(() => ({ |
125 |
| - 'card-img': |
126 |
| - !props.imgEnd && |
127 |
| - !props.imgRight && |
128 |
| - !props.imgStart && |
129 |
| - !props.imgLeft && |
130 |
| - !props.imgTop && |
131 |
| - !props.imgTop, |
132 |
| - 'card-img-right': props.imgEnd || props.imgRight, |
133 |
| - 'card-img-left': props.imgStart || props.imgLeft, |
134 |
| - 'card-img-top': props.imgTop, |
135 |
| - 'card-img-bottom': props.imgBottom, |
136 |
| - })) |
| 131 | +const footerClasses = computed(() => ({ |
| 132 | + [`bg-${props.footerBgVariant}`]: props.footerBgVariant, |
| 133 | + [`border-${props.footerBorderVariant}`]: props.footerBorderVariant, |
| 134 | + [`text-${props.footerTextVariant}`]: props.footerTextVariant, |
| 135 | +})) |
137 | 136 |
|
138 |
| - const imgAttr = computed(() => ({ |
139 |
| - src: props.imgSrc, |
140 |
| - alt: props.imgAlt, |
141 |
| - height: props.imgHeight, |
142 |
| - width: props.imgWidth, |
143 |
| - })) |
| 137 | +const headerClasses = computed(() => ({ |
| 138 | + [`bg-${props.headerBgVariant}`]: props.headerBgVariant, |
| 139 | + [`border-${props.headerBorderVariant}`]: props.headerBorderVariant, |
| 140 | + [`text-${props.headerTextVariant}`]: props.headerTextVariant, |
| 141 | +})) |
144 | 142 |
|
145 |
| - const subTitleClasses = computed(() => ({ |
146 |
| - [`text-${props.subTitleTextVariant}`]: props.subTitleTextVariant, |
147 |
| - })) |
| 143 | +const imgClasses = computed(() => ({ |
| 144 | + 'card-img': |
| 145 | + !props.imgEnd && |
| 146 | + !props.imgRight && |
| 147 | + !props.imgStart && |
| 148 | + !props.imgLeft && |
| 149 | + !props.imgTop && |
| 150 | + !props.imgTop, |
| 151 | + 'card-img-right': props.imgEnd || props.imgRight, |
| 152 | + 'card-img-left': props.imgStart || props.imgLeft, |
| 153 | + 'card-img-top': props.imgTop, |
| 154 | + 'card-img-bottom': props.imgBottom, |
| 155 | +})) |
148 | 156 |
|
149 |
| - return { |
150 |
| - classes, |
151 |
| - bodyClasses, |
152 |
| - footerClasses, |
153 |
| - headerClasses, |
154 |
| - imgClasses, |
155 |
| - imgAttr, |
156 |
| - subTitleClasses, |
157 |
| - } |
158 |
| - }, |
159 |
| -}) |
| 157 | +const imgAttr = computed(() => ({ |
| 158 | + src: props.imgSrc, |
| 159 | + alt: props.imgAlt, |
| 160 | + height: props.imgHeight, |
| 161 | + width: props.imgWidth, |
| 162 | +})) |
| 163 | +
|
| 164 | +const subTitleClasses = computed(() => ({ |
| 165 | + [`text-${props.subTitleTextVariant}`]: props.subTitleTextVariant, |
| 166 | +})) |
160 | 167 | </script>
|
0 commit comments