Skip to content

Commit d4690c9

Browse files
committed
Improvement - VueUiKpi - Add formatters
1 parent af2c3f6 commit d4690c9

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

TestingArena/ArenaVueUiKpi.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ function updateVal() {
1212
dataset.value = Math.random() * 10000
1313
}
1414
15+
const config = ref({
16+
formatter: ({ value }) => {
17+
return `f | ${value}`
18+
}
19+
})
20+
1521
1622
</script>
1723

@@ -24,16 +30,16 @@ function updateVal() {
2430
<template #title>VueUiKpi</template>
2531

2632
<template #local>
27-
<LocalVueUiKpi :dataset="dataset"/>
33+
<LocalVueUiKpi :dataset="dataset" :config="config"/>
2834
</template>
2935
<template #VDUI-local>
30-
<LocalVueDataUi component="VueUiKpi" :dataset="dataset"/>
36+
<LocalVueDataUi component="VueUiKpi" :dataset="dataset" :config="config"/>
3137
</template>
3238
<template #build>
33-
<VueUiKpi :dataset="dataset"/>
39+
<VueUiKpi :dataset="dataset" :config="config"/>
3440
</template>
3541
<template #VDUI-build>
36-
<VueDataUi component="VueUiKpi" :dataset="dataset"/>
42+
<VueDataUi component="VueUiKpi" :dataset="dataset" :config="config"/>
3743
</template>
3844
</Box>
3945
</template>

src/components/vue-ui-kpi.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup>
22
import { ref, computed, onMounted, watch } from "vue";
33
import { useNestedProp } from "../useNestedProp";
4-
import { dataLabel } from "../lib";
4+
import { applyDataLabel, dataLabel } from "../lib";
55
import { useConfig } from "../useConfig";
66
77
const { vue_ui_kpi: DEFAULT_CONFIG } = useConfig();
@@ -76,7 +76,16 @@ watch(() => props.dataset, (newValue) => {
7676
<slot name="comment-before" :comment="dataset"></slot>
7777
<div :class="`vue-ui-kpi-value ${FINAL_CONFIG.valueClass}`" :style="`font-family: ${FINAL_CONFIG.fontFamily}; font-size:${FINAL_CONFIG.valueFontSize}px; color:${FINAL_CONFIG.valueColor}; font-weight:${FINAL_CONFIG.valueBold ? 'bold': 'normal'}; ${FINAL_CONFIG.valueCss}`">
7878
<slot name="value" :comment="dataset"></slot>
79-
{{ dataLabel({ p: FINAL_CONFIG.prefix, v: displayedValue, s: FINAL_CONFIG.suffix, r: FINAL_CONFIG.valueRounding }) }}
79+
{{ applyDataLabel(
80+
FINAL_CONFIG.formatter,
81+
displayedValue,
82+
dataLabel({
83+
p: FINAL_CONFIG.prefix,
84+
v: displayedValue,
85+
s: FINAL_CONFIG.suffix,
86+
r: FINAL_CONFIG.valueRounding
87+
}))
88+
}}
8089
</div>
8190
<slot name="comment-after" :comment="dataset"></slot>
8291
</div>

src/useConfig.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3792,7 +3792,8 @@ export function useConfig() {
37923792
valueClass: '',
37933793
valueCss: '',
37943794
valueFontSize: FONT._32,
3795-
valueRounding: 0
3795+
valueRounding: 0,
3796+
formatter: null
37963797
}
37973798

37983799
const vue_ui_mini_loader = {

types/vue-data-ui.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ declare module 'vue-data-ui' {
249249
valueCss?: string;
250250
valueFontSize?: number;
251251
valueRounding?: number;
252+
formatter?: null;
252253
}
253254

254255
export const VueUiKpi: DefineComponent<{

0 commit comments

Comments
 (0)