@@ -15,7 +15,9 @@ import {
1515 TemplateRef ,
1616 Type ,
1717} from '@angular/core' ;
18+ import classnames from 'classnames' ;
1819import toStyle from 'css-to-style' ;
20+ import { Many } from '../declarations/many' ;
1921import { ReactContentProps } from '../renderer/react-content' ;
2022import { isReactNode } from '../renderer/react-node' ;
2123import { isReactRendererData } from '../renderer/renderer' ;
@@ -42,33 +44,34 @@ export type InputRendererOptions<TContext extends object> =
4244
4345export type JsxRenderFunc < TContext > = ( context : TContext ) => JSX . Element ;
4446
47+ export type ContentClassValue = string [ ] | Set < string > | { [ klass : string ] : any } ;
4548/**
4649 * Base class for Angular @Components wrapping React Components.
4750 * Simplifies some of the handling around passing down props and setting CSS on the host component.
4851 */
4952// NOTE: TProps is not used at the moment, but a preparation for a potential future change.
5053export abstract class ReactWrapperComponent < TProps extends { } > implements AfterViewInit , OnChanges {
51- private _contentClass : string ;
52- private _contentStyle : string ;
54+ private _contentClass : Many < ContentClassValue > ;
55+ private _contentStyle : ContentStyleValue ;
5356
5457 protected abstract reactNodeRef : ElementRef < HTMLElement > ;
5558
5659 /**
57- * Alternative to `class` using the same syntax.
60+ * Alternative to `class` and `[ngClass]` using the same syntax.
5861 *
59- * @description Since this is a wrapper component, sticking to the virtual DOM concept, this should have any styling of its own.
60- * Any value passes to `contentClass` will be passed to the root component's class.
62+ * @description Since this is a wrapper component, sticking to the virtual DOM concept, its DOM element shouldn't have any styling of its own.
63+ * Instead, any value passes to `contentClass` will be passed to the root component's class as `className` .
6164 */
6265 @Input ( )
63- set contentClass ( value : string ) {
66+ set contentClass ( value : Many < ContentClassValue > ) {
6467 this . _contentClass = value ;
6568 if ( isReactNode ( this . reactNodeRef . nativeElement ) ) {
66- this . reactNodeRef . nativeElement . setProperty ( 'className' , value ) ;
69+ this . reactNodeRef . nativeElement . setProperty ( 'className' , classnames ( value ) ) ;
6770 this . changeDetectorRef . detectChanges ( ) ;
6871 }
6972 }
7073
71- get contentClass ( ) : string {
74+ get contentClass ( ) : Many < ContentClassValue > {
7275 return this . _contentClass ;
7376 }
7477
0 commit comments