Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-shadow

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-shadow

Use Shadow DOM with React.js and CSS imports; write your component styles in CSS!

  • 0.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
70K
increased by113.77%
Maintainers
1
Weekly downloads
 
Created
Source

ReactShadow

Travis   Experimental   License MIT

  • Heroku: http://react-shadow.herokuapp.com/

Screenshot


With ReactShadow you can apply a Shadow DOM root inside of your component. Under normal React.js conditions, your styles are written inline for style encapsulation – with ReactShadow your styles can now be moved into their rightful place – within CSS documents!

Getting Started

ReactShadow is implemented as a mixin that you can import into your component:

var ReadmeApp = $react.createClass({
    mixins: [ReactShadow]
});

From there ReactShadow will take over – creating a shadow root inside of your component, and importing any CSS documents defined in your cssDocuments property – which can be either an array or a function:

var ReadmeApp = $react.createClass({
    mixins: [ReactShadow],
    cssDocuments: ['../css/Default.css']
});

If you're applying CSS documents at runtime then it may well be useful to have the cssDocuments property as a function:

var ReadmeApp = $react.createClass({
    mixins: [ReactShadow],
    cssDocuments: function cssDocuments() {
        return ['../css/Component.css', '../css/' + this.props.cssDocument];
    }
});

You can inline css with cssSource property.

var ReadmeApp = $react.createClass({
    mixins: [ReactShadow],
    cssSource: "body { color: black; }"
});

When cssDocuments and cssSource are both defined, style defined in cssSource is appended after cssDocuments.

Event Retargeting

As Shadow DOM has the concept of Event Retargeting for encapsulation purposes, event delegation will not function correctly because all events will appear to be coming from the Shadow DOM – therefore ReactShadow uses the React ID for each element to dispatch the event from the original element, therefore maintaining React's event delegation implementation.

Events are therefore written in exactly the same way:

var ReadmeApp = $react.createClass({
    render: function render() {
        return <a onClick={this.reset} title="Reset Counter">
                   Reset, Comrade!
               </a>
    }
});

Keywords

FAQs

Package last updated on 20 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc