cca-io / rescript-mui

ReScript bindings for MUI
MIT License
254 stars 52 forks source link

Self-hosted Font in Theme #114

Closed FilipKittnar closed 3 years ago

FilipKittnar commented 4 years ago

Hello, I absolutely love this library, amazing work. However, I stumbled upon one strange thing. I think that binding for custom self-hosted font in MUI theme is slightly off. It converts itself to wrong JSON. Had to do Obj.magic in order for the font to work:

let theme =
  MaterialUi_Theme.create(
    {
      MaterialUi_ThemeOptions.(
        make(
          ~typography=Typography.make(~fontFamily="MyFont", ()),
          ~overrides=Obj.magic({
                       "MuiCssBaseline": {
                         "@global": {
                           "@font-face": [myFont],
                         },
                       },
                     }),
          (),
        )
      );
    },
  );

Am I doing something wrong?

jsiebern commented 4 years ago

Hi there, thank you for your kind words! No, you're probably not doing anything wrong, the theme types are far from perfect unfortunately. Translating typescript types is quite sketchy as it is, so an Obj.magic here and there might be required.

I'm looking to solve that in another project, but it will be a while until that is actually usable at this kind of scope.