Skip to content

Commit efaaa3d

Browse files
committed
ci: docs
1 parent 34d3b21 commit efaaa3d

3 files changed

Lines changed: 81 additions & 81 deletions

File tree

README.md

Lines changed: 0 additions & 79 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages/theme/README.md

packages/docs/src/stories/Introduction.stories.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Readme from '../../../../README.md'
1+
import Readme from '@marcus-rise/react-theme/README.md'
22
import {Canvas, Meta} from '@storybook/addon-docs';
33
import {Description} from '@storybook/addon-docs/blocks';
44
import {App} from "../components/simple-example.component";

packages/theme/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/theme/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# React theme
2+
3+
Handle system color scheme and user preferences.
4+
5+
## Install
6+
7+
using `npm`
8+
9+
```bash
10+
npm install @marcus-rise/react-theme
11+
```
12+
13+
or using `yarn`
14+
15+
```bash
16+
yarn add @marcus-rise/react-theme
17+
```
18+
19+
## Usage
20+
21+
First of all, we need to initialize `ThemeProvider` context, and after this we can get access with
22+
hook `useTheme`.
23+
24+
```tsx
25+
import {ThemeProvider, useTheme} from "@marcus-rise/react-theme";
26+
27+
const ThemeToggle = () => {
28+
const {isDarkTheme, preferences, toggleTheme} = useTheme();
29+
30+
return (
31+
<>
32+
<button onClick={toggleTheme}>toggle</button>
33+
<br/>
34+
<span>preferences: {preferences}</span>
35+
<br/>
36+
<span>isDarkTheme: {isDarkTheme ? "yes" : "no"}</span>
37+
</>
38+
)
39+
}
40+
41+
const App = () => (
42+
<ThemeProvider>
43+
<ThemeToggle/>
44+
</ThemeProvider>
45+
)
46+
```
47+
48+
## API
49+
50+
### Context provider `ThemeProvider`
51+
52+
To set custom localStorage key set `preferencesStorageKey` property for user preferences
53+
54+
```tsx
55+
<ThemeProvider preferencesStorageKey={"OPTIONAL_APP_THEME_STORAGE_KEY"}>
56+
```
57+
58+
### Hook `useTheme`
59+
60+
- `isDarkTheme` is a`boolean` what color scheme is selected, basing on user preferences and system
61+
settings
62+
- `preferences` is a `string` form `enum`
63+
64+
```ts
65+
enum ThemePreference {
66+
DARK = "dark",
67+
LIGHT = "light",
68+
SYSTEM = "system",
69+
}
70+
```
71+
72+
you can import this enum directly
73+
74+
```ts
75+
import {ThemeProvider} from "@marcus-rise/react-theme";
76+
```
77+
78+
- `toggleTheme` is a `function`, that toggle preferences from `system` -> `light` -> `dark`
79+

0 commit comments

Comments
 (0)