{"id":26268154,"url":"https://github.com/andreruffert/color-scheme-switch-element","last_synced_at":"2025-04-30T19:27:31.504Z","repository":{"id":279512436,"uuid":"939061098","full_name":"andreruffert/color-scheme-switch-element","owner":"andreruffert","description":"💡 A simple custom element to toggle between a light and dark page color scheme","archived":false,"fork":false,"pushed_at":"2025-04-30T11:58:00.000Z","size":185,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T13:07:54.299Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreruffert.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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,"zenodo":null}},"created_at":"2025-02-25T23:37:47.000Z","updated_at":"2025-04-30T11:58:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"14de318a-507a-4c7e-a4ac-8b550ce37d08","html_url":"https://github.com/andreruffert/color-scheme-switch-element","commit_stats":null,"previous_names":["andreruffert/color-scheme-switch-element"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreruffert%2Fcolor-scheme-switch-element","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreruffert%2Fcolor-scheme-switch-element/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreruffert%2Fcolor-scheme-switch-element/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreruffert%2Fcolor-scheme-switch-element/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreruffert","download_url":"https://codeload.github.com/andreruffert/color-scheme-switch-element/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251711871,"owners_count":21631297,"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":[],"created_at":"2025-03-14T04:19:54.874Z","updated_at":"2025-04-30T19:27:31.486Z","avatar_url":"https://github.com/andreruffert.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u0026lt;color-scheme-switch\u0026gt; element\n\n\u003e A simple custom element to toggle between a light and dark page color scheme.\n\n[![Test status](https://img.shields.io/github/actions/workflow/status/andreruffert/color-scheme-switch-element/test.yml?label=Test\u0026logo=github\u0026color=lightyellow\u0026labelColor=212121)](https://github.com/andreruffert/color-scheme-switch-element/actions/workflows/test.yml)\n[![npm version](https://img.shields.io/npm/v/color-scheme-switch-element?color=lightyellow\u0026labelColor=212121)](https://www.npmjs.com/package/color-scheme-switch-element)\n[![gzip size](https://img.shields.io/badge/gzip-846B-lightyellow?labelColor=212121)](https://pkg-size.dev/color-scheme-switch-element@latest)\n[![npm downloads](https://img.shields.io/npm/dm/color-scheme-switch-element?logo=npm\u0026color=lightyellow\u0026labelColor=212121)](https://www.npmjs.com/package/color-scheme-switch-element)\n[![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/color-scheme-switch-element?color=lightyellow\u0026labelColor=212121)](https://www.jsdelivr.com/package/npm/color-scheme-switch-element)\n\n## Features\n\n- Toggle between a light and dark color scheme\n- Considers system preference\n- Persist user preference\n\n**[Demo](https://andreruffert.github.io/syntax-highlight-element)**\n\n## Installation\n\n```shell\nnpm install color-scheme-switch-element\n```\n\n## Usage\n\n### JavaScript\n\n```html\n\u003cscript\u003e\n  // Ensure the event listener is setup before the initial `color-scheme-switch` event gets dispatched.\n  document.addEventListener('color-scheme-switch', event =\u003e {\n    const colorScheme = event.target.value;\n\n    // Set the page color scheme e.g\n    document.documentElement.style.setProperty('color-scheme', colorScheme);\n    // ...\n  });\n\u003c/script\u003e\n\u003cscript type=\"module\" async blocking=\"render\" src=\"https://unpkg.com/color-scheme-switch-element@latest/dist/color-scheme-switch-element.js\"\u003e\u003c/script\u003e\n```\n\n\u003c!--\nImport as ES module:\n\n```js\nimport ColorSchemeSwitchElement from 'color-scheme-switch-element?define=false'\n\n// Ensure the event listener is setup before the initial `color-scheme-switch` event gets dispatched.\ndocument.addEventListener('color-scheme-switch', event =\u003e {\n  const colorScheme = event.target.value;\n\n  // Set the page color scheme e.g\n  document.documentElement.style.setProperty('color-scheme', colorScheme);\n  // ...\n});\n\nColorSchemeSwitchElement.define();\n```\n--\u003e\n\n### Markup\n\n```html\n\u003ccolor-scheme-switch title=\"Toggle light \u0026 dark color scheme\"\u003e\n  \u003c!-- ... --\u003e\n\u003c/color-scheme-switch\u003e\n```\n\n### Events\n\nWhen initially loaded or after switching the color scheme, a `color-scheme-switch` event is dispatched from the `\u003ccolor-scheme-switch\u003e` element.\n\n```js\ndocument.addEventListener('color-scheme-switch', event =\u003e {\n  const button = event.target;\n  const colorScheme = event.target.value;\n\n  // Set page color scheme, update aria-label, icon, etc.\n})\n```\n\n## License\n\nDistributed under the MIT license. See LICENSE for details. \n\n© [André Ruffert](https://andreruffert.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreruffert%2Fcolor-scheme-switch-element","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreruffert%2Fcolor-scheme-switch-element","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreruffert%2Fcolor-scheme-switch-element/lists"}