|
1 | 1 | <script setup lang='ts'> |
2 | 2 | import type { FormKitFrameworkContext } from '@formkit/core' |
3 | 3 | import type { PropType } from 'vue' |
| 4 | +import { computed } from 'vue' |
4 | 5 | import { useFormKitSection } from '../composables' |
5 | 6 |
|
| 7 | +export interface FormKitOutputListProps { |
| 8 | + listStyle?: 'div' | 'ul' | 'ol' | 'span' |
| 9 | +} |
| 10 | +
|
6 | 11 | const props = defineProps({ |
7 | 12 | context: { |
8 | | - type: Object as PropType<FormKitFrameworkContext>, |
| 13 | + type: Object as PropType<FormKitFrameworkContext & FormKitOutputListProps>, |
9 | 14 | required: true, |
10 | 15 | }, |
11 | 16 | }) |
12 | 17 |
|
| 18 | +const listStyle = computed(() => { |
| 19 | + return props.context?.listStyle || 'span' |
| 20 | +}) |
| 21 | +
|
13 | 22 | const { hasPrefix, hasPrefixIcon, hasSuffix, hasSuffixIcon } = useFormKitSection(props.context) |
14 | 23 | </script> |
15 | 24 |
|
16 | 25 | <template> |
17 | 26 | <div class="p-formkit p-output-list"> |
18 | 27 | <i v-if="hasPrefixIcon" class="formkit-prefix-icon" :class="context?.iconPrefix" /> |
19 | | - <span v-if="hasPrefix" class="formkit-prefix"> |
| 28 | + <span v-if="hasPrefix && listStyle === 'span'" class="formkit-prefix"> |
20 | 29 | {{ context?.prefix }} |
21 | 30 | </span> |
22 | | - <span :id="context?.id" :style="context?.attrs?.style" class="p-output-list-items" :class="context?.attrs?.class"> |
| 31 | + <span v-if="listStyle === 'span'" :id="context?.id" :style="context?.attrs?.style" class="p-output-list-items" :class="context?.attrs?.class"> |
23 | 32 | <template v-for="(value, index) of context?._value" :key="index"> |
24 | 33 | <span v-if="index !== 0" class="p-output-list-divider" :class="context?.dividerClass">{{ context?.divider ?? ', ' }}</span> |
25 | 34 | <span class="p-output-list-item" :class="context?.itemClass">{{ value }}</span> |
26 | 35 | </template> |
27 | 36 | </span> |
28 | | - <span v-if="hasSuffix" class="formkit-suffix"> |
| 37 | + <div v-if="listStyle === 'div'" :id="context?.id" :style="context?.attrs?.style" class="p-output-list-items" :class="context?.attrs?.class"> |
| 38 | + <template v-for="(value, index) of context?._value" :key="index"> |
| 39 | + <div class="p-output-list-item" :class="context?.itemClass"> |
| 40 | + {{ value }} |
| 41 | + </div> |
| 42 | + </template> |
| 43 | + </div> |
| 44 | + <ul v-if="listStyle === 'ul'" :id="context?.id" :style="context?.attrs?.style" class="p-output-list-items" :class="context?.attrs?.class"> |
| 45 | + <li v-for="(value, index) of context?._value" :key="index"> |
| 46 | + <span class="p-output-list-item" :class="context?.itemClass"> |
| 47 | + {{ value }} |
| 48 | + </span> |
| 49 | + </li> |
| 50 | + </ul> |
| 51 | + <ol v-if="listStyle === 'ol'" :id="context?.id" :style="context?.attrs?.style" class="p-output-list-items" :class="context?.attrs?.class"> |
| 52 | + <li v-for="(value, index) of context?._value" :key="index"> |
| 53 | + <span class="p-output-list-item" :class="context?.itemClass"> |
| 54 | + {{ value }} |
| 55 | + </span> |
| 56 | + </li> |
| 57 | + </ol> |
| 58 | + <span v-if="hasSuffix && listStyle === 'span'" class="formkit-suffix"> |
29 | 59 | {{ context?.suffix }} |
30 | 60 | </span> |
31 | 61 | <i v-if="hasSuffixIcon" class="formkit-suffix-icon" :class="context?.iconSuffix" /> |
|
0 commit comments