@thinkpixellab-public/px-vue 3.0.21 → 3.0.23

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.
@@ -0,0 +1,126 @@
1
+ <!--
2
+ Creates a horizontally scrolling container with an invisible scrollbar and arrows on either side
3
+ to scroll to the beginning or end of the container.
4
+
5
+ <px-arrow-scroller :arrow-start-src="require(...)" :arrow-end-src="require(...)">
6
+ ...
7
+ </px-arrow-scroller>
8
+
9
+ -->
10
+ <template>
11
+ <div :class="bem()">
12
+ <px-icon-button
13
+ :class="[bem('arrow', { start: true, visible: arrowStartVisible }), arrowClass]"
14
+ :src="arrowStartSrc"
15
+ size="0.8em"
16
+ @click="scrollTo(0)"
17
+ />
18
+
19
+ <div :class="bem('scroller')" ref="scroller" @scroll="updateScrollArrows">
20
+ <slot />
21
+ </div>
22
+
23
+ <px-icon-button
24
+ :class="[bem('arrow', { end: true, visible: arrowEndVisible }), arrowClass]"
25
+ :src="arrowEndSrc"
26
+ size="0.8em"
27
+ @click="scrollTo(100000)"
28
+ />
29
+ </div>
30
+ </template>
31
+
32
+ <script>
33
+ // import { mapState } from 'vuex';
34
+ // import Component from '~/components/Component.vue';
35
+ // import Mixin from '~/components/Mixin.vue';
36
+ import PxBaseResize from './PxBaseResize.vue';
37
+ import PxIconButton from '@thinkpixellab-public/px-vue/components/PxIconButton.vue';
38
+
39
+ export default {
40
+ name: 'px-arrow-scroller',
41
+ components: { PxIconButton },
42
+ mixins: [PxBaseResize, PxIconButton],
43
+ props: {
44
+ arrowStartSrc: { type: String, default: null },
45
+ arrowEndSrc: { type: String, default: null },
46
+ arrowClass: { type: String, default: null },
47
+ },
48
+ data() {
49
+ return {
50
+ arrowsVisible: false,
51
+ arrowStartVisible: false,
52
+ arrowEndVisible: false,
53
+ };
54
+ },
55
+ // computed: {},
56
+ // watch: {},
57
+ // mounted() {},
58
+ methods: {
59
+ resize() {
60
+ this.updateScrollArrows();
61
+ },
62
+ updateScrollArrows() {
63
+ const scroller = this.$refs.scroller;
64
+
65
+ if (!scroller) {
66
+ return;
67
+ }
68
+
69
+ const fromStart = scroller.scrollLeft;
70
+ const fromEnd = scroller.scrollWidth - scroller.scrollLeft - scroller.clientWidth;
71
+
72
+ this.arrowsVisible = scroller.clientWidth > scroller.scrollWidth;
73
+ this.arrowStartVisible = fromStart > 2;
74
+ this.arrowEndVisible = fromEnd > 2;
75
+ },
76
+
77
+ scrollTo(x) {
78
+ if (this.$refs.scroller) {
79
+ this.$refs.scroller.scrollTo({
80
+ left: x,
81
+ behavior: 'smooth',
82
+ });
83
+ }
84
+ },
85
+ },
86
+ };
87
+ </script>
88
+
89
+ <style lang="scss">
90
+ @use '../styles/px.scss' as *;
91
+
92
+ .px-arrow-scroller {
93
+ // prettier-ignore
94
+ @include grid-art((
95
+ 'auto | 1fr | auto |',
96
+ 'arrow-start | scroller | arrow-end | auto'
97
+ ));
98
+
99
+ &__arrow {
100
+ padding: 0.1em 1em 0.25em;
101
+
102
+ &--start {
103
+ grid-area: arrow-start;
104
+ }
105
+
106
+ &--end {
107
+ grid-area: arrow-end;
108
+ }
109
+
110
+ @include transition(opacity, $dur: 200ms);
111
+ opacity: 0;
112
+ pointer-events: none;
113
+
114
+ &--visible {
115
+ opacity: 1;
116
+ pointer-events: visible;
117
+ }
118
+ }
119
+
120
+ &__scroller {
121
+ grid-area: scroller;
122
+ overflow-x: auto;
123
+ @include invisible-scrollbar;
124
+ }
125
+ }
126
+ </style>
@@ -202,6 +202,7 @@ export default {
202
202
  debug: { type: Boolean, default: false },
203
203
  getItemCountFn: { default: null },
204
204
  getItemFn: { default: null },
205
+ centerSingleRow: { type: Boolean, default: true },
205
206
  },
206
207
 
207
208
  data() {
@@ -212,14 +213,23 @@ export default {
212
213
  },
213
214
  computed: {
214
215
  gridStyle() {
216
+ let rowCount = this.rows?.length || 0;
217
+ let colCount = this.columnCount;
218
+
219
+ if (this.centerSingleRow && rowCount == 1) {
220
+ colCount = 0;
221
+ this.rows[0].forEach(sp => {
222
+ colCount += sp.name == 'wide' ? 2 : 1;
223
+ });
224
+ }
225
+
215
226
  const defAspect = aspect(this.cardAspect);
216
227
  const wideAspect = (this.cardMinWidth * 2 + this.gap) / (this.cardMinWidth / defAspect);
217
- const maxGridWidth =
218
- this.cardMaxWidth * this.columnCount + this.gap * (this.columnCount - 1);
228
+ const maxGridWidth = this.cardMaxWidth * colCount + this.gap * (this.columnCount - 1);
219
229
 
220
230
  return {
221
231
  // prettier-ignore
222
- gridTemplateColumns: `repeat(${this.columnCount}, 1fr)`,
232
+ gridTemplateColumns: `repeat(${colCount}, 1fr)`,
223
233
  maxWidth: this.cssPx(maxGridWidth),
224
234
  '--gap': this.cssPx(this.gap),
225
235
  '--aspect': defAspect,
@@ -68,7 +68,6 @@ export default {
68
68
  </script>
69
69
 
70
70
  <style lang="scss">
71
- @import '@/styles/include.scss';
72
71
  .px-qr-code {
73
72
  aspect-ratio: 1;
74
73
  width: 256px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "3.0.21",
3
+ "version": "3.0.23",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": "Pixel Lab",
6
6
  "license": "MIT",