{"id":18563122,"url":"https://github.com/compulim/react-accent-color","last_synced_at":"2025-05-15T18:12:44.132Z","repository":{"id":82478940,"uuid":"114626667","full_name":"compulim/react-accent-color","owner":"compulim","description":"Accent color palette for React components","archived":false,"fork":false,"pushed_at":"2017-12-19T09:21:29.000Z","size":221,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-05T09:04:18.900Z","etag":null,"topics":[],"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/compulim.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-18T10:18:16.000Z","updated_at":"2024-06-09T21:52:25.000Z","dependencies_parsed_at":"2023-06-07T21:45:43.613Z","dependency_job_id":null,"html_url":"https://github.com/compulim/react-accent-color","commit_stats":{"total_commits":46,"total_committers":1,"mean_commits":46.0,"dds":0.0,"last_synced_commit":"69a89e3655f7db3fdbe232dc1fa169130a92dce9"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Freact-accent-color","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Freact-accent-color/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Freact-accent-color/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Freact-accent-color/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/compulim","download_url":"https://codeload.github.com/compulim/react-accent-color/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254394726,"owners_count":22063984,"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-11-06T22:11:51.958Z","updated_at":"2025-05-15T18:12:40.122Z","avatar_url":"https://github.com/compulim.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Accent color palette for React\n\n[![Build Status](https://travis-ci.org/compulim/react-accent-color.svg?branch=master)](https://travis-ci.org/compulim/react-accent-color) [![npm version](https://badge.fury.io/js/react-accent-color.svg)](https://badge.fury.io/js/react-accent-color)\n\nInspired by [UWP color design](https://docs.microsoft.com/en-us/windows/uwp/design/style/color), with light and dark theme.\n\n## Introduction\n\nTheming is tricky.\n\nWe believe designers should have ultimate controls on overall design, like margin, padding, and roundness. But sometimes, they may want to delegate some customizations to web developers, like [accent color](https://support.microsoft.com/en-us/help/17144/windows-10-change-desktop-background). We made this library to make the job a little bit easier.\n\nThis library is designed to play nice with [`glamor`](https://github.com/threepointone/glamor) and [Redux](https://github.com/reactjs/redux).\n\n## How to use\n\n\u003e Alternatively, you can find our demo at [react-accent-color-testbed](https://github.com/compulim/react-accent-color-testbed) repository.\n\nDo `npm install react-accent-color --save`.\n\nThen, in your code:\n\n* [Hoist colors to props using `withPalette()`](#hoist-colors-to-props-using-withpalette)\n* [Add `\u003cPaletteProvider\u003e` to the root of your app](#add-paletteprovider-to-the-root-of-your-app)\n\n### Hoist colors to props using `withPalette()`\n\nLike Redux `connect()`, we use [Higher-Order Components](https://reactjs.org/docs/higher-order-components.html) pattern to hoist colors to props. So you are in control of which colors should be hoisted.\n\nIn this example, `accent` color is extracted from `withPalette()` and passed into the component as `fillColor` prop.\n\nYou can see list of colors in the palette [here](#colors).\n\n```jsx\nimport React from 'react';\n\nclass MyButton extends React.Component {\n  render() {\n    return (\n      \u003cbutton style={{ backgroundColor: this.props.fillColor }}\u003e\n        { this.props.children }\n      \u003c/button\u003e\n    );\n  }\n}\n\nexport default withPalette(({ palette }) =\u003e ({\n  fillColor: palette.accent\n}))(MyButton)\n```\n\n\u003e Tips: You can also hoist on [stateless component](https://medium.com/@joshblack/stateless-components-in-react-0-14-f9798f8b992d).\n\n### Add `\u003cPaletteProvider\u003e` to the root of your app\n\nSelect your accent color and theme, then wrap your app with `\u003cPaletteProvider\u003e`.\n\n\u003e See [list of accent colors](https://docs.microsoft.com/en-us/windows/uwp/design/style/color#accent-color) for your project from UWP color design article.\n\n```jsx\nimport React               from 'react';\nimport { PaletteProvider } from 'react-prime-ui';\n\nimport MyButton from './UI/MyButton';\n\nexport default class App extends React.Component {\n  render() {\n    return (\n      \u003cPaletteProvider accent=\"#0078D7\" theme=\"light\"\u003e\n        \u003cMyButton\u003eWoohoo!\u003c/MyButton\u003e\n      \u003c/PaletteProvider\u003e\n    )\n  }\n}\n```\n\n\u003e You can choose between `\"light\"` or `\"dark\"` theme. We prefer it \"light\", just like [GitHub](https://github.com/desktop/desktop/issues/2557).\n\n## What's next?\n\nNow you can start using accent colors in your app and components. There are few things you will want to try out.\n\n* [Overriding color for some components](#overriding-color-for-some-components)\n* [Mixing colors with props](#mixing-colors-with-props)\n* [Creating your color based on theme](#creating-your-color-based-on-theme)\n  * [Non-color customization](#non-color-customization)\n* [Working with `glamor`](#working-with-glamor)\n  * [Making it render fast with `glamor`](#making-it-render-fast-with-glamor)\n* [My component has already `connect`-ed with Redux](#my-component-has-already-connect-ed-with-redux)\n\n### Overriding color for some components\n\nIf you provide `accent` or `theme` props to the hoisted component, you can override the accent color provided from `\u003cPaletteProvider\u003e`.\n\nThe following example added `accent=\"#E81123\"` to `\u003cMyButton\u003e` and will fill it red.\n\n```jsx\n\u003cPaletteProvider accent=\"#0078D7\" theme=\"light\"\u003e\n  \u003cMyButton accent=\"#E81123\"\u003eI am red, instead of blue.\u003c/MyButton\u003e\n\u003c/PaletteProvider\u003e\n```\n\n\u003e Tips: You can also override accent color by adding another layer of `\u003cPaletteProvider\u003e`.\n\n### Mixing colors with props\n\nIn addition to our predefined palette, you can also create new colors from props.\n\nIn this example, we set the opacity of the background color by using [`color`](https://npmjs.com/package/color) and varied by passing an `opacity` prop.\n\n```jsx\nimport color from 'color';\n\n// ...\n\nexport default withPalette(({ palette }, props) =\u003e ({\n  fillColor: color(palette.accent).alpha(props.opacity)\n}))(MyButton)\n```\n\nAnd in your app,\n\n```jsx\n\u003cPaletteProvider accent=\"#0078D7\" theme=\"light\"\u003e\n  \u003cMyButton opacity={ 0.5 }\u003eI am transparent\u003c/MyButton\u003e\n\u003c/PaletteProvider\u003e\n```\n\n### Creating your color based on theme\n\nIn addition to the color palette, you can also create your own colors using `theme` from `\u003cPaletteProvider\u003e`.\n\n```jsx\nexport default withPalette(({ palette, theme }, props) =\u003e ({\n  fillColor: theme === 'light' ? palette.accentDark1 : palette.accentLight1\n}))(MyButton)\n```\n\n#### Non-color customization\n\nIn addition to `palette`, all props from `\u003cPaletteProvider\u003e` are passed as first argument to your props factory. In the following example, we are passing `roundness` of `0.5` to `\u003cPaletteProvider\u003e` and it will be piped to `withPalette()`.\n\n```jsx\nexport default withPalette(({ roundness }) =\u003e ({\n  borderRadius: 10 * roundness\n}))(MyButton)\n```\n\nAnd in your app,\n\n```jsx\n\u003cPaletteProvider roundness={ 0.5 }\u003e\n  \u003cMyButton\u003eThis button is round.\u003c/MyButton\u003e\n\u003c/PaletteProvider\u003e\n```\n\n\u003e Tips: You should always consult your designer before customizing any UI designs, they may have designed it intentionally. Don't over-customize!\n\n### Working with glamor\n\n`react-accent-color` is designed to play nice with [`glamor`](https://github.com/threepointone/glamor).\n\nInstead of using `style` props, we can use `glamor` to create CSS style when accent color has updated.\n\n```jsx\nimport React   from 'react';\nimport { css } from 'glamor';\n\nconst createCSS = palette =\u003e css({\n  backgroundColor: palette.backgroundColor\n});\n\nclass MyButton extends React.Component {\n  render() {\n    return (\n      \u003cbutton { ...this.props.css }\u003e\n        { this.props.children }\n      \u003c/button\u003e\n    );\n  }\n}\n\nexport default withPalette(({ palette }) =\u003e ({\n  css: createCSS(palette)\n}))(MyButton)\n```\n\n#### Making it render fast with `glamor`\n\n\u003e Tips: `glamor.css()` calls should be done outside of `render()` and avoid calling it more than you need.\n\nThe factory function passed to `withPalette` will be called when:\n\n* Any props on `\u003cPaletteProvider\u003e` has changed\n* Any props on your component has changed\n\nThis could means, every time a prop on `MyButton` has changed, we will call `glamor.css()`. If the props are updated but not leading to any visible change, it could be saved to improve performance.\n\nYou can use a memoizer to call `css()` only when there are \"meaningful\" changes, i.e. changes that would lead to style update. In the following example, `css()` will only be called when either `palette.accent` or `props.opacity` has changed.\n\n\u003e For your convenience, we exported our shallow memoizer with FIFO = 1, inspired by [`reselect`](https://github.com/reactjs/reselect).\n\n```jsx\nimport { memoize } from 'react-accent-color';\n\nconst createCSS = memoize((accent, opacity) =\u003e css({\n  backgroundColor: color(accent).alpha(opacity)\n}));\n\nexport default withPalette(({ palette }, props) =\u003e ({\n  css: createCSS(palette.accent, props.opacity)\n}))(MyButton)\n```\n\n### My component has already `connect`-ed with Redux\n\nNo worries. HOC pattern is designed to play nice with each other, like `connect()` from Redux.\n\n```jsx\nexport default connect(state =\u003e ({\n  name: state.userProfile.name\n}))(withPalette(({ palette }) =\u003e ({\n  fillColor: palette.accent\n}))(MyButton))\n```\n\n\u003e Tips: You can also pass `accent` prop from `connect()` to make your accent color reactive to Redux.\n\n## Colors\n\nWe follow [UWP color design](https://docs.microsoft.com/en-us/windows/uwp/design/style/color) and exposed the following colors:\n\n| Color name | Light theme | Dark theme |\n| - | - | - |\n| `accentDark1` | `{ accentColor.darken(.2) }` | *(Same as light)* |\n| `accentDark2` | `{ accentColor.darken(.4) }` | *(Same as light)* |\n| `accentDark3` | `{ accentColor.darken(.6) }` | *(Same as light)* |\n| `accentLight1` | `{ accentColor.lighten(.2) }` | *(Same as light)* |\n| `accentLight2` | `{ accentColor.lighten(.4) }` | *(Same as light)* |\n| `accentLight3` | `{ accentColor.lighten(.6) }` | *(Same as light)* |\n| `background` | `#FFF` | `#000` |\n| `foreground` | `#000` | `#FFF` |\n| `baseLow` | `rgba(0, 0, 0, .2)` | `rgba(255, 255, 255, .2)` |\n| `baseMediumLow` | `rgba(0, 0, 0, .4)` | `rgba(255, 255, 255, .4)` |\n| `baseMedium` | `rgba(0, 0, 0, .6)` | `rgba(255, 255, 255, .6)` |\n| `baseMediumHigh` | `rgba(0, 0, 0, .8)` | `rgba(255, 255, 255, .8)` |\n| `baseHigh` | `#000` | `#FFF` |\n| `altLow` | `rgba(255, 255, 255, .2)` | `rgba(0, 0, 0, .2)` |\n| `altMediumLow` | `rgba(255, 255, 255, .4)` | `rgba(0, 0, 0, .4)` |\n| `altMedium` | `rgba(255, 255, 255, .6)` | `rgba(0, 0, 0, .6)` |\n| `altMediumHigh` | `rgba(255, 255, 255, .8)` | `rgba(0, 0, 0, .8)` |\n| `altHigh` | `#FFF` | `#000` |\n| `listLow` | `rgba(0, 0, 0, .1)` | `rgba(255, 255, 255, .1)` |\n| `listMedium` | `rgba(0, 0, 0, .2)` | `rgba(255, 255, 255, .2)` |\n| `listAccentLow` | `{ accentColor.fade(.4) }` | *(Same as light)* |\n| `listAccentMedium` | `{ accentColor.fade(.6) }` | *(Same as light)* |\n| `listAccentHigh` | `{ accentColor.fade(.7) }` | *(Same as light)* |\n| `chromeLow` | `#F2F2F2` | `#171717` |\n| `chromeMediumLow` | `#F2F2F2` | `#2B2B2B` |\n| `chromeMedium` | `#E6E6E6` | `#1F1F1F` |\n| `chromeHigh` | `#CCC` | `#767676` |\n| `chromeAltLow` | `#171717` | `#F2F2F2` |\n| `chromeDisabledLow` | `#7A7A7A` | `#858585` |\n| `chromeDisabledHigh` | `#CCC` | `#333` |\n| `chromeBlackLow` | `rgba(0, 0, 0, .2)` | *(Same as light)* |\n| `chromeBlackMediumLow` | `rgba(0, 0, 0, .4)` | *(Same as light)* |\n| `chromeBlackMedium` | `rgba(0, 0, 0, .8)` | *(Same as light)* |\n| `chromeBlackHigh` | `#000` | *(Same as light)* |\n| `chromeWhite` | `#FFF` | *(Same as light)* |\n| `primaryText` | *(Same as `baseHigh`)* | *(Same as `baseHigh`)* |\n| `secondaryText` | *(Same as `baseMedium`)* | *(Same as `baseMedium`)* |\n| `disabledUI` | *(Same as `baseMediumLow`)* | *(Same as `baseMediumLow`)* |\n\n### Foreground color\n\nFinding the right foreground color can be tricky because the fill color can be too bright for white text, and vice versa. What's more, for accessibility, it should have contrast ratio of [4.5:1](http://www.w3.org/TR/WCAG20-TECHS/G18.html).\n\nWe provide foreground colors from `palette.textOn` maps. For example, to get the foreground color for `listLow` color, you can get it from `palette.textOn.listLow`. For example,\n\n```js\nexport default withPalette(({ palette }) =\u003e ({\n  fillColor: palette.listLow,\n  color    : palette.textOn.listLow\n}))(MyButton)\n```\n\nThe foreground color is by calculating if the fill color is \"dark\", using the following algorithm (inspired from UWP):\n\n```js\nfunction isDark(color) {\n  return color.green() * 5 + color.red() * 2 + color.blue() \u003c= 8 * 128;\n}\n```\n\n\u003e Foreground color is either `\"white\"` or `\"black\"`.\n\n## Contribution\n\nLike us? [Star](https://github.com/compulim/react-accent-color/stargazers) us.\n\nDoesn't like something? File us an [issue](https://github.com/compulim/react-accent-color/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompulim%2Freact-accent-color","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompulim%2Freact-accent-color","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompulim%2Freact-accent-color/lists"}