input component updates in vue3

This commit is contained in:
Forms Dev 2023-11-28 13:54:57 +05:30
parent 9b4ac38ae4
commit f74959214d
4 changed files with 74 additions and 45 deletions

View File

@ -36,7 +36,7 @@
"vue-notion": "^3.0.0-beta.1", "vue-notion": "^3.0.0-beta.1",
"vue-router": "^4.2.5", "vue-router": "^4.2.5",
"vue-signature-pad": "^3.0.2", "vue-signature-pad": "^3.0.2",
"vue2-editor": "^2.10.3", "vue3-editor": "^0.1.1",
"vue3-vt-notifications": "^1.0.0", "vue3-vt-notifications": "^1.0.0",
"vuedraggable": "^4.1.0", "vuedraggable": "^4.1.0",
"vuex": "^4.1.0" "vuex": "^4.1.0"

View File

@ -1,14 +1,11 @@
<template> <template>
<div :class="wrapperClass" :style="inputStyle"> <input-wrapper
<label v-if="label" :for="id?id:name" v-bind="$props"
:class="[theme.default.label,{'uppercase text-xs':uppercaseLabels, 'text-sm':!uppercaseLabels}]"
> >
{{ label }} <template #label>
<span v-if="required" class="text-red-500 required-dot">*</span> <slot name="label" />
</label> </template>
<small v-if="help && helpPosition=='above_input'" :class="theme.default.help" class="flex mb-1">
<slot name="help"><span class="field-help" v-html="help" /></slot>
</small>
<div class="stars-outer"> <div class="stars-outer">
<div v-for="i in numberOfStars" :key="i" <div v-for="i in numberOfStars" :key="i"
@ -26,25 +23,45 @@
</div> </div>
</div> </div>
<small v-if="help && helpPosition=='below_input'" :class="theme.default.help"> <template #help>
<slot name="help"><span class="field-help" v-html="help" /></slot> <slot name="help" />
</small> </template>
<has-error v-if="hasValidation" :form="form" :field="name" /> <template #error>
</div> <slot name="error" />
</template>
</input-wrapper>
</template> </template>
<script> <script>
import inputMixin from '~/mixins/forms/input.js' import { inputProps, useFormInput } from './useFormInput.js'
import InputWrapper from './components/InputWrapper.vue'
export default { export default {
name: 'RatingInput', name: 'RatingInput',
components: { InputWrapper },
mixins: [inputMixin],
props: { props: {
...inputProps,
numberOfStars: { type: Number, default: 5 } numberOfStars: { type: Number, default: 5 }
}, },
setup (props, context) {
const {
compVal,
inputStyle,
hasValidation,
hasError
} = useFormInput(props, context)
return {
compVal,
inputStyle,
hasValidation,
hasError
}
},
data () { data () {
return { return {
hoverRating: -1 hoverRating: -1

View File

@ -1,41 +1,39 @@
<template> <template>
<div :class="wrapperClass"> <input-wrapper
<label v-if="label" :for="id?id:name" v-bind="$props"
:class="[theme.RichTextAreaInput.label, {'uppercase text-xs':uppercaseLabels, 'text-sm':!uppercaseLabels}]"
> >
{{ label }} <template #label>
<span v-if="required" class="text-red-500 required-dot">*</span> <slot name="label" />
</label> </template>
<div v-if="help && helpPosition=='above_input'" class="flex mb-1">
<small :class="theme.RichTextAreaInput.help" class="grow">
<slot name="help"><span class="field-help" v-html="help" /></slot>
</small>
</div>
<vue-editor :id="id?id:name" ref="editor" v-model="compVal" :disabled="disabled" <vue-editor :id="id?id:name" ref="editor" v-model="compVal" :disabled="disabled"
:placeholder="placeholder" :class="[{ '!ring-red-500 !ring-2': hasValidation && form.errors.has(name), '!cursor-not-allowed !bg-gray-200':disabled }, theme.RichTextAreaInput.input]" :placeholder="placeholder" :class="[{ '!ring-red-500 !ring-2': hasValidation && form.errors.has(name), '!cursor-not-allowed !bg-gray-200':disabled }, theme.RichTextAreaInput.input]"
:editor-toolbar="editorToolbar" class="rich-editor resize-y" :editor-toolbar="editorToolbar" class="rich-editor resize-y"
:style="inputStyle" :style="inputStyle"
/> />
<small v-if="help && helpPosition=='below_input'" :class="theme.RichTextAreaInput.help"> <template #help>
<slot name="help"><span class="field-help" v-html="help" /></slot> <slot name="help" />
</small> </template>
<has-error v-if="hasValidation" :form="form" :field="name" /> <template #error>
</div> <slot name="error" />
</template>
</input-wrapper>
</template> </template>
<script> <script>
import { VueEditor, Quill } from 'vue2-editor' import { inputProps, useFormInput } from './useFormInput.js'
import inputMixin from '~/mixins/forms/input.js' import InputWrapper from './components/InputWrapper.vue'
import { VueEditor, Quill } from 'vue3-editor'
Quill.imports['formats/link'].PROTOCOL_WHITELIST.push('notion') Quill.imports['formats/link'].PROTOCOL_WHITELIST.push('notion')
export default { export default {
name: 'RichTextAreaInput', name: 'RichTextAreaInput',
components: { VueEditor }, components: { InputWrapper, VueEditor },
mixins: [inputMixin],
props: { props: {
...inputProps,
editorToolbar: { editorToolbar: {
type: Array, type: Array,
default: () => { default: () => {
@ -47,8 +45,25 @@ export default {
] ]
} }
} }
},
setup (props, context) {
const {
compVal,
inputStyle,
hasValidation,
hasError
} = useFormInput(props, context)
return {
compVal,
inputStyle,
hasValidation,
hasError
} }
} }
}
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@ -13,15 +13,12 @@
:options="{ onEnd }" :options="{ onEnd }"
/> />
<div class="flex"> <template #bottom_after_help>
<small :class="theme.default.help"> <small :class="theme.default.help">
<a :class="theme.default.help" href="#" @click.prevent="clear">Clear</a> <a :class="theme.default.help" href="#" @click.prevent="clear">Clear</a>
</small> </small>
</div>
<template #help>
<slot name="help" />
</template> </template>
<template #error> <template #error>
<slot name="error" /> <slot name="error" />
</template> </template>