-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inject component css into the window document #15
Comments
This would be awesome. Not sure how we would achieve this, it kinda needs the style loader to be invoked again to load the styles into the popup. Any ideas? For the moment I use the url to load a page with some styles but it's not great. |
I was able to do this using webpack and some simple DOM manipulation. |
@donnrriz Do you have an example of how you copy the css link into the head of the new window? |
Sorry for my late reply. |
Sorry my message has the following missing |
Sorry for bombarding you , this is my last post unless you want more information. Actually its pretty easy using React, if you just set the url to the address you are using it'll have the css in the head . Then remove the div used to load the React code - which removes all the content from the body, then load the children from props. Would you like a pull request done ? |
@donnrriz no thanks - that's great. Got it working. |
donnrriz, could you please post an example code? I am in the same problem. My react components loose their CSS definitions within the popout |
Here's what I came up with
|
@colshacol Would be interesting to see if that works without a url. |
@marchaos What exactly do you mean? You gotta have a href to get the file. A quick alternative would be getting the Meh, idk. I am much too tired to be prescribing code right now. -_- |
@colshacol I mean a url on the popout itself - not sure it will work with about:blank. You're using popout.html. |
Copying the parent's |
@colshacol : Do we need to do anything specific to make I tried but getting error: |
Combining #15 (comment)
function copyStyles(sourceDoc, targetDoc) {
Array.from(sourceDoc.styleSheets).forEach(styleSheet => {
if (styleSheet.cssRules) { // for <style> elements
const newStyleEl = sourceDoc.createElement('style');
Array.from(styleSheet.cssRules).forEach(cssRule => {
// write the text of each rule into the body of the style element
newStyleEl.appendChild(sourceDoc.createTextNode(cssRule.cssText));
});
targetDoc.head.appendChild(newStyleEl);
} else if (styleSheet.href) { // for <link> elements loading CSS from a URL
const newLinkEl = sourceDoc.createElement('link');
newLinkEl.rel = 'stylesheet';
newLinkEl.href = styleSheet.href;
targetDoc.head.appendChild(newLinkEl);
}
});
}
const App = props => {
return (
<Popout>
{
popoutWindow => {
copyStyles(window.document, popoutWindow.document);
return (
<div>
...
</div>
);
}
}
</Popout>
)
}
``` |
I had success using https://github.com/rmariuzzo/react-new-window. |
Unfortunately react-new-window doesn't work in IE11. |
@msimonian77 We've moved to https://github.com/Microsoft/react-popout-component which has good cross browser support including IE |
@chriddyp Do you know how to make sure that bootstrap glyphicons also work in the popout window. Currently the copyStyles is working but how do I also include fonts such as glyphicons and awesome-font |
Re-wrote copyStyle to include fonts as well
Anyone knows how to include global stylesheets? |
This seems simpler. Is it missing anything? const copyStyles = (src, dest) => {
Array.from(src.styleSheets).forEach(styleSheet => {
dest.head.appendChild(styleSheet.ownerNode.cloneNode(true))
})
Array.from(src.fonts).forEach(font => dest.fonts.add(font))
} |
The module style imports do not seem to be used in the resulting document, it would be a nice if they did.
The text was updated successfully, but these errors were encountered: