Skip to content

Instantly share code, notes, and snippets.

@morphatic
Created September 11, 2019 00:12
Show Gist options
  • Save morphatic/40306a7d46a2dc0ae88221ce6fd90155 to your computer and use it in GitHub Desktop.
Save morphatic/40306a7d46a2dc0ae88221ce6fd90155 to your computer and use it in GitHub Desktop.
Adding custom properties to VStateSelect
// 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