vueless 1.5.2-beta.0 → 1.5.2-beta.1

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 { onMounted, ref, watch, computed, onBeforeUnmount } from "vue";
1
+ import { ref, computed } 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);
29
28
  const BREAKPOINT_KEYS = Object.keys(BreakpointName) as (keyof typeof BreakpointName)[];
30
-
31
- watch(windowWidth, setBreakpoint, { immediate: true });
29
+ const currentBreakpoint = computed(() => getBreakpoint(windowWidth.value));
32
30
 
33
31
  export function useBreakpoint() {
32
+ initBreakpointListener();
33
+
34
34
  const isPhone = computed(() => {
35
35
  return currentBreakpoint.value === BreakpointName.Xs;
36
36
  });
@@ -67,14 +67,6 @@ 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
-
78
70
  return {
79
71
  isPhone,
80
72
  isLargePhone,
@@ -139,20 +131,16 @@ export function r<T>(config: ResponsiveConfig<T>): T {
139
131
  return config[BreakpointName[definedKeys[0]]] as T;
140
132
  }
141
133
 
142
- function setBreakpoint(newWindowWidth: number) {
143
- if (newWindowWidth === undefined) return;
144
-
134
+ function getBreakpoint(width: number) {
145
135
  for (let i = BREAKPOINT_KEYS.length - 1; i >= 0; i--) {
146
136
  const key = BREAKPOINT_KEYS[i];
147
137
 
148
- if (newWindowWidth >= BreakpointWidth[key]) {
149
- currentBreakpoint.value = BreakpointName[key];
150
-
151
- return;
138
+ if (width >= BreakpointWidth[key]) {
139
+ return BreakpointName[key];
152
140
  }
153
141
  }
154
142
 
155
- currentBreakpoint.value = BreakpointName.Xs;
143
+ return BreakpointName.Xs;
156
144
  }
157
145
 
158
146
  function resizeListener() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "1.5.2-beta.0",
3
+ "version": "1.5.2-beta.1",
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",
@@ -59,7 +59,7 @@
59
59
  "@vue/eslint-config-typescript": "^14.7.0",
60
60
  "@vue/test-utils": "^2.4.8",
61
61
  "@vue/tsconfig": "^0.9.1",
62
- "@vueless/storybook": "^1.8.0",
62
+ "@vueless/storybook": "^1.8.1",
63
63
  "eslint": "^10.2.1",
64
64
  "eslint-plugin-storybook": "^10.3.5",
65
65
  "eslint-plugin-tailwindcss": "^4.0.0-alpha.7",