Skip to content

Commit

Permalink
fix(modalcomp): remove hard coded swtich with computed property (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-larks authored Apr 29, 2024
1 parent a0bb854 commit f2ee497
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 61 deletions.
75 changes: 16 additions & 59 deletions src/components/ModalComp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ Vue.use(VModal);
ModalRedirect,
ModalConfirmation,
ModalPrime,
ModalPrimeIntro
}
ModalPrimeIntro,
},
})
export default class ModalComp extends Vue {
@Prop()
Expand All @@ -133,7 +133,18 @@ export default class ModalComp extends Vue {
@Prop()
scrollable!: boolean;
@Prop()
@Prop({
required: true,
validator: (v: string) =>
[
"basic",
"subscribe",
"redirect",
"confirmation",
"welcome-prime",
"prime-intro",
].includes(v),
})
type!: string;
@Prop()
Expand Down Expand Up @@ -187,62 +198,8 @@ export default class ModalComp extends Vue {
@Prop()
clickToClose!: boolean;
modalName: string = "";
mounted() {
this.selectName();
}
selectName() {
switch (this.type) {
case "basic":
if (this.name) {
this.modalName = this.name;
} else {
this.modalName = "modal-basic";
}
break;
case "subscribe":
if (this.name) {
this.modalName = this.name;
} else {
this.modalName = "modal-subscribe";
}
break;
case "redirect":
if (this.name) {
this.modalName = this.name;
} else {
this.modalName = "modal-redirect";
}
break;
case "confirmation":
if (this.name) {
this.modalName = this.name;
} else {
this.modalName = "modal-confirmation";
}
break;
case "welcome-prime":
if (this.name) {
this.modalName = this.name;
} else {
this.modalName = "modal-welcome-prime";
}
break;
case "prime-intro":
if (this.name) {
this.modalName = this.name;
} else {
this.modalName = "modal-prime-intro";
}
break;
}
get modalName() {
return this.name || `modal-${this.type}`;
}
}
</script>
4 changes: 2 additions & 2 deletions src/demos/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ import ModalsCode from "./Modals.vue?raw";
components: {
Button,
DemoSection,
ModalComp
}
ModalComp,
},
})
export default class Modals extends Vue {
demoCode = ModalsCode;
Expand Down

0 comments on commit f2ee497

Please sign in to comment.