{"id":17280372,"url":"https://github.com/alotropico/dark-mode-attribute","last_synced_at":"2025-03-26T15:16:28.632Z","repository":{"id":57096801,"uuid":"375890331","full_name":"alotropico/dark-mode-attribute","owner":"alotropico","description":"Very simple and lightweight utility to manage dark and light schemes from vanilla JavaScript. Call it with your button as a parameter and you're all set.","archived":false,"fork":false,"pushed_at":"2021-06-11T09:50:43.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T19:57:34.056Z","etag":null,"topics":["color-scheme","dark-mode","dark-theme","scheme-tools","toggle-scheme"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@alotropico/dark-mode-attribute","language":"JavaScript","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/alotropico.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-06-11T03:11:02.000Z","updated_at":"2021-06-11T09:50:45.000Z","dependencies_parsed_at":"2022-08-20T16:11:01.550Z","dependency_job_id":null,"html_url":"https://github.com/alotropico/dark-mode-attribute","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/alotropico%2Fdark-mode-attribute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alotropico%2Fdark-mode-attribute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alotropico%2Fdark-mode-attribute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alotropico%2Fdark-mode-attribute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alotropico","download_url":"https://codeload.github.com/alotropico/dark-mode-attribute/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245678901,"owners_count":20654738,"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":["color-scheme","dark-mode","dark-theme","scheme-tools","toggle-scheme"],"created_at":"2024-10-15T09:20:15.703Z","updated_at":"2025-03-26T15:16:28.613Z","avatar_url":"https://github.com/alotropico.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Dark Mode Attribute\n\nVery simple and lightweight utility to manage **dark and light schemes from vanilla JavaScript**.\n\nCall it with your button as a parameter and you're all set: `dark-mode-attribute(toggleButton)`\n\nWhen no default value is provided, the module checks if the user saved a preference from a previous session.\n\nIf they haven't, it looks for the user's system preference.\n\n### Installation\n\n```shell\nnpm i --save-dev @alotropico/dark-mode-attribute\n```\n\n### Usage\n\nIn your **JavaScript**, call dark-mode-attribute with your toggle-dark-mode element as a parameter:\n\n```javascript\nimport * as dma from '@alotropico/dark-mode-attribute'\n\nconst toggleButton = document.querySelector('.my-button')\n\ndma(toggleButton)\n```\n\nYour **CSS**:\n```css\nbody {\n    background-color: white;\n    color: black;\n}\nbody.dark {\n    background-color: black;\n    color: white;\n}\n.my-button:after {\n    content: '🌞'\n}\nbody.dark .my-button:after {\n    content: '🌚'\n}\n```\n\n### Options\n\nBy default, it adds the *dark* class to the body element, but you can customize it.\n\n\nUse a **custom class**:\n\n```javascript\ndma(toggleButton, 'dark-mode')\n```\n\n\nInstead of a class, let it be a **custom attribute**:\n\n```javascript\ndma(toggleButton, 'dark-mode', 'data-scheme')\n```\n```css\nbody[data-scheme=\"dark-mode\"] {\n    background-color: black;\n}\n```\n\n\nInstead of the body, apply the class/attribute to a **custom element**:\n\n```javascript\nconst container = document.body.querySelector('.container')\n\ndma(toggleButton, 'dark-mode', 'data-scheme', container)\n```\n\n\nPass a **default value**, which overrides the built-in detection and storage methods:\n```javascript\ndma(toggleButton, 'dark', 'class', container, true)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falotropico%2Fdark-mode-attribute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falotropico%2Fdark-mode-attribute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falotropico%2Fdark-mode-attribute/lists"}