Skip to content

Commit

Permalink
tweak(triptych): Do not render slots outside the viewport when using …
Browse files Browse the repository at this point in the history
…the 3-slot split layout (#1855)
  • Loading branch information
jzimbel-mbta authored Sep 7, 2023
1 parent 2862d86 commit eaab154
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions assets/src/components/v2/triptych/triptych_three_pane.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import React from "react";

import Widget, { WidgetData } from "Components/v2/widget";
import { TriptychPane, getTriptychPane } from "Util/outfront";

interface Props {
left_pane: WidgetData;
middle_pane: WidgetData;
right_pane: WidgetData;
}

const isInViewport = (pane: TriptychPane | null, slotPosition: TriptychPane) =>
pane == null || pane == slotPosition;

const TriptychThreePane: React.ComponentType<Props> = ({
left_pane: leftPane,
middle_pane: middlePane,
right_pane: rightPane,
}) => {
const pane = getTriptychPane();

return (
<>
<div className="left-pane">
<Widget data={leftPane} />
{isInViewport(pane, "left") && <Widget data={leftPane} />}
</div>
<div className="middle-pane">
<Widget data={middlePane} />
{isInViewport(pane, "middle") && <Widget data={middlePane} />}
</div>
<div className="right-pane">
<Widget data={rightPane} />
{isInViewport(pane, "right") && <Widget data={rightPane} />}
</div>
</>
);
Expand Down

0 comments on commit eaab154

Please sign in to comment.