/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import React from "react"; import MarkdownRender from "./MarkdownRender"; import { Widget } from "../models"; import WidgetRender from "./WidgetRender"; import Tabs from "./Tabs"; import TabsVertical from "./TabsVertical"; import { useWindowSize } from "../hooks"; import { Waypoint } from "react-waypoint"; import ShareButton from "./ShareButton"; import Utils from "../services/UtilsService"; interface Props { widget: Widget; showMobilePreview?: boolean; widgets?: Array; setActiveWidgetId?: Function; topOffset?: string; bottomOffset?: string; defaultActive?: string; } function SectionWidget(props: Props) { const { content, showTitle } = props.widget; const windowSize = useWindowSize(); let activeTabId = "0"; if (props.widgets && props.defaultActive) { const widget = props.widgets?.find((w: Widget) => w.id === props.defaultActive); if (widget && widget.section) { const parent = props.widgets?.find((w: Widget) => w.id === widget.section); if (parent && parent.id === props.widget.id) { const index = parent.content.widgetIds.findIndex( (w: string) => w === props.defaultActive, ); if (index >= 0) { activeTabId = index.toString(); } } } } const chartId = `chart-${Utils.getShorterId(props.widget.id)}`; const sectionHeaderId = `section-header-${props.widget.id}`; return (
{!content.showWithTabs ? ( { if (props.setActiveWidgetId) { props.setActiveWidgetId(props.widget.id); } }} topOffset={props.topOffset} bottomOffset={props.bottomOffset} fireOnRapidScroll={false} >
{showTitle && (

{content.title}

)} {content.summary ? (
) : ( "" )}
) : ( <> {showTitle && (

{content.title}

)} {content.summary ? (
) : ( "" )} )} {!content.showWithTabs && content.widgetIds && content.widgetIds.map((id: string, index: number) => { const widget = props.widgets?.find((w) => w.id === id); if (widget) { return (
{ if (props.setActiveWidgetId) { props.setActiveWidgetId(widget.id); } }} topOffset={props.topOffset} bottomOffset={props.bottomOffset} fireOnRapidScroll={false} >

{widget.content.title}

); } return false; })} {content.showWithTabs && (content.horizontally || props.showMobilePreview || windowSize.width <= 600) && content.widgetIds?.length > 0 && ( {content.widgetIds.map((id: string, index: number) => { const widget = props.widgets?.find((w) => w.id === id); if (widget) { return (
); } return false; })}
)} {content.showWithTabs && !content.horizontally && !props.showMobilePreview && windowSize.width > 600 && content.widgetIds && ( {content.widgetIds.map((id: string, index: number) => { const widget = props.widgets?.find((w) => w.id === id); if (widget) { return (
); } return false; })}
)}
); } export default SectionWidget;