-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: draggable windows tab * feat: improve drag and drop animation * fix: drag overlay style when active * fix: tab not clickable , dragged tab not active * refactor: remove unused keyboard sensor * refactor * feat: add icon to the tab --------- Co-authored-by: Visal .In <[email protected]>
- Loading branch information
1 parent
72ec87f
commit d8b3679
Showing
7 changed files
with
264 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.tab .close { | ||
visibility: hidden; | ||
} | ||
|
||
.tab:hover .close { | ||
visibility: visible; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { LucideIcon, LucideX } from "lucide-react"; | ||
import { useSortable } from "@dnd-kit/sortable"; | ||
import styles from "./sortable-tab.module.css"; | ||
import { WindowTabItemProps } from "./windows-tab"; | ||
import { cn } from "@/lib/utils"; | ||
import { forwardRef } from "react"; | ||
import { ButtonProps } from "./ui/button"; | ||
|
||
interface SortableTabProps { | ||
tab: WindowTabItemProps; | ||
selected: boolean; | ||
onSelectChange: () => void; | ||
onClose: () => void; | ||
} | ||
|
||
type WindowTabItemButtonProps = ButtonProps & { | ||
selected?: boolean; | ||
title: string; | ||
icon: LucideIcon; | ||
onClose?: () => void; | ||
}; | ||
|
||
export const WindowTabItemButton = forwardRef< | ||
HTMLButtonElement, | ||
WindowTabItemButtonProps | ||
>(function WindowTabItemButton(props: WindowTabItemButtonProps, ref) { | ||
const { icon: Icon, selected, title, onClose, ...rest } = props; | ||
|
||
const className = cn( | ||
"h-9 flex items-center text-left text-xs font-semibold px-2 w-max-[150px]", | ||
styles.tab, | ||
selected | ||
? "border-x border-t bg-background border-b-background rounded-t" | ||
: "border-b border-t border-t-secondary border-x-secondary opacity-65 hover:opacity-100" | ||
); | ||
|
||
return ( | ||
<button className={className} ref={ref} {...rest}> | ||
<Icon className="w-4 h-4 ml-2 grow-0 shrink-0" /> | ||
<div className="line-clamp-1 grow px-2">{title}</div> | ||
<div | ||
className={cn( | ||
"rounded-full hover:bg-red-600 hover:text-white w-4 h-4 ml-2 flex justify-center items-center", | ||
styles.close | ||
)} | ||
> | ||
<LucideX | ||
className={cn("w-3 h-3 grow-0 shrink-0", styles.close)} | ||
onClick={onClose} | ||
/> | ||
</div> | ||
</button> | ||
); | ||
}); | ||
|
||
export function SortableTab({ | ||
tab, | ||
selected, | ||
onSelectChange, | ||
onClose, | ||
}: SortableTabProps) { | ||
const { attributes, listeners, setNodeRef } = useSortable({ id: tab.key }); | ||
|
||
return ( | ||
<WindowTabItemButton | ||
ref={setNodeRef} | ||
icon={tab.icon} | ||
title={tab.title} | ||
onClick={onSelectChange} | ||
selected={selected} | ||
onClose={onClose} | ||
{...attributes} | ||
{...listeners} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.