From ceb933fde34637619dedbb8c1a4147df9f3d663e Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Tue, 2 Jul 2024 22:29:30 -0400 Subject: [PATCH] Use `calc()` in Sass --- index.html | 8 ++++-- src/css/_controls.scss | 33 ++++++++++++++++-------- src/css/_header.scss | 2 +- src/css/theme/_touchable-icons.scss | 39 +++-------------------------- src/js/about.ts | 2 +- tests/app/about.test.ts | 2 +- 6 files changed, 34 insertions(+), 52 deletions(-) diff --git a/index.html b/index.html index bc40cdf..cd6417d 100644 --- a/index.html +++ b/index.html @@ -83,10 +83,14 @@ >
-
+
- + div.leaflet-control-container > div.leaflet-top.leaflet-right { - top: 104px; - margin-left: 10px; + $zoom-controls-height: calc( + (touchable-icons.$min-touch-target * 2) + $outer-border-thickness + ); + $margin-between-zoom-control: 8px; + top: calc( + $zoom-controls-top-offset + $zoom-controls-height + + $margin-between-zoom-control + ); + margin-left: 10px; // Mirrors zoom controls. right: auto; } @@ -47,19 +59,18 @@ } .leaflet-control-layers label { - font-size: typography.$font-size-md; + font-size: $label-font-size; line-height: 1; &:first-child { - border-bottom: 1px solid colors.$gray-light-translucent; + border-bottom: $option-divider; } display: flex; align-items: center; - // Each option is naturally 18px, so 13px padding results in - // the touch target being the minimum size of 44px. - padding: 13px 8px; + $padding-y: calc((touchable-icons.$min-touch-target - $label-font-size) / 2); + padding: $padding-y 8px; input[type="radio"] { margin: 0; diff --git a/src/css/_header.scss b/src/css/_header.scss index 69c9094..a1f4124 100644 --- a/src/css/_header.scss +++ b/src/css/_header.scss @@ -20,7 +20,7 @@ header { color: colors.$white; } - .header-about-icon { + .header-about-icon-container { margin-right: 0.75em; } diff --git a/src/css/theme/_touchable-icons.scss b/src/css/theme/_touchable-icons.scss index c96f6d9..6457b96 100644 --- a/src/css/theme/_touchable-icons.scss +++ b/src/css/theme/_touchable-icons.scss @@ -1,39 +1,6 @@ -$icon-size-xs: 20px; -$icon-size-sm: 24px; -$icon-size-md: 32px; +$icon-size-sm: 20px; +$icon-size-md: 24px; +$icon-size-lg: 32px; // https://www.w3.org/WAI/WCAG21/Understanding/target-size.html $min-touch-target: 44px; - -@mixin touchable-icon($icon-size) { - width: $icon-size; - height: $icon-size; - - // Ensure minimum touch target size - $touch-size: max($icon-size, $min-touch-target); - min-width: $touch-size; - min-height: $touch-size; - - // Center the icon within the touch target - display: inline-flex; - align-items: center; - justify-content: center; - - // Add padding if icon is smaller than min touch target - @if $icon-size < $min-touch-target { - $padding: ($min-touch-target - $icon-size) / 2; - padding: $padding; - } -} - -@mixin touchable-icon-xs { - @include touchable-icon($icon-size-xs); -} - -@mixin touchable-icon-sm { - @include touchable-icon($icon-size-sm); -} - -@mixin touchable-icon-md { - @include touchable-icon($icon-size-md); -} diff --git a/src/js/about.ts b/src/js/about.ts index 5ae5a52..7335e33 100644 --- a/src/js/about.ts +++ b/src/js/about.ts @@ -6,7 +6,7 @@ const setUpAbout = () => { const aboutElement: HTMLElement | null = document.querySelector(".about-text-popup"); - const infoButton = document.querySelector(".header-about-icon"); + const infoButton = document.querySelector(".header-about-icon-container"); if (infoButton && aboutElement) { infoButton.addEventListener("click", () => { aboutElement.style.display = diff --git a/tests/app/about.test.ts b/tests/app/about.test.ts index 5a8b16a..b328664 100644 --- a/tests/app/about.test.ts +++ b/tests/app/about.test.ts @@ -3,7 +3,7 @@ import { expect, test } from "@playwright/test"; test("about popup can be opened and closed", async ({ page }) => { await page.goto(""); - const aboutIcon = ".header-about-icon"; + const aboutIcon = ".header-about-icon-container"; const aboutIsVisible = async () => page.$eval(".about-text-popup", (el) => el.style.display === "block");