@rypen-dev/shared-components 7.0.17 → 7.0.18

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 6, this package is built with Webpack 5 and Vue 3.",
4
- "version": "7.0.17",
4
+ "version": "7.0.18",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
7
7
  "build": "webpack --config ./webpack.config.js",
@@ -13,7 +13,7 @@
13
13
  </div>
14
14
  </template>
15
15
  <script setup>
16
- import { onMounted, ref } from "vue";
16
+ import { ref } from "vue";
17
17
  import moment from "moment";
18
18
 
19
19
  const props = defineProps({
@@ -62,14 +62,11 @@
62
62
  }
63
63
  }
64
64
 
65
- onMounted(() => {
66
- console.log(inputref.value);
67
- });
65
+ function triggerBlur() {
66
+ inputref.value && inputref.value.blur();
67
+ }
68
68
 
69
69
  defineExpose({
70
- triggerBlur: () => {
71
- inputref.value && inputref.value.blur();
72
- console.log('blur triggered');
73
- },
70
+ triggerBlur,
74
71
  });
75
72
  </script>
@@ -4,45 +4,41 @@
4
4
  <a v-if="includeClear && value.length" class="clear-button" @click="clearInput"><i class="fa-solid fa-times"></i></a>
5
5
  </div>
6
6
  </template>
7
- <script>
7
+ <script setup>
8
+ import { onBeforeMount, watch, ref } from "vue";
9
+
8
10
  import { debounce } from "@rypen-dev/helpers";
9
11
 
10
- export default {
11
- name: 'DebouncedTextBox',
12
- props: {
13
- cssClass: String,
14
- initialValue: String,
15
- includeClear: {
16
- type: Boolean,
17
- default: false,
18
- },
19
- },
20
- data: () => {
21
- return {
22
- value: '',
23
- debouncedValue: '',
24
- };
12
+ const props = defineProps({
13
+ cssClass: String,
14
+ initialValue: String,
15
+ includeClear: {
16
+ type: Boolean,
17
+ default: false,
25
18
  },
26
- created: function() {
27
- this.debouncedAction = debounce(value => {
28
- this.debouncedValue = value;
29
- this.$emit('change', value);
30
- });
19
+ });
20
+ const emit = defineEmits(['change']);
31
21
 
32
- if (this.initialValue) {
33
- this.value = this.initialValue;
34
- }
35
- },
36
- methods: {
37
- clearInput() {
38
- this.value = '';
39
- this.debouncedAction('');
40
- },
41
- },
42
- watch: {
43
- value(newValue) {
44
- this.debouncedAction(newValue);
45
- },
46
- },
47
- };
22
+ const value = ref('');
23
+ const debouncedValue = ref('');
24
+
25
+ onBeforeMount(() => {
26
+ if (props.initialValue) {
27
+ value.value = props.initialValue;
28
+ }
29
+ });
30
+
31
+ const debouncedAction = debounce((newValue) => {
32
+ debouncedValue.value = newValue;
33
+ emit('change', newValue);
34
+ });
35
+
36
+ function clearInput() {
37
+ value.value = '';
38
+ emit('change', '');
39
+ }
40
+
41
+ watch(value, (newValue) => {
42
+ debouncedAction(newValue);
43
+ });
48
44
  </script>
@@ -1,143 +1,141 @@
1
1
  <template>
2
2
  <input type="number"
3
- :value="internalValue"
4
- :placeholder="placeholder"
5
- :disabled="disabled"
6
- :pattern="pattern"
7
- inputmode="numeric"
8
- ref="input"
9
- @keydown.up.prevent="increment"
10
- @keydown.down.prevent="decrement"
11
- @keydown.enter="triggerChange"
12
- @change="change"
13
- @paste="paste"
14
- @blur="blur"
15
- @focus="focus"
16
- />
3
+ :value="internalValue"
4
+ :placeholder="placeholder"
5
+ :disabled="disabled"
6
+ :pattern="pattern"
7
+ inputmode="numeric"
8
+ ref="inputref"
9
+ @keydown.up.prevent="increment"
10
+ @keydown.down.prevent="decrement"
11
+ @keydown.enter="triggerChange"
12
+ @change="change"
13
+ @paste="paste"
14
+ @blur="blur"
15
+ @focus="focus" />
17
16
  </template>
18
- <script>
17
+ <script setup>
18
+ import { ref, watch } from "vue";
19
+
19
20
  const REGEXP_NUMBER = /^-?(?:\d+|\d+\.\d+|\.\d+)(?:[eE][-+]?\d+)?$/;
20
21
 
21
- export default {
22
- name: 'NumberInput',
23
- props: {
24
- value: {
25
- type: Number,
26
- },
27
- min: {
28
- type: Number,
29
- default: 0,
30
- },
31
- max: {
32
- type: Number,
33
- default: Infinity,
34
- },
35
- step: {
36
- type: Number,
37
- default: 1,
38
- },
39
- placeholder: String,
40
- disabled: {
41
- type: Boolean,
42
- default: false,
43
- },
44
- pattern: {
45
- type: String,
46
- default: '[0-9]*', // this allows ONLY NUMBERS
47
- },
48
- selectOnFocus: {
49
- type: Boolean,
50
- default: false,
51
- },
22
+ const props = defineProps({
23
+ initialValue: Number,
24
+ min: {
25
+ type: Number,
26
+ default: 0,
52
27
  },
53
- data () {
54
- return {
55
- internalValue: this.value,
56
- };
28
+ max: {
29
+ type: Number,
30
+ default: Infinity,
57
31
  },
58
- created: function () {
59
-
32
+ step: {
33
+ type: Number,
34
+ default: 1,
60
35
  },
61
- methods: {
62
- triggerChange(e) {
63
- this.change(e);
64
- },
65
- change(e) {
66
- this.setValue(e.target.value);
67
- },
68
- blur(e) {
69
- let val = this.between(this.min, e.target.value, this.max);
70
- if (this.value !== val) {
71
- this.setValue(e.target.value);
72
- }
73
- },
74
- focus(e) {
75
- if (this.selectOnFocus) {
76
- this.$refs.input.select();
77
- }
78
- },
79
- paste(e) {
80
- const clipboardData = e.clipboardData || window.clipboardData;
81
- if (clipboardData && !REGEXP_NUMBER.test(clipboardData.getData('text'))) {
82
- e.preventDefault();
83
- }
84
- },
85
- between(min, val, max) {
86
- if (min <= max) {
87
- return Math.min(max, Math.max(min, val));
88
- }
89
-
90
- return val;
91
- },
92
- setValue(value) {
93
- const oldValue = this.internalValue;
94
- let newValue = Math.round(value);
95
-
96
- if (this.min <= this.max) {
97
- newValue = this.between(this.min, newValue, this.max);
98
- }
99
-
100
- this.internalValue = newValue;
101
-
102
- if (newValue === oldValue) {
103
- this.$refs.input.value = newValue;
104
- }
105
-
106
- this.$emit('change', newValue, oldValue);
107
- },
108
-
109
- crement(up = true) {
110
- let step = this.step;
111
- if (!up) {
112
- step = -step;
113
- }
114
-
115
- this.internalValue += step;
116
- },
117
- increment(e) {
118
- if (this.internalValue < this.max) {
119
- this.crement();
120
- }
121
- },
122
- decrement(e) {
123
- if (this.internalValue > this.min) {
124
- this.crement(false);
125
- }
126
- },
36
+ placeholder: String,
37
+ disabled: {
38
+ type: Boolean,
39
+ default: false,
127
40
  },
128
- computed: {
129
-
41
+ pattern: {
42
+ type: String,
43
+ default: '[0-9]*', // this allows ONLY NUMBERS
130
44
  },
131
- watch: {
132
- value: {
133
- immediate: true,
134
- handler(value) {
135
- value = parseInt(value);
136
- if (!isNaN(value) && value !== this.internalValue) {
137
- this.setValue(value);
138
- }
139
- }
140
- }
45
+ selectOnFocus: {
46
+ type: Boolean,
47
+ default: false,
141
48
  },
142
- };
49
+ });
50
+
51
+ const emit = defineEmits(['change']);
52
+
53
+ const inputref = ref(null);
54
+
55
+ const internalValue = ref(props.initialValue);
56
+
57
+ // methods
58
+ function triggerChange(e) {
59
+ change(e);
60
+ }
61
+
62
+ function change(e) {
63
+ setValue(e.target.value);
64
+ }
65
+
66
+ function blur(e) {
67
+ let val = between(props.min, e.target.value, props.max);
68
+ if (internalValue.value !== val) {
69
+ setValue(e.target.value);
70
+ }
71
+ }
72
+
73
+ function focus(e) {
74
+ if (props.selectOnFocus) {
75
+ e.target.select();
76
+ }
77
+ }
78
+
79
+ function paste(e) {
80
+ const clipboardData = e.clipboardData || window.clipboardData;
81
+ if (clipboardData && !REGEXP_NUMBER.test(clipboardData.getData('text'))) {
82
+ e.preventDefault();
83
+ }
84
+ }
85
+
86
+ function between(min, val, max) {
87
+ if (min <= max) {
88
+ return Math.min(max, Math.max(min, val));
89
+ }
90
+ return val;
91
+ }
92
+
93
+ function setValue(value) {
94
+ const oldValue = internalValue.value;
95
+ let newValue = Math.round(value);
96
+
97
+ if (props.min <= props.max) {
98
+ newValue = between(props.min, newValue, props.max);
99
+ }
100
+
101
+ internalValue.value = newValue;
102
+
103
+ if (newValue === oldValue) {
104
+ inputref.value.value = newValue;
105
+ }
106
+
107
+ emit('change', newValue, oldValue);
108
+ }
109
+
110
+ function crement(up = true) {
111
+ let step = props.step;
112
+ if (!up) {
113
+ step = -step;
114
+ }
115
+
116
+ internalValue.value += step;
117
+ }
118
+
119
+ function increment(e) {
120
+ if (internalValue.value < props.max) {
121
+ crement();
122
+ }
123
+ }
124
+
125
+ function decrement(e) {
126
+ if (internalValue.value > props.min) {
127
+ crement(false);
128
+ }
129
+ }
130
+
131
+ watch(() => props.initialValue, (newValue) => {
132
+ const value = parseInt(newValue);
133
+ if (!isNaN(value) && value !== internalValue.value) {
134
+ setValue(value);
135
+ }
136
+ });
137
+
138
+ defineExpose({
139
+ triggerChange,
140
+ });
143
141
  </script>
@@ -7,22 +7,11 @@
7
7
  </svg>
8
8
  </template>
9
9
 
10
- <script>
11
- export default {
12
- name: 'SuccessCheckmark',
13
- props: {
14
- on: {
15
- type: Boolean,
16
- default: false,
17
- },
10
+ <script setup>
11
+ const props = defineProps({
12
+ on: {
13
+ type: Boolean,
14
+ default: false,
18
15
  },
19
- data: () => {
20
- return {
21
-
22
- }
23
- },
24
- created: function () {
25
-
26
- },
27
- }
16
+ });
28
17
  </script>
@@ -4,44 +4,36 @@
4
4
  <label :for="id" class="switch-paddle" :data-true-label="trueLabel" :data-false-label="falseLabel"></label>
5
5
  </div>
6
6
  </template>
7
- <script>
8
- export default {
9
- name: 'SwitchInput',
10
- props: {
11
- value: {
12
- type: Boolean,
13
- },
14
- disabled: {
15
- type: Boolean,
16
- default: false,
17
- },
18
- trueLabel: {
19
- type: String,
20
- default: 'Yes',
21
- },
22
- falseLabel: {
23
- type: String,
24
- default: 'No',
25
- },
26
- id: String,
27
- cssClass: String,
7
+ <script setup>
8
+ import { ref } from "vue";
9
+
10
+ const props = defineProps({
11
+ value: {
12
+ type: Boolean,
13
+ default: false,
28
14
  },
29
- data () {
30
- return {
31
- internalValue: false,
32
- };
15
+ disabled: {
16
+ type: Boolean,
17
+ default: false,
33
18
  },
34
- created: function () {
35
- this.internalValue = this.value;
19
+ trueLabel: {
20
+ type: String,
21
+ default: 'Yes',
36
22
  },
37
- methods: {
38
- change() {
39
- this.internalValue = !this.internalValue;
40
- this.$emit('change', this.internalValue);
41
- },
23
+ falseLabel: {
24
+ type: String,
25
+ default: 'No',
42
26
  },
43
- computed: {
44
-
45
- },
46
- };
27
+ id: String,
28
+ cssClass: String,
29
+ });
30
+
31
+ const internalValue = ref(props.value);
32
+
33
+ const emit = defineEmits(['change']);
34
+
35
+ function change() {
36
+ internalValue.value = !internalValue.value;
37
+ emit('change', internalValue.value);
38
+ }
47
39
  </script>