Skip to content

Commit 7a15c4b

Browse files
author
Olaf Sulich
committed
📝 Add docs to useTheme hook
1 parent 0de809f commit 7a15c4b

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282

8383
- [`useMeasure`](./docs/useMeasure.md) — gives sizes of an element and its position
8484

85+
- [`useTheme`](./docs/useTheme.md) — dynamically change the appearance of your app using CSS variables with light/dark mode.
86+
8587
<br />
8688

8789
## Technologies

docs/useTheme.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# `useEventListener`
2+
3+
This hook helps you implement light/dark mode in your app, based on prefers-color-scheme and localStorage.
4+
5+
## Usage
6+
7+
Component:
8+
9+
```jsx
10+
import { useEventListener } from 'use-haki';
11+
12+
const App = () => {
13+
const [theme, setTheme] = useTheme();
14+
15+
return (
16+
<section>
17+
<h2>Current theme: {theme}</h2>
18+
<button onClick={() => setTheme('dark')}>Set dark theme<button>
19+
<button onClick={() => setTheme('light')}>Set light theme<button>
20+
<section />
21+
)
22+
};
23+
```
24+
25+
CSS:
26+
27+
```css
28+
html[data-theme='dark'] {
29+
--text-color: #f0f0f0;
30+
--background-body: #1c1c1c;
31+
--other-var: #111111;
32+
}
33+
34+
html[data-theme='light'] {
35+
--text-color: #111111;
36+
--background-body: #fafafa;
37+
--other-var: #ffffff;
38+
}
39+
40+
body {
41+
color: var(--text-color);
42+
background-color: var(--background-body);
43+
}
44+
```
45+
46+
## Reference
47+
48+
```ts
49+
const [theme, setTheme] = useTheme();
50+
```
51+
52+
- **theme** - current theme, based on prefers-color-scheme
53+
- **setTheme** - function that set theme

0 commit comments

Comments
 (0)