All files / applications/go-by-transit/src/component/footer AppFooter.tsx

100% Statements 9/9
100% Branches 8/8
100% Functions 5/5
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119            17x 17x 17x 17x     3x       2x       3x     17x                                               3x                                                                                                                                              
import { Dialog, useTheme } from "@wintermuted/ui-react";
import React, { useState } from "react";
import FontAwesome from "react-fontawesome";
import { useFeatureFlags } from "../feature-flags/FeatureFlags";
 
export default function AppFooter() {
  const { resolvedTheme, setPreference } = useTheme();
  const nextTheme = resolvedTheme === "dark" ? "light" : "dark";
  const { walkingEnabled, setWalkingEnabled } = useFeatureFlags();
  const [flagsOpen, setFlagsOpen] = useState(false);
 
  function openFeatureFlags() {
    setFlagsOpen(true);
  }
 
  function closeFeatureFlags() {
    setFlagsOpen(false);
  }
 
  function changeWalkingEnabled(event: React.ChangeEvent<HTMLInputElement>) {
    setWalkingEnabled(event.currentTarget.checked);
  }
 
  return (
    <footer className="transit-app-footer">
      <nav className="transit-footer-navigation" aria-label="Footer navigation">
        <div className="transit-footer-links">
          <a
            href="https://github.com/wintermuted/overworld"
            target="_blank"
            rel="noopener noreferrer"
          >
            <FontAwesome name="github" aria-hidden="true" />
            Source
          </a>
          <a
            href="https://github.com/wintermuted/overworld/releases"
            target="_blank"
            rel="noopener noreferrer"
          >
            Releases
          </a>
        </div>
        <div className="transit-footer-theme">
          <button
            type="button"
            className="wm-docs-topbar-toggle"
            onClick={() => setPreference(nextTheme)}
            aria-label="Toggle dark mode"
            title="Toggle dark mode"
          >
            <svg
              viewBox="0 0 24 24"
              fill="none"
              stroke="currentColor"
              strokeWidth="2"
              strokeLinecap="round"
              strokeLinejoin="round"
              aria-hidden="true"
              focusable="false"
            >
              {nextTheme === "light" ? (
                <>
                  <circle cx="12" cy="12" r="4" />
                  <path d="M12 2v2m0 16v2M2 12h2m16 0h2M4.93 4.93l1.42 1.42m11.3 11.3 1.42 1.42M4.93 19.07l1.42-1.42m11.3-11.3 1.42-1.42" />
                </>
              ) : (
                <path d="M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401" />
              )}
            </svg>
            <span>{nextTheme === "light" ? "Light" : "Dark"}</span>
          </button>
          <button
            type="button"
            className="wm-docs-topbar-toggle"
            aria-haspopup="dialog"
            aria-expanded={flagsOpen}
            onClick={openFeatureFlags}
          >
            <FontAwesome name="sliders" aria-hidden="true" />
            Feature flags
          </button>
        </div>
      </nav>
      {flagsOpen && (
        <Dialog open onClose={closeFeatureFlags} title="Feature flags">
          <div className="transit-feature-flags-content">
            <p>
              Experimental features are off by default. Changes apply
              immediately in this tab and reset on reload.
            </p>
            <label
              className="transit-feature-flag"
              htmlFor="feature-walking-estimates"
            >
              <input
                id="feature-walking-estimates"
                type="checkbox"
                role="switch"
                checked={walkingEnabled}
                aria-describedby="feature-walking-description"
                onChange={changeWalkingEnabled}
              />
              Enable walking estimates
            </label>
            <p id="feature-walking-description">
              Nearby sends your current location and stop coordinates, or the
              endpoints of trip-planner walking legs, to Mapbox to estimate
              walking distances and paths. GPS and mapped paths may
              be inaccurate; accessibility is not verified. Turning this off
              cancels requests and removes the walking path.
            </p>
          </div>
        </Dialog>
      )}
    </footer>
  );
}