Skip to content

Commit

Permalink
chore(react,vue): Simplify legend implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Sep 6, 2024
1 parent b98b87a commit 677c6e4
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 198 deletions.
142 changes: 71 additions & 71 deletions packages/create-common/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,77 @@ body {
flex-grow: 1;
}

/******************************************************************************
* CARDS
*/

.card {
background: var(--card-background);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
display: flex;
flex-direction: column;
position: relative;
}

summary.card-summary {
width: 100%;
height: var(--card-summary-height);
line-height: var(--card-summary-height);
flex-shrink: 0;
flex-grow: 0;
border-bottom: 1px solid var(--border-color);
cursor: pointer;
user-select: none;
}

summary.card-summary {
list-style: none;
}

summary.card-summary::-webkit-details-marker {
display: none;
}

summary.card-summary::after {
content: ' ►';
position: absolute;
top: 0rem;
right: 0.8rem;
color: var(--control-color);
}

details[open].card summary.card-summary:after {
content: ' ▼';
}

details.card summary.card-summary:hover:after {
color: var(--control-color-hover);
}

summary .card-summary-title {
padding: 0 1rem;
width: 100%;
}

.card-content {
flex-grow: 1;
padding: 1rem;
overflow: auto;
}

/******************************************************************************
* SKELETONS
*/

.skeleton {
display: block;
width: 100%;
background: var(--border-color);
filter: brightness(110%);
border-radius: var(--border-radius);
}

/******************************************************************************
* SIDEBAR
*/
Expand Down Expand Up @@ -464,77 +535,6 @@ ul.category-list + button {
right: 0;
}

/******************************************************************************
* CARDS
*/

.card {
background: var(--card-background);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
display: flex;
flex-direction: column;
position: relative;
}

summary.card-summary {
width: 100%;
height: var(--card-summary-height);
line-height: var(--card-summary-height);
flex-shrink: 0;
flex-grow: 0;
border-bottom: 1px solid var(--border-color);
cursor: pointer;
user-select: none;
}

summary.card-summary {
list-style: none;
}

summary.card-summary::-webkit-details-marker {
display: none;
}

summary.card-summary::after {
content: ' ►';
position: absolute;
top: 0rem;
right: 0.8rem;
color: var(--control-color);
}

details[open].card summary.card-summary:after {
content: ' ▼';
}

details.card summary.card-summary:hover:after {
color: var(--control-color-hover);
}

summary .card-summary-title {
padding: 0 1rem;
width: 100%;
}

.card-content {
flex-grow: 1;
padding: 1rem;
overflow: auto;
}

/******************************************************************************
* SKELETONS
*/

.skeleton {
display: block;
width: 100%;
background: var(--border-color);
filter: brightness(110%);
border-radius: var(--border-radius);
}

/******************************************************************************
* FORMS
*/
Expand Down
12 changes: 9 additions & 3 deletions packages/create-react/src/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ interface CardProps {
title?: string;
open?: boolean;
collapsible?: boolean;
className?: string;
}

export function Card({ children, title, open = true }: CardProps) {
export function Card({
children,
title,
className = '',
open = true,
}: CardProps) {
if (!title) {
return (
<section className="card">
<section className={`card ${className}`}>
<div className="card-content">{children}</div>
</section>
);
}
return (
<details className="card" open={open}>
<details className={`card ${className}`} open={open}>
<summary className="card-summary">
<span className="body1 card-summary-title">{title}</span>
</summary>
Expand Down
30 changes: 0 additions & 30 deletions packages/create-react/src/components/legends/Legend.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Color } from '@deck.gl/core';
import { toHexString } from '../../utils';

export type LegendEntryCategoricalProps = {
type: 'categorical';
title: string;
subtitle: string;
values: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Color } from '@deck.gl/core';
import { toHexString } from '../../utils';

export type LegendEntryContinuousProps = {
type: 'continuous';
title: string;
subtitle: string;
domain: [number, number];
Expand Down
24 changes: 11 additions & 13 deletions packages/create-react/src/components/views/CellTowersView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FormulaWidget } from '../widgets/FormulaWidget';
import { CategoryWidget } from '../widgets/CategoryWidget';
import { useDebouncedState } from '../../hooks/useDebouncedState';
import { AppContext } from '../../context';
import { LegendEntryCategorical } from '../legends/LegendEntryCategorical';

const MAP_VIEW = new MapView({ repeat: true });
const MAP_STYLE =
Expand Down Expand Up @@ -131,19 +132,16 @@ export default function CellTowersView() {
layerVisibility={layerVisibility}
onLayerVisibilityChange={setLayerVisibility}
/>
<Legend
entries={[
// TODO: Cleaner way to generate a legend?
{
type: 'categorical',
title: 'Cell towers',
subtitle: 'By Radio',
values: RADIO_DOMAIN,
getSwatchColor: (value: string) =>
RADIO_COLORS({ properties: { radio: value } }, null!),
},
]}
/>
<Card title="Legend" className="legend">
<LegendEntryCategorical
title="Cell towers"
subtitle="By Radio"
values={RADIO_DOMAIN}
getSwatchColor={(value: string) =>
RADIO_COLORS({ properties: { radio: value } }, null!)
}
/>
</Card>
<aside
className="map-footer"
dangerouslySetInnerHTML={{ __html: attributionHTML }}
Expand Down
24 changes: 11 additions & 13 deletions packages/create-react/src/components/views/PopulationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Layers } from '../Layers';
import { Card } from '../Card';
import { AppContext } from '../../context';
import { useDebouncedState } from '../../hooks/useDebouncedState';
import { LegendEntryContinuous } from '../legends/LegendEntryContinuous';

const MAP_VIEW = new MapView({ repeat: true });
const MAP_STYLE =
Expand Down Expand Up @@ -109,19 +110,16 @@ export default function PopulationView() {
layerVisibility={layerVisibility}
onLayerVisibilityChange={setLayerVisibility}
/>
<Legend
entries={[
// TODO: Cleaner way to generate a legend?
{
type: 'continuous',
title: 'U.S. population',
subtitle: 'Sum of population by H3 cell',
domain: POP_DOMAIN,
getSwatchColor: (value) =>
POP_COLORS({ properties: { population_sum: value } }, null!),
},
]}
/>
<Card title="Legend" className="legend">
<LegendEntryContinuous
title="U.S. population"
subtitle="Sum of population by H3 cell"
domain={POP_DOMAIN}
getSwatchColor={(value) =>
POP_COLORS({ properties: { population_sum: value } }, null!)
}
/>
</Card>
<aside
className="map-footer"
dangerouslySetInnerHTML={{ __html: attributionHTML }}
Expand Down
37 changes: 0 additions & 37 deletions packages/create-vue/src/components/legends/Legend.vue

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Color } from '@deck.gl/core';
import { toHexString } from '../../utils';
export type LegendEntryCategoricalProps = {
type: 'categorical';
title: string;
subtitle: string;
values: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import type { Color } from '@deck.gl/core';
export type LegendEntryContinuousProps = {
type: 'continuous';
title: string;
subtitle: string;
domain: [number, number];
Expand Down
Loading

0 comments on commit 677c6e4

Please sign in to comment.