import React from "react"; import {AbstractCoreComponent, CoreComponentModel, CoreComponentState} from "../../../AbstractCoreComponent"; import {ImageV2} from "../../../authoring/image/v2/ImageV2"; import {TitleV2} from "../../../authoring/title/v2/TitleV2"; import {RoutedLink} from "../../../routing/RoutedLink"; import {RoutedCoreComponentModel, isItemRouted, RoutedModel} from "../../../routing/RoutedCoreComponent"; export function TeaserV1IsEmptyFn(props:TeaserV1Model): boolean{ return (!props.imagePath && !props.description && props.actions.length == 0) } export interface TeaserV1Action extends RoutedModel{ title: string URL: string } export interface TeaserV1Model extends RoutedCoreComponentModel{ pretitle?: string title?: string description?: string titleType: string linkURL: string actionsEnabled: boolean imageLinkHidden: boolean titleLinkHidden: boolean actions: TeaserV1Action[] imagePath: string } export class TeaserV1 extends AbstractCoreComponent{ public static defaultProps = { hidePlaceHolder: false, isInEditor: false }; constructor(props: Model) { super(props, 'cmp-teaser', 'TeaserV1'); } isEmpty(): boolean { return TeaserV1IsEmptyFn(this.props); } get image(){ return this.props.imagePath && (
); } get pretitle(){ return this.props.pretitle &&
{this.props.pretitle}
} get title(){ return this.props.title && ( ) } get description(){ const text:string = this.props.description as string; return this.props.description && (
) } generateLink(action:TeaserV1Action, index:number){ return ( ${action.title} ) } get actions(){ const hasActions:boolean = this.props.actions.length > 0; return this.props.actionsEnabled && hasActions && (
{ this.props.actions.map((action, index) => { this.generateLink(action,index) }) }
) } renderComponent(): JSX.Element { const cssClass = this.baseCssCls + (this.props.isInEditor) ? ' cq-dd-image' : ''; return (
{this.image}
{this.pretitle} {this.title} {this.description} {this.actions}
) } }