Skip to content

Commit

Permalink
🔨 (grapher) refactor modals and entity selector
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Apr 15, 2024
1 parent 0deb912 commit e68c6a0
Show file tree
Hide file tree
Showing 23 changed files with 413 additions and 430 deletions.
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
12 changes: 6 additions & 6 deletions packages/@ourworldindata/grapher/src/controls/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
TableFilterToggle,
TableFilterToggleManager,
} from "./settings/TableFilterToggle"
import { OverlayHeader } from "../core/OverlayHeader"

const {
LineChart,
Expand Down Expand Up @@ -315,12 +316,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 @@ -90,6 +90,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

0 comments on commit e68c6a0

Please sign in to comment.