redux-devtools/packages/react-base16-styling
Nathan Bierema ba5bd18d5b Publish
- remotedev-redux-devtools-extension@3.0.0
 - d3-state-visualizer@1.4.2
 - d3tooltip@1.3.2
 - map2tree@1.5.2
 - react-base16-styling@0.8.2
 - react-dock@0.4.2
 - react-json-tree@0.15.2
 - @redux-devtools/app@1.0.0
 - @redux-devtools/chart-monitor@1.9.2
 - @redux-devtools/cli@1.0.0
 - @redux-devtools/dock-monitor@1.4.2
 - @redux-devtools/extension@3.0.0
 - @redux-devtools/inspector-monitor-test-tab@0.7.4
 - @redux-devtools/inspector-monitor-trace-tab@0.2.4
 - @redux-devtools/inspector-monitor@1.0.2
 - @redux-devtools/instrument@1.11.2
 - @redux-devtools/log-monitor@2.3.2
 - @redux-devtools/remote@0.6.1
 - @redux-devtools/rtk-query-monitor@1.0.2
 - @redux-devtools/serialize@0.3.2
 - @redux-devtools/slider-monitor@2.0.0
 - @redux-devtools/ui@1.0.0
 - @redux-devtools/utils@1.0.0
 - @redux-devtools/core@3.9.2
 - d3-state-visualizer-tree-example@0.1.2
 - react-dock-demo@0.1.2
 - react-json-tree-example@1.1.4
 - test-demo@0.1.2
 - inspector-demo@0.1.2
 - rtk-query-demo@0.1.2
 - slider-todomvc@0.1.4
 - counter-redux@0.1.4
 - todomvc@0.2.3
2022-01-07 21:24:58 -05:00
..
src chore(deps): update typescript-eslint monorepo to v5 (major) (#907) 2021-10-21 19:08:35 +00:00
test chore(deps): update typescript-eslint monorepo to v5 (major) (#907) 2021-10-21 19:08:35 +00:00
.babelrc chore(*): clean up babel configs (#816) 2021-08-29 23:25:48 +00:00
.eslintignore refactor(react-base16-styling)!: convert react-base16-styling to TypeScript (#592) 2020-08-16 09:00:54 -04:00
.eslintrc.js chore(*): move devDependencies back to packages (#870) 2021-09-18 23:47:03 +00:00
CHANGELOG.md feature(devui): convert to TypeScript (#629) 2020-09-09 10:35:22 -04:00
jest.config.js chore(deps): update jest monorepo (major) (#791) 2021-08-27 16:08:40 +00:00
LICENSE.md chore(*): add back license files (#578) 2020-08-09 01:11:43 -04:00
package.json Publish 2022-01-07 21:24:58 -05:00
README.md chore(*): remove Travis (#864) 2021-09-17 15:02:33 +00: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 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.