Skip to content

Commit 8f29037

Browse files
authored
Merge pull request #49 from JoseRFelix/chore/pnpm-ci-react-compat-darkmode-switch
Modernize build setup and harden DarkModeSwitch for React 16–19
2 parents 91b30e5 + 99a8e3e commit 8f29037

16 files changed

Lines changed: 5673 additions & 11612 deletions

File tree

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "restricted",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.github/workflows/main.yml

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,77 @@ jobs:
66

77
steps:
88
- name: Begin CI...
9-
uses: actions/checkout@v2
9+
uses: actions/checkout@v4
1010

11-
- name: Use Node 12
12-
uses: actions/setup-node@v1
13-
with:
14-
node-version: 12.x
11+
- name: Setup pnpm
12+
uses: pnpm/action-setup@v4
1513

16-
- name: Use cached node_modules
17-
uses: actions/cache@v1
14+
- name: Use Node 20
15+
uses: actions/setup-node@v4
1816
with:
19-
path: node_modules
20-
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
21-
restore-keys: |
22-
nodeModules-
17+
node-version: 20.x
18+
cache: pnpm
19+
20+
- name: Setup Bun
21+
uses: oven-sh/setup-bun@v2
2322

2423
- name: Install dependencies
25-
run: yarn install --frozen-lockfile
24+
run: pnpm install --frozen-lockfile
2625
env:
2726
CI: true
2827

2928
- name: Lint
30-
run: yarn lint
29+
run: pnpm lint
3130
env:
3231
CI: true
3332

3433
- name: Test
35-
run: yarn test --ci --coverage --maxWorkers=2
34+
run: pnpm test
3635
env:
3736
CI: true
3837

3938
- name: Build
40-
run: yarn build
39+
run: pnpm build
40+
env:
41+
CI: true
42+
43+
react-compatibility:
44+
runs-on: ubuntu-latest
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
react-version: [16.14.0, 17.0.2, 18.3.1, 19.0.0]
49+
50+
steps:
51+
- name: Begin compatibility checks...
52+
uses: actions/checkout@v4
53+
54+
- name: Setup pnpm
55+
uses: pnpm/action-setup@v4
56+
57+
- name: Use Node 20
58+
uses: actions/setup-node@v4
59+
with:
60+
node-version: 20.x
61+
cache: pnpm
62+
63+
- name: Setup Bun
64+
uses: oven-sh/setup-bun@v2
65+
66+
- name: Install dependencies
67+
run: pnpm install --frozen-lockfile
68+
env:
69+
CI: true
70+
71+
- name: Test React ${{ matrix.react-version }} compatibility
72+
run: pnpm add -Dw react@${{ matrix.react-version }} react-dom@${{ matrix.react-version }} --ignore-scripts
73+
74+
- name: Run tests
75+
run: pnpm test
76+
env:
77+
CI: true
78+
79+
- name: Build with matrix React version
80+
run: pnpm build
4181
env:
4282
CI: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
*.log
22
.DS_Store
33
node_modules
4+
.pnpm-store
45
.cache
56
dist
7+
.parcel-cache

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm lint

README.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<a href="https://www.npmjs.com/package/react-toggle-dark-mode" target="_blank">
66
<img alt="Version" src="https://img.shields.io/npm/v/react-toggle-dark-mode.svg">
77
</a>
8-
<img src="https://img.shields.io/badge/node-%3E%3D10-blue.svg" />
8+
<img src="https://img.shields.io/badge/node-%3E%3D20-blue.svg" />
99
<a href="#" target="_blank">
1010
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
1111
</a>
@@ -17,29 +17,31 @@
1717

1818
> 🌃 Animated dark mode toggle as seen in blogs!
1919
20+
Supports React 16.14+ through 19.
21+
2022
![Interactive sun and moon transition](./docs/demo.gif)
2123

2224
## Prerequisites
2325

24-
- node >=10
26+
- node >=20
2527

2628
## Installation
2729

2830
```shell
2931
npm i react-toggle-dark-mode
3032
```
3133

32-
or with Yarn:
34+
or with pnpm:
3335

3436
```shell
35-
yarn add react-toggle-dark-mode
37+
pnpm add react-toggle-dark-mode
3638
```
3739

3840
## Usage
3941

4042
```jsx
4143
import * as React from 'react';
42-
import * as ReactDOM from 'react-dom';
44+
import { createRoot } from 'react-dom/client';
4345
import { DarkModeSwitch } from 'react-toggle-dark-mode';
4446

4547
const App = () => {
@@ -58,6 +60,14 @@ const App = () => {
5860
/>
5961
);
6062
};
63+
64+
const rootElement = document.getElementById('root');
65+
66+
if (!rootElement) {
67+
throw new Error('Unable to find root element');
68+
}
69+
70+
createRoot(rootElement).render(<App />);
6171
```
6272

6373
## API
@@ -66,15 +76,20 @@ const App = () => {
6676

6777
#### Props
6878

69-
| Name | Type | Default Value | Description |
70-
| ------------------- | ---------------------------- | ------------------------------- | ----------------------------------------- |
71-
| onChange | \(checked: boolean\) => void | | Event that triggers when icon is clicked. |
72-
| checked | boolean | false | Current icon state. |
73-
| style | Object | | CSS properties object. |
74-
| size | number | 24 | SVG size. |
75-
| animationProperties | Object | defaultProperties \(see below\) | Override default animation properties. |
76-
| moonColor | string | white | Color of the moon. |
77-
| sunColor | string | black | Color of the sun. |
79+
| Name | Type | Default Value | Description |
80+
| ------------------- | -------------------------------------------------- | ------------------------------- | -------------------------------------------------------------------------------------------- |
81+
| onChange | \(checked: boolean\) => void | | Event that triggers when icon is clicked. |
82+
| checked | boolean | false | Current icon state. |
83+
| style | React.CSSProperties | | CSS properties object applied to the button wrapper. |
84+
| size | number \| string | 24 | SVG size. |
85+
| animationProperties | Partial animation properties object | defaultProperties \(see below\) | Override only the fields you want; missing fields are merged with defaults. |
86+
| moonColor | string | white | Color of the moon. |
87+
| sunColor | string | black | Color of the sun. |
88+
| aria-label | string | Toggle dark mode | Accessible label for the control. Ignored when `aria-labelledby` is provided. |
89+
| aria-labelledby | string | | Links the control to an external label element. |
90+
| onClick | \(event: React.MouseEvent<HTMLButtonElement>\)=>void | | Optional button click handler. Call `event.preventDefault()` to prevent toggling on click. |
91+
92+
All valid button attributes (except `children`) are forwarded to the underlying button element.
7893

7994
### Default Animation Properties
8095

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
<body style="margin: 0 ;">
1111
<div id="root"></div>
12-
<script src="./index.tsx"></script>
12+
<script type="module" src="./index.tsx"></script>
1313
</body>
1414
</html>

example/index.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import 'react-app-polyfill/ie11';
21
import * as React from 'react';
3-
import * as ReactDOM from 'react-dom';
4-
import { DarkModeSwitch } from '../.';
2+
import { createRoot } from 'react-dom/client';
3+
import { DarkModeSwitch } from '../src';
54

65
function arrayN(size: number) {
76
return new Array(size).fill(undefined);
@@ -16,7 +15,7 @@ const App = () => {
1615
};
1716

1817
const addToggle = () => {
19-
setToggleAmount(prevValue => prevValue + 1);
18+
setToggleAmount((prevValue) => prevValue + 1);
2019
};
2120

2221
return (
@@ -50,17 +49,24 @@ const App = () => {
5049
moonColor="red"
5150
size={30}
5251
/>
53-
{arrayN(toggleAmount).map(() => (
52+
{arrayN(toggleAmount).map((_, index) => (
5453
<DarkModeSwitch
54+
key={index}
5555
style={{ marginBottom: '2rem' }}
5656
checked={isDarkMode}
5757
onChange={toggleDarkMode}
58-
size={Math.floor(Math.random() * 60) + 1}
58+
size={Math.floor(Math.random() * 20) + 20}
5959
/>
6060
))}
6161
<button onClick={addToggle}>Add toggle</button>
6262
</div>
6363
);
6464
};
6565

66-
ReactDOM.render(<App />, document.getElementById('root'));
66+
const rootElement = document.getElementById('root');
67+
68+
if (!rootElement) {
69+
throw new Error('Unable to find root element');
70+
}
71+
72+
createRoot(rootElement).render(<App />);

example/package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
{
22
"name": "example",
33
"version": "1.0.0",
4-
"main": "index.js",
54
"license": "MIT",
65
"scripts": {
76
"start": "parcel index.html",
87
"build": "parcel build index.html"
98
},
109
"dependencies": {
11-
"react-app-polyfill": "^1.0.0"
12-
},
13-
"alias": {
14-
"react": "../node_modules/react",
15-
"react-dom": "../node_modules/react-dom/profiling",
16-
"scheduler/tracing": "../node_modules/scheduler/tracing-profiling"
10+
"react": "19.0.0",
11+
"react-dom": "19.0.0"
1712
},
1813
"devDependencies": {
19-
"@types/react": "^16.9.11",
20-
"@types/react-dom": "^16.8.4",
21-
"parcel": "^1.12.3",
14+
"@types/react": "^19.2.14",
15+
"@types/react-dom": "^19.2.3",
16+
"parcel": "^2.16.4",
2217
"typescript": "^3.4.5"
2318
}
2419
}

0 commit comments

Comments
 (0)