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

fix(docs:styleguidist): Некостыльный @deprecated и другие фиксы для стайлгайда #4701

Merged
merged 3 commits into from
Apr 4, 2023
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
26 changes: 13 additions & 13 deletions styleguide/Components/ReactComponent/ReactComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Markdown from '@rsg-components/Markdown';
import Slot from '@rsg-components/Slot';
import { Caption, classNames, Link } from '@vkui';
import { VKUI_PACKAGE } from '../../../shared';
import { deprecated } from '../../deprecated';
import { getDeprecatedFromComponentTags } from '../../utils';
import Heading from '../Heading/index';
import { SectionSubheading } from '../SectionSubheading/SectionSubheading';
import './ReactComponent.css';
Expand All @@ -15,10 +15,7 @@ const toKebabCase = (str) =>
const ReactComponent = ({ component, exampleMode }) => {
const { name, visibleName, pathLine } = component;
const { description = '', examples = [] } = component.props || {};
const isDeprecated = deprecated.includes(name);

const showPropsPlaceholder =
process.env.NODE_ENV === 'development' && process.env.VKUI_STYLEGUIDE_PROPSPARSER !== 1;
const deprecated = getDeprecatedFromComponentTags(component);

const githubTag = `cmp:${toKebabCase(visibleName)}`;
const issuesQuery = `is:open is:issue label:${githubTag}`;
Expand Down Expand Up @@ -46,23 +43,26 @@ const ReactComponent = ({ component, exampleMode }) => {
<Heading
level={1}
className={classNames('ReactComponent__name', {
'ReactComponent__name--deprecated': isDeprecated,
'ReactComponent__name--deprecated': deprecated.isDeprecated,
})}
>
{visibleName}
</Heading>
{deprecated.description && (
<Text Component="blockquote" className="Blockquote">
<Markdown text={`**@deprecated**: ${deprecated.description}`} />
</Text>
)}
{description && <Markdown text={description} />}
{examples.length > 0 && (
<Examples examples={examples} name={name} exampleMode={exampleMode} />
)}
<SectionSubheading href={`#/${name}?id=props`}>Свойства и методы</SectionSubheading>
{showPropsPlaceholder ? (
<blockquote className="Blockquote">
<Text>
В режиме разработки свойства и методы не генерируются по умолчанию. Если они вам
необходимы, воспользуйтесь командой <span className="Code">yarn styleguide:props</span>.
</Text>
</blockquote>
{process.env.NODE_ENV === 'development' && process.env.VKUI_STYLEGUIDE_PROPSPARSER !== 1 ? (
<Text Component="blockquote" className="Blockquote">
В режиме разработки свойства и методы не генерируются по умолчанию. Если они вам нужны,
воспользуйтесь командой <code className="Code">yarn docs:styleguide:props</code>.
</Text>
) : (
<Slot name="docsTabs" props={component} />
)}
Expand Down
4 changes: 2 additions & 2 deletions styleguide/Components/Table/TableRenderer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { createContext, Fragment, useContext, useEffect, useRef, useState } from 'react';
import { Icon16MoreHorizontal, Icon16Up } from '@vkontakte/icons';
import { Icon20HideOutline, Icon20ViewOutline } from '@vkontakte/icons';
import { noop, throttle } from '@vkontakte/vkjs';
import { classNames, Text, useAppearance } from '@vkui';
import NameRenderer from '../Name/NameRenderer';
Expand Down Expand Up @@ -95,7 +95,7 @@ export const TableRenderer = ({ columns, rows, getRowKey }) => {
<tr className="Table__tr">
<td className="Table__td" colSpan={columns.length}>
<TogglePropsButton
before={expanded ? <Icon16Up /> : <Icon16MoreHorizontal />}
before={expanded ? <Icon20HideOutline /> : <Icon20ViewOutline />}
onClick={() => toggleExpanded(!expanded)}
>
{expanded ? (
Expand Down
22 changes: 12 additions & 10 deletions styleguide/Components/TableOfContents/TableOfContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
SimpleCell,
useAdaptivityWithJSMediaQueries,
} from '@vkui';
import { deprecated } from '../../deprecated';
import { unstable } from '../../unstable';
import { getDeprecatedFromComponentTags } from '../../utils';
import './TableOfContents.css';

function capitalize(string = '') {
Expand Down Expand Up @@ -53,33 +53,37 @@ const normalizer = (sections) => {
return sections.map(
({
name,
title,
content,
sections: childrenSections = [],
href,
components = [],
expand = false,
search,
deprecated = false,
...restProps
}) => {
const children = normalizer([
...childrenSections,
...components.map((component) => {
const { isDeprecated } = getDeprecatedFromComponentTags(component);

return {
name: component.name,
title: component.title,
href: component.href,
content: component.filepath,
deprecated: isDeprecated,
};
}),
]);

return {
title,
name,
content,
sections: children,
href: content && `#/${name}`,
expand,
search,
sections: children,
deprecated,
...restProps,
};
},
);
Expand Down Expand Up @@ -245,7 +249,7 @@ class TableOfContents extends React.PureComponent {
)}
</IconButton>
)) ||
(unstable.includes(section.name) && !deprecated.includes(section.name) && (
(unstable.includes(section.name) && (
<Icon28WarningTriangleOutline
fill="var(--vkui--color_accent_orange)"
title="Компонент является нестабильным"
Expand All @@ -258,9 +262,7 @@ class TableOfContents extends React.PureComponent {
'TableOfContents__section--selected':
section.name === this.state.currentSectionName,
})}
indicator={
deprecated.includes(section.name) && <Caption level="2">deprecated</Caption>
}
indicator={section.deprecated && <Caption level="2">deprecated</Caption>}
>
{section.title || section.name}
</SimpleCell>
Expand Down
1 change: 0 additions & 1 deletion styleguide/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const baseConfig = {
},
},
},
propsParser: () => ({}),
exampleMode: 'expand',
sections: [
{
Expand Down
3 changes: 0 additions & 3 deletions styleguide/deprecated.js

This file was deleted.

14 changes: 14 additions & 0 deletions styleguide/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,18 @@ export const perfLogger = {
},
};

export const getDeprecatedFromComponentTags = (component) => {
const { deprecated } = component?.props?.tags || {};

const description =
process.env.NODE_ENV === 'development' && process.env.VKUI_STYLEGUIDE_PROPSPARSER !== 1
? deprecated?.[0]?.description // baseConfig
: deprecated; // prodConfig

return {
isDeprecated: !!deprecated,
description,
};
};

export * from './useViewPortSize';