Skip to content

Commit 9a611fd

Browse files
feat(ThemeProvider): apply Fiori scrollbar styling to all scroll containers (#5978)
BREAKING CHANGE: the `GlobalStyleClasses` enum has been removed --------- Co-authored-by: Lukas Harbarth <[email protected]>
1 parent 2cf6183 commit 9a611fd

File tree

9 files changed

+37
-85
lines changed

9 files changed

+37
-85
lines changed

docs/MigrationGuide.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ function MyRootComponent() {
3838
}
3939
```
4040

41+
### Scrollbar Styling
42+
43+
Starting with v2, the `ThemeProvider` will apply the Fiori styles to all scrollbars on the page.
44+
If you have previously used our global style classes `sapScrollBar` or `inheritingSapScrollBar`, you can now remove them.
45+
46+
To opt-out of this behavior, you can add the `.ui5-content-native-scrollbars` class to the element to prevent the scrollbar styling from being applied.
47+
48+
More details can be found in our [Styling Knowledge Base](?path=/docs/knowledge-base-styling--docs#scrollbars).
49+
4150
## Removed hooks
4251

4352
### `useResponsiveContentPadding`

docs/knowledge-base/Styling.mdx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,20 @@ You can change CSS Variables on any level - in the head, or on every single elem
3737
A full list of all supported CSS Variables can be found [here](https://github.com/SAP/ui5-webcomponents-react/blob/main/packages/base/src/styling/ThemingParameters.ts)
3838
or in the [theming-base-content](https://github.com/SAP/theming-base-content/tree/master/content/Base/baseLib) repo.
3939

40-
## Reuse global style classes
40+
## Scrollbars
4141

42-
The `ThemeProvider` component is offering global css classes that can be reused in your applications code to help you to achieve a Fiori look-and-feel.
43-
All globally available style classes are tracked in the `GlobalStyleClasses` enum which can be imported from `import { GlobalStyleClasses } from "@ui5/webcomponents-react";`.
44-
45-
| CSS Class | Description |
46-
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
47-
| `sapScrollBar` | If added to an container that supports scrolling, the scrollbar will be styled according to Fiori guidelines. |
48-
| `inheritingSapScrollBar` | If added to a container, the scollbars of the container and of all of its children will be styled according to Fiori guidelines. |
42+
Rendering our `ThemeProvider` will apply the Fiori styles to all scrollbars on the page.
43+
If you want to opt-out of this behavior, you can add the `.ui5-content-native-scrollbars` class to the respective element to prevent the scrollbar styling from being applied.
4944

5045
<MessageStrip
46+
design={MessageStripDesign.Information}
5147
hideCloseButton
52-
style={{ marginBlockEnd: '1rem' }}
53-
children="With our next major release (v2.0.0), both style classes will be removed as then the SAP scrollbar will be used per
54-
default for the whole application."
48+
children="Due to the limited configuration options for scrollbars, you must apply this class to each scroll-container element individually."
5549
/>
5650

57-
### Use default browser scrollbar
58-
59-
Some components like the `ObjectPage`, `DynamicPage` and `AnalyticalTable` use the CSS class `sapScrollBar` by default. To prevent components from using the custom scrollbar, you can pass `data-native-scrollbar` as prop.
51+
```tsx
52+
<ObjectPage className="ui5-content-native-scrollbars">{children}</ObjectPage>
53+
```
6054

6155
## Style your own components
6256

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ import {
3131
AnalyticalTableSelectionBehavior,
3232
AnalyticalTableSelectionMode,
3333
AnalyticalTableSubComponentsBehavior,
34-
AnalyticalTableVisibleRowCountMode,
35-
GlobalStyleClasses
34+
AnalyticalTableVisibleRowCountMode
3635
} from '../../enums/index.js';
3736
import {
3837
COLLAPSE_NODE,
@@ -655,9 +654,9 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
655654

656655
const tableClasses = clsx(
657656
classNames.table,
658-
GlobalStyleClasses.sapScrollBar,
659657
withNavigationHighlight && classNames.hasNavigationIndicator,
660-
showVerticalEndBorder && classNames.showVerticalEndBorder
658+
showVerticalEndBorder && classNames.showVerticalEndBorder,
659+
className?.includes('ui5-content-native-scrollbars') && 'ui5-content-native-scrollbars'
661660
);
662661

663662
const handleOnLoadMore = (e) => {
@@ -746,7 +745,6 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
746745
data-per-page={internalVisibleRowCount}
747746
data-component-name="AnalyticalTableContainer"
748747
ref={tableRef}
749-
data-native-scrollbar={props['data-native-scrollbar']}
750748
className={tableClasses}
751749
>
752750
<div className={classNames.tableHeaderBackgroundElement} />
@@ -837,9 +835,9 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
837835
tableRef={tableRef}
838836
handleVerticalScrollBarScroll={handleVerticalScrollBarScroll}
839837
ref={verticalScrollBarRef}
840-
data-native-scrollbar={props['data-native-scrollbar']}
841838
scrollContainerRef={scrollContainerRef}
842839
parentRef={parentRef}
840+
nativeScrollbar={className?.includes('ui5-content-native-scrollbars')}
843841
/>
844842
)}
845843
</FlexBox>

packages/main/src/components/AnalyticalTable/scrollbars/VerticalScrollbar.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ThemingParameters, useStylesheet, useSyncRef } from '@ui5/webcomponents
22
import { clsx } from 'clsx';
33
import type { MutableRefObject, RefObject } from 'react';
44
import { forwardRef, useEffect, useRef } from 'react';
5-
import { FlexBoxDirection, GlobalStyleClasses } from '../../../enums/index.js';
5+
import { FlexBoxDirection } from '../../../enums/index.js';
66
import { FlexBox } from '../../FlexBox/index.js';
77
import { classNames, styleData } from './VerticalScrollbar.module.css.js';
88

@@ -11,14 +11,21 @@ interface VerticalScrollbarProps {
1111
tableRef: RefObject<any>;
1212
handleVerticalScrollBarScroll: any;
1313
tableBodyHeight: number;
14-
'data-native-scrollbar'?: any;
1514
scrollContainerRef: MutableRefObject<HTMLDivElement>;
1615
parentRef: MutableRefObject<HTMLDivElement>;
16+
nativeScrollbar: boolean;
1717
}
1818

1919
export const VerticalScrollbar = forwardRef<HTMLDivElement, VerticalScrollbarProps>((props, ref) => {
20-
const { internalRowHeight, tableRef, handleVerticalScrollBarScroll, tableBodyHeight, scrollContainerRef, parentRef } =
21-
props;
20+
const {
21+
internalRowHeight,
22+
tableRef,
23+
handleVerticalScrollBarScroll,
24+
tableBodyHeight,
25+
scrollContainerRef,
26+
nativeScrollbar,
27+
parentRef
28+
} = props;
2229
const [componentRef, containerRef] = useSyncRef(ref);
2330
const scrollElementRef = useRef(null);
2431
useStylesheet(styleData, VerticalScrollbar.displayName);
@@ -58,8 +65,7 @@ export const VerticalScrollbar = forwardRef<HTMLDivElement, VerticalScrollbarPro
5865
height: tableRef.current ? `${tableBodyHeight}px` : '0'
5966
}}
6067
onScroll={handleVerticalScrollBarScroll}
61-
data-native-scrollbar={props['data-native-scrollbar']}
62-
className={`${GlobalStyleClasses.sapScrollBar} ${classNames.scrollbar}`}
68+
className={clsx(classNames.scrollbar, nativeScrollbar && 'ui5-content-native-scrollbars')}
6369
data-component-name="AnalyticalTableVerticalScrollbar"
6470
>
6571
<div

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useI18nBundle, useStylesheet, useSyncRef } from '@ui5/webcomponents-rea
1010
import { clsx } from 'clsx';
1111
import type { ReactElement, ReactNode } from 'react';
1212
import { Children, forwardRef, Fragment, isValidElement, useCallback, useEffect, useState } from 'react';
13-
import { FlexBoxDirection, GlobalStyleClasses } from '../../enums/index.js';
13+
import { FlexBoxDirection } from '../../enums/index.js';
1414
import { ALL, LIST_NO_DATA } from '../../i18n/i18n-defaults.js';
1515
import { MessageViewContext } from '../../internal/MessageViewContext.js';
1616
import type { CommonProps } from '../../types/index.js';
@@ -145,12 +145,7 @@ const MessageView = forwardRef<MessageViewDomRef, MessageViewPropTypes>((props,
145145
setListFilter(e.detail.selectedItems.at(0).dataset.key as never);
146146
};
147147

148-
const outerClasses = clsx(
149-
classNames.container,
150-
GlobalStyleClasses.sapScrollBar,
151-
className,
152-
selectedMessage && classNames.showDetails
153-
);
148+
const outerClasses = clsx(classNames.container, className, selectedMessage && classNames.showDetails);
154149

155150
return (
156151
<div ref={componentRef} {...rest} className={outerClasses}>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { clsx } from 'clsx';
1414
import type { CSSProperties, ReactElement, ReactNode } from 'react';
1515
import { cloneElement, forwardRef, isValidElement, useCallback, useEffect, useMemo, useRef, useState } from 'react';
16-
import { GlobalStyleClasses, ObjectPageMode } from '../../enums/index.js';
16+
import { ObjectPageMode } from '../../enums/index.js';
1717
import { addCustomCSSWithScoping } from '../../internal/addCustomCSSWithScoping.js';
1818
import { safeGetChildrenArray } from '../../internal/safeGetChildrenArray.js';
1919
import { useObserveHeights } from '../../internal/useObserveHeights.js';
@@ -549,7 +549,6 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
549549

550550
const objectPageClasses = clsx(
551551
classNames.objectPage,
552-
GlobalStyleClasses.sapScrollBar,
553552
className,
554553
mode === ObjectPageMode.IconTabBar && classNames.iconTabBarMode
555554
);

packages/main/src/components/ThemeProvider/ThemeProvider.css

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@import '../../themes/sap_horizon_hcb.css';
1515
@import '../../themes/sap_horizon_hcw.css';
1616

17-
.inheritingSapScrollBar *:not([data-native-scrollbar]) {
17+
:not(.ui5-content-native-scrollbars) {
1818
&::-webkit-scrollbar {
1919
background-color: var(--sapScrollBar_TrackColor);
2020
-webkit-border-start: var(--_ui5wcr_Scrollbar_Border);
@@ -49,41 +49,3 @@
4949
width: var(--sapScrollBar_Dimension);
5050
}
5151
}
52-
53-
.sapScrollBar:not([data-native-scrollbar]) {
54-
&::-webkit-scrollbar {
55-
background-color: var(--sapScrollBar_TrackColor);
56-
-webkit-border-start: var(--_ui5wcr_Scrollbar_Border);
57-
}
58-
59-
&::-webkit-scrollbar-thumb {
60-
border-radius: var(--_ui5wcr_Scrollbar_BorderRadius);
61-
background-color: var(--sapScrollBar_FaceColor);
62-
}
63-
64-
&::-webkit-scrollbar-corner {
65-
background-color: var(--sapScrollBar_TrackColor);
66-
}
67-
68-
&::-webkit-scrollbar-thumb {
69-
&:hover {
70-
background-color: var(--sapScrollBar_Hover_FaceColor);
71-
}
72-
73-
&:horizontal {
74-
height: var(--sapScrollBar_Dimension);
75-
}
76-
77-
&:vertical {
78-
width: var(--sapScrollBar_Dimension);
79-
}
80-
}
81-
82-
&::-webkit-scrollbar:horizontal {
83-
height: var(--sapScrollBar_Dimension);
84-
}
85-
86-
&::-webkit-scrollbar:vertical {
87-
width: var(--sapScrollBar_Dimension);
88-
}
89-
}

packages/main/src/enums/GlobalStyleClasses.ts

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

packages/main/src/enums/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export * from './FlexBoxAlignItems.js';
1313
export * from './FlexBoxDirection.js';
1414
export * from './FlexBoxJustifyContent.js';
1515
export * from './FlexBoxWrap.js';
16-
export * from './GlobalStyleClasses.js';
1716
export * from './GridPosition.js';
1817
export * from './IndicationColor.js';
1918
export * from './LoaderType.js';

0 commit comments

Comments
 (0)