{"id":13725660,"url":"https://github.com/styled-components/styled-theming","last_synced_at":"2025-10-06T22:08:11.894Z","repository":{"id":46647096,"uuid":"98470014","full_name":"styled-components/styled-theming","owner":"styled-components","description":"Create themes for your app using styled-components","archived":false,"fork":false,"pushed_at":"2021-10-01T20:07:40.000Z","size":63,"stargazers_count":1172,"open_issues_count":4,"forks_count":39,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-14T08:06:14.879Z","etag":null,"topics":["css-in-js","react","styled-components","theming"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"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/styled-components.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}},"created_at":"2017-07-26T22:14:41.000Z","updated_at":"2025-04-06T08:11:33.000Z","dependencies_parsed_at":"2022-08-30T00:41:03.796Z","dependency_job_id":null,"html_url":"https://github.com/styled-components/styled-theming","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styled-components%2Fstyled-theming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styled-components%2Fstyled-theming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styled-components%2Fstyled-theming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styled-components%2Fstyled-theming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/styled-components","download_url":"https://codeload.github.com/styled-components/styled-theming/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254276447,"owners_count":22043867,"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":["css-in-js","react","styled-components","theming"],"created_at":"2024-08-03T01:02:30.441Z","updated_at":"2025-10-06T22:08:06.862Z","avatar_url":"https://github.com/styled-components.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# styled-theming\n\n\u003e Create themes for your app using [styled-components](https://www.styled-components.com/)\n\nRead the [introductory blog post](http://thejameskyle.com/styled-theming.html)\n\n## Installation\n\n```sh\nyarn add styled-components styled-theming\n```\n\n## Example\n\n```js\nimport React from 'react';\nimport styled, {ThemeProvider} from 'styled-components';\nimport theme from 'styled-theming';\n\nconst boxBackgroundColor = theme('mode', {\n  light: '#fff',\n  dark: '#000',\n});\n\nconst Box = styled.div`\n  background-color: ${boxBackgroundColor};\n`;\n\nexport default function App() {\n  return (\n    \u003cThemeProvider theme={{ mode: 'light' }}\u003e\n      \u003cBox\u003e\n        Hello World\n      \u003c/Box\u003e\n    \u003c/ThemeProvider\u003e\n  );\n}\n```\n\n## API\n\n### `\u003cThemeProvider\u003e`\n\nSee [styled-components docs](https://www.styled-components.com/docs/advanced#theming)\n\n`\u003cThemeProvider\u003e` is part of styled-components, but is required for styled-theming.\n\n```js\nimport {ThemeProvider} from 'styled-components';\n```\n\n`\u003cThemeProvider\u003e` accepts a single prop `theme` which you should pass an object\nwith either strings or getter functions. For example:\n\n```js\n\u003cThemeProvider theme={{ mode: 'dark', size: 'large' }}\u003e\n\u003cThemeProvider theme={{ mode: modes =\u003e modes.dark, size: sizes =\u003e sizes.large }}\u003e\n```\n\nYou should generally set up a `\u003cThemeProvider\u003e` at the root of your app:\n\n```js\nfunction App() {\n  return (\n    \u003cThemeProvider theme={...}\u003e\n      {/* rest of your app */}\n    \u003c/ThemeProvider\u003e\n  );\n}\n```\n\n### `theme(name, values)`\n\nMost of your theming will be done with this function.\n\n`name` should match one of the keys in your `\u003cThemeProvider\u003e` theme.\n\n```js\n\u003cThemeProvider theme={{ whatever: '...' }}/\u003e\n\ntheme('whatever', {...});\n```\n\n`values` should be an object where one of the keys will be selected by the\nvalue provided to `\u003cThemeProvider\u003e` theme.\n\n```js\n\u003cThemeProvider theme={{ mode: 'light' }}/\u003e\n\u003cThemeProvider theme={{ mode: 'dark' }}/\u003e\n\ntheme('mode', {\n  light: '...',\n  dark: '...',\n});\n```\n\nThe values of this object can be any CSS value.\n\n```js\ntheme('mode', {\n  light: '#fff',\n  dark: '#000',\n});\n\ntheme('font', {\n  sansSerif: '\"Helvetica Neue\", Helvetica, Arial, sans-serif',\n  serif: 'Georgia, Times, \"Times New Roman\", serif',\n  monoSpaced: 'Consolas, monaco, monospace',\n});\n```\n\nThese values can also be functions that return CSS values.\n\n```js\ntheme('mode', {\n  light: props =\u003e props.theme.userProfileAccentColor.light,\n  dark: props =\u003e props.theme.userProfileAccentColor.dark,\n});\n```\n\n`theme` will create a function that you can use as a value in\nstyled-component's `styled` function.\n\n```js\nimport styled from 'styled-components';\nimport theme from 'styled-theming';\n\nconst backgroundColor = theme('mode', {\n  light: '#fff',\n  dark: '#000',\n});\n\nconst Box = styled.div`\n  background-color: ${backgroundColor}\n`;\n```\n\nThe values will be passed through like any other interpolation\nin styled-components. You can use the `css` helper to add entire\nblocks of styles, including their own interpolations.\n\n```js\nimport styled, {css} from 'styled-components';\nimport theme from 'styled-theming';\n\nconst white = \"#fff\";\nconst black = \"#000\";\n\nconst boxStyles = theme('mode', {\n  light: css`\n    background: ${white};\n    color: ${black};\n  `,\n  dark: css`\n    background: ${black};\n    color: ${white};\n  `,\n});\n\nconst Box = styled.div`\n  ${boxStyles}\n`;\n```\n\n### `theme.variants(name, prop, themes)`\n\nIt's often useful to create variants of the same component that are selected\nvia an additional prop.\n\nTo make this easier with theming, styled-theming provides a `theme.variants`\nfunction.\n\n```js\nimport styled from 'styled-components';\nimport theme from 'styled-theming';\n\nconst backgroundColor = theme.variants('mode', 'variant', {\n  default: { light: 'gray', dark: 'darkgray' },\n  primary: { light: 'blue', dark: 'darkblue' },\n  success: { light: 'green', dark: 'darkgreen' },\n  warning: { light: 'orange', dark: 'darkorange' },\n});\n\nconst Button = styled.button`\n  background-color: ${backgroundColor};\n`;\n\nButton.propTypes = {\n  variant: PropTypes.oneOf(['default', 'primary', 'success', 'warning'])\n};\n\nButton.defaultProps = {\n  variant: 'default',\n};\n\n\u003cButton/\u003e\n\u003cButton variant=\"primary\"/\u003e\n\u003cButton variant=\"success\"/\u003e\n\u003cButton variant=\"warning\"/\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstyled-components%2Fstyled-theming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstyled-components%2Fstyled-theming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstyled-components%2Fstyled-theming/lists"}