diff options
Diffstat (limited to 'components/Ranking')
-rw-r--r-- | components/Ranking/RankingEntry.vue | 52 | ||||
-rw-r--r-- | components/Ranking/RankingFirstEntry.vue | 49 | ||||
-rw-r--r-- | components/Ranking/RankingList.vue | 56 |
3 files changed, 157 insertions, 0 deletions
diff --git a/components/Ranking/RankingEntry.vue b/components/Ranking/RankingEntry.vue new file mode 100644 index 0000000..e10cf8d --- /dev/null +++ b/components/Ranking/RankingEntry.vue @@ -0,0 +1,52 @@ +<template> + <li class="ranking-entry"> + <div class="ranking-entry__troop">{{ troop }}</div> + <div class="ranking-entry__points">{{ points }}</div> + </li> +</template> + +<script> +export default { + name: 'RankingEntry', + props: { + troop: { + type: String, + required: true + }, + points: { + type: Number, + required: true + } + } +} +</script> + +<style scoped> +.ranking-entry { + width: 100%; + list-style: none; + + margin: 5px; + padding: 10px 20px; + + border: 2px solid #efefef; + + display: grid; + grid-template-columns: 0% 75% 25%; + + font-size: 20px; +} + +.ranking-entry div { + display: inline-block; +} + +.ranking-entry__troop { + text-align: left; + grid-column: 2; +} + +.ranking-entry__points { + grid-column: 3; +} +</style> diff --git a/components/Ranking/RankingFirstEntry.vue b/components/Ranking/RankingFirstEntry.vue new file mode 100644 index 0000000..b7142ae --- /dev/null +++ b/components/Ranking/RankingFirstEntry.vue @@ -0,0 +1,49 @@ +<template> + <li class="ranking-first-entry"> + <img class="crown" src="/assets/crown.svg" /> + <div class="ranking-first-entry__troop">{{ troop }}</div> + <div class="ranking-first-entry__points">{{ points }}</div> + </li> +</template> + +<script> +export default { + name: 'RankingFirstEntry', + props: { + troop: { + type: String, + required: true + }, + points: { + type: Number, + required: true + } + } +} +</script> + +<style scoped> +.ranking-first-entry { + list-style: none; + padding: 10px 20px; + display: grid; + + width: 150%; + grid-template-columns: 15% 60% 25%; + box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.25); + + font-size: 26px; +} + +.crown { + margin: auto; +} + +.ranking-first-entry__troop { + grid-column: 2; +} + +.ranking-first-entry__points { + grid-column: 3; +} +</style> diff --git a/components/Ranking/RankingList.vue b/components/Ranking/RankingList.vue new file mode 100644 index 0000000..68fdb16 --- /dev/null +++ b/components/Ranking/RankingList.vue @@ -0,0 +1,56 @@ +<template> + <ol class="ranking-list"> + <ranking-first-entry + :troop="sortedScores[0].troop" + :points="sortedScores[0].points" + /> + <ranking-entry + v-for="score in sortedScores.slice(1)" + :key="score.troop" + :troop="score.troop" + :points="score.points" + /> + </ol> +</template> + +<script> +import RankingFirstEntry from './RankingFirstEntry' +import RankingEntry from './RankingEntry' + +function compare(a, b) { + return b.points - a.points +} + +export default { + name: 'RankingList', + components: { + RankingEntry, + RankingFirstEntry + }, + props: { + scores: { + type: Array, //i.e. [{troop: "Troop 1", points: 12}, {troop: "Troop 2", points: 22}] + required: true + } + }, + computed: { + sortedScores() { + return [...this.scores].sort(compare) + } + } +} +</script> + +<style scoped> +.ranking-list { + display: flex; + flex-direction: column; + align-items: center; + margin: 10px; + padding: 0; + padding-inline-start: 0; + + width: 100%; + max-width: 200px; +} +</style> |