Skip to content

Commit 3fa5240

Browse files
committed
docs(Styling): update to latest ui5wc recommendations
1 parent 13ccc8c commit 3fa5240

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

docs/knowledge-base/Styling.mdx

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,44 @@ You can apply CSS variables, use the `::part` pseudo-element selectors, or apply
1919
Components currently only available in the `ui5/webcomponents-react` repo, are not necessarily web components. For these kind of components you can follow the standard styling approach of React.
2020

2121
<MessageStrip
22-
design={MessageStripDesign.Critical}
23-
hideCloseButton
24-
children="While it's easily possible targeting DOM elements and CSS classes of components without a shadow root, modifying internal structures or styles is not officially supported and may break with future updates. Use such changes carefully."
22+
design={MessageStripDesign.Critical}
23+
hideCloseButton
24+
children="While it's easily possible targeting DOM elements and CSS classes of components without a shadow root, modifying internal structures or styles is not officially supported and may break with future updates. Use such changes carefully."
2525
/>
2626

2727
## Scrollbars
2828

2929
`@ui5/webcomponents` components come with globally applied scrollbar styles.
3030
If you want to opt-out of this behavior, you can add the `.ui5-content-native-scrollbars` class to the `body` of the page. You can find out more about this in the [ui5/webcomponents documentation](https://ui5.github.io/webcomponents/docs/advanced/scrollbars-customization/).
3131

32-
## Style your own components
32+
## Changing CSS Variables
33+
34+
You can override SAP theming CSS variables on specific web component selectors to customize their appearance:
35+
36+
```css
37+
[ui5-button] {
38+
--sapButton_TextColor: purple;
39+
}
40+
```
3341

34-
It's quite likely you have to create some custom components when you are building an app.
35-
In order to reuse our central styling approach, you can import the `ThemingParameters` that contain the various CSS variables used in our theming, or use the CSS variables directly.
42+
<MessageStrip
43+
design={MessageStripDesign.Information}
44+
hideCloseButton
45+
children="Whenever possible, override CSS variables through the SAP UI Theme Designer for consistent updates across all components."
46+
/>
3647

37-
A full list of all supported CSS Variables can be found [here](https://github.com/UI5/webcomponents-react/blob/main/packages/base/src/styling/ThemingParameters.ts)
38-
or in the [theming-base-content](https://github.com/SAP/theming-base-content/tree/master/content/Base/baseLib) repo.
48+
## Style your own components
3949

40-
You can then create a custom component by following this recipe:
50+
When building custom components, use SAP CSS variables directly to stay consistent with the Fiori design system.
51+
A full list of all supported CSS variables can be found in the [theming-base-content](https://github.com/SAP/theming-base-content/tree/master/content/Base/baseLib) repo.
4152

4253
```tsx
43-
import { ThemingParameters } from '@ui5/webcomponents-react-base/ThemingParameters';
4454
import './MyCustomElement.css';
4555

4656
export const MyCustomElement = () => {
4757
return (
4858
<div className="containerCustomElement">
49-
<span style={{ color: ThemingParameters.sapNegativeColor, fontSize: ThemingParameters.sapFontLargeSize }}>
50-
My Text
51-
</span>
59+
<span style={{ color: 'var(--sapNegativeColor)', fontSize: 'var(--sapFontLargeSize)' }}>My Text</span>
5260
</div>
5361
);
5462
};
@@ -65,6 +73,12 @@ export const MyCustomElement = () => {
6573
}
6674
```
6775

76+
If you need to access CSS variable values in JavaScript, you can use [ThemingParameters](https://ui5.github.io/webcomponents-react/v2/?path=/docs/knowledge-base-public-utils--docs#theming-parameters) as well:
77+
78+
```tsx
79+
<span style={{ color: ThemingParameters.sapNegativeColor, fontSize: ThemingParameters.sapFontLargeSize }}>My Text</span>
80+
```
81+
6882
This would then be the result:
6983

7084
<ThemeProvider>
@@ -76,7 +90,7 @@ This would then be the result:
7690
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).
7791
For web components, this does **not** mean that styles are inherited by shadow root elements per default.
7892
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.
79-
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.
93+
Another special case are [abstract](http://localhost:6007/?path=/docs/knowledge-base-faq--docs#what-are-abstract-ui5-web-components) 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.
8094

8195
## Explicitly import CSS bundles
8296

@@ -142,6 +156,16 @@ function MyComponent() {
142156

143157
</details>
144158

159+
## CSS Custom States
160+
161+
Some components expose custom states that you can target with the `:state()` pseudo-class for conditional styling:
162+
163+
```css
164+
[ui5-toolbar-item]:state(overflowed) {
165+
flex-direction: column;
166+
}
167+
```
168+
145169
## Common CSS
146170

147171
For applying common styling blocks based on SAP Fiori Design Guidelines, we recommend using the [@sap-ui/common-css](https://www.npmjs.com/package/@sap-ui/common-css) package. You can find out more about this [here](?path=/docs/knowledge-base-common-css--docs).

0 commit comments

Comments
 (0)