I really like syntax highlighting, and it helps greatly during development, but also when I read code. I have grown very fond of Solarized Dark and One Dark (not light!), but I wanted to be more accessible, so I created my own themes that adheres with the WCAG requirements.
The colors
WCAG AA compliant for color contrast. WCAG AAA compliance forces the values on a light background to be too similar to each other to be used effectively for syntax highlighting.
Dark theme
All colors have a contrast ratio of >=5 against the background color #262831, Sky Captain.
#859BA3
#C79500
#2CAAA0
#469EDD
#8C9B9B
#E4E4E7
#262831
#FF6666
Light theme
All colors have a contrast ratio of >=5 against the background color #F5F6F7, Gram’s Hair.
import React from 'react';
import {
BrowserRouter,
Routes,
Route,
useLocation,
useNavigate,
} from 'react-router-dom';
import { GlobalAppShell } from '@tfso/global-app-shell';
import type {
GlobalNavigationPropsType,
GlobalHeaderWCPropsType,
} from './types';
// -- Tiny helper that runs inside the Router and syncs props to the WC --
function SyncNavWithRouter({
refNav,
baseProps, // whatever you previously put in navigationArgs
}: {
refNav: React.RefObject<any>;
baseProps: GlobalNavigationPropsType;
}) {
const location = useLocation();
const navigate = useNavigate();
const onNavigate = React.useMemo(
() => (to: string) => {
if (!to) return;
navigate(to); // SPA navigation
},
[navigate]
);
React.useEffect(() => {
if (!refNav.current) return;
// Push updated props into the web component whenever the route changes.
refNav.current.props = {
...baseProps,
onNavigate,
currentPath: location.pathname, // <- critical for is-active
// keep urlPrefix if you use one, e.g. baseProps.urlPrefix
};
}, [refNav, baseProps, onNavigate, location.pathname]);
return null;
}
export default function App({
navigationArgs,
headerArgs,
}: {
navigationArgs: GlobalNavigationPropsType;
headerArgs: GlobalHeaderWCPropsType;
}) {
const refNav = React.useRef<any>(null);
const refHeader = React.useRef<any>(null);
React.useEffect(() => {
if (refHeader.current) {
refHeader.current.props = headerArgs;
}
}, [headerArgs]);
return (
<>
<tfso-global-header ref={refHeader}></tfso-global-header>
<tfso-global-navigation ref={refNav}></tfso-global-navigation>
<GlobalAppShell isOpen={true}>
<BrowserRouter /* basename="/app" if you mount under a sub-path */>
{/* Keep WC in sync with the router */}
<SyncNavWithRouter refNav={refNav} baseProps={navigationArgs} />
{/* Your routed content */}
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/reports" element={<ReportsPage />} />
<Route path="/reports/:id" element={<ReportDetails />} />
{/* ...other routes */}
</Routes>
</BrowserRouter>
</GlobalAppShell>
</>
);
}
About the author
Hi! My name is Alexander, and I am a creative frontender, specializing
in UX, accessibility, universal design, frontend-architecture, node and
design systems. I am passionate with open source projects and love to
dabble with new emerging technologies related to frontend. With over
27 years of
frontend experience, I have earned the right to be called a veteran. I
am a lover of life, technologist at heart. If I am not coding, I am
cooking and I love whisky and cigars. Oh, and coffee, I LOVE coffee!
I am also an avid speaker on several topics! Check
out some of the things I speak about,
and contact me if you are interested in having me at your next event!