From 87e73695f6a24d14e109df8a150b21d8ed356408 Mon Sep 17 00:00:00 2001 From: "Somayeh.Ghanavati" Date: Sat, 11 Jul 2026 19:12:32 +0330 Subject: [PATCH] fea(panel) :add hotkey for add word in panel (ctrl+b) --- src/App.tsx | 95 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 32 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 580e8c8..a5f713e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,47 +1,78 @@ +import { useState, useEffect } from "react"; import { MantineProvider, Tabs } from "@mantine/core"; -import { useHotkeys } from "react-hotkeys-hook"; -import { useState } from "react"; +import { + HotkeysProvider, + useHotkeys, + useHotkeysContext, +} from "react-hotkeys-hook"; import "@mantine/core/styles.css"; -function App() { - const [activeTab, setActiveTab] = useState("1"); +function TabContent({ title, scopeName }: any) { + const [text, setText] = useState(`${title} panel `); + const [used, setUsed] = useState(false); useHotkeys( - "ctrl+1, ctrl+2, ctrl+3", - (event, handler) => { - const key = handler.keys?.[0]; - if (key) { - setActiveTab(key); - } + "ctrl+b", + () => { + if (used) return; + setText((prev) => prev + `${title} `); + setUsed(true); + }, + { + scopes: [scopeName], + preventDefault: true, }, - { preventDefault: true, enableOnFormTags: true }, ); + return <>{text}; +} + +function TabsPage() { + const { enableScope, disableScope } = useHotkeysContext(); + const [activeTab, setActiveTab] = useState("1"); + + useEffect(() => { + const currentScope = `tab${activeTab}`; + enableScope(currentScope); + + return () => { + disableScope(currentScope); + }; + }, [activeTab, enableScope, disableScope]); + + useHotkeys("ctrl+1", () => setActiveTab("1"), { preventDefault: true }); + useHotkeys("ctrl+2", () => setActiveTab("2"), { preventDefault: true }); + useHotkeys("ctrl+3", () => setActiveTab("3"), { preventDefault: true }); + return ( - - - - First tab - - Second tab - - Third tab - + value && setActiveTab(value)}> + + First + Second + Third + - - First panel - + + + - - Second panel - + + + - - Third panel - - - + + + + ); } -export default App; +export default function App() { + return ( + + + + + + ); +}