Skip to content

Commit

Permalink
fix: remove CSS @layer rule from static CSS bundle (#6430)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas742 authored Oct 2, 2024
1 parent 4bcf334 commit b2942f8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
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

0 comments on commit b2942f8

Please sign in to comment.