{"id":13599164,"url":"https://github.com/beynar/svelte-themes","last_synced_at":"2025-04-13T10:40:28.182Z","repository":{"id":64658474,"uuid":"443378195","full_name":"beynar/svelte-themes","owner":"beynar","description":"Perfect SvelteKit dark mode in 2 lines of code. Support System preference and any other theme with no flashing","archived":false,"fork":false,"pushed_at":"2022-09-08T18:06:14.000Z","size":107,"stargazers_count":67,"open_issues_count":7,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T02:02:42.130Z","etag":null,"topics":["dark-mode","dark-theme","sveltejs","sveltekit","theme","themes"],"latest_commit_sha":null,"homepage":"https://svelte-themes.vercel.app/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beynar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-31T15:48:53.000Z","updated_at":"2024-12-16T20:02:01.000Z","dependencies_parsed_at":"2022-12-12T11:15:22.014Z","dependency_job_id":null,"html_url":"https://github.com/beynar/svelte-themes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beynar%2Fsvelte-themes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beynar%2Fsvelte-themes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beynar%2Fsvelte-themes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beynar%2Fsvelte-themes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beynar","download_url":"https://codeload.github.com/beynar/svelte-themes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248700840,"owners_count":21147917,"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":["dark-mode","dark-theme","sveltejs","sveltekit","theme","themes"],"created_at":"2024-08-01T17:01:00.420Z","updated_at":"2025-04-13T10:40:28.151Z","avatar_url":"https://github.com/beynar.png","language":"TypeScript","readme":"This library is a port of [next-theme](https://github.com/pacocoursey/next-themes/) for SvelteKit. All credit goes to [pacocoursey](https://github.com/pacocoursey) and all [next-themes contributors](https://github.com/pacocoursey/next-themes/graphs/contributors)\n\nWhile usable, this library is still in its early phase, PR are welcome.\n\n# svelte-themes ![svelte-themes minzip package size](https://img.shields.io/bundlephobia/minzip/svelte-themes) ![Version](https://img.shields.io/npm/v/svelte-themes.svg?colorB=green)\n\nAn abstraction for themes in your SvelteKit.js app.\n\n- ✅ Perfect dark mode in 2 lines of code\n- ✅ System setting with prefers-color-scheme\n- ✅ Themed browser UI with color-scheme\n- ✅ No flash on load\n- ✅ Sync theme across tabs and windows\n- ✅ Disable flashing when changing themes\n- ✅ Force pages to specific themes\n- ✅ Class or data attribute selector\n- ✅ Theme store\n\nCheck out the [Live Example](https://svelte-themes.vercel.app) to try it for yourself.\n\n## Install\n\n```bash\n$ pnpm add svelte-themes\n# or\n$ npm install svelte-themes\n# or\n$ yarn add svelte-themes\n```\n\n## Using svelte-themes\n\nIn order to use svelte-themes you will need to add `SvelteTheme` inside your [`__layout component`](https://kit.svelte.dev/docs#layouts).\n\n```tsx\n// pages/__layout.svelte\n\n\u003cscript\u003e\n\timport SvelteTheme from 'svelte-themes/SvelteTheme.svelte';\n\u003c/script\u003e\n\n\u003cSvelteTheme /\u003e\n\u003cslot /\u003e\n```\n\n### Props\n\n- `storageKey = 'theme'`: Key used to store theme setting in localStorage\n- `defaultTheme = 'system'`: Default theme name. If `enableSystem` is false, the default theme is `light`\n- `forcedTheme`: Forced theme name for the current page (does not modify saved theme settings)\n- `enableSystem = true`: Whether to switch between `dark` and `light` based on `prefers-color-scheme`\n- `enableColorScheme = true`: Whether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons\n- `disableTransitionOnChange = false`: Optionally disable all CSS transitions when switching themes\n- `themes = ['light', 'dark']`: List of theme names\n- `attribute = 'data-theme'`: HTML attribute modified based on the active theme\n  - accepts `class` and `data-*` (meaning any data attribute, `data-mode`, `data-color`, etc.)\n- `value`: Optional mapping of theme name to attribute value\n  - value is an `object` where key is the theme name and value is the attribute value\n\n## Reading and updating the theme\n\nSvelte-themes exports\n\n- a `theme` writable store as its default so you can access the theme props anywhere in you app\n- `setTheme` function so you can easily switch the theme.\n\n```tsx\n\u003cscript\u003e\nimport themeStore, { setTheme } from 'svelte-themes';\n\u003cscript/\u003e\n\n\u003cselect bind:value={$themeStore.theme}\u003e\n        \u003coption value=\"dark\"\u003eDark\u003c/option\u003e\n        \u003coption value=\"light\"\u003eLight\u003c/option\u003e\n        \u003coption value=\"system\"\u003eSystem\u003c/option\u003e\n\u003c/select\u003e\n\n\u003cbutton on:click={() =\u003e setTheme('dark')}\u003e Dark mode \u003c/button\u003e\n```\n\n### Theme store\n\n- `theme`: Active theme name\n- `forcedTheme`: Forced page theme or falsy. If `forcedTheme` is set, you should disable any theme switching UI\n- `resolvedTheme`: If `enableSystem` is true and the active theme is \"system\", this returns whether the system preference resolved to \"dark\" or \"light\". Otherwise, identical to `theme`\n- `systemTheme`: If `enableSystem` is true, represents the System theme preference (\"dark\" or \"light\"), regardless what the active theme is\n- `themes`: The list of themes passed to `ThemeProvider` (with \"system\" appended, if `enableSystem` is true)\n\nFor the rest of the documentation please refer to the [next-themes repo](https://github.com/pacocoursey/next-themes).\n","funding_links":[],"categories":["TypeScript","Enhancers/Extensions"],"sub_categories":["The _How To's?_"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeynar%2Fsvelte-themes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeynar%2Fsvelte-themes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeynar%2Fsvelte-themes/lists"}