| 1 |
<template> |
| 2 |
<div class="ivyforms-field__html"> |
| 3 |
<IvyFormItem :label="hideLabel ? '' : label" :label-position="labelPosition"> |
| 4 |
<SafeHTML |
| 5 |
v-if="htmlContent" |
| 6 |
class="ivyforms-field__html-preview" |
| 7 |
:html="htmlContent" |
| 8 |
:allowed-tags="ALLOWED_TAGS" |
| 9 |
:allowed-attributes="ALLOWED_ATTR" |
| 10 |
/> |
| 11 |
<div |
| 12 |
v-else |
| 13 |
class="ivyforms-field__html-placeholder ivyforms-flex ivyforms-p-12 ivyforms-align-items-center ivyforms-justify-content-center regular-14" |
| 14 |
> |
| 15 |
{{ getLabel('html_field_placeholder') }} |
| 16 |
</div> |
| 17 |
<div v-if="description" class="ivyforms-description-message ivyforms-mt-8 regular-14"> |
| 18 |
{{ description }} |
| 19 |
</div> |
| 20 |
</IvyFormItem> |
| 21 |
</div> |
| 22 |
</template> |
| 23 |
|
| 24 |
<script setup lang="ts"> |
| 25 |
import { computed } from 'vue' |
| 26 |
import { useFormBuilder } from '@/stores/useFormBuilder' |
| 27 |
import { useLabels } from '@/composables/useLabels' |
| 28 |
import SafeHTML from '@/views/_components/SafeHTML.vue' |
| 29 |
import { |
| 30 |
ALLOWED_HTML_TAGS as ALLOWED_TAGS, |
| 31 |
ALLOWED_HTML_ATTR as ALLOWED_ATTR, |
| 32 |
} from '@/constants/html-sanitization.ts' |
| 33 |
|
| 34 |
const props = defineProps<{ fieldIndex: number }>() |
| 35 |
const formBuilderStore = useFormBuilder() |
| 36 |
const { getLabel } = useLabels() |
| 37 |
|
| 38 |
const field = computed(() => formBuilderStore.fields.find((f) => f.fieldIndex === props.fieldIndex)) |
| 39 |
|
| 40 |
const label = computed(() => field.value?.label || '') |
| 41 |
const hideLabel = computed(() => field.value?.hideLabel || false) |
| 42 |
const htmlContent = computed(() => field.value?.htmlContent || '') |
| 43 |
const description = computed(() => field.value?.description || '') |
| 44 |
const labelPosition = computed(() => |
| 45 |
field.value?.labelPosition === 'default' ? 'top' : field.value?.labelPosition || 'top', |
| 46 |
) |
| 47 |
</script> |
| 48 |
|
| 49 |
<style lang="scss" scoped> |
| 50 |
.ivyforms-field__html { |
| 51 |
cursor: default; |
| 52 |
|
| 53 |
.ivyforms-form-item { |
| 54 |
cursor: default; |
| 55 |
margin-bottom: 0; |
| 56 |
|
| 57 |
:deep(.ivyforms-form-item__label) { |
| 58 |
display: flex; |
| 59 |
align-items: center; |
| 60 |
color: var(--map-base-text-0); |
| 61 |
/* Medium/Medium 14 */ |
| 62 |
font-size: 14px; |
| 63 |
font-style: normal; |
| 64 |
font-weight: 500; |
| 65 |
line-height: 20px; /* 142.857% */ |
| 66 |
cursor: default !important; |
| 67 |
} |
| 68 |
|
| 69 |
:deep(.el-form-item__label) { |
| 70 |
cursor: default; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
&-preview, |
| 75 |
.ivyforms-safe-html { |
| 76 |
padding: 12px; |
| 77 |
border-radius: var(--Radius-radius-md, 8px); |
| 78 |
border: 1px solid var(--map-base-dusk-stroke--2); |
| 79 |
background: var(--map-base-dusk-o025); |
| 80 |
color: var(--map-base-text-0); |
| 81 |
min-height: 40px; |
| 82 |
cursor: default; |
| 83 |
width: 95%; |
| 84 |
display: block; |
| 85 |
white-space: normal; |
| 86 |
overflow-wrap: anywhere; |
| 87 |
word-break: break-word; |
| 88 |
} |
| 89 |
|
| 90 |
&-placeholder { |
| 91 |
border-radius: var(--Radius-radius-md, 8px); |
| 92 |
border: 1px dashed var(--map-base-dusk-stroke--2); |
| 93 |
background: var(--map-base-dusk-o025); |
| 94 |
color: var(--map-base-dusk-stroke--2); |
| 95 |
min-height: 40px; |
| 96 |
cursor: default; |
| 97 |
} |
| 98 |
|
| 99 |
.ivyforms-description-message { |
| 100 |
color: var(--map-base-text-0); |
| 101 |
display: block; |
| 102 |
width: 100%; |
| 103 |
white-space: normal; |
| 104 |
overflow-wrap: anywhere; |
| 105 |
word-break: break-word; |
| 106 |
} |
| 107 |
} |
| 108 |
</style> |
| 109 |
|