Skip to content
14paxton edited this page Jul 14, 2023 · 3 revisions

RGB to HEX

https://css-tricks.com/converting-color-spaces-in-javascript/

function RGBToHex(rgb) {
    let sep = rgb.indexOf(",") > -1
              ? ","
              : " ";
    rgb = rgb.substr(4).split(")")[0].split(sep);

    // Convert %s to 0–255
    for (let R in rgb) {
        let r = rgb[R];
        if (r.indexOf("%") > -1) rgb[R] = Math.round(r.substr(0, r.length - 1) / 100 * 255);
        /* Example:
         75% -> 191
         75/100 = 0.75, * 255 = 191.25 -> 191
         */
    }

Create Style element insert into document head

generateRulesAll(tableRef.current).then((css) => {
    const styleElement = document.createElement('style');
    styleElement.innerText = css;
    iframeRef?.current.contentWindow.document.head.appendChild(styleElement);
});

Clone this wiki locally