{"id":23768306,"url":"https://github.com/awalsolution/tailwing-theming","last_synced_at":"2026-02-05T05:01:05.123Z","repository":{"id":269294106,"uuid":"898684285","full_name":"awalsolution/tailwing-theming","owner":"awalsolution","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-04T17:08:23.000Z","size":120,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-05T03:59:06.529Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/awalsolution.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2024-12-04T20:55:22.000Z","updated_at":"2025-01-04T17:07:15.000Z","dependencies_parsed_at":"2024-12-22T14:41:24.637Z","dependency_job_id":null,"html_url":"https://github.com/awalsolution/tailwing-theming","commit_stats":null,"previous_names":["awalsolution/tailwing-theming"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/awalsolution/tailwing-theming","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awalsolution%2Ftailwing-theming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awalsolution%2Ftailwing-theming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awalsolution%2Ftailwing-theming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awalsolution%2Ftailwing-theming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awalsolution","download_url":"https://codeload.github.com/awalsolution/tailwing-theming/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awalsolution%2Ftailwing-theming/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29113188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T03:44:17.043Z","status":"ssl_error","status_checked_at":"2026-02-05T03:44:12.077Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-01-01T01:27:50.043Z","updated_at":"2026-02-05T05:01:05.096Z","avatar_url":"https://github.com/awalsolution.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"left\"\u003e\n \u003ch1\u003eTailwind theming\u003c/h1\u003e\n  \u003cp\u003eThe \u003cb\u003eTailwindCSS Multi-Theming Plugin\u003c/b\u003e is a utility for creating and managing multiple themes in your TailwindCSS-based projects. With this library, you can define, add, update, and remove themes dynamically while keeping your configuration clean and extensible.\u003c/p\u003e\n  \u003cdiv \u003e\n    \u003cimg src=\"https://img.shields.io/badge/-TypeScript-black?style=for-the-badge\u0026logoColor=white\u0026logo=typescript\u0026color=3178c6\" alt=\"typescript\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/-Tailwind_CSS-black?style=for-the-badge\u0026logoColor=white\u0026logo=tailwindcss\u0026color=06B6D4\" alt=\"tailwindcss\" /\u003e\n  \u003c/div\u003e\n\u003chr/\u003e\n\u003c/div\u003e\n\n## Features:\n\n- **Dynamic Theme Management**:\n  - Add, update, and remove themes programmatically.\n- **Flexible Theme Configuration**:\n  - Define themes using `extend` to seamlessly integrate with TailwindCSS.\n- **Data Attributes Selectors**:\n  - Apply themes via `data-theme` attributes.\n- **Default Theme Support**:\n  - Specify a default theme to be applied globally.\n- **Customizable Media Queries**:\n  - Apply themes based on user preferences, such as dark mode.\n\n---\n\n## Installation:\n\nInstall the package via your package manager:\n\n```bash\nyarn add @awal-solution/tailwind-theming\n# or\nnpm install @awal-solution/tailwind-theming\n```\n\n---\n\n## Getting Started:\n\n### 1. Configure TailwindCSS Plugin\n\nAdd the `themePlugin` to your TailwindCSS configuration:\n\n```javascript\n// tailwind.config.js|ts\nimport { themePlugin } from '@awal-solution/tailwind-theming'\n\nexport default {\n  content: ['./src/**/*.{html,js,ts}'],\n  plugins: [themePlugin()],\n}\n```\n\n### 2. Initialize Themes in Your Application\n\nCreate a `ThemeManager` instance and define your themes:\n\n```typescript\nimport { ThemeManager } from '@awal-solution/tailwind-theming'\n\nconst themeManager = new ThemeManager({\n  themes: {\n    'light-theme': {\n      colors: {\n        background: { DEFAULT: '#FFFFFF' },\n        foreground: { DEFAULT: '#000000' },\n        primary: { DEFAULT: '#0000FF', light: '#0096FF' },\n      },\n    },\n    'dark-theme': {\n      colors: {\n        background: { DEFAULT: '#000000' },\n        foreground: { DEFAULT: '#FFFFFF' },\n        primary: { DEFAULT: '#0000FF', light: '#0096FF' },\n      },\n    },\n  },\n  defaultTheme: 'light-theme',\n})\n\nexport { themeManager }\n```\n\n### 3. Apply Themes\n\nUse the generated selectors to toggle themes in your application:\n\n```typescript\n// Apply the default theme\ndocument.documentElement.setAttribute('data-theme', 'light-theme')\n\n// Toggle between themes\nfunction toggleTheme() {\n  const currentTheme = document.documentElement.getAttribute('data-theme')\n  const newTheme = currentTheme === 'light-theme' ? 'dark-theme' : 'light-theme'\n  document.documentElement.setAttribute('data-theme', newTheme)\n}\n```\n\n---\n\n## API Reference\n\n### **ThemeManager**\n\n#### Constructor\n\n```typescript\nconstructor({ themes: Record\u003cstring, Theme\u003e, defaultTheme?: string });\n```\n\n- `themes`: A record of theme names and their configurations.\n- `defaultTheme`: (Optional) The default theme to apply initially.\n\n#### Methods\n\n##### **`get()`**\n\nReturns all themes, including the default theme and additional themes.\n\n```typescript\nthemeManager.get()\n```\n\n##### **`getThemeSelectors()`**\n\nReturns an object containing theme names and their associated selectors.\n\n```typescript\nthemeManager.getThemeSelectors()\n```\n\n##### **`add(theme: AddThemeType)`**\n\nAdds a new theme to the existing themes.\n\n```typescript\nthemeManager.add({\n  name: 'custom-theme',\n  selectors: ['[data-theme=\"custom-theme\"]'],\n  theme: {\n    colors: {\n      background: { DEFAULT: '#555' },\n    },\n  },\n})\n```\n\n##### **`update(themeName: string, properties: Partial\u003cTailwindExtension\u003e)`**\n\nUpdates an existing theme's configuration.\n\n```typescript\nthemeManager.update('custom-theme', {\n  colors: {\n    primary: { DEFAULT: '#FF0000' },\n  },\n})\n```\n\n##### **`remove(themeName: string)`**\n\nRemoves an existing theme by name.\n\n```typescript\nthemeManager.remove('custom-theme')\n```\n\n---\n\n## Plugin Options\n\nThe `themePlugin` provides the following options:\n\n- **`defaultTheme`**: (Optional) Default theme configuration.\n- **`themes`**: An array of theme configurations.\n\nExample usage in TailwindCSS:\n\n```javascript\nimport { themePlugin } from '@awal-solution/tailwind-theming'\nimport { themeManager } from './themeManager'\n\nexport default {\n  content: ['./src/**/*.{html,js,ts}'],\n  plugins: [themePlugin(themeManager.get())],\n}\n```\n\n---\n\nExample CSS:\n\n```css\n@tailwind base;\n@tailwind components;\n@tailwind utilities;\n```\n\n## Example\n\nAn example setup for toggling themes in your app:\n\n```typescript\nimport './index.css'\nimport { storage } from './storage'\nimport { themeManager } from './themeManager'\n\nlet themeNames = themeManager.getThemeSelectors()\nlet currentTheme = storage.get\u003cstring\u003e('APP_THEME') ?? Object.keys(themeNames)[0]\n\nconst initializeApp = () =\u003e {\n  const root = document.documentElement\n\n  // Apply the saved theme or system theme as default\n  root.className = currentTheme\n  root.setAttribute('data-theme', currentTheme)\n  storage.set('APP_THEME', currentTheme)\n}\n\nconst toggleTheme = () =\u003e {\n  const root = document.documentElement\n  const themeKeys = Object.keys(themeNames)\n  const currentIndex = themeKeys.findIndex((key) =\u003e key === currentTheme)\n\n  // Determine the next theme\n  const nextIndex = (currentIndex + 1) % themeKeys.length\n  currentTheme = themeKeys[nextIndex]\n\n  // Apply the new theme\n  root.className = currentTheme\n  root.setAttribute('data-theme', currentTheme)\n  storage.set('APP_THEME', currentTheme)\n\n  // Update button text to show the next theme\n  const button = document.querySelector\u003cHTMLButtonElement\u003e('#theme-toggle')\n  if (button) {\n    const nextTheme = themeNames[themeKeys[(nextIndex + 1) % themeKeys.length]].name\n    button.textContent = `Switch to ${nextTheme.charAt(0).toUpperCase() + nextTheme.slice(1)} Mode`\n  }\n}\n\nconst renderApp = () =\u003e {\n  const app = document.querySelector\u003cHTMLDivElement\u003e('#app')\n  if (!app) return\n\n  app.innerHTML = `\n    \u003cdiv class=\"min-h-screen flex gap-4 items-center justify-center bg-background text-foreground\"\u003e\n      \u003cbutton id=\"theme-toggle\" class=\"px-4 py-2 bg-primary text-white rounded\"\u003e\n        Switch to ${Object.keys(themeNames)[0]} Mode\n      \u003c/button\u003e\n      \u003ch1 class=\"border-b border-divider\"\u003e\n        Hello, TailwindCSS Theme Toggling!\n      \u003c/h1\u003e\n    \u003c/div\u003e\n  `\n\n  // Attach event listener for the theme toggle button\n  const button = document.querySelector\u003cHTMLButtonElement\u003e('#theme-toggle')\n  if (button) {\n    button.addEventListener('click', toggleTheme)\n  }\n}\n\ninitializeApp()\nrenderApp()\n```\n\n---\n\n## License\n\nThis library is open-source and licensed under the [MIT License](./LICENSE).\n\n---\n\n## Contributions\n\nContributions are welcome! If you find a bug or want to suggest a feature, please open an issue or submit a pull request.\n\n## Commits\n\n### Patch release\n\n```bash\n\nfix(theme): correct issue with theme manager\n\n```\n\n### Minor release\n\n```bash\n\nfeat(utils): add utility functions for theming\n\n```\n\n### Major release\n\n```bash\n\nfix!: update API endpoints (BREAKING CHANGE: endpoint changes)\n\n```\n\n---\n\nHappy coding! 🎉\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawalsolution%2Ftailwing-theming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawalsolution%2Ftailwing-theming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawalsolution%2Ftailwing-theming/lists"}