Skip to content
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

fix: remove CSS @layer rule from static CSS bundle #6430

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/merge-css-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ for (const cssModule of cssModules) {
const componentName = basename(cssModule, '.module.css');

fileContent.push(`/* ${componentName} */`);
fileContent.push(cssContent);
fileContent.push(cssContent.replace('@layer ui5-webcomponents-react{', '').replace(/}$/, ''));
fileContent.push('');
}

Expand Down
8 changes: 0 additions & 8 deletions config/postcss-config-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ export function postcssConfigFactory(packageName) {
cssLayersPlugin(),
postcssModules({
// generateScopedName: '[name]__[local]___[hash:base64:5]',
generateScopedName: function (name, filename, css) {
const file = path.basename(filename, '.module.css');
const i = css.indexOf(`.${name}`);
const lineNumber = css.substring(0, i).split(/[\r\n]/).length;
const hash = stringHash(css).toString(36).substring(0, 5);

return `${file}_${name}_${hash}_${lineNumber}`;
},
getJSON: (cssFileName, json) => {
return null;
},
Expand Down
5 changes: 4 additions & 1 deletion docs/knowledge-base/Styling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ This would then be the result:

## Applying styling via `className` or `style`

Almost all components allow setting `className` or `style` to style the component. For web components, this does **not** mean that styles are inherited by shadow root elements per default.
Almost all components allow setting `className` or `style` for custom styling. For standard elements like `div`, `span`, etc., you can easily override internal CSS properties and values, as our styles are encapsulated in a [CSS layer](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer).
For web components, this does **not** mean that styles are inherited by shadow root elements per default.
Only [inherited CSS properties](https://developer.mozilla.org/en-US/docs/Web/CSS/inheritance#inherited_properties) that are not set inside the shadow root or internally passed properties will change the styles of the internal elements.
Another special case are abstract components like the `SuggestionItem`. The `ui5-suggestion-item` element is mainly there to pass props to the actual component inside the shadow root and is therefore not stylable.

Expand All @@ -114,6 +115,8 @@ Another special case are abstract components like the `SuggestionItem`. The `ui5
By default, the `ThemeProvider` injects the CSS of the components during runtime. If you want to import the CSS bundles explicitly, you can set the `staticCssInjected` prop to `true`.
This approach provides you with control over the order in which CSS files are injected, making it easier to override styles.

Please note that the static CSS is not wrapped inside a [CSS layer](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer). You can use the [`@import` CSS at-rule](https://developer.mozilla.org/en-US/docs/Web/CSS/@import) to achieve that.

- **main** package import: `import '@ui5/webcomponents-react/styles.css'`
- **charts** package import: `import '@ui5/webcomponents-react-charts/styles.css'`

Expand Down
Loading