Skip to content

Commit

Permalink
refactor: use mixin for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
14nrv committed Sep 30, 2018
1 parent f1b7c12 commit 14435d2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 93 deletions.
15 changes: 2 additions & 13 deletions src/components/Fields/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,14 @@
</template>

<script>
import { slug } from '@/helpers'
import fieldsMixin from '@/mixins/fields'
export default {
name: 'Checkbox',
filters: {
slugify: value => slug(value)
},
mixins: [ fieldsMixin ],
data: () => ({
value: []
}),
props: {
item: {
type: Object,
required: true
},
error: {
required: true
}
},
methods: {
updateValue (ev) {
this.value = [...this.value, ev.target.value]
Expand Down
20 changes: 2 additions & 18 deletions src/components/Fields/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,10 @@
</template>

<script>
import { slug } from '@/helpers'
import fieldsMixin from '@/mixins/fields'
export default {
name: 'Input',
filters: {
slugify: value => slug(value)
},
props: {
item: {
type: Object,
required: true
},
error: {
required: true
}
},
methods: {
updateValue (e) {
this.$emit('input', e.target.value)
}
}
mixins: [ fieldsMixin ]
}
</script>
22 changes: 3 additions & 19 deletions src/components/Fields/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,14 @@
</template>

<script>
import { slug } from '@/helpers'
import fieldsMixin from '@/mixins/fields'
export default {
name: 'Radio',
filters: {
slugify: value => slug(value)
},
mixins: [ fieldsMixin ],
data: () => ({
value: []
}),
props: {
item: {
type: Object,
required: true
},
error: {
required: true
}
},
methods: {
updateValue () {
this.$emit('input', this.value)
}
}
})
}
</script>

Expand Down
22 changes: 2 additions & 20 deletions src/components/Fields/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,15 @@
</template>

<script>
import { slug } from '@/helpers'
import fieldsMixin from '@/mixins/fields'
export default {
name: 'Select',
filters: {
slugify: value => slug(value)
},
props: {
item: {
type: Object,
required: true
},
error: {
required: true
}
},
methods: {
updateValue (e) {
this.$emit('input', e.target.value)
}
}
mixins: [ fieldsMixin ]
}
</script>

<style lang="stylus">
dangerColor = #ff3860
.is-fullwidth
width 100%
</style>
25 changes: 2 additions & 23 deletions src/components/Fields/Textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,10 @@
</template>

<script>
import { slug } from '@/helpers'
import fieldsMixin from '@/mixins/fields'
export default {
name: 'Textarea',
filters: {
slugify: value => slug(value)
},
data () {
return {
formName: this.$parent.formName
}
},
props: {
item: {
type: Object,
required: true
},
error: {
required: false
}
},
methods: {
updateValue (e) {
this.$emit('input', e.target.value)
}
}
mixins: [ fieldsMixin ]
}
</script>
21 changes: 21 additions & 0 deletions src/mixins/fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { slug } from '@/helpers'

export default {
filters: {
slugify: value => slug(value)
},
props: {
item: {
type: Object,
required: true
},
error: {
required: true
}
},
methods: {
updateValue (e) {
this.$emit('input', e.target.value)
}
}
}

0 comments on commit 14435d2

Please sign in to comment.