{"id":16078253,"url":"https://github.com/dominictobias/react-js2css-theme","last_synced_at":"2026-03-01T05:08:53.283Z","repository":{"id":44005936,"uuid":"237202137","full_name":"dominictobias/react-js2css-theme","owner":"dominictobias","description":"Expose theme objects but use CSS Variables internally","archived":false,"fork":false,"pushed_at":"2023-01-05T06:04:03.000Z","size":364,"stargazers_count":7,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T19:57:46.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dominictobias.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":"2020-01-30T11:48:48.000Z","updated_at":"2024-07-03T11:09:38.000Z","dependencies_parsed_at":"2023-02-03T14:47:23.694Z","dependency_job_id":null,"html_url":"https://github.com/dominictobias/react-js2css-theme","commit_stats":null,"previous_names":["sekoyo/react-js2css-theme","dominictobias/react-js2css-theme"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictobias%2Freact-js2css-theme","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictobias%2Freact-js2css-theme/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictobias%2Freact-js2css-theme/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictobias%2Freact-js2css-theme/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dominictobias","download_url":"https://codeload.github.com/dominictobias/react-js2css-theme/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243903179,"owners_count":20366438,"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":"2024-10-09T10:09:51.937Z","updated_at":"2026-03-01T05:08:53.245Z","avatar_url":"https://github.com/dominictobias.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React CSS Theming (with JS objects)\n\nThis tiny 500byte (not gzipped) component allows JS theme objects to be passed into your component where they're converted into CSS Variables for internal use.\n\n\u003ch2\u003eDemo\u003c/h2\u003e\n\nhttps://codesandbox.io/s/react-js2css-theme-demo-s6xlx\n\n\u003ch2\u003eWhy?\u003c/h2\u003e\n\n- Switching CSS Variables for themes is unpleasant for users of your component, JS objects are easier to deal with.\n\n- CSS Variable changes are much faster than React re-renders via Context which is what CSS-in-JS solutions do.\n\n- If you care about performance and bundle size and want to avoid CSS-in-JS solutions altogether you can still provide a nice JS theme object interface to your users.\n\n## Install\n\n```\nyarn add react-js2css-theme\n```\n\n\u003ch2\u003eUsage\u003c/h2\u003e\n\n```js\nconst yourTheme = {\n  background: 'black',\n  textColor: 'white',\n  fontFamily: '\"Roboto\", sans-serif',\n  fontWeight: 500,\n  button: {\n    padding: '10px',\n  },\n};\n```\n\n\u003ch3\u003eAs a component\u003c/h3\u003e\n\n```js\nimport JSToCSSTheme from 'react-js2css-theme';\n\n\u003cJSToCSSTheme namespace=\"xx\" theme={yourTheme}\u003e\n  \u003cYourComponent /\u003e\n\u003c/JSToCSSTheme\u003e;\n```\n\n\u003ch3\u003eAs a hook\u003c/h3\u003e\n\nYou may not wish to create an extra wrapping element, in this case you can use the hook:\n\n```js\nimport { useJsToCss } from 'react-js2css-theme';\n\nfunction YourComponent() {\n  const themeStyle = useJsToCss('xx', yourTheme);\n\n  return (\n    \u003cdiv\u003e\n      \u003cstyle\u003e{themeStyle}\u003c/style\u003e\n      {/* ... your component JSX */}\n    \u003c/div\u003e\n  );\n}\n```\n\nYour component can now make use of the following CSS Variables:\n\n```css\n:root {\n  --xx-background: black;\n  --xx-textColor: white;\n  --xx-fontFamily: 'Roboto', sans-serif;\n  --xx-fontWeight: 500;\n  --xx-buttonPadding: 10px;\n}\n```\n\nNow try changing the theme object and watch your component's theme change :)\n\n\u003ch2\u003eRequirements\u003c/h2\u003e\n\n- All browsers except IE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominictobias%2Freact-js2css-theme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominictobias%2Freact-js2css-theme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominictobias%2Freact-js2css-theme/lists"}