diff --git a/src/components/AsideHeader/AsideHeader.tsx b/src/components/AsideHeader/AsideHeader.tsx index a61a221..9b0a866 100644 --- a/src/components/AsideHeader/AsideHeader.tsx +++ b/src/components/AsideHeader/AsideHeader.tsx @@ -12,8 +12,9 @@ import './AsideHeader.scss'; import {ASIDE_HEADER_COMPACT_WIDTH, ASIDE_HEADER_EXPANDED_WIDTH} from '../constants'; import {useAsideHeaderInnerContextValue} from './useAsideHeaderInnerContextValue'; -export const AsideHeader = (props: AsideHeaderProps) => { +export const AsideHeader = React.forwardRef((props, ref) => { const {className, compact} = props; + const size = compact ? ASIDE_HEADER_COMPACT_WIDTH : ASIDE_HEADER_EXPANDED_WIDTH; const asideHeaderContextValue = useMemo(() => ({size, compact}), [compact, size]); const asideHeaderInnerContextValue = useAsideHeaderInnerContextValue({...props, size}); @@ -23,7 +24,7 @@ export const AsideHeader = (props: AsideHeaderProps) => {
{/* First Panel */} - + {/* Second Panel */} { ); -}; +}); diff --git a/src/components/AsideHeader/README.md b/src/components/AsideHeader/README.md new file mode 100644 index 0000000..7fc330a --- /dev/null +++ b/src/components/AsideHeader/README.md @@ -0,0 +1,17 @@ +# AsideHeader [⚠️ WIP] + +## Imports + +```ts +import {AsideHeader} from '@gravity-ui/navigation'; +``` + +## Example + +// TODO + +## Properties + +| Name | Description | Type | Default | +| :--- | :--------------------------- | :----------------------------------------------------: | :-----: | +| ref | `ref` to target popup anchor | `React.ForwardedRef` | | diff --git a/src/components/AsideHeader/__stories__/AsideHeaderShowcase.scss b/src/components/AsideHeader/__stories__/AsideHeaderShowcase.scss index 0b470cd..eb97bbf 100644 --- a/src/components/AsideHeader/__stories__/AsideHeaderShowcase.scss +++ b/src/components/AsideHeader/__stories__/AsideHeaderShowcase.scss @@ -27,10 +27,14 @@ body { } } - &__settings-ul { + &__settings { padding-right: 30px; } + &__settings-ul { + margin: 0; + } + &__panel { width: 300px; height: 100%; diff --git a/src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx b/src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx index af8e08b..92376b7 100644 --- a/src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx +++ b/src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx @@ -35,6 +35,7 @@ export const AsideHeaderShowcase: FC = ({ multipleTooltip = false, initialCompact = false, }) => { + const ref = React.useRef(null); const [popupVisible, setPopupVisible] = React.useState(false); const [subheaderPopupVisible, setSubheaderPopupVisible] = React.useState(false); const [visiblePanel, setVisiblePanel] = React.useState(); @@ -73,6 +74,7 @@ export const AsideHeaderShowcase: FC = ({
= ({ setSubheaderPopupVisible(!subheaderPopupVisible); }, }, + popupAnchor: ref, + popupPlacement: ['right-start'], + popupOffset: [10, 10], popupVisible: subheaderPopupVisible, onClosePopup: () => setSubheaderPopupVisible(false), renderPopupContent: () => { return ( -
-
    +
    +
    • Set 1
    • Set 2
    • Set 3
    • diff --git a/src/components/AsideHeader/components/FirstPanel.tsx b/src/components/AsideHeader/components/FirstPanel.tsx index 4fb5950..cbc6c08 100644 --- a/src/components/AsideHeader/components/FirstPanel.tsx +++ b/src/components/AsideHeader/components/FirstPanel.tsx @@ -1,4 +1,4 @@ -import React, {useRef} from 'react'; +import React, {useRef, useMemo} from 'react'; import {CompositeBar} from '../../CompositeBar/CompositeBar'; import {useAsideHeaderInnerContext} from '../AsideHeaderContext'; import {b} from '../utils'; @@ -9,7 +9,7 @@ import {Header} from './Header'; import {CollapseButton} from './CollapseButton'; import {Panels} from './Panels'; -export const FirstPanel = () => { +export const FirstPanel = React.forwardRef((_props, ref) => { const { size, onItemClick, @@ -23,10 +23,12 @@ export const FirstPanel = () => { const asideRef = useRef(null); + const popupAnchorRef = useMemo(() => ref || asideRef, [ref, asideRef]); + return ( <>
      -
      +
      {visibleMenuItems?.length ? ( @@ -44,7 +46,7 @@ export const FirstPanel = () => { {renderFooter?.({ size, compact: Boolean(compact), - asideRef, + asideRef: popupAnchorRef, })}
      @@ -53,4 +55,4 @@ export const FirstPanel = () => { ); -}; +}); diff --git a/src/components/AsideHeader/types.tsx b/src/components/AsideHeader/types.tsx index e636923..ea74bc0 100644 --- a/src/components/AsideHeader/types.tsx +++ b/src/components/AsideHeader/types.tsx @@ -14,7 +14,7 @@ export interface AsideHeaderGeneralProps { renderFooter?: (data: { size: number; compact: boolean; - asideRef: React.RefObject; + asideRef: React.ForwardedRef; }) => React.ReactNode; onClosePanel?: () => void; onChangeCompact?: (compact: boolean) => void;