@bgord/ui 0.8.16 → 0.8.18

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.
@@ -12,3 +12,4 @@ export * from "./use-scroll-lock";
12
12
  export * from "./use-shortcuts";
13
13
  export * from "./use-text-field";
14
14
  export * from "./use-toggle";
15
+ export * from "./use-window-dimensions";
@@ -12,3 +12,4 @@ export * from "./use-scroll-lock";
12
12
  export * from "./use-shortcuts";
13
13
  export * from "./use-text-field";
14
14
  export * from "./use-toggle";
15
+ export * from "./use-window-dimensions";
@@ -23,6 +23,5 @@ const OnlineStatusStore = {
23
23
  getServerSnapshot: () => OnlineStatus.online,
24
24
  };
25
25
  export function useOnlineStatus() {
26
- const status = useSyncExternalStore(OnlineStatusStore.subscribe, OnlineStatusStore.getSnapshot, OnlineStatusStore.getServerSnapshot);
27
- return status;
26
+ return useSyncExternalStore(OnlineStatusStore.subscribe, OnlineStatusStore.getSnapshot, OnlineStatusStore.getServerSnapshot);
28
27
  }
@@ -0,0 +1,5 @@
1
+ export type WindowDimensions = {
2
+ width: number | undefined;
3
+ height: number | undefined;
4
+ };
5
+ export declare function useWindowDimensions(): WindowDimensions;
@@ -0,0 +1,27 @@
1
+ import { useSyncExternalStore } from "react";
2
+ const DefaultWindowDimensions = { width: undefined, height: undefined };
3
+ let snapshot = DefaultWindowDimensions;
4
+ const WindowDimensionsStore = {
5
+ subscribe(callback) {
6
+ if (typeof window === "undefined")
7
+ return () => { };
8
+ window.addEventListener("resize", callback);
9
+ return () => window.removeEventListener("resize", callback);
10
+ },
11
+ getSnapshot() {
12
+ if (typeof window === "undefined")
13
+ return DefaultWindowDimensions;
14
+ const width = window.innerWidth;
15
+ const height = window.innerHeight;
16
+ if (snapshot.width === width && snapshot.height === height)
17
+ return snapshot;
18
+ snapshot = { width, height };
19
+ return snapshot;
20
+ },
21
+ getServerSnapshot() {
22
+ return DefaultWindowDimensions;
23
+ },
24
+ };
25
+ export function useWindowDimensions() {
26
+ return useSyncExternalStore(WindowDimensionsStore.subscribe, WindowDimensionsStore.getSnapshot, WindowDimensionsStore.getServerSnapshot);
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/ui",
3
- "version": "0.8.16",
3
+ "version": "0.8.18",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -23,21 +23,22 @@
23
23
  "access": "public"
24
24
  },
25
25
  "devDependencies": {
26
- "@biomejs/biome": "2.3.10",
27
- "@commitlint/cli": "20.2.0",
28
- "@commitlint/config-conventional": "20.2.0",
29
- "@happy-dom/global-registrator": "20.0.11",
26
+ "@biomejs/biome": "2.3.11",
27
+ "@commitlint/cli": "20.3.1",
28
+ "@commitlint/config-conventional": "20.3.1",
29
+ "@happy-dom/global-registrator": "20.1.0",
30
+ "@stryker-mutator/core": "9.4.0",
30
31
  "@testing-library/dom": "10.4.1",
31
32
  "@testing-library/jest-dom": "6.9.1",
32
33
  "@testing-library/react": "16.3.1",
33
34
  "@testing-library/user-event": "14.6.1",
34
35
  "@types/bun": "1.3.5",
35
36
  "@types/js-cookie": "3.0.6",
36
- "@types/react": "19.2.7",
37
+ "@types/react": "19.2.8",
37
38
  "@types/react-dom": "19.2.3",
38
- "cspell": "9.4.0",
39
- "knip": "5.78.0",
40
- "lefthook": "2.0.13",
39
+ "cspell": "9.6.0",
40
+ "knip": "5.80.2",
41
+ "lefthook": "2.0.14",
41
42
  "lockfile-lint": "4.14.1",
42
43
  "only-allow": "1.2.2",
43
44
  "shellcheck": "4.1.0",
package/readme.md CHANGED
@@ -40,7 +40,8 @@ src/
40
40
  │   ├── use-scroll-lock.ts
41
41
  │   ├── use-shortcuts.ts
42
42
  │   ├── use-text-field.ts
43
- │   └── use-toggle.ts
43
+ │   ├── use-toggle.ts
44
+ │   └── use-window-dimensions.ts
44
45
  └── services
45
46
  ├── absolute-url.ts
46
47
  ├── autocomplete.ts