2022-09-20 19:59:52 +00:00
|
|
|
<template>
|
|
|
|
<div :class="wrapperClass">
|
|
|
|
<label v-if="label" :for="id?id:name"
|
|
|
|
:class="[theme.CodeInput.label,{'uppercase text-xs':uppercaseLabels, 'text-sm':!uppercaseLabels}]"
|
|
|
|
>
|
|
|
|
{{ label }}
|
|
|
|
<span v-if="required" class="text-red-500 required-dot">*</span>
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<prism-editor :id="id?id:name" v-model="compVal" :disabled="disabled"
|
|
|
|
class="code-editor"
|
2023-03-22 14:49:52 +00:00
|
|
|
:class="[theme.CodeInput.input,{ '!ring-red-500 !ring-2': hasValidation && form.errors.has(name), '!cursor-not-allowed !bg-gray-200':disabled }]"
|
2022-09-20 19:59:52 +00:00
|
|
|
:style="inputStyle" :name="name"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
:highlight="highlighter" @change="onChange"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<small v-if="help" :class="theme.CodeInput.help">
|
2023-04-19 08:13:50 +00:00
|
|
|
<slot name="help"><span class="field-help" v-html="help" /></slot>
|
2022-09-20 19:59:52 +00:00
|
|
|
</small>
|
|
|
|
<has-error v-if="hasValidation" :form="form" :field="name" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
// import Prism Editor
|
|
|
|
import { PrismEditor } from 'vue-prism-editor'
|
|
|
|
import 'vue-prism-editor/dist/prismeditor.min.css' // import the styles somewhere
|
|
|
|
// import highlighting library (you can use any library you want just return html string)
|
|
|
|
|
|
|
|
import { highlight, languages } from 'prismjs/components/prism-core'
|
|
|
|
import 'prismjs/components/prism-clike'
|
|
|
|
import 'prismjs/components/prism-markup'
|
|
|
|
import 'prismjs/themes/prism-tomorrow.css' // import syntax highlighting styles
|
2023-01-21 11:57:37 +00:00
|
|
|
import inputMixin from '~/mixins/forms/input.js'
|
2022-09-20 19:59:52 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'CodeInput',
|
|
|
|
|
|
|
|
components: { PrismEditor },
|
|
|
|
mixins: [inputMixin],
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
onChange (event) {
|
|
|
|
const file = event.target.files[0]
|
|
|
|
this.$set(this.form, this.name, file)
|
|
|
|
},
|
|
|
|
highlighter (code) {
|
|
|
|
return highlight(code, languages.markup) // languages.<insert language> to return html with markup
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|