Skip to content

Commit d816b5d

Browse files
author
Ben Grynhaus
committed
merge from master
1 parent b2c2f96 commit d816b5d

38 files changed

+296
-281
lines changed

apps/docs/src/app/containers/component-docs/fabric/fabric.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h2>Dialog</h2>
1313
<fab-dialog [hidden]="dialogHidden" (onDismiss)="toggleDialog()" title="Fabric [React] Dialog" subText="Use Fabric React components inside your Angular app!">
1414
{{ sampleContent2 }} {{ sampleContent3 }}
1515
<fab-dialog-footer>
16-
<fab-default-button (onClick)="clickSave()" text='Save' style="margin-right:10px;"></fab-default-button>
16+
<fab-default-button (onClick)="clickSave()" text='Save' contentStyle="margin-right: 10px;"></fab-default-button>
1717
<fab-default-button (onClick)="toggleDialog()" text='Cancel'></fab-default-button>
1818
</fab-dialog-footer>
1919
</fab-dialog>

libs/core/package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"$schema": "../../node_modules/ng-packagr/package.schema.json",
33
"name": "@angular-react/core",
4-
"version": "0.3.0-alpha1",
4+
"version": "0.3.0-alpha3",
55
"ngPackage": {
6+
"deleteDestPath": true,
7+
"whitelistedNonPeerDependencies": [
8+
"tslib",
9+
"css-to-style"
10+
],
611
"lib": {
712
"languageLevel": [
813
"dom",
914
"es2017"
1015
],
11-
"embedded": [
12-
"css-to-style"
13-
],
1416
"entryFile": "public-api.ts",
1517
"umdModuleIds": {
1618
"react": "React",
@@ -52,5 +54,11 @@
5254
"@angular/platform-browser": "^6.1.0",
5355
"react-dom": "^16.4.1",
5456
"react": "^16.4.1"
55-
}
57+
},
58+
"dependencies": {
59+
"css-to-style": "^1.2.0"
60+
},
61+
"bundledDependencies": [
62+
"css-to-style"
63+
]
5664
}

libs/core/src/lib/components/wrapper-component.ts

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
import {
22
AfterViewInit,
3+
ChangeDetectorRef,
34
ComponentFactoryResolver,
45
ComponentRef,
56
ElementRef,
67
Injector,
7-
TemplateRef,
8-
Type,
9-
ChangeDetectorRef,
8+
Input,
109
OnChanges,
1110
SimpleChanges,
12-
HostBinding,
13-
Input,
11+
TemplateRef,
12+
Type,
1413
} from '@angular/core';
1514
import toStyle from 'css-to-style';
16-
15+
import { ReactContentProps } from '../renderer/react-content';
1716
import { isReactNode } from '../renderer/react-node';
1817
import { renderComponent, renderFunc, renderTemplate } from '../renderer/renderprop-helpers';
19-
import { ExternalReactContentProps } from '../renderer/react-content';
2018
import { unreachable } from '../utils/types/unreachable';
2119

22-
type AttributeNameAlternative = [string, string | undefined];
23-
24-
const forbiddenAttributesAsProps: ReadonlyArray<AttributeNameAlternative> = [
25-
['key', null],
26-
['class', 'rClass'],
27-
['style', 'rStyle'],
28-
];
29-
3020
// Forbidden attributes are still ignored, since they may be set from the wrapper components themselves (forbidden is only applied for users of the wrapper components)
3121
const ignoredAttributeMatchers = [/^_?ng-?.*/, /^style$/, /^class$/];
3222

@@ -52,47 +42,47 @@ export type JsxRenderFunc<TContext> = (context: TContext) => JSX.Element;
5242
*/
5343
// NOTE: TProps is not used at the moment, but a preparation for a potential future change.
5444
export abstract class ReactWrapperComponent<TProps extends {}> implements AfterViewInit, OnChanges {
55-
private _rClass: string;
56-
private _rStyle: string;
45+
private _contentClass: string;
46+
private _contentStyle: string;
5747

58-
protected abstract reactNodeRef: ElementRef;
48+
protected abstract reactNodeRef: ElementRef<HTMLElement>;
5949

6050
/**
6151
* Alternative to `class` using the same syntax.
6252
*
6353
* @description Since this is a wrapper component, sticking to the virtual DOM concept, this should have any styling of its own.
64-
* Any value passes to `rClass` will be passed to the root component's class.
54+
* Any value passes to `contentClass` will be passed to the root component's class.
6555
*/
6656
@Input()
67-
set rClass(value: string) {
68-
this._rClass = value;
57+
set contentClass(value: string) {
58+
this._contentClass = value;
6959
if (isReactNode(this.reactNodeRef.nativeElement)) {
7060
this.reactNodeRef.nativeElement.setProperty('className', value);
7161
this.changeDetectorRef.detectChanges();
7262
}
7363
}
7464

75-
get rClass(): string {
76-
return this._rClass;
65+
get contentClass(): string {
66+
return this._contentClass;
7767
}
7868

7969
/**
8070
* Alternative to `style` using the same syntax.
8171
*
8272
* @description Since this is a wrapper component, sticking to the virtual DOM concept, this should have any styling of its own.
83-
* Any value passes to `rStyle` will be passed to the root component's style.
73+
* Any value passes to `contentStyle` will be passed to the root component's style.
8474
*/
8575
@Input()
86-
set rStyle(value: string) {
87-
this._rStyle = value;
76+
set contentStyle(value: string) {
77+
this._contentStyle = value;
8878
if (isReactNode(this.reactNodeRef.nativeElement)) {
8979
this.reactNodeRef.nativeElement.setProperty('style', toStyle(value));
9080
this.changeDetectorRef.detectChanges();
9181
}
9282
}
9383

94-
get rStyle(): string {
95-
return this._rStyle;
84+
get contentStyle(): string {
85+
return this._contentStyle;
9686
}
9787

9888
/**
@@ -138,7 +128,7 @@ export abstract class ReactWrapperComponent<TProps extends {}> implements AfterV
138128
*/
139129
protected createInputJsxRenderer<TContext extends object>(
140130
input: InputRendererOptions<TContext>,
141-
additionalProps?: ExternalReactContentProps
131+
additionalProps?: ReactContentProps
142132
): JsxRenderFunc<TContext> | undefined {
143133
if (input === undefined) {
144134
return undefined;
@@ -176,7 +166,7 @@ export abstract class ReactWrapperComponent<TProps extends {}> implements AfterV
176166
protected createRenderPropHandler<TProps extends object>(
177167
renderInputValue: InputRendererOptions<TProps>,
178168
jsxRenderer?: JsxRenderFunc<TProps>,
179-
additionalProps?: ExternalReactContentProps
169+
additionalProps?: ReactContentProps
180170
): (props?: TProps, defaultRender?: JsxRenderFunc<TProps>) => JSX.Element | null {
181171
const renderer = jsxRenderer || this.createInputJsxRenderer(renderInputValue, additionalProps);
182172

@@ -241,12 +231,13 @@ export abstract class ReactWrapperComponent<TProps extends {}> implements AfterV
241231
const { name, value } = attr;
242232

243233
if (name === 'key') return [true, undefined];
244-
if (name === 'class' && value.split(' ').some(className => !ngClassRegExp.test(className))) return [true, 'rClass'];
234+
if (name === 'class' && value.split(' ').some(className => !ngClassRegExp.test(className)))
235+
return [true, 'contentClass'];
245236
if (name === 'style') {
246237
const style = toStyle(value);
247238
// Only allowing style if it's something that changes the display - setting anything else should be done on the child component directly (via the `styles` attribute in fabric for example)
248239
if (Object.entries(style).filter(([key, value]) => value && key !== 'display').length > 0) {
249-
return [true, 'rStyle'];
240+
return [true, 'contentStyle'];
250241
}
251242
}
252243

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type StringMap<T = any> = { [index: string]: T };
File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './omit';
2+
export * from './StringMap';

libs/core/src/lib/renderer/components/Disguise.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
3-
43
import { ReactWrapperComponent } from '../../components/wrapper-component';
5-
import { passPropsSymbol, getPassProps, PassProp } from '../../renderer/pass-prop-decorator';
6-
import { ReactContent } from '../react-content';
4+
import { getPassProps } from '../../renderer/pass-prop-decorator';
75
import removeUndefinedProperties from '../../utils/object/remove-undefined-properties';
6+
import { ReactContent } from '../react-content';
87

98
/**
109
* Props for `Disguise` component.

libs/core/src/lib/renderer/react-content.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
3+
import { Omit } from '../declarations/omit';
34

45
const DEBUG = false;
5-
export const CHILDREN_TO_APPEND_PROP = Symbol('children-to-append');
6+
export const CHILDREN_TO_APPEND_PROP = 'children-to-append';
67

78
/**
89
* Props that can be passed to `ReactContent` from users.
910
*/
10-
export interface ExternalReactContentProps {
11+
export type ReactContentProps = Omit<AllReactContentProps, typeof CHILDREN_TO_APPEND_PROP>;
12+
13+
/**
14+
* @internal
15+
*/
16+
export interface AllReactContentProps {
17+
readonly [CHILDREN_TO_APPEND_PROP]: HTMLElement[];
18+
1119
/**
1220
* Experimental rendering mode.
1321
* Uses a similar approach to `router-outlet`, where the child elements are added to the parent, instead of this node, and this is hidden.
@@ -16,20 +24,14 @@ export interface ExternalReactContentProps {
1624
legacyRenderMode?: boolean;
1725
}
1826

19-
// NOTE: Separated into `ExternalReactContentProps` since We only want a subset of props to be exposed to external users.
20-
// With Omit type (TS 2.8) we can simply have `type ExternalReactContentProps = Omit<ReactContentProps, 'children-to-append'>`
21-
export interface ReactContentProps extends ExternalReactContentProps {
22-
readonly [CHILDREN_TO_APPEND_PROP]: HTMLElement[];
23-
}
24-
2527
/**
2628
* Render any `HTMLElement`s (including Angular components) as a child of React components.
2729
* Supports two rendering modes:
2830
* 1. `legacy` - append `<react-content>` as the root, and nest the `children-to-append` underneath it.
2931
* 2. `new` (**default**) - append the `children-to-append` to the parent of this component, and hide the `<react-content>` element.
3032
* (similar to how `router-outlet` behaves in Angular).
3133
*/
32-
export class ReactContent extends React.PureComponent<ReactContentProps> {
34+
export class ReactContent extends React.PureComponent<AllReactContentProps> {
3335
componentDidMount() {
3436
const element = ReactDOM.findDOMNode(this);
3537
if (this.props[CHILDREN_TO_APPEND_PROP]) {

libs/core/src/lib/renderer/react-node.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
/// <reference path="../types/StringMap.d.ts" />
2-
31
import * as React from 'react';
42
import * as ReactDOM from 'react-dom';
5-
3+
import { StringMap } from '../declarations/StringMap';
64
import removeUndefinedProperties from '../utils/object/remove-undefined-properties';
75
import { CHILDREN_TO_APPEND_PROP } from './react-content';
86
import { getComponentClass } from './registry';
@@ -202,13 +200,10 @@ export class ReactNode {
202200
return React.createElement(this.type, clearedProps, children.length > 0 ? children : undefined);
203201
}
204202

205-
private transformProps(props: object) {
203+
private transformProps<TProps extends object>(props: TProps) {
206204
return Object.entries(props).reduce((acc, [key, value]) => {
207-
const [transformKey, transformValue] = this.transformProp(key, value);
208-
return {
209-
...acc,
210-
[transformKey]: transformValue,
211-
};
205+
const [newKey, newValue] = typeof key !== 'string' ? [key, value] : this.transformProp(key, value);
206+
return Object.assign(acc, { [newKey]: newValue });
212207
}, {});
213208
}
214209

libs/core/src/lib/renderer/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable, Renderer2, RendererStyleFlags2, RendererType2 } from '@angular/core';
22
import { EventManager, ɵDomRendererFactory2, ɵDomSharedStylesHost } from '@angular/platform-browser';
33
import * as ReactDOM from 'react-dom';
4-
4+
import { StringMap } from '../declarations/StringMap';
55
import { isReactNode, ReactNode } from './react-node';
66

77
const DEBUG = false;

0 commit comments

Comments
 (0)