{"id":18075731,"url":"https://github.com/elsoul/fresh-theme","last_synced_at":"2026-04-29T09:34:14.077Z","repository":{"id":259673511,"uuid":"879172908","full_name":"elsoul/fresh-theme","owner":"elsoul","description":"Theme Module for Fresh App","archived":false,"fork":false,"pushed_at":"2024-10-30T13:10:27.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-02T22:42:08.929Z","etag":null,"topics":["deno","edge","fresh"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elsoul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-27T07:35:12.000Z","updated_at":"2024-10-30T13:10:17.000Z","dependencies_parsed_at":"2024-10-27T08:50:48.267Z","dependency_job_id":"1dfe2065-2821-4b76-a499-6f5d68dbcf43","html_url":"https://github.com/elsoul/fresh-theme","commit_stats":null,"previous_names":["elsoul/fresh-theme"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsoul%2Ffresh-theme","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsoul%2Ffresh-theme/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsoul%2Ffresh-theme/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsoul%2Ffresh-theme/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elsoul","download_url":"https://codeload.github.com/elsoul/fresh-theme/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393538,"owners_count":20931809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","edge","fresh"],"created_at":"2024-10-31T11:07:06.721Z","updated_at":"2026-04-29T09:34:14.050Z","avatar_url":"https://github.com/elsoul.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Theme Module for Fresh v2 App\n\nThis module provides tools to manage theme preferences (dark or light mode) in a\nFresh v2 app. It includes:\n\n1. A default script for setting dark mode as the default theme.\n2. A default script for setting light mode as the default theme.\n3. A function to toggle between light and dark themes and persist the choice\n   using `localStorage`.\n\n## Features\n\n- **Default Theme Initialization**: Choose between dark or light as the default\n  theme based on user or system preferences.\n- **Persistent Theme Setting**: Saves the selected theme in `localStorage` for\n  consistent experience across sessions.\n- **Simple API**: Minimal API with `setTheme` for theme management and initial\n  setup scripts.\n\n## Installation and Usage\n\n### 1. Import the Module\n\nImport the desired script (dark or light mode) in your app’s main entry point to\nset the initial theme.\n\n```typescript\nimport {\n  defaultDarkModeScript,\n  defaultLightModeScript,\n  setTheme,\n} from 'jsr:@elsoul/fresh-theme'\n```\n\n### 2. Adding the Theme Script to Your App\n\nInsert the desired theme script in the `\u003chead\u003e` section of your app to\nautomatically apply the initial theme based on user settings or system\npreferences.\n\n#### Example for Default Dark Mode\n\n```typescript\nimport { asset } from 'fresh/runtime'\nimport { define } from '@/utils/state.ts'\nimport { defaultDarkModeScript } from 'jsr:@elsoul/fresh-theme'\n\nexport default define.page(function App({ Component, state, url }) {\n  return (\n    \u003chtml lang={state.locale || 'en'}\u003e\n      \u003chead\u003e\n        \u003cscript dangerouslySetInnerHTML={{ __html: defaultDarkModeScript }} /\u003e\n        \u003clink rel='stylesheet' href={asset('/styles.css')} /\u003e\n      \u003c/head\u003e\n      \u003cbody\u003e\n        \u003cComponent /\u003e\n      \u003c/body\u003e\n    \u003c/html\u003e\n  )\n})\n```\n\n#### Example for Default Light Mode\n\n```typescript\nimport { asset } from 'fresh/runtime'\nimport { define } from '@/utils/state.ts'\nimport { defaultLightModeScript } from 'jsr:@elsoul/fresh-theme'\n\nexport default define.page(function App({ Component, state, url }) {\n  return (\n    \u003chtml lang={state.locale || 'en'}\u003e\n      \u003chead\u003e\n        \u003cscript dangerouslySetInnerHTML={{ __html: defaultLightModeScript }} /\u003e\n        \u003clink rel='stylesheet' href={asset('/styles.css')} /\u003e\n      \u003c/head\u003e\n      \u003cbody\u003e\n        \u003cComponent /\u003e\n      \u003c/body\u003e\n    \u003c/html\u003e\n  )\n})\n```\n\n### 3. Changing the Theme Programmatically\n\nUse the `setTheme` function to programmatically change the theme between light\nand dark modes. This function updates the theme preference in `localStorage` and\nadjusts the `\u003chtml\u003e` element class.\n\n```typescript\n// Example: Setting the theme to dark mode\nsetTheme('dark')\n// Example: Setting the theme to light mode\nsetTheme('light')\n```\n\n## API Reference\n\n### `defaultDarkModeScript`\n\nJavaScript code to initialize the theme with dark mode as the default. This\nscript applies the theme based on `localStorage` or system preference if no\ntheme is set.\n\n### `defaultLightModeScript`\n\nJavaScript code to initialize the theme with light mode as the default. This\nscript applies the theme based on `localStorage` or system preference if no\ntheme is set.\n\n### `setTheme(newTheme: 'dark' | 'light')`\n\nSets the theme to `'dark'` or `'light'` and stores the choice in `localStorage`.\nAdjusts the `\u003chtml\u003e` element to reflect the new theme.\n\n- **Parameters**:\n  - `newTheme` - The desired theme, either `'dark'` or `'light'`.\n\n### useTheme hook\n\n```typescript\nimport { useTheme } from 'jsr:@elsoul/fresh-theme'\n\nfunction ThemeToggleButton() {\n  const { theme, setTheme } = useTheme()\n\n  const toggleTheme = () =\u003e {\n    const newTheme = theme === 'dark' ? 'light' : 'dark'\n    setTheme(newTheme)\n  }\n\n  return (\n    \u003cbutton onClick={toggleTheme}\u003e\n      Switch to {theme === 'dark' ? 'Light' : 'Dark'} Mode\n    \u003c/button\u003e\n  )\n}\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/elsoul/fresh-theme This project is intended to be a safe,\nwelcoming space for collaboration, and contributors are expected to adhere to\nthe [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe package is available as open source under the terms of the\n[Apache-2.0 License](https://www.apache.org/licenses/LICENSE-2.0).\n\n## Code of Conduct\n\nEveryone interacting in the SKEET project’s codebases, issue trackers, chat\nrooms and mailing lists is expected to follow the\n[code of conduct](https://github.com/elsoul/skeet/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felsoul%2Ffresh-theme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felsoul%2Ffresh-theme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felsoul%2Ffresh-theme/lists"}