-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9669744
commit 727e68f
Showing
9 changed files
with
232 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import { MapMouseEvent } from "react-map-gl"; | ||
|
||
import { atom } from "jotai"; | ||
|
||
export const projectsUIState = atom<{ | ||
filtersOpen: boolean; | ||
}>({ | ||
filtersOpen: false, | ||
}); | ||
|
||
export const popupAtom = atom<{ | ||
lngLat: MapMouseEvent["lngLat"]; | ||
features: MapMouseEvent["features"]; | ||
} | null>(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { PropsWithChildren } from "react"; | ||
import * as React from "react"; | ||
|
||
import { Popup } from "react-map-gl"; | ||
|
||
import { useAtom } from "jotai"; | ||
import { XIcon } from "lucide-react"; | ||
|
||
import { popupAtom } from "@/app/(overview)/store"; | ||
|
||
export default function MapPopup({ children }: PropsWithChildren) { | ||
const [popup, setPopup] = useAtom(popupAtom); | ||
|
||
if (!popup || !popup.features?.length) { | ||
return null; | ||
} | ||
|
||
const closePopup = () => { | ||
setPopup(null); | ||
}; | ||
|
||
return ( | ||
<Popup | ||
longitude={popup.lngLat.lng} | ||
latitude={popup.lngLat.lat} | ||
closeOnClick={false} | ||
onClose={closePopup} | ||
className="bg-transparent text-sm" | ||
maxWidth="320" | ||
> | ||
<div className="flex flex-col gap-2"> | ||
<> | ||
<button type="button" onClick={closePopup} className="self-end"> | ||
<XIcon className="h-5 w-5 text-foreground hover:text-muted-foreground" /> | ||
</button> | ||
{children} | ||
</> | ||
</div> | ||
</Popup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as React from "react"; | ||
|
||
import { cva, type VariantProps } from "class-variance-authority"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
|
||
const badgeVariants = cva( | ||
"inline-flex items-center rounded-xl border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", | ||
{ | ||
variants: { | ||
variant: { | ||
default: | ||
"border-transparent bg-primary text-big-stone-900 shadow hover:bg-primary/80", | ||
secondary: | ||
"border-transparent bg-secondary text-accent-foreground hover:bg-slate-200", | ||
destructive: | ||
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-rose-700", | ||
outline: "text-foreground", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
}, | ||
}, | ||
); | ||
|
||
export interface BadgeProps | ||
extends React.HTMLAttributes<HTMLDivElement>, | ||
VariantProps<typeof badgeVariants> {} | ||
|
||
function Badge({ className, variant, ...props }: BadgeProps) { | ||
return ( | ||
<div className={cn(badgeVariants({ variant }), className)} {...props} /> | ||
); | ||
} | ||
|
||
export { Badge, badgeVariants }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useAtomValue } from "jotai"; | ||
|
||
import { renderCurrency } from "@/lib/format"; | ||
import { cn } from "@/lib/utils"; | ||
|
||
import { popupAtom } from "@/app/(overview)/store"; | ||
|
||
import MapPopup from "@/components/map/popup"; | ||
import { Badge } from "@/components/ui/badge"; | ||
|
||
const HEADER_CLASSES = "py-0.5 text-left font-normal text-muted-foreground"; | ||
const CELL_CLASSES = "py-0.5 font-semibold"; | ||
|
||
export default function CostAbatementPopup() { | ||
const popup = useAtomValue(popupAtom); | ||
|
||
return ( | ||
<MapPopup> | ||
<div className="flex items-center justify-between"> | ||
<span className="font-semibold"> | ||
{popup?.features?.[0]?.properties?.country} | ||
</span> | ||
<Badge variant="outline" className="pointer-events-none"> | ||
SUM | ||
</Badge> | ||
</div> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th className={cn(HEADER_CLASSES, "pr-2")}>Cost</th> | ||
<th className={cn(HEADER_CLASSES, "px-2")}>Abatement</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td className={cn(CELL_CLASSES, "pr-2")}> | ||
{renderCurrency(popup?.features?.[0]?.properties?.cost)} | ||
</td> | ||
<td className={cn(CELL_CLASSES, "px-2")}> | ||
{renderCurrency( | ||
popup?.features?.[0]?.properties?.abatementPotential, | ||
)} | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<p className="text-xs text-muted-foreground"> | ||
Values for the SUM of all projects. | ||
</p> | ||
</MapPopup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { cn } from "@/lib/utils"; | ||
|
||
export const formatCurrency = ( | ||
value: number, | ||
options: Intl.NumberFormatOptions = {}, | ||
) => { | ||
return Intl.NumberFormat(undefined, { | ||
style: "currency", | ||
currency: "USD", | ||
...options, | ||
}).format(value); | ||
}; | ||
|
||
export function renderCurrency( | ||
value: number, | ||
options: Intl.NumberFormatOptions = {}, | ||
className?: HTMLSpanElement["className"], | ||
) { | ||
return ( | ||
<span | ||
className={cn( | ||
"inline-block first-letter:align-top first-letter:text-xs first-letter:tracking-[0.1rem] first-letter:text-muted-foreground", | ||
className, | ||
)} | ||
> | ||
{formatCurrency(value, options)} | ||
</span> | ||
); | ||
} |