Skip to content

Commit 6c3a342

Browse files
committed
first commit
0 parents  commit 6c3a342

11 files changed

+5733
-0
lines changed

.babelrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env",
4+
"@babel/preset-react"
5+
]
6+
}

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
logfile
2+
3+
.env
4+
5+
node_modules/
6+
lib/

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/
2+
test/

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"printWidth": 70,
6+
}

.travis.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: node_js
2+
3+
node_js:
4+
- stable
5+
6+
install:
7+
- npm install
8+
9+
script:
10+
- npm run test
11+
12+
after_script:
13+
- npm run coverage

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Robin Wieruch
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# useCustomElement React Hook
2+
3+
[![Build Status](https://travis-ci.org/the-road-to-learn-react/use-custom-element.svg?branch=master)](https://travis-ci.org/the-road-to-learn-react/use-custom-element) [![Slack](https://slack-the-road-to-learn-react.wieruch.com/badge.svg)](https://slack-the-road-to-learn-react.wieruch.com/) [![Greenkeeper badge](https://badges.greenkeeper.io/the-road-to-learn-react/use-custom-element.svg)](https://greenkeeper.io/) [![Coverage Status](https://coveralls.io/repos/github/the-road-to-learn-react/use-custom-element/badge.svg?branch=master)](https://coveralls.io/github/the-road-to-learn-react/use-custom-element?branch=master) ![NPM](https://img.shields.io/npm/l/use-custom-element.svg)
4+
5+
Custom hook to bridge Custom Elements (Web Components) to React.
6+
7+
## Installation
8+
9+
`npm install use-custom-element`
10+
11+
## Usage
12+
13+
In this scenario, we are using a specific [Dropdown Web Component](https://github.com/rwieruch/web-components-dropdown) 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.
14+
15+
```
16+
import React from 'react';
17+
18+
// Web Component Use Case
19+
// install via npm install road-dropdown
20+
import 'road-dropdown';
21+
22+
import customElementProps from 'use-custom-element';
23+
24+
const Dropdown = props => {
25+
const [customElementProps, ref] = useCustomElement(props);
26+
27+
return <road-dropdown {...customElementProps} ref={ref} />;
28+
};
29+
```
30+
31+
Afterward, the Dropdown component can be used:
32+
33+
```
34+
const props = {
35+
label: 'Label',
36+
option: 'option1',
37+
options: {
38+
option1: { label: 'Option 1' },
39+
option2: { label: 'Option 2' },
40+
},
41+
onChange: (value) => console.log(value),
42+
};
43+
44+
return <Dropdown {...props} />;
45+
```
46+
47+
## Contribute
48+
49+
* `git clone git@github.com:the-road-to-learn-react/use-custom-element.git`
50+
* `cd use-custom-element`
51+
* `npm install`
52+
* `npm run test`
53+
54+
### More
55+
56+
* [Publishing a Node Package to NPM](https://www.robinwieruch.de/publish-npm-package-node/)
57+
* [Node.js Testing Setup](https://www.robinwieruch.de/node-js-testing-mocha-chai/)
58+
* [React Testing Setup](https://www.robinwieruch.de/react-testing-tutorial/)

0 commit comments

Comments
 (0)