Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizable right panel #5073

Merged
merged 14 commits into from
Dec 22, 2023
163 changes: 0 additions & 163 deletions frontend/app/src/components/Panel.svelte

This file was deleted.

90 changes: 90 additions & 0 deletions frontend/app/src/components/Resizable.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<script lang="ts">
import { onMount } from "svelte";
import { rightPanelWidth } from "../stores/layout";
import { mobileWidth } from "../stores/screenDimensions";

const MIN_COL_WIDTH = 400;
const MAX_COL_WIDTH = 900;

export let section: HTMLElement;
export let modal: boolean;
export let resizedWidth: string;
export let resized: boolean;
export let resizing = false;

let previous = 0;

onMount(() => {
return rightPanelWidth.subscribe((width) => {
resized = width !== undefined;
resizedWidth = getWidthVar(width);
});
});

function startResize(ev: MouseEvent) {
previous = ev.screenX;
resizing = true;
document.body.style.cursor = "ew-resize";
}

function stopResize() {
resizing = false;
document.body.style.cursor = "";
}

function resetSize() {
rightPanelWidth.set(undefined);
}

function clampResize(size: number): number {
if (size > MAX_COL_WIDTH) return MAX_COL_WIDTH;
if (size < MIN_COL_WIDTH) return MIN_COL_WIDTH;
return size;
}

function drag(ev: MouseEvent) {
if (resizing) {
const diff = previous - ev.screenX;
const updated = clampResize(section.offsetWidth + diff);
rightPanelWidth.set(updated);
previous = ev.screenX;
}
}

function getWidthVar(rw: number | undefined): string {
if (modal) {
return rw ? `${rw}px` : "500px";
} else {
return rw ? `${rw}px` : "7";
}
}
</script>

<svelte:window on:mousemove={drag} on:mouseup={stopResize} />

{#if !$mobileWidth}
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<div
role="separator"
class:resizing
on:mousedown={startResize}
on:dblclick={resetSize}
class="handle">
</div>
{/if}

<style lang="scss">
.handle {
position: absolute;
left: 0;
height: 100%;
width: 5px;
cursor: ew-resize;
transition: background-color 300ms ease-in-out;

&.resizing,
&:hover {
background-color: var(--accent);
}
}
</style>
18 changes: 15 additions & 3 deletions frontend/app/src/components/SelectChatModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import Avatar from "./Avatar.svelte";
import CollapsibleCard from "./CollapsibleCard.svelte";
import { AvatarSize, chatIdentifiersEqual } from "openchat-client";
import Panel from "./Panel.svelte";
import { iconSize } from "../stores/iconSize";
import HoverIcon from "./HoverIcon.svelte";
import AccountMultiple from "svelte-material-icons/AccountMultiple.svelte";
Expand Down Expand Up @@ -250,7 +249,7 @@
}
</script>

<Panel right forceModal>
<section>
<SectionHeader border={false} gap>
<HoverIcon>
<AccountMultiple size={$iconSize} color={"var(--icon-txt)"} />
Expand Down Expand Up @@ -419,7 +418,7 @@
{/each}
</div>
{/if}
</Panel>
</section>

<style lang="scss">
:global(.selectable-chats .body) {
Expand All @@ -436,6 +435,19 @@
margin-top: 2px;
}

section {
background: var(--panel-right-modal);
height: calc(var(--vh, 1vh) * 100);
position: relative;
width: 500px;
overflow: auto;
overflow-x: hidden;

@include mobile() {
width: 100%;
}
}

.no-chats {
margin: $sp3;
padding: $sp3 $sp4;
Expand Down
Loading
Loading