vueless 1.5.2-beta.1 → 1.5.2

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.
@@ -1,4 +1,4 @@
1
- import { ref, computed } from "vue";
1
+ import { onMounted, ref, watch, computed, onBeforeUnmount } from "vue";
2
2
  import { isSSR } from "../utils/helper";
3
3
 
4
4
  type ResponsiveConfig<T> = Partial<Record<BreakpointName, T>>;
@@ -25,12 +25,12 @@ let isInitialized = false;
25
25
  let animationId: number | undefined;
26
26
 
27
27
  const windowWidth = ref(0);
28
+ const currentBreakpoint = ref(BreakpointName.Xs);
28
29
  const BREAKPOINT_KEYS = Object.keys(BreakpointName) as (keyof typeof BreakpointName)[];
29
- const currentBreakpoint = computed(() => getBreakpoint(windowWidth.value));
30
30
 
31
- export function useBreakpoint() {
32
- initBreakpointListener();
31
+ watch(windowWidth, setBreakpoint, { immediate: true });
33
32
 
33
+ export function useBreakpoint() {
34
34
  const isPhone = computed(() => {
35
35
  return currentBreakpoint.value === BreakpointName.Xs;
36
36
  });
@@ -67,6 +67,14 @@ export function useBreakpoint() {
67
67
  return isDesktop.value || isLargeDesktop.value;
68
68
  });
69
69
 
70
+ onMounted(() => {
71
+ initBreakpointListener();
72
+ });
73
+
74
+ onBeforeUnmount(() => {
75
+ window.removeEventListener("resize", resizeListener);
76
+ });
77
+
70
78
  return {
71
79
  isPhone,
72
80
  isLargePhone,
@@ -131,16 +139,20 @@ export function r<T>(config: ResponsiveConfig<T>): T {
131
139
  return config[BreakpointName[definedKeys[0]]] as T;
132
140
  }
133
141
 
134
- function getBreakpoint(width: number) {
142
+ function setBreakpoint(newWindowWidth: number) {
143
+ if (newWindowWidth === undefined) return;
144
+
135
145
  for (let i = BREAKPOINT_KEYS.length - 1; i >= 0; i--) {
136
146
  const key = BREAKPOINT_KEYS[i];
137
147
 
138
- if (width >= BreakpointWidth[key]) {
139
- return BreakpointName[key];
148
+ if (newWindowWidth >= BreakpointWidth[key]) {
149
+ currentBreakpoint.value = BreakpointName[key];
150
+
151
+ return;
140
152
  }
141
153
  }
142
154
 
143
- return BreakpointName.Xs;
155
+ currentBreakpoint.value = BreakpointName.Xs;
144
156
  }
145
157
 
146
158
  function resizeListener() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "1.5.2-beta.1",
3
+ "version": "1.5.2",
4
4
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
5
5
  "author": "Johnny Grid <hello@vueless.com> (https://vueless.com)",
6
6
  "homepage": "https://vueless.com",