@imaginario27/air-ui-ds 1.0.21 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="w-full space-y-1.5"
|
|
4
|
+
>
|
|
5
|
+
<div
|
|
6
|
+
v-if="showProgressLabel && progressLabelPosition === Position.TOP"
|
|
7
|
+
:class="[
|
|
8
|
+
'text-xs text-text-neutral-subtle',
|
|
9
|
+
labelAlignmentClass,
|
|
10
|
+
progressLabelClass,
|
|
11
|
+
]"
|
|
12
|
+
>
|
|
13
|
+
{{ isIndeterminate ? loadingText : `${normalizedProgress}%` }}
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<div
|
|
17
|
+
:class="[
|
|
18
|
+
'w-full',
|
|
19
|
+
'overflow-hidden',
|
|
20
|
+
barSizeClass,
|
|
21
|
+
incompleteBackgroundColorClass,
|
|
22
|
+
isRounded && 'rounded-full',
|
|
23
|
+
'relative',
|
|
24
|
+
]"
|
|
25
|
+
>
|
|
26
|
+
<div
|
|
27
|
+
v-if="!isIndeterminate && normalizedProgress > 0"
|
|
28
|
+
:class="[
|
|
29
|
+
'h-full',
|
|
30
|
+
'transition-all',
|
|
31
|
+
'duration-300',
|
|
32
|
+
'ease-in-out',
|
|
33
|
+
isRounded && 'rounded-full',
|
|
34
|
+
completedBackgroundColorClass,
|
|
35
|
+
progressClass,
|
|
36
|
+
]"
|
|
37
|
+
:style="{ width: `${normalizedProgress}%` }"
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<div
|
|
41
|
+
v-else-if="isIndeterminate"
|
|
42
|
+
:class="[
|
|
43
|
+
'absolute top-0 left-0 h-full w-1/3',
|
|
44
|
+
'indeterminate-bar',
|
|
45
|
+
isRounded && 'rounded-full',
|
|
46
|
+
completedBackgroundColorClass,
|
|
47
|
+
progressClass,
|
|
48
|
+
]"
|
|
49
|
+
/>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<div
|
|
53
|
+
v-if="showProgressLabel && progressLabelPosition === Position.BOTTOM"
|
|
54
|
+
:class="[
|
|
55
|
+
'text-xs text-text-neutral-subtle',
|
|
56
|
+
labelAlignmentClass,
|
|
57
|
+
progressLabelClass,
|
|
58
|
+
]"
|
|
59
|
+
>
|
|
60
|
+
{{ isIndeterminate ? loadingText : `${normalizedProgress}%` }}
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
64
|
+
<script setup lang="ts">
|
|
65
|
+
// Props
|
|
66
|
+
const props = defineProps({
|
|
67
|
+
progress: {
|
|
68
|
+
type: Number as PropType<number>,
|
|
69
|
+
default: 50,
|
|
70
|
+
},
|
|
71
|
+
color: {
|
|
72
|
+
type: String as PropType<ColorAccent>,
|
|
73
|
+
default: ColorAccent.PRIMARY_BRAND,
|
|
74
|
+
validator: (value: ColorAccent) => Object.values(ColorAccent).includes(value),
|
|
75
|
+
},
|
|
76
|
+
size: {
|
|
77
|
+
type: String as PropType<ProgressBarSize>,
|
|
78
|
+
default: ProgressBarSize.SM,
|
|
79
|
+
validator: (value: ProgressBarSize) => Object.values(ProgressBarSize).includes(value),
|
|
80
|
+
},
|
|
81
|
+
isRounded: {
|
|
82
|
+
type: Boolean as PropType<boolean>,
|
|
83
|
+
default: true,
|
|
84
|
+
},
|
|
85
|
+
showProgressLabel: {
|
|
86
|
+
type: Boolean as PropType<boolean>,
|
|
87
|
+
default: false,
|
|
88
|
+
},
|
|
89
|
+
progressLabelPosition: {
|
|
90
|
+
type: String as PropType<Position>,
|
|
91
|
+
default: Position.TOP,
|
|
92
|
+
validator: (value: Position) => Object.values(Position).includes(value),
|
|
93
|
+
},
|
|
94
|
+
progressLabelAlignment: {
|
|
95
|
+
type: String as PropType<Align>,
|
|
96
|
+
default: Align.CENTER,
|
|
97
|
+
validator: (value: Align) => Object.values(Align).includes(value),
|
|
98
|
+
},
|
|
99
|
+
min: {
|
|
100
|
+
type: Number as PropType<number>,
|
|
101
|
+
default: 0,
|
|
102
|
+
},
|
|
103
|
+
max: {
|
|
104
|
+
type: Number as PropType<number>,
|
|
105
|
+
default: 100,
|
|
106
|
+
},
|
|
107
|
+
isIndeterminate: {
|
|
108
|
+
type: Boolean as PropType<boolean>,
|
|
109
|
+
default: false,
|
|
110
|
+
},
|
|
111
|
+
loadingText: {
|
|
112
|
+
type: String as PropType<string>,
|
|
113
|
+
default: 'Loading...',
|
|
114
|
+
},
|
|
115
|
+
progressClass: String as PropType<string>,
|
|
116
|
+
progressLabelClass: String as PropType<string>,
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// Computed
|
|
120
|
+
const normalizedProgress = computed(() => {
|
|
121
|
+
if (props.isIndeterminate) return 100
|
|
122
|
+
|
|
123
|
+
const clamped = Math.min(Math.max(props.progress, props.min), props.max)
|
|
124
|
+
const percent = ((clamped - props.min) / (props.max - props.min)) * 100
|
|
125
|
+
|
|
126
|
+
return Math.round(percent)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// Computed classes
|
|
130
|
+
const barSizeClass = computed(() => {
|
|
131
|
+
const variants = {
|
|
132
|
+
[ProgressBarSize.XS]: 'h-[4px]',
|
|
133
|
+
[ProgressBarSize.SM]: 'h-[8px]',
|
|
134
|
+
[ProgressBarSize.MD]: 'h-[12px]',
|
|
135
|
+
[ProgressBarSize.LG]: 'h-[16px]',
|
|
136
|
+
[ProgressBarSize.XL]: 'h-[20px]',
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return variants[props.size as ProgressBarSize] || 'h-[8px]'
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
const incompleteBackgroundColorClass = computed(() => {
|
|
143
|
+
const variants = {
|
|
144
|
+
[ColorAccent.NEUTRAL]: 'bg-background-neutral-default/10',
|
|
145
|
+
[ColorAccent.SUCCESS]: 'bg-background-success-bold/10',
|
|
146
|
+
[ColorAccent.WARNING]: 'bg-background-warning-bold/10',
|
|
147
|
+
[ColorAccent.DANGER]: 'bg-background-danger-bold/10',
|
|
148
|
+
[ColorAccent.INFO]: 'bg-background-info-bold/10',
|
|
149
|
+
[ColorAccent.PRIMARY_BRAND]: 'bg-background-primary-brand-default/10',
|
|
150
|
+
[ColorAccent.SECONDARY_BRAND]: 'bg-background-secondary-brand-default/10',
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return variants[props.color as ColorAccent] || 'bg-background-primary-brand-default/10'
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
const completedBackgroundColorClass = computed(() => {
|
|
157
|
+
const variants = {
|
|
158
|
+
[ColorAccent.NEUTRAL]: 'bg-background-neutral-default',
|
|
159
|
+
[ColorAccent.SUCCESS]: 'bg-background-success-bold',
|
|
160
|
+
[ColorAccent.WARNING]: 'bg-background-warning-bold',
|
|
161
|
+
[ColorAccent.DANGER]: 'bg-background-danger-bold',
|
|
162
|
+
[ColorAccent.INFO]: 'bg-background-info-bold',
|
|
163
|
+
[ColorAccent.PRIMARY_BRAND]: 'bg-background-primary-brand-default',
|
|
164
|
+
[ColorAccent.SECONDARY_BRAND]: 'bg-background-secondary-brand-default',
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return variants[props.color as ColorAccent] || 'bg-background-primary-brand-default'
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
const labelAlignmentClass = computed(() => {
|
|
171
|
+
const variants = {
|
|
172
|
+
[Align.LEFT]: 'text-left',
|
|
173
|
+
[Align.CENTER]: 'text-center',
|
|
174
|
+
[Align.RIGHT]: 'text-right',
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return variants[props.progressLabelAlignment as Align] || 'text-center'
|
|
178
|
+
})
|
|
179
|
+
</script>
|
|
180
|
+
|
|
181
|
+
<style scoped>
|
|
182
|
+
@keyframes indeterminate-slide {
|
|
183
|
+
0% {
|
|
184
|
+
transform: translateX(-100%);
|
|
185
|
+
}
|
|
186
|
+
100% {
|
|
187
|
+
transform: translateX(300%);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.indeterminate-bar {
|
|
192
|
+
animation: indeterminate-slide 2s ease-in-out infinite;
|
|
193
|
+
}
|
|
194
|
+
</style>
|