@itfin/components 1.2.100 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itfin/components",
3
- "version": "1.2.100",
3
+ "version": "1.2.102",
4
4
  "author": "Vitalii Savchuk <esvit666@gmail.com>",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -0,0 +1,59 @@
1
+ <template>
2
+
3
+ <itf-text-field
4
+ ref="input"
5
+ v-bind="$props"
6
+ @input="onValueChange"
7
+ @blur="onBlur"
8
+ />
9
+
10
+ </template>
11
+ <script>
12
+ import { Vue, Watch, Component, Model, Inject, Prop } from 'vue-property-decorator';
13
+ import itfTextField from './TextField.vue';
14
+ import { parseHours, formatHours } from '../../helpers/formatters';
15
+
16
+ export default @Component({
17
+ name: 'itfHoursField',
18
+ components: {
19
+ itfTextField
20
+ }
21
+ })
22
+ class itfHoursField extends Vue {
23
+ @Inject({ default: null }) itemLabel;
24
+ @Model('input') value;
25
+ @Prop() hours;
26
+ @Prop(String) prependIcon;
27
+ @Prop(String) placeholder;
28
+ @Prop(Boolean) clearable;
29
+ @Prop(Boolean) disabled;
30
+ @Prop(Boolean) readonly;
31
+ @Prop({ type: [Number, String], default: 0 }) delayInput;
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
+
43
+ onValueChange(text) {
44
+ }
45
+
46
+ focus() {
47
+ this.$refs.input.focus();
48
+ }
49
+
50
+ blur() {
51
+ this.$refs.input.blur();
52
+ }
53
+
54
+ onBlur(e) {
55
+ const hours = parseHours(e.target.value) / 60;
56
+ this.$emit('update:hours', hours);
57
+ }
58
+ }
59
+ </script>
@@ -1,5 +1,6 @@
1
1
  import { storiesOf } from '@storybook/vue';
2
2
  import itfMoneyField from './MoneyField.vue';
3
+ import itfHoursField from './HoursField.vue';
3
4
  import itfForm from '../form/Form.vue';
4
5
  import itfButton from '../button/Button.vue';
5
6
  import itfIcon from '../icon/Icon.vue';
@@ -14,7 +15,8 @@ storiesOf('Common', module)
14
15
  itfForm,
15
16
  itfButton,
16
17
  itfLabel,
17
- itfMoneyField
18
+ itfMoneyField,
19
+ itfHoursField
18
20
  },
19
21
  data() {
20
22
  return {
@@ -25,6 +27,8 @@ storiesOf('Common', module)
25
27
  { Id: 4, Symbol: 'ERO', Code: 'EUR', Title: 'Euroooo' },
26
28
  { Id: 3, Symbol: ".د.ب", Code: 'AED', Title: 'Emirati Dirham' },
27
29
  ],
30
+ hoursStr: '10h 10m',
31
+ hours: 0,
28
32
  currency: null
29
33
  }
30
34
  },
@@ -43,11 +47,12 @@ storiesOf('Common', module)
43
47
 
44
48
  <itf-app ref="app">
45
49
 
46
- {{value}}
47
- {{currency}}
50
+ {{hours}}
48
51
 
49
52
  <itf-money-field v-model="value" :currencies="currencies" :currency.sync="currency" />
50
53
 
54
+ <itf-hours-field v-model="hoursStr" :hours.sync="hours" />
55
+
51
56
  </itf-app>
52
57
  </div>`,
53
58
  }));
@@ -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
+ }