mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 01:52:19 +08:00
feature(react): add react directory to make the react-framework-delegate a first-class citizen and to make it easier to keep APIs in sync
This commit is contained in:
13
packages/react/README.md
Normal file
13
packages/react/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
## React
|
||||
|
||||
These are React specific building blocks on top of `@ionic/core` components/services.
|
||||
|
||||
## To Build
|
||||
|
||||
1. run `npm run build` to build a distro to `dist`
|
||||
|
||||
## Publishing
|
||||
|
||||
1. Run `npm run deploy`
|
||||
2. Commit and push any outstanding changes
|
3087
packages/react/package-lock.json
generated
Normal file
3087
packages/react/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
43
packages/react/package.json
Normal file
43
packages/react/package.json
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "@ionic/react",
|
||||
"version": "0.0.0",
|
||||
"description": "React specific wrapper for @ionic/core",
|
||||
"keywords": [
|
||||
"ionic",
|
||||
"framework",
|
||||
"mobile",
|
||||
"app",
|
||||
"hybrid",
|
||||
"webapp",
|
||||
"cordova",
|
||||
"progressive web app",
|
||||
"pwa"
|
||||
],
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ionic-team/ionic.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run clean && npm run compile",
|
||||
"clean": "rm -rf dist",
|
||||
"compile": "npm run tsc",
|
||||
"deploy": "np --any-branch",
|
||||
"tsc": "tsc -p ."
|
||||
},
|
||||
"main": "./dist/src/index.js",
|
||||
"module": "./dist/src/index.js",
|
||||
"types": "./dist/src/index.d.ts",
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@ionic/core": "next",
|
||||
"react": "^16.2.0",
|
||||
"react-dom": "^16.2.0",
|
||||
"typescript": "~2.5.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stencil/core": "0.0.8"
|
||||
}
|
||||
}
|
2
packages/react/src/declarations.d.ts
vendored
Normal file
2
packages/react/src/declarations.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
declare module 'react';
|
||||
declare module 'react-dom';
|
2
packages/react/src/index.ts
Normal file
2
packages/react/src/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export { Delegate } from './react-framework-delegate';
|
||||
export * from './utils/wc-shim';
|
39
packages/react/src/react-framework-delegate.ts
Normal file
39
packages/react/src/react-framework-delegate.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import { FrameworkDelegate } from '@ionic/core';
|
||||
|
||||
export function attachViewToDom(parentElement: HTMLElement, reactComponent: any, propsOrData: any, classesToAdd: string[]) {
|
||||
const wrappingDiv = document.createElement('div');
|
||||
if (classesToAdd) {
|
||||
for (const clazz of classesToAdd) {
|
||||
wrappingDiv.classList.add(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
parentElement.appendChild(wrappingDiv);
|
||||
|
||||
// mount the React component
|
||||
const reactElement = React.createElement(reactComponent, propsOrData);
|
||||
const mountedComponentInstance = ReactDOM.render(reactElement, wrappingDiv);
|
||||
|
||||
return Promise.resolve({
|
||||
element: wrappingDiv,
|
||||
reactElement: reactElement,
|
||||
instance: mountedComponentInstance
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export function removeViewFromDom(parentElement: HTMLElement, childElement: HTMLElement): Promise<any> {
|
||||
ReactDOM.unmountComponentAtNode(childElement);
|
||||
parentElement.removeChild(childElement);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const Delegate: FrameworkDelegate = {
|
||||
attachViewToDom: attachViewToDom,
|
||||
removeViewFromDom: removeViewFromDom,
|
||||
};
|
||||
|
||||
export { Delegate }
|
24
packages/react/src/utils/wc-shim.ts
Normal file
24
packages/react/src/utils/wc-shim.ts
Normal file
@ -0,0 +1,24 @@
|
||||
export function wc(events = {}, obj = {}) {
|
||||
let storedEl: HTMLElement;
|
||||
|
||||
return function (el: HTMLElement) {
|
||||
|
||||
(Object as any).entries(events).forEach((keyValues: string[]) => {
|
||||
const name = keyValues[0];
|
||||
const value = keyValues[1];
|
||||
const action = (el) ? el.addEventListener : storedEl.removeEventListener;
|
||||
if (typeof value === 'function') {
|
||||
action(name, value);
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (el) {
|
||||
(Object as any).entries(obj).forEach((keyValues: string[]) => {
|
||||
const name = keyValues[0];
|
||||
const value = keyValues[1];
|
||||
(el as any)[name] = value;
|
||||
});
|
||||
}
|
||||
storedEl = el;
|
||||
};
|
||||
}
|
25
packages/react/tsconfig.json
Normal file
25
packages/react/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowUnreachableCode": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"declaration": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"lib": ["dom", "es2015"],
|
||||
"module": "es2015",
|
||||
"moduleResolution": "node",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"outDir": "dist",
|
||||
"removeComments": false,
|
||||
"sourceMap": true,
|
||||
"target": "es2015"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"compileOnSave": false,
|
||||
"buildOnSave": false
|
||||
}
|
3
packages/react/tslint.json
Normal file
3
packages/react/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "tslint-ionic-rules"
|
||||
}
|
Reference in New Issue
Block a user