refactor: clean up progress button; emit click event

This commit is contained in:
pskfyi 2022-01-10 02:15:49 -08:00 committed by pskfyi
parent 57f1e64575
commit 8c61da296d
1 changed files with 16 additions and 7 deletions

View File

@ -1,27 +1,34 @@
<template> <template>
<button <button
class="relative flex flex-col pt-2 pb-3 px-3 border rounded-lg overflow-hidden" class="relative flex flex-col pt-2 pb-3 px-3 border rounded-lg overflow-hidden border-current"
:class="[colorClasses, clickable ? 'cursor-pointer' : 'cursor-default']" :class="[colorClasses, clickable ? 'cursor-pointer' : 'cursor-default']"
:disable="!clickable" :disable="!clickable"
@click="$emit('click')"
> >
<progress <progress
v-if="!clickable" v-if="!clickable"
class="absolute top-0 left-0 right-0 h-1 w-full" class="absolute top-0 left-0 right-0 h-1 w-full"
:max="max" :max="max"
:value="value" :value="cappedValue"
/> />
<span class="absolute top-3 right-3 font-semibold text-sm"> <span class="absolute top-3 right-3 font-semibold text-sm">
{{ value }} / {{ max }} {{ cappedValue }} / {{ max }}
<span class="fas fa-hourglass-half" /> <span class="fas fa-hourglass-half" />
</span> </span>
<span <span
class="w-full text-left lg:text-center text-lg md:text-xl font-semibold" class="w-full text-left lg:text-center text-lg lg:text-xl font-semibold"
v-text="label" v-text="label"
/> />
<p class="w-full text-left" v-text="description" /> <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>
</button> </button>
</template> </template>
@ -35,8 +42,13 @@ export default {
max: { type: Number, required: true }, max: { type: Number, required: true },
value: { type: [Number, Decimal], required: true }, value: { type: [Number, Decimal], required: true },
unit: { type: String, default: null }, unit: { type: String, default: null },
current: { type: String, default: null },
next: { type: String, default: null },
}, },
computed: { computed: {
cappedValue() {
return this.value > this.max ? this.max : this.value
},
clickable() { clickable() {
return this.value >= this.max return this.value >= this.max
}, },
@ -52,9 +64,6 @@ export default {
</script> </script>
<style scoped> <style scoped>
button {
border-color: currentColor;
}
/* progress background for all browsers */ /* progress background for all browsers */
progress::-webkit-progress-bar { progress::-webkit-progress-bar {
background-color: rgba(0, 0, 0, 0.1); background-color: rgba(0, 0, 0, 0.1);