@itfin/components 1.2.101 → 1.2.102
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.
package/package.json
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
ref="input"
|
|
5
5
|
v-bind="$props"
|
|
6
6
|
@input="onValueChange"
|
|
7
|
+
@blur="onBlur"
|
|
7
8
|
/>
|
|
8
9
|
|
|
9
10
|
</template>
|
|
10
11
|
<script>
|
|
11
|
-
import { Vue, Component, Model, Inject, Prop } from 'vue-property-decorator';
|
|
12
|
+
import { Vue, Watch, Component, Model, Inject, Prop } from 'vue-property-decorator';
|
|
12
13
|
import itfTextField from './TextField.vue';
|
|
13
|
-
import {parseHours} from
|
|
14
|
+
import { parseHours, formatHours } from '../../helpers/formatters';
|
|
14
15
|
|
|
15
16
|
export default @Component({
|
|
16
17
|
name: 'itfHoursField',
|
|
@@ -24,19 +25,22 @@ class itfHoursField extends Vue {
|
|
|
24
25
|
@Prop() hours;
|
|
25
26
|
@Prop(String) prependIcon;
|
|
26
27
|
@Prop(String) placeholder;
|
|
27
|
-
@Prop() step;
|
|
28
|
-
@Prop() min;
|
|
29
|
-
@Prop() max;
|
|
30
28
|
@Prop(Boolean) clearable;
|
|
31
29
|
@Prop(Boolean) disabled;
|
|
32
30
|
@Prop(Boolean) readonly;
|
|
33
|
-
@Prop({ type: String, default: 'text' }) type;
|
|
34
31
|
@Prop({ type: [Number, String], default: 0 }) delayInput;
|
|
35
32
|
|
|
33
|
+
mounted() {
|
|
34
|
+
this.onHoursChanged();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Watch('hours')
|
|
38
|
+
onHoursChanged() {
|
|
39
|
+
console.info(formatHours(this.hours),this.hours)
|
|
40
|
+
this.$emit('input', formatHours(this.hours));
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
onValueChange(text) {
|
|
37
|
-
const hours = parseHours(text);
|
|
38
|
-
this.$emit('update:hours', hours);
|
|
39
|
-
this.$emit('input', text);
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
focus() {
|
|
@@ -46,5 +50,10 @@ class itfHoursField extends Vue {
|
|
|
46
50
|
blur() {
|
|
47
51
|
this.$refs.input.blur();
|
|
48
52
|
}
|
|
53
|
+
|
|
54
|
+
onBlur(e) {
|
|
55
|
+
const hours = parseHours(e.target.value) / 60;
|
|
56
|
+
this.$emit('update:hours', hours);
|
|
57
|
+
}
|
|
49
58
|
}
|
|
50
59
|
</script>
|
|
@@ -81,3 +81,28 @@ export function firstLetters(name) {
|
|
|
81
81
|
}
|
|
82
82
|
return ((first[0] || '') + (second[0] || '')).toUpperCase();
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
export function formatHours (val, removeEmptyMinutes = false) {
|
|
86
|
+
let hours = Math.floor(Math.abs(val) / 60);
|
|
87
|
+
let minutes = Math.abs(val) - hours * 60;
|
|
88
|
+
if (isNaN(minutes)) {
|
|
89
|
+
return '—';
|
|
90
|
+
}
|
|
91
|
+
minutes = Math.floor(minutes);
|
|
92
|
+
if (!removeEmptyMinutes) {
|
|
93
|
+
if (minutes < 10) {
|
|
94
|
+
minutes = '0' + minutes;
|
|
95
|
+
}
|
|
96
|
+
minutes = ` ${minutes}m`;
|
|
97
|
+
} else {
|
|
98
|
+
minutes = '';
|
|
99
|
+
}
|
|
100
|
+
const sign = val < 0 ? '-' : '';
|
|
101
|
+
if (!hours) {
|
|
102
|
+
return `${sign}0h${minutes}`;
|
|
103
|
+
}
|
|
104
|
+
if (hours < 10) {
|
|
105
|
+
hours = '0' + hours;
|
|
106
|
+
}
|
|
107
|
+
return `${sign}${hours}h${minutes}`;
|
|
108
|
+
}
|