Skip to content

Commit

Permalink
Allow global override of select type (affects both selects and multis…
Browse files Browse the repository at this point in the history
…elects) with defaultSelectType in settings object
  • Loading branch information
wallslide committed Apr 13, 2021
1 parent 51651f0 commit 54f083f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/components/FormMode/multi-select/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<component
:is="selectType"
v-bind="{ ...$props, ...$attrs }"
v-bind="{ ...$props, ...$attrs, state }"
v-on="$listeners"
/>
</template>
Expand All @@ -16,14 +16,24 @@ const selectTypeMap = {
export default {
mixins: [widgeti18nMixin],
props: {
state: {
type: Object,
},
},
components: {
default: () => import('./multi-select'),
options: () => import('./options'),
},
computed: {
settings() {
return this.state.settings
},
selectType() {
const defaultSelectType =
this.settings.defaultSelectType || selectTypeMap.default
return selectTypeMap[
this.localeArgLookup('selectType') || selectTypeMap.default
this.localeArgLookup('selectType') || defaultSelectType
]
},
},
Expand Down
14 changes: 12 additions & 2 deletions src/components/FormMode/select/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<component
:is="selectType"
v-bind="{ ...$props, ...$attrs }"
v-bind="{ ...$props, ...$attrs, state }"
v-on="$listeners"
/>
</template>
Expand All @@ -16,14 +16,24 @@ const selectTypeMap = {
export default {
mixins: [widgeti18nMixin],
props: {
state: {
type: Object,
},
},
components: {
default: () => import('./select'),
options: () => import('./options'),
},
computed: {
settings() {
return this.state.settings
},
selectType() {
const defaultSelectType =
this.settings.defaultSelectType || selectTypeMap.default
return selectTypeMap[
this.localeArgLookup('selectType') || selectTypeMap.default
this.localeArgLookup('selectType') || defaultSelectType
]
},
},
Expand Down
11 changes: 11 additions & 0 deletions stories/Formmode.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ export default {
args: {
templateText: '',
listeners: {},
defaultSelectType: 'default',
},
argTypes: {
templateText: {
control: {
type: 'text',
},
},
defaultSelectType: {
control: {
type: 'select',
options: ['default', 'options'],
},
},
listeners: {
type: 'object',
},
Expand All @@ -40,6 +47,7 @@ const formmodeTemplate = (args) => {
this.upil.startRaw(this.templateText, {
mode: 'form',
resetOnInputUpdate: true,
defaultSelectType: this.defaultSelectType,
})
},
},
Expand All @@ -50,6 +58,9 @@ const formmodeTemplate = (args) => {
templateText() {
this.startUpil()
},
defaultSelectType() {
this.startUpil()
},
},
}
}
Expand Down

1 comment on commit 54f083f

@vercel
Copy link

@vercel vercel bot commented on 54f083f Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.