Skip to content

Commit

Permalink
Add calendar in tooltip to show available dates, rather than an unord…
Browse files Browse the repository at this point in the history
…ered list
  • Loading branch information
mileswwatkins committed Nov 27, 2024
1 parent 8f1ccb0 commit ed66596
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 24 deletions.
54 changes: 54 additions & 0 deletions public/link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions src/components/Attribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,25 @@ const Attribution = () => {
</a>
</span>
<span className="Attribution">
Logo based on{" "}
<a href="https://thenounproject.com/icon/watchtower-1247287/">
Logo and favicon based on{" "}
<a
href="https://thenounproject.com/icon/watchtower-1247287/"
rel="noreferrer"
target="_blank"
>
work by Creative Mania
</a>
</span>
<span className="Attribution">
<a
href="https://thenounproject.com/icon/external-3776998/"
rel="noreferrer"
target="_blank"
>
Link icon
</a>{" "}
by Adrien Coquet
</span>
</div>
);
};
Expand Down
40 changes: 27 additions & 13 deletions src/components/MapPopup.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
.mapboxgl-popup-content {
background-color: #faf3ce;
}

.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip {
border-top-color: #faf3ce;
}

.Map-Popup {
max-height: 150px;
overflow: auto;
margin-top: 0;
width: 242px;
}

.Map-Popup-header {
Expand All @@ -21,6 +12,12 @@

.Map-Popup-header > a {
color: #000;
width: 200px;
}

.Map-Popup-link-icon {
height: 14px;
margin-left: 5px;
}

.Map-Popup-body {
Expand All @@ -39,7 +36,24 @@
font-style: italic;
}

.Map-Popup-list {
margin-top: 2px;
margin-bottom: 0;
.Map-Popup-body__available {
font-style: italic;
display: block;
margin-bottom: 4px;
}

/* Override values from third-party libraries */

/* Use the theme color for the popup background */
.mapboxgl-popup-content {
background-color: #faf3ce;
}
.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip {
border-top-color: #faf3ce;
}

/* Apply uniform spacing to the tooltip container */
.mapboxgl-popup-content {
padding: 12px;
padding-bottom: 9px;
}
36 changes: 27 additions & 9 deletions src/components/MapPopup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Fragment } from "react";
import { Popup } from "react-map-gl";
import { formatFacilityName, reformatDate, isLikelyClosed } from "../utils";
import { formatFacilityName, isLikelyClosed } from "../utils";
import DatePicker from "react-datepicker";
import "./MapPopup.css";
import "react-datepicker/dist/react-datepicker.css";
import { add } from "date-fns";

const MapPopup = ({ location, info }) => {
let availableDates = [];
Expand All @@ -15,6 +18,9 @@ const MapPopup = ({ location, info }) => {
new Date().getMonth(),
);

const minDate = new Date();
const maxDate = add(new Date(), { months: 6, days: 1 });

return (
<Popup
{...location}
Expand Down Expand Up @@ -42,6 +48,11 @@ const MapPopup = ({ location, info }) => {
rel="noopener noreferrer"
>
{formatFacilityName(info.metadata.facility_name)}
<img
src="link.svg"
alt="link icon"
className="Map-Popup-link-icon"
></img>
</a>
</span>
<div className="Map-Popup-body">
Expand All @@ -60,15 +71,22 @@ const MapPopup = ({ location, info }) => {
</span>
) : (
<Fragment>
<span>
Available for {availableDates.length} nights over the next 6
months:
<span className="Map-Popup-body__available">
Available for {availableDates.length} night
{availableDates.length > 1 && "s"} over the next 6 months. Click
on the link above to book.
</span>
<ul className="Map-Popup-list">
{availableDates.map((date) => (
<li key={date}>{reformatDate(date)}</li>
))}
</ul>
<DatePicker
inline
// Helps with styling enough to be okay with the loss of
// accessibility
disabledKeyboardNavigation
minDate={minDate}
maxDate={maxDate}
highlightDates={availableDates.map((date) => new Date(date))}
// Don't suggest to the user that they can select anything
selectedDates={[]}
/>
</Fragment>
)}
</div>
Expand Down

0 comments on commit ed66596

Please sign in to comment.