-
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.
Merge remote-tracking branch 'origin/main' into feature/added-selecti…
…on-to-settings
- Loading branch information
Showing
15 changed files
with
238 additions
and
79 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 |
---|---|---|
|
@@ -24,6 +24,33 @@ npm install --dev @gravity-ui/uikit@^3.0.2 @bem-react/[email protected] react@^16. | |
- MobileHeaderFooterItem | ||
- Drawer | ||
- DrawerItem | ||
- PageLayout | ||
- PageLayoutAside | ||
|
||
## 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})), | ||
+); | ||
|
||
- <AsideHeader renderContent={renderContent} {...restProps} /> | ||
+ <PageLayout reverse> | ||
+ <PageLayout.Content> | ||
+ <ContentExample /> | ||
+ </PageLayout.Content> | ||
+ | ||
+ <Suspense fallback={null}> | ||
+ <PageLayoutAside {...restProps} /> | ||
+ </Suspense> | ||
+ </PageLayout> | ||
``` | ||
|
||
## Imports | ||
|
||
|
@@ -45,4 +72,4 @@ Used for themization Navigation's components | |
| `--gn-aside-header-footer-item-icon-color` | | `--g-color-text-primary` | | ||
| `--gn-aside-header-subheader-item-icon-color` | | `--g-color-text-primary` | | ||
| `--gn-aside-header-item-icon-background-size` | Background size used when `AsideHeader` is compact | `38px` | | ||
| `--gn-aside-header-divider-line-color` | Vertical color divider between `AsideHeader` and content | Light theme: `transparent`, Dark theme: `--g-color-line-generic-solid` | | ||
| `--gn-aside-header-divider-line-color` | Vertical color divider between `AsideHeader` and content | Light theme: `--g-color-line-generic`, Dark theme: `--g-color-line-generic-solid` | |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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 './components/PageLayout/PageLayout'; | ||
import {PageLayoutAside} from './components/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
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
49 changes: 49 additions & 0 deletions
49
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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 {LayoutProps} from '../../types'; | ||
import {b} from '../../utils'; | ||
|
||
import '../../AsideHeader.scss'; | ||
|
||
export interface PageLayoutProps extends PropsWithChildren<LayoutProps> { | ||
reverse?: boolean; | ||
} | ||
|
||
const Layout = ({compact, reverse, className, children}: PageLayoutProps) => { | ||
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<PropsWithChildren<Pick<ContentProps, 'renderContent'>>> = ({ | ||
children, | ||
renderContent, | ||
}) => { | ||
const {size} = useAsideHeaderContext(); | ||
|
||
return ( | ||
<Content size={size} className={b('content')} renderContent={renderContent}> | ||
{children} | ||
</Content> | ||
); | ||
}; | ||
|
||
const PageLayout = Object.assign(Layout, { | ||
Content: ConnectedContent, | ||
}); | ||
|
||
export {PageLayout}; |
Oops, something went wrong.