diff --git a/.changeset/late-rivers-kick.md b/.changeset/late-rivers-kick.md new file mode 100644 index 00000000..986aba71 --- /dev/null +++ b/.changeset/late-rivers-kick.md @@ -0,0 +1,5 @@ +--- +"react18-themes": major +--- + +Do not export force-theme and force-color-scheme components from the root. diff --git a/.changeset/popular-otters-whisper.md b/.changeset/popular-otters-whisper.md new file mode 100644 index 00000000..c69d40d1 --- /dev/null +++ b/.changeset/popular-otters-whisper.md @@ -0,0 +1,5 @@ +--- +"react18-themes": major +--- + +Remove support for passing styles object from CSS modules or CSS-in-JS for the theme classes. diff --git a/.changeset/pre.json b/.changeset/pre.json new file mode 100644 index 00000000..fd76f852 --- /dev/null +++ b/.changeset/pre.json @@ -0,0 +1,18 @@ +{ + "mode": "exit", + "tag": "alpha", + "initialVersions": { + "@example/app": "0.0.0", + "@example/pages": "0.0.0", + "@example/vite": "0.0.0", + "react18-themes": "4.0.0-alpha.0", + "@repo/eslint-config": "0.0.0", + "@repo/typescript-config": "0.0.0", + "@repo/shared": "0.0.2-alpha.0", + "@repo/scripts": "0.0.0" + }, + "changesets": [ + "late-rivers-kick", + "popular-otters-whisper" + ] +} diff --git a/README.md b/README.md index aa6f7dad..73a03c36 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ interface UseThemeYield { ### Next.js App Router ```tsx -import { ForceTheme } from "react18-themes"; +import { ForceTheme } from "react18-themes/force-theme"; function MyPage() { return ( diff --git a/examples/app-router/src/app/forced-color-scheme/[colorScheme]/page.tsx b/examples/app-router/src/app/forced-color-scheme/[colorScheme]/page.tsx index deb9558e..6ab12160 100644 --- a/examples/app-router/src/app/forced-color-scheme/[colorScheme]/page.tsx +++ b/examples/app-router/src/app/forced-color-scheme/[colorScheme]/page.tsx @@ -1,5 +1,5 @@ import type { ColorSchemeType } from "react18-themes"; -import { ForceColorScheme } from "react18-themes"; +import { ForceColorScheme } from "react18-themes/force-color-scheme"; interface PageWithForcedColorSchemeProps { params: { colorScheme: ColorSchemeType }; diff --git a/examples/app-router/src/app/forced-color-scheme/page.tsx b/examples/app-router/src/app/forced-color-scheme/page.tsx index e3dc4a5c..d0cc5fda 100644 --- a/examples/app-router/src/app/forced-color-scheme/page.tsx +++ b/examples/app-router/src/app/forced-color-scheme/page.tsx @@ -1,4 +1,4 @@ -import { ForceColorScheme } from "react18-themes"; +import { ForceColorScheme } from "react18-themes/force-color-scheme"; export default function PageWithForcedColorScheme(): JSX.Element { return ( diff --git a/examples/app-router/src/app/themed-page/[theme]/page.tsx b/examples/app-router/src/app/themed-page/[theme]/page.tsx index 66945890..93bc00c0 100644 --- a/examples/app-router/src/app/themed-page/[theme]/page.tsx +++ b/examples/app-router/src/app/themed-page/[theme]/page.tsx @@ -1,4 +1,4 @@ -import { ForceTheme } from "react18-themes"; +import { ForceTheme } from "react18-themes/force-theme"; interface PageProps { params: { theme: string }; diff --git a/examples/app-router/src/app/themed-page/page.tsx b/examples/app-router/src/app/themed-page/page.tsx index 13f8d750..aa97870a 100644 --- a/examples/app-router/src/app/themed-page/page.tsx +++ b/examples/app-router/src/app/themed-page/page.tsx @@ -1,4 +1,4 @@ -import { ForceTheme } from "react18-themes"; +import { ForceTheme } from "react18-themes/force-theme"; export default function PageWithForcedTheme(): JSX.Element { return ( diff --git a/examples/pages-router/src/pages/forced-color-scheme/[colorScheme].tsx b/examples/pages-router/src/pages/forced-color-scheme/[colorScheme].tsx index 42cbf60f..feda127a 100644 --- a/examples/pages-router/src/pages/forced-color-scheme/[colorScheme].tsx +++ b/examples/pages-router/src/pages/forced-color-scheme/[colorScheme].tsx @@ -1,5 +1,6 @@ import { useRouter } from "next/router"; -import { ColorSchemeType, ForceColorScheme } from "react18-themes"; +import { ColorSchemeType } from "react18-themes"; +import { ForceColorScheme } from "react18-themes/client/force-color-scheme"; export default function PageWithForcedColorScheme() { const router = useRouter(); diff --git a/examples/pages-router/src/pages/themed-page/[theme].tsx b/examples/pages-router/src/pages/themed-page/[theme].tsx index f5e02b9a..92f97a08 100644 --- a/examples/pages-router/src/pages/themed-page/[theme].tsx +++ b/examples/pages-router/src/pages/themed-page/[theme].tsx @@ -1,5 +1,5 @@ import { useRouter } from "next/router"; -import { ForceTheme } from "react18-themes"; +import { ForceTheme } from "react18-themes/force-theme"; export default function PageWithForcedTheme() { const router = useRouter(); diff --git a/examples/vite/src/app/forced-color-scheme-page.tsx b/examples/vite/src/app/forced-color-scheme-page.tsx index a0ba9a6e..9c9bfbdc 100644 --- a/examples/vite/src/app/forced-color-scheme-page.tsx +++ b/examples/vite/src/app/forced-color-scheme-page.tsx @@ -1,7 +1,8 @@ import React from "react"; -import { ColorSchemeType, ForceColorScheme } from "react18-themes"; +import { ColorSchemeType } from "react18-themes"; import { Link, useParams } from "react-router-dom"; import { Header } from "@repo/shared"; +import { ForceColorScheme } from "react18-themes/client/force-color-scheme"; export default function ForcedColorSchemePage() { const { colorScheme } = useParams(); diff --git a/examples/vite/src/app/themed-page.tsx b/examples/vite/src/app/themed-page.tsx index 3830d5c7..e8816c31 100644 --- a/examples/vite/src/app/themed-page.tsx +++ b/examples/vite/src/app/themed-page.tsx @@ -1,6 +1,6 @@ import React from "react"; import { Link, useParams } from "react-router-dom"; -import { ForceTheme } from "react18-themes"; +import { ForceTheme } from "react18-themes/force-theme"; import { Header } from "@repo/shared"; export default function ThemedPage() { diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index ee22cfd9..ced05b83 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -1,5 +1,12 @@ # react18-themes +## 4.0.0-alpha.0 + +### Major Changes + +- a4b539b: Do not export force-theme and force-color-scheme components from the root. +- 88f5f17: Remove support for passing styles object from CSS modules or CSS-in-JS for the theme classes. + ## 3.2.0 ### Minor Changes diff --git a/lib/README.md b/lib/README.md index aa6f7dad..73a03c36 100644 --- a/lib/README.md +++ b/lib/README.md @@ -221,7 +221,7 @@ interface UseThemeYield { ### Next.js App Router ```tsx -import { ForceTheme } from "react18-themes"; +import { ForceTheme } from "react18-themes/force-theme"; function MyPage() { return ( diff --git a/lib/package.json b/lib/package.json index 02e5fa04..5ea2135e 100644 --- a/lib/package.json +++ b/lib/package.json @@ -2,7 +2,7 @@ "name": "react18-themes", "author": "Mayank Kumar Chaudhari ", "private": false, - "version": "3.2.0", + "version": "4.0.0-alpha.0", "description": "Unleash the Power of React Server Components! Use multiple themes on your site with confidence, without losing any advantages of React Server Components.", "license": "MPL-2.0", "main": "./dist/index.js", @@ -46,6 +46,26 @@ "import": "./dist/client/theme-switcher/index.mjs", "types": "./dist/client/theme-switcher/index.d.ts" }, + "./client/force-color-scheme": { + "require": "./dist/client/force-color-scheme/index.js", + "import": "./dist/client/force-color-scheme/index.mjs", + "types": "./dist/client/force-color-scheme/index.d.ts" + }, + "./force-color-scheme": { + "require": "./dist/client/force-color-scheme/index.js", + "import": "./dist/client/force-color-scheme/index.mjs", + "types": "./dist/client/force-color-scheme/index.d.ts" + }, + "./client/force-theme": { + "require": "./dist/client/force-theme/index.js", + "import": "./dist/client/force-theme/index.mjs", + "types": "./dist/client/force-theme/index.d.ts" + }, + "./force-theme": { + "require": "./dist/client/force-theme/index.js", + "import": "./dist/client/force-theme/index.mjs", + "types": "./dist/client/force-theme/index.d.ts" + }, "./server": { "require": "./dist/server/index.js", "import": "./dist/server/index.mjs", @@ -81,9 +101,9 @@ "import": "./dist/hooks/index.mjs", "types": "./dist/hooks/index.d.ts" }, - "./styles.css": "./dist/index.css", - "./styles": "./dist/index.css", - "./css": "./dist/index.css" + "./styles.css": "./dist/client/color-switch/index.css", + "./styles": "./dist/client/color-switch/index.css", + "./css": "./dist/client/color-switch/index.css" }, "scripts": { "build": "tsup && tsc -p tsconfig-build.json", diff --git a/lib/src/client/color-switch/color-switch.module.scss b/lib/src/client/color-switch/color-switch.module.scss index 8a10d3f1..d0a27ad4 100644 --- a/lib/src/client/color-switch/color-switch.module.scss +++ b/lib/src/client/color-switch/color-switch.module.scss @@ -1,4 +1,4 @@ -.color-switch { +.s { all: unset; position: relative; box-shadow: none; @@ -6,46 +6,46 @@ border-radius: 50%; border: 1px dashed gray; cursor: pointer; - --size: 25px; - height: var(--size); - width: var(--size); + --s: 25px; + height: var(--s); + width: var(--s); transition: all 0.3s ease-in-out 0s !important; } -[data-csp="system"] .color-switch::after, -[data-csp="system"] ~ .color-switch::after, -[data-csp="system"] ~ * .color-switch::after { +[data-csp="system"] .s::after, +[data-csp="system"] ~ .s::after, +[data-csp="system"] ~ * .s::after { position: absolute; height: 100%; width: 100%; top: 0; left: 0; font-weight: 600; - font-size: calc(1 * var(--size) / 2); + font-size: calc(1 * var(--s) / 2); display: flex; align-items: center; justify-content: center; content: "A"; } -[data-csp="dark"] .color-switch, -[data-csp="dark"] ~ .color-switch, -[data-csp="dark"] ~ * .color-switch { - box-shadow: calc(var(--size) / 4) calc(var(--size) / -4) calc(var(--size) / 8) inset #fff; +[data-csp="dark"] .s, +[data-csp="dark"] ~ .s, +[data-csp="dark"] ~ * .s { + box-shadow: calc(var(--s) / 4) calc(var(--s) / -4) calc(var(--s) / 8) inset #fff; border: none; background: transparent; - animation: swing linear 0.5s; + animation: a linear 0.5s; } -[data-csp="light"] .color-switch, -[data-csp="light"] ~ .color-switch, -[data-csp="light"] ~ * .color-switch { +[data-csp="light"] .s, +[data-csp="light"] ~ .s, +[data-csp="light"] ~ * .s { box-shadow: 0 0 50px 10px yellow; background-color: yellow; border: 1px solid orangered; } -@keyframes swing { +@keyframes a { 40% { transform: rotate(-15deg); } diff --git a/lib/src/client/color-switch/color-switch.tsx b/lib/src/client/color-switch/color-switch.tsx index 1d21cd7f..0cd64b34 100644 --- a/lib/src/client/color-switch/color-switch.tsx +++ b/lib/src/client/color-switch/color-switch.tsx @@ -7,7 +7,6 @@ export interface ColorSwitchProps extends HTMLProps { size?: number; /** Skip system colorScheme while toggling */ skipSystem?: boolean; - targetSelector?: string; } /** @@ -24,16 +23,10 @@ export interface ColorSwitchProps extends HTMLProps { * * ``` */ -export const ColorSwitch = ({ - size = 25, - skipSystem, - targetSelector, - className, - ...props -}: ColorSwitchProps) => { - const { toggleColorScheme } = useTheme(targetSelector); +export const ColorSwitch = ({ size = 25, skipSystem, className, ...props }: ColorSwitchProps) => { + const { toggleColorScheme } = useTheme(); - const cls = [styles["color-switch"], className].join(" "); + const cls = [styles.s, className].join(" "); return (