@@ -22,7 +22,7 @@ type TemperatureScale = 'kelvin' | 'celsius' | 'fahrenheit' | 'rankine' | 'delis
22
22
const units = reactive <
23
23
Record <
24
24
string | TemperatureScale ,
25
- { title : string ; unit : string ; ref : number ; toKelvin : (v : number ) => number ; fromKelvin : (v : number ) => number }
25
+ { title : string ; unit : string ; ref : number ; toKelvin : (v : number ) => number ; fromKelvin : (v : number ) => number ; min ?: number ; max ?: number ; maxLimit ?: boolean }
26
26
>
27
27
> ({
28
28
kelvin: {
@@ -59,6 +59,7 @@ const units = reactive<
59
59
ref: 0 ,
60
60
toKelvin: convertDelisleToKelvin ,
61
61
fromKelvin: convertKelvinToDelisle ,
62
+ maxLimit: true ,
62
63
},
63
64
newton: {
64
65
title: ' Newton' ,
@@ -86,7 +87,9 @@ const units = reactive<
86
87
function update(key : TemperatureScale ) {
87
88
const { ref : value, toKelvin } = units [key ];
88
89
89
- const kelvins = toKelvin (value ) ?? 0 ;
90
+ let kelvins = toKelvin (value ) ?? 0 ;
91
+
92
+ kelvins = kelvins < 0 ? 0 : kelvins ;
90
93
91
94
_ .chain (units )
92
95
.omit (key )
@@ -96,6 +99,18 @@ function update(key: TemperatureScale) {
96
99
.value ();
97
100
}
98
101
102
+ function setupLimit() {
103
+ _ .forEach (units , (unit ) => {
104
+ if (unit .maxLimit ) {
105
+ unit .max = Math .ceil (unit .fromKelvin (0 ) * 100 ) / 100 ;
106
+ }
107
+ else {
108
+ unit .min = Math .floor (unit .fromKelvin (0 ) * 100 ) / 100 ;
109
+ }
110
+ });
111
+ }
112
+
113
+ setupLimit ();
99
114
update (' kelvin' );
100
115
</script >
101
116
@@ -109,6 +124,8 @@ update('kelvin');
109
124
<n-input-number
110
125
v-model:value =" units[key].ref"
111
126
style =" flex : 1 "
127
+ :min =" units[key].min"
128
+ :max =" units[key].max"
112
129
@update:value =" () => update(key as TemperatureScale)"
113
130
/>
114
131
0 commit comments