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

🔨 (grapher) refactor modals and entity selector #3490

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ nav.controlsRow .chart-controls .settings-menu {
// chart-type label
//
.settings-menu-header {
display: flex;
justify-content: space-between;
align-items: center;
background: white;
padding: 9px $indent 3px $indent;
position: sticky;
Expand Down
13 changes: 6 additions & 7 deletions packages/@ourworldindata/grapher/src/controls/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { SelectionArray } from "../selection/SelectionArray"
import { ChartDimension } from "../chart/ChartDimension"
import { makeSelectionArray } from "../chart/ChartUtils.js"
import { AxisConfig } from "../axis/AxisConfig"
import { CloseButton } from "../closeButton/CloseButton.js"

import { AxisScaleToggle } from "./settings/AxisScaleToggle"
import { AbsRelToggle, AbsRelToggleManager } from "./settings/AbsRelToggle"
Expand All @@ -30,6 +29,7 @@ import {
TableFilterToggle,
TableFilterToggleManager,
} from "./settings/TableFilterToggle"
import { OverlayHeader } from "../core/OverlayHeader"

const {
LineChart,
Expand Down Expand Up @@ -315,12 +315,11 @@ export class SettingsMenu extends React.Component<{
...this.layout,
}}
>
<div className="settings-menu-header">
<div className="grapher_h5-black-caps grapher_light">
{menuTitle}
</div>
<CloseButton onClick={() => this.toggleVisibility()} />
</div>
<OverlayHeader
className="settings-menu-header"
title={menuTitle}
onDismiss={this.toggleVisibility}
/>

<div className="settings-menu-controls">
<SettingsGroup
Expand Down
15 changes: 1 addition & 14 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
reaction,
} from "mobx"
import { bind } from "decko"
import a from "indefinite"
import {
uniqWith,
isEqual,
Expand Down Expand Up @@ -2606,10 +2605,7 @@ export class Grapher
<div className="CaptionedChartAndSidePanel">
<CaptionedChart manager={this} />
{this.sidePanelBounds && (
<SidePanel
title={this.entitySelectorTitle}
bounds={this.sidePanelBounds}
>
<SidePanel bounds={this.sidePanelBounds}>
<EntitySelector manager={this} />
</SidePanel>
)}
Expand All @@ -2625,7 +2621,6 @@ export class Grapher

{/* entity selector in a slide-in drawer */}
<SlideInDrawer
title={this.entitySelectorTitle}
active={this.isEntitySelectorDrawerOpen}
toggle={() => {
this.isEntitySelectorModalOrDrawerOpen =
Expand Down Expand Up @@ -3115,14 +3110,6 @@ export class Grapher
: timeColumn.formatValue(value)
}

@computed get entitySelectorTitle(): string {
return this.canHighlightEntities
? `Select ${this.entityTypePlural}`
: this.canChangeEntity
? `Choose ${a(this.entityType)}`
: `Add/remove ${this.entityTypePlural}`
}

@computed get canSelectMultipleEntities(): boolean {
if (this.numSelectableEntityNames < 2) return false
if (this.addCountryMode === EntitySelectionMode.MultipleEntities)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ export const GRAPHER_EMBEDDED_FIGURE_CONFIG_ATTR = "data-grapher-config"
export const GRAPHER_PAGE_BODY_CLASS = "StandaloneGrapherOrExplorerPage"
export const GRAPHER_DRAWER_ID = "grapher-drawer"
export const GRAPHER_IS_IN_IFRAME_CLASS = "IsInIframe"
export const GRAPHER_SCROLLABLE_CONTAINER_CLASS = "scrollable-container"
export const GRAPHER_TIMELINE_CLASS = "timeline-component"
export const GRAPHER_ENTITY_SELECTOR_CLASS = "entity-selector"
export const GRAPHER_SIDE_PANEL_CLASS = "side-panel"

export const DEFAULT_GRAPHER_CONFIG_SCHEMA =
"https://files.ourworldindata.org/schemas/grapher-schema.004.json"
Expand Down
12 changes: 12 additions & 0 deletions packages/@ourworldindata/grapher/src/core/OverlayHeader.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.overlay-header {
--padding: var(--modal-padding, 16px);

display: flex;
justify-content: space-between;
align-items: center;
padding: var(--padding) var(--padding) 16px;

button {
margin-left: 8px;
}
}
20 changes: 20 additions & 0 deletions packages/@ourworldindata/grapher/src/core/OverlayHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react"
import cx from "classnames"
import { CloseButton } from "../closeButton/CloseButton.js"

export function OverlayHeader({
title,
onDismiss,
className,
}: {
title: string
onDismiss?: () => void
className?: string
}): JSX.Element {
return (
<div className={cx("overlay-header", className)}>
<h2 className="grapher_h5-black-caps grapher_light">{title}</h2>
{onDismiss && <CloseButton onClick={onDismiss} />}
</div>
)
}
1 change: 1 addition & 0 deletions packages/@ourworldindata/grapher/src/core/grapher.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ $zindex-controls-drawer: 150;
@import "../closeButton/CloseButton.scss";
@import "../controls/RadioButton.scss";
@import "../controls/Dropdown.scss";
@import "../core/OverlayHeader.scss";

.grapher_dark {
color: $dark-text;
Expand Down
Loading
Loading