Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add page-constructor page type #220

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -46,6 +46,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 @@ -167,3 +175,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;
}
Loading