@casinogate/ui 1.10.13 → 1.10.15
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.
|
@@ -15,13 +15,21 @@
|
|
|
15
15
|
max = Infinity,
|
|
16
16
|
step = 1,
|
|
17
17
|
allowFloat = false,
|
|
18
|
+
precision = 2,
|
|
18
19
|
class: className,
|
|
19
20
|
containerClass,
|
|
21
|
+
disabled,
|
|
20
22
|
...restProps
|
|
21
23
|
}: NumberInputProps = $props();
|
|
22
24
|
|
|
23
25
|
const onlyNumberPattern = $derived(allowFloat ? /^\d*\.?\d*$/ : /^\d*$/);
|
|
24
26
|
|
|
27
|
+
const roundToPrecision = (num: number): number => {
|
|
28
|
+
if (!allowFloat || precision == null) return num;
|
|
29
|
+
const factor = Math.pow(10, precision);
|
|
30
|
+
return Math.round(num * factor) / factor;
|
|
31
|
+
};
|
|
32
|
+
|
|
25
33
|
let internalValue = $state(value?.toString() ?? '');
|
|
26
34
|
|
|
27
35
|
$effect(() => {
|
|
@@ -55,6 +63,15 @@
|
|
|
55
63
|
if (vNum > max) return;
|
|
56
64
|
if (vNum < min) return;
|
|
57
65
|
|
|
66
|
+
const rounded = roundToPrecision(vNum);
|
|
67
|
+
|
|
68
|
+
if (rounded !== vNum) {
|
|
69
|
+
const roundedStr = rounded.toString();
|
|
70
|
+
internalValue = roundedStr;
|
|
71
|
+
value = rounded;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
58
75
|
internalValue = v;
|
|
59
76
|
value = vNum;
|
|
60
77
|
}
|
|
@@ -63,7 +80,7 @@
|
|
|
63
80
|
const onPlusClick = () => {
|
|
64
81
|
const currentVal = internalValue ? parseFloat(internalValue) : 0;
|
|
65
82
|
const base = Number.isNaN(currentVal) ? 0 : currentVal;
|
|
66
|
-
const newValue = base + step;
|
|
83
|
+
const newValue = roundToPrecision(base + step);
|
|
67
84
|
if (newValue > max) return;
|
|
68
85
|
internalValueBox.current = newValue.toString();
|
|
69
86
|
};
|
|
@@ -71,7 +88,7 @@
|
|
|
71
88
|
const onMinusClick = () => {
|
|
72
89
|
const currentVal = internalValue ? parseFloat(internalValue) : 0;
|
|
73
90
|
const base = Number.isNaN(currentVal) ? 0 : currentVal;
|
|
74
|
-
const newValue = base - step;
|
|
91
|
+
const newValue = roundToPrecision(base - step);
|
|
75
92
|
if (newValue < min) return;
|
|
76
93
|
internalValueBox.current = newValue.toString();
|
|
77
94
|
};
|
|
@@ -85,11 +102,17 @@
|
|
|
85
102
|
class="cgui:border cgui:w-9 cgui:border-r-0 cgui:border-stroke-default cgui:text-fg-dark cgui:bg-surface-lightest"
|
|
86
103
|
size="clean"
|
|
87
104
|
onclick={onMinusClick}
|
|
105
|
+
{disabled}
|
|
88
106
|
>
|
|
89
107
|
<Icon.Minus width={16} height={16} />
|
|
90
108
|
</Button>
|
|
91
109
|
|
|
92
|
-
<Input
|
|
110
|
+
<Input
|
|
111
|
+
bind:value={internalValueBox.current}
|
|
112
|
+
class={cn('cgui:border-r cgui:border-l!', className)}
|
|
113
|
+
{disabled}
|
|
114
|
+
{...restProps}
|
|
115
|
+
/>
|
|
93
116
|
|
|
94
117
|
<Button
|
|
95
118
|
type="button"
|
|
@@ -98,6 +121,7 @@
|
|
|
98
121
|
class="cgui:border cgui:w-9 cgui:border-stroke-default cgui:text-fg-dark cgui:bg-surface-lightest"
|
|
99
122
|
size="clean"
|
|
100
123
|
onclick={onPlusClick}
|
|
124
|
+
{disabled}
|
|
101
125
|
>
|
|
102
126
|
<Icon.Plus width={16} height={16} />
|
|
103
127
|
</Button>
|