-
-
Notifications
You must be signed in to change notification settings - Fork 470
Add shadow-DOM option type for injectType #536
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
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong solution, you don't need style-loader
in this case, just use css-loader
and use toString()
from returned content
@alexander-akait Thanks for reviewing the PR. So the full case see like: import css from './style.css'
// ...
export component; /b/component.tsx import css from './style.css'
// ...
export component;
main.tsx import Main from 'components';
import {render} from 'react-dom'
import getCss from 'style-loader/dist/runtime/injectStyleInScript';
class MyElement extends Element {
constructor() {
super();
const shadowContent = this.attachShadow({ mode: 'open' });
const style = document.createElement('style');
style.innerHTML = getCss();
shadowContent.appendChild(style);
const root = document.createElement('div');
shadowContent.appendChild(root);
render(<Main />, root);
}
} |
run |
@alexander-akait So you mean I can use that see like: import Main from 'components';
import {render} from 'react-dom'
import allCss from 'css-loader/dist/runtime/api';
class MyElement extends Element {
constructor() {
super();
const shadowContent = this.attachShadow({ mode: 'open' });
const style = document.createElement('style');
style.innerHTML = allCss.toString(); // This one?
shadowContent.appendChild(style);
const root = document.createElement('div');
shadowContent.appendChild(root);
render(<Main />, root);
}
} |
No, just use: import Main from 'components';
import {render} from 'react-dom'
import styles from './style.css';
class MyElement extends Element {
constructor() {
super();
const shadowContent = this.attachShadow({ mode: 'open' });
const style = document.createElement('style');
style.innerHTML = styles.toString();
shadowContent.appendChild(style);
const root = document.createElement('div');
shadowContent.appendChild(root);
render(<Main />, root);
}
} |
@alexander-akait Sorry, I don't quite understand the method of use you proposed |
Example above |
Just remove |
I can import the root CSS file see like your provided case. But how to apply nested component styles? |
Sorry, it is not QA services, please use stackoverflow for questions and personal help, we don't need this API, because |
/a/component.tsx import css from './style.css'
const A = () => {
return <div />
}
export default A; /b/component.tsx import css from './style.css'
import A from '../a/component'
const B = () => {
return <div>
<A />
</div>
}
export component;
main.tsx import B from 'b/component';
import {render} from 'react-dom'
import getCss from 'style-loader/dist/runtime/injectStyleInScript';
class MyElement extends Element {
constructor() {
super();
const shadowContent = this.attachShadow({ mode: 'open' });
const style = document.createElement('style');
style.innerHTML = getCss();
shadowContent.appendChild(style);
const root = document.createElement('div');
shadowContent.appendChild(root);
render(<Main />, root);
}
} |
You don't need this API, what is not clear from my answer? Remove |
You mix multiple react component with the one custom component, this is the wrong approach to what you are trying to achieve |
You should not have |
This PR contains a:
Motivation / Use-Case
Extract styles and put into a container, then can injected into the shadow-DOM conainer