Skip to content

Commit 00be998

Browse files
author
Zoran Liu
committed
5.0.0-alpha
1 parent 5ff9836 commit 00be998

59 files changed

Lines changed: 169 additions & 58 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/docs/src/app/react-components/react-dot/react-dot.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {
1414
} from '@angular/core';
1515
import * as React from 'react';
1616
import { ReactWrapperComponent } from '@angular-react/core';
17+
import { AngularReact } from '@angular-react/core';
1718

19+
@AngularReact()
1820
@Component({
1921
selector: 'app-react-dot',
2022
template: `
@@ -38,7 +40,6 @@ import { ReactWrapperComponent } from '@angular-react/core';
3840
</ReactDot>
3941
`,
4042
changeDetection: ChangeDetectionStrategy.OnPush,
41-
styles: ['react-renderer { display: none; }'],
4243
})
4344
export class ReactDotComponent extends ReactWrapperComponent<ReactDotProps> {
4445
@ViewChild('reactNode', { static: true }) protected reactNodeRef: ElementRef;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type AngularReactMetadata = unknown;

libs/core/src/lib/declarations/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './known-keys';
55
export * from './many';
66
export * from './omit';
77
export * from './string-map';
8+
export * from './interfaces';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Type, ɵNG_COMP_DEF, ɵComponentDef } from '@angular/core'
2+
import { AngularReactMetadata } from '../declarations/interfaces';
3+
import { setAngularReactMetadata } from '../utils/angular-react/metadata';
4+
5+
export function AngularReact(metadata?: AngularReactMetadata) {
6+
return <T>(componentType: Type<T>) => {
7+
Promise.resolve().then(() => {
8+
const componentDef: ɵComponentDef<T> = componentType[ɵNG_COMP_DEF];
9+
10+
if (componentDef === undefined) {
11+
throw new Error('Ivy is not enabled.');
12+
}
13+
14+
setAngularReactMetadata(componentDef, metadata ?? {});
15+
});
16+
17+
return componentType as any;
18+
}
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { AngularReact } from './angular-react';

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ReactContent } from './react-content';
99
import { isReactNode, ReactNode } from './react-node';
1010
import { registerElement } from './registry';
1111
import './geteventlisteners';
12+
import { isAngularReactComponent } from '../utils/angular-react/metadata';
1213

1314
const DEBUG = false;
1415

@@ -41,7 +42,7 @@ export class AngularReactRendererFactory extends ɵDomRendererFactory2 {
4142
}
4243

4344
createRenderer(element: any, type: RendererType2 | null): Renderer2 {
44-
if (typeof type.styles?.[0] === 'string' && type.styles[0].startsWith('react-renderer')) {
45+
if (type.styles?.[0] === 'react-renderer' || isAngularReactComponent(type)) {
4546
return this.defaultReactRenderer;
4647
}
4748

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { AngularReactMetadata } from '../../declarations/interfaces';
2+
import { RendererType2 } from '@angular/core';
3+
4+
const KEY = 'angularReact';
5+
6+
export const setAngularReactMetadata = (
7+
componentDef: {
8+
data: {
9+
[kind: string]: any;
10+
};
11+
},
12+
metadata: AngularReactMetadata
13+
): void => {
14+
if (componentDef.data) {
15+
componentDef.data[KEY] = metadata;
16+
} else {
17+
componentDef.data = {
18+
[KEY]: metadata
19+
}
20+
}
21+
};
22+
23+
export const getAngularReactMetadata = (
24+
type: {
25+
data: {
26+
[kind: string]: any;
27+
};
28+
}
29+
): AngularReactMetadata => {
30+
return type?.data?.[KEY] as AngularReactMetadata;
31+
};
32+
33+
export const isAngularReactComponent = (type: RendererType2 | null): boolean => {
34+
return type?.data?.[KEY] != null;
35+
};

libs/core/src/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export {
1515
InputRendererOptions,
1616
RenderPropOptions,
1717
} from './lib/components/render-props';
18+
export * from './lib/decorators/index';

libs/fabric/lib/components/breadcrumb/breadcrumb.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {
1414
} from '@angular/core';
1515
import { IBreadcrumbItem, IBreadcrumbProps } from '@fluentui/react/lib/Breadcrumb';
1616
import { Styled } from '@angular-react/fabric/lib/utils';
17+
import { AngularReact } from '@angular-react/core';
1718

19+
@AngularReact()
1820
@Styled('FabBreadcrumbComponent')
1921
@Component({
2022
selector: 'fab-breadcrumb',
@@ -40,7 +42,6 @@ import { Styled } from '@angular-react/fabric/lib/utils';
4042
>
4143
</Breadcrumb>
4244
`,
43-
styles: ['react-renderer { display: none; }'],
4445
changeDetection: ChangeDetectionStrategy.OnPush,
4546
})
4647
export class FabBreadcrumbComponent extends ReactWrapperComponent<IBreadcrumbProps> implements OnInit {

libs/fabric/lib/components/button/action-button.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
} from '@angular/core';
1313
import { FabBaseButtonComponent } from './base-button.component';
1414
import { Styled } from '@angular-react/fabric/lib/utils';
15+
import { AngularReact } from '@angular-react/core';
1516

17+
@AngularReact()
1618
@Styled('FabActionButtonComponent')
1719
@Component({
1820
selector: 'fab-action-button',
@@ -65,7 +67,6 @@ import { Styled } from '@angular-react/fabric/lib/utils';
6567
<ReactContent><ng-content></ng-content></ReactContent>
6668
</ActionButton>
6769
`,
68-
styles: ['react-renderer { display: none; }'],
6970
changeDetection: ChangeDetectionStrategy.OnPush,
7071
})
7172
export class FabActionButtonComponent extends FabBaseButtonComponent {

0 commit comments

Comments
 (0)