@mbao01/common 0.7.0 → 0.7.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.
@@ -4,5 +4,5 @@ export declare const Flex: React.ForwardRefExoticComponent<React.HTMLAttributes<
4
4
  align?: "end" | "center" | "start" | "stretch" | "baseline" | undefined;
5
5
  justify?: "end" | "center" | "start" | "between" | "around" | "evenly" | undefined;
6
6
  wrap?: "wrap" | "wrap-reverse" | "nowrap" | undefined;
7
- gap?: 0 | 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 16 | undefined;
7
+ gap?: 0 | 1 | 4 | 3 | 8 | 2 | 12 | 16 | 5 | 6 | 10 | undefined;
8
8
  } & React.RefAttributes<HTMLDivElement>>;
@@ -3,5 +3,5 @@ export declare const getFlexClasses: (props?: ({
3
3
  align?: "end" | "center" | "start" | "stretch" | "baseline" | null | undefined;
4
4
  justify?: "end" | "center" | "start" | "between" | "around" | "evenly" | null | undefined;
5
5
  wrap?: "wrap" | "wrap-reverse" | "nowrap" | null | undefined;
6
- gap?: 0 | 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 16 | null | undefined;
6
+ gap?: 0 | 1 | 4 | 3 | 8 | 2 | 12 | 16 | 5 | 6 | 10 | null | undefined;
7
7
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
@@ -1,11 +1,11 @@
1
1
  import { default as React } from 'react';
2
2
  export declare const Grid: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
3
- gap?: 0 | 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 16 | undefined;
4
- columns?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 7 | 9 | 11 | undefined;
5
- rows?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 7 | 9 | 11 | undefined;
3
+ gap?: 0 | 1 | 4 | 3 | 8 | 2 | 12 | 16 | 5 | 6 | 10 | undefined;
4
+ columns?: 1 | 4 | 3 | 8 | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | undefined;
5
+ rows?: 1 | 4 | 3 | 8 | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | undefined;
6
6
  flow?: "row" | "col" | "dense" | "row-dense" | "col-dense" | undefined;
7
7
  } & React.RefAttributes<HTMLDivElement>>;
8
8
  export declare const GridItem: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
9
- colSpan?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 7 | 9 | 11 | "full" | undefined;
10
- rowSpan?: 1 | 4 | 3 | 2 | 5 | 6 | "full" | undefined;
9
+ colSpan?: 1 | 4 | 3 | 8 | "full" | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | undefined;
10
+ rowSpan?: 1 | 4 | 3 | "full" | 2 | 5 | 6 | undefined;
11
11
  } & React.RefAttributes<HTMLDivElement>>;
@@ -1,10 +1,10 @@
1
1
  export declare const getGridClasses: (props?: ({
2
- columns?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 7 | 9 | 11 | null | undefined;
3
- rows?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 7 | 9 | 11 | null | undefined;
4
- gap?: 0 | 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 16 | null | undefined;
2
+ columns?: 1 | 4 | 3 | 8 | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | null | undefined;
3
+ rows?: 1 | 4 | 3 | 8 | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | null | undefined;
4
+ gap?: 0 | 1 | 4 | 3 | 8 | 2 | 12 | 16 | 5 | 6 | 10 | null | undefined;
5
5
  flow?: "row" | "col" | "dense" | "row-dense" | "col-dense" | null | undefined;
6
6
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
7
7
  export declare const getGridItemClasses: (props?: ({
8
- colSpan?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 7 | 9 | 11 | "full" | null | undefined;
9
- rowSpan?: 1 | 4 | 3 | 2 | 5 | 6 | "full" | null | undefined;
8
+ colSpan?: 1 | 4 | 3 | 8 | "full" | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | null | undefined;
9
+ rowSpan?: 1 | 4 | 3 | "full" | 2 | 5 | 6 | null | undefined;
10
10
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
@@ -1,6 +1,6 @@
1
1
  export declare const getSkeletonClasses: (props?: ({
2
2
  animate?: "pulse" | null | undefined;
3
- width?: 4 | 8 | 2 | 12 | 16 | "full" | 24 | 32 | 48 | 64 | null | undefined;
4
- height?: 4 | 8 | 2 | 12 | 16 | "full" | 24 | 32 | 48 | 64 | null | undefined;
3
+ width?: 4 | 8 | "full" | 2 | 12 | 16 | 24 | 32 | 48 | 64 | null | undefined;
4
+ height?: 4 | 8 | "full" | 2 | 12 | 16 | 24 | 32 | 48 | 64 | null | undefined;
5
5
  round?: boolean | null | undefined;
6
6
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
@@ -1,5 +1,5 @@
1
1
  import { default as React } from 'react';
2
2
  export declare const Spacer: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & {
3
3
  axis?: "horizontal" | "vertical" | undefined;
4
- gap?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 16 | 20 | 24 | undefined;
4
+ gap?: 1 | 4 | 3 | 8 | 2 | 12 | 16 | 24 | 5 | 6 | 10 | 20 | undefined;
5
5
  } & React.RefAttributes<HTMLDivElement>>;
@@ -1,4 +1,4 @@
1
1
  export declare const getSpacerClasses: (props?: ({
2
2
  axis?: "horizontal" | "vertical" | null | undefined;
3
- gap?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 | 12 | 16 | 20 | 24 | null | undefined;
3
+ gap?: 1 | 4 | 3 | 8 | 2 | 12 | 16 | 24 | 5 | 6 | 10 | 20 | null | undefined;
4
4
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
@@ -1,5 +1,5 @@
1
1
  export declare const getStatusClasses: (props?: ({
2
2
  variant?: "accent" | "default" | "error" | "ghost" | "info" | "neutral" | "primary" | "secondary" | "success" | "warning" | null | undefined;
3
3
  size?: "xs" | "sm" | "md" | "lg" | "xl" | null | undefined;
4
- animate?: "ping" | "bounce" | "pulse" | "spin" | null | undefined;
4
+ animate?: "ping" | "pulse" | "bounce" | "spin" | null | undefined;
5
5
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
@@ -1,4 +1,4 @@
1
1
  export type Theme = "dark" | "light";
2
2
  export declare const THEME_COOKIE_NAME = "data-theme";
3
3
  export declare const getTheme: () => Theme | null;
4
- export declare const saveTheme: (theme: Theme | null) => null | undefined;
4
+ export declare const saveTheme: (theme: Theme | null) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mbao01/common",
3
3
  "private": false,
4
- "version": "0.7.0",
4
+ "version": "0.7.1",
5
5
  "type": "module",
6
6
  "author": "Ayomide Bakare",
7
7
  "license": "MIT",
@@ -131,8 +131,8 @@
131
131
  "@types/node": "^25.0.3",
132
132
  "@types/react": "^19.2.7",
133
133
  "@types/react-dom": "^19.2.3",
134
- "@typescript-eslint/eslint-plugin": "^8.51.0",
135
- "@typescript-eslint/parser": "^8.51.0",
134
+ "@typescript-eslint/eslint-plugin": "^8.52.0",
135
+ "@typescript-eslint/parser": "^8.52.0",
136
136
  "@vitejs/plugin-react": "^5.1.2",
137
137
  "@vitest/coverage-v8": "^3.2.4",
138
138
  "@vitest/ui": "^3.2.4",
@@ -151,12 +151,12 @@
151
151
  "prettier": "^3.7.4",
152
152
  "react": "^19.2.3",
153
153
  "react-dom": "^19.2.3",
154
- "react-router-dom": "^7.11.0",
154
+ "react-router-dom": "^7.12.0",
155
155
  "recharts": "^3.6.0",
156
156
  "storybook": "^10.1.11",
157
157
  "tailwindcss": "^4.1.18",
158
158
  "typescript": "^5.9.3",
159
- "typescript-eslint": "^8.51.0",
159
+ "typescript-eslint": "^8.52.0",
160
160
  "vite": "^6.4.1",
161
161
  "vite-plugin-dts": "^4.5.4",
162
162
  "vitest": "^3.2.4"
@@ -168,5 +168,5 @@
168
168
  "recharts": "2",
169
169
  "typescript": "5"
170
170
  },
171
- "gitHead": "412b7c47a5fe2f7fc7e8e17255b6df1dbb3428b5"
171
+ "gitHead": "5ccbce52df9f8411ec194b45909b47a0bc7d5b51"
172
172
  }
@@ -4,6 +4,7 @@ import { useLayoutEffect, useState } from "react";
4
4
  import { MonitorIcon, MoonIcon, SunIcon } from "lucide-react";
5
5
  import type { SwitchProps, ThemeSwitchProps } from "./types";
6
6
  import { cn, getTheme, saveTheme, Theme } from "../../utilities";
7
+ import { Skeleton } from "../Skeleton";
7
8
  import { getThemeSwitchClasses, getThemeSwitchIconClasses } from "./constants";
8
9
 
9
10
  const Switcher = ({ id, icon, swap, value, label, theme, changeTheme, className }: SwitchProps) => {
@@ -38,12 +39,32 @@ export const ThemeSwitch = ({
38
39
  className,
39
40
  theme: defaultTheme,
40
41
  }: ThemeSwitchProps) => {
42
+ const [isClient, setIsClient] = useState(false);
41
43
  const [theme, setTheme] = useState(() => defaultTheme ?? getTheme());
42
44
 
43
45
  useLayoutEffect(() => {
44
46
  saveTheme(theme);
45
47
  }, [theme]);
46
48
 
49
+ useLayoutEffect(() => {
50
+ setIsClient(true);
51
+ const observer = new MutationObserver(() => {
52
+ const attr = document.body.getAttribute("data-theme");
53
+ if (attr === "dark" || attr === "light") {
54
+ setTheme(attr);
55
+ } else {
56
+ setTheme(null);
57
+ }
58
+ });
59
+ observer.observe(document.body, { attributes: true, attributeFilter: ["data-theme"] });
60
+
61
+ return () => observer.disconnect();
62
+ }, []);
63
+
64
+ if (!isClient) {
65
+ return <Skeleton width={swap ? 4 : 16} />;
66
+ }
67
+
47
68
  if (render) {
48
69
  return render({ theme, setTheme });
49
70
  }
@@ -20,10 +20,14 @@ export const getTheme = () => {
20
20
  };
21
21
 
22
22
  export const saveTheme = (theme: Theme | null) => {
23
- const newTheme = theme ?? getSystemTheme();
24
- if (!newTheme) return null;
25
-
26
23
  const cookies = new Cookies();
27
- cookies.set(THEME_COOKIE_NAME, newTheme, { path: "/", secure: true });
28
- document.body.setAttribute(THEME_COOKIE_NAME, newTheme);
24
+
25
+ if (!theme) {
26
+ cookies.remove(THEME_COOKIE_NAME);
27
+ document.body.removeAttribute(THEME_COOKIE_NAME);
28
+ return;
29
+ }
30
+
31
+ cookies.set(THEME_COOKIE_NAME, theme, { path: "/", secure: true });
32
+ document.body.setAttribute(THEME_COOKIE_NAME, theme);
29
33
  };