This repository has been archived on 2024-03-13. You can view files and clone it, but cannot push or open issues or pull requests.
timekeeper/components/ProgressButton.vue

118 lines
3.1 KiB
Vue
Raw Normal View History

2022-01-08 03:46:33 +00:00
<template>
<button
class="relative flex flex-col pt-2 pb-3 px-3 border rounded-lg overflow-hidden border-current"
:class="[
colorClasses,
{
disabled,
[`text-${$store.getters.activeTab.darkColor}`]: disabled,
'cursor-pointer': clickable,
'cursor-default': !clickable,
},
]"
2022-01-08 03:46:33 +00:00
:disable="!clickable"
@click="clickable && $emit('click')"
2022-01-08 03:46:33 +00:00
>
<progress
v-if="!clickable"
class="absolute top-0 left-0 right-0 h-1 w-full"
:class="{ hidden: disabled }"
2022-01-08 03:46:33 +00:00
:max="max"
:value="cappedValue"
2022-01-08 03:46:33 +00:00
/>
<span
class="absolute top-3 right-3 font-semibold text-sm"
:class="{ hidden: disabled }"
>
<span v-if="unit === 'apprenticeLevels'">L</span>{{ cappedValueText }}
/
<span v-if="unit === 'apprenticeLevels'">L</span>{{ maxText }}
<span v-if="unit === 'spareTime'" class="fas fa-hourglass-half" />
<span v-if="unit === 'energy'" class="fas fa-bolt" />
2022-01-08 03:46:33 +00:00
</span>
<span
class="w-full text-left text-lg lg:text-xl font-semibold"
2022-01-08 03:46:33 +00:00
v-text="label"
/>
<p class="w-full text-left" v-text="description" />
<div v-if="current && next" class="text-sm m-auto">
<span>Current: {{ current }}</span>
<span class="fas fa-arrow-right mx-2" />
<span>Next: {{ next }}</span>
</div>
2022-01-08 03:46:33 +00:00
</button>
</template>
<script>
2022-01-10 07:12:41 +00:00
import Decimal from 'break_infinity.js'
2022-01-08 03:46:33 +00:00
export default {
props: {
label: { type: String, required: true },
description: { type: String, default: null },
max: { type: Number, required: true },
2022-01-10 07:12:41 +00:00
value: { type: [Number, Decimal], required: true },
unit: { type: String, default: 'spareTime' },
current: { type: [Number, String], default: null },
next: { type: [Number, String], default: null },
disabled: { type: Boolean, default: false },
2022-01-08 03:46:33 +00:00
},
computed: {
cappedValue() {
return this.value > this.max ? this.max : this.value
},
cappedValueText() {
return this.unit === 'maxAge'
? this.$store.getters.ageText
2022-01-14 01:28:19 +00:00
: this.$store.getters.suffixedDecimalText(this.cappedValue)
},
maxText() {
2022-01-14 01:28:19 +00:00
return this.unit === 'maxAge'
? this.$store.getters.ageMaxText
: this.$store.getters.suffixedDecimalText(this.max)
},
2022-01-08 03:46:33 +00:00
clickable() {
return !this.disabled && this.value >= this.max
2022-01-08 03:46:33 +00:00
},
colorClasses() {
const { lightColor, darkColor } = this.$store.getters.activeTab
return this.clickable
? `bg-${darkColor} text-${lightColor}`
: `bg-${lightColor} text-${darkColor}`
},
},
}
</script>
<style scoped>
.disabled {
background-color: rgba(0, 0, 0, 0.1);
}
.clickable {
box-shadow: 0px 4px 8px -3px var(--dark-color);
}
2022-01-08 03:46:33 +00:00
/* progress background for all browsers */
progress::-webkit-progress-bar {
background-color: rgba(0, 0, 0, 0.1);
width: 100%;
}
progress {
background-color: rgba(0, 0, 0, 0.1);
}
/* progress value for all browsers */
progress::-webkit-progress-value {
background-color: currentColor;
}
progress::-moz-progress-bar {
background-color: currentColor;
}
progress {
color: currentColor;
}
</style>