mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
refactor: make SwitchToggle component reusable
This commit is contained in:
parent
8e8a72e262
commit
13e12f7ccf
2 changed files with 32 additions and 16 deletions
|
|
@ -11,7 +11,7 @@
|
||||||
:class="{'selected-label': selected}"
|
:class="{'selected-label': selected}"
|
||||||
for="toggle-on"
|
for="toggle-on"
|
||||||
class="inline-block py-1 rounded-l-full border-t-2 border-r border-b-2 border-l-2 border-teal-500 cursor-pointer"
|
class="inline-block py-1 rounded-l-full border-t-2 border-r border-b-2 border-l-2 border-teal-500 cursor-pointer"
|
||||||
>%</label>
|
>{{ leftLabel }}</label>
|
||||||
<input
|
<input
|
||||||
v-model="selected"
|
v-model="selected"
|
||||||
id="toggle-off"
|
id="toggle-off"
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
:class="{'selected-label': !selected}"
|
:class="{'selected-label': !selected}"
|
||||||
for="toggle-off"
|
for="toggle-off"
|
||||||
class="inline-block py-1 rounded-r-full border-t-2 border-r-2 border-b-2 border-l border-teal-500 cursor-pointer"
|
class="inline-block py-1 rounded-r-full border-t-2 border-r-2 border-b-2 border-l border-teal-500 cursor-pointer"
|
||||||
>Total</label>
|
>{{ rightLabel }}</label>
|
||||||
<div
|
<div
|
||||||
:class="selected ? 'left-checked' : 'right-checked'"
|
:class="selected ? 'left-checked' : 'right-checked'"
|
||||||
class="selector absolute w-1/2 inset-0 bg-teal-500"
|
class="selector absolute w-1/2 inset-0 bg-teal-500"
|
||||||
|
|
@ -32,26 +32,31 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapActions, mapState } from 'vuex'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
props: {
|
||||||
|
leftLabel: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
rightLabel: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
selected: {
|
selected: {
|
||||||
get() {
|
get() {
|
||||||
return this.percentSettings
|
return this.value
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
this.updatePercent(value)
|
this.$emit('updateValue', value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
...mapState({
|
|
||||||
percentSettings: state => state.settings.percent
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
|
||||||
...mapActions('settings', ['updatePercent']),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,13 @@
|
||||||
|
|
||||||
<div class="px-3 py-2 flex justify-between items-start">
|
<div class="px-3 py-2 flex justify-between items-start">
|
||||||
<DetailedMatchGlobalStats :team="allyTeam" :ally-team="true" />
|
<DetailedMatchGlobalStats :team="allyTeam" :ally-team="true" />
|
||||||
<SwitchToggle class="mt-2"></SwitchToggle>
|
<SwitchToggle
|
||||||
|
@updateValue="updatePercent"
|
||||||
|
left-label="%"
|
||||||
|
right-label="Total"
|
||||||
|
:value="percentSettings"
|
||||||
|
class="mt-2"
|
||||||
|
></SwitchToggle>
|
||||||
<DetailedMatchGlobalStats :team="enemyTeam" :ally-team="false" />
|
<DetailedMatchGlobalStats :team="enemyTeam" :ally-team="false" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -26,7 +32,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapState } from 'vuex'
|
import { mapActions, mapState } from 'vuex'
|
||||||
import DetailedMatchGlobalStats from '@/components/Match/DetailedMatchGlobalStats.vue'
|
import DetailedMatchGlobalStats from '@/components/Match/DetailedMatchGlobalStats.vue'
|
||||||
import DetailedMatchTeam from '@/components/Match/DetailedMatchTeam.vue'
|
import DetailedMatchTeam from '@/components/Match/DetailedMatchTeam.vue'
|
||||||
import SwitchToggle from '@/components/Form/SwitchToggle.vue'
|
import SwitchToggle from '@/components/Form/SwitchToggle.vue'
|
||||||
|
|
@ -56,8 +62,13 @@ export default {
|
||||||
return this.data.blueTeam.players.some(p => p.summonerId === this.account.id) ? this.data.redTeam : this.data.blueTeam
|
return this.data.blueTeam.players.some(p => p.summonerId === this.account.id) ? this.data.redTeam : this.data.blueTeam
|
||||||
},
|
},
|
||||||
...mapState({
|
...mapState({
|
||||||
account: state => state.summoner.basic.account
|
account: state => state.summoner.basic.account,
|
||||||
|
percentSettings: state => state.settings.percent
|
||||||
}),
|
}),
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
...mapActions('settings', ['updatePercent']),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue