import innerText from "react-innertext"; import HeadingAnchor from "../HeadingAnchor"; import { styled, theme } from "../../lib/styles/stitches.config"; import type { ComponentPropsWithoutRef } from "react"; const Anchor = styled(HeadingAnchor, { margin: "0 0.4em", padding: "0 0.2em", color: theme.colors.medium, opacity: 0, // overridden on hover below (except on small screens) "&:hover, &:focus-visible": { color: theme.colors.link, }, "@medium": { margin: "0 0.2em", padding: "0 0.4em", // don't require hover to show anchor link on small (likely touch) screens opacity: 1, }, }); const H = styled("h1", { marginTop: "1em", marginBottom: "0.5em", lineHeight: 1.5, // offset (approximately) with sticky header so jumped-to content isn't hiding behind it. // note: use rem so it isn't based on the heading's font size. scrollMarginTop: "5.5rem", "@medium": { scrollMarginTop: "6.5rem", }, // show anchor link when hovering anywhere over the heading line, or on keyboard tab focus [`&:hover ${Anchor}, ${Anchor}:focus-visible`]: { opacity: 1, }, variants: { // subtle horizontal rule under the heading, set by default on `