Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collapsibility to calculator pages #1878

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
18ec65e
test: Try out one implementation of expandable
May 31, 2024
8284448
feat: Rudimentary implementation of collapsible
Jun 3, 2024
7dd51d6
feat: Improve aesthetics
Jun 3, 2024
632879a
feat: Improve aesthetics
Jun 3, 2024
5314ab5
feat: Fix to bottom
Jun 3, 2024
d3e1642
feat: CollapsedPanel
Jun 3, 2024
c14231f
fix: Improve styling
Jun 4, 2024
b3ee2bf
feat: Naïve implementation; will refactor
Jun 5, 2024
443e733
fix: Beginning of rewrite to use ThreeColumnPage for button
Jun 6, 2024
bf61f31
fix: Refactor CollapsedPanel
Jun 6, 2024
453833e
fix: Add panel titles as props
Jun 6, 2024
6e1bfe9
fix: Improve styling at bottom of page
Jun 6, 2024
0aca4e2
feat: Add collapsing to household inputs
Jun 6, 2024
0f5d0ca
feat: Refactor using padding instead of margin
Jun 7, 2024
f970c58
feat: Add proper sizing to middle panel of policy editor
Jun 7, 2024
854cd8f
feat: Replace box shadow with top border
Jun 7, 2024
dc5e69b
fix: Redo how gradient ends are calced
Jun 7, 2024
c340802
fix: Change center title on policy output
Jun 7, 2024
df3218a
fix: Repair household calculator panel names
Jun 7, 2024
feeee46
fix: Fix household left panel sizing
Jun 7, 2024
3485d3b
fix: Improve sizing
Jun 7, 2024
db33393
chore: Lint
Jun 7, 2024
7f96703
feat: Add width context to charts
Jun 10, 2024
1daddeb
feat: Refactor BottomCarousel to work with collapse
Jun 13, 2024
8823e7d
fix: Lint
Jun 13, 2024
1007e0c
fix: Move resize observer to ThreePanelPage
Jun 13, 2024
a993637
feat: Add resizing to input charts
Jun 13, 2024
8c3236e
fix: Polyfill ResizeObserver
Jun 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"lint-staged": "^15.2.5",
"node-fetch": "^3.3.2",
"prettier": "^3.2.5",
"resize-observer-polyfill": "^1.5.1",
"typescript": "^5.4.5",
"whatwg-fetch": "^3.6.20"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fireEvent, render, screen } from "@testing-library/react";
import BaselineAndReformChart from "pages/household/output/EarningsVariation/BaselineAndReformChart";
import { getValueFromHousehold } from "api/variables.js";
import ResizeObserver from "resize-observer-polyfill";

jest.mock("react-plotly.js", () => jest.fn());
jest.mock("../../../../../api/variables.js", () => ({
Expand All @@ -22,6 +23,8 @@ const metadata = {
},
};

global.ResizeObserver = ResizeObserver;

describe("Test Render Output", () => {
test("Should render toggle", () => {
getValueFromHousehold.mockImplementation(() => {
Expand Down
74 changes: 74 additions & 0 deletions src/controls/CollapseButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { DoubleLeftOutlined, DoubleRightOutlined } from "@ant-design/icons";
import { Tooltip } from "antd";
import fixedStyles from "../style";

export default function CollapseButton(props) {
const { onClick, isCollapsed, style, title } = props;

Check warning on line 6 in src/controls/CollapseButton.jsx

View check run for this annotation

Codecov / codecov/patch

src/controls/CollapseButton.jsx#L5-L6

Added lines #L5 - L6 were not covered by tests

function clickHandler() {

Check warning on line 8 in src/controls/CollapseButton.jsx

View check run for this annotation

Codecov / codecov/patch

src/controls/CollapseButton.jsx#L8

Added line #L8 was not covered by tests
if (onClick instanceof Function) {
onClick();

Check warning on line 10 in src/controls/CollapseButton.jsx

View check run for this annotation

Codecov / codecov/patch

src/controls/CollapseButton.jsx#L10

Added line #L10 was not covered by tests
}
}

return (

Check warning on line 14 in src/controls/CollapseButton.jsx

View check run for this annotation

Codecov / codecov/patch

src/controls/CollapseButton.jsx#L14

Added line #L14 was not covered by tests
<div
style={{
width: "100%",
display: "flex",
justifyContent: "flex-start",
alignItems: "center",
gap: "12px",
// Extra padding at bottom to
// avoid collision with scrollbar
// padding: "10px 0px 0px 20px",
paddingLeft: "20px",
borderStyle: "solid",
borderImage: `linear-gradient(to right,
${fixedStyles.colors.LIGHT_GRAY} 0px,
${fixedStyles.colors.LIGHT_GRAY} 12px,
${fixedStyles.colors.MEDIUM_DARK_GRAY} 12px,
${fixedStyles.colors.MEDIUM_DARK_GRAY} calc(100% - 12px),
${fixedStyles.colors.LIGHT_GRAY} calc(100% - 12px),
${fixedStyles.colors.LIGHT_GRAY} 100%) 100% 0 0 0/3px 0 0 0 stretch`,
backgroundColor: fixedStyles.colors.LIGHT_GRAY,
borderImageWidth: "1px",
borderWidth: "1px",
height: "100%",
...style,
}}
>
<Tooltip
title={`${isCollapsed ? "Maximize" : "Minimize"} panel`}
placement="right"
>
{isCollapsed ? (
<DoubleRightOutlined

Check warning on line 46 in src/controls/CollapseButton.jsx

View check run for this annotation

Codecov / codecov/patch

src/controls/CollapseButton.jsx#L46

Added line #L46 was not covered by tests
onClick={clickHandler}
style={{
fontSize: "12px",
color: fixedStyles.colors.DARK_GRAY,
}}
/>
) : (
<DoubleLeftOutlined

Check warning on line 54 in src/controls/CollapseButton.jsx

View check run for this annotation

Codecov / codecov/patch

src/controls/CollapseButton.jsx#L54

Added line #L54 was not covered by tests
onClick={clickHandler}
style={{
fontSize: "12px",
color: fixedStyles.colors.DARK_GRAY,
}}
/>
)}
</Tooltip>
<p
style={{
margin: "0",
fontSize: "12px",
color: fixedStyles.colors.DARK_GRAY,
}}
>
{title}
</p>
</div>
);
}
84 changes: 49 additions & 35 deletions src/layout/BottomCarousel.jsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import SearchParamNavButton from "../controls/SearchParamNavButton";
import style from "../style";
import useMobile from "./Responsive";
import { COLLAPSE_BUTTON_HEIGHT, PaneWidthContext } from "./ThreeColumnPage";
import { useContext } from "react";

export default function BottomCarousel(props) {
const { selected, options, bottomElements } = props;
const mobile = useMobile();
const currentIndex = options.map((option) => option.name).indexOf(selected);
const previous = options[currentIndex - 1] || {};
const next = options[currentIndex + 1] || {};
const paneWidth = useContext(PaneWidthContext);

Check warning on line 13 in src/layout/BottomCarousel.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/BottomCarousel.jsx#L13

Added line #L13 was not covered by tests

// Show the previous to the left, the current in the middle, and the next to the right

return (
<div
style={{
position: "absolute",
position: "fixed",
bottom: mobile ? "25vh" : 0,
display: "flex",
height: "min-content",
left: mobile ? 0 : "50%",
width: mobile ? "100%" : "50%",
minHeight: COLLAPSE_BUTTON_HEIGHT,
right: 0,
width: mobile ? "100%" : paneWidth,
alignItems: "center",
backgroundColor: style.colors.WHITE,
justifyContent: mobile ? "center" : "right",
// borderTop: "1px solid black",
borderTop: `1px solid ${style.colors.MEDIUM_DARK_GRAY}`,
justifyContent: mobile ? "center" : "left",
borderImage: `linear-gradient(to right,
${style.colors.LIGHT_GRAY} 0px,
${style.colors.LIGHT_GRAY} 12px,
${style.colors.MEDIUM_DARK_GRAY} 12px,
${style.colors.MEDIUM_DARK_GRAY} calc(100% - 12px),
${style.colors.LIGHT_GRAY} calc(100% - 12px),
${style.colors.LIGHT_GRAY} 100%) 100% 0 0 0/3px 0 0 0 stretch`,
borderImageWidth: "1px",
borderWidth: "1px",
borderStyle: "solid",
padding: "10px 20px",
gap: "10px",
}}
Expand All @@ -35,40 +47,42 @@
display: "flex",
justifyContent: "flex-end",
alignItems: "flex-start",
color: style.colors.DARK_GRAY,
}}
>
{bottomElements}
</div>
)}
<div
style={{
flex: 1,
display: "flex",
justifyContent: mobile ? "center" : "right",
alignItems: "flex-start",
gap: 20,
}}
>
{mobile && previous.label ? (
<SearchParamNavButton
focus={previous.name}
direction="left"
style={{ width: 50, fontSize: 16 }}
/>
) : (
<div style={{ width: 50 }} />
)}
{}
{mobile && next.label ? (
<SearchParamNavButton
focus={next.name}
direction="right"
style={{ width: 50, fontSize: 16 }}
/>
) : (
<div style={{ width: 60 }} />
)}
</div>
{mobile && (
<div

Check warning on line 57 in src/layout/BottomCarousel.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/BottomCarousel.jsx#L57

Added line #L57 was not covered by tests
style={{
flex: 1,
display: "flex",
justifyContent: mobile ? "center" : "right",
alignItems: "flex-start",
gap: 20,
}}
>
{previous.label ? (
<SearchParamNavButton

Check warning on line 67 in src/layout/BottomCarousel.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/BottomCarousel.jsx#L67

Added line #L67 was not covered by tests
focus={previous.name}
direction="left"
style={{ width: 50, fontSize: 16 }}
/>
) : (
<div style={{ width: 50 }} />

Check warning on line 73 in src/layout/BottomCarousel.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/BottomCarousel.jsx#L73

Added line #L73 was not covered by tests
)}
{mobile && next.label ? (
<SearchParamNavButton

Check warning on line 76 in src/layout/BottomCarousel.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/BottomCarousel.jsx#L76

Added line #L76 was not covered by tests
focus={next.name}
direction="right"
style={{ width: 50, fontSize: 16 }}
/>
) : (
<div style={{ width: 60 }} />

Check warning on line 82 in src/layout/BottomCarousel.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/BottomCarousel.jsx#L82

Added line #L82 was not covered by tests
)}
</div>
)}
</div>
);
}
32 changes: 32 additions & 0 deletions src/layout/CollapsedPanel.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import style from "../style";

export default function CollapsedPanel(props) {
const { title } = props;

Check warning on line 4 in src/layout/CollapsedPanel.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/CollapsedPanel.jsx#L3-L4

Added lines #L3 - L4 were not covered by tests

return (

Check warning on line 6 in src/layout/CollapsedPanel.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/CollapsedPanel.jsx#L6

Added line #L6 was not covered by tests
<div
style={{
height: "100%",
width: "100%",
backgroundColor: style.colors.LIGHT_GRAY,
position: "relative",
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
alignItems: "center",
}}
>
<p
style={{
writingMode: "sideways-lr",
margin: "0",
paddingTop: "30px",
fontSize: "12px",
color: style.colors.DARK_GRAY,
}}
>
{title}
</p>
</div>
);
}
54 changes: 43 additions & 11 deletions src/layout/HoverCard.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { AnimatePresence, motion } from "framer-motion";
import { createContext, useEffect, useState, memo } from "react";
import { createContext, useEffect, useState, memo, useRef } from "react";
import style from "../style";
import Divider from "./Divider";

export const HoverCardContext = createContext((obj) => obj);

export const ChartWidthContext = createContext((obj) => obj);

export default function HoverCard(props) {
const { children } = props;
const [enabled, setEnabled] = useState(false);
Expand Down Expand Up @@ -64,18 +66,48 @@

const MemoizedChildren = memo(function MemoizedChildren(props) {
const { children, setContent, setEnabled } = props;

const [chartWidth, setChartWidth] = useState(0);

// This represents the div holding the hovercard item,
// and will be used for dynamic size updating
const containerRef = useRef(null);

useEffect(() => {
if (containerRef.current) {
// If the container div
const observer = new ResizeObserver((entries) => {
setChartWidth(entries[0].contentRect.width);

Check warning on line 80 in src/layout/HoverCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/HoverCard.jsx#L80

Added line #L80 was not covered by tests
});

observer.observe(containerRef.current);

return () => {
observer.disconnect();
};
}
});

return (
<HoverCardContext.Provider value={setContent}>
<div
onMouseEnter={() => {
setEnabled(true);
}}
onMouseLeave={() => {
setEnabled(false);
}}
>
{children}
</div>
<ChartWidthContext.Provider value={chartWidth}>
<div
className="test"
onMouseEnter={() => {
setEnabled(true);

Check warning on line 97 in src/layout/HoverCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/HoverCard.jsx#L96-L97

Added lines #L96 - L97 were not covered by tests
}}
onMouseLeave={() => {
setEnabled(false);

Check warning on line 100 in src/layout/HoverCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/layout/HoverCard.jsx#L99-L100

Added lines #L99 - L100 were not covered by tests
}}
ref={containerRef}
style={{
height: "100%",
display: "flex",
}}
>
{children}
</div>
</ChartWidthContext.Provider>
</HoverCardContext.Provider>
);
});
4 changes: 2 additions & 2 deletions src/layout/StackedMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default function StackedMenu(props) {
}

return (
<div style={{ height: "80vh" }}>
<div style={{ overflow: "scroll", padding: 20 }}>{result}</div>
<div style={{ overflow: "scroll", padding: 20, height: "100%" }}>
{result}
</div>
);
}
Loading
Loading