Skip to content

Commit

Permalink
style: Turn off shadow DOM for map marker styling, to inherit styles …
Browse files Browse the repository at this point in the history
…from map
  • Loading branch information
purplebugs committed Nov 5, 2024
1 parent 6c718e2 commit 76624f3
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 141 deletions.
147 changes: 6 additions & 141 deletions src/alpaca-map-marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,147 +21,6 @@ export default class AlpacaMapMarker extends LitElement {
} /* If a property changes the element re-renders */,
};

static styles = [
css`
/********* FARM MARKERS *********/
/* Ref: https://developers.google.com/maps/documentation/javascript/advanced-markers/html-markers#maps_advanced_markers_html-css */
/* Farm markers */
.farm-marker {
padding: 0.75rem;
background-color: white;
color: var(--almost-black);
transition: all 0.3s ease-out;
width: auto;
max-width: 15rem;
border-radius: 1rem;
border-width: 0.2rem;
border-style: solid;
&.public {
border-color: var(--public-farm);
}
&.private {
border-color: var(--private-farm);
}
.summary {
display: flex;
gap: 0.5rem;
align-items: center;
font-size: 1.5rem;
}
.count {
font-weight: bolder;
}
.more-info {
display: flex;
border-radius: 0.5rem;
flex: 1;
flex-direction: column;
&:not(.highlight) {
display: none;
}
}
.city {
border-radius: 10px;
padding: 0.2rem 0.5rem;
border: 1px solid var(--gray-100);
max-width: fit-content;
}
.address {
font-size: 1rem;
font-style: normal;
margin-top: 1rem;
}
.farm-marker-link {
font-size: 1rem;
font-style: normal;
margin: 1rem 0 0.5rem 0;
border-radius: 1rem;
padding: 1rem 0.5rem;
border: 0.125rem solid var(--gray-500);
box-shadow: 0 0.25rem 0 0.125rem var(--gray-200);
.text {
margin: 0 0 0 1rem;
}
}
.farm-marker-link:hover {
border-color: var(--pink);
box-shadow: 0 0.25rem 0 0.125rem var(--gray-400);
}
.directions,
.city address {
display: flex;
flex-basis: auto;
align-items: center;
padding: 0 0.25rem 0 0;
}
/* Icons */
.icon {
&.link-arrow {
margin-left: 0.5rem;
}
}
&.public .icon {
color: var(--green);
}
&.private .icon {
color: var(--brown);
}
}
.farm-marker::after {
/* Pointer under farm marker - taken from css in https://developers.google.com/maps/documentation/javascript/advanced-markers/html-markers*/
border-left: 8px solid transparent;
border-right: 8px solid transparent;
content: "";
height: 0;
left: 50%;
position: absolute;
top: 100%;
transform: translateX(-50%) translateY(calc(0.1em * -1));
/* translateY inspired from hotels.com */
width: 0;
}
.farm-marker.public::after {
border-top: 8px solid var(--green);
}
.farm-marker.private::after {
border-top: 8px solid var(--brown);
}
/********* Links *********/
a {
color: var(--dark-blue);
}
a:hover {
color: var(--pale-blue);
text-decoration: underline;
text-decoration-thickness: 0.5em;
}
`,
];

constructor() {
super();
this.name;
Expand All @@ -180,6 +39,12 @@ export default class AlpacaMapMarker extends LitElement {
super.connectedCallback();
}

createRenderRoot() {
// Turns off shadow DOM.
// Since AlpacaMapMarker is not used externally, only by AlpacaMap then we want to inherit all styling, so turn off shadow DOM.
return this;
}

render() {
return html` <div class="farm-marker ${this.category} ${this.highlight}">
<div class="summary">
Expand Down
2 changes: 2 additions & 0 deletions src/alpaca-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MarkerClusterer } from "@googlemaps/markerclusterer";
import { Loader } from "@googlemaps/js-api-loader";

import STYLED_MAP_TYPE from "./styles-map.js";
import stylesMapMarker from "./styles-map-marker.js";
import "./alpaca-map-marker.js";
import "./alpaca-map-icon.js";

Expand Down Expand Up @@ -215,6 +216,7 @@ export default class AlpacaMap extends LitElement {
background-color: var(--pale-blue);
}
`,
stylesMapMarker,
];

constructor() {
Expand Down
130 changes: 130 additions & 0 deletions src/styles-map-marker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { css } from "lit";

/**
* Map marker styling
*
* Ref: https://developers.google.com/maps/documentation/javascript/advanced-markers/html-markers#maps_advanced_markers_html-css
*
*/

export default css`
.farm-marker {
padding: 0.75rem;
background-color: white;
color: var(--almost-black);
transition: all 0.3s ease-out;
width: auto;
max-width: 15rem;
border-radius: 1rem;
border-width: 0.2rem;
border-style: solid;
&.public {
border-color: var(--public-farm);
}
&.private {
border-color: var(--private-farm);
}
.summary {
display: flex;
gap: 0.5rem;
align-items: center;
font-size: 1.5rem;
}
.count {
font-weight: bolder;
}
.more-info {
display: flex;
border-radius: 0.5rem;
flex: 1;
flex-direction: column;
&:not(.highlight) {
display: none;
}
}
.city {
border-radius: 10px;
padding: 0.2rem 0.5rem;
border: 1px solid var(--gray-100);
max-width: fit-content;
}
.address {
font-size: 1rem;
font-style: normal;
margin-top: 1rem;
}
.farm-marker-link {
font-size: 1rem;
font-style: normal;
margin: 1rem 0 0.5rem 0;
border-radius: 1rem;
padding: 1rem 0.5rem;
border: 0.125rem solid var(--gray-500);
box-shadow: 0 0.25rem 0 0.125rem var(--gray-200);
.text {
margin: 0 0 0 1rem;
}
}
.farm-marker-link:hover {
border-color: var(--pink);
box-shadow: 0 0.25rem 0 0.125rem var(--gray-400);
}
.directions,
.city address {
display: flex;
flex-basis: auto;
align-items: center;
padding: 0 0.25rem 0 0;
}
/* Icons */
.icon {
&.link-arrow {
margin-left: 0.5rem;
}
}
&.public .icon {
color: var(--green);
}
&.private .icon {
color: var(--brown);
}
}
.farm-marker::after {
/* Pointer under farm marker - taken from css in https://developers.google.com/maps/documentation/javascript/advanced-markers/html-markers*/
border-left: 8px solid transparent;
border-right: 8px solid transparent;
content: "";
height: 0;
left: 50%;
position: absolute;
top: 100%;
transform: translateX(-50%) translateY(calc(0.1em * -1));
/* translateY inspired from hotels.com */
width: 0;
}
.farm-marker.public::after {
border-top: 8px solid var(--green);
}
.farm-marker.private::after {
border-top: 8px solid var(--brown);
}
`;

0 comments on commit 76624f3

Please sign in to comment.