Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/added-selecti…
Browse files Browse the repository at this point in the history
…on-to-settings
  • Loading branch information
Ruminat committed Nov 10, 2023
2 parents 2015103 + 1e7dc82 commit e42f033
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 79 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [1.2.0](https://github.com/gravity-ui/navigation/compare/v1.1.3...v1.2.0) (2023-11-03)


### Features

* split AsideHeader to compound components ([#140](https://github.com/gravity-ui/navigation/issues/140)) ([1099f68](https://github.com/gravity-ui/navigation/commit/1099f6830b25ceb393e3a4b51d33f92bc5b16760))

## [1.1.3](https://github.com/gravity-ui/navigation/compare/v1.1.2...v1.1.3) (2023-10-24)


Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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` |
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@gravity-ui/navigation",
"version": "1.1.3",
"version": "1.2.0",
"description": "Gravity UI Navigation components",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/gravity-ui/navigation"
},
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"main": "build/cjs",
"module": "build/esm",
"types": "build/esm/index.d.ts",
"sideEffects": [
"*.css",
Expand Down
58 changes: 43 additions & 15 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,60 @@ import peerDepsExternal from 'rollup-plugin-peer-deps-external';

const packageJson = require('./package.json');

const input = [
'src/index.ts',
'src/components/ActionBar/index.ts',
'src/components/Title/index.ts',
'src/components/HotkeysPanel/index.ts',
'src/components/Settings/index.ts',
'src/components/MobileHeader/index.ts',
'src/components/AsideHeader/AsideHeader.tsx',
'src/components/AsideHeader/AsideHeaderContext.ts',
'src/components/Drawer/Drawer.tsx',
'src/components/FooterItem/FooterItem.tsx',
'src/components/AsideHeader/components/PageLayout/PageLayout.tsx',
'src/components/AsideHeader/components/PageLayout/PageLayoutAside.tsx',
];

const getPlugins = (outDir) => {
return [
peerDepsExternal(),
json(),
resolve(),
commonjs(),
typescript({
typescript: require('typescript'),
tsconfig: './tsconfig.publish.json',
outDir,
}),
postcss({
minimize: true,
}),
svgr(),
];
};

export default [
{
input: 'src/index.ts',
input,
output: [
{
file: packageJson.module,
dir: packageJson.module,
format: 'esm',
sourcemap: true,
},
],
plugins: getPlugins(packageJson.module),
},
{
input,
output: [
{
file: packageJson.main,
dir: packageJson.main,
format: 'cjs',
sourcemap: true,
},
],
plugins: [
peerDepsExternal(),
json(),
resolve(),
commonjs(),
typescript({
typescript: require('typescript'),
tsconfig: './tsconfig.publish.json',
}),
postcss(),
svgr(),
],
plugins: getPlugins(packageJson.main),
},
];
16 changes: 5 additions & 11 deletions src/components/AsideHeader/AsideHeader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $block: '.#{variables.$ns}aside-header';

.g-root_theme_light,
.g-root_theme_light-hc {
--gn-aside-header-divider-line-color: transparent;
--gn-aside-header-divider-line-color: var(--g-color-line-generic);
--gn-aside-header-subheader-divider-line-color: var(--g-color-line-generic);
}

Expand Down Expand Up @@ -78,16 +78,6 @@ $block: '.#{variables.$ns}aside-header';
z-index: 2;
user-select: none;

&::after {
position: absolute;
top: 0;
right: -100px;
bottom: 0;
width: 100px;
content: '';
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1), 0px 0px 24px rgba(0, 0, 0, 0.08);
}

& > #{$class}-logo {
margin: 8px 0;
}
Expand Down Expand Up @@ -202,6 +192,10 @@ $block: '.#{variables.$ns}aside-header';
flex-direction: row;
}

&_reverse #{$block}__pane-container {
flex-direction: row-reverse;
}

&__content {
width: calc(100% - var(--gn-aside-header-size));
z-index: 95;
Expand Down
69 changes: 28 additions & 41 deletions src/components/AsideHeader/AsideHeader.tsx
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>
);
},
);
3 changes: 1 addition & 2 deletions src/components/AsideHeader/AsideHeaderContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {AsideHeaderInnerProps} from './types';
export interface AsideHeaderInnerContextType extends AsideHeaderInnerProps {
menuItems: MenuItem[];
allPagesIsAvailable: boolean;
size: number;
onItemClick: (
item: MenuItem,
collapsed: boolean,
Expand All @@ -30,7 +29,7 @@ export const useAsideHeaderInnerContext = (): AsideHeaderInnerContextType => {
};

export interface AsideHeaderContextType {
compact?: boolean;
compact: boolean;
size: number;
}

Expand Down
33 changes: 33 additions & 0 deletions src/components/AsideHeader/__stories__/AsideHeader.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import type {Meta, StoryFn} from '@storybook/react';

import {AsideHeader} from '../AsideHeader';
import {AsideHeaderShowcase} from './AsideHeaderShowcase';
import {PageLayout} from '../components/PageLayout/PageLayout';
import {PageLayoutAside} from '../components/PageLayout/PageLayoutAside';
import logoIcon from '../../../../.storybook/assets/logo.svg';
import {menuItemsShowcase} from './moc';

export default {
title: 'components/AsideHeader',
Expand All @@ -25,3 +29,32 @@ MultipleTooltip.args = {
multipleTooltip: true,
initialCompact: true,
};

const AdvancedUsageTemplate: StoryFn = (args) => {
const [compact, setCompact] = React.useState(args.initialCompact);

return (
<PageLayout reverse compact={compact}>
<PageLayout.Content>PageContent</PageLayout.Content>
<PageLayoutAside
headerDecoration
menuItems={menuItemsShowcase}
logo={{
text: 'Service',
icon: logoIcon,
href: '#',
onClick: () => alert('click on logo'),
}}
onChangeCompact={setCompact}
{...args}
/>
</PageLayout>
);
};

export const AdvancedUsage = AdvancedUsageTemplate.bind({});

AdvancedUsage.args = {
multipleTooltip: false,
initialCompact: true,
};
1 change: 1 addition & 0 deletions src/components/AsideHeader/__stories__/moc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function renderTag(tag: string) {

export const EMPTY_CONTEXT_VALUE: AsideHeaderContextType = {
size: ASIDE_HEADER_EXPANDED_WIDTH,
compact: true,
};

export const menuItemsShowcase: MenuItem[] = [
Expand Down
49 changes: 49 additions & 0 deletions src/components/AsideHeader/components/PageLayout/PageLayout.tsx
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};
Loading

0 comments on commit e42f033

Please sign in to comment.