-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split AsideHeader to compound components
- Loading branch information
Showing
8 changed files
with
152 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,31 @@ | ||
import React, {useMemo} from 'react'; | ||
import React from 'react'; | ||
|
||
import {Content} from '../Content'; | ||
|
||
import {AsideHeaderContextProvider, AsideHeaderInnerContextProvider} from './AsideHeaderContext'; | ||
import {AsideHeaderProps} from './types'; | ||
import {PageLayout} from './PageLayout/PageLayout'; | ||
import {PageLayoutAside} from './PageLayout/PageLayoutAside'; | ||
|
||
import {FirstPanel} from './components'; | ||
import {b} from './utils'; | ||
|
||
import './AsideHeader.scss'; | ||
import {ASIDE_HEADER_COMPACT_WIDTH, ASIDE_HEADER_EXPANDED_WIDTH} from '../constants'; | ||
import {useAsideHeaderInnerContextValue} from './useAsideHeaderInnerContextValue'; | ||
|
||
export const AsideHeader = React.forwardRef<HTMLDivElement, AsideHeaderProps>((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}); | ||
return ( | ||
<AsideHeaderContextProvider value={asideHeaderContextValue}> | ||
<AsideHeaderInnerContextProvider value={asideHeaderInnerContextValue}> | ||
<div | ||
className={b({compact}, className)} | ||
style={{ | ||
...({'--gn-aside-header-size': `${size}px`} as React.CSSProperties), | ||
}} | ||
> | ||
<div className={b('pane-container')}> | ||
{/* First Panel */} | ||
<FirstPanel ref={ref} /> | ||
{/* Second Panel */} | ||
<Content | ||
size={size} | ||
renderContent={props.renderContent} | ||
className={b('content')} | ||
/> | ||
</div> | ||
</div> | ||
</AsideHeaderInnerContextProvider> | ||
</AsideHeaderContextProvider> | ||
); | ||
}); | ||
/** | ||
* Simply usage of AsideHeader: | ||
* @example | ||
* <AsideHeader renderContent={renderContent} {...props} /> | ||
* | ||
* Advanced usage of AsideHeader: | ||
* @example | ||
* <PageLayout reverse > | ||
* <PageLayout.Content> | ||
* <Content /> | ||
* </PageLayout.Content> | ||
* | ||
* <PageLayoutAside {...props} /> | ||
* </PageLayout> | ||
*/ | ||
export const AsideHeader = React.forwardRef<HTMLDivElement, AsideHeaderProps>( | ||
({compact, className, ...props}, ref) => { | ||
return ( | ||
<PageLayout compact={compact} className={className}> | ||
<PageLayoutAside ref={ref} {...props} /> | ||
<PageLayout.Content renderContent={props.renderContent} /> | ||
</PageLayout> | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, {PropsWithChildren, useMemo} from 'react'; | ||
import {AsideHeaderContextProvider, useAsideHeaderContext} from '../AsideHeaderContext'; | ||
import {Content, ContentProps} from '../../Content'; | ||
import {ASIDE_HEADER_COMPACT_WIDTH, ASIDE_HEADER_EXPANDED_WIDTH} from '../../constants'; | ||
import {PageLayoutProps} from '../types'; | ||
import {b} from '../utils'; | ||
|
||
import '../AsideHeader.scss'; | ||
|
||
const PageLayout = ({ | ||
compact, | ||
reverse, | ||
className, | ||
children, | ||
}: PropsWithChildren<PageLayoutProps> & { | ||
reverse?: boolean; | ||
}) => { | ||
const size = compact ? ASIDE_HEADER_COMPACT_WIDTH : ASIDE_HEADER_EXPANDED_WIDTH; | ||
const asideHeaderContextValue = useMemo(() => ({size, compact}), [compact, size]); | ||
|
||
return ( | ||
<AsideHeaderContextProvider value={asideHeaderContextValue}> | ||
<div | ||
className={b({compact, reverse}, className)} | ||
style={{ | ||
...({'--gn-aside-header-size': `${size}px`} as React.CSSProperties), | ||
}} | ||
> | ||
<div className={b('pane-container')}>{children}</div> | ||
</div> | ||
</AsideHeaderContextProvider> | ||
); | ||
}; | ||
|
||
const ConnectedContent: React.FC<Pick<ContentProps, 'renderContent'>> = ({ | ||
children, | ||
renderContent, | ||
}) => { | ||
const {size} = useAsideHeaderContext(); | ||
|
||
return ( | ||
<Content size={size} className={b('content')} renderContent={renderContent}> | ||
{children} | ||
</Content> | ||
); | ||
}; | ||
|
||
PageLayout.Content = ConnectedContent; | ||
|
||
export {PageLayout}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import {FirstPanel} from '../components'; | ||
import {useAsideHeaderInnerContextValue} from '../useAsideHeaderInnerContextValue'; | ||
import {AsideHeaderInnerContextProvider, useAsideHeaderContext} from '../AsideHeaderContext'; | ||
import {AsideHeaderProps} from '../types'; | ||
|
||
type Props = Omit<AsideHeaderProps, 'compact' | 'size'>; | ||
|
||
export const PageLayoutAside = React.forwardRef<HTMLDivElement, Props>((props, ref) => { | ||
const {size, compact} = useAsideHeaderContext(); | ||
|
||
const asideHeaderInnerContextValue = useAsideHeaderInnerContextValue({size, compact, ...props}); | ||
|
||
return ( | ||
<AsideHeaderInnerContextProvider value={asideHeaderInnerContextValue}> | ||
<FirstPanel ref={ref} /> | ||
</AsideHeaderInnerContextProvider> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters