@thinkpixellab-public/px-vue 3.0.7 → 3.0.9

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,72 @@
1
+ <!--
2
+ Use for global mobile awareness in javascript. This doesn't actually handle mobile detection
3
+ but provides a consistent interface for communicating between a single component that does
4
+ the detection and other components that subscribe to an eventbus and update a property called
5
+ isMobile.
6
+
7
+ Sample usage using a css variable for detecting mobile (this keeps css and js in sync):
8
+
9
+ ### MyLayout.vue (or other global component)
10
+
11
+ // add PxBaseMobileAware as a mixin
12
+ import PxBaseMobileAware from '@thinkpixellab-public/px-vue/components/PxBaseMobileAware.vue';
13
+ mixins: [PxBaseMobileAware],
14
+
15
+ // add a resize handler and call setGlobalIsMobile
16
+ resize() {
17
+ if (this.$el) {
18
+ const cssMobile = getComputedStyle(this.$el).getPropertyValue('--is-mobile');
19
+ this.setGlobalIsMobile(cssMobile.toLowerCase().trim() == 'true');
20
+ }
21
+ },
22
+
23
+ // add a css variable that changes with the viewport
24
+
25
+ .my-layout {
26
+ --is-mobile: false;
27
+ @include media-until-mobile() {
28
+ --is-mobile: true;
29
+ }
30
+ }
31
+
32
+ ### MyComponent.vue
33
+
34
+ // use PxBaseMobileAware as a mixin
35
+ import PxBaseMobileAware from '@thinkpixellab-public/px-vue/components/PxBaseMobileAware.vue';
36
+ mixins: [PxBaseMobileAware]
37
+
38
+ // use the isMobile property as needed in a template
39
+ <div> This is mobile: {{isMobile ? 'yup' : 'nope' }} </div>
40
+
41
+ // or in code
42
+ watch: {
43
+ isMobile(nv) {
44
+ // do something when isMobile changes
45
+ }
46
+ }
47
+
48
+
49
+ -->
50
+
51
+ <script>
52
+ export default {
53
+ data() {
54
+ return { isMobile: null };
55
+ },
56
+ mounted() {
57
+ if (this.$globalOn) {
58
+ this.$globalOn('mobile-changed', isMobile => {
59
+ this.isMobile = isMobile;
60
+ });
61
+ }
62
+ },
63
+ methods: {
64
+ setGlobalIsMobile(isMobile) {
65
+ if (this.$globalEmit) {
66
+ this.$globalEmit('mobile-changed', isMobile);
67
+ this.isMobile = isMobile;
68
+ }
69
+ },
70
+ },
71
+ };
72
+ </script>
@@ -27,7 +27,7 @@ export default {
27
27
  disabled: {
28
28
  immediate: true,
29
29
  handler(disabled) {
30
- if (!process.server) {
30
+ if (isBrowser) {
31
31
  if (disabled) {
32
32
  this.unmount();
33
33
  } else {
@@ -126,12 +126,12 @@ export default {
126
126
  },
127
127
  },
128
128
  render(h) {
129
- if (!isBrowser) return;
130
129
  if (this.disabled) {
131
130
  const nodes = this.$scopedSlots && this.$scopedSlots.default();
132
131
  if (!nodes) return h();
133
132
  return nodes.length < 2 && !nodes[0].text ? nodes : h(this.tag, nodes);
134
133
  }
134
+ if (!isBrowser) return;
135
135
  return h();
136
136
  },
137
137
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "3.0.7",
3
+ "version": "3.0.9",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": "Pixel Lab",
6
6
  "license": "MIT",