import { useEffect, useRef, useState } from "preact/hooks"; import "./NoteMap.css"; import { rgb2hex } from "./utils"; interface CssData { fontFamily: string; textColor: string; mutedTextColor: string; } export default function NoteMap() { const containerRef = useRef(null); const styleResolverRef = useRef(null); const [ cssData, setCssData ] = useState(); console.log("Got CSS ", cssData); useEffect(() => { if (!containerRef.current || !styleResolverRef.current) return; setCssData(getCssData(containerRef.current, styleResolverRef.current)); }, []); return (
Container goes here.
) } function getCssData(container: HTMLElement, styleResolver: HTMLElement): CssData { const containerStyle = window.getComputedStyle(container); const styleResolverStyle = window.getComputedStyle(styleResolver); return { fontFamily: containerStyle.fontFamily, textColor: rgb2hex(containerStyle.color), mutedTextColor: rgb2hex(styleResolverStyle.color) } }