{"_id":"@arsalanshaikhh/auto-time-theme-react","_rev":"2-9c99aa701365f1c7ef057efd50d31fc2","name":"@arsalanshaikhh/auto-time-theme-react","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@arsalanshaikhh/auto-time-theme-react","version":"1.0.0","keywords":["react","theme","dark-mode","light-mode","auto-theme","time-based-theme","theming"],"author":{"name":"Arsalan Shaikh"},"license":"MIT","_id":"@arsalanshaikhh/auto-time-theme-react@1.0.0","maintainers":[{"name":"arsalanshaikhh","email":"arsalan.developer7@gmail.com"}],"homepage":"https://github.com/arsalanshaikhh/smart-auto-theme-ar","bugs":{"url":"https://github.com/arsalanshaikhh/smart-auto-theme-ar/issues"},"dist":{"shasum":"362a07c86c8156f732c590c9f2d5c07ad588f25f","tarball":"https://registry.npmjs.org/@arsalanshaikhh/auto-time-theme-react/-/auto-time-theme-react-1.0.0.tgz","fileCount":14,"integrity":"sha512-t5JTqmIt/DfL8cxXhFqkM6wbyGO1xWoaMl26mDc1vMLoFACaBCiarOsCoCC/CBkFbm2hJ26c5p9QWBV0bjNiRg==","signatures":[{"sig":"MEQCIBHl1XSTBfc2kaIX0Zy6Kah4CBbJa4iWiiaEL5WBj9OLAiALzRCxozSVxE2OH7XhrS59J3QuHXVdECja1s+k4VmjbQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":86289},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"fbb70c9f2e9c7e7fe51531ac47889a888e83fabf","prepare":"npm run build","scripts":{"dev":"node esbuild.config.js --watch","demo":"cd demo && npm run dev","build":"node esbuild.config.js && tsc --emitDeclarationOnly --declaration --outDir dist","typecheck":"tsc --noEmit","demo:build":"cd demo && npm run build"},"_npmUser":{"name":"arsalanshaikhh","email":"arsalan.developer7@gmail.com"},"repository":{"url":"git+https://github.com/arsalanshaikhh/smart-auto-theme-ar.git","type":"git"},"_npmVersion":"10.7.0","description":"A lightweight React npm package that automatically switches between light and dark themes based on the user's local time, with full manual override support.","directories":{},"_nodeVersion":"18.20.4","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"esbuild":"^0.19.0","typescript":"^5.0.0","@types/react":"^18.2.0","@types/react-dom":"^18.2.0"},"peerDependencies":{"react":">=17.0.0","react-dom":">=17.0.0"},"_npmOperationalInternal":{"tmp":"tmp/auto-time-theme-react_1.0.0_1767839152827_0.6264949506046957","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@arsalanshaikhh/auto-time-theme-react","version":"1.0.2","description":"A lightweight React npm package that automatically switches between light and dark themes based on the user's local time, with full manual override support.","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/arsalanshaikhh/smart-auto-theme-ar.git"},"homepage":"https://github.com/arsalanshaikhh/smart-auto-theme-ar#readme","demo":"https://demo-qhqosmydg-arsalanshaikhhs-projects.vercel.app","bugs":{"url":"https://github.com/arsalanshaikhh/smart-auto-theme-ar/issues"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"build":"node esbuild.config.js && tsc --emitDeclarationOnly --declaration --outDir dist","dev":"node esbuild.config.js --watch","typecheck":"tsc --noEmit","demo":"cd demo && npm run dev","demo:build":"cd demo && npm run build"},"prepare":"npm run build","publishConfig":{"access":"public"},"keywords":["react","theme","dark-mode","light-mode","auto-theme","time-based-theme","theming"],"author":{"name":"Arsalan Shaikh"},"license":"MIT","peerDependencies":{"react":">=17.0.0","react-dom":">=17.0.0"},"devDependencies":{"@types/react":"^18.2.0","@types/react-dom":"^18.2.0","esbuild":"^0.19.0","typescript":"^5.0.0"},"_id":"@arsalanshaikhh/auto-time-theme-react@1.0.2","gitHead":"5a11baeb98acb6f47c04ca951c8b1b73b240fbf2","_nodeVersion":"18.20.4","_npmVersion":"10.7.0","dist":{"integrity":"sha512-Okbj1hMn1F0+cLhiR/8fnZdNcP79b242JvYlcZtF9L1mcXvV3jMK+0uqEv8OrzPeIPL9f0vfdzyUppT3Cd81HQ==","shasum":"2a3a440811030317e626f91f336d4ac1a154c214","tarball":"https://registry.npmjs.org/@arsalanshaikhh/auto-time-theme-react/-/auto-time-theme-react-1.0.2.tgz","fileCount":14,"unpackedSize":86864,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBfF2Dj+9GOObbIC7ZT6RqAsR+29rYwXKEy/T6t5zgsnAiA/4ZnJ9Jf4vOj8QICauCZj8jOile5FSswYfpuK1KAqzw=="}]},"_npmUser":{"name":"arsalanshaikhh","email":"arsalan.developer7@gmail.com"},"directories":{},"maintainers":[{"name":"arsalanshaikhh","email":"arsalan.developer7@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/auto-time-theme-react_1.0.2_1767840211861_0.16665782503484539"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-08T02:25:52.662Z","modified":"2026-01-08T02:43:32.190Z","1.0.0":"2026-01-08T02:25:53.000Z","1.0.2":"2026-01-08T02:43:32.001Z"},"bugs":{"url":"https://github.com/arsalanshaikhh/smart-auto-theme-ar/issues"},"author":{"name":"Arsalan Shaikh"},"license":"MIT","homepage":"https://github.com/arsalanshaikhh/smart-auto-theme-ar#readme","keywords":["react","theme","dark-mode","light-mode","auto-theme","time-based-theme","theming"],"repository":{"type":"git","url":"git+https://github.com/arsalanshaikhh/smart-auto-theme-ar.git"},"description":"A lightweight React npm package that automatically switches between light and dark themes based on the user's local time, with full manual override support.","maintainers":[{"name":"arsalanshaikhh","email":"arsalan.developer7@gmail.com"}],"readme":"# Auto React Theme\r\n\r\n[![npm version](https://img.shields.io/npm/v/@arsalanshaikhh/auto-time-theme-react.svg)](https://npmjs.com/package/@arsalanshaikhh/auto-time-theme-react)\r\n[![License](https://img.shields.io/npm/l/@arsalanshaikhh/auto-time-theme-react.svg)](https://opensource.org/licenses/MIT)\r\n[![Live Demo](https://img.shields.io/badge/Live-Demo-blue)](https://demo-qhqosmydg-arsalanshaikhhs-projects.vercel.app)\r\n\r\nA lightweight React npm package that automatically switches between light and dark themes based on the user's local time, with full manual override support.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @arsalanshaikhh/auto-time-theme-react\r\n```\r\n\r\nor\r\n\r\n```bash\r\nyarn add @arsalanshaikhh/auto-time-theme-react\r\n```\r\n\r\n## Live Demo\r\n\r\nTry the live demo at: [https://demo-qhqosmydg-arsalanshaikhhs-projects.vercel.app](https://demo-qhqosmydg-arsalanshaikhhs-projects.vercel.app)\r\n\r\n## Quick Start\r\n\r\n### 1. Wrap your app with the provider\r\n\r\n```tsx\r\nimport { AutoThemeProvider } from '@arsalanshaikhh/auto-time-theme-react';\r\n\r\nfunction App() {\r\n  return (\r\n    <AutoThemeProvider>\r\n      <YourApp />\r\n    </AutoThemeProvider>\r\n  );\r\n}\r\n```\r\n\r\n### 2. Use the hook in your components\r\n\r\n```tsx\r\nimport { useAutoTheme } from '@arsalanshaikhh/auto-time-theme-react';\r\n\r\nfunction ThemeToggle() {\r\n  const { theme, mode, setLight, setDark, setAuto, toggleTheme } = useAutoTheme();\r\n\r\n  return (\r\n    <div>\r\n      <p>Current theme: {theme}</p>\r\n      <p>Current mode: {mode}</p>\r\n      <button onClick={setLight}>Light</button>\r\n      <button onClick={setDark}>Dark</button>\r\n      <button onClick={setAuto}>Auto</button>\r\n      <button onClick={toggleTheme}>Toggle</button>\r\n    </div>\r\n  );\r\n}\r\n```\r\n\r\n## API Reference\r\n\r\n### AutoThemeProvider Props\r\n\r\n| Prop | Type | Default | Description |\r\n|------|------|---------|-------------|\r\n| `lightStart` | `string` | `\"07:00\"` | Start time for light mode (HH:MM format) |\r\n| `darkStart` | `string` | `\"22:00\"` | Start time for dark mode (HH:MM format) |\r\n| `defaultMode` | `\"auto\" \\| \"light\" \\| \"dark\"` | `\"auto\"` | Initial mode when no stored preference exists |\r\n| `storageKey` | `string` | `\"auto-theme-mode\"` | LocalStorage key for storing user preference |\r\n| `applyTo` | `\"html\" \\| \"body\"` | `\"html\"` | DOM element to apply the `data-theme` attribute to |\r\n| `onThemeChange` | `(theme: Theme, mode: Mode) => void` | `undefined` | Callback invoked when the theme changes |\r\n\r\n### useAutoTheme Return Value\r\n\r\n| Property | Type | Description |\r\n|----------|------|-------------|\r\n| `theme` | `Theme` | Current theme (`\"light\"` or `\"dark\"`) |\r\n| `mode` | `Mode` | Current mode (`\"auto\"`, `\"light\"`, or `\"dark\"`) |\r\n| `setLight` | `() => void` | Set the mode to light (manual override) |\r\n| `setDark` | `() => void` | Set the mode to dark (manual override) |\r\n| `setAuto` | `() => void` | Set the mode to auto (enables time-based switching) |\r\n| `toggleTheme` | `() => void` | Toggle between light and dark themes |\r\n\r\n### Additional Hooks\r\n\r\n```tsx\r\n// Get only the current theme\r\nimport { useTheme } from '@arsalanshaikhh/auto-time-theme-react';\r\nconst theme = useTheme();\r\n\r\n// Get only the current mode\r\nimport { useMode } from '@arsalanshaikhh/auto-time-theme-react';\r\nconst mode = useMode();\r\n```\r\n\r\n## Theme Application Strategy\r\n\r\nThe package does not apply styles directly. It only adds a `data-theme` attribute to the specified DOM element:\r\n\r\n```html\r\n<html data-theme=\"light\">\r\n<!-- or -->\r\n<html data-theme=\"dark\">\r\n```\r\n\r\nUse CSS variables with the attribute selector:\r\n\r\n```css\r\n[data-theme=\"light\"] {\r\n  --bg-color: #ffffff;\r\n  --text-color: #111111;\r\n}\r\n\r\n[data-theme=\"dark\"] {\r\n  --bg-color: #111111;\r\n  --text-color: #ffffff;\r\n}\r\n\r\nbody {\r\n  background-color: var(--bg-color);\r\n  color: var(--text-color);\r\n}\r\n```\r\n\r\n## Default Behavior\r\n\r\n- **Light Theme**: 7:00 AM to 10:00 PM\r\n- **Dark Theme**: 10:00 PM to 7:00 AM\r\n\r\nTime is calculated using the user's local system time. Theme updates automatically when the time crosses a boundary without requiring a page refresh.\r\n\r\n## Theme Priority Order\r\n\r\n1. **User manual selection** - If the user has selected a manual theme\r\n2. **Time-based automatic logic** - If mode is set to auto\r\n3. **Default fallback** - The defaultMode prop value\r\n\r\nIf the user selects a manual theme, time-based switching is paused until auto mode is restored.\r\n\r\n## Configuration Examples\r\n\r\n### Custom Time Ranges\r\n\r\n```tsx\r\n<AutoThemeProvider\r\n  config={{\r\n    lightStart: '06:00',  // Light theme starts at 6 AM\r\n    darkStart: '20:00',   // Dark theme starts at 8 PM\r\n  }}\r\n>\r\n  <App />\r\n</AutoThemeProvider>\r\n```\r\n\r\n### Custom Storage Key\r\n\r\n```tsx\r\n<AutoThemeProvider\r\n  config={{\r\n    storageKey: 'my-app-theme-preference',\r\n  }}\r\n>\r\n  <App />\r\n</AutoThemeProvider>\r\n```\r\n\r\n### Theme Change Callback\r\n\r\n```tsx\r\n<AutoThemeProvider\r\n  config={{\r\n    onThemeChange: (theme, mode) => {\r\n      console.log(`Theme changed to ${theme} (mode: ${mode})`);\r\n      // You can send analytics events here\r\n    },\r\n  }}\r\n>\r\n  <App />\r\n</AutoThemeProvider>\r\n```\r\n\r\n### Apply to Body Instead of Html\r\n\r\n```tsx\r\n<AutoThemeProvider\r\n  config={{\r\n    applyTo: 'body',\r\n  }}\r\n>\r\n  <App />\r\n</AutoThemeProvider>\r\n```\r\n\r\n## Advanced Usage\r\n\r\n### With a Theme Toggle Component\r\n\r\n```tsx\r\nimport { useAutoTheme } from '@arsalanshaikhh/auto-time-theme-react';\r\n\r\nfunction ThemeToggle() {\r\n  const { theme, mode, setLight, setDark, setAuto, toggleTheme } = useAutoTheme();\r\n\r\n  return (\r\n    <div className=\"theme-toggle\">\r\n      <button\r\n        onClick={setLight}\r\n        className={mode === 'light' ? 'active' : ''}\r\n      >\r\n        ☀️ Light\r\n      </button>\r\n      <button\r\n        onClick={setDark}\r\n        className={mode === 'dark' ? 'active' : ''}\r\n      >\r\n        🌙 Dark\r\n      </button>\r\n      <button\r\n        onClick={setAuto}\r\n        className={mode === 'auto' ? 'active' : ''}\r\n      >\r\n        ⏰ Auto\r\n      </button>\r\n    </div>\r\n  );\r\n}\r\n```\r\n\r\n### Using with CSS-in-JS\r\n\r\n```tsx\r\nimport { useTheme } from '@arsalanshaikhh/auto-time-theme-react';\r\n\r\nfunction StyledComponent() {\r\n  const theme = useTheme();\r\n  const isDark = theme === 'dark';\r\n\r\n  const styles = {\r\n    backgroundColor: isDark ? '#111111' : '#ffffff',\r\n    color: isDark ? '#ffffff' : '#111111',\r\n  };\r\n\r\n  return <div style={styles}>Content</div>;\r\n}\r\n```\r\n\r\n## SSR Compatibility\r\n\r\nThe package is designed to be safe for server-side rendering:\r\n\r\n- No `window` or `document` access during initial render\r\n- Theme is applied on client-side mount\r\n- Proper checks for environment before DOM access\r\n\r\n```tsx\r\n// This works with Next.js, Gatsby, Remix, etc.\r\nimport { AutoThemeProvider } from '@arsalanshaikhh/auto-time-theme-react';\r\n\r\nexport default function MyApp({ Component, pageProps }) {\r\n  return (\r\n    <AutoThemeProvider>\r\n      <Component {...pageProps} />\r\n    </AutoThemeProvider>\r\n  );\r\n}\r\n```\r\n\r\n## Edge Cases Handled\r\n\r\n- ✅ Time range crossing midnight\r\n- ✅ Tab sleeping and resuming (visibility change)\r\n- ✅ System time change during app usage\r\n- ✅ Invalid time configuration (falls back to defaults)\r\n- ✅ Disabled localStorage (graceful fallback)\r\n- ✅ SSR environments\r\n\r\n## Performance Considerations\r\n\r\n- **No constant polling** - Uses setTimeout to schedule only the next required theme switch\r\n- **Minimal re-renders** - Efficient context design\r\n- **Event listener cleanup** - Proper cleanup on unmount\r\n- **Memoized callbacks** - Reduces unnecessary re-renders\r\n\r\n## Folder Structure\r\n\r\n```\r\nsrc/\r\n ├── AutoThemeProvider.tsx   # Context provider component\r\n ├── useAutoTheme.ts         # Main hook and additional hooks\r\n ├── timeUtils.ts            # Time calculation utilities\r\n ├── storage.ts              # LocalStorage utilities\r\n ├── constants.ts            # Default values and constants\r\n ├── types.ts                # TypeScript type definitions\r\n └── index.ts                # Public exports\r\n```\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a Pull Request.\r\n\r\n## License\r\n\r\nMIT License - feel free to use this package in your projects.\r\n\r\n## Future Enhancements\r\n\r\nPotential features for future versions:\r\n\r\n- System theme synchronization (prefers-color-scheme)\r\n- Sunrise and sunset based themes (using geolocation)\r\n- Multiple theme presets\r\n- Cookie-based persistence\r\n- Animation support for theme transitions\r\n\r\n---\r\n\r\nBuilt with ❤️ for the React community\r\n","readmeFilename":"README.md"}