All Projects → reactive-elements → Reactive Elements

reactive-elements / Reactive Elements

Allows to use React.js component as HTML element (web component)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Reactive Elements

Apollo Elements
🚀🌛 Use the Launch Platform 👩‍🚀👨‍🚀
Stars: ✭ 278 (-60%)
Mutual labels:  webcomponents
Awesome Polymer
A collection of awesome Polymer resources.
Stars: ✭ 384 (-44.75%)
Mutual labels:  webcomponents
Shoelace
A collection of professionally designed, every day UI components built on a framework-agnostic technology. 🥾
Stars: ✭ 5,904 (+749.5%)
Mutual labels:  webcomponents
Snuggsi
snuggsi ツ - Easy Custom Elements in ~1kB
Stars: ✭ 288 (-58.56%)
Mutual labels:  webcomponents
Vaadin Core
An evolving set of free, open source web components for building mobile and desktop web applications in modern browsers.
Stars: ✭ 382 (-45.04%)
Mutual labels:  webcomponents
Vaadin
An evolving set of open source web components for building mobile and desktop web applications in modern browsers.
Stars: ✭ 424 (-38.99%)
Mutual labels:  webcomponents
orgenic-ui
ORGENIC UI is an MIT-licensed open source project for creating strong user interfaces with high quality web components.
Stars: ✭ 53 (-92.37%)
Mutual labels:  webcomponents
React Svg Pan Zoom
👀 A React component that adds pan and zoom features to SVG
Stars: ✭ 569 (-18.13%)
Mutual labels:  webcomponents
Vaadin Grid
vaadin-grid is a free, high quality data grid / data table Web Component. Part of the Vaadin components.
Stars: ✭ 383 (-44.89%)
Mutual labels:  webcomponents
Awesome Stenciljs
List of Awesome Web Components Built with StencilJS
Stars: ✭ 520 (-25.18%)
Mutual labels:  webcomponents
Spectrum Web Components
Spectrum Web Components
Stars: ✭ 314 (-54.82%)
Mutual labels:  webcomponents
Westore
更好的小程序项目架构
Stars: ✭ 3,897 (+460.72%)
Mutual labels:  webcomponents
Framework
A modular front-end framework - inspired by the server-side and Web Components.
Stars: ✭ 448 (-35.54%)
Mutual labels:  webcomponents
Google Chart
Google Charts API web components
Stars: ✭ 284 (-59.14%)
Mutual labels:  webcomponents
Resize Observer
Polyfills the ResizeObserver API.
Stars: ✭ 540 (-22.3%)
Mutual labels:  webcomponents
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 (-62.45%)
Mutual labels:  webcomponents
Mosaic
🎨 A front-end JavaScript library for building user interfaces!
Stars: ✭ 390 (-43.88%)
Mutual labels:  webcomponents
Rendertron
A Headless Chrome rendering solution
Stars: ✭ 5,593 (+704.75%)
Mutual labels:  webcomponents
Elix
High-quality, customizable web components for common user interface patterns
Stars: ✭ 546 (-21.44%)
Mutual labels:  webcomponents
Vanilla Colorful
A tiny color picker custom element for modern web apps (2.7 KB) 🎨
Stars: ✭ 467 (-32.81%)
Mutual labels:  webcomponents
Reactive Elements

Note! The docs here are for the v1.0.0 alpha. This is not ready for production use yet.

You should use this README, which refers to 0.10.0, the latest stable version on npm: https://github.com/PixelsCommander/ReactiveElements/blob/7cce3d7b472989878ac1433cec0e8168fd4136aa/README.md

Convert React.js components into Web Components

npm install reactive-elements
yarn add reactive-elements

How to use?

Directly in a browser

Placing component in a pure HTML

<body>
	<my-react-component items="{window.someArray}"></my-react-component>
</body>

React class definition

/* @jsx React.DOM */
MyComponent = React.createClass({
  render: function() {
    console.log(this.props.items); // passed as HTML tag`s argument
    console.log(this.props.children); // original tag children
    return (
      <ul>
        <li>React content</li>
      </ul>
    );
  },
});

ReactiveElements('my-react-component', MyComponent);

With Bundler

import React, { Component } from 'react';
import ReactiveElements from 'reactive-elements';

class Welcome extends Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}

ReactiveElements('welcome-component', Welcome);

Nesting

Original children of a custom element is injected to component as this.props.children.

<my-react-component>Hello world</my-react-component>

In this case this.props.children is equal to "Hello world".

Container node of the element is passed as this.props.container. Both props.container and props.children have type of documentFragment.

Boolean attribute transforms (added in version 0.7.0)

An attribute that has the value "true" or "false" will be converted into the boolean true or false when given to the React component:

<my-react-component is-logged-in="true">Hello world</my-react-component>

Here, this.props.isLoggedIn === true within the React component.

If you don't want this behaviour you can disable it with a special attribute:

<my-react-component is-logged-in="true" reactive-elements-no-boolean-transform>Hello world</my-react-component>

Exposing components methods on custom element

If you want to expose React component methods on custom element - assign them to component as following:

componentDidMount: function() {
    this.props.container.setTextContent = this.setTextContent.bind(this);
}

Handling attributes change

You may add attributeChanged callback to component in order to handle / modify / filter incoming values.

attributeChanged: function(attributeName, oldValue, newValue) {
    console.log('Attribute ' + attributeName + ' was changed from ' + oldValue + ' to ' + newValue);
    this.props[attributeName] = parseInt(newValue);
}

Communicate via DOM events

You may trigger DOM event from React component by using following snippet:

var event = new CustomEvent('change', {
  bubbles: true,
});
React.findDOMNode(this).dispatchEvent(event);

Subscribing to DOM events is similar:

React.findDOMNode(this).addEventListener('change', function(e){...});

Options

You can also specify options to the ReactiveElements call, e.g.

ReactiveElements('welcome-component', Welcome, options);

options.useShadowDom (default false)

By default, your React element is rendered directly into the web-component root. However, by setting this option - your React element will instead be rendered in a Shadow DOM inside the web-component instead.

Dependencies

  • React.js
  • React DOM
  • Custom elements support or polyfill
  • Support or polyfills for:
    • regexp.match
    • regexp.replace
    • object.define-setter
    • object.define-getter
    • object.define-property
    • function.name
    • web.dom.iterable
    • array.iterator
    • object.keys
    • object.set-prototype-of
    • reflect.construct
    • function.bind

License

MIT: http://mit-license.org/

Copyright 2014 Denis Radin aka PixelsCommander

Inspired by Christopher Chedeau`s react-xtags

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].