-
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: add AsideFallback * chore: share HEADER_DIVIDER_HEIGHT
- Loading branch information
Showing
13 changed files
with
114 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,30 +26,43 @@ npm install --dev @gravity-ui/uikit@^3.0.2 @bem-react/[email protected] react@^16. | |
- DrawerItem | ||
- PageLayout | ||
- PageLayoutAside | ||
- AsideFallback | ||
|
||
## Optimization | ||
|
||
If your app content needs to be rendered faster than by passing it throw `AsideHeader` props, | ||
you may need to switch usage of `AsideHeader` to advanced style with `PageLayout` like this: | ||
|
||
```diff | ||
-import {AsideHeader} from '@gravity-ui/navigation'; | ||
+import {PageLayout} from '@gravity-ui/navigation'; | ||
+ | ||
+const PageLayoutAside = React.lazy(() => | ||
+ import('@gravity-ui/navigation').then((module) => ({default: module.PageLayoutAside})), | ||
--- Main.tsx | ||
+++ Main.tsx | ||
-import {AsideHeader} from './AsideHeader' | ||
+import {PageLayout, AsideFallback} from '@gravity-ui/navigation'; | ||
+const Aside = React.lazy(() => | ||
+ import('./Aside').then(({Aside}) => ({ default: Aside })) | ||
+); | ||
|
||
- <AsideHeader renderContent={renderContent} {...restProps} /> | ||
+ <PageLayout> | ||
+ <Suspense fallback={null}> | ||
+ <PageLayoutAside {...restProps} /> | ||
+ <Suspense fallback={<AsideFallback />}> | ||
+ <Aside /> | ||
+ </Suspense> | ||
+ | ||
+ <PageLayout.Content> | ||
+ <ContentExample /> | ||
+ </PageLayout.Content> | ||
+ </PageLayout> | ||
--- Aside.tsx | ||
+++ Aside.tsx | ||
-import {AsideHeader} from '@gravity-ui/navigation'; | ||
+import {PageLayoutAside} from '@gravity-ui/navigation'; | ||
|
||
export const Aside: FC = () => { | ||
return ( | ||
- <AsideHeader {...props}> | ||
+ <PageLayoutAside {...props}/> | ||
); | ||
}; | ||
``` | ||
|
||
## Imports | ||
|
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
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
38 changes: 38 additions & 0 deletions
38
src/components/AsideHeader/components/PageLayout/AsideFallback.tsx
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,38 @@ | ||
import React from 'react'; | ||
import {useAsideHeaderContext} from '../../AsideHeaderContext'; | ||
import headerDividerCollapsedIcon from '../../../../../assets/icons/divider-collapsed.svg'; | ||
import {b} from '../../utils'; | ||
import {Icon} from '@gravity-ui/uikit'; | ||
import {ASIDE_HEADER_COMPACT_WIDTH, HEADER_DIVIDER_HEIGHT, ITEM_HEIGHT} from '../../../constants'; | ||
|
||
export interface Props { | ||
headerDecoration?: boolean; | ||
subheaderItemsCount?: number; | ||
} | ||
|
||
export const AsideFallback: React.FC<Props> = ({headerDecoration, subheaderItemsCount = 0}) => { | ||
const {compact} = useAsideHeaderContext(); | ||
|
||
const widthVar = compact ? '--gn-aside-header-min-width' : '--gn-aside-header-size'; | ||
|
||
const subheaderHeight = (1 + subheaderItemsCount) * ITEM_HEIGHT; | ||
|
||
return ( | ||
<div className={b('aside')} style={{width: `var(${widthVar})`}}> | ||
<div className={b('aside-content', {'with-decoration': headerDecoration})}> | ||
<div className={b('header', {'with-decoration': headerDecoration})}> | ||
<div style={{height: subheaderHeight}} /> | ||
{compact ? ( | ||
<Icon | ||
data={headerDividerCollapsedIcon} | ||
className={b('header-divider')} | ||
width={ASIDE_HEADER_COMPACT_WIDTH} | ||
height={HEADER_DIVIDER_HEIGHT} | ||
/> | ||
) : null} | ||
</div> | ||
<div style={{flex: 1}} /> | ||
</div> | ||
</div> | ||
); | ||
}; |
21 changes: 13 additions & 8 deletions
21
src/components/AsideHeader/components/PageLayout/PageLayout.tsx
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
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,3 +1,5 @@ | ||
export const ASIDE_HEADER_ICON_SIZE = 18; | ||
export const ASIDE_HEADER_COMPACT_WIDTH = 56; | ||
export const ASIDE_HEADER_EXPANDED_WIDTH = 236; | ||
export const ITEM_HEIGHT = 40; | ||
export const HEADER_DIVIDER_HEIGHT = 29; |
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