From 28f84cc7aa18a4cba61731eb165bd7e5671cfa3e Mon Sep 17 00:00:00 2001 From: Ilya Bychek Date: Thu, 6 Jun 2024 18:50:17 +0300 Subject: [PATCH] fix(docs): Change proptable and check types after json generate --- .../caldera-online/api/caldera-online.api.md | 30 ++++++++++++--- .../src/components/Switch/Switch.tsx | 12 ++---- packages/plasma-asdk/api/plasma-asdk.api.md | 29 ++++++++++++--- .../src/components/Switch/Switch.tsx | 12 ++---- packages/plasma-b2c/api/plasma-b2c.api.md | 28 +++++++++++--- .../src/components/Switch/Switch.tsx | 12 ++---- .../src/components/Switch/Switch.tsx | 8 ++-- .../src/components/Switch/Switch.types.ts | 21 +++++++++-- .../src/components/Switch/index.ts | 1 + packages/plasma-web/api/plasma-web.api.md | 28 +++++++++++--- .../src/components/Switch/Switch.tsx | 12 ++---- packages/sdds-serv/api/sdds-serv.api.md | 28 +++++++++++--- .../src/components/Switch/Switch.tsx | 12 ++---- scaffold/template-docs/docusaurus.config.js | 11 +++--- utils/plasma-docs-ui/README.md | 37 +++++++++++++++++++ .../src/components/PropsTable.tsx | 15 ++++++-- utils/plasma-docs-ui/src/types/DocgenInfo.ts | 4 ++ website/plasma-ui-docs/docusaurus.config.js | 11 +++--- .../src/components/PropsTable.tsx | 9 +++-- .../docs/components/Checkbox.mdx | 2 +- .../docs/components/Radiobox.mdx | 2 +- .../docs/components/Switch.mdx | 2 +- website/plasma-web-docs/docusaurus.config.js | 11 +++--- .../src/components/PropsTable.tsx | 9 +++-- .../docs/components/Checkbox.mdx | 2 +- .../docs/components/Radiobox.mdx | 2 +- .../sdds-serv-docs/docs/components/Switch.mdx | 2 +- website/sdds-serv-docs/docusaurus.config.js | 11 +++--- .../src/components/PropsTable.tsx | 9 +++-- 29 files changed, 255 insertions(+), 117 deletions(-) create mode 100644 utils/plasma-docs-ui/README.md diff --git a/packages/caldera-online/api/caldera-online.api.md b/packages/caldera-online/api/caldera-online.api.md index 19ae6f8328..1d6b662074 100644 --- a/packages/caldera-online/api/caldera-online.api.md +++ b/packages/caldera-online/api/caldera-online.api.md @@ -33,7 +33,7 @@ import { dsplMBold } from '@salutejs/caldera-online-themes/tokens'; import { dsplS } from '@salutejs/caldera-online-themes/tokens'; import { dsplSBold } from '@salutejs/caldera-online-themes/tokens'; import { Filter } from '@salutejs/plasma-new-hope/types/engines/types'; -import { ForwardRefExoticComponent } from 'react'; +import type { ForwardRefExoticComponent } from 'react'; import { FunctionComponent } from 'react'; import { h1 } from '@salutejs/caldera-online-themes/tokens'; import { h1Bold } from '@salutejs/caldera-online-themes/tokens'; @@ -68,7 +68,7 @@ import { ShowToastArgs } from '@salutejs/plasma-new-hope/styled-components'; import { SpacingProps } from '@salutejs/plasma-new-hope/styled-components'; import { SSRProvider } from '@salutejs/plasma-new-hope/styled-components'; import { StyledComponent } from 'styled-components'; -import type { SwitchProps } from '@salutejs/plasma-core'; +import { SwitchProps as SwitchProps_2 } from '@salutejs/plasma-new-hope/styled-components'; import { textL } from '@salutejs/caldera-online-themes/tokens'; import { textLBold } from '@salutejs/caldera-online-themes/tokens'; import { textM } from '@salutejs/caldera-online-themes/tokens'; @@ -581,11 +581,29 @@ export type SpinnerProps = HTMLAttributes & { export { SSRProvider } // @public (undocumented) -export const Switch: ForwardRefExoticComponent< { -defaultChecked: boolean; -} & SwitchProps & RefAttributes>; +export const Switch: FunctionComponent & SwitchProps_2 & RefAttributes>; -export { SwitchProps } +// Warning: (ae-forgotten-export) The symbol "SwitchComponent" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export type SwitchProps = ComponentProps; // @public (undocumented) export const TextL: FunctionComponent ->; -export type { SwitchProps }; +export const Switch = SwitchComponent; +export type SwitchProps = ComponentProps; diff --git a/packages/plasma-asdk/api/plasma-asdk.api.md b/packages/plasma-asdk/api/plasma-asdk.api.md index fd5298178d..28547221df 100644 --- a/packages/plasma-asdk/api/plasma-asdk.api.md +++ b/packages/plasma-asdk/api/plasma-asdk.api.md @@ -14,7 +14,6 @@ import { ButtonHTMLAttributes } from 'react'; import { CheckboxProps as CheckboxProps_2 } from '@salutejs/plasma-new-hope/types/components/Checkbox/Checkbox.types'; import { ComponentProps } from 'react'; import { Filter } from '@salutejs/plasma-new-hope/types/engines/types'; -import { ForwardRefExoticComponent } from 'react'; import { FunctionComponent } from 'react'; import { HTMLAttributes } from 'react'; import { InputHTMLAttributes } from '@salutejs/plasma-new-hope/types/types'; @@ -27,7 +26,7 @@ import { SpacingProps } from '@salutejs/plasma-new-hope/styled-components'; import { SSRProvider } from '@salutejs/plasma-new-hope/styled-components'; import { StyledComponent } from 'styled-components'; import { SubtitleProps } from '@salutejs/plasma-new-hope/styled-components'; -import type { SwitchProps } from '@salutejs/plasma-core'; +import { SwitchProps as SwitchProps_2 } from '@salutejs/plasma-new-hope/styled-components'; import { TypographyOldProps } from '@salutejs/plasma-new-hope/types/components/Typography/Old/TypographyOld'; // @public (undocumented) @@ -437,11 +436,29 @@ m: string; }> & SubtitleProps & RefAttributes>; // @public (undocumented) -export const Switch: ForwardRefExoticComponent< { -defaultChecked: boolean; -} & SwitchProps & RefAttributes>; +export const Switch: FunctionComponent & SwitchProps_2 & RefAttributes>; -export { SwitchProps } +// Warning: (ae-forgotten-export) The symbol "SwitchComponent" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export type SwitchProps = ComponentProps; // @public (undocumented) export const TextL: FunctionComponent ->; -export type { SwitchProps }; +export const Switch = SwitchComponent; +export type SwitchProps = ComponentProps; diff --git a/packages/plasma-b2c/api/plasma-b2c.api.md b/packages/plasma-b2c/api/plasma-b2c.api.md index 2d92b82551..f5ffda7195 100644 --- a/packages/plasma-b2c/api/plasma-b2c.api.md +++ b/packages/plasma-b2c/api/plasma-b2c.api.md @@ -228,7 +228,7 @@ import { StyledCard } from '@salutejs/plasma-hope'; import { StyledComponent } from 'styled-components'; import { StyledPreviewGallery } from '@salutejs/plasma-hope'; import { SubtitleProps } from '@salutejs/plasma-new-hope/styled-components'; -import type { SwitchProps } from '@salutejs/plasma-core'; +import { SwitchProps as SwitchProps_2 } from '@salutejs/plasma-new-hope/styled-components'; import { syntheticFocus } from '@salutejs/plasma-core'; import { TabItemProps } from '@salutejs/plasma-new-hope/styled-components'; import { TabItemRefs } from '@salutejs/plasma-new-hope/styled-components'; @@ -1873,11 +1873,29 @@ m: string; }> & SubtitleProps & RefAttributes>; // @public (undocumented) -export const Switch: ForwardRefExoticComponent< { -defaultChecked: boolean; -} & SwitchProps & RefAttributes>; +export const Switch: FunctionComponent & SwitchProps_2 & RefAttributes>; -export { SwitchProps } +// Warning: (ae-forgotten-export) The symbol "SwitchComponent" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export type SwitchProps = ComponentProps; export { syntheticFocus } diff --git a/packages/plasma-b2c/src/components/Switch/Switch.tsx b/packages/plasma-b2c/src/components/Switch/Switch.tsx index 6ecd843892..db87cda862 100644 --- a/packages/plasma-b2c/src/components/Switch/Switch.tsx +++ b/packages/plasma-b2c/src/components/Switch/Switch.tsx @@ -1,16 +1,10 @@ import { switchConfig, component, mergeConfig } from '@salutejs/plasma-new-hope/styled-components'; -import type { SwitchProps } from '@salutejs/plasma-core'; +import { ComponentProps } from 'react'; import { config } from './Switch.config'; -type SwitchPropsCustom = { - defaultChecked: boolean; -} & SwitchProps; - const mergedConfig = mergeConfig(switchConfig, config); const SwitchComponent = component(mergedConfig); -export const Switch = SwitchComponent as React.ForwardRefExoticComponent< - SwitchPropsCustom & React.RefAttributes ->; -export type { SwitchProps }; +export const Switch = SwitchComponent; +export type SwitchProps = ComponentProps; diff --git a/packages/plasma-new-hope/src/components/Switch/Switch.tsx b/packages/plasma-new-hope/src/components/Switch/Switch.tsx index 9dff82d31c..a72c077df8 100644 --- a/packages/plasma-new-hope/src/components/Switch/Switch.tsx +++ b/packages/plasma-new-hope/src/components/Switch/Switch.tsx @@ -30,6 +30,7 @@ export const switchRoot = (Root: RootProps) => size, view, focused, + outlined, disabled, labelPosition, @@ -42,12 +43,13 @@ export const switchRoot = (Root: RootProps) => // singleLine, checked, + pressed, defaultChecked, ...rest } = props; - const exactChecked = Boolean(checked !== undefined ? checked : defaultChecked); + const exactChecked = Boolean((checked ?? pressed) !== undefined ? checked ?? pressed : defaultChecked); // const singleLineClass = singleLine ? 'single-line' : ''; return ( @@ -55,7 +57,7 @@ export const switchRoot = (Root: RootProps) => view={view} size={size} disabled={disabled} - focused={focused} + focused={focused ?? outlined} labelPosition={labelPosition} id={id} style={style} @@ -67,7 +69,7 @@ export const switchRoot = (Root: RootProps) => role="switch" aria-checked={exactChecked} type="checkbox" - checked={checked} + checked={checked ?? pressed} defaultChecked={defaultChecked} disabled={disabled} /> diff --git a/packages/plasma-new-hope/src/components/Switch/Switch.types.ts b/packages/plasma-new-hope/src/components/Switch/Switch.types.ts index 5a9d51e7d2..4190a832b9 100644 --- a/packages/plasma-new-hope/src/components/Switch/Switch.types.ts +++ b/packages/plasma-new-hope/src/components/Switch/Switch.types.ts @@ -1,6 +1,4 @@ -import { InputHTMLAttributes } from 'react'; - -import { Filter } from '../../engines/types'; +import type { InputHTMLAttributes } from '../../types'; export interface SwitchPropsPropsBase { /** @@ -23,7 +21,22 @@ export interface SwitchPropsVariations extends SwitchPropsPropsBase { */ labelPosition?: 'before' | 'after'; + /** + * Добавить рамку при фокусе + */ focused?: boolean; + + /** + * Нажатие на компонент + * @deprecated + */ + pressed?: boolean; + + /** + * Добавить рамку при фокусе + * @deprecated + */ + outlined?: boolean; } -export type SwitchProps = Filter, 'size'> & SwitchPropsVariations; +export interface SwitchProps extends Omit, 'size'>, SwitchPropsVariations {} diff --git a/packages/plasma-new-hope/src/components/Switch/index.ts b/packages/plasma-new-hope/src/components/Switch/index.ts index 4bff847061..ddb8f3ff95 100644 --- a/packages/plasma-new-hope/src/components/Switch/index.ts +++ b/packages/plasma-new-hope/src/components/Switch/index.ts @@ -3,6 +3,7 @@ import { labelPosition_Before } from './_label-position/before'; export { switchRoot, switchConfig } from './Switch'; export { tokens as switchTokens } from './Switch.tokens'; +export type { SwitchProps } from './Switch.types'; // TODO: Think how we could name such things export { labelPosition_Before as Switch_LabelPosition_Before }; diff --git a/packages/plasma-web/api/plasma-web.api.md b/packages/plasma-web/api/plasma-web.api.md index 7447d16086..809ffa7794 100644 --- a/packages/plasma-web/api/plasma-web.api.md +++ b/packages/plasma-web/api/plasma-web.api.md @@ -228,7 +228,7 @@ import { StyledCard } from '@salutejs/plasma-hope'; import { StyledComponent } from 'styled-components'; import { StyledPreviewGallery } from '@salutejs/plasma-hope'; import { SubtitleProps } from '@salutejs/plasma-new-hope/styled-components'; -import type { SwitchProps } from '@salutejs/plasma-core'; +import { SwitchProps as SwitchProps_2 } from '@salutejs/plasma-new-hope/styled-components'; import { syntheticFocus } from '@salutejs/plasma-core'; import { TabItemProps } from '@salutejs/plasma-new-hope/styled-components'; import { TabItemRefs } from '@salutejs/plasma-new-hope/styled-components'; @@ -1875,11 +1875,29 @@ m: string; }> & SubtitleProps & RefAttributes>; // @public (undocumented) -export const Switch: ForwardRefExoticComponent< { -defaultChecked: boolean; -} & SwitchProps & RefAttributes>; +export const Switch: FunctionComponent & SwitchProps_2 & RefAttributes>; -export { SwitchProps } +// Warning: (ae-forgotten-export) The symbol "SwitchComponent" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export type SwitchProps = ComponentProps; export { syntheticFocus } diff --git a/packages/plasma-web/src/components/Switch/Switch.tsx b/packages/plasma-web/src/components/Switch/Switch.tsx index 6ecd843892..db87cda862 100644 --- a/packages/plasma-web/src/components/Switch/Switch.tsx +++ b/packages/plasma-web/src/components/Switch/Switch.tsx @@ -1,16 +1,10 @@ import { switchConfig, component, mergeConfig } from '@salutejs/plasma-new-hope/styled-components'; -import type { SwitchProps } from '@salutejs/plasma-core'; +import { ComponentProps } from 'react'; import { config } from './Switch.config'; -type SwitchPropsCustom = { - defaultChecked: boolean; -} & SwitchProps; - const mergedConfig = mergeConfig(switchConfig, config); const SwitchComponent = component(mergedConfig); -export const Switch = SwitchComponent as React.ForwardRefExoticComponent< - SwitchPropsCustom & React.RefAttributes ->; -export type { SwitchProps }; +export const Switch = SwitchComponent; +export type SwitchProps = ComponentProps; diff --git a/packages/sdds-serv/api/sdds-serv.api.md b/packages/sdds-serv/api/sdds-serv.api.md index ea83c21dd0..556ea0b79b 100644 --- a/packages/sdds-serv/api/sdds-serv.api.md +++ b/packages/sdds-serv/api/sdds-serv.api.md @@ -131,7 +131,7 @@ import { SpacingProps } from '@salutejs/plasma-new-hope/styled-components'; import { SSRProvider } from '@salutejs/plasma-new-hope/styled-components'; import { StatusLabels } from '@salutejs/plasma-new-hope/types/components/Avatar/Avatar.types'; import { StyledComponent } from 'styled-components'; -import type { SwitchProps } from '@salutejs/plasma-core'; +import { SwitchProps as SwitchProps_2 } from '@salutejs/plasma-new-hope/styled-components'; import { TabItemProps } from '@salutejs/plasma-new-hope/styled-components'; import { TabItemRefs } from '@salutejs/plasma-new-hope/styled-components'; import { TabsContext } from '@salutejs/plasma-new-hope/styled-components'; @@ -1387,11 +1387,29 @@ export type SpinnerProps = HTMLAttributes & { export { SSRProvider } // @public (undocumented) -export const Switch: ForwardRefExoticComponent< { -defaultChecked: boolean; -} & SwitchProps & RefAttributes>; +export const Switch: FunctionComponent & SwitchProps_2 & RefAttributes>; -export { SwitchProps } +// Warning: (ae-forgotten-export) The symbol "SwitchComponent" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export type SwitchProps = ComponentProps; // @public export const TabItem: FunctionComponent ->; -export type { SwitchProps }; +export const Switch = SwitchComponent; +export type SwitchProps = ComponentProps; diff --git a/scaffold/template-docs/docusaurus.config.js b/scaffold/template-docs/docusaurus.config.js index 36de28a9ff..bf20a5f875 100644 --- a/scaffold/template-docs/docusaurus.config.js +++ b/scaffold/template-docs/docusaurus.config.js @@ -100,16 +100,16 @@ const config = { ], plugins: [ function docgenPlugin() { + // Плагин генерации документации return { name: 'docusaurus-plugin-react-docgen-typescript', async loadContent() { + // Загрузка компонентов для документации return withCustomConfig('./tsconfig.json', { shouldExtractLiteralValuesFromEnum: true, shouldRemoveUndefinedFromOptional: true, - propFilter: (prop) => { - if (prop.parent) { - return !prop.parent.fileName.includes('@types/react'); - } + propFilter: () => { + // Функция обрезки типов return true; }, }).parse( @@ -133,6 +133,7 @@ const config = { }; }, async contentLoaded({ content, actions }) { + // Генерация массива типов const names = []; content .filter((module) => { @@ -154,7 +155,7 @@ const config = { `${component.displayName}.json`, JSON.stringify({ props: Object.entries(component.props).reduce( - (acc, [key, { declarations, parent, ...rest }]) => ({ + (acc, [key, { declarations, ...rest }]) => ({ ...acc, [key]: rest, }), diff --git a/utils/plasma-docs-ui/README.md b/utils/plasma-docs-ui/README.md new file mode 100644 index 0000000000..02ba536788 --- /dev/null +++ b/utils/plasma-docs-ui/README.md @@ -0,0 +1,37 @@ +### Описание работы документации + +В файле docusaurus.config.js в каждой из библиотек, задаются функции, которые собирают, фильтруют типы и на их основе генерируют json файлы. ( В файле более подробно ) + +Хук useDynamicImport - динамически импорирует нужный json файл + +### Работа PropsTable + +PropsTable.tsx - Вывод типов и их форматирование ( Подробнее в файле компонента ) + +В файл поступает 3 параметра: + +- Props: Object[] +- Exlude: String[] +- Include: String: [] + +Props: Массив объектов, где есть два ключа: + +- Key: название параметра +- Prop: Информация об параметре + +### Использование + +```jsx +import React, { FC } from 'react'; +import { PropsTable } from '@salutejs/plasma-docs-ui'; + +function App({ props }) { + return ( +
+ +
+ ); +} + +export default App; +``` diff --git a/utils/plasma-docs-ui/src/components/PropsTable.tsx b/utils/plasma-docs-ui/src/components/PropsTable.tsx index c58aa09a95..e1fbc2338c 100644 --- a/utils/plasma-docs-ui/src/components/PropsTable.tsx +++ b/utils/plasma-docs-ui/src/components/PropsTable.tsx @@ -6,6 +6,7 @@ import type { ComponentProps, ComponentProp } from '../types'; export interface PropsTableProps extends HTMLAttributes { props: ComponentProps; exclude?: string[]; + include?: string[]; } const defaultExclude = ['forwardedAs', 'as', 'theme', 'ref']; @@ -13,13 +14,21 @@ const defaultExclude = ['forwardedAs', 'as', 'theme', 'ref']; /** * Компонент для вывода таблицы пропсов. */ -export const PropsTable: FC = ({ props, exclude: propsExclude = [] }) => { +export const PropsTable: FC = ({ props, exclude: propsExclude = [], include }) => { const filteredPropsList = useMemo(() => { if (!props) { return null; } const exclude = propsExclude.concat(defaultExclude); - return Object.entries(props).filter((entry) => !exclude.includes(entry[0])); + return Object.entries(props) + .map((item) => { + return { + key: item[0], // Ключ параметра + prop: item[1], // Информация о параметре + }; + }) + .filter((type) => !type?.prop?.parent?.fileName?.includes('@types/react') || include?.includes(type.key)) // Обрезаются стандартные типы из react, если они указаны в include, то они не обрезаются + .filter((type) => !exclude.includes(type.key)); // Обрезаются типы, которые указаны в exclude }, [props, propsExclude]); if (!filteredPropsList?.length) { @@ -49,7 +58,7 @@ export const PropsTable: FC = ({ props, exclude: propsExclude = - {filteredPropsList.map(([key, prop]) => { + {filteredPropsList.map(({ key, prop }) => { return ( diff --git a/utils/plasma-docs-ui/src/types/DocgenInfo.ts b/utils/plasma-docs-ui/src/types/DocgenInfo.ts index a07bd01c97..77e1977151 100644 --- a/utils/plasma-docs-ui/src/types/DocgenInfo.ts +++ b/utils/plasma-docs-ui/src/types/DocgenInfo.ts @@ -7,6 +7,10 @@ export interface ComponentProp { defaultValue?: any; description?: string; required?: boolean; + parent?: { + name?: string; + fileName?: string; + }; } export type ComponentProps = Record; export interface ComponentDocgenInfo { diff --git a/website/plasma-ui-docs/docusaurus.config.js b/website/plasma-ui-docs/docusaurus.config.js index 92f1296be1..340f39b5e6 100644 --- a/website/plasma-ui-docs/docusaurus.config.js +++ b/website/plasma-ui-docs/docusaurus.config.js @@ -138,17 +138,17 @@ module.exports = { ], plugins: [ function docgenPlugin() { + // Плагин генерации документации return { name: 'docusaurus-plugin-react-docgen-typescript', async loadContent() { + // Загрузка компонентов для документации return docgen .withCustomConfig('./tsconfig.json', { shouldExtractLiteralValuesFromEnum: true, shouldRemoveUndefinedFromOptional: true, - propFilter: (prop) => { - if (prop.parent) { - return !prop.parent.fileName.includes('@types/react'); - } + propFilter: () => { + // Функция обрезки типов return true; }, }) @@ -173,6 +173,7 @@ module.exports = { }; }, async contentLoaded({ content, actions }) { + // Генерация массива типов const names = []; content .filter((module) => { @@ -194,7 +195,7 @@ module.exports = { `${component.displayName}.json`, JSON.stringify({ props: Object.entries(component.props).reduce( - (acc, [key, { declarations, parent, ...rest }]) => ({ + (acc, [key, { declarations, ...rest }]) => ({ ...acc, [key]: rest, }), diff --git a/website/plasma-ui-docs/src/components/PropsTable.tsx b/website/plasma-ui-docs/src/components/PropsTable.tsx index 972578e1da..9802697017 100644 --- a/website/plasma-ui-docs/src/components/PropsTable.tsx +++ b/website/plasma-ui-docs/src/components/PropsTable.tsx @@ -3,12 +3,15 @@ import { PropsTable as PropsTableView } from '@salutejs/plasma-docs-ui'; import { useDynamicImport } from '../hooks'; -export const PropsTable: FC<{ name: string; exclude?: string[] }> = ({ name, exclude }) => { +export const PropsTable: FC<{ name: string; exclude?: string[]; include?: string[] }> = ({ + name, + exclude, + include, +}) => { const { props } = useDynamicImport('@docgen', name); - if (!props) { return null; } - return ; + return ; }; diff --git a/website/plasma-web-docs/docs/components/Checkbox.mdx b/website/plasma-web-docs/docs/components/Checkbox.mdx index a95a6ec53b..6bb7c211eb 100644 --- a/website/plasma-web-docs/docs/components/Checkbox.mdx +++ b/website/plasma-web-docs/docs/components/Checkbox.mdx @@ -7,7 +7,7 @@ import { PropsTable, Description, StorybookLink } from '@site/src/components'; # Checkbox - + ## Использование diff --git a/website/plasma-web-docs/docs/components/Radiobox.mdx b/website/plasma-web-docs/docs/components/Radiobox.mdx index d7e8bd2ceb..ca6ec49209 100644 --- a/website/plasma-web-docs/docs/components/Radiobox.mdx +++ b/website/plasma-web-docs/docs/components/Radiobox.mdx @@ -7,7 +7,7 @@ import { PropsTable, Description, StorybookLink } from '@site/src/components'; # Radiobox - + ## Использование diff --git a/website/plasma-web-docs/docs/components/Switch.mdx b/website/plasma-web-docs/docs/components/Switch.mdx index 402e678d53..1297499431 100644 --- a/website/plasma-web-docs/docs/components/Switch.mdx +++ b/website/plasma-web-docs/docs/components/Switch.mdx @@ -7,7 +7,7 @@ import { PropsTable, Description, StorybookLink } from '@site/src/components'; # Switch - + ## Использование diff --git a/website/plasma-web-docs/docusaurus.config.js b/website/plasma-web-docs/docusaurus.config.js index fee46d9436..f9b91fc407 100644 --- a/website/plasma-web-docs/docusaurus.config.js +++ b/website/plasma-web-docs/docusaurus.config.js @@ -138,17 +138,17 @@ module.exports = { ], plugins: [ function docgenPlugin() { + // Плагин генерации документации return { name: 'docusaurus-plugin-react-docgen-typescript', async loadContent() { + // Загрузка компонентов для документации return docgen .withCustomConfig('./tsconfig.json', { shouldExtractLiteralValuesFromEnum: true, shouldRemoveUndefinedFromOptional: true, - propFilter: (prop) => { - if (prop.parent) { - return !prop.parent.fileName.includes('@types/react'); - } + propFilter: () => { + // Функция обрезки типов return true; }, }) @@ -175,6 +175,7 @@ module.exports = { }; }, async contentLoaded({ content, actions }) { + // Генерация массива типов const names = []; content .filter((module) => { @@ -196,7 +197,7 @@ module.exports = { `${component.displayName}.json`, JSON.stringify({ props: Object.entries(component.props).reduce( - (acc, [key, { declarations, parent, ...rest }]) => ({ + (acc, [key, { declarations, ...rest }]) => ({ ...acc, [key]: rest, }), diff --git a/website/plasma-web-docs/src/components/PropsTable.tsx b/website/plasma-web-docs/src/components/PropsTable.tsx index 972578e1da..9802697017 100644 --- a/website/plasma-web-docs/src/components/PropsTable.tsx +++ b/website/plasma-web-docs/src/components/PropsTable.tsx @@ -3,12 +3,15 @@ import { PropsTable as PropsTableView } from '@salutejs/plasma-docs-ui'; import { useDynamicImport } from '../hooks'; -export const PropsTable: FC<{ name: string; exclude?: string[] }> = ({ name, exclude }) => { +export const PropsTable: FC<{ name: string; exclude?: string[]; include?: string[] }> = ({ + name, + exclude, + include, +}) => { const { props } = useDynamicImport('@docgen', name); - if (!props) { return null; } - return ; + return ; }; diff --git a/website/sdds-serv-docs/docs/components/Checkbox.mdx b/website/sdds-serv-docs/docs/components/Checkbox.mdx index 38e8fdf1a5..54c4368e1d 100644 --- a/website/sdds-serv-docs/docs/components/Checkbox.mdx +++ b/website/sdds-serv-docs/docs/components/Checkbox.mdx @@ -7,7 +7,7 @@ import { PropsTable, Description } from '@site/src/components'; # Checkbox - + ## Использование Компонент `Checkbox` может содержать лейбл и описание. diff --git a/website/sdds-serv-docs/docs/components/Radiobox.mdx b/website/sdds-serv-docs/docs/components/Radiobox.mdx index a66dd9b67a..0f7791cf49 100644 --- a/website/sdds-serv-docs/docs/components/Radiobox.mdx +++ b/website/sdds-serv-docs/docs/components/Radiobox.mdx @@ -7,7 +7,7 @@ import { PropsTable, Description } from '@site/src/components'; # Radiobox - + ## Использование Компонент `Radiobox` может содержать лейбл и описание. diff --git a/website/sdds-serv-docs/docs/components/Switch.mdx b/website/sdds-serv-docs/docs/components/Switch.mdx index 3d2b79d843..95b6207ec8 100644 --- a/website/sdds-serv-docs/docs/components/Switch.mdx +++ b/website/sdds-serv-docs/docs/components/Switch.mdx @@ -7,7 +7,7 @@ import { PropsTable, Description } from '@site/src/components'; # Switch - + ## Использование Компонент `Switch` может содержать лейбл. diff --git a/website/sdds-serv-docs/docusaurus.config.js b/website/sdds-serv-docs/docusaurus.config.js index b52ea8f546..f1370c9022 100644 --- a/website/sdds-serv-docs/docusaurus.config.js +++ b/website/sdds-serv-docs/docusaurus.config.js @@ -101,17 +101,17 @@ module.exports = { ], plugins: [ function docgenPlugin() { + // Плагин генерации документации return { name: 'docusaurus-plugin-react-docgen-typescript', + // Загрузка компонентов для документации async loadContent() { return docgen .withCustomConfig('./tsconfig.json', { shouldExtractLiteralValuesFromEnum: true, shouldRemoveUndefinedFromOptional: true, - propFilter: (prop) => { - if (prop.parent) { - return !prop.parent.fileName.includes('@types/react'); - } + propFilter: () => { + // Функция обрезки типов return true; }, }) @@ -136,6 +136,7 @@ module.exports = { }; }, async contentLoaded({ content, actions }) { + // Генерация массива типов const names = []; content .filter((module) => { @@ -157,7 +158,7 @@ module.exports = { `${component.displayName}.json`, JSON.stringify({ props: Object.entries(component.props).reduce( - (acc, [key, { declarations, parent, ...rest }]) => ({ + (acc, [key, { declarations, ...rest }]) => ({ ...acc, [key]: rest, }), diff --git a/website/sdds-serv-docs/src/components/PropsTable.tsx b/website/sdds-serv-docs/src/components/PropsTable.tsx index 972578e1da..9802697017 100644 --- a/website/sdds-serv-docs/src/components/PropsTable.tsx +++ b/website/sdds-serv-docs/src/components/PropsTable.tsx @@ -3,12 +3,15 @@ import { PropsTable as PropsTableView } from '@salutejs/plasma-docs-ui'; import { useDynamicImport } from '../hooks'; -export const PropsTable: FC<{ name: string; exclude?: string[] }> = ({ name, exclude }) => { +export const PropsTable: FC<{ name: string; exclude?: string[]; include?: string[] }> = ({ + name, + exclude, + include, +}) => { const { props } = useDynamicImport('@docgen', name); - if (!props) { return null; } - return ; + return ; };