redux-devtools/packages/react-base16-styling
renovate[bot] 9a77585dd7
chore(deps): update all non-major dependencies (#758)
* chore(deps): update all non-major dependencies

* Prettify

* Combine versions

* Downgrade knex

* Engine changes

* Only LTS

* Greater than

* Combine lodash

* Fix type

* Fix type

* Update snapshots

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Nathan Bierema <nbierema@gmail.com>
2021-08-26 09:52:23 -04:00
..
src chore(*): upgrade prettier (#743) 2021-06-17 23:56:36 -04:00
test chore(*): upgrade to TypeScript 4.0 (#736) 2021-06-16 12:20:20 -04:00
.babelrc refactor(react-base16-styling)!: convert react-base16-styling to TypeScript (#592) 2020-08-16 09:00:54 -04:00
.eslintignore refactor(react-base16-styling)!: convert react-base16-styling to TypeScript (#592) 2020-08-16 09:00:54 -04:00
.eslintrc.js feat(redux-devtools-serialize): convert to TypeScript (#621) 2020-08-29 00:14:49 -04:00
CHANGELOG.md feature(devui): convert to TypeScript (#629) 2020-09-09 10:35:22 -04:00
jest.config.js refactor(react-base16-styling)!: convert react-base16-styling to TypeScript (#592) 2020-08-16 09:00:54 -04:00
LICENSE.md chore(*): add back license files (#578) 2020-08-09 01:11:43 -04:00
package.json chore(deps): update all non-major dependencies (#758) 2021-08-26 09:52:23 -04:00
README.md chore(*): upgrade prettier (#570) 2020-08-08 16:26:39 -04:00
tsconfig.json refactor(react-base16-styling)!: convert react-base16-styling to TypeScript (#592) 2020-08-16 09:00:54 -04:00

react-base16-styling Build Status Latest Stable Version

React styling with base16 color scheme support

Inspired by react-themeable, this utility provides flexible theming for your component with base16 theme support.

Install

yarn add react-base16-styling

Usage

import { createStyling } from 'react-base16-styling';
import base16Themes from './base16Themes';

function getStylingFromBase16(base16Theme) {
  return {
    myComponent: {
      backgroundColor: base16Theme.base00,
    },

    myComponentToggleColor({ style, className }, clickCount) {
      return {
        style: {
          ...style,
          backgroundColor: clickCount % 2 ? 'red' : 'blue',
        },
      };
    },
  };
}

const createStylingFromTheme = createStyling(getStylingFromBase16, {
  defaultBase16: base16Themes.solarized,
  base16Themes,
});

class MyComponent extends Component {
  state = { clickCount: 0 };
  render() {
    const { theme } = this.props;
    const { clickCount } = this.state;

    const styling = createStylingFromTheme(theme);

    return (
      <div {...styling('myComponent')}>
        <a onClick={() => this.setState({ clickCount: clickCount + 1 })}>
          Click Me
        </a>
        <div {...styling('myComponentToggleColor', clickCount)}>
          {clickCount}
        </div>
      </div>
    );
  }
}

createStyling

function(getStylingFromBase16, defaultStylingOptions, themeOrStyling)
Argument Signature Description
getStylingFromBase16 function(base16Theme) creates object with default stylings for your component, using provided base16 theme.
defaultStylingOptions { defaultBase16, base16Themes } optional parameters, allow to set default base16 theme and additional base16 themes for component.
themeOrStyling string or object base16 theme name, base16 theme object or styling object. Theme name can have a modifier: "themeName:inverted" to invert theme colors (see #invertTheme)

Styling object values could be: - objects (treated as style definitions) - strings (class names) - functions (they may be provided with additional parameters and should return object { style, className })

getBase16Theme

function(themeOrStyling, base16Themes)

Helper method that returns base16 theme object if themeOrStyling is base16 theme name or theme object.

invertBase16Theme

function(base16Theme)

Helper method that inverts base16 theme colors, creating light theme out of dark one or vice versa.

invertTheme

function(theme)

Helper method that inverts a theme or styling object to be passed into the themeOrStyling parameter of createStyling.