playroom icon indicating copy to clipboard operation
playroom copied to clipboard

Modify Head

Open hipstersmoothie opened this issue 7 years ago • 1 comments

It would be nice to have a way to include things in the head of the page.

For example here i need to include a company font icon hosted on an internal CDN. Something like storybook's preview-head.html would be perfect

hipstersmoothie avatar Dec 06 '18 09:12 hipstersmoothie

There is a workaround in the meantime, by "abusing" framecomponent to append scripts/stylesheet in the head.

Example:

import * as React from 'react';

function useStylesheet(url: string) {
  React.useEffect(() => {
    const link = document.createElement('link');
    link.href = url;
    link.rel = 'stylesheet';
    const head = document.getElementsByTagName('head')[0];
    head.appendChild(link);
    return function() {
      head.removeChild(link);
    };
  }, [url]);
}

export default function PlayroomFrame(props: { children: React.ReactNode }) {
  useStylesheet('https://mycdn/mystyle.css');

  return <>{props.children}</>;
}

malcolm-kee avatar Dec 23 '19 06:12 malcolm-kee