@thinkpixellab-public/px-vue 4.1.15 → 4.1.17

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.
@@ -75,8 +75,9 @@ export default {
75
75
  ) {
76
76
  this.resizeObserver.observe(this.observeElementValue);
77
77
  } else {
78
+ const name = this.bem ? this.bem() : 'PxBaseResize';
78
79
  console.warn(
79
- `Could not call ResizeObserver.observe because observeElementValue is not an element: ${this.observeElementValue}`,
80
+ `${name}: Could not call ResizeObserver.observe because observeElementValue is not an element: ${this.observeElementValue}`,
80
81
  );
81
82
  }
82
83
  },
@@ -146,6 +146,18 @@ export default {
146
146
  onComplete: () => {
147
147
  this.$emit('after-enter');
148
148
  },
149
+ onUpdateParams: [this],
150
+ onUpdate: function (self) {
151
+ self.$emit('progress', {
152
+ active: self.active,
153
+ progress: this.progress(),
154
+ direction: 'enter',
155
+ });
156
+ self.$emit('enter-progress', {
157
+ active: self.active,
158
+ progress: this.progress(),
159
+ });
160
+ },
149
161
  });
150
162
  },
151
163
  leave(element) {
@@ -190,6 +202,18 @@ export default {
190
202
  onComplete: () => {
191
203
  this.$emit('after-leave');
192
204
  },
205
+ onUpdateParams: [this],
206
+ onUpdate: function (self) {
207
+ self.$emit('progress', {
208
+ active: self.active,
209
+ progress: this.progress(),
210
+ direction: 'leave',
211
+ });
212
+ self.$emit('leave-progress', {
213
+ active: self.active,
214
+ progress: this.progress(),
215
+ });
216
+ },
193
217
  });
194
218
  },
195
219
  },
@@ -0,0 +1,88 @@
1
+ /**
2
+ * useBodyClass()
3
+ *
4
+ * This composable lets components add or remove <body> classes in a way that:
5
+ * - SSR-safe (works with Nuxt `useHead` or manual DOM binding)
6
+ * - supports multiple components contributing classes
7
+ * - automatically removes classes on unmount (optional)
8
+ * - works in both Nuxt and plain Vue 3 apps
9
+ *
10
+ * Usage in Nuxt (in a layout):
11
+ * -------------------------------------
12
+ * import { useHead } from '#imports'
13
+ * import { useBodyClass } from '~/composables/useBodyClass'
14
+ *
15
+ * const { bodyClass } = useBodyClass()
16
+ *
17
+ * useHead({
18
+ * bodyAttrs: {
19
+ * class: bodyClass,
20
+ * },
21
+ * })
22
+ *
23
+ * Usage in a Nuxt page or component:
24
+ * -------------------------------------
25
+ * import { useBodyClass } from '~/composables/useBodyClass'
26
+ * const { addBodyClass } = useBodyClass()
27
+ * addBodyClass(['my-page', 'dark'], { autoCleanup: true })
28
+ *
29
+ * Usage in plain Vue 3 (non-Nuxt):
30
+ * -------------------------------------
31
+ * import { useBodyClass } from './composables/useBodyClass'
32
+ * import { watch } from 'vue'
33
+ *
34
+ * const { bodyClass } = useBodyClass()
35
+ *
36
+ * watch(bodyClass, (val) => {
37
+ * if (typeof document !== 'undefined') {
38
+ * document.body.className = val
39
+ * }
40
+ * }, { immediate: true })
41
+ *
42
+ * In a component:
43
+ * import { useBodyClass } from './composables/useBodyClass'
44
+ * const { addBodyClass } = useBodyClass()
45
+ * addBodyClass('fullscreen')
46
+ */
47
+ import { computed, onUnmounted } from 'vue';
48
+
49
+ export function useBodyClass() {
50
+ const _bodyClasses = useState('body-classes', () => new Set());
51
+
52
+ function normalize(input) {
53
+ return Array.isArray(input) ? input : [input];
54
+ }
55
+
56
+ function addBodyClass(classNames, { autoCleanup = true } = {}) {
57
+ const classes = normalize(classNames);
58
+
59
+ classes.forEach(c => _bodyClasses.value.add(c));
60
+
61
+ if (autoCleanup) {
62
+ onUnmounted(() => {
63
+ classes.forEach(c => _bodyClasses.value.delete(c));
64
+ });
65
+ }
66
+ }
67
+
68
+ function removeBodyClass(classNames) {
69
+ normalize(classNames).forEach(c => _bodyClasses.value.delete(c));
70
+ }
71
+
72
+ function toggleBodyClass(className, condition) {
73
+ if (condition) {
74
+ _bodyClasses.value.add(className);
75
+ } else {
76
+ _bodyClasses.value.delete(className);
77
+ }
78
+ }
79
+
80
+ const bodyClass = computed(() => Array.from(_bodyClasses.value).join(' '));
81
+
82
+ return {
83
+ addBodyClass,
84
+ removeBodyClass,
85
+ toggleBodyClass,
86
+ bodyClass,
87
+ };
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "4.1.15",
3
+ "version": "4.1.17",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": {
6
6
  "name": "Pixel Lab"