-
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: Add tooltip that says "Click to start detour" (#2366)
* feat: Add tooltip that says "Click to start detour" * fix: Use fireEvent instead of userEvent in diversionPage tests to fix a known bug in userEvent * refactor: Extract <MapTooltip /> out as its own component * feat(storybook): Add storybook story for <MapTooltip />
- Loading branch information
1 parent
2e6c52a
commit b65aee6
Showing
7 changed files
with
99 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.c-map-tooltip::before { | ||
border-top-color: black; | ||
} | ||
|
||
.c-map-tooltip { | ||
background-color: black; | ||
border-color: black; | ||
color: white; | ||
opacity: 100% !important; | ||
font-size: 14px; | ||
padding: 4px 8px 4px 8px; | ||
font-family: var(--bs-body-font-family); | ||
border-radius: var(--bs-border-radius); | ||
} |
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,20 @@ | ||
import React, { PropsWithChildren } from "react" | ||
import { Tooltip } from "react-leaflet" | ||
|
||
interface MapTooltipProps extends PropsWithChildren { | ||
permanent?: boolean | ||
} | ||
|
||
export const MapTooltip = ({ children, permanent }: MapTooltipProps) => ( | ||
<Tooltip | ||
/* key is present here to force React to re-render the <MapTooltip /> if the value of permanent changes */ | ||
key={`tooltip-permanent-${permanent}`} | ||
className="c-map-tooltip" | ||
direction="top" | ||
offset={[0, -15]} | ||
sticky | ||
permanent={permanent} | ||
> | ||
{children} | ||
</Tooltip> | ||
) |
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 React from "react" | ||
import { MapTooltip } from "../../../src/components/map/tooltip" | ||
import type { Meta, StoryObj } from "@storybook/react" | ||
import { inMapDecorator } from "../../../.storybook/inMapDecorator" | ||
import { Polyline } from "react-leaflet" | ||
|
||
const meta = { | ||
component: MapTooltip, | ||
args: { | ||
children: "Tooltip Title", | ||
permanent: true, | ||
}, | ||
argTypes: { | ||
permanent: { table: { disable: true } }, | ||
}, | ||
render: ({ children, permanent }) => ( | ||
<Polyline | ||
className="c-detour_map--original-route-shape" | ||
positions={[ | ||
{ lat: 42.36, lng: -71.03 }, | ||
{ lat: 42.36, lng: -71.09 }, | ||
]} | ||
> | ||
<MapTooltip permanent={permanent}>{children}</MapTooltip> | ||
</Polyline> | ||
), | ||
decorators: [inMapDecorator], | ||
parameters: { layout: "fullscreen", stretch: true }, | ||
} satisfies Meta<typeof MapTooltip> | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof meta> | ||
|
||
export const Visible: Story = {} | ||
|
||
export const OnlyVisibleOnHover: Story = { | ||
args: { | ||
permanent: false, | ||
}, | ||
} |
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