Skip to content

Commit

Permalink
fix: spacing on new menu
Browse files Browse the repository at this point in the history
Signed-off-by: rare-magma <[email protected]>
  • Loading branch information
rare-magma committed Sep 14, 2024
1 parent f89a91a commit dfb201d
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 111 deletions.
13 changes: 8 additions & 5 deletions src/components/NavBar/NavBar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { BrowserRouter } from "react-router-dom";
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi, beforeEach } from "vitest";
import { BudgetMother } from "../../guitos/domain/budget.mother";
import {
budgetContextSpy,
Expand All @@ -11,6 +11,12 @@ import {
import { NavBar } from "./NavBar";

describe("NavBar", () => {
const windowSpy = vi.spyOn(window, "open");

beforeEach(() => {
windowSpy.mockClear();
});

const comp = (
<BrowserRouter>
<NavBar />
Expand Down Expand Up @@ -138,10 +144,7 @@ describe("NavBar", () => {
"open instructions in new tab",
);
await userEvent.click(instructionsButton);
expect(instructionsButton).toHaveAttribute(
"href",
"https://github.com/rare-magma/guitos#getting-started",
);
expect(windowSpy).toHaveBeenCalled();
});

it("opens guitos repo in new tab", async () => {
Expand Down
232 changes: 133 additions & 99 deletions src/components/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export function NavBar() {
{<BsXLg aria-hidden={true} />}
</Button>
</Offcanvas.Header>
<Offcanvas.Body className="justify-content-end">
<Offcanvas.Body className="justify-content-end flex">
<Nav>
<Nav className={expanded ? "p-2" : "m-2"}>
{hasMultipleBudgets && (
Expand All @@ -286,111 +286,145 @@ export function NavBar() {
)}
</Nav>
</Nav>
<Nav
className={
<div
style={
expanded
? "mt-4 flex-wrap flex-row row-cols-2 flex-grow-1 h-75"
: ""
? {
display: "flex",
flexDirection: "row",
flexWrap: "wrap",
}
: {}
}
>
{hasOneOrMoreBudgets && (
<>
<NavBarItem
disabled={!canUndo}
itemClassName={expanded ? "p-4" : "m-2"}
onClick={undo}
tooltipID={"tooltip-undo-history"}
tooltipText={"undo"}
buttonAriaLabel={"undo change"}
buttonClassName={expanded ? "w-100 h-100" : "w-100"}
buttonVariant={"outline-info"}
buttonIcon={
<BsArrowCounterclockwise
size={expanded ? 50 : 0}
aria-hidden={true}
/>
}
/>

<NavBarItem
disabled={!canRedo}
itemClassName={expanded ? "p-4" : "m-2"}
onClick={redo}
tooltipID={"tooltip-redo-history"}
tooltipText={"redo"}
buttonAriaLabel={"redo change"}
buttonClassName={expanded ? "w-100 h-100" : "w-100"}
buttonVariant={"outline-info"}
buttonIcon={
<BsArrowClockwise
size={expanded ? 50 : 0}
aria-hidden={true}
/>
}
/>
</>
)}
<NavBarItem
itemClassName={expanded ? "p-4" : "m-2"}
onClick={() => {
setExpanded(false);
createBudget();
}}
tooltipID={"tooltip-new-budget"}
tooltipText={"new budget"}
buttonAriaLabel={"new budget"}
buttonClassName={expanded ? "w-100 h-100" : "w-100"}
buttonVariant={"outline-success"}
buttonIcon={
<BsPlusLg size={expanded ? 50 : 0} aria-hidden={true} />
<Nav
style={
expanded
? {
marginTop: "4",
flexDirection: "row",
flexWrap: "wrap",
}
: {}
}
/>
{hasOneOrMoreBudgets && (
<>
<NavBarItem
itemClassName={expanded ? "p-4" : "m-2"}
onClick={() => {
setExpanded(false);
cloneBudget();
}}
tooltipID={"tooltip-clone-budget"}
tooltipText={"clone budget"}
buttonAriaLabel={"clone budget"}
buttonClassName={expanded ? "w-100 h-100" : "w-100"}
buttonVariant={"outline-success"}
buttonIcon={
<FaRegClone size={expanded ? 50 : 0} aria-hidden={true} />
}
/>
<NavBarDelete
deleteButtonRef={deleteButtonRef}
handleRemove={() => handleRemoveBudget(budget?.id)}
expanded={expanded}
/>
</>
)}
>
{hasOneOrMoreBudgets && (
<>
<NavBarItem
disabled={!canUndo}
itemClassName={expanded ? "m-4 flex-grow-1 h-25" : "m-2"}
onClick={undo}
tooltipID={"tooltip-undo-history"}
tooltipText={"undo"}
buttonAriaLabel={"undo change"}
buttonClassName={expanded ? "w-100 h-100" : "w-100"}
buttonVariant={"outline-info"}
buttonIcon={
<BsArrowCounterclockwise
size={expanded ? 50 : 0}
aria-hidden={true}
/>
}
/>

<NavBarItem
disabled={!canRedo}
itemClassName={expanded ? "m-4 flex-grow-1 h-25" : "m-2"}
onClick={redo}
tooltipID={"tooltip-redo-history"}
tooltipText={"redo"}
buttonAriaLabel={"redo change"}
buttonClassName={expanded ? "w-100 h-100" : "w-100"}
buttonVariant={"outline-info"}
buttonIcon={
<BsArrowClockwise
size={expanded ? 50 : 0}
aria-hidden={true}
/>
}
/>
</>
)}
<NavBarItem
itemClassName={
expanded
? hasOneOrMoreBudgets
? "m-4 flex-grow-1 h-25"
: "m-4 flex-grow-1 h-75"
: "m-2"
}
onClick={() => {
setExpanded(false);
createBudget();
}}
tooltipID={"tooltip-new-budget"}
tooltipText={"new budget"}
buttonAriaLabel={"new budget"}
buttonClassName={expanded ? "w-100 h-100" : "w-100"}
buttonVariant={"outline-success"}
buttonIcon={
<BsPlusLg size={expanded ? 50 : 0} aria-hidden={true} />
}
/>
{hasOneOrMoreBudgets && (
<>
<NavBarItem
itemClassName={expanded ? "m-4 flex-grow-1 h-25" : "m-2"}
onClick={() => {
setExpanded(false);
cloneBudget();
}}
tooltipID={"tooltip-clone-budget"}
tooltipText={"clone budget"}
buttonAriaLabel={"clone budget"}
buttonClassName={expanded ? "w-100 h-100" : "w-100"}
buttonVariant={"outline-success"}
buttonIcon={
<FaRegClone
size={expanded ? 50 : 0}
aria-hidden={true}
/>
}
/>
<NavBarDelete
deleteButtonRef={deleteButtonRef}
handleRemove={() => handleRemoveBudget(budget?.id)}
expanded={expanded}
/>
</>
)}

<NavBarImpExp expanded={expanded} setExpanded={setExpanded} />
<NavBarImpExp expanded={expanded} setExpanded={setExpanded} />

{hasOneOrMoreBudgets && <NavBarSettings expanded={expanded} />}
{hasOneOrMoreBudgets && <NavBarSettings expanded={expanded} />}

<NavBarItem
itemClassName={expanded ? "p-4" : "m-2"}
onClick={() =>
window.open(
"https://github.com/rare-magma/guitos#getting-started",
)
}
tooltipID={"tooltip-guitos-instructions"}
tooltipText={"open instructions in new tab"}
buttonAriaLabel={"open instructions in new tab"}
buttonClassName={expanded ? "w-100 h-100" : "w-100"}
buttonVariant={"outline-info"}
buttonIcon={
<BsQuestionLg size={expanded ? 50 : 0} aria-hidden={true} />
}
/>
</Nav>
<NavBarItem
itemClassName={
expanded
? hasOneOrMoreBudgets
? "m-4 flex-grow-1 h-25"
: "m-4 flex-grow-1 h-75"
: "m-2"
}
onClick={() => {
const newWindow = window.open(
"https://github.com/rare-magma/guitos#getting-started",
"_blank",
"noopener,noreferrer",
);
if (newWindow) newWindow.opener = null;
}}
tooltipID={"tooltip-guitos-instructions"}
tooltipText={"open instructions in new tab"}
buttonAriaLabel={"open instructions in new tab"}
buttonClassName={expanded ? "w-100 h-100" : "w-100"}
buttonVariant={"outline-info"}
buttonIcon={
<BsQuestionLg size={expanded ? 50 : 0} aria-hidden={true} />
}
/>
</Nav>
</div>
</Offcanvas.Body>
</Navbar.Offcanvas>
</Container>
Expand Down
2 changes: 1 addition & 1 deletion src/components/NavBar/NavBarDelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function NavBarDelete({
const { budget } = useBudget();

return (
<Nav className={expanded ? "p-4" : "m-2"}>
<Nav className={expanded ? "m-4 flex-grow-1 h-25" : "m-2"}>
<OverlayTrigger
trigger="click"
key="nav-deletion-overlay"
Expand Down
10 changes: 5 additions & 5 deletions src/components/NavBar/NavBarImpExp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function NavBarImpExp({ expanded, setExpanded }: NavBarImpExpProps) {
}

return hasOneOrMoreBudgets ? (
<Nav className={expanded ? "p-4" : "m-2"}>
<Nav className={expanded ? "m-4 flex-grow-1 h-25" : "m-2"}>
<OverlayTrigger
trigger="click"
key="nav-imp-exp-overlay"
Expand Down Expand Up @@ -160,7 +160,7 @@ export function NavBarImpExp({ expanded, setExpanded }: NavBarImpExpProps) {
</OverlayTrigger>
</Nav>
) : (
<Nav className="m-2">
<Nav className={expanded ? "m-4 flex-grow-1 h-75 w-25" : "m-2"}>
<OverlayTrigger
delay={250}
placement="bottom"
Expand All @@ -170,14 +170,14 @@ export function NavBarImpExp({ expanded, setExpanded }: NavBarImpExpProps) {
</Tooltip>
}
>
<Form.Group controlId="import">
<Form.Group className="w-100 h-100" controlId="import">
<Button
className="w-100"
className="w-100 h-100"
aria-label="import budget"
variant="outline-primary"
onClick={() => importRef.current?.click()}
>
{<BsUpload aria-hidden={true} />}
{<BsUpload size={expanded ? 50 : 0} aria-hidden={true} />}
</Button>
<Form.Control
data-testid="import-form-control"
Expand Down
2 changes: 1 addition & 1 deletion src/components/NavBar/NavBarSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function NavBarSettings({ expanded }: NavBarSettingsProps) {
});

return (
<Nav className={expanded ? "p-4" : "m-2"}>
<Nav className={expanded ? "m-4 flex-grow-1 h-25" : "m-2"}>
<OverlayTrigger
trigger="click"
key="nav-settings-overlay"
Expand Down

0 comments on commit dfb201d

Please sign in to comment.