Skip to content

Commit 09cb87c

Browse files
committed
add a form to customize the example of Value Display
1 parent 15de79b commit 09cb87c

File tree

1 file changed

+99
-12
lines changed

1 file changed

+99
-12
lines changed

src/topper/extra/value_display/index.md

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,40 @@
22
title: Value Display
33
---
44

5+
<script setup>
6+
import { ref } from 'vue';
7+
8+
const decimalFormData = ref({
9+
decimalSeparator: '.',
10+
groupingSeparator: ',',
11+
groupingSize: '3',
12+
maximumFractionDigits: '2',
13+
});
14+
15+
const timeFormData = ref({
16+
pattern: 'HH:mm:ss',
17+
type: 'duration',
18+
unit: 'seconds',
19+
});
20+
21+
const shortenFormData = ref({
22+
customGroups: [],
23+
});
24+
</script>
25+
526
# Value Display
627

728
Some places like [`{value}` in `line`](/topper/extra/provider/#default-values) and [the `value` and
8-
`top_value` queries](/topper/query/) can be expanded to format the value in a more readable way. This is done by
29+
`top_value` queries](/topper/query/#types) allows you to apply a format to display the value in a more readable way. This is done by
930
specifying some settings for them like:
1031

11-
- `{value_<format>}`
12-
- `<holder>;value;<format>`
13-
- `<holder>;top_value;<position>;<format>`
32+
```
33+
{value_<format>}
34+
<holder>;value;<format>
35+
<holder>;top_value;<position>;<format>
36+
```
1437

15-
The following section will guide you through the available formats to replace `<format>`, we will use the
16-
`<holder>;value;<format>` query as an example.
38+
The following section will guide you through the available formats to replace `<format>`.
1739

1840
## Available Formats
1941

@@ -28,7 +50,24 @@ The following section will guide you through the available formats to replace `<
2850
| `groupingSize` | The number of digits in each group to the left of the decimal separator | | `groupingSize=3` |
2951
| `maximumFractionDigits` | The maximum number of digits allowed in the fractional part of the number | | `maximumFractionDigits=2` |
3052

31-
Example: `jump;value;decimal:decimalSeparator=,&groupingSeparator=.&groupingSize=3&maximumFractionDigits=2`
53+
#### Example
54+
55+
```-vue
56+
{value_decimal:{{ ['decimalSeparator=' + decimalFormData.decimalSeparator, decimalFormData.groupingSeparator ? 'groupingSeparator=' + decimalFormData.groupingSeparator : '', decimalFormData.groupingSize ? 'groupingSize=' + decimalFormData.groupingSize : '', decimalFormData.maximumFractionDigits ? 'maximumFractionDigits=' + decimalFormData.maximumFractionDigits : ''].filter(Boolean).join('&') }}}
57+
<holder>;value;decimal:{{ ['decimalSeparator=' + decimalFormData.decimalSeparator, decimalFormData.groupingSeparator ? 'groupingSeparator=' + decimalFormData.groupingSeparator : '', decimalFormData.groupingSize ? 'groupingSize=' + decimalFormData.groupingSize : '', decimalFormData.maximumFractionDigits ? 'maximumFractionDigits=' + decimalFormData.maximumFractionDigits : ''].filter(Boolean).join('&') }}
58+
<holder>;top_value;<position>;decimal:{{ ['decimalSeparator=' + decimalFormData.decimalSeparator, decimalFormData.groupingSeparator ? 'groupingSeparator=' + decimalFormData.groupingSeparator : '', decimalFormData.groupingSize ? 'groupingSize=' + decimalFormData.groupingSize : '', decimalFormData.maximumFractionDigits ? 'maximumFractionDigits=' + decimalFormData.maximumFractionDigits : ''].filter(Boolean).join('&') }}
59+
```
60+
61+
::: details Click me to edit the settings
62+
63+
<Vueform v-model="decimalFormData" sync>
64+
<TextElement name="decimalSeparator" label="Decimal Separator" description="The character used to separate the integer part from the fractional part" />
65+
<TextElement name="groupingSeparator" label="Grouping Separator" description="The character used to separate groups of digits (leave empty to disable)" />
66+
<TextElement name="groupingSize" label="Grouping Size" input-type="number" description="The number of digits in each group" />
67+
<TextElement name="maximumFractionDigits" label="Maximum Fraction Digits" input-type="number" description="The maximum number of digits in the fractional part (leave empty for unlimited)" />
68+
</Vueform>
69+
70+
:::
3271

3372
### Time Format
3473

@@ -40,7 +79,37 @@ Example: `jump;value;decimal:decimalSeparator=,&groupingSeparator=.&groupingSize
4079
| `type` | The type of the time: `duration` or `time` | `duration` | `type=duration` |
4180
| `unit` | The unit of the time: `ticks`, `nanoseconds`, `microseconds`, `milliseconds`, `seconds`, `minutes`, `hours`, `days` | `seconds` | `unit=seconds` |
4281

43-
Example: `playtime;value;time:pattern=HH:mm:ss&type=duration&unit=ticks`
82+
#### Example
83+
84+
```-vue
85+
{value_time:pattern={{ timeFormData.pattern }}&type={{ timeFormData.type }}&unit={{ timeFormData.unit }}}
86+
<holder>;value;time:pattern={{ timeFormData.pattern }}&type={{ timeFormData.type }}&unit={{ timeFormData.unit }}
87+
<holder>;top_value;<position>;time:pattern={{ timeFormData.pattern }}&type={{ timeFormData.type }}&unit={{ timeFormData.unit }}
88+
```
89+
90+
::: details Click me to edit the settings
91+
92+
<Vueform v-model="timeFormData" sync>
93+
<TextElement name="pattern" label="Pattern" description="The pattern describing the date and time format" />
94+
<SelectElement
95+
name="type"
96+
label="Type"
97+
:native="false"
98+
:items="['duration', 'time']"
99+
:canClear="false"
100+
description="The type of the time: duration or time"
101+
/>
102+
<SelectElement
103+
name="unit"
104+
label="Unit"
105+
:native="false"
106+
:items="['ticks', 'nanoseconds', 'microseconds', 'milliseconds', 'seconds', 'minutes', 'hours', 'days']"
107+
:canClear="false"
108+
description="The unit of the time"
109+
/>
110+
</Vueform>
111+
112+
:::
44113

45114
#### Short Form
46115

@@ -62,7 +131,7 @@ on the `type`:
62131

63132
### Shorten
64133

65-
> Format: `shorten`
134+
> Format: `shorten` or `shorten:number1=suffix1&number2=suffix2`
66135
67136
This is a format that shorten the number to the nearest "number group" (e.g. `1000` will be `1k`)
68137

@@ -80,7 +149,25 @@ For example: `shorten:1000=k&100000=hk&1000000=m` would shorten the number based
80149
- `100,000` to `1hk`
81150
- `1,000,000` to `1m`
82151

83-
Example:
152+
#### Example
153+
154+
```-vue
155+
{value_shorten{{ shortenFormData.customGroups.filter(g => g && g.number && g.suffix).length > 0 ? ':' + shortenFormData.customGroups.filter(g => g && g.number && g.suffix).map(g => g.number + '=' + g.suffix).join('&') : '' }}}
156+
<holder>;value;shorten{{ shortenFormData.customGroups.filter(g => g && g.number && g.suffix).length > 0 ? ':' + shortenFormData.customGroups.filter(g => g && g.number && g.suffix).map(g => g.number + '=' + g.suffix).join('&') : '' }}
157+
<holder>;top_value;<position>;shorten{{ shortenFormData.customGroups.filter(g => g && g.number && g.suffix).length > 0 ? ':' + shortenFormData.customGroups.filter(g => g && g.number && g.suffix).map(g => g.number + '=' + g.suffix).join('&') : '' }}
158+
```
159+
160+
::: details Click me to edit the custom groups
161+
162+
<Vueform v-model="shortenFormData" sync>
163+
<ListElement name="customGroups" label="Custom Groups" description="Define custom number and suffix pairs (leave empty to use default groups)">
164+
<template #default="{ index }">
165+
<ObjectElement :name="index" label="Group">
166+
<TextElement name="number" placeholder="Number (e.g., 1000)" />
167+
<TextElement name="suffix" placeholder="Suffix (e.g., k)" />
168+
</ObjectElement>
169+
</template>
170+
</ListElement>
171+
</Vueform>
84172

85-
- `money:value:shorten`
86-
- `money:value:shorten:1000=k&100000=hk&1000000=m`
173+
:::

0 commit comments

Comments
 (0)