All Projects β†’ danbahrami β†’ React Custom Properties

danbahrami / React Custom Properties

Licence: mit
A React component for applying CSS Variables (Custom Properties)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Custom Properties

v-helper
A shorter SCSS access to CSS custom properties.
Stars: ✭ 14 (-75.44%)
Mutual labels:  css-variables
scroll-padlock
πŸ”’ CSS variables-based scrollbars locker, compatible with all reactive frameworks
Stars: ✭ 12 (-78.95%)
Mutual labels:  css-variables
Tailwindcss Theming
Tailwind CSS plugin for client-side theming using CSS variables, with dark mode support
Stars: ✭ 349 (+512.28%)
Mutual labels:  css-variables
multi-brand-colors
Multi Brand Colors with support for CSS/CSS-Vars/SCSS/SASS/Stylus/LESS/JSON
Stars: ✭ 26 (-54.39%)
Mutual labels:  css-variables
svelte-style-directive
A custom Svelte preprocessor to add support for style directive.
Stars: ✭ 19 (-66.67%)
Mutual labels:  css-variables
animadio
Animadio CSS Framework
Stars: ✭ 24 (-57.89%)
Mutual labels:  css-variables
fylgja
The modular highly customisable CSS framework. Powered by CSS Components, Utilities and Props for building your Web UI.
Stars: ✭ 65 (+14.04%)
Mutual labels:  css-variables
Ie11customproperties
CSS variables (Custom Properties) polyfill for IE11
Stars: ✭ 765 (+1242.11%)
Mutual labels:  css-variables
tailwindcss-variables
Easily create css variables without the need for a css file!
Stars: ✭ 47 (-17.54%)
Mutual labels:  css-variables
Grayshift
A lightweight front-end component library for developing fast and powerful web interfaces.
Stars: ✭ 304 (+433.33%)
Mutual labels:  css-variables
focussed-twitter
Let's focus on the tweets! 🐦
Stars: ✭ 15 (-73.68%)
Mutual labels:  css-variables
theme-change
Change CSS theme with toggle, buttons or select using CSS custom properties and localStorage
Stars: ✭ 283 (+396.49%)
Mutual labels:  css-variables
Switzerland
πŸ‡¨πŸ‡­Switzerland takes a functional approach to Web Components by applying middleware to your components. Supports Redux, attribute mutations, CSS variables, React-esque setState/state, etc… out-of-the-box, along with Shadow DOM for style encapsulation and Custom Elements for interoperability.
Stars: ✭ 261 (+357.89%)
Mutual labels:  css-variables
kladenets
Future-proof native CSS variables in :root
Stars: ✭ 25 (-56.14%)
Mutual labels:  css-variables
Must Watch Css
A useful list of must-watch talks about CSS
Stars: ✭ 3,966 (+6857.89%)
Mutual labels:  css-variables
pollen
The CSS variables build system
Stars: ✭ 754 (+1222.81%)
Mutual labels:  css-variables
svelte-themer
A theming engine for your Svelte apps using CSS Variables, persisted.
Stars: ✭ 88 (+54.39%)
Mutual labels:  css-variables
Snack Helper
πŸ—ƒ A universal CSS helper library.
Stars: ✭ 50 (-12.28%)
Mutual labels:  css-variables
Darken
πŸŒ‘ Dark mode made easy
Stars: ✭ 571 (+901.75%)
Mutual labels:  css-variables
You Need To Know Css
πŸ’„CSS tricks for web developers~
Stars: ✭ 3,777 (+6526.32%)
Mutual labels:  css-variables

React Custom Properties

A React component for declaratively applying CSS Variables or CSS Custom Properties as the are officially known. For CSS variable usage see https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables

Install

To get started install via npm

npm install react-custom-properties

You can then import the component into your code using ES5 require

var CustomProperties = require('react-custom-properties');

or ES6 imports

import CustomProperties from 'react-custom-properties';

Usage

This module provides a <CustomProperties /> component. When mounted it will, by default, apply any CSS variables passed to the properties component to its children.

So for example, your stylesheet may contain CSS Variables like this.

.header {
  background: var(--branding-color);
}

And you can apply values to those variables like this.

import React, { Component } from 'react';
import CustomProperties from 'react-custom-properties';

class App extends Component {
  render() {
    return (
      <div>
        <CustomProperties properties={{ '--branding-color': '#FF0000' }}>
          <div className="header">
            this will have the background color #FF0000
          </div>
        </CustomProperties>
      </div>
    );
  }
}

Nesting

The CustomProperties component can be nested so that properties set by parent instances are overridden by ones set by child instances. So for example...

Using the same stylesheet as before

import React, { Component } from 'react';
import CustomProperties from 'react-custom-properties';

class App extends Component {
  render() {
    return (
      <div>
        <CustomProperties properties={{ '--branding-color': '#FF0000' }}>
          <div className="header">
            this will have the background color #FF0000
          </div>
          
          <CustomProperties properties={{ '--branding-color': '#555555' }}>
            <div className="header">
              this will have the background color #555555
            </div>
          </CustomProperties>
        </CustomProperties>
      </div>
    );
  }
}

Global

The CustomProperties component accepts a boolean global prop. By default the CSS Variables will only apply to the component's children. When the global prop is passed the CSS Variables will be set on the document root and will therefor be globally applied to all styles.

Using the same stylesheet as before

import React, { Component } from 'react';
import CustomProperties from 'react-custom-properties';

class App extends Component {
  render() {
    return (
      <div>
        <CustomProperties 
          global
          properties={{ '--branding-color': '#FF0000' }} 
        />

        <div className="header">
          this will have the background color #FF0000
        </div>
      </div>
    );
  }
}

Any properties set by a non-global instance will take precedence over properties set by a global instance

Credit

Contribute

  1. Fork this repo
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make sure the tests pass (npm run test)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].