-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add enum type for stars component #147
- Loading branch information
Showing
2 changed files
with
31 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,55 @@ | ||
<script lang="ts"> | ||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' | ||
import type { PropType } from 'nuxt/dist/app/compat/capi' | ||
import { defineNuxtComponent } from '#app' | ||
enum StarsEnum { | ||
One = '1', | ||
OneS = '1S', | ||
Two = '2', | ||
TwoS = '2S', | ||
Three = '3', | ||
ThreeS = '3S', | ||
Four = '4', | ||
FourS = '4S', | ||
Five = '5', | ||
FiveS = '5S', | ||
} | ||
export default defineNuxtComponent({ | ||
components: { | ||
FontAwesomeIcon, | ||
}, | ||
props: { | ||
stars: { | ||
type: Number, | ||
type: String as PropType<StarsEnum>, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
isSNotation(): boolean { | ||
return Boolean(this.stars.includes('S')) | ||
}, | ||
numericProp(): number { | ||
let stars: string = this.stars | ||
if (this.isSNotation) | ||
stars = this.stars.slice(0, -1) | ||
return Number(stars) | ||
}, | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="stars-data tw-text-amber-500 tw-mb-1"> | ||
<FontAwesomeIcon | ||
v-for="index in stars" | ||
v-for="(_item, index) in numericProp" | ||
:key="index" | ||
icon="star" | ||
/> | ||
{{ isSNotation ? 'S' : '' }} | ||
</div> | ||
</template> |
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