Skip to content

Conversation

Reklino
Copy link

@Reklino Reklino commented Jun 12, 2020

Hey there! This is great little tool 🙏 . Thanks for putting it together.

I'm using this in a project that uses Google Fonts in an iframe, so I need the <style> tags to be included in that document rather than the base document. This simply adds a new prop for this use case.

Copy link
Owner

@jakewtaylor jakewtaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for submitting a PR! 🙏

I'm just a little confused about the PropTypes/Typescript definitions you've added, can you explain? 😃

@jakewtaylor
Copy link
Owner

Hi @Reklino, how's it going - did you manage to figure out what the types should be? 😆😋

@Reklino
Copy link
Author

Reklino commented Jun 24, 2020

@jakewtaylor thanks for the reminder. #document is just a good old object. Just updated.

@jakewtaylor
Copy link
Owner

Apologies for the delay @Reklino, the code looks good to me now. Sorry to be a pain, but could you provide a small example of how this new prop works, just so I can test it? 😄

@Reklino
Copy link
Author

Reklino commented Sep 26, 2020

@jakewtaylor sure!

If you have a rendered iframe, just get the document of that iframe and pass it to your component via the contentDocument prop.

Example using react-frame-component (link)

const MyComponent = (props, context) => (
<Fragment>
  <Frame>
    <FrameContextConsumer>
      {
        // Callback is invoked with iframe's window and document instances
        ({document, window}) => {
          <Fragment>
           <GoogleFontLoader
              fonts={[
                {
                  font: 'Roboto',
                  weights: [400, '400i'],
                },
              ]}
              contentDocument={document}
            />
          <h1 style={{ fontFamily: 'Roboto'; }}>Will render with Roboto</h1>
          </Fragment>
        }
      }
    </FrameContextConsumer>
  </Frame>
  <h1 style={{ fontFamily: 'Roboto'; }}>Will not render with Roboto</h1>
</Fragment>
);

Of course, you don't have to use react-frame-component. That's just my preferred method.

@Reklino
Copy link
Author

Reklino commented Dec 11, 2020

Hey @jakewtaylor 👋 . Any chance we could merge this one in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants