@rypen-dev/shared-components 7.0.20 → 8.0.0

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.
@@ -8,74 +8,72 @@
8
8
  </span>
9
9
  </span>
10
10
  </template>
11
- <script>
12
- export default {
13
- name: 'FileUpload',
14
- props: {
15
- assetBasePath: {
16
- type: String,
17
- d0efault: '', //MERCH_ASSET_BASE_PATH
18
- },
11
+ <script setup>
12
+ import { ref, computed, onMounted } from 'vue';
19
13
 
20
- file: [Object, File],
21
- id: String,
22
- updating: {
23
- type: Boolean,
24
- default: false,
25
- },
26
- disabled: {
27
- type: Boolean,
28
- default: false,
29
- },
30
- text: {
31
- type: String,
32
- default: 'Choose a File',
33
- },
34
- showFilePath: {
35
- type: Boolean,
36
- default: false,
37
- },
38
- accept: {
39
- type: String,
40
- default: 'image/*',
41
- },
42
- cssClass: String,
14
+ const props = defineProps({
15
+ assetBasePath: {
16
+ type: String,
17
+ default: '', //MERCH_ASSET_BASE_PATH
43
18
  },
44
- data () {
45
- return {
46
- reader: null,
47
19
 
48
- internalFile: '',
49
- };
20
+ file: [Object, File],
21
+ id: String,
22
+ updating: {
23
+ type: Boolean,
24
+ default: false,
50
25
  },
51
- created: function () {
52
- if (this.file) {
53
- this.internalFile = this.assetBasePath + this.file;
54
- }
55
-
56
- this.reader = new FileReader();
57
- this.reader.addEventListener('load', this.setFile);
26
+ disabled: {
27
+ type: Boolean,
28
+ default: false,
58
29
  },
59
- methods: {
60
- uploadFile(e) {
61
- const { value, files } = e.target;
62
- if (files[0]) {
63
- this.readFile(files[0]);
64
-
65
- this.$emit('change', files[0]);
66
- }
67
- },
68
- readFile(file) {
69
- this.reader.readAsDataURL(file);
70
- },
71
- setFile() {
72
- this.internalFile = this.reader.result;
73
- },
30
+ text: {
31
+ type: String,
32
+ default: 'Choose a File',
33
+ },
34
+ showFilePath: {
35
+ type: Boolean,
36
+ default: false,
74
37
  },
75
- computed: {
76
- fullCssClass() {
77
- return (this.disabled || this.updating ? 'disabled' : '') + ' ' + (this.cssClass || '');
78
- },
38
+ accept: {
39
+ type: String,
40
+ default: 'image/*',
79
41
  },
80
- };
42
+ cssClass: String,
43
+ });
44
+ const emit = defineEmits(['change']);
45
+
46
+ const reader = ref(null);
47
+ const fileupload = ref(null);
48
+
49
+ onMounted(() => {
50
+ if (props.file) {
51
+ internalFile.value = props.assetBasePath + props.file;
52
+ }
53
+
54
+ reader.value = new FileReader();
55
+ reader.value.addEventListener('load', setFile);
56
+ });
57
+
58
+ function uploadFile(e) {
59
+ const { value, files } = e.target;
60
+ if (files[0]) {
61
+ readFile(files[0]);
62
+
63
+ // emit the file change
64
+ emit('change', files[0]);
65
+ }
66
+ }
67
+
68
+ function readFile(file) {
69
+ reader.value.readAsDataURL(file);
70
+ }
71
+
72
+ function setFile() {
73
+ internalFile.value = reader.value.result;
74
+ }
75
+
76
+ const fullCssClass = computed(() => {
77
+ return (props.disabled || props.updating ? 'disabled' : '') + ' ' + (props.cssClass || '');
78
+ });
81
79
  </script>
@@ -4,11 +4,8 @@
4
4
  </div>
5
5
  </template>
6
6
 
7
- <script>
8
- export default {
9
- name: 'GenericLoader',
10
- props: {
11
- cssClass: String,
12
- },
13
- }
7
+ <script setup>
8
+ const props = defineProps({
9
+ cssClass: String,
10
+ });
14
11
  </script>
@@ -4,15 +4,6 @@
4
4
  </div>
5
5
  </template>
6
6
 
7
- <script>
7
+ <script setup>
8
8
  import loadingImage from "../assets/rypen_logomarkreveal_100px.gif";
9
-
10
- export default {
11
- name: 'Loader',
12
- data: () => {
13
- return {
14
- loadingImage: loadingImage,
15
- }
16
- },
17
- }
18
9
  </script>
@@ -2,7 +2,7 @@
2
2
  <div class="lookup-container" :class="{ small: small }">
3
3
  <div class="input-container" :class="{ loading: loading, suggestions: suggestionsOpen, small: small, error: invalid }">
4
4
  <input v-if="useExternalValue" ref="inputforexternal" type="text" autocomplete="off" :value="externalValue" :maxlength="maxLength" @input="updateExternalValue" @focus="focusOn" @blur="focusOff" @keyup.enter="enterMethod" :disabled="disabled" />
5
- <input v-else ref="input" type="text" autocomplete="off" v-model="value" :maxlength="maxLength" @focus="focusOn" @blur="focusOff" @keyup.enter="enterMethod" :disabled="disabled" />
5
+ <input v-else ref="inputref" type="text" autocomplete="off" v-model="value" :maxlength="maxLength" @focus="focusOn" @blur="focusOff" @keyup.enter="enterMethod" :disabled="disabled" />
6
6
  <span v-if="loading" class="mini-loader"></span>
7
7
  </div>
8
8
  <div v-if="suggestionsOpen" class="lookup-suggestions">
@@ -13,121 +13,129 @@
13
13
  </div>
14
14
  </div>
15
15
  </template>
16
- <script>
16
+ <script setup>
17
+ import { ref, computed, watch } from "vue";
18
+
17
19
  import { debounce } from "@rypen-dev/helpers";
18
20
 
19
- export default {
20
- name: 'LookupTextBox',
21
- props: {
22
- loading: {
23
- type: Boolean,
24
- default: false,
25
- },
26
- suggestions: {
27
- type: Array,
28
- default: () => [],
29
- },
30
- invalid: {
31
- type: Boolean,
32
- default: false,
33
- },
34
- minimumLength: {
35
- type: Number,
36
- default: 3,
37
- },
38
- maxLength: {
39
- type: Number,
40
- default: 200,
41
- },
42
- small: {
43
- type: Boolean,
44
- default: false,
45
- },
46
- disabled: {
47
- type: Boolean,
48
- default: false,
49
- },
50
- useExternalValue: {
51
- type: Boolean,
52
- default: false,
53
- },
54
- externalValue: String,
55
- nameOnly: {
56
- type: Boolean,
57
- default: false,
58
- },
59
- searchType: {
60
- type: String,
61
- default: 'products'
62
- },
21
+ const props = defineProps({
22
+ loading: {
23
+ type: Boolean,
24
+ default: false,
25
+ },
26
+ suggestions: {
27
+ type: Array,
28
+ default: () => [],
29
+ },
30
+ invalid: {
31
+ type: Boolean,
32
+ default: false,
33
+ },
34
+ minimumLength: {
35
+ type: Number,
36
+ default: 3,
63
37
  },
64
- data: () => {
65
- return {
66
- value: '',
67
- debouncedValue: '',
68
-
69
- focused: false,
70
- };
38
+ maxLength: {
39
+ type: Number,
40
+ default: 200,
71
41
  },
72
- created: function () {
73
- this.debouncedGetSuggestions = debounce(value => {
74
- this.debouncedValue = value;
75
- this.getSuggestions();
76
- });
42
+ small: {
43
+ type: Boolean,
44
+ default: false,
77
45
  },
78
- methods: {
79
- getSuggestions() {
80
- const usedValue = this.useExternalValue ? this.externalValue : this.value;
81
- if (usedValue.length === 0 || usedValue.length >= this.minimumLength) {
82
- this.$emit('search', usedValue);
83
- }
84
- },
85
- selectSuggestion(suggestion) {
86
- let data = suggestion;
87
- if (this.nameOnly) {
88
- data = suggestion.Name;
89
- }
90
-
91
- this.$emit('select', data);
92
- },
93
-
94
- updateExternalValue(e) {
95
- this.$emit('select', e.target.value);
96
- },
97
-
98
- focusInput() {
99
- if (this.$refs.inputforexternal) {
100
- this.$refs.inputforexternal.focus();
101
- } else if (this.$refs.input) {
102
- this.$refs.input.focus();
103
- }
104
- },
105
- focusOn() {
106
- this.focused = true;
107
- },
108
- focusOff() {
109
- setTimeout(() => {
110
- this.focused = false;
111
- this.value = '';
112
- }, 200);
113
- },
114
-
115
- enterMethod() {
116
- this.$emit('enter');
117
- },
46
+ disabled: {
47
+ type: Boolean,
48
+ default: false,
118
49
  },
119
- computed: {
120
- suggestionsOpen() {
121
- return this.debouncedValue && this.debouncedValue.length >= this.minimumLength && this.focused && (!this.loading || this.suggestions.length > 0);
122
- }
50
+ useExternalValue: {
51
+ type: Boolean,
52
+ default: false,
123
53
  },
124
- watch: {
125
- value(newValue) {
126
- this.debouncedGetSuggestions(newValue);
127
- },
128
- externalValue(newValue) {
129
- this.debouncedGetSuggestions(newValue);
130
- },
54
+ externalValue: String,
55
+ nameOnly: {
56
+ type: Boolean,
57
+ default: false,
131
58
  },
59
+ searchType: {
60
+ type: String,
61
+ default: 'products'
62
+ },
63
+ });
64
+
65
+ const emit = defineEmits(['search', 'select', 'enter']);
66
+
67
+ const value = ref('');
68
+ const debouncedValue = ref('');
69
+ const focused = ref(false);
70
+
71
+ const inputref = ref(null);
72
+ const inputforexternal = ref(null);
73
+
74
+ const suggestionsOpen = computed(() => {
75
+ return debouncedValue.value && debouncedValue.value.length >= props.minimumLength && focused.value && (!props.loading || props.suggestions.length > 0);
76
+ });
77
+
78
+ const debouncedGetSuggestions = debounce((newValue) => {
79
+ debouncedValue.value = newValue;
80
+ getSuggestions();
81
+ });
82
+
83
+ function getSuggestions() {
84
+ const usedValue = props.useExternalValue ? props.externalValue : value.value;
85
+ if (usedValue.length === 0 || usedValue.length >= props.minimumLength) {
86
+ emit('search', usedValue);
87
+ }
88
+ }
89
+
90
+ function selectSuggestion(suggestion) {
91
+ let data = suggestion;
92
+ if (props.nameOnly) {
93
+ data = suggestion.Name;
94
+ }
95
+
96
+ emit('select', data);
132
97
  }
98
+
99
+ function updateExternalValue(e) {
100
+ emit('select', e.target.value);
101
+ }
102
+
103
+ function focusInput() {
104
+ if (props.useExternalValue && inputforexternal.value) {
105
+ inputforexternal.value.focus();
106
+ } else if (inputref.value) {
107
+ inputref.value.focus();
108
+ }
109
+ }
110
+
111
+ function focusOn() {
112
+ focused.value = true;
113
+ }
114
+
115
+ function focusOff() {
116
+ setTimeout(() => {
117
+ focused.value = false;
118
+ value.value = '';
119
+ }, 200);
120
+ }
121
+
122
+ function enterMethod() {
123
+ emit('enter');
124
+ }
125
+
126
+ watch(() => props.externalValue, (newValue) => {
127
+ if (props.useExternalValue) {
128
+ debouncedGetSuggestions(newValue);
129
+ }
130
+ }, { immediate: true });
131
+
132
+ watch(value, (newValue) => {
133
+ if (!props.useExternalValue) {
134
+ debouncedGetSuggestions(newValue);
135
+ }
136
+ }, { immediate: true });
137
+
138
+ defineExpose({
139
+ focusInput,
140
+ });
133
141
  </script>
@@ -23,48 +23,39 @@
23
23
  </transition>
24
24
  </template>
25
25
 
26
- <script>
26
+ <script setup>
27
27
  import IconBase from "./icons/IconBase.vue";
28
28
  import IconClose from "./icons/IconClose.vue";
29
29
 
30
- export default {
31
- name: 'ModalWrapper',
32
- props: {
33
- header: {
34
- type: String,
35
- default: ' ',
36
- },
37
- subheader: {
38
- type: String,
39
- default: '',
40
- },
41
- closeable: {
42
- type: Boolean,
43
- default: true,
44
- },
45
- cssClass: String,
46
- maskCssClass: String,
47
- },
48
- data: () => {
49
- return {
50
-
51
- }
30
+ import { computed, useSlots } from "vue";
31
+
32
+ const slots = useSlots();
33
+ const emit = defineEmits(['close']);
34
+
35
+ const props = defineProps({
36
+ header: {
37
+ type: String,
38
+ default: ' ',
52
39
  },
53
- components: {
54
- IconBase,
55
- IconClose,
40
+ subheader: {
41
+ type: String,
42
+ default: '',
56
43
  },
57
- methods: {
58
- closeIfCloseable(e) {
59
- if (this.closeable && e.target == e.currentTarget) {
60
- this.$emit('close');
61
- }
62
- }
44
+ closeable: {
45
+ type: Boolean,
46
+ default: true,
63
47
  },
64
- computed: {
65
- hasFooter() {
66
- return !!this.$slots.footer;
67
- }
48
+ cssClass: String,
49
+ maskCssClass: String,
50
+ });
51
+
52
+ const hasFooter = computed(() => {
53
+ return !!slots.footer;
54
+ });
55
+
56
+ function closeIfCloseable(e) {
57
+ if (props.closeable && e.target === e.currentTarget) {
58
+ emit('close');
68
59
  }
69
60
  }
70
61
  </script>
@@ -93,7 +93,6 @@
93
93
  }
94
94
 
95
95
  function setValue(value, inputEvent = false) {
96
- const oldValue = internalValue.value;
97
96
  let newValue = Math.round(value);
98
97
 
99
98
  if (props.min <= props.max) {
@@ -102,7 +101,7 @@
102
101
 
103
102
  internalValue.value = newValue;
104
103
 
105
- if (newValue === oldValue) {
104
+ if (inputref.value.value != newValue) {
106
105
  inputref.value.value = newValue;
107
106
  }
108
107