waveterm/frontend/app/tab/tab.tsx

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-06-18 06:50:33 +02:00
// Copyright 2024, Command Line Inc.
2024-05-14 00:10:31 +02:00
// SPDX-License-Identifier: Apache-2.0
2024-06-18 06:50:33 +02:00
import { Button } from "@/element/button";
import * as WOS from "@/store/wos";
2024-06-18 06:50:33 +02:00
import { clsx } from "clsx";
import React from "react";
2024-05-14 00:10:31 +02:00
2024-05-28 21:12:28 +02:00
import "./tab.less";
2024-05-14 00:10:31 +02:00
2024-06-18 06:50:33 +02:00
interface TabProps {
id: string;
active: boolean;
isBeforeActive: boolean;
isDragging: boolean;
onSelect: () => void;
onClose: () => void;
onDragStart: () => void;
}
const Tab = React.forwardRef<HTMLDivElement, TabProps>(
({ id, active, isBeforeActive, isDragging, onSelect, onClose, onDragStart }, ref) => {
const [tabData, tabLoading] = WOS.useWaveObjectValue<Tab>(WOS.makeORef("tab", id));
const name = tabData?.name ?? "...";
2024-05-28 01:33:31 +02:00
return (
2024-06-18 06:50:33 +02:00
<div
ref={ref}
className={clsx("tab", { active, isDragging, "before-active": isBeforeActive })}
onMouseDown={onDragStart}
onClick={onSelect}
data-tab-id={id}
>
<div className="name">{name}</div>
{!isDragging && <div className="vertical-line" />}
{active && <div className="mask" />}
<Button className="secondary ghost close" onClick={onClose}>
<i className="fa fa-solid fa-xmark" />
</Button>
2024-05-28 01:33:31 +02:00
</div>
);
}
2024-06-18 06:50:33 +02:00
);
2024-06-18 06:50:33 +02:00
export { Tab };