{"id":13480121,"url":"https://github.com/crswll/tailwindcss-theme-swapper","last_synced_at":"2025-05-13T12:56:54.880Z","repository":{"id":38447301,"uuid":"245522996","full_name":"crswll/tailwindcss-theme-swapper","owner":"crswll","description":"A helper for getting tailwind values into css custom properties and switching them between media queries and classes. You can try it out here: https://play.tailwindcss.com/Gt21fePNvv","archived":false,"fork":false,"pushed_at":"2024-09-02T22:46:16.000Z","size":638,"stargazers_count":324,"open_issues_count":4,"forks_count":15,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-27T10:38:35.667Z","etag":null,"topics":["tailwindcss","theming"],"latest_commit_sha":null,"homepage":"","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/crswll.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"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}},"created_at":"2020-03-06T21:51:14.000Z","updated_at":"2025-03-17T22:19:38.000Z","dependencies_parsed_at":"2023-02-05T03:30:30.717Z","dependency_job_id":"0b5a826c-219c-471a-9569-5bbd6686972c","html_url":"https://github.com/crswll/tailwindcss-theme-swapper","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crswll%2Ftailwindcss-theme-swapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crswll%2Ftailwindcss-theme-swapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crswll%2Ftailwindcss-theme-swapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crswll%2Ftailwindcss-theme-swapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crswll","download_url":"https://codeload.github.com/crswll/tailwindcss-theme-swapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253948346,"owners_count":21988953,"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":["tailwindcss","theming"],"created_at":"2024-07-31T17:00:34.867Z","updated_at":"2025-05-13T12:56:54.855Z","avatar_url":"https://github.com/crswll.png","language":"JavaScript","funding_links":[],"categories":["Plugins","JavaScript"],"sub_categories":[],"readme":"# tailwindcss-theme-swapper\n\n**Extend** your tailwind config with CSS Custom Properties and trigger the updating of them with any type of selector or media query.\n\n## Requirements\n\n* Tailwind 1.2\n\n## Browser Support\n\nJust needs to support CSS Custom Properties. IE11 can kind of work but only the base theme with something like `postcss-preset-env`.\n\n## Installation\n\n```bash\nyarn add tailwindcss-theme-swapper\n# or\nnpm install tailwindcss-theme-swapper --save-dev\n```\n\n## Try It Out\n\n### Minimal\nhttps://play.tailwindcss.com/Gt21fePNvv\n\n### Fancier (radix colors, multiple themes)\nhttps://play.tailwindcss.com/jskI9McL20\n\n## Usage Example\n\nIn your tailwind.config.js:\n\n```js\nconst themeSwapper = require('tailwindcss-theme-swapper')\n\nmodule.exports = {\n  plugins: [\n    themeSwapper({\n      themes: [\n        // The only required theme is `base`. Every property used in\n        // other themes must exist in here.\n        {\n          name: 'base',\n          selectors: [':root'],\n          theme: {\n            colors: {\n              primary: '#f00',\n            },\n          },\n        },\n        {\n          name: 'dark',\n          selectors: ['.dark'],\n          mediaQuery: '@media (prefers-color-scheme: dark)',\n          theme: {\n            colors: {\n              primary: '#fff',\n            },\n          },\n        },\n        {\n          name: 'matrix',\n          selectors: ['.matrix'],\n          theme: {\n            colors: {\n              primary: '#0f0',\n            },\n          },\n        },\n      ],\n    }),\n  ],\n}\n```\n\n### Theme Swapper Properties\n\n```js\n{\n  // The name of the theme. You only have to name `base`.\n  name: 'dark',\n\n  // Apply one of these selectors(?) to an element and all of its children to use that theme.\n  // `\u003cdiv class=\"dark\"\u003e`, `\u003cdiv data-theme=\"dark\"\u003e`, `\u003cdiv dark\u003e`\n  selectors: ['.dark', '[data-theme=\"dark\"]', '[dark]', ],\n\n  // If this media query matches the theme will apply to the entire page.\n  mediaQuery: '@media (prefers-color-scheme: dark)',\n\n  // This extends your tailwind theme.\n  // Only keys/values defined here will be made into custom properties.\n  theme: {\n    colors: {\n      // ...\n    },\n    spacing: {\n      // ...\n    },\n    borderRadius: {\n      // ...\n    },\n  },\n}\n```\n\n## Example I:O\n\n### Themes Input\n\n```js\nconst themes = [\n  {\n    name: 'base',\n    selectors: [':root'],\n    theme: {\n      colors: {\n        primary: 'hsl(0 100% 50%)',\n      },\n      spacing: {\n        sm: '3px',\n      },\n    },\n  },\n  {\n    name: 'dark',\n    selectors: [\n      '.dark',\n      '[dark]',\n      '[data-theme=\"dark\"]'\n    ],\n    mediaQuery: '@media (prefers-color-scheme: dark)',\n    theme: {\n      colors: {\n        primary: 'darkslateblue',\n      },\n    },\n  },\n  {\n    selectors: ['.lime']\n    theme: {\n      colors: {\n        primary: '#0f0',\n      },\n    },\n  },\n]\n```\n\n### CSS Output\n\n```css\n:root {\n  --colors-primary: hsl(0 100% 50%);\n  --spacing-sm: 3px\n}\n\n.dark, [dark], [data-theme=\"dark\"] {\n  --colors-primary: darkslateblue\n}\n\n@media (prefers-color-scheme: dark) {\n  :root{\n    --colors-primary: darkslateblue\n  }\n}\n\n.lime {\n  --colors-primary: #0f0\n}\n\n/* ... */\n\n.bg-primary {\n  --tw-bg-opacity: 1;\n  background-color: color-mix(in srgb, var(--colors-primary), transparent calc(100% - 100% * var(--tw-bg-opacity)))\n}\n\n.text-primary {\n  --tw-text-opacity: 1;\n  background-color: color-mix(in srgb, var(--colors-primary), transparent calc(100% - 100% * var(--tw-text-opacity)))\n}\n\n.p-sm {\n  padding: var(--spacing-sm)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrswll%2Ftailwindcss-theme-swapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrswll%2Ftailwindcss-theme-swapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrswll%2Ftailwindcss-theme-swapper/lists"}