mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Add a simple tooltip to the sidebar (#6295)
## Summary Not perfect, but IMO helpful: <img width="1792" alt="Screen Shot 2023-08-02 at 9 29 24 PM" src="e613e918
-75cb-475e-9ea4-f833d1a0b5f6"> <img width="1792" alt="Screen Shot 2023-08-02 at 9 29 20 PM" src="bb3efdfe
-40e1-45b5-b774-082521b2d214">
This commit is contained in:
parent
d7627c398c
commit
9e2bbf4beb
4 changed files with 31 additions and 5 deletions
|
@ -16,6 +16,7 @@ export default function PrimarySideBar({
|
|||
<SideBar position="left">
|
||||
<SideBarEntry
|
||||
title="Source"
|
||||
position={"left"}
|
||||
onClick={() => onSelectTool("Source")}
|
||||
selected={selected == "Source"}
|
||||
>
|
||||
|
@ -24,6 +25,7 @@ export default function PrimarySideBar({
|
|||
|
||||
<SideBarEntry
|
||||
title="Settings"
|
||||
position={"left"}
|
||||
onClick={() => onSelectTool("Settings")}
|
||||
selected={selected == "Settings"}
|
||||
>
|
||||
|
|
|
@ -20,6 +20,7 @@ export default function SecondarySideBar({
|
|||
<SideBar position="right">
|
||||
<SideBarEntry
|
||||
title="Format (alpha)"
|
||||
position={"right"}
|
||||
selected={selected === SecondaryTool.Format}
|
||||
onClick={() => onSelected(SecondaryTool.Format)}
|
||||
>
|
||||
|
@ -28,6 +29,7 @@ export default function SecondarySideBar({
|
|||
|
||||
<SideBarEntry
|
||||
title="AST"
|
||||
position={"right"}
|
||||
selected={selected === SecondaryTool.AST}
|
||||
onClick={() => onSelected(SecondaryTool.AST)}
|
||||
>
|
||||
|
@ -36,6 +38,7 @@ export default function SecondarySideBar({
|
|||
|
||||
<SideBarEntry
|
||||
title="Tokens"
|
||||
position={"right"}
|
||||
selected={selected === SecondaryTool.Tokens}
|
||||
onClick={() => onSelected(SecondaryTool.Tokens)}
|
||||
>
|
||||
|
@ -44,6 +47,7 @@ export default function SecondarySideBar({
|
|||
|
||||
<SideBarEntry
|
||||
title="Formatter IR"
|
||||
position={"right"}
|
||||
selected={selected === SecondaryTool.FIR}
|
||||
onClick={() => onSelected(SecondaryTool.FIR)}
|
||||
>
|
||||
|
|
|
@ -22,9 +22,7 @@ export default function ShareButton({ onShare }: { onShare?: () => void }) {
|
|||
>
|
||||
Share
|
||||
</span>
|
||||
<span aria-hidden="false">
|
||||
Copied!
|
||||
</span>
|
||||
<span aria-hidden="false">Copied!</span>
|
||||
</AstralButton>
|
||||
) : (
|
||||
<AstralButton
|
||||
|
|
|
@ -23,6 +23,8 @@ export interface SideBarEntryProps {
|
|||
title: string;
|
||||
selected: boolean;
|
||||
children: ReactNode;
|
||||
position: "left" | "right";
|
||||
|
||||
onClick?(): void;
|
||||
}
|
||||
|
||||
|
@ -31,13 +33,14 @@ export function SideBarEntry({
|
|||
onClick,
|
||||
children,
|
||||
selected,
|
||||
position,
|
||||
}: SideBarEntryProps) {
|
||||
return (
|
||||
<li
|
||||
title={title}
|
||||
aria-label={title}
|
||||
onClick={onClick}
|
||||
role="button"
|
||||
className={`py-4 px-2 relative flex items-center flex-col fill-white text-white ${
|
||||
className={`group py-4 px-2 relative flex items-center justify-center flex-col fill-white text-white ${
|
||||
selected ? "opacity-100" : "opacity-50 hover:opacity-100"
|
||||
}`}
|
||||
>
|
||||
|
@ -45,6 +48,25 @@ export function SideBarEntry({
|
|||
{selected && (
|
||||
<span className="absolute start-0 inset-y-0 bg-white w-0.5"></span>
|
||||
)}
|
||||
|
||||
<Tooltip position={position}>{title}</Tooltip>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
interface TooltipProps {
|
||||
children: ReactNode;
|
||||
position: "left" | "right";
|
||||
}
|
||||
|
||||
function Tooltip({ children, position }: TooltipProps) {
|
||||
return (
|
||||
<span
|
||||
className={`z-10 absolute w-100 rounded dark:border-[1px] dark:border-white bg-space dark:bg-white px-2 py-1 hidden text-xs text-white dark:text-black group-hover:flex whitespace-nowrap ${
|
||||
position === "right" ? "right-[52px]" : "left-[52px]"
|
||||
}`}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue