Skip to content

Commit c76a630

Browse files
fix(MdCore): prop validator message now uses Vue.util.warn
1 parent 9631403 commit c76a630

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

docs/app/pages/UiElements.vue

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
</template>
1515

1616
<script>
17-
export default {
18-
name: 'UiElements',
19-
data: () => ({
20-
elements: [
17+
export default {
18+
name: 'UiElements',
19+
data: () => ({
20+
elements: [
2121
22-
]
23-
})
24-
}
22+
]
23+
})
24+
}
2525
</script>

src/components/MdChips/MdChips.vue

+3-10
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929

3030
<script>
3131
import MdComponent from 'core/MdComponent'
32-
import MdUuid from 'core/utils/MdUuid'
3332
import MdField from 'components/MdField/MdField'
3433
import MdInput from 'components/MdField/MdInput/MdInput'
34+
import MdUuid from 'core/utils/MdUuid'
35+
import MdPropValidator from 'core/utils/MdPropValidator'
3536
3637
export default new MdComponent({
3738
name: 'MdChips',
@@ -47,15 +48,7 @@
4748
},
4849
mdInputType: {
4950
type: [String, Number],
50-
validator (type) {
51-
if (type === 'file') {
52-
console.error('The md-input-type prop cannot be \'file\'')
53-
54-
return false
55-
}
56-
57-
return true
58-
}
51+
...MdPropValidator('md-input-type', ['email', 'number', 'password', 'search', 'tel', 'text', 'url'])
5952
},
6053
mdPlaceholder: [String, Number],
6154
mdStatic: Boolean,

src/components/MdPortal/MdPortal.vue

+2-6
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@
2424
props: {
2525
mdIf: {
2626
type: null,
27-
validator: (value) => {
28-
return validator('md-if', this, value === null || typeof value === 'boolean', 'You should pass a Boolean value')
29-
}
27+
validator: (value) => validator('md-if', this, value === null || typeof value === 'boolean', 'You should pass a Boolean value')
3028
},
3129
mdTransitionName: String,
3230
mdTransitionAppear: Boolean,
3331
mdFollowEl: HTMLElement,
3432
mdTargetEl: {
3533
type: HTMLElement,
36-
validator: (value) => {
37-
return validator('md-target-el', this, value && value instanceof HTMLElement, 'You should pass a valid HTMLElement')
38-
}
34+
validator: (value) => validator('md-target-el', this, value && value instanceof HTMLElement, 'You should pass a valid HTMLElement')
3935
}
4036
},
4137
data: () => ({

src/core/utils/MdPropValidator.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import { util } from 'vue'
2+
13
export default (name, options) => {
24
return {
3-
validator (value) {
5+
validator: value => {
46
if (options.includes(value)) {
57
return true
68
}
79

8-
console.error(`The ${name} prop is invalid. Given value: ${value}. Available options: ${options.join(', ')}.`)
10+
util.warn(`The ${name} prop is invalid. Given value: ${value}. Available options: ${options.join(', ')}.`, this)
911

1012
return false
1113
}

0 commit comments

Comments
 (0)