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

nat dash dropdown #1108

Merged
merged 2 commits into from
Apr 16, 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
12 changes: 6 additions & 6 deletions src/containers/datasets/carbon-market-potential/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ const CarbonMarketPotentialWidget = () => {
</span>
</PopoverTrigger>

<PopoverContent>
<ul className="max-h-56 space-y-2">
<PopoverContent className="rounded-2xl px-2 shadow-border">
<ul className="max-h-32 space-y-0.5">
{labels?.map((l) => (
<li key={l} className="last-of-type:pb-4">
<li key={l}>
<button
className={cn({
'font-bold': true,
Expand Down Expand Up @@ -94,10 +94,10 @@ const CarbonMarketPotentialWidget = () => {
</span>
</PopoverTrigger>

<PopoverContent>
<ul className="max-h-56 space-y-2">
<PopoverContent className="rounded-2xl px-2 shadow-border">
<ul className="max-h-32 space-y-0.5">
{units?.map((u) => (
<li key={u.label} className="last-of-type:pb-4">
<li key={u.label}>
<button
aria-label="set unit"
className={cn({
Expand Down
4 changes: 2 additions & 2 deletions src/containers/datasets/habitat-change/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const HabitatExtent = () => {
<PopoverContent className="rounded-2xl px-2 shadow-border">
<ul className="z-20 max-h-56 space-y-0.5">
{years?.map((y) => (
<li key={y} className="last-of-type:pb-4">
<li key={y}>
<button
aria-label="Select start year"
className={cn({
Expand Down Expand Up @@ -119,7 +119,7 @@ const HabitatExtent = () => {
<PopoverContent className="rounded-2xl px-2 shadow-border">
<ul className="z-20 max-h-56 space-y-0.5">
{years?.map((y) => (
<li key={y} className="last-of-type:pb-4">
<li key={y}>
<button
aria-label="select end year"
className={cn({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,19 @@ import Icon from 'components/icon';
import { Popover, PopoverContent, PopoverTrigger } from 'components/popover';
import { SwitchWrapper, SwitchRoot, SwitchThumb } from 'components/switch';
import WidgetControls from 'components/widget-controls';
import { WIDGET_SELECT_STYLES, WIDGET_SELECT_ARROW_STYLES } from 'styles/widgets';
import type { ActiveLayers } from 'types/layers';
import type { WidgetSlugType } from 'types/widget';

import ARROW_SVG from 'svgs/ui/arrow-filled.svg?sprite';

import { DATA_SOURCES } from '../constants';

import type { IndicatorSourceTypes } from './types';

const LABEL_UNITS = {
km2: 'km²',
};

type DataSourceTypes = {
value: number;
layer_link: `globalmangrovewatch.${string}`;
download_link: string;
layer_info: string;
source_layer: string;
};

type IndicatorSourceTypes = {
id: WidgetSlugType;
locationIso: string;
layerIndex: number;
source: string;
years: number[];
unit: string;
dataSource: DataSourceTypes;
color: string;
yearSelected: number;
setYearSelected: (year: number) => void;
};

const IndicatorSource = ({
id,
source,
Expand Down Expand Up @@ -91,24 +72,26 @@ const IndicatorSource = ({
{years.length > 1 && (
<Popover>
<PopoverTrigger asChild>
<span className="first-line:after relative cursor-pointer border-b-2 border-b-brand-800 font-bold">
<span className={`${WIDGET_SELECT_STYLES} print:border-hidden`}>
{yearSelected}
<Icon
icon={ARROW_SVG}
className="absolute -bottom-2.5 left-1/2 inline-block h-2 w-2 -translate-x-1/2"
className={`${WIDGET_SELECT_ARROW_STYLES} print:hidden`}
description="Arrow"
/>
</span>
</PopoverTrigger>

<PopoverContent>
<ul className="max-h-56 space-y-2">
<PopoverContent className="rounded-2xl px-2 shadow-border">
<ul className="max-h-32 space-y-0.5">
{years?.map((u) => (
<li key={u} className="last-of-type:pb-4">
<li key={u}>
<button
aria-label="set year"
className={cn({
'font-bold': true,
'w-full rounded-lg py-1 px-2 text-left hover:bg-brand-800/20': true,
'hover:text-brand-800': yearSelected !== u,
'pointer-events-none opacity-50': yearSelected === u,
})}
type="button"
onClick={() => setYearSelected(u)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { WidgetSlugType } from 'types/widget';

type DataSourceTypes = {
value: number;
layer_link: `globalmangrovewatch.${string}`;
download_link: string;
layer_info: string;
source_layer: string;
};

export type IndicatorSourceTypes = {
id: WidgetSlugType;
locationIso: string;
layerIndex: number;
source: string;
years: number[];
unit: string;
dataSource: DataSourceTypes;
color: string;
yearSelected: number;
setYearSelected: (year: number) => void;
};
6 changes: 3 additions & 3 deletions src/containers/datasets/species-distribution/widget.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRef, useState, useLayoutEffect } from 'react';
import { createRef, useState, useLayoutEffect, useRef, useEffect } from 'react';

import cn from 'lib/classnames';

Expand Down Expand Up @@ -28,10 +28,10 @@ const SpeciesDistribution = () => {

const isWorldwide = location === 'Worldwide';
// const total = data?.total;
const ref = createRef<HTMLDivElement>();
const ref = useRef<HTMLDivElement>(null);
const trianglePosition = (total * lineChartWidth) / worldwideTotal - 11; // substract icon size
// fires synchronously after all DOM mutations.
useLayoutEffect(() => {
useEffect(() => {
if (ref && ref.current && ref.current.offsetWidth) {
setLineChartWidth(ref?.current?.offsetWidth);
}
Expand Down
Loading