Skip to content

Commit 4c5a819

Browse files
committed
Merged PR #7 manually
2 parents 1352bc4 + 68ce8fb commit 4c5a819

7 files changed

Lines changed: 2186 additions & 1939 deletions

File tree

assets/index.cjs.js

Lines changed: 37 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "An updated, cute dark mode toggle button for React.",
55
"module": "dist/index.es.js",
66
"types": "dist/index.d.ts",
7+
"type": "module",
78
"main": "dist/index.cjs.js",
89
"exports": {
910
".": [
@@ -50,6 +51,7 @@
5051
"license": "MIT",
5152
"private": false,
5253
"dependencies": {
54+
"classnames": "^2.3.2",
5355
"react-lottie-player": "^1.4.3"
5456
},
5557
"peerDependencies": {
@@ -58,7 +60,6 @@
5860
},
5961
"devDependencies": {
6062
"@babel/core": "^7.18.6",
61-
"@emotion/css": "^11.9.0",
6263
"@rollup/plugin-typescript": "^8.3.3",
6364
"@storybook/addon-actions": "^6.5.9",
6465
"@storybook/addon-essentials": "^6.5.9",
@@ -86,10 +87,12 @@
8687
"react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0",
8788
"rimraf": "^3.0.2",
8889
"rollup": "^2.76.0",
90+
"rollup-plugin-polyfill-node": "^0.12.0",
8991
"ts-jest": "^28.0.5",
9092
"ts-node": "^10.9.1",
9193
"typescript": "^4.7.4",
92-
"vite": "^3.0.0"
94+
"vite": "^3.0.0",
95+
"vite-plugin-css-injected-by-js": "^3.1.0"
9396
},
9497
"lint-staged": {
9598
"./{src,stories}/**/*.{ts,tsx,js,jsx}": [

src/index.module.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.button {
2+
cursor: pointer;
3+
overflow: hidden;
4+
appearance: none;
5+
border: none;
6+
background-color: transparent;
7+
padding: 0;
8+
}
9+
10+
.player {
11+
display: none;
12+
align-items: center;
13+
justify-content: center;
14+
}
15+
16+
.player--loaded {
17+
display: flex;
18+
}

src/index.tsx

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { css, cx } from "@emotion/css";
1+
import cx from "classnames";
22
import { AnimationSegment } from "lottie-web";
33
import * as React from "react";
44
import LottiePlayerLight from "react-lottie-player/dist/LottiePlayerLight";
55

66
import animationData from "./animationData.json";
7+
import styles from "./index.module.css";
78
import { parseUnit } from "./parseUnit";
89

910
export declare namespace DarkModeToggle {
@@ -68,11 +69,21 @@ export const DarkModeToggle = React.memo<DarkModeToggle.Props>(
6869
<button
6970
onClick={onToggleClick}
7071
aria-hidden="true"
71-
className={cx(buttonStyles(sizeValue, sizeUnit), className)}
72+
style={{
73+
width: `${sizeValue}${sizeUnit}`,
74+
height: `${sizeValue * 0.5}${sizeUnit}`,
75+
}}
76+
className={cx(styles.button, className)}
7277
id={id}
7378
>
7479
<LottiePlayerLight
75-
className={playerStyles(isLottiePlayerMounted, sizeValue, sizeUnit)}
80+
className={cx(styles.player, { [styles["player--loaded"]]: isLottiePlayerMounted })}
81+
style={{
82+
marginTop: `${sizeValue * -0.575}${sizeUnit}`,
83+
marginLeft: `${sizeValue * -0.32}${sizeUnit}`,
84+
width: `${sizeValue * 1.65}${sizeUnit}`,
85+
height: `${sizeValue * 1.65}${sizeUnit}`,
86+
}}
7687
loop={false}
7788
speed={speed}
7889
play={playAnimation}
@@ -98,28 +109,3 @@ function arePropsEqual(prevProps: DarkModeToggle.Props, nextProps: DarkModeToggl
98109
prevProps.id === nextProps.id
99110
);
100111
}
101-
102-
function buttonStyles(sizeValue: number, sizeUnit: string): string {
103-
return css({
104-
cursor: "pointer",
105-
overflow: "hidden",
106-
width: `${sizeValue}${sizeUnit}`,
107-
height: `${sizeValue * 0.5}${sizeUnit}`,
108-
appearance: "none",
109-
border: "none",
110-
backgroundColor: "transparent",
111-
padding: 0,
112-
});
113-
}
114-
115-
function playerStyles(isLoaded: boolean, sizeValue: number, sizeUnit: string): string {
116-
return css({
117-
display: isLoaded ? "flex" : "none",
118-
alignItems: "center",
119-
justifyContent: "center",
120-
marginTop: `${sizeValue * -0.575}${sizeUnit}`,
121-
marginLeft: `${sizeValue * -0.32}${sizeUnit}`,
122-
width: `${sizeValue * 1.65}${sizeUnit}`,
123-
height: `${sizeValue * 1.65}${sizeUnit}`,
124-
});
125-
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"resolveJsonModule": true,
1616
"isolatedModules": true,
1717
"noEmit": true,
18-
"jsx": "react"
18+
"jsx": "react-jsx",
1919
},
2020
"include": ["./src","jest.config.ts", "vite.config.ts"],
2121
}

vite.config.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import typescript from "@rollup/plugin-typescript";
22
import react from "@vitejs/plugin-react";
33
import { defineConfig } from "vite";
4+
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
45

5-
// https://vitejs.dev/config/
6-
export default defineConfig({
7-
plugins: [react()],
6+
import pkg from "./package.json";
7+
8+
const externals = Object.keys(pkg.peerDependencies);
89

10+
export default defineConfig({
11+
plugins: [react(), cssInjectedByJsPlugin({ topExecutionPriority: false })],
912
build: {
1013
lib: {
1114
entry: "src/index.tsx",
@@ -15,7 +18,7 @@ export default defineConfig({
1518

1619
rollupOptions: {
1720
// Don't bundle react or react-dom
18-
external: ["react", "react-dom"],
21+
external: externals,
1922

2023
plugins: [
2124
// Write the types to our dist directory

0 commit comments

Comments
 (0)