seek-oss / playroom

Design with JSX, powered by your own component library.
MIT License
4.45k stars 183 forks source link

Custom fonts/static assets #254

Open mikefrancis opened 2 years ago

mikefrancis commented 2 years ago

Hey there,

Thanks for making Playroom.

I'd like to serve up some local fonts to use from within Playroom but can't find any docs on how to do this.

Is it possible?

michaeltaranto commented 2 years ago

Hey 👋

I would recommend doing this with a custom FrameComponent.

Here is a basic example:

// FrameComponent.tsx

export default ({ children }) => {
  return (
    <>
      <link href="---web font url---" rel="stylesheet" />
      {children}
    </>
  );
}

And then provide the path of that file to your playroom config:

// playroom.config.js

module.exports = {
  // ...
  frameComponent: './FrameComponent.tsx'
}
mikefrancis commented 2 years ago

@michaeltaranto Thanks for the reply! Is there any way to host the fonts from the playroom dev server without these being served from the public web?

michaelwarren1106 commented 2 years ago

I've been trying to use a custom frame component to remove the margin on the iframe element body tag, etc

I did exactly what you suggest above (copy and paste), and i've been getting:

image

my Frame.tsx is:

export default ({ children }) => {
  return (
    <>
      <link href="---web font url---" rel="stylesheet" />
      {children}
    </>
  );
}
mikefrancis commented 2 years ago

@michaelwarren1106 You'll need to add a CSS loader to your webpack config:

// playroom.config.js

module.exports = {
  // ...
  webpackConfig: () => ({
    module: {
      rules: [
        {
          test: /\.css$/,
          exclude: /node_modules/,
          use: ['style-loader', 'css-loader'],
        },
      ],
    },
  },
  // ...
};