-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts/components/RecenterControl): localize
RecenterControl
state…
… and styling (#2252) * feat(ts/components/RecenterControl): localize `RecenterControl` state and styling and refactor old control to use `CustomControl` * feat(ts/component/recenterControl): add stories
- Loading branch information
Showing
17 changed files
with
264 additions
and
366 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
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,17 @@ | ||
.c-recenter-control { | ||
path { | ||
fill: none; | ||
stroke: $color-button-secondary; | ||
stroke-width: 2; | ||
} | ||
|
||
&[data-is-active="true"] { | ||
background-color: $color-button-disabled; | ||
color: $color-font-grey; | ||
cursor: default; | ||
|
||
path { | ||
stroke: $color-font-grey; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,54 +1,56 @@ | ||
import { Control, ControlOptions, DomUtil } from "leaflet" | ||
import { createControlComponent } from "@react-leaflet/core" | ||
import { fullStoryEvent } from "../../../helpers/fullStory" | ||
import { ControlOptions } from "leaflet" | ||
import React from "react" | ||
|
||
interface RecenterControlProps extends ControlOptions { | ||
recenter: () => void | ||
} | ||
class LeafletRecenterControl extends Control { | ||
private recenter: () => void | ||
constructor(props: ControlOptions, recenter: () => void) { | ||
super(props) | ||
this.recenter = recenter | ||
} | ||
|
||
onAdd() { | ||
const controlContainer = DomUtil.create( | ||
"div", | ||
"leaflet-control leaflet-bar c-vehicle-map__recenter-button" | ||
) | ||
controlContainer.onclick = (e) => { | ||
e.stopPropagation() | ||
e.preventDefault() | ||
import { CustomControl } from "./customControl" | ||
|
||
fullStoryEvent("Recenter control clicked", {}) | ||
|
||
this.recenter() | ||
} | ||
controlContainer.innerHTML = ` | ||
<a | ||
href="#" | ||
title="Recenter Map" | ||
role="button" | ||
aria-label="Recenter Map" | ||
> | ||
<svg | ||
height="26" | ||
viewBox="-5 -5 32 32" | ||
width="26" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="m10 2.7-6.21 16.94a2.33 2.33 0 0 0 1.38 3 2.36 2.36 0 0 0 1.93-.14l4.9-2.67 4.89 2.71a2.34 2.34 0 0 0 3.34-2.8l-5.81-17a2.34 2.34 0 0 0 -4.4 0z" | ||
transform="rotate(60, 12, 12)" | ||
/> | ||
</svg> | ||
</a>` | ||
return controlContainer | ||
export interface RecenterButtonProps { | ||
active?: boolean | ||
onActivate?: () => void | ||
} | ||
export const RecenterButton = ({ | ||
active, | ||
onActivate: onActivateProp, | ||
}: RecenterButtonProps) => { | ||
const onActivate = () => { | ||
fullStoryEvent("Recenter control clicked", {}) | ||
onActivateProp?.() | ||
} | ||
return ( | ||
//eslint-disable-next-line jsx-a11y/anchor-is-valid | ||
<a | ||
className="c-recenter-control" | ||
title="Recenter Map" | ||
role="button" | ||
aria-label="Recenter Map" | ||
onKeyDown={(e) => e.key === "Enter" && onActivate()} | ||
tabIndex={-1} | ||
onClick={onActivate} | ||
data-is-active={active} | ||
> | ||
<svg | ||
height="26" | ||
width="26" | ||
viewBox="-5 -5 32 32" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="m10 2.7-6.21 16.94a2.33 2.33 0 0 0 1.38 3 2.36 2.36 0 0 0 1.93-.14l4.9-2.67 4.89 2.71a2.34 2.34 0 0 0 3.34-2.8l-5.81-17a2.34 2.34 0 0 0 -4.4 0z" | ||
transform="rotate(60, 12, 12)" | ||
/> | ||
</svg> | ||
</a> | ||
) | ||
} | ||
|
||
export const RecenterControl = createControlComponent( | ||
({ position: position, recenter: recenterFn }: RecenterControlProps) => | ||
new LeafletRecenterControl({ position: position }, recenterFn) | ||
) | ||
export const RecenterControl = ({ | ||
active = false, | ||
onActivate: onClick, | ||
...props | ||
}: RecenterButtonProps & ControlOptions) => { | ||
return ( | ||
<CustomControl position="topright" {...props} className="leaflet-bar"> | ||
<RecenterButton {...{ active, onActivate: onClick }} /> | ||
</CustomControl> | ||
) | ||
} |
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
Oops, something went wrong.