Socket
Socket
Sign inDemoInstall

react-polymer-component

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-polymer-component

A generic React.Component for wrapping Polymer Elements and binding events and property data between them


Version published
Weekly downloads
1
Maintainers
1
Install size
11.9 kB
Created
Weekly downloads
 

Changelog

Source

[0.1.4]-2019-06-03

Added

  • Deprecation message.

Readme

Source

This package is deprecated

This project represents an experiment to simplify the use of Polymer Elements with React Components but is not intended to for use in a production environment and no longer maintained.

react-polymer-component

npm version travis build lgtm code quality

A generic React.Component for wrapping Polymer Elements and binding events and property data between them. No changes to the element required!

Use

Wrapping an Element

Polymer elements can be wrapped and used in two ways and used just like any other React component in the render() function:

const React = require('react')

// Generic class for wrapping a Polymer element
const PolymerComponent = require('react-polymer-component')

// Get a class that specifically wraps the element 'my-polymer-element'
const MyPolymerElement = PolymerComponent.bind('my-polymer-element')

class SubComponent extends React.Component {
  // ...
  render() {
    return <div>
      // ...
      <PolymerComponent element-tag="my-polymer-element"></PolymerElement>
      // or
      <MyPolymerElement></MyPolymerElement>
      // ...
    </div>
  }
}

Binding Data

Data is bound like all other React properties and set on the Polymer element using the set() function. The property must exist in the Polymer class' properties object to be bound. If a bound property is removed or set to undefined, then the original Polymer property value is used.

<MyPolymerElement items={ this.props.items }></MyPolymerElement>

Event Handling

Events are registered using the existing Polymer convention of prefixing events with on-, so they can easily be bound to from a React component.

<MyPolymerElement on-my-custom-event={ e => console.log('Event Fired!', e) }></MyPolymerElement>

Slotted Children

Slot elements and slotted children work as expected, including using the slot attribute field.

<MyPolymerElement>
  <div slot="special-slot">Slotted Content!</div>
</MyPolymerElement>

Styling

The styles passed to the element are applied to the Polymer element directly. CSS variables work to the extent that they work in modern browsers.

<MyPolymerElement style={ { '--color-variable': 'red' } }></MyPolymerElement>

Keywords

FAQs

Last updated on 05 Jun 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc