From ebcb357ba82da436f840b9ba92e717731250af45 Mon Sep 17 00:00:00 2001 From: Red Adaya Date: Wed, 18 Dec 2024 23:31:29 +0800 Subject: [PATCH] init --- frontend/app/element/tabs.scss | 40 +++++++++++++++++++ frontend/app/element/tabs.stories.tsx | 0 frontend/app/element/tabs.tsx | 55 +++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 frontend/app/element/tabs.scss create mode 100644 frontend/app/element/tabs.stories.tsx create mode 100644 frontend/app/element/tabs.tsx diff --git a/frontend/app/element/tabs.scss b/frontend/app/element/tabs.scss new file mode 100644 index 000000000..511ef6803 --- /dev/null +++ b/frontend/app/element/tabs.scss @@ -0,0 +1,40 @@ +// Copyright 2024, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +.tabs-container { + display: flex; + flex-direction: column; + font-family: Arial, sans-serif; + + .tabs-list { + display: flex; + gap: 12px; + border: 1px solid #444; + border-radius: 6px; + padding: 4px; + background-color: #111; + + .tab-item { + padding: 6px 12px; + cursor: pointer; + border-radius: 4px; + color: #aaa; + transition: all 0.2s ease-in-out; + + &:hover { + background-color: #222; + } + + &.active { + border: 1px solid #28a745; + background-color: #0a0a0a; + color: #fff; + font-weight: bold; + } + + &:focus { + outline: 2px solid #28a745; + } + } + } +} \ No newline at end of file diff --git a/frontend/app/element/tabs.stories.tsx b/frontend/app/element/tabs.stories.tsx new file mode 100644 index 000000000..e69de29bb diff --git a/frontend/app/element/tabs.tsx b/frontend/app/element/tabs.tsx new file mode 100644 index 000000000..607b88a3d --- /dev/null +++ b/frontend/app/element/tabs.tsx @@ -0,0 +1,55 @@ +// Copyright 2024, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import React, { useState } from "react"; +import "./tabs.scss"; + +type Tab = { + label: string; + onClick: () => void; +}; + +type TabsProps = { + tabs: Tab[]; +}; + +const Tabs: React.FC = ({ tabs }) => { + const [activeIndex, setActiveIndex] = useState(0); + + const handleKeyDown = (event: React.KeyboardEvent, index: number) => { + if (event.key === "ArrowRight") { + setActiveIndex((prevIndex) => (prevIndex + 1) % tabs.length); + } else if (event.key === "ArrowLeft") { + setActiveIndex((prevIndex) => (prevIndex - 1 + tabs.length) % tabs.length); + } else if (event.key === "Enter" || event.key === " ") { + event.preventDefault(); + tabs[index].onClick(); + setActiveIndex(index); + } + }; + + return ( +
+
+ {tabs.map((tab, index) => ( +
{ + tab.onClick(); + setActiveIndex(index); + }} + onKeyDown={(e) => handleKeyDown(e, index)} + > + {tab.label} +
+ ))} +
+
+ ); +}; + +export { Tabs };