Skip to content

Commit

Permalink
feat: add page-constructor page type (#220)
Browse files Browse the repository at this point in the history
* feat: add page-constructor page type

* return leading prop

* rename PageConstructor -> ConstructorPage

* add storybook

* move  all PC  logic into client & del storybook
  • Loading branch information
martyanovandrey authored Mar 25, 2024
1 parent db017da commit cbf6b79
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 17 deletions.
103 changes: 88 additions & 15 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
"dependencies": {
"@gravity-ui/icons": "^2.5.0",
"@gravity-ui/uikit": "6.0.0",
"@gravity-ui/uikit": "^6.2.0",
"@popperjs/core": "^2.11.2",
"bem-cn-lite": "4.1.0",
"i18next": "^19.9.2",
Expand Down
59 changes: 59 additions & 0 deletions src/components/DocContentPage/DocContentPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';

import block from 'bem-cn-lite';

import {DEFAULT_SETTINGS} from '../../constants';
import {DocContentPageData, Router} from '../../models';
import {DocLayout} from '../DocLayout';

const b = block('dc-doc-page');

const {wideFormat: defaultWideFormat} = DEFAULT_SETTINGS;

export interface DocContentPageProps extends DocContentPageData {
router: Router;
headerHeight?: number;
wideFormat?: boolean;
hideTocHeader?: boolean;
hideToc?: boolean;
tocTitleIcon?: React.ReactNode;
}

export const DocContentPage: React.FC<DocContentPageProps> = ({
data,
toc,
router,
headerHeight,
wideFormat = defaultWideFormat,
hideTocHeader,
hideToc,
tocTitleIcon,
footer,
children,
}) => {
const modes = {
'regular-page-width': !wideFormat,
};

return (
<DocLayout
toc={toc}
router={router}
headerHeight={headerHeight}
className={b(modes)}
hideTocHeader={hideTocHeader}
hideToc={hideToc || data?.fullScreen}
fullScreen={data?.fullScreen}
tocTitleIcon={tocTitleIcon}
footer={footer}
hideRight={true}
wideFormat={wideFormat}
>
<DocLayout.Center>
<div className={b('main')}>
<main className={b('content')}>{children}</main>
</div>
</DocLayout.Center>
</DocLayout>
);
};
1 change: 1 addition & 0 deletions src/components/DocContentPage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './DocContentPage';
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export * from './components/ErrorBoundary';
export * from './components/Paginator';
export * from './components/SearchItem';
export * from './components/SearchPage';
export * from './components/DocContentPage';

export * from './config';
export * from './models';
export * from './constants';
export * from './utils';
14 changes: 14 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ export interface DocLeadingPageData extends DocBasePageData {
data: DocLeadingData;
}

export interface DocContentPageData extends DocBasePageData {
leading: true;
data: {
fullScreen?: boolean;
};
children?: React.ReactNode;
}

export interface DocLeadingData {
title: string;
description: string | string[];
Expand Down Expand Up @@ -176,3 +184,9 @@ export interface SubscribeData {
email: string;
type: SubscribeType;
}

export enum DocumentType {
Base = 'BASE',
Leading = 'LEADING',
PageConstructor = 'PAGE_CONSTRUCTOR',
}
35 changes: 34 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import {parse} from 'url';

import {ThemeContextProps} from '@gravity-ui/uikit';

import {DocContentPage} from '../components/DocContentPage';
import {DocLeadingPage} from '../components/DocLeadingPage';
import {DocPage} from '../components/DocPage';
import {PopperPosition} from '../hooks';
import {Contributor, Router} from '../models';
import {
Contributor,
DocContentPageData,
DocLeadingPageData,
DocPageData,
DocumentType,
Router,
} from '../models';

export type InnerProps<TProps extends Partial<TDefaultProps>, TDefaultProps> = Omit<
TProps,
Expand Down Expand Up @@ -97,3 +107,26 @@ export const getPopupPosition = (

return isVerticalView ? PopperPosition.LEFT_START : PopperPosition.BOTTOM_END;
};

export function getPageByType(type: DocumentType) {
const PageTypes = {
[DocumentType.Base]: DocPage,
[DocumentType.Leading]: DocLeadingPage,
[DocumentType.PageConstructor]: DocContentPage,
};

return PageTypes[type] || null;
}

export function getPageType({
data,
leading,
}: DocLeadingPageData | (DocPageData & {data?: undefined}) | DocContentPageData): DocumentType {
if (leading && data) {
return Object.prototype.hasOwnProperty.call(data, 'links')
? DocumentType.Leading
: DocumentType.PageConstructor;
}

return DocumentType.Base;
}

0 comments on commit cbf6b79

Please sign in to comment.