11import {
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' ;
1514import toStyle from 'css-to-style' ;
16-
15+ import { ReactContentProps } from '../renderer/react-content' ;
1716import { isReactNode } from '../renderer/react-node' ;
1817import { renderComponent , renderFunc , renderTemplate } from '../renderer/renderprop-helpers' ;
19- import { ExternalReactContentProps } from '../renderer/react-content' ;
2018import { 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)
3121const ignoredAttributeMatchers = [ / ^ _ ? n g - ? .* / , / ^ s t y l e $ / , / ^ c l a s s $ / ] ;
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.
5444export 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
0 commit comments