Skip to content

Commit

Permalink
✨ (entity selector) redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Apr 8, 2024
1 parent 07f7537 commit 889ebd5
Show file tree
Hide file tree
Showing 20 changed files with 715 additions and 283 deletions.
5 changes: 2 additions & 3 deletions packages/@ourworldindata/components/src/Checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@
}

.label {
@include grapher_label-2-regular;
padding-left: $checkbox-size + 8px;
cursor: pointer;
font-size: 14px;
letter-spacing: 0.01em;
line-height: 1.15;
user-select: none;
}

&:hover {
Expand Down
4 changes: 2 additions & 2 deletions packages/@ourworldindata/components/src/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { faCheck } from "@fortawesome/free-solid-svg-icons"

export class Checkbox extends React.Component<{
checked: boolean
onChange: () => any
label: string | React.ReactNode
onChange: React.ChangeEventHandler<HTMLInputElement>
label: React.ReactNode
}> {
render(): JSX.Element {
const { checked, onChange, label } = this.props
Expand Down
72 changes: 72 additions & 0 deletions packages/@ourworldindata/grapher/src/controls/RadioButton.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.radio {
$radio-size: 16px;

$light-stroke: #dadada;
$hover-stroke: #a4b6ca;
$active-fill: #dbe5f0;

position: relative;

input {
position: absolute;
opacity: 0;
left: 0;
cursor: pointer;
}

.outer {
position: absolute;
left: 0;
top: 0;
content: " ";
width: $radio-size;
height: $radio-size;

background: white;
pointer-events: none;
border-radius: 50%;
border: 1px solid #a4b6ca;
color: $dark-text;

display: flex;
align-items: center;
justify-content: center;

.inner {
display: none;
width: $radio-size / 2;
height: $radio-size / 2;
background-color: #6e87a2;
border-radius: 50%;
}
}

input:focus-visible + .outer {
outline: 2px solid $controls-color;
}

input:active + .outer > .inner {
display: block;
}

input:checked + .outer > .inner {
display: block;
}

input:checked:active + .outer > .inner {
display: block;
}

.label {
@include grapher_label-2-regular;
padding-left: $radio-size + 8px;
cursor: pointer;
user-select: none;
}

&:hover {
input:not(:checked) + .custom {
border-color: $hover-stroke;
}
}
}
31 changes: 31 additions & 0 deletions packages/@ourworldindata/grapher/src/controls/RadioButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react"

export class RadioButton extends React.Component<{
checked: boolean
onChange: React.ChangeEventHandler<HTMLInputElement>
label: React.ReactNode
group?: string
}> {
render(): JSX.Element {
const { checked, onChange, label, group } = this.props

return (
<div className="radio">
<label>
<input
type="radio"
name={group}
checked={checked}
onChange={onChange}
/>
<div className="outer">
{checked && <div className="inner" />}
</div>
<div className="label">
{label} {checked}
</div>
</label>
</div>
)
}
}
13 changes: 9 additions & 4 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ import {
} from "../captionedChart/StaticChartRasterizer.js"
import { SlopeChartManager } from "../slopeCharts/SlopeChart"
import { SidePanel } from "../sidePanel/SidePanel"
import { EntitySelector } from "../entitySelector/EntitySelector"
import {
EntitySelector,
type EntitySelectorState,
} from "../entitySelector/EntitySelector"
import { SlideInDrawer } from "../slideInDrawer/SlideInDrawer"

declare global {
Expand Down Expand Up @@ -464,6 +467,8 @@ export class Grapher

@observable.ref legacyConfigAsAuthored: Partial<LegacyGrapherInterface> = {}

@observable entitySelectorState: Partial<EntitySelectorState> = {}

@computed get dataApiUrlForAdmin(): string | undefined {
return this.props.dataApiUrlForAdmin
}
Expand Down Expand Up @@ -2151,7 +2156,7 @@ export class Grapher
0,
// the chart takes up 9 columns in 12-column grid
(9 / 12) * this.frameBounds.width,
this.frameBounds.height
this.frameBounds.height - 2 // 2px accounts for the border
)
}

Expand All @@ -2162,7 +2167,7 @@ export class Grapher
0, // not in use; intentionally set to zero
0, // not in use; intentionally set to zero
this.frameBounds.width - this.captionedChartBounds.width,
this.frameBounds.height
this.captionedChartBounds.height
)
}

Expand Down Expand Up @@ -3128,7 +3133,7 @@ export class Grapher
return this.canHighlightEntities
? `Select ${this.entityTypePlural}`
: this.canChangeEntity
? `Change ${a(this.entityType)}`
? `Choose ${a(this.entityType)}`
: `Add/remove ${this.entityTypePlural}`
}

Expand Down
5 changes: 2 additions & 3 deletions packages/@ourworldindata/grapher/src/core/GrapherConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ export const GRAPHER_EMBEDDED_FIGURE_ATTR = "data-grapher-src"
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_SCROLLABLE_CONTAINER_CLASS = "scrollable-container"
export const GRAPHER_IS_IN_IFRAME_CLASS = "IsInIframe"
export const GRAPHER_DRAWER_ID = "grapher-drawer"

export const DEFAULT_GRAPHER_CONFIG_SCHEMA =
"https://files.ourworldindata.org/schemas/grapher-schema.003.json"
Expand Down
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 @@ -88,6 +88,7 @@ $zindex-controls-drawer: 150;
@import "../fullScreen/FullScreen.scss";
@import "../../../components/src/Checkbox.scss";
@import "../closeButton/CloseButton.scss";
@import "../controls/RadioButton.scss";

.grapher_dark {
color: $dark-text;
Expand Down
33 changes: 33 additions & 0 deletions packages/@ourworldindata/grapher/src/core/typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@
@include grapher_body-3-medium;
}

@mixin grapher_body-3-regular {
@include grapher_body-3-medium;
font-weight: 400;
}

.grapher_body-3-regular {
@include grapher_body-3-regular;
}

@mixin grapher_body-3-medium-italic {
@include grapher_body-3-medium;
font-style: italic;
}

.grapher_body-3-medium-italic {
@include grapher_body-3-medium-italic;
}

//
// labels
//
Expand All @@ -101,3 +119,18 @@
.grapher_label-1-medium {
@include grapher_label-1-medium;
}

@mixin grapher_label-2-regular {
display: block;
margin: 0;

font-family: $sans-serif-font-stack;
font-size: 0.8125rem;
font-weight: 400;
line-height: 1.2;
letter-spacing: 0.01em;
}

.grapher_label-2-regular {
@include grapher_label-2-regular;
}
Loading

0 comments on commit 889ebd5

Please sign in to comment.