React Base16 Styling

0.10.0 · abandoned · verified Sun Apr 19

react-base16-styling provides a utility for flexible theming of React components, specifically integrating with base16 color schemes. Its current and only stable version is `0.10.0`, published in late 2017. The package is effectively unmaintained, with no releases or significant code changes in over six years. It distinguishes itself by offering a `createStyling` factory that consumes `base16` themes, allowing component styles to be defined as static objects, dynamic functions returning style objects, or simple class names, inspired by `react-themeable`. Due to its age, it may not be compatible with modern React features like Hooks or the latest lifecycle methods, and lacks updates for potential security vulnerabilities or performance optimizations, making it unsuitable for new projects.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `createStyling` with base16 themes and apply dynamic styles within a React class component. It shows both static style objects and functions for conditional styling.

import React, { Component } from 'react';
import { createStyling } from 'react-base16-styling';

// Mock base16Themes for runnable example
const base16Themes = {
  solarized: {
    base00: '#002b36', // Dark background
    base01: '#073642',
    base02: '#586e75',
    base03: '#657b83',
    base04: '#839496',
    base05: '#93a1a1', // Light foreground
    base06: '#eee8d5',
    base07: '#fdf6e3',
    base08: '#dc322f',
    base09: '#cb4b16',
    base0A: '#b58900',
    base0B: '#859900',
    base0C: '#2aa198',
    base0D: '#268bd2',
    base0E: '#6c71c4',
    base0F: '#d33682'
  }
};

function getStylingFromBase16(base16Theme) {
  return {
    myComponent: {
      backgroundColor: base16Theme.base00,
      color: base16Theme.base05, // Added for readability
      padding: '10px',
      borderRadius: '5px'
    },

    myComponentToggleColor({ style, className }, clickCount) {
      return {
        style: {
          ...style,
          backgroundColor: clickCount % 2 === 0 ? base16Theme.base0D : base16Theme.base08, // Using base16 colors
          color: 'white',
          padding: '5px',
          marginTop: '10px'
        },
        className
      };
    }
  };
}

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')} style={{ width: '300px', margin: '20px auto', textAlign: 'center' }}>
        <p>This is a themed component.</p>
        <button onClick={() => this.setState({ clickCount: clickCount + 1 })} style={{ padding: '8px 15px', cursor: 'pointer' }}>
          Click Me
        </button>
        <div {...styling('myComponentToggleColor', clickCount)}>
          Click Count: {clickCount}
        </div>
      </div>
    );
  }
}

export default MyComponent; // Export for use in a larger app

view raw JSON →