Skip to content

Commit

Permalink
Merge pull request #10 from react18-tools/feat/dont-sync
Browse files Browse the repository at this point in the history
Feat/dont sync
  • Loading branch information
mayank1513 committed Jun 14, 2024
2 parents 36da2f8 + 9fffbf5 commit 3f38206
Show file tree
Hide file tree
Showing 25 changed files with 317 additions and 20 deletions.
4 changes: 1 addition & 3 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"commit": true,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["@example/*"]
}
2 changes: 1 addition & 1 deletion .tkb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
},
"W_uPAM5Vm86aJ8yEEMKHh": {
"id": "W_uPAM5Vm86aJ8yEEMKHh",
"description": "Update examples\n- Add example for tailwind",
"description": "Update examples\n- Add example for mui",
"columnId": "column-todo"
},
"zE0aqgk59cyZ95s5TkECd": {
Expand Down
8 changes: 8 additions & 0 deletions examples/tailwind-ssg/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ["@repo/eslint-config/next.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
};
24 changes: 24 additions & 0 deletions examples/tailwind-ssg/app/_components/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
interface CardProps {
href: string;
title: string;
text: string;
}

/** Card component */
export default function Card({ href, title, text }: CardProps) {
return (
<a
href={href}
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer">
<h2 className={"mb-3 text-2xl font-semibold"}>
{`${title} `}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={"m-0 max-w-[30ch] text-sm opacity-50"}>{text}</p>
</a>
);
}
Binary file added examples/tailwind-ssg/app/favicon.ico
Binary file not shown.
5 changes: 5 additions & 0 deletions examples/tailwind-ssg/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@import "nextjs-darkmode/css";
23 changes: 23 additions & 0 deletions examples/tailwind-ssg/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { Core } from "nextjs-darkmode";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Tailwind CSS Example",
description: "Generated by Mayank <https://github.com/mayank1513>",
};

/** Root layout */
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body className={[inter.className, "bg-white dark:bg-black dark:text-white"].join(" ")}>
<Core t="background .3s" dp />
{children}
</body>
</html>
);
}
61 changes: 61 additions & 0 deletions examples/tailwind-ssg/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { StarMe } from "@mayank1513/fork-me";
import { Switch } from "nextjs-darkmode/switch";
import Card from "./_components/card";

// Home page
export default function Home() {
return (
// skipcq: JS-0415
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
nextjs-darkmode Tailwind CSS example
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://mayank-chaudhari.vercel.app"
target="_blank"
rel="noopener noreferrer">
By Mayank
</a>
</div>
</div>

<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40 before:lg:h-[360px] z-[-1]" />

<Switch />

<div className="mb-32 grid text-center lg:max-w-5xl lg:w-full lg:mb-0 lg:grid-cols-4 lg:text-left">
<Card
href="https://react18-tools.github.io/nextjs-darkmode/"
title="Docs"
text="Find in-depth information about nextjs-darkmode features and API."
/>
<Card
href="https://github.com/react18-tools/nextjs-darkmode"
title="Examples"
text="Learn through more examples on official GitHub repo."
/>
<StarMe
gitHubUrl="https://github.com/react18-tools/nextjs-darkmode"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30">
<h2 className={"mb-3 text-2xl font-semibold"}>
Star Me{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={"m-0 max-w-[30ch] text-sm opacity-50"}>
Explore and star official <code>nextjs-darkmode</code> repo.
</p>
</StarMe>
<Card
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
title="Deploy"
text="Instantly deploy your Next.js site to a shareable URL with Vercel."
/>
</div>
</main>
);
}
6 changes: 6 additions & 0 deletions examples/tailwind-ssg/cache/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"telemetry": {
"notifiedAt": "1717946618192",
"enabled": false
}
}
5 changes: 5 additions & 0 deletions examples/tailwind-ssg/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
3 changes: 3 additions & 0 deletions examples/tailwind-ssg/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
reactStrictMode: true,
};
37 changes: 37 additions & 0 deletions examples/tailwind-ssg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@example/tailwind-ssg",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "next build",
"clean": "rm -rf .next",
"dev": "next dev -p 3002",
"lint": "next lint",
"typecheck": "tsc --noEmit",
"start": "next start",
"postinstall": "next telemetry disable"
},
"dependencies": {
"@mayank1513/fork-me": "^2.1.2",
"@repo/logger": "workspace:*",
"@repo/shared": "workspace:*",
"next": "^14.2.4",
"nextjs-darkmode": "workspace:*",
"nextjs-themes": "^3.1.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react18-loaders": "^1.1.1"
},
"devDependencies": {
"@next/eslint-plugin-next": "^14.2.4",
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/node": "^20.14.2",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.4",
"typescript": "^5.4.5"
}
}
6 changes: 6 additions & 0 deletions examples/tailwind-ssg/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
16 changes: 16 additions & 0 deletions examples/tailwind-ssg/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Config } from "tailwindcss";

const config: Config = {
content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {},
plugins: [],
darkMode: [
"variant",
["@media (prefers-color-scheme: dark) { &:not(.light *) }", "&:is(.dark *)"],
],
};
export default config;
13 changes: 13 additions & 0 deletions examples/tailwind-ssg/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"exclude": ["node_modules"],
"extends": "@repo/typescript-config/nextjs.json",
"compilerOptions": {
"outDir": "dist",
"plugins": [
{
"name": "next"
}
]
},
"include": ["src", "next.config.js", "next-env.d.ts", ".next/types/**/*.ts"]
}
13 changes: 13 additions & 0 deletions examples/tailwind-ssg/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": [
"//"
],
"tasks": {
"build": {
"outputs": [
".next/**",
"!.next/cache/**"
]
}
}
}
6 changes: 2 additions & 4 deletions examples/tailwind/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ export default function Home() {
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
href="https://mayank-chaudhari.vercel.app"
target="_blank"
rel="noopener noreferrer">
<a href="https://mayank-chaudhari.vercel.app" rel="noopener noreferrer" target="_blank">
By Mayank
</a>
By Mayank
</a>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# nextjs-darkmode

## 0.3.0

### Minor Changes

- 814e277: Support do not persist prop -> `dp`

### Patch Changes

- 29905cf: "updateInternalDependencies": "patch",

## 0.2.0

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nextjs-darkmode",
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
"private": false,
"version": "0.2.0",
"version": "0.3.0",
"description": "Unleash the Power of React Server Components! Use dark/light mode on your site with confidence, without losing any advantages of React Server Components",
"license": "MPL-2.0",
"main": "./dist/index.js",
Expand Down Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"@types/react": "16.8 - 19",
"next": "10 - 14",
"next": "10 - 15",
"react": "16.8 - 19"
},
"peerDependenciesMeta": {
Expand Down
10 changes: 6 additions & 4 deletions lib/src/client/core/core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface CoreProps {
t?: string;
/** The nonce value for your Content Security Policy. */
nonce?: string;
/** dp -> Do Not Persist. Set this prop when you do not want to persist the mode. e.g., when using Tailwind, but you prefer SSG */
dp?: boolean;
}

/** Modify transition globally to avoid patched transitions */
Expand Down Expand Up @@ -36,8 +38,8 @@ const modifyTransition = (themeTransition = "none", nonce = "") => {
*
* @source - Source code
*/
export const Core = ({ t, nonce }: CoreProps) => {
const [{ m: mode, s: systemMode }, setThemeState] = useStore();
export const Core = ({ t, nonce, dp }: CoreProps) => {
const [{ m: mode, s: systemMode }, setThemeState] = useStore(dp);
const resolvedMode = mode === SYSTEM ? systemMode : mode; // resolvedMode is the actual mode that will be used

useEffect(() => {
Expand Down Expand Up @@ -73,8 +75,8 @@ export const Core = ({ t, nonce }: CoreProps) => {
});
restoreTransitions();
// System mode is decided by current system state and need not be stored in localStorage
localStorage.setItem(COOKIE_KEY, mode);
if (serverTargetEl)
!dp && localStorage.setItem(COOKIE_KEY, mode);
if (!dp && serverTargetEl)
document.cookie = `${COOKIE_KEY}=${resolvedMode};max-age=31536000;SameSite=Strict;`;
}, [resolvedMode, systemMode, mode, t, nonce]);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export interface Store {
}

/** local abstaction of RGS to avoid multiple imports */
export const useStore = () =>
export const useStore = (/** Do not persist */ dp?: boolean) =>
useRGS<Store>("ndm", () =>
typeof localStorage === "undefined"
? /* v8 ignore next */
{ m: SYSTEM, s: DARK as ResolvedScheme }
: {
m: (localStorage.getItem(COOKIE_KEY) ?? SYSTEM) as ColorSchemePreference,
m: (dp ? SYSTEM : localStorage.getItem(COOKIE_KEY) ?? SYSTEM) as ColorSchemePreference,
s: (matchMedia(MEDIA).matches ? DARK : LIGHT) as ResolvedScheme,
},
);
8 changes: 8 additions & 0 deletions packages/shared/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @repo/shared

## 0.0.7

### Patch Changes

- Updated dependencies [29905cf]
- Updated dependencies [814e277]
- [email protected]

## 0.0.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@repo/shared",
"version": "0.0.6",
"version": "0.0.7",
"private": true,
"sideEffects": false,
"main": "./dist/index.js",
Expand Down
Loading

0 comments on commit 3f38206

Please sign in to comment.