All Projects → the-road-to-learn-react → Use Custom Element

the-road-to-learn-react / Use Custom Element

Licence: mit
Custom hook to bridge Custom Elements (Web Components) to React.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Use Custom Element

Ion Phaser
A web component to use Phaser Framework with Angular, React, Vue, etc 🎮
Stars: ✭ 152 (+97.4%)
Mutual labels:  web-components, custom-elements, web-component
cwco
Powerful and Fast Web Component Library with a Simple API
Stars: ✭ 27 (-64.94%)
Mutual labels:  web-component, web-components, custom-elements
svelte-webcomponents
A ready-to-use project template to build custom elements (web components) with Svelte 3 with support and examples for web components, jest, sass, nested components with props, eslinting, stylelinting, Github actions, propagating custom events from shadow-DOM to real-DOM etc.
Stars: ✭ 22 (-71.43%)
Mutual labels:  web-component, web-components, custom-elements
Lume
Create CSS3D/WebGL applications declaratively with HTML. Give regular DOM elements shadow and lighting.
Stars: ✭ 445 (+477.92%)
Mutual labels:  web-components, custom-elements
Include Fragment Element
A client-side includes tag.
Stars: ✭ 380 (+393.51%)
Mutual labels:  web-components, custom-elements
Vaadin Grid
vaadin-grid is a free, high quality data grid / data table Web Component. Part of the Vaadin components.
Stars: ✭ 383 (+397.4%)
Mutual labels:  custom-elements, web-component
Weightless
High-quality web components with a small footprint
Stars: ✭ 284 (+268.83%)
Mutual labels:  web-components, custom-elements
Vaadin Charts
Vaadin Charts is a feature-rich interactive graph library that answers the data visualization needs of modern web applications
Stars: ✭ 47 (-38.96%)
Mutual labels:  web-components, web-component
Details Menu Element
A menu opened with <details>.
Stars: ✭ 455 (+490.91%)
Mutual labels:  web-components, custom-elements
Task Lists Element
Drag and drop task list items.
Stars: ✭ 73 (-5.19%)
Mutual labels:  web-components, custom-elements
File Input
A better <input type="file">
Stars: ✭ 59 (-23.38%)
Mutual labels:  web-components, custom-elements
Monogatari
Monogatari is a simple web visual novel engine, created to bring Visual Novels to the web.
Stars: ✭ 357 (+363.64%)
Mutual labels:  web-components, custom-elements
Three Elements
Web Components-powered custom HTML elements for building Three.js-powered games and interactive experiences. 🎉
Stars: ✭ 331 (+329.87%)
Mutual labels:  web-components, custom-elements
Custom Elements Ts
Create native custom elements using Typescript
Stars: ✭ 52 (-32.47%)
Mutual labels:  web-components, custom-elements
Synergy
Synergy is a tiny runtime library for building web user interfaces
Stars: ✭ 296 (+284.42%)
Mutual labels:  web-components, custom-elements
Vanilla Colorful
A tiny color picker custom element for modern web apps (2.7 KB) 🎨
Stars: ✭ 467 (+506.49%)
Mutual labels:  web-components, custom-elements
Dark Mode Toggle
A custom element that allows you to easily put a Dark Mode 🌒 toggle or switch on your site:
Stars: ✭ 550 (+614.29%)
Mutual labels:  web-components, custom-elements
Emoji Picker Element
A lightweight emoji picker for the modern web
Stars: ✭ 587 (+662.34%)
Mutual labels:  web-components, custom-elements
Details Dialog Element
A modal dialog that's opened with <details>.
Stars: ✭ 603 (+683.12%)
Mutual labels:  web-components, custom-elements
storify
Instagram/Whatsapp stories clone built on Web Components and Web Animations API. 🔥
Stars: ✭ 64 (-16.88%)
Mutual labels:  web-components, custom-elements

useCustomElement React Hook

Build Status Slack Greenkeeper badge NPM

Custom hook to bridge Custom Elements (Web Components) to React.

Installation

npm install use-custom-element

Usage

In this scenario, we are using a specific Dropdown Web Component as a React Dropdown Component. By using the custom React hook, we can provide all props in the right format to the custom element and register all event listeners (e.g. onChange from props) behind the scenes.

import React from 'react';

// Web Component Use Case
// install via npm install road-dropdown
import 'road-dropdown';

import useCustomElement from 'use-custom-element';

const Dropdown = props => {
  const [customElementProps, ref] = useCustomElement(props);

  return <road-dropdown {...customElementProps} ref={ref} />;
};

Afterward, the Dropdown component can be used:

const props = {
  label: 'Label',
  option: 'option1',
  options: {
    option1: { label: 'Option 1' },
    option2: { label: 'Option 2' },
  },
  onChange: (value) => console.log(value),
};

return <Dropdown {...props} />;

Custom Mapping

You can also define a custom mapping:

import React from 'react';

// Web Component Use Case
// install via npm install road-dropdown
import 'road-dropdown';

import useCustomElement from 'use-custom-element';

const Dropdown = props => {
  const [customElementProps, ref] = useCustomElement(props, {
    option: 'selected',
    onChange: 'click',
  });

  console.log(customElementProps);

  // label: "Label"
  // options: "{"option1":{"label":"Option 1"},"option2":{"label":"Option 2"}}"
  // selected: "option1"

  // and "onChange" mapped to "click" event for the event listener

  return <my-dropdown {...customElementProps} ref={ref} />;
};

Contribute

  • git clone [email protected]:the-road-to-learn-react/use-custom-element.git
  • cd use-custom-element
  • npm install
  • npm run test

More

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