@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.
@@ -29,107 +29,105 @@
29
29
  </ul>
30
30
  </nav>
31
31
  </template>
32
- <script>
33
- export default {
34
- name: 'Pagination',
35
- props: {
36
- pageIndex: Number,
37
- totalPages: Number,
38
- maxVisiblePages: {
39
- type: Number,
40
- default: 7,
41
- },
42
- hasPreviousPage: {
43
- type: Boolean,
44
- default: false,
45
- },
46
- hasNextPage: {
47
- type: Boolean,
48
- default: false,
49
- },
50
- loading: {
51
- type: Boolean,
52
- default: false,
53
- },
32
+ <script setup>
33
+ import { reactive, ref, watch } from 'vue';
34
+
35
+ const props = defineProps({
36
+ pageIndex: {
37
+ type: Number,
38
+ default: 0,
54
39
  },
55
- data: () => {
56
- return {
57
- initialPageset: [],
58
- showInitialEllipse: false,
59
- mainPageset: [],
60
- subsequentPageset: [],
61
- showSubsequentEllipse: false,
62
- };
40
+ totalPages: {
41
+ type: Number,
42
+ default: 0,
63
43
  },
64
- created: function () {
65
-
44
+ maxVisiblePages: {
45
+ type: Number,
46
+ default: 7,
66
47
  },
67
- methods: {
68
- navigateToNext() {
69
- if (this.hasNextPage) {
70
- this.navigateToPage(this.pageIndex + 1);
71
- }
72
- },
73
- navigateToPrev() {
74
- if (this.hasPreviousPage) {
75
- this.navigateToPage(this.pageIndex - 1);
76
- }
77
- },
78
- navigateToPage(page) {
79
- if (page !== this.pageIndex) {
80
- this.$emit('navigate', page);
81
- this.$emit('top');
82
- }
83
- },
48
+ hasPreviousPage: {
49
+ type: Boolean,
50
+ default: false,
51
+ },
52
+ hasNextPage: {
53
+ type: Boolean,
54
+ default: false,
55
+ },
56
+ loading: {
57
+ type: Boolean,
58
+ default: false,
59
+ },
60
+ });
61
+
62
+ const emit = defineEmits(['navigate', 'top']);
84
63
 
85
- recalculateVisiblePages() {
86
- this.initialPageset.splice(0);
87
- this.showInitialEllipse = false;
88
- this.mainPageset.splice(0);
89
- this.showSubsequentEllipse = false;
90
- this.subsequentPageset.splice(0);
64
+ const initialPageset = reactive([]);
65
+ const showInitialEllipse = ref(false);
66
+ const mainPageset = reactive([]);
67
+ const subsequentPageset = reactive([]);
68
+ const showSubsequentEllipse = ref(false);
91
69
 
92
- if (this.totalPages > 0) {
93
- if (this.totalPages > this.maxVisiblePages) {
94
- let start = 0;
95
- const middle = Math.floor(this.maxVisiblePages / 2);
70
+ function navigateToNext() {
71
+ if (props.hasNextPage) {
72
+ navigateToPage(props.pageIndex + 1);
73
+ }
74
+ }
96
75
 
97
- if (this.pageIndex > (this.totalPages - middle - 1)) {
98
- start = this.totalPages - this.maxVisiblePages;
99
- } else if (this.pageIndex > middle) {
100
- start = this.pageIndex - middle;
101
- }
76
+ function navigateToPrev() {
77
+ if (props.hasPreviousPage) {
78
+ navigateToPage(props.pageIndex - 1);
79
+ }
80
+ }
102
81
 
103
- if (start > 0) {
104
- this.initialPageset.push(0);
105
- this.showInitialEllipse = true;
106
- }
82
+ function navigateToPage(page) {
83
+ if (page !== props.pageIndex) {
84
+ emit('navigate', page);
85
+ emit('top');
86
+ }
87
+ }
107
88
 
108
- for (let i = start; i < (start + this.maxVisiblePages); i++) {
109
- this.mainPageset.push(i);
110
- }
89
+ function recalculateVisiblePages() {
90
+ initialPageset.splice(0);
91
+ showInitialEllipse.value = false;
92
+ mainPageset.splice(0);
93
+ showSubsequentEllipse.value = false;
94
+ subsequentPageset.splice(0);
111
95
 
112
- if (start < this.totalPages - this.maxVisiblePages) {
113
- this.showSubsequentEllipse = true;
114
- this.subsequentPageset.push(this.totalPages - 1);
115
- }
116
- } else {
117
- for (let i = 0; i < this.totalPages; i++) {
118
- this.mainPageset.push(i);
119
- }
120
- }
96
+ if (props.totalPages > 0) {
97
+ if (props.totalPages > props.maxVisiblePages) {
98
+ let start = 0;
99
+ const middle = Math.floor(props.maxVisiblePages / 2);
100
+
101
+ if (props.pageIndex > (props.totalPages - middle - 1)) {
102
+ start = props.totalPages - props.maxVisiblePages;
103
+ } else if (props.pageIndex > middle) {
104
+ start = props.pageIndex - middle;
121
105
  }
122
- },
123
- },
124
- computed: {
125
-
126
- },
127
- watch: {
128
- loading(value, prev) {
129
- if (!value && prev) {
130
- this.recalculateVisiblePages();
106
+
107
+ if (start > 0) {
108
+ initialPageset.push(0);
109
+ showInitialEllipse.value = true;
131
110
  }
132
- },
133
- },
134
- };
111
+
112
+ for (let i = start; i < (start + props.maxVisiblePages); i++) {
113
+ mainPageset.push(i);
114
+ }
115
+
116
+ if (start < props.totalPages - props.maxVisiblePages) {
117
+ showSubsequentEllipse.value = true;
118
+ subsequentPageset.push(props.totalPages - 1);
119
+ }
120
+ } else {
121
+ for (let i = 0; i < props.totalPages; i++) {
122
+ mainPageset.push(i);
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ watch(() => props.loading, (newValue, oldValue) => {
129
+ if (!newValue && oldValue) {
130
+ recalculateVisiblePages();
131
+ }
132
+ });
135
133
  </script>
@@ -26,154 +26,153 @@
26
26
  </nav>
27
27
  </div>
28
28
  </template>
29
- <script>
29
+ <script setup>
30
30
  import IconBase from "./icons/IconBase.vue";
31
31
  import IconCaret from "./icons/IconCaret.vue";
32
32
 
33
- export default {
34
- name: 'ProductImageSelector',
35
- props: {
36
- imageBasePath: {
37
- type: String,
38
- default: '', //IMAGE_BASE_PATH
39
- },
40
-
41
- product: Object,
42
- variant: Object,
43
- hasVariants: {
44
- type: Boolean,
45
- default: true,
46
- },
47
- selectedImage: String,
48
- disabled: {
49
- type: Boolean,
50
- default: false,
51
- },
52
- showEmpty: {
53
- type: Boolean,
54
- default: false,
55
- },
56
- usePathPrefix: {
57
- type: Boolean,
58
- default: true,
59
- },
60
- forceNav: {
61
- type: Boolean,
62
- default: false,
63
- },
33
+ import { ref, computed } from 'vue';
34
+
35
+ const props = defineProps({
36
+ imageBasePath: {
37
+ type: String,
38
+ default: '', //IMAGE_BASE_PATH
64
39
  },
65
- data: () => {
66
- return {
67
- error: null,
68
40
 
69
- carouselIndex: 0,
70
- maxImagesShown: 6,
71
- }
41
+ product: Object,
42
+ variant: Object,
43
+ hasVariants: {
44
+ type: Boolean,
45
+ default: true,
72
46
  },
73
- created: function () {
74
-
47
+ selectedImage: String,
48
+ disabled: {
49
+ type: Boolean,
50
+ default: false,
75
51
  },
76
- methods: {
77
- imageSelected(item) {
78
- const pathCompare = this.selectedImage.replace(this.imageBasePath, '');
79
-
80
- return pathCompare === item.ImageUrl;
81
- },
82
-
83
- selectImage(item) {
84
- if (!this.disabled) {
85
- this.$emit('update', item);
86
- }
87
- },
88
- selectVariantImage() {
89
- if (!this.disabled) {
90
- if (this.variant) {
91
- this.$emit('update', this.variant);
92
- } else {
93
- this.$emit('update', this.product.PrimaryImage);
94
- }
95
- }
96
- },
97
- imagePath(item) {
98
- if (item && item.ImageUrl) {
99
- return this.imageBasePath + item.ImageUrl + ';width=100;height=100';
100
- }
101
-
102
- return null;
103
- },
104
-
105
- previous() {
106
- this.moveCarousel(-1);
107
- },
108
- next() {
109
- this.moveCarousel(1);
110
- },
111
- moveCarousel(number) {
112
- let newIndex = this.carouselIndex + number;
113
- if (newIndex < 0) {
114
- newIndex = 0;
115
- } else if (newIndex > this.carouselSlideCount) {
116
- newIndex = this.carouselSlideCount;
117
- }
118
-
119
- this.carouselIndex = newIndex;
120
- },
52
+ showEmpty: {
53
+ type: Boolean,
54
+ default: false,
121
55
  },
122
- computed: {
123
- nonVariantImageCount() {
124
- return this.product ? (this.product.AdditionalImages.length + this.product.LifeStyleImages.length) : 0;
125
- },
126
- totalImageCount() {
127
- return this.nonVariantImageCount + (this.hasVariants ? 1 : 0);
128
- },
129
- showArrows() {
130
- return this.totalImageCount > this.maxImagesShown;
131
- },
132
- carouselSlideCount() {
133
- return this.totalImageCount - this.maxImagesShown; //number of spaces past the default state we can move
134
- },
135
-
136
- currentImageUrl() {
137
- if (this.selectedImage) {
138
- return (this.usePathPrefix ? this.imageBasePath : '') + this.selectedImage;
139
- }
140
-
141
- return null;
142
- },
143
- currentImageStyle() {
144
- if (this.currentImageUrl) {
145
- return { 'background-image': 'url("' + this.currentImageUrl + (this.usePathPrefix ? ';width=1200;height=1200' : '') + '")' };
146
- }
147
-
148
- return null;
149
- },
150
- variantImageSelected() {
151
- const pathCompare = this.selectedImage.replace(this.imageBasePath, '');
152
-
153
- return (this.selectedImage && ((this.variant && this.variant.ImageUrl === pathCompare) || (this.product && this.product.PrimaryImage && this.product.PrimaryImage.ImageUrl === pathCompare)));
154
- },
155
- variantImagePath() {
156
- if (this.variant && this.variant.ImageUrl) {
157
- return this.imageBasePath + this.variant.ImageUrl + ';width=100;height=100';
158
- } else if (this.product) {
159
- return this.imageBasePath + this.product.PrimaryImage.ImageUrl + ';width=100;height=100';
160
- }
161
-
162
- return null;
163
- },
164
- substitutedImage() {
165
- return this.variantImageSelected && this.variant && this.variant.SubstitutedImage;
166
- },
167
- imageListClass() {
168
- return 'up-' + Math.min(this.totalImageCount, this.maxImagesShown);
169
- },
170
- shiftStyle() {
171
- return { left: '-' + this.carouselIndex * (100 / this.maxImagesShown) + '%' };
172
- },
56
+ usePathPrefix: {
57
+ type: Boolean,
58
+ default: true,
173
59
  },
174
- components: {
175
- IconBase,
176
- IconCaret,
60
+ forceNav: {
61
+ type: Boolean,
62
+ default: false,
63
+ },
64
+ });
65
+ const emit = defineEmits(['update']);
66
+
67
+ const carouselIndex = ref(0);
68
+ const maxImagesShown = ref(6);
69
+
70
+ // selecting images
71
+ function imageSelected(item) {
72
+ const pathCompare = props.selectedImage.replace(props.imageBasePath, '');
73
+ return pathCompare === item.ImageUrl;
74
+ }
75
+
76
+ function selectImage(item) {
77
+ if (!props.disabled) {
78
+ emit('update', item);
79
+ }
80
+ }
81
+
82
+ function selectVariantImage() {
83
+ if (!props.disabled) {
84
+ if (props.variant) {
85
+ emit('update', props.variant);
86
+ } else {
87
+ emit('update', props.product.PrimaryImage);
88
+ }
89
+ }
90
+ }
91
+
92
+ const variantImageSelected = computed(() => {
93
+ const pathCompare = props.selectedImage.replace(props.imageBasePath, '');
94
+ return (props.selectedImage && ((props.variant && props.variant.ImageUrl === pathCompare) || (props.product && props.product.PrimaryImage && props.product.PrimaryImage.ImageUrl === pathCompare)));
95
+ });
96
+
97
+ // moving carousel
98
+ function previous() {
99
+ moveCarousel(-1);
100
+ }
101
+
102
+ function next() {
103
+ moveCarousel(1);
104
+ }
105
+
106
+ function moveCarousel(number) {
107
+ let newIndex = carouselIndex.value + number;
108
+ if (newIndex < 0) {
109
+ newIndex = 0;
110
+ } else if (newIndex > carouselSlideCount.value) {
111
+ newIndex = carouselSlideCount.value;
112
+ }
113
+
114
+ carouselIndex.value = newIndex;
115
+ }
116
+
117
+ // image counts
118
+ const nonVariantImageCount = computed(() => {
119
+ return props.product ? (props.product.AdditionalImages.length + props.product.LifeStyleImages.length) : 0;
120
+ });
121
+
122
+ const totalImageCount = computed(() => {
123
+ return nonVariantImageCount.value + (props.hasVariants ? 1 : 0);
124
+ });
125
+
126
+ const showArrows = computed(() => {
127
+ return totalImageCount.value > maxImagesShown.value;
128
+ });
129
+
130
+ const carouselSlideCount = computed(() => {
131
+ return totalImageCount.value - maxImagesShown.value; //number of spaces past the default state we can move
132
+ });
133
+
134
+
135
+ // image paths and styles
136
+ function imagePath(item) {
137
+ if (item && item.ImageUrl) {
138
+ return props.imageBasePath + item.ImageUrl + ';width=100;height=100';
139
+ }
140
+
141
+ return null;
142
+ }
143
+
144
+ const currentImageUrl = computed(() => {
145
+ if (props.selectedImage) {
146
+ return (props.usePathPrefix ? props.imageBasePath : '') + props.selectedImage;
147
+ }
148
+ return null;
149
+ });
150
+
151
+ const currentImageStyle = computed(() => {
152
+ if (currentImageUrl.value) {
153
+ return { 'background-image': 'url("' + currentImageUrl.value + (props.usePathPrefix ? ';width=1200;height=1200' : '') + '")' };
154
+ }
155
+ return null;
156
+ });
157
+
158
+ const variantImagePath = computed(() => {
159
+ if (props.variant && props.variant.ImageUrl) {
160
+ return props.imageBasePath + props.variant.ImageUrl + ';width=100;height=100';
161
+ } else if (props.product) {
162
+ return props.imageBasePath + props.product.PrimaryImage.ImageUrl + ';width=100;height=100';
177
163
  }
178
- };
164
+ return null;
165
+ });
166
+
167
+ const imageListClass = computed(() => {
168
+ return 'up-' + Math.min(totalImageCount.value, maxImagesShown.value);
169
+ });
170
+
171
+ const shiftStyle = computed(() => {
172
+ return { left: '-' + carouselIndex.value * (100 / maxImagesShown.value) + '%' };
173
+ });
174
+
175
+ const substitutedImage = computed(() => {
176
+ return variantImageSelected.value && props.variant && props.variant.SubstitutedImage;
177
+ });
179
178
  </script>