@thinkpixellab-public/px-vue 3.0.65 → 3.0.66

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,113 @@
1
+ <!--
2
+ A simple position:stickky container that adds stuck / unstuck events and classes as the item
3
+ becomes stuck / unstuck.
4
+ -->
5
+ <template>
6
+ <div
7
+ :class="[bem({ disabled: !enabled }), stuck ? stuckClass : unstuckClass]"
8
+ :style="enabled ? { top: cssPx(top), position: 'sticky', zIndex: z } : null"
9
+ >
10
+ <div
11
+ v-show="enabled"
12
+ ref="sentinel"
13
+ :class="bem('sentinel')"
14
+ :style="enabled ? { top: cssPx(-(top + overlap)), height: cssPx(top + overlap) } : null"
15
+ ></div>
16
+ <slot :stuck="stuck" />
17
+ </div>
18
+ </template>
19
+
20
+ <script>
21
+ export default {
22
+ name: 'px-sticky',
23
+ props: {
24
+ enabled: { type: Boolean, default: true },
25
+ top: { type: Number, default: 0 },
26
+ overlap: { type: Number, default: 1 },
27
+ z: { type: Number, default: 1 },
28
+ stuckClass: { type: String, default: '' },
29
+ unstuckClass: { type: String, default: '' },
30
+ },
31
+ data() {
32
+ return {
33
+ stuck: false,
34
+ stuckScrollY: null,
35
+ };
36
+ },
37
+ watch: {
38
+ enabled() {
39
+ this.updateConnections();
40
+ },
41
+ stuck(nv) {
42
+ if (nv) {
43
+ this.$emit('stuck');
44
+ } else {
45
+ this.$emit('unstuck');
46
+ }
47
+ },
48
+ },
49
+ mounted() {
50
+ this.updateConnections();
51
+ },
52
+ beforeDestroy() {
53
+ this.tryDisconnect();
54
+ },
55
+ methods: {
56
+ updateConnections() {
57
+ if (this.enabled) {
58
+ this.tryConnect();
59
+ } else {
60
+ this.tryDisconnect();
61
+ }
62
+ },
63
+ tryConnect() {
64
+ if (!this.observer) {
65
+ try {
66
+ this.observer = new IntersectionObserver(
67
+ ([e]) => {
68
+ this.stuck = e.intersectionRatio < 1;
69
+ },
70
+ { threshold: [1] }
71
+ );
72
+ this.observer.observe(this.$refs.sentinel);
73
+ } catch (e) {
74
+ console.warn('Cound not create css sticky detector.');
75
+ console.warn(e);
76
+ }
77
+ }
78
+ },
79
+ tryDisconnect() {
80
+ this.stuck = false;
81
+ if (this.observer) {
82
+ this.observer.disconnect();
83
+ this.observer = null;
84
+ }
85
+ },
86
+ },
87
+ };
88
+ </script>
89
+
90
+ <style lang="scss">
91
+ @import '@/styles/include.scss';
92
+ .px-sticky {
93
+ position: relative;
94
+
95
+ &:not(.px-sticky--disabled) {
96
+ position: sticky !important;
97
+ }
98
+
99
+ &__sentinel {
100
+ position: absolute;
101
+ left: 0;
102
+ right: 0; /* needs dimensions */
103
+ visibility: hidden;
104
+ opacity: 0;
105
+
106
+ // DEBUG
107
+ // visibility: visible;
108
+ // opacity: 0.9;
109
+ // background-color: lime;
110
+ // z-index: 10000000;
111
+ }
112
+ }
113
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "3.0.65",
3
+ "version": "3.0.66",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": "Pixel Lab",
6
6
  "license": "MIT",
package/utils/utils.js CHANGED
@@ -260,4 +260,16 @@ export default {
260
260
  setTimeout(resolve, ms);
261
261
  });
262
262
  },
263
+
264
+ /**
265
+ * Generate a 6 letter random sequence of letters and numbers, based on this:
266
+ * https://stackoverflow.com/questions/6248666/how-to-generate-short-uid-like-ax4j9z-in-js
267
+ */
268
+
269
+ uniqueId() {
270
+ return (
271
+ ('000' + ((Math.random() * 46656) | 0).toString(36)).slice(-3) +
272
+ ('000' + ((Math.random() * 46656) | 0).toString(36)).slice(-3)
273
+ );
274
+ },
263
275
  };