Skip to content

Commit 40c5b90

Browse files
authored
Merge pull request #54 from devforth/afcl
add progress bar to afcl
2 parents 00081d0 + 00c57f2 commit 40c5b90

File tree

9 files changed

+102
-4
lines changed

9 files changed

+102
-4
lines changed

adminforth/documentation/docs/tutorial/03-Customization/14-afcl.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,47 @@ If there is less then `pageSize` rows, pagination will not be shown.
531531
</div>
532532

533533

534+
## ProgressBar
535+
536+
<div class="split-screen" >
537+
<div>
538+
```html
539+
<ProgressBar
540+
:currentValue="2600"
541+
:minValue="0"
542+
:maxValue="5000"
543+
/>
544+
```
545+
</div>
546+
<div>
547+
![ProgressBar](image-81.png)
548+
</div>
549+
</div>
550+
551+
### Custom labels
552+
553+
Custom labels in the ProgressBar component allow you to customize the text displayed on the left and right sides of the progress bar. You can also customize the format of the value and the progress text.
554+
555+
<div class="split-screen" >
556+
<div>
557+
```html
558+
<ProgressBar
559+
:currentValue="1070"
560+
:minValue="0"
561+
:maxValue="5000"
562+
:leftLabel="'Level 2'"
563+
:rightLabel="'Level 3'"
564+
:formatter="(value: number) => `${value} points`"
565+
:progressFormatter="(value: number, percentage: number) => `${value} done`"
566+
/>
567+
```
568+
</div>
569+
<div>
570+
![ProgressBar](image-80.png)
571+
</div>
572+
</div>
573+
574+
534575
## Bar Chart
535576

536577
Under the hood AdminForth uses MIT-licensed [ApexCharts](https://apexcharts.com/). It has very rich variety of options, you can pass
6.64 KB
Loading
4.93 KB
Loading
10.7 KB
Loading
4.2 KB
Loading

adminforth/plugins/foreign-inline-list/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/plugins/foreign-inline-list/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adminforth/foreign-inline-list",
3-
"version": "1.0.26",
3+
"version": "1.0.27",
44
"description": "AdminForth plugin for adding list of children items to the parent item show page",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<template>
2+
<div class="relative mt-4 lg:mt-10 w-full max-w-[700px] bg-gray-200 rounded-full h-2.5 dark:bg-gray-700">
3+
<span class="absolute -top-6 left-0 text-sm text-gray-500">{{ leftLabel }}</span>
4+
<span class="absolute -top-6 right-0 text-sm text-gray-500">{{ rightLabel }}</span>
5+
<div
6+
class="bg-lightPrimary dark:bg-darkPrimary h-2.5 rounded-full"
7+
:style="{ width: `${percentage}%` }"
8+
></div>
9+
<template v-if="showValues">
10+
<span class="absolute top-4 left-0 text-sm text-gray-500">{{ formatValue(minValue) }}</span>
11+
<span v-if="showProgress" class="absolute top-4 right-1/2 translate-x-1/2 text-sm text-gray-500">{{ progressText }}</span>
12+
<span class="absolute top-4 right-0 text-sm text-gray-500">{{ formatValue(maxValue) }}</span>
13+
</template>
14+
</div>
15+
</template>
16+
17+
<script setup lang="ts">
18+
import { computed } from 'vue'
19+
20+
interface Props {
21+
currentValue: number
22+
minValue?: number
23+
maxValue?: number
24+
leftLabel?: string
25+
rightLabel?: string
26+
formatter?: (value: number) => string
27+
progressFormatter?: (value: number, percentage: number) => string
28+
showLabels?: boolean
29+
showValues: boolean
30+
showProgress: boolean
31+
}
32+
33+
const props = withDefaults(defineProps<Props>(), {
34+
minValue: 0,
35+
maxValue: 100,
36+
formatter: (value: number) => `${value}`,
37+
progressFormatter: (value: number, percentage: number) => `${value}`,
38+
showValues: true,
39+
showProgress: true
40+
})
41+
42+
const percentage = computed((): number => {
43+
const min = props.minValue
44+
const max = props.maxValue
45+
return Math.round(((props.currentValue - min) / (max - min)) * 100)
46+
})
47+
48+
const progressText = computed((): string => {
49+
const formatter = props.progressFormatter
50+
return formatter(props.currentValue, percentage.value)
51+
})
52+
53+
const formatValue = (value: number): string => {
54+
const formatter = props.formatter
55+
return formatter(value)
56+
}
57+
</script>

adminforth/spa/src/afcl/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export { default as AreaChart } from './AreaChart.vue';
1313
export { default as BarChart } from './BarChart.vue';
1414
export { default as PieChart } from './PieChart.vue';
1515
export { default as Table } from './Table.vue';
16-
16+
export { default as ProgressBar } from './ProgressBar.vue';
1717

1818

0 commit comments

Comments
 (0)