Skip to content

Commit

Permalink
fix: global scroll with top panel and aside header (#159)
Browse files Browse the repository at this point in the history
* fix: global scroll with top panel and aside header

* fix: top margin aside

* fix: hook missing set func

* fix: scroll aside sticky correct
  • Loading branch information
goshander authored Nov 24, 2023
1 parent d1d68a4 commit cfe44e0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 29 deletions.
14 changes: 12 additions & 2 deletions src/components/AsideHeader/AsideHeader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $block: '.#{variables.$ns}aside-header';

&__aside {
position: sticky;
top: 0;
top: var(--gn-aside-top-panel-height);
left: 0;
height: 100vh;
width: inherit;
Expand All @@ -46,6 +46,7 @@ $block: '.#{variables.$ns}aside-header';
background-color: var(--g-color-base-background);
z-index: 100;
max-height: calc(100vh - var(--gn-aside-top-panel-height));
margin-top: var(--gn-aside-top-panel-height);

box-sizing: border-box;

Expand Down Expand Up @@ -198,10 +199,18 @@ $block: '.#{variables.$ns}aside-header';

&__pane-top-divider {
height: 1px;
background-color: var(--gn-aside-header-collapse-button-divider-line-color);
background-color: var(--gn-aside-header-divider-line-color);
margin-top: -1px;
}

&__pane-top {
position: fixed;
z-index: 98;
top: 0;
background: var(--g-color-base-background);
width: 100%;
}

&__pane-top-alert {
&_centered {
display: flex;
Expand All @@ -221,6 +230,7 @@ $block: '.#{variables.$ns}aside-header';
&__content {
width: calc(100% - var(--gn-aside-header-size));
z-index: 95;
margin-top: var(--gn-aside-top-panel-height);
}

&__collapse-button {
Expand Down
5 changes: 1 addition & 4 deletions src/components/AsideHeader/AsideHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ export const AsideHeader = React.forwardRef<HTMLDivElement, AsideHeaderProps>(
return (
<PageLayout compact={compact} className={className} topAlert={topAlert}>
<PageLayoutAside ref={ref} {...props} />
<PageLayout.Content
renderContent={props.renderContent}
withTop={Boolean(topAlert)}
/>
<PageLayout.Content renderContent={props.renderContent} />
</PageLayout>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ HeaderAlert.args = {
topAlert: {
title: 'Maintenance',
view: 'filled',
message: 'Scheduled maintenance is being performed',
message:
'Scheduled maintenance is being performed Scheduled maintenance is being performed Scheduled maintenance is being performed Scheduled maintenance is being performed Scheduled maintenance is being performed Scheduled maintenance is being performed Scheduled mainten',
closable: true,
},
};
Expand All @@ -76,5 +77,6 @@ HeaderAlertCentered.args = {
view: 'filled',
message: 'Scheduled maintenance is being performed',
centered: true,
dense: true,
},
};
14 changes: 5 additions & 9 deletions src/components/AsideHeader/components/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,14 @@ const Layout = ({compact, reverse, className, children, topAlert}: PageLayoutPro
);
};

const ConnectedContent: React.FC<
PropsWithChildren<Pick<ContentProps, 'renderContent' | 'withTop'>>
> = ({children, withTop, renderContent}) => {
const ConnectedContent: React.FC<PropsWithChildren<Pick<ContentProps, 'renderContent'>>> = ({
children,
renderContent,
}) => {
const {size} = useAsideHeaderContext();

return (
<Content
withTop={withTop}
size={size}
className={b('content')}
renderContent={renderContent}
>
<Content size={size} className={b('content')} renderContent={renderContent}>
{children}
</Content>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/AsideHeader/useAsideHeaderTopPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const useAsideHeaderTopPanel = ({
window.removeEventListener('resize', updateTopSizeDebounce);
setAsideTopPanelHeight(0);
};
}, [topAlert, topHeight, topRef, updateTopSize]);
}, [topAlert, topHeight, topRef, updateTopSize, setAsideTopPanelHeight]);

return {
topRef,
Expand Down
16 changes: 4 additions & 12 deletions src/components/Content/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface ContentProps {
size: number;
className?: string;
cssSizeVariableName?: string;
withTop?: boolean;
renderContent?: RenderContentType;
}

Expand All @@ -27,21 +26,14 @@ export const Content: React.FC<ContentProps> = ({
size, // TODO: move to context when MobileHeader will support it
className,
cssSizeVariableName = '--gn-aside-header-size',
withTop,
renderContent,
children,
}) => {
const style: React.CSSProperties = {
[cssSizeVariableName]: `${size}px`,
};

if (withTop) {
style.maxHeight = 'calc(100vh - var(--gn-aside-top-panel-height))';
style.overflowY = 'auto';
}

return (
<div className={className} style={style}>
<div
className={className}
style={{...({[cssSizeVariableName]: `${size}px`} as React.CSSProperties)}}
>
{typeof renderContent === 'function' ? (
<RenderContent size={size} renderContent={renderContent} />
) : (
Expand Down

0 comments on commit cfe44e0

Please sign in to comment.