maitrid-react-theme-toggle
v0.1.0
Published
Light/Dark theme toggle for React
Maintainers
Readme
@your-scope/react-theme-toggle
Small React component to toggle between light and dark themes.
Install
npm i @your-scope/react-theme-toggle
Usage
import { useState } from "react";
import { ThemeToggle, Theme } from "@your-scope/react-theme-toggle";
export default function App() {
const [theme, setTheme] = useState<Theme>("light");
return (
<div data-theme={theme}>
<ThemeToggle theme={theme} onToggle={setTheme} />
</div>
);
}
13) Add a LICENSE
- Create `LICENSE` (MIT is common). You can copy an MIT template and add your name/year.
14) Build the package
```bash
npm run build- This should create a
distfolder withindex.cjs,index.mjs, andindex.d.ts.
- Test locally using npm pack
npm pack- This creates a
.tgzfile likeyour-scope-react-theme-toggle-0.1.0.tgz.
- Try it in a sample app
- In another test React app:
cd path\to\your\test-app
npm i ..\path\to\react-theme-toggle\your-scope-react-theme-toggle-0.1.0.tgz- Import the component and ensure it renders and toggles.
- Prepare to publish
- Double-check:
nameis available.versionis correct.filesincludesdist,README.md,LICENSE.peerDependencieshas React and ReactDOM.- No secrets in your repo.
- Publish to npm
- If scoped and public:
npm publish --access public- If unscoped:
npm publish- If you enabled 2FA on npm, enter your OTP.
- Verify on npm
- Visit your package page (e.g.,
https://www.npmjs.com/package/@your-scope/react-theme-toggle). - Try installing via:
npm i @your-scope/react-theme-toggle- Update versions later
- For changes:
npm version patch # or minor/major
npm publishCommon gotchas (read this)
- Keep React in peerDependencies, not dependencies.
- Ensure
distexists before publish (prepublishOnly runs build). - If “You do not have permission to publish” appears, the name is taken or scope permissions are missing.
- For monorepos with workspaces, add the package path to the root
workspacesif you use them (optional). - If using GitHub, tag versions automatically when running
npm version(it creates a git tag).
If you want, I can generate the folder structure and files in your repo and run the build/publish commands for you.
