INitial scoped slot expansion work
This commit is contained in:
parent
b58ed70a5f
commit
3d79733cba
2
dist/formulate.esm.js
vendored
2
dist/formulate.esm.js
vendored
File diff suppressed because one or more lines are too long
4
dist/formulate.min.js
vendored
4
dist/formulate.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/formulate.umd.js
vendored
2
dist/formulate.umd.js
vendored
File diff suppressed because one or more lines are too long
@ -9,6 +9,8 @@ import fauxUploader from './libs/faux-uploader'
|
|||||||
import FormulateInput from './FormulateInput.vue'
|
import FormulateInput from './FormulateInput.vue'
|
||||||
import FormulateForm from './FormulateForm.vue'
|
import FormulateForm from './FormulateForm.vue'
|
||||||
import FormulateErrors from './FormulateErrors.vue'
|
import FormulateErrors from './FormulateErrors.vue'
|
||||||
|
import FormulateHelp from './slots/FormulateHelp.vue'
|
||||||
|
import FormulateLabel from './slots/FormulateLabel.vue'
|
||||||
import FormulateInputGroup from './FormulateInputGroup.vue'
|
import FormulateInputGroup from './FormulateInputGroup.vue'
|
||||||
import FormulateInputBox from './inputs/FormulateInputBox.vue'
|
import FormulateInputBox from './inputs/FormulateInputBox.vue'
|
||||||
import FormulateInputText from './inputs/FormulateInputText.vue'
|
import FormulateInputText from './inputs/FormulateInputText.vue'
|
||||||
@ -30,6 +32,8 @@ class Formulate {
|
|||||||
this.defaults = {
|
this.defaults = {
|
||||||
components: {
|
components: {
|
||||||
FormulateForm,
|
FormulateForm,
|
||||||
|
FormulateHelp,
|
||||||
|
FormulateLabel,
|
||||||
FormulateInput,
|
FormulateInput,
|
||||||
FormulateErrors,
|
FormulateErrors,
|
||||||
FormulateInputBox,
|
FormulateInputBox,
|
||||||
@ -41,6 +45,11 @@ class Formulate {
|
|||||||
FormulateInputSlider,
|
FormulateInputSlider,
|
||||||
FormulateInputTextArea
|
FormulateInputTextArea
|
||||||
},
|
},
|
||||||
|
slotDefaults: {
|
||||||
|
label: 'FormulateLabel',
|
||||||
|
help: 'FormulateHelp',
|
||||||
|
errors: 'FormulateErrors'
|
||||||
|
},
|
||||||
library,
|
library,
|
||||||
rules,
|
rules,
|
||||||
mimes,
|
mimes,
|
||||||
@ -138,6 +147,19 @@ class Formulate {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What component should be rendered for the given slot location and type.
|
||||||
|
* @param {string} type the type of component
|
||||||
|
* @param {string} slot the name of the slot
|
||||||
|
*/
|
||||||
|
slotComponent (type, slot) {
|
||||||
|
const def = this.options.library[type]
|
||||||
|
if (def.slots && def.slots[slot]) {
|
||||||
|
return def.slots[slot]
|
||||||
|
}
|
||||||
|
return this.options.slotDefaults[slot]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get validation rules.
|
* Get validation rules.
|
||||||
* @return {object} object of validation functions
|
* @return {object} object of validation functions
|
||||||
|
@ -8,14 +8,14 @@
|
|||||||
>
|
>
|
||||||
<div class="formulate-input-wrapper">
|
<div class="formulate-input-wrapper">
|
||||||
<slot
|
<slot
|
||||||
v-if="context.hasLabel && context.labelPosition === 'before'"
|
v-if="context.labelPosition === 'before'"
|
||||||
name="label"
|
name="label"
|
||||||
v-bind="context"
|
v-bind="context"
|
||||||
>
|
>
|
||||||
<label
|
<component
|
||||||
class="formulate-input-label formulate-input-label--before"
|
:is="context.slotComponents.label"
|
||||||
:for="context.attributes.id"
|
v-if="context.hasLabel"
|
||||||
v-text="context.label"
|
:context="context"
|
||||||
/>
|
/>
|
||||||
</slot>
|
</slot>
|
||||||
<slot
|
<slot
|
||||||
@ -30,14 +30,14 @@
|
|||||||
</component>
|
</component>
|
||||||
</slot>
|
</slot>
|
||||||
<slot
|
<slot
|
||||||
v-if="context.hasLabel && context.labelPosition === 'after'"
|
v-if="context.labelPosition === 'after'"
|
||||||
name="label"
|
name="label"
|
||||||
v-bind="context"
|
v-bind="context"
|
||||||
>
|
>
|
||||||
<label
|
<component
|
||||||
class="formulate-input-label formulate-input-label--after"
|
:is="context.slotComponents.label"
|
||||||
:for="context.attributes.id"
|
v-if="context.hasLabel"
|
||||||
v-text="context.label"
|
:context="context"
|
||||||
/>
|
/>
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
@ -45,10 +45,10 @@
|
|||||||
name="help"
|
name="help"
|
||||||
v-bind="context"
|
v-bind="context"
|
||||||
>
|
>
|
||||||
<div
|
<component
|
||||||
|
:is="slotComponents.help"
|
||||||
v-if="context.help"
|
v-if="context.help"
|
||||||
class="formulate-input-help"
|
:context="context"
|
||||||
v-text="context.help"
|
|
||||||
/>
|
/>
|
||||||
</slot>
|
</slot>
|
||||||
<FormulateErrors
|
<FormulateErrors
|
||||||
|
@ -46,6 +46,7 @@ export default {
|
|||||||
visibleValidationErrors,
|
visibleValidationErrors,
|
||||||
component,
|
component,
|
||||||
hasLabel,
|
hasLabel,
|
||||||
|
slotComponents,
|
||||||
...context
|
...context
|
||||||
} = this.context
|
} = this.context
|
||||||
return this.options.map(option => this.groupItemContext(
|
return this.options.map(option => this.groupItemContext(
|
||||||
|
@ -27,6 +27,7 @@ export default {
|
|||||||
preventWindowDrops: this.preventWindowDrops,
|
preventWindowDrops: this.preventWindowDrops,
|
||||||
setErrors: this.setErrors.bind(this),
|
setErrors: this.setErrors.bind(this),
|
||||||
showValidationErrors: this.showValidationErrors,
|
showValidationErrors: this.showValidationErrors,
|
||||||
|
slotComponents: this.slotComponents,
|
||||||
type: this.type,
|
type: this.type,
|
||||||
uploadBehavior: this.uploadBehavior,
|
uploadBehavior: this.uploadBehavior,
|
||||||
uploadUrl: this.mergedUploadUrl,
|
uploadUrl: this.mergedUploadUrl,
|
||||||
@ -52,7 +53,8 @@ export default {
|
|||||||
hasErrors,
|
hasErrors,
|
||||||
hasVisibleErrors,
|
hasVisibleErrors,
|
||||||
showValidationErrors,
|
showValidationErrors,
|
||||||
visibleValidationErrors
|
visibleValidationErrors,
|
||||||
|
slotComponents
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -230,6 +232,16 @@ function hasVisibleErrors () {
|
|||||||
return ((this.validationErrors && this.showValidationErrors) || !!this.explicitErrors.length)
|
return ((this.validationErrors && this.showValidationErrors) || !!this.explicitErrors.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The component that should be rendered in the label slot as default.
|
||||||
|
*/
|
||||||
|
function slotComponents () {
|
||||||
|
return {
|
||||||
|
label: this.$formulate.slotComponent(this.type, 'label'),
|
||||||
|
help: this.$formulate.slotComponent(this.type, 'help')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bound into the context object.
|
* Bound into the context object.
|
||||||
*/
|
*/
|
||||||
|
22
src/slots/FormulateHelp.vue
Normal file
22
src/slots/FormulateHelp.vue
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
v-if="context.help"
|
||||||
|
class="formulate-input-help"
|
||||||
|
v-text="context.help"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
context: {
|
||||||
|
type: Object,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
22
src/slots/FormulateLabel.vue
Normal file
22
src/slots/FormulateLabel.vue
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<template>
|
||||||
|
<label
|
||||||
|
:class="`formulate-input-label formulate-input-label--${context.labelPosition}`"
|
||||||
|
:for="context.id"
|
||||||
|
v-text="context.label"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
context: {
|
||||||
|
type: Object,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
@ -63,6 +63,8 @@ describe('Formulate', () => {
|
|||||||
it('installs on vue instance', () => {
|
it('installs on vue instance', () => {
|
||||||
const components = [
|
const components = [
|
||||||
'FormulateForm',
|
'FormulateForm',
|
||||||
|
'FormulateHelp',
|
||||||
|
'FormulateLabel',
|
||||||
'FormulateInput',
|
'FormulateInput',
|
||||||
'FormulateErrors',
|
'FormulateErrors',
|
||||||
'FormulateInputBox',
|
'FormulateInputBox',
|
||||||
|
Loading…
Reference in New Issue
Block a user