pet_data/components/pixel/PixelProgressBar.vue

122 lines
2.3 KiB
Vue
Raw Normal View History

2025-11-25 10:04:01 +00:00
<template>
<div class="pixel-progress-bar">
<div class="progress-label" v-if="label">{{ label }}</div>
<div class="progress-container">
<div
class="progress-fill"
:class="[colorClass, { striped }]"
:style="{ width: `${clampedValue}%` }"
>
<div v-if="striped" class="stripes"></div>
</div>
</div>
<div class="progress-value" v-if="showValue">
{{ current !== null ? `${Math.round(current)}/${max}` : `${Math.round(clampedValue)}%` }}
</div>
</div>
</template>
<script setup>
const props = defineProps({
value: {
type: Number,
required: true
},
max: {
type: Number,
default: 100
},
current: {
type: Number,
default: null
},
label: {
type: String,
default: ''
},
color: {
type: String,
default: 'primary', // 'primary', 'success', 'danger', 'warning'
validator: (value) => ['primary', 'success', 'danger', 'warning'].includes(value)
},
striped: {
type: Boolean,
default: false
},
showValue: {
type: Boolean,
default: true
}
})
const clampedValue = computed(() => {
if (props.current !== null) {
return Math.min(100, Math.max(0, (props.current / props.max) * 100))
}
return Math.min(100, Math.max(0, props.value))
})
const colorClass = computed(() => `color-${props.color}`)
</script>
<style scoped>
.pixel-progress-bar {
display: flex;
align-items: center;
gap: 8px;
font-size: 10px;
}
.progress-label {
min-width: 80px;
font-weight: bold;
}
.progress-container {
flex: 1;
height: 24px;
background: #ddd;
border: 3px solid #000;
position: relative;
overflow: hidden;
}
.progress-fill {
height: 100%;
transition: width 0.3s ease;
position: relative;
}
.progress-fill.color-primary {
background: var(--color-primary);
}
.progress-fill.color-success {
background: var(--color-success);
}
.progress-fill.color-danger {
background: var(--color-danger);
}
.progress-fill.color-warning {
background: var(--color-warning);
}
.progress-fill.striped {
background-image: repeating-linear-gradient(
45deg,
transparent,
transparent 10px,
rgba(0, 0, 0, 0.1) 10px,
rgba(0, 0, 0, 0.1) 20px
);
}
.progress-value {
min-width: 70px;
text-align: right;
font-weight: bold;
}
</style>