You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 813663d
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# jamstacks
2
2
3
-
Shared React components for Jamstacks templates. The initial library provides a dark-mode switch and a shared theme API. It works with React 18.2+ and React 19, including Next.js App Router and static exports, with no Next.js or Tailwind runtime dependency.
3
+
Shared React components for Jamstacks templates. The initial library provides a light/dark/system theme toggle and a shared theme API. It works with React 18.2+ and React 19, including Next.js App Router and static exports, with no Next.js or Tailwind runtime dependency.
4
4
5
5
## Install in a template
6
6
@@ -44,7 +44,7 @@ export default function App() {
44
44
}
45
45
```
46
46
47
-
Use one provider per document and place all switches inside it. Multiple switches share the same state. `DarkModeToggle` is a native keyboard-accessible button with `role="switch"`, a default accessible name of "Dark mode", and a live `aria-checked` value. It supports a forwarded button ref and ordinary button props, including `className`, `style`, `disabled`, `aria-label`, and `onClick`. Calling `event.preventDefault()` in `onClick` cancels the theme change. It stays disabled until hydration finishes so a click cannot overwrite a saved preference before it has loaded.
47
+
Use one provider per document and place all toggles inside it. Multiple toggles share the same state. `DarkModeToggle` is a single native keyboard-accessible button that cycles between three preferences, showing a sun, moon or monitor icon for the current one. From System, a click switches to the opposite of the device's appearance, then to the device's appearance, then back to System, so the first click always changes what the visitor sees. Its accessible name and tooltip include the current preference ("Theme: System" by default; `aria-label` replaces the "Theme" prefix), and `data-theme-preference="light|dark|system"` exposes it to template selectors. It supports a forwarded button ref and ordinary button props, including `className`, `style`, `disabled`, `aria-label`, and `onClick`. Calling `event.preventDefault()` in `onClick` cancels the theme change. It stays disabled until hydration finishes so a click cannot overwrite a saved preference before it has loaded.
48
48
49
49
## Next.js App Router
50
50
@@ -72,7 +72,7 @@ export default function RootLayout({ children }: { children: ReactNode }) {
@@ -108,7 +108,7 @@ An existing template that uses only `@media (prefers-color-scheme: dark)` needs
108
108
body { background: var(--page-background); color: var(--page-ink); }
109
109
```
110
110
111
-
Apply the same pattern to all of the template's dark palette variables, including inherited `--jamstacks-*` component fallbacks. With Tailwind, configure its dark variant to use the `.dark` class rather than a media query. The toggle carries its own inline styles and needs no stylesheet import or global CSS rules. Its colours can be customized through `--jamstacks-toggle-background`, `--jamstacks-toggle-dark-background`, `--jamstacks-toggle-border`, `--jamstacks-toggle-color`, `--jamstacks-toggle-dark-color`, and `--jamstacks-toggle-thumb`. The `style` prop overrides the button's defaults; `className` remains available for template selectors. It preserves the browser's native keyboard-focus outline. Theme changes are instantaneous, with no animation that needs reduced-motion handling.
111
+
Apply the same pattern to all of the template's dark palette variables, including inherited `--jamstacks-*` component fallbacks. With Tailwind, configure its dark variant to use the `.dark` class rather than a media query. The toggle carries its own inline styles and needs no stylesheet import or global CSS rules. Its colours can be customized through `--jamstacks-toggle-background`, `--jamstacks-toggle-dark-background`, `--jamstacks-toggle-border`, `--jamstacks-toggle-color`, and `--jamstacks-toggle-dark-color`. The `style` prop overrides the button's defaults; `className` remains available for template selectors. It preserves the browser's native keyboard-focus outline. Theme changes are instantaneous, with no animation that needs reduced-motion handling.
0 commit comments