Files
element-call/src/grid/SpotlightExpandedLayout.tsx
T

76 lines
2.0 KiB
TypeScript
Raw Normal View History

/*
Copyright 2024 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
2025-06-23 22:48:37 -04:00
import { type ReactNode, useCallback } from "react";
import { type SpotlightExpandedLayout as SpotlightExpandedLayoutModel } from "../state/layout-types.ts";
import { type CallLayout } from "./CallLayout";
import { type DragCallback, useUpdateLayout } from "./Grid";
import styles from "./SpotlightExpandedLayout.module.css";
import { useBehavior } from "../useBehavior";
2024-07-18 11:33:20 -04:00
/**
* An implementation of the "expanded spotlight" layout, in which the spotlight
* tile stretches edge-to-edge and is overlaid by a picture-in-picture tile.
*/
export const makeSpotlightExpandedLayout: CallLayout<
SpotlightExpandedLayoutModel
> = () => ({
foreground: "scrolling",
2025-06-23 22:48:37 -04:00
fixed: function SpotlightExpandedLayoutFixed({
ref,
2025-06-23 22:48:37 -04:00
model,
Slot,
}): ReactNode {
2024-07-25 12:50:28 -04:00
useUpdateLayout();
return (
2024-07-24 16:57:20 -04:00
<div ref={ref} className={styles.layer}>
<Slot
className={styles.spotlight}
id="spotlight"
2024-11-06 04:36:48 -05:00
model={model.spotlight}
/>
</div>
);
2025-06-23 22:48:37 -04:00
},
2025-06-23 22:48:37 -04:00
scrolling: function SpotlightExpandedLayoutScrolling({
ref,
2025-06-23 22:48:37 -04:00
model,
Slot,
}): ReactNode {
2024-07-25 12:50:28 -04:00
useUpdateLayout();
const pipAlignment = useBehavior(model.pipAlignment$);
const onDragPip: DragCallback = useCallback(
({ xRatio, yRatio }) =>
model.pipAlignment$.next({
block: yRatio < 0.5 ? "start" : "end",
inline: xRatio < 0.5 ? "start" : "end",
}),
[model.pipAlignment$],
);
return (
2024-07-24 16:57:20 -04:00
<div ref={ref} className={styles.layer}>
2024-11-06 04:36:48 -05:00
{model.pip && (
<Slot
className={styles.pip}
2024-11-06 04:36:48 -05:00
id={model.pip.id}
model={model.pip}
onDrag={onDragPip}
data-block-alignment={pipAlignment.block}
data-inline-alignment={pipAlignment.inline}
/>
)}
</div>
);
2025-06-23 22:48:37 -04:00
},
});