Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Dynamic & ObjectPage): migrate shared components from react-jss to css modules #5700

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.container {
position: absolute;
inset-inline-start: 50%;

&:before,
&:after {
content: '';
position: absolute;
width: 4rem;
inset-block-start: 50%;
height: 0.0625rem;
}

&:before {
inset-inline-end: 100%;
background-image: linear-gradient(to left, var(--sapObjectHeader_BorderColor), transparent);
}

&:after {
inset-inline-start: 100%;
background-image: linear-gradient(to right, var(--sapObjectHeader_BorderColor), transparent);
}
}

.anchorBarActionButton {
--_ui5wcr_anchor-btn-center: calc((var(--_ui5_button_base_min_width) - var(--sapButton_BorderWidth)) / 2);
position: absolute;
inset-block-start: calc(-1 * var(--_ui5wcr_anchor-btn-center));
inset-inline-start: calc(50% - var(--_ui5wcr_anchor-btn-center));
z-index: 3;

&:not([pressed]) {
background-color: var(--sapObjectHeader_Background);
}
}

.anchorBarActionButtonExpandable {
+ .anchorBarActionButtonPinnable {
inset-inline-start: calc(50% - var(--_ui5wcr_anchor-btn-center) + 1rem);
}
}

.anchorBarActionPinnableAndExpandable {
&.anchorBarActionButtonExpandable {
inset-inline-start: calc(50% - var(--_ui5wcr_anchor-btn-center) - 1rem);
}
}
63 changes: 9 additions & 54 deletions packages/main/src/components/DynamicPageAnchorBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import iconPushPin from '@ui5/webcomponents-icons/dist/pushpin-off.js';
import iconArrowDown from '@ui5/webcomponents-icons/dist/slim-arrow-down.js';
import iconArrowUp from '@ui5/webcomponents-icons/dist/slim-arrow-up.js';
import { enrichEventWithDetails, ThemingParameters, useI18nBundle } from '@ui5/webcomponents-react-base';
import { enrichEventWithDetails, useI18nBundle, useStylesheet } from '@ui5/webcomponents-react-base';
import { clsx } from 'clsx';
import React, { forwardRef, useCallback, useEffect, useRef } from 'react';
import type { CSSProperties } from 'react';
import { createUseStyles } from 'react-jss';
import React, { forwardRef, useCallback, useEffect, useRef } from 'react';
import { COLLAPSE_HEADER, EXPAND_HEADER, PIN_HEADER, UNPIN_HEADER } from '../../i18n/i18n-defaults.js';
import { cssVarVersionInfoPrefix } from '../../internal/utils.js';
import type { CommonProps } from '../../types/index.js';
import { Button, ToggleButton } from '../../webComponents/index.js';
import { classNames, styleData } from './DynamicPageAnchorBar.module.css.js';

const _buttonBaseMinWidth = `${cssVarVersionInfoPrefix}button_base_min_width`;
const _buttonBaseHeight = `${cssVarVersionInfoPrefix}button_base_height`;
Expand All @@ -21,51 +21,6 @@ const anchorButtonVariables = {
[_buttonBaseHeight]: '1.5rem'
} as CSSProperties;

const anchorBarStyles = {
container: {
position: 'absolute',
left: '50%',
'&:before, &:after': {
content: '""',
position: 'absolute',
width: '4rem',
top: '50%',
height: '0.0625rem'
},
'&:before': {
right: '100%',
backgroundImage: `linear-gradient(to left, ${ThemingParameters.sapObjectHeader_BorderColor}, transparent)`
},
'&:after': {
backgroundImage: `linear-gradient(to right, ${ThemingParameters.sapObjectHeader_BorderColor}, transparent)`,
left: '100%'
}
},
anchorBarActionButton: {
'--_ui5wcr_anchor-btn-center': `calc((var(${_buttonBaseMinWidth}) - ${ThemingParameters.sapButton_BorderWidth}) / 2)`,
position: 'absolute',
insetBlockStart: `calc(-1 * var(--_ui5wcr_anchor-btn-center))`,
insetInlineStart: 'calc(50% - var(--_ui5wcr_anchor-btn-center))',
zIndex: 3,
'&:not([pressed])': {
backgroundColor: ThemingParameters.sapObjectHeader_Background
}
},
anchorBarActionButtonExpandable: {
'& + $anchorBarActionButtonPinnable': {
insetInlineStart: 'calc(50% - var(--_ui5wcr_anchor-btn-center) + 1rem)'
}
},
anchorBarActionButtonPinnable: {},
anchorBarActionPinnableAndExpandable: {
'&$anchorBarActionButtonExpandable': {
insetInlineStart: 'calc(50% - var(--_ui5wcr_anchor-btn-center) - 1rem)'
}
}
};

const useStyles = createUseStyles(anchorBarStyles, { name: 'DynamicPageAnchorBar' });

interface DynamicPageAnchorBarPropTypes extends CommonProps {
/**
* Determines if the header content is visible.
Expand Down Expand Up @@ -127,7 +82,7 @@ const DynamicPageAnchorBar = forwardRef<HTMLElement, DynamicPageAnchorBarPropTyp
onHoverToggleButton
} = props;

const classes = useStyles();
useStylesheet(styleData, DynamicPageAnchorBar.displayName);
const shouldRenderHeaderPinnableButton = headerContentPinnable && headerContentVisible;
const showBothActions = shouldRenderHeaderPinnableButton && showHideHeaderButton;

Expand Down Expand Up @@ -157,17 +112,17 @@ const DynamicPageAnchorBar = forwardRef<HTMLElement, DynamicPageAnchorBarPropTyp
data-component-name="DynamicPageAnchorBar"
style={style}
role={a11yConfig?.dynamicPageAnchorBar?.role ?? 'navigation'}
className={showHideHeaderButton || headerContentPinnable ? classes.container : null}
className={showHideHeaderButton || headerContentPinnable ? classNames.container : null}
ref={ref}
>
{showHideHeaderButton && (
<Button
icon={!headerContentVisible ? iconArrowDown : iconArrowUp}
data-ui5wcr-dynamic-page-header-action=""
className={clsx(
classes.anchorBarActionButton,
classes.anchorBarActionButtonExpandable,
showBothActions && classes.anchorBarActionPinnableAndExpandable
classNames.anchorBarActionButton,
classNames.anchorBarActionButtonExpandable,
showBothActions && classNames.anchorBarActionPinnableAndExpandable
)}
style={anchorButtonVariables}
onClick={onToggleHeaderButtonClick}
Expand All @@ -182,7 +137,7 @@ const DynamicPageAnchorBar = forwardRef<HTMLElement, DynamicPageAnchorBarPropTyp
<ToggleButton
icon={iconPushPin}
data-ui5wcr-dynamic-page-header-action=""
className={clsx(classes.anchorBarActionButton, classes.anchorBarActionButtonPinnable)}
className={clsx(classNames.anchorBarActionButton, classNames.anchorBarActionButtonPinnable)}
style={anchorButtonVariables}
pressed={headerPinned}
onClick={onPinHeader}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.header {
background-color: var(--sapObjectHeader_Background);
position: sticky;
z-index: 1;
padding-block-start: 1rem;
padding-block-end: 1rem;
display: var(--_ui5wcr_DynamicPage_header_display);
overflow: hidden;
}
17 changes: 10 additions & 7 deletions packages/main/src/components/DynamicPageHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client';

import { useStylesheet } from '@ui5/webcomponents-react-base';
import { clsx } from 'clsx';
import type { ReactNode } from 'react';
import React, { forwardRef, useMemo } from 'react';
import { createUseStyles } from 'react-jss';
import type { CommonProps } from '../../types/index.js';
import { DynamicPageHeaderStyles } from './DynamicPageHeader.jss.js';
import { classNames, styleData } from './DynamicPageHeader.module.css.js';

export interface DynamicPageHeaderPropTypes extends CommonProps {
/**
Expand All @@ -25,8 +25,6 @@ interface InternalProps extends DynamicPageHeaderPropTypes {
topHeaderHeight?: number;
}

const useStyles = createUseStyles(DynamicPageHeaderStyles, { name: 'DynamicPageHeader' });

/**
* The `DynamicPageHeader` component is part of the `DynamicPage` family and is used to serve as header section of the `DynamicPage` and `ObjectPage`.
* This component can be collapsed and pinned by the anchorbar.
Expand All @@ -47,11 +45,16 @@ const DynamicPageHeader = forwardRef<HTMLDivElement, InternalProps>((props, ref)
return style;
}, [headerPinned, topHeaderHeight, style]);

const classes = useStyles();
const classNames = clsx(classes.header, className);
useStylesheet(styleData, DynamicPageHeader.displayName);

return (
<div ref={ref} {...rest} className={classNames} data-component-name="DynamicPageHeader" style={headerStyles}>
<div
ref={ref}
{...rest}
className={clsx(classNames.header, className)}
data-component-name="DynamicPageHeader"
style={headerStyles}
>
{children}
</div>
);
Expand Down

This file was deleted.

Loading
Loading