Created
September 11, 2019 00:12
-
-
Save morphatic/40306a7d46a2dc0ae88221ce6fd90155 to your computer and use it in GitHub Desktop.
Adding custom properties to VStateSelect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create Base Mixins and Define Custom Properties | |
const base = Vue.extend({ mixins: [VAutocomplete] }) | |
interface options extends InstanceType<typeof base> { | |
/** | |
* !Props unique to VStateSelect | |
*/ | |
contiguousOnly: boolean | |
exclude: string[] | |
includeTerritories: boolean | |
} | |
// Extend VAutocomplete to define the VStateSelect component | |
export default base.extend<options>().extend({ | |
name: 'v-state-select', | |
props: { | |
contiguousOnly: { | |
type: Boolean, | |
default: false, | |
}, | |
exclude: { | |
type: Array, | |
default: () => [], | |
}, | |
includeTerritories: { | |
type: Boolean, | |
default: false, | |
}, | |
}, | |
computed: { | |
allItems (): object[] { | |
const { contiguousOnly, exclude, includeTerritories } = this | |
const usaStates = new UsaStates({ | |
contiguousOnly, | |
exclude, | |
includeTerritories, | |
}) | |
return usaStates.format({ | |
$text: 'name', | |
$value: 'abbr', | |
}) | |
}, | |
classes (): object { | |
return { | |
...VAutocomplete.options.computed.classes.call(this), | |
'v-state-select': true, | |
} | |
}, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment