Skip to content

Commit

Permalink
fix(AsideHeader): change ref type (#128)
Browse files Browse the repository at this point in the history
* fix(AsideHeader): change ref type

* chore(CompositeBar): change popupProps
  • Loading branch information
Lunory authored Oct 9, 2023
1 parent 8232679 commit a3274e8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ body {
}

&__settings {
padding-right: 30px;
width: 200px;
height: 100%;
padding: 20px;
}

&__settings-ul {
Expand Down
10 changes: 6 additions & 4 deletions src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const AsideHeaderShowcase: FC<AsideHeaderShowcaseProps> = ({
compact={compact}
multipleTooltip={multipleTooltip}
openModalSubscriber={openModalSubscriber}
renderFooter={({compact}) => (
renderFooter={({compact, asideRef}) => (

Check warning on line 132 in src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'compact' is already declared in the upper scope
<React.Fragment>
<FooterItem
compact={compact}
Expand All @@ -151,12 +151,14 @@ export const AsideHeaderShowcase: FC<AsideHeaderShowcaseProps> = ({
}}
enableTooltip={false}
popupVisible={popupVisible}
popupOffset={[0, 8]}
popupAnchor={asideRef}
popupPlacement={['right-end']}
popupOffset={[-20, 10]}
onClosePopup={() => setPopupVisible(false)}
renderPopupContent={() => {
return (
<div className={b('settings-ul')}>
<ul>
<div className={b('settings')}>
<ul className={b('settings-ul')}>
<li>Set 1</li>
<li>Set 2</li>
<li>Set 3</li>
Expand Down
12 changes: 8 additions & 4 deletions src/components/AsideHeader/components/FirstPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, {useRef, useMemo} from 'react';
import React, {useRef} from 'react';

import {setRef} from '@gravity-ui/uikit';
import {CompositeBar} from '../../CompositeBar/CompositeBar';
import {useAsideHeaderInnerContext} from '../AsideHeaderContext';
import {b} from '../utils';
Expand All @@ -23,12 +25,14 @@ export const FirstPanel = React.forwardRef<HTMLDivElement>((_props, ref) => {

const asideRef = useRef<HTMLDivElement>(null);

const popupAnchorRef = useMemo(() => ref || asideRef, [ref, asideRef]);
React.useEffect(() => {
setRef<HTMLDivElement>(ref, asideRef.current);
}, [ref]);

return (
<>
<div className={b('aside')} style={{width: size}}>
<div className={b('aside-popup-anchor')} ref={popupAnchorRef} />
<div className={b('aside-popup-anchor')} ref={asideRef} />
<div className={b('aside-content', {['with-decoration']: headerDecoration})}>
<Header />
{visibleMenuItems?.length ? (
Expand All @@ -46,7 +50,7 @@ export const FirstPanel = React.forwardRef<HTMLDivElement>((_props, ref) => {
{renderFooter?.({
size,
compact: Boolean(compact),
asideRef: popupAnchorRef,
asideRef,
})}
</div>
<CollapseButton />
Expand Down
2 changes: 1 addition & 1 deletion src/components/AsideHeader/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface AsideHeaderGeneralProps {
renderFooter?: (data: {
size: number;
compact: boolean;
asideRef: React.ForwardedRef<HTMLDivElement>;
asideRef: React.RefObject<HTMLDivElement>;
}) => React.ReactNode;
onClosePanel?: () => void;
onChangeCompact?: (compact: boolean) => void;
Expand Down
8 changes: 4 additions & 4 deletions src/components/CompositeBar/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import './Item.scss';
const b = block('composite-bar-item');

interface ItemPopup {
popupVisible?: boolean;
popupAnchor?: React.RefObject<HTMLElement>;
popupPlacement?: PopupPlacement;
popupVisible?: PopupProps['open'];
popupAnchor?: PopupProps['anchorRef'];
popupPlacement?: PopupProps['placement'];
popupOffset?: PopupProps['offset'];
popupKeepMounted?: boolean;
popupKeepMounted?: PopupProps['keepMounted'];
renderPopupContent?: () => React.ReactNode;
onClosePopup?: () => void;
}
Expand Down

0 comments on commit a3274e8

Please sign in to comment.