-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (entity selector) render into panel, drawer or modal (#3373)
[Cycle 2024.2: Entity selector](#3349) | [Designs](https://www.figma.com/file/X5mOEX8zULS6qyHocUYdmh/Grapher-UI?type=design&node-id=2523%3A6266&mode=design&t=7edFp79OOjz6RENz-1) ## Summary Renders the entity selector either into... - a side panel next to the chart - a drawer that slides in from the right - or a modal The entity selector itself hasn't been touched but will be redesigned in subsequent PRs. <details><summary><b>Screenshots</b></summary> <p> ![Screenshot 2024-03-21 at 10 10 14](https://github.com/owid/owid-grapher/assets/12461810/de7bc544-15c8-4d61-a92b-718b4d3431f6) ![Screenshot 2024-03-21 at 10 10 42](https://github.com/owid/owid-grapher/assets/12461810/59829930-401c-47e3-b5fc-4b7ede6fbc58) ![Screenshot 2024-03-21 at 10 11 25](https://github.com/owid/owid-grapher/assets/12461810/75a810e8-7e5d-4e95-b03f-858759d4394d) </p> </details> ## Details - Bounds (see screenshot below) - `frameBounds` are the bounds of the whole Grapher frame (including the side panel if it exists) - `captionedChartBounds` are the bounds of the `<CaptionedChart />` component that renders the chart itself and its header and footer - `sidePanelBounds` are the bounds of the side panel (if present) - New components - `EntitySelector` has been broken out of `EntitySelectorModal` so that we can render it into different spaces - `SidePanel` and `SlideInDrawer` are both utility components that don't know anything about the content they render - `SlideInDrawer` renders a drawer outside of Grapher that slides in on request (it works exactly like the slide-in drawer for the settings menu used to work) - `SidePanel` renders a panel to the right of the chart <details><summary><b>Screenshot</b></summary> <p> ![Screenshot 2024-03-21 at 10 56 40](https://github.com/owid/owid-grapher/assets/12461810/f2dff3c6-2e9b-4bb9-9ee2-0954826fb9b5) </p> </details> ## Caveats - Ideal bounds: - Grapher uses ideal bounds on Grapher pages - If the side panel is visible, then the ideal bounds should apply to the captioned chart, not the whole frame, since we care about the aspect ratio of the chart - Making it so that the `captionedChartBounds` are ideal (rather than the `frameBounds`) makes it more difficult to mirror that behaviour in CSS - Since making this work is not trivial, and in theory the design suggests that Grapher should be rendered into a 12-column grid anyway, I decided to look into sizing on Grapher pages at the end of the project ## Notes for the reviewer - It looks like a big PR, but most of it comes down to moving code around - I didn't spend any time making the current (old) design work when rendered into the side panel or drawer since it will be redesigned in subsequent PRs - There is no need to thoroughly review the CSS in particular (it's mostly just copy-pasted from other places or will change in the near future) - I removed the behaviour where clicking on an entity name opened the entity selector (it was difficult to discover for users and also inconsistent across charts (this only worked for line charts and stacked area charts)) - That's also the reason that the SVG tester fails for all line charts and all stacked area charts
- Loading branch information
1 parent
6a13031
commit df7e545
Showing
38 changed files
with
1,127 additions
and
632 deletions.
There are no files selected for viewing
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
3 changes: 3 additions & 0 deletions
3
packages/@ourworldindata/grapher/src/bodyPortal/.eslintrc.yaml
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,3 @@ | ||
rules: | ||
"@typescript-eslint/explicit-function-return-type": "warn" | ||
"@typescript-eslint/explicit-module-boundary-types": "warn" |
32 changes: 32 additions & 0 deletions
32
packages/@ourworldindata/grapher/src/bodyPortal/BodyPortal.tsx
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,32 @@ | ||
import React from "react" | ||
import ReactDOM from "react-dom" | ||
|
||
interface BodyPortalProps { | ||
id?: string | ||
tagName?: string // default: "div" | ||
children: React.ReactNode | ||
} | ||
|
||
// Render a component on the Body instead of inside the current Tree. | ||
// https://reactjs.org/docs/portals.html | ||
export class BodyPortal extends React.Component<BodyPortalProps> { | ||
el: HTMLElement | ||
|
||
constructor(props: BodyPortalProps) { | ||
super(props) | ||
this.el = document.createElement(props.tagName || "div") | ||
if (props.id) this.el.id = props.id | ||
} | ||
|
||
componentDidMount(): void { | ||
document.body.appendChild(this.el) | ||
} | ||
|
||
componentWillUnmount(): void { | ||
document.body.removeChild(this.el) | ||
} | ||
|
||
render(): any { | ||
return ReactDOM.createPortal(this.props.children, this.el) | ||
} | ||
} |
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
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
Oops, something went wrong.