Skip to content

Commit 8bcfab6

Browse files
authoredApr 17, 2024··
docs: refactor components and example to use css (modules) instead of react-jss (#5721)
1 parent 3afca47 commit 8bcfab6

File tree

7 files changed

+41
-83
lines changed

7 files changed

+41
-83
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.tableContainer {
2+
margin-top: 25px;
3+
4+
table {
5+
margin-top: 0 !important;
6+
}
7+
}
8+
9+
.strip {
10+
margin-bottom: 10px;
11+
}

‎.storybook/components/ArgTypesWithNote.tsx

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
import { ArgTypes } from '@storybook/blocks';
22
import { MessageStrip, MessageStripDesign } from '@ui5/webcomponents-react';
3-
import React, { ComponentProps, ReactNode, useEffect, useRef } from 'react';
4-
import { createUseStyles } from 'react-jss';
5-
6-
const useStyles = createUseStyles({
7-
tableContainer: {
8-
marginTop: '25px',
9-
'& table': {
10-
marginTop: '0 !important'
11-
}
12-
},
13-
strip: { marginBottom: '10px' }
14-
});
3+
import React, { ComponentProps, ReactNode } from 'react';
4+
import classes from './ArgTypesWithNote.module.css';
155

166
interface ArgTypesWithNotePropTypes {
177
hideHTMLPropsNote?: boolean;
@@ -25,7 +15,6 @@ interface ArgTypesWithNotePropTypes {
2515

2616
export function ArgTypesWithNote(props: ComponentProps<typeof ArgTypes> & ArgTypesWithNotePropTypes) {
2717
const { hideHTMLPropsNote, noteText, ...rest } = props;
28-
const classes = useStyles();
2918

3019
if (hideHTMLPropsNote) {
3120
return <ArgTypes {...rest} />;

‎docs/knowledge-base/Styling.mdx

+17-24
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Footer, TableOfContent } from '@sb/components';
1313
## Styling UI5 Web Components for React components
1414

1515
You can change the appearance of the Web Components by using [CSS Variables](https://www.w3schools.com/Css/css3_variables.asp).
16-
Per default, we are injecting the Fiori 3 theme parameters as CSS Variables into the `<head>`.
16+
Per default, we are injecting the Horizon theme parameters as CSS Variables into the `<head>`.
1717
For example, if you want to change the color of all texts that use the `--sapTextColor` variable, you can create an additional `style` tag with the following content:
1818

1919
```html
@@ -60,11 +60,7 @@ Some components like the `ObjectPage`, `DynamicPage` and `AnalyticalTable` use t
6060
## Style your own components
6161

6262
It's quite likely you have to create some custom components when you are building an app.
63-
In order to reuse our central styling approach, you can import the `ThemingParameters` that contain the various CSS variables used in our theming.
64-
65-
If you want to style your components with the `react-jss` syntax, you can use the `createUseStyles` styling hook.
66-
`react-jss` comes already as a dependency of `@ui5/webcomponents-react` to your project - but we recommend adding it to your `package.json` as well.
67-
**Please make sure you are installing `"react-jss": "^10.0.0"`**. Previous versions of this library won't work correctly together with our library.
63+
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.
6864

6965
<MessageStrip
7066
design={MessageStripDesign.Information}
@@ -85,28 +81,14 @@ If you want to style your components with the `react-jss` syntax, you can use th
8581

8682
You can then create a custom component by following this recipe:
8783

88-
```jsx
84+
```tsx
8985
import React from 'react';
90-
import { createUseStyles } from 'react-jss';
9186
import { ThemingParameters } from '@ui5/webcomponents-react-base';
87+
import './MyCustomElement.css';
9288

93-
const styles = {
94-
container: {
95-
backgroundColor: ThemingParameters.sapBackgroundColor,
96-
fontFamily: ThemingParameters.sapFontFamily,
97-
height: '50px',
98-
display: 'flex',
99-
justifyContent: 'center',
100-
alignItems: 'center'
101-
}
102-
};
103-
104-
const useStyles = createUseStyles(styles, { name: 'MyCustomElement' });
105-
106-
const MyCustomElement = () => {
107-
const classes = useStyles();
89+
export const MyCustomElement = () => {
10890
return (
109-
<div className={classes.container}>
91+
<div className="containerCustomElement">
11092
<span style={{ color: ThemingParameters.sapNegativeColor, fontSize: ThemingParameters.sapFontLargeSize }}>
11193
My Text
11294
</span>
@@ -115,6 +97,17 @@ const MyCustomElement = () => {
11597
};
11698
```
11799

100+
```css
101+
.containerCustomElement {
102+
background-color: var(--sapBackgroundColor);
103+
font-family: var(--sapFontFamily);
104+
height: 50px;
105+
display: flex;
106+
justify-content: center;
107+
align-items: center;
108+
}
109+
```
110+
118111
This would then be the result:
119112

120113
<ThemeProvider>

‎docs/styling/MyCustomElement.css

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.containerCustomElement {
2+
background-color: var(--sapBackgroundColor);
3+
font-family: var(--sapFontFamily);
4+
height: 50px;
5+
display: flex;
6+
justify-content: center;
7+
align-items: center;
8+
}

‎docs/styling/MyCustomElement.jsx

-30
This file was deleted.

‎docs/styling/MyCustomElement.tsx

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
import React from 'react';
2-
import { createUseStyles } from 'react-jss';
32
import { ThemingParameters } from '@ui5/webcomponents-react-base';
4-
5-
const styles = {
6-
container: {
7-
backgroundColor: ThemingParameters.sapBackgroundColor,
8-
fontFamily: ThemingParameters.sapFontFamily,
9-
height: '50px',
10-
display: 'flex',
11-
justifyContent: 'center',
12-
alignItems: 'center'
13-
}
14-
};
15-
16-
const useStyles = createUseStyles(styles, { name: 'MyCustomElement' });
3+
import './MyCustomElement.css';
174

185
export const MyCustomElement = () => {
19-
const classes = useStyles();
206
return (
21-
<div className={classes.container}>
7+
<div className="containerCustomElement">
228
<span style={{ color: ThemingParameters.sapNegativeColor, fontSize: ThemingParameters.sapFontLargeSize }}>
239
My Text
2410
</span>

‎tsconfig.node.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"include": [
1111
"vite.config.ts",
1212
".storybook",
13+
"docs",
1314
"packages/**/*.stories.tsx",
1415
"packages/cypress-commands/CommandsAndQueries.tsx"
1516
]

0 commit comments

Comments
 (0)
Please sign in to comment.