Regap
Use your React components as WebComponents.
Motivation
React is a very popular frontend framework. A lot of companies builds own UI libraries based on React. Regap helps you to provide your React UI library as WebComponents. For example:
- It helps your designer to build prototypes just using HTML/CSS.
- It helps your 3rd party teams without special skills to build simple landing pages and etc.
- It helps your to share knoweldge to all your teams about how your UI library looks and feels.
Base concepts
Attributes reflection
Regap provides feature to reflect WebComponents attributes to React components props.
Usage example
// react-component.js; Component static propTypes = someCounter: ReactPropTypesnumberisRequired ; { return <div>Some counter: thispropssomeCounter</div> ; } // regap-component.js;; ; // Render WebComponent to bodydocumentbodyinnerHTML = '<x-example some-counter="5"></x-example>'; // Get WecComponent's instancelet xExample = documentbody; xExample; // Rerender component throw `setAttribute` call.xExample'some-counter' = 20; // Rerender component throw property assign.
Predefined types
regap.types.ArrayType
regap.types.BooleanType
regap.types.FunctionType
regap.types.NumberType
regap.types.ObjectType
regap.types.StringType
Callbacks binding
Regap provides feature to bind WebComponents callbacks to React components callbacks props.
Usage example
// react-component.js; Component static propTypes = onClick: ReactPropTypefuncisRequired ; { thisprops; } { return <div onClick= thishandleClick /> ; } // regap-component.js;; ; // Render WebComponent to bodydocumentbodyinnerHTML = '<x-example></x-example>'; // Get WecComponent's instancelet xExample = documentbody; // Subscribe to React component's event.xExample;
Public methods binding
Regap provides feature to bind WebComponents public methods to React components public methods.
Usage example
// react-component.js; Component /** * @public */ { thisinput; } { return <input ref= { thisinput = input; } /> ; } // regap-component.js;; ; // Render WebComponent to bodydocumentbodyinnerHTML = '<x-example></x-example>'; // Get WecComponent's instancelet xExample = documentbody; // Call React component's public method.xExample;
Slots
Regap provides feature to reflect WebComponents slots to React components props.
// react-component.js; Component static propTypes = someOtherChildren: ReactPropTypesnode ; { return <div> thispropschildren <span>thispropssomeOtherChildren</span> </div> ; } // regap-component.js;; ; // Render WebComponent to bodydocumentbodyinnerHTML = '<x-example>' + 'Some children content' + '<span slot="some-other-children">' + 'Some other children content' + '</span>' '</x-example>';
API Reference
/** * Attribute description. * * @typedef * @property * @property */ /** * Callback description. * * @typedef * @property */ /** * Public method description. * * @typedef * @property */ /** * Slot description. * * @typedef * @property */ /** * Regap component description. * * @typedef * @property * @property * @property * @property * @property * @property * @property * @property * @property * @property * @property * @property * @property */ /** * Register WebComponent based on React component. * * @param * @param * @param * @returns */; /** * Exported Regap HTMLElement. * * @type */regapHTMLElement; /** * Exported mixins collection. * * @type */regapmixins; /** * Exported predefined types collection. * * @type */regaptypes;
License
The MIT License (MIT)
Copyright (c) 2017 Alfa Laboratory
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.