|
| 1 | +<!-- eslint-disable vue/no-v-html --> |
1 | 2 | <template>
|
2 | 3 | <div
|
3 | 4 | :id="computedId"
|
|
11 | 12 | class="d-block w-100"
|
12 | 13 | :alt="imgAlt"
|
13 | 14 | :src="imgSrc"
|
14 |
| - :width="imgWidth || width" |
15 |
| - :height="imgHeight || height" |
| 15 | + :width="imgWidth || parentWidth" |
| 16 | + :height="imgHeight || parentHeight" |
16 | 17 | :blank="imgBlank"
|
17 | 18 | :blank-color="imgBlankColor"
|
18 | 19 | />
|
|
36 | 37 | </div>
|
37 | 38 | </template>
|
38 | 39 |
|
39 |
| -<script lang="ts"> |
40 |
| -import useId from '../../composables/useId' |
41 |
| -import {computed, defineComponent, inject} from 'vue' |
42 |
| -import {injectionKey, ParentData} from './BCarousel.vue' |
| 40 | +<script setup lang="ts"> |
| 41 | +// import type {BCarouselSlideProps} from '@/types/components' |
| 42 | +import useId from '@/composables/useId' |
| 43 | +import {computed, inject} from 'vue' |
| 44 | +import type {BCarouselParentData} from '@/types/components' |
| 45 | +import {injectionKey} from './BCarousel.vue' |
43 | 46 |
|
44 |
| -export default defineComponent({ |
45 |
| - name: 'BCarouselSlide', |
46 |
| - props: { |
47 |
| - active: {type: Boolean, default: false}, |
48 |
| - background: {type: String, required: false}, |
49 |
| - caption: {type: String, required: false}, |
50 |
| - captionHtml: {type: String, required: false}, |
51 |
| - captionTag: {type: String, default: 'h3'}, |
52 |
| - contentTag: {type: String, default: 'div'}, |
53 |
| - contentVisibleUp: {type: String, required: false}, |
54 |
| - id: {type: String, required: false}, |
55 |
| - imgAlt: {type: String, required: false}, |
56 |
| - imgBlank: {type: Boolean, default: false}, |
57 |
| - imgBlankColor: {type: String, default: 'transparent'}, |
58 |
| - imgHeight: {type: String}, |
59 |
| - imgSrc: {type: String}, |
60 |
| - imgWidth: {type: String}, |
61 |
| - interval: {type: [String, Number]}, |
62 |
| - text: {type: String, required: false}, |
63 |
| - textHtml: {type: String, required: false}, |
64 |
| - textTag: {type: String, default: 'p'}, |
65 |
| - }, |
66 |
| - setup(props) { |
67 |
| - const parentData = inject<ParentData>(injectionKey, {}) |
68 |
| - const computedId = useId(props.id, 'accordion') |
69 |
| - const img = computed(() => (props.imgBlank ? props.imgBlank : props.imgSrc)) |
| 47 | +interface BCarouselSlideProps { |
| 48 | + imgSrc: string |
| 49 | + imgHeight: string |
| 50 | + imgWidth: string |
| 51 | + interval: string | number |
| 52 | + active?: boolean |
| 53 | + background?: string |
| 54 | + caption?: string |
| 55 | + captionHtml?: string |
| 56 | + captionTag?: string |
| 57 | + contentTag?: string |
| 58 | + contentVisibleUp?: string |
| 59 | + id?: string |
| 60 | + imgAlt?: string |
| 61 | + imgBlank?: boolean |
| 62 | + imgBlankColor?: string |
| 63 | + text?: string |
| 64 | + textHtml?: string |
| 65 | + textTag?: string |
| 66 | +} |
70 | 67 |
|
71 |
| - const computedAttr = computed(() => ({ |
72 |
| - background: `${ |
73 |
| - props.background || parentData.background || 'rgb(171, 171, 171)' |
74 |
| - } none repeat scroll 0% 0%`, |
75 |
| - })) |
| 68 | +const props = withDefaults(defineProps<BCarouselSlideProps>(), { |
| 69 | + active: false, |
| 70 | + captionTag: 'h3', |
| 71 | + contentTag: 'div', |
| 72 | + imgBlank: false, |
| 73 | + imgBlankColor: 'transparent', |
| 74 | + textTag: 'p', |
| 75 | +}) |
76 | 76 |
|
77 |
| - const computedContentClasses = computed(() => ({ |
78 |
| - 'd-none': props.contentVisibleUp, |
79 |
| - [`d-${props.contentVisibleUp}-block`]: props.contentVisibleUp, |
80 |
| - })) |
81 |
| - const showText = computed(() => props.text && !props.textHtml) |
82 |
| - const showTextAsHtml = computed(() => props.textHtml) |
83 |
| - const showCaption = computed(() => props.caption && !props.captionHtml) |
84 |
| - const showCaptionAsHtml = computed(() => props.captionHtml) |
| 77 | +const parentData = inject<BCarouselParentData>(injectionKey, {}) |
| 78 | +const computedId = useId(props.id, 'accordion') |
| 79 | +// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 80 | +const img = computed<string | true>(() => (props.imgBlank ? props.imgBlank : props.imgSrc)) |
85 | 81 |
|
86 |
| - return { |
87 |
| - computedAttr, |
88 |
| - computedContentClasses, |
89 |
| - computedId, |
90 |
| - height: parentData.height, |
91 |
| - img, |
92 |
| - showCaption, |
93 |
| - showCaptionAsHtml, |
94 |
| - showText, |
95 |
| - showTextAsHtml, |
96 |
| - width: parentData.width, |
97 |
| - } |
98 |
| - }, |
99 |
| -}) |
| 82 | +const computedAttr = computed(() => ({ |
| 83 | + background: `${ |
| 84 | + props.background || parentData.background || 'rgb(171, 171, 171)' |
| 85 | + } none repeat scroll 0% 0%`, |
| 86 | +})) |
| 87 | +
|
| 88 | +const computedContentClasses = computed(() => ({ |
| 89 | + 'd-none': props.contentVisibleUp, |
| 90 | + [`d-${props.contentVisibleUp}-block`]: props.contentVisibleUp, |
| 91 | +})) |
| 92 | +const showText = computed<boolean | '' | undefined>(() => props.text && !props.textHtml) |
| 93 | +const showTextAsHtml = computed<string | undefined>(() => props.textHtml) |
| 94 | +const showCaption = computed<boolean | '' | undefined>(() => props.caption && !props.captionHtml) |
| 95 | +const showCaptionAsHtml = computed<string | undefined>(() => props.captionHtml) |
| 96 | +const parentWidth = computed<string | undefined>(() => parentData.width) |
| 97 | +const parentHeight = computed<string | undefined>(() => parentData.height) |
100 | 98 | </script>
|
0 commit comments