@rypen-dev/shared-components 8.0.12 → 8.0.14

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@rypen-dev/shared-components",
3
3
  "description": "Shared styles and Vuejs ui components for Rypen projects. Starting with version 8, this package is built with Vite 7 and Vue 3.",
4
- "version": "8.0.12",
4
+ "version": "8.0.14",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "scripts": {
@@ -6,9 +6,7 @@
6
6
  :pattern="pattern"
7
7
  inputmode="numeric"
8
8
  ref="inputref"
9
- @keydown.up.prevent="increment"
10
- @keydown.down.prevent="decrement"
11
- @keydown.enter="change"
9
+ @keydown="checkKey"
12
10
  @input="updateValue"
13
11
  @blur="change"
14
12
  @focus="focus"
@@ -46,6 +44,10 @@
46
44
  type: Boolean,
47
45
  default: false,
48
46
  },
47
+ enforceNumbersOnly: {
48
+ type: Boolean,
49
+ default: true,
50
+ },
49
51
  emitOnInput: {
50
52
  type: Boolean,
51
53
  default: false,
@@ -85,6 +87,20 @@
85
87
  }
86
88
  }
87
89
 
90
+ function checkKey(e) {
91
+ const { key } = e;
92
+
93
+ if (key === 'ArrowUp') {
94
+ increment();
95
+ } else if (key === 'ArrowDown') {
96
+ decrement();
97
+ } else if (key === 'Enter') {
98
+ inputref.value.blur();
99
+ } else if (props.enforceNumbersOnly && key.length === 1 && !e.ctrlKey && !e.shiftKey && isNaN(key)) {
100
+ e.preventDefault();
101
+ }
102
+ }
103
+
88
104
  function between(min, val, max) {
89
105
  if (min <= max) {
90
106
  return Math.min(max, Math.max(min, val));
@@ -1,23 +1,23 @@
1
1
  <template>
2
2
  <div class="timespan">
3
3
  <div class="input-container">
4
- <input type="number" :min="0" :max="9999" @change="updateValue" :value="daysValue" />
4
+ <number-input :value="daysValue" @change="updateValue" :min="0" :max="9999" />
5
5
  </div>
6
6
  <div class="input-container select">
7
7
  <select :value="selectedInterval" @change="updateTimeInterval">
8
8
  <option :value="TIMESPAN_INTERVALS.DAYS">Days</option>
9
9
  <option :value="TIMESPAN_INTERVALS.WEEKS">Weeks</option>
10
- <option :value="TIMESPAN_INTERVALS.MONTHS">Months</option>
11
10
  <option :value="TIMESPAN_INTERVALS.YEARS">Years</option>
12
11
  </select>
13
12
  </div>
14
13
  </div>
15
14
  </template>
16
15
  <script setup>
16
+ import NumberInput from './NumberInput.vue';
17
+
17
18
  const TIMESPAN_INTERVALS = {
18
19
  DAYS: 'DAYS',
19
20
  WEEKS: 'WEEKS',
20
- MONTHS: 'MONTHS',
21
21
  YEARS: 'YEARS',
22
22
  };
23
23
 
@@ -32,7 +32,7 @@
32
32
  });
33
33
  const emit = defineEmits(['update']);
34
34
 
35
- const value = ref('');
35
+ const daysValue = ref(0);
36
36
  const selectedInterval = ref(TIMESPAN_INTERVALS.DAYS);
37
37
 
38
38
  onMounted(() => {
@@ -61,23 +61,26 @@
61
61
  let newValue = value;
62
62
  let newInterval = selectedInterval.value;
63
63
 
64
- if (value && !isNaN(value)) {
65
- if (selectedInterval.value === TIMESPAN_INTERVALS.DAYS) {
66
- if (newValue % 365 === 0) {
67
- newValue = newValue / 365;
68
- newInterval = TIMESPAN_INTERVALS.YEARS;
69
- } else if (newValue % 7 === 0) {
70
- newValue = newValue / 7;
71
- newInterval = TIMESPAN_INTERVALS.WEEKS;
72
- }
73
- } else if (selectedInterval.value === TIMESPAN_INTERVALS.MONTHS) {
74
- if (value % 12 === 0) {
75
- newValue = value / 12;
76
- newInterval = TIMESPAN_INTERVALS.YEARS;
64
+ if (!isNaN(value)) {
65
+ if (value > 0) {
66
+ if (selectedInterval.value === TIMESPAN_INTERVALS.DAYS) {
67
+ if (newValue % 365 === 0) {
68
+ newValue = newValue / 365;
69
+ newInterval = TIMESPAN_INTERVALS.YEARS;
70
+ } else if (newValue % 7 === 0) {
71
+ newValue = newValue / 7;
72
+ newInterval = TIMESPAN_INTERVALS.WEEKS;
73
+ }
74
+ } else if (selectedInterval.value === TIMESPAN_INTERVALS.WEEKS) {
75
+ if (value % 52 === 0) {
76
+ newValue = value / 52;
77
+ newInterval = TIMESPAN_INTERVALS.YEARS;
78
+ }
77
79
  }
78
80
  }
81
+
79
82
  } else {
80
- newValue = '';
83
+ newValue = props.initialValue;
81
84
  newInterval = TIMESPAN_INTERVALS.DAYS;
82
85
  }
83
86