Skip to content

Commit 5342836

Browse files
chore: remove react-jss (#5907)
BREAKING CHANGE: UI5 Web Components for React is no longer relying on `react-jss` internally, hence the dependency is now removed and the `react-jss` ThemeProvider is no longer rendered as part of our `ThemeProvider`. If you are relying on `react-jss` in your application, please make sure to render your own `react-jss` ThemeProvider. BREAKING CHANGE: The `useResponsiveContentPadding` has been removed. You can achieve the same look and feel by using the [responsive content padding from Common CSS](https://sap.github.io/ui5-webcomponents-react/main/?path=/docs/knowledge-base-common-css--docs#content-paddings).
1 parent 2da6d60 commit 5342836

File tree

22 files changed

+110
-539
lines changed

22 files changed

+110
-539
lines changed

cypress.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export default defineConfig({
99
'**/src/interfaces/*',
1010
'**/src/enums/*',
1111
'**/*.stories.tsx',
12-
'**/*.jss.ts',
1312
'**/*.test.{ts,tsx}',
1413
'**/node_modules/**',
1514
'packages/*/src/index.ts',

docs/MigrationGuide.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,35 @@ or the [changelog](?path=/docs/change-log--page)._
1717

1818
<TableOfContent headingSelector="h2" />
1919

20+
## General changes
21+
22+
### Removed `react-jss`
23+
24+
UI5 Web Components for React is no longer relying on `react-jss` internally, hence the dependency is now removed and the `react-jss` ThemeProvider is no longer rendered as part of our `ThemeProvider`.
25+
If you are relying on `react-jss` in your application, please make sure to render your own `react-jss` ThemeProvider:
26+
27+
```tsx
28+
import { ThemeProvider } from '@ui5/webcomponents-react';
29+
import { ThemingParameters } from '@ui5/webcomponents-react-base';
30+
import { ThemeProvider as ReactJssThemeProvider } from 'react-jss';
31+
32+
function MyRootComponent() {
33+
return (
34+
<ThemeProvider>
35+
<ReactJssThemeProvider theme={ThemingParameters}>{/* your app content goes here */}</ReactJssThemeProvider>
36+
</ThemeProvider>
37+
);
38+
}
39+
```
40+
41+
## Removed hooks
42+
43+
### `useResponsiveContentPadding`
44+
45+
The `useResponsiveContentPadding` hook has been removed.
46+
You can now apply responsive content paddings by applying the `sap-content-paddings-container` class from `@sap-ui/common-css` package to your element.
47+
You can find a more detailed documentation [here](https://sap.github.io/ui5-webcomponents-react/main/?path=/docs/knowledge-base-common-css--docs#content-paddings).
48+
2049
## Replaced Components
2150

2251
### AnalyticalCard

docs/knowledge-base/CommonCSS.mdx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Footer, TableOfContent } from '@sb/components';
2+
import { Meta } from '@storybook/blocks';
3+
import { Link, MessageStrip } from '@ui5/webcomponents-react';
4+
5+
<Meta title="Common CSS" />
6+
7+
# Using Common CSS in your application
8+
9+
<TableOfContent />
10+
11+
We recommend using the [@sap-ui/common-css](https://www.npmjs.com/package/@sap-ui/common-css) package for applying common styling blocks based on SAP Fiori Design Guidelines.
12+
13+
<MessageStrip
14+
hideCloseButton
15+
children={
16+
<>
17+
This documentation is only showing a few samples which we consider to be useful for applications using UI5 Web
18+
Components for React. You can find the full documentation for SAP UI Common CSS{' '}
19+
<Link href="https://sap.github.io/fundamental-styles/?path=/docs/common-css-introduction--docs">here</Link>.
20+
</>
21+
}
22+
></MessageStrip>
23+
24+
<br />
25+
<br />
26+
27+
## Content Paddings
28+
29+
[Full Documentation](https://sap.github.io/fundamental-styles/?path=/docs/common-css-content-paddings--docs)
30+
31+
You can import the content paddings by adding the following import to your project:
32+
33+
```ts
34+
import '@sap-ui/common-css/dist/sap-content-paddings.css';
35+
```
36+
37+
### Responsive Content Paddings
38+
39+
You can apply a dynamic content padding for your element by applying the following classes to your HTML:
40+
41+
```html
42+
<div class="sap-container-type-inline-size">
43+
<div class="sap-content-paddings-container">I will have a responsive content padding</div>
44+
</div>
45+
```
46+
47+
<Footer />

docs/knowledge-base/Public-Utils.mdx

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,4 @@ The `useI18nBundle` hook can be used for adding internationalization to your app
105105
The `useViewportRange` hook is a utility hook based on the `Device.getCurrentRange()` and `Device.attachMediaHandler` API.
106106
It will always return a string with the name of the currently active range.
107107

108-
### `useResponsiveContentPadding`
109-
110-
<Source code={`import { useResponsiveContentPadding } from '@ui5/webcomponents-react-base';`} />
111-
112-
The `useResponsiveContentPadding` hook is a hook generating a style class or a tuple containing the style class and the current range if `returnRangeString` is set to `true`.
113-
It adds `padding-left` and `padding-right` corresponding to the range (retrieved with `Device.getCurrentRange()`) of the element.
114-
115-
```jsx
116-
const YourComponent = (props) => {
117-
const elementRef = useRef(null);
118-
const responsivePaddingClass = useResponsiveContentPadding(elementRef.current);
119-
return (
120-
<div ref={elementRef} className={responsivePaddingClass}>
121-
Content
122-
</div>
123-
);
124-
};
125-
```
126-
127-
```js
128-
// returns the style class as string
129-
const responsivePaddingClass = useResponsiveContentPadding(elementRef.current);
130-
// returns a tuple - the first entry is the style class, the second the current range string
131-
const [responsivePaddingClass, currentRange] = useResponsiveContentPadding(elementRef.current, true);
132-
```
133-
134108
<Footer />

docs/knowledge-base/ServerSideRendering.mdx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,22 @@ We have templates available for both the pages and the app router.
2626

2727
In case you already have an existing Next.js project and want to add UI5 Web Components for React to it, you first need to follow our [general Getting Started Guide](https://sap.github.io/ui5-webcomponents-react/?path=/docs/getting-started--docs#add-ui5webcomponents-react-to-an-existing-app).
2828

29-
As UI5 Web Components for React is using `react-jss` internally, you need to apply some changes to your `_app` and `_document` file (in case you are using the pages router).
30-
You can copy these changes either from the official [next.js-react-jss example](https://github.com/vercel/next.js/tree/canary/examples/with-react-jss) or from our [pages router template](https://github.com/SAP/ui5-webcomponents-react/tree/main/examples/nextjs-pages).
29+
For a better SSR support, we recommend importing our stylesheet bundle inside the `_app` file or the root layout (depending on whether you are using the pages or the app router) and set the `staticCssInjected` prop on our `ThemeProvider`:
30+
31+
```tsx
32+
import '@ui5/webcomponents-react/styles.css';
33+
34+
export default function AppOrRootLayout() {
35+
// ...
36+
return (
37+
// ...
38+
<ThemeProvider staticCssInjected>
39+
// ...
40+
</ThemeProvider>
41+
)
42+
}
43+
```
3144

32-
In case you are already using the app router, you can copy the `react-jss` setup from the `app/CssRegistry.tsx` in our [app router template](https://github.com/SAP/ui5-webcomponents-react/tree/main/examples/nextjs-app). Make sure to add this component to your root layout!
3345

3446
### Common Pitfalls
3547

docs/knowledge-base/Styling.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,8 @@ const TableComponent = () => {
193193

194194
</details>
195195

196+
## Common CSS
197+
198+
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).
199+
196200
<Footer />

examples/nextjs-app/app/CssRegistry.tsx

Lines changed: 0 additions & 24 deletions
This file was deleted.

examples/nextjs-app/app/layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import '@ui5/webcomponents-react/styles.css';
22
import './globals.css';
33
import { AppShell } from '@/app/components/AppShell';
4-
import { CssRegistry } from '@/app/CssRegistry';
4+
import { ThemeProvider } from '@ui5/webcomponents-react';
55

66
export default function RootLayout({ children }: { children: React.ReactNode }) {
77
return (
@@ -19,9 +19,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })
1919
</head>
2020
<body>
2121
<div className="appShell">
22-
<CssRegistry>
22+
<ThemeProvider staticCssInjected>
2323
<AppShell>{children}</AppShell>
24-
</CssRegistry>
24+
</ThemeProvider>
2525
</div>
2626
</body>
2727
</html>

examples/nextjs-pages/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## UI5 Web Components React - Next.js Pages Router Example
22

33
This example shows how to use the [Next.js](https://nextjs.org/) Pages Router with UI5 Web Components for React.
4-
It includes the required adjustments in `pages/_app.tsx` and `pages/_document.tsx` as well as a very simple Todo
4+
It includes the required adjustments in `pages/_app.tsx` as well as a very simple Todo
55
App.
66

77
## How to use this template

examples/nextjs-pages/pages/_app.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@ import '../styles/globals.css';
44
import { ThemeProvider } from '@ui5/webcomponents-react/ssr';
55
import type { AppProps } from 'next/app';
66
import Head from 'next/head';
7-
import { useEffect } from 'react';
87
import { AppShell } from '../components/AppShell';
98

109
export default function App({ Component, pageProps }: AppProps) {
11-
useEffect(() => {
12-
const style = document.getElementById('server-side-styles');
13-
if (style) {
14-
style.parentNode?.removeChild(style);
15-
}
16-
}, []);
17-
1810
return (
1911
<>
2012
<Head>

examples/nextjs-pages/pages/_document.tsx

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/base/src/hooks/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useI18nBundle } from './useI18nBundle.js';
33
import { useIsomorphicId } from './useIsomorphicId.js';
44
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js';
55
import { useIsRTL } from './useIsRTL.js';
6-
import { useResponsiveContentPadding } from './useResponsiveContentPadding.js';
76
import { useStylesheet } from './useStylesheet.js';
87
import { useSyncRef } from './useSyncRef.js';
98
import { useViewportRange } from './useViewportRange.js';
@@ -12,7 +11,6 @@ export {
1211
useI18nBundle,
1312
useIsomorphicLayoutEffect,
1413
useIsRTL,
15-
useResponsiveContentPadding,
1614
useSyncRef,
1715
useViewportRange,
1816
useIsomorphicId,

packages/base/src/hooks/useResponsiveContentPadding.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

packages/main/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"@tanstack/react-virtual": "~3.5.0",
5656
"@ui5/webcomponents-react-base": "workspace:~",
5757
"clsx": "2.1.1",
58-
"react-jss": "^10.10.0",
5958
"react-table": "7.8.0"
6059
},
6160
"peerDependencies": {

packages/main/src/components/ThemeProvider/ThemeProvider.cy.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { setTheme } from '@ui5/webcomponents-base/dist/config/Theme.js';
2-
import { ThemingParameters } from '@ui5/webcomponents-react-base';
3-
import { useTheme } from 'react-jss';
42

53
describe('ThemeProvider', () => {
64
it('Provides Correct Context', () => {
75
const InnerComponent = () => {
8-
const theme = useTheme();
9-
expect(JSON.stringify(theme)).equal(JSON.stringify(ThemingParameters));
10-
116
return (
127
<button
138
onClick={() => {

packages/main/src/components/ThemeProvider/index.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@
22

33
import { getTheme } from '@ui5/webcomponents-base/dist/config/Theme.js';
44
import { attachThemeLoaded, detachThemeLoaded } from '@ui5/webcomponents-base/dist/theming/ThemeLoaded.js';
5-
import {
6-
StyleStore,
7-
ThemingParameters,
8-
useIsomorphicId,
9-
useIsomorphicLayoutEffect,
10-
useStylesheet
11-
} from '@ui5/webcomponents-react-base';
5+
import { StyleStore, useIsomorphicId, useIsomorphicLayoutEffect, useStylesheet } from '@ui5/webcomponents-react-base';
126
import type { FC, ReactNode } from 'react';
13-
import { ThemeProvider as ReactJssThemeProvider } from 'react-jss';
147
import { I18nProvider } from '../../internal/I18nProvider.js';
158
import { ModalsProvider } from '../Modals/ModalsProvider.js';
169
import { styleData } from './ThemeProvider.css.js';
@@ -65,9 +58,7 @@ const ThemeProvider: FC<ThemeProviderPropTypes> = (props: ThemeProviderPropTypes
6558
return (
6659
<>
6760
<ThemeProviderStyles />
68-
<ReactJssThemeProvider theme={ThemingParameters}>
69-
<I18nProvider>{withoutModalsProvider ? children : <ModalsProvider>{children}</ModalsProvider>}</I18nProvider>
70-
</ReactJssThemeProvider>
61+
<I18nProvider>{withoutModalsProvider ? children : <ModalsProvider>{children}</ModalsProvider>}</I18nProvider>
7162
</>
7263
);
7364
};

0 commit comments

Comments
 (0)