Skip to content

Commit

Permalink
feat(plasma-docs-ui): Update types for props keys
Browse files Browse the repository at this point in the history
  • Loading branch information
neretin-trike committed Sep 27, 2023
1 parent fca1d88 commit 598d486
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
16 changes: 14 additions & 2 deletions utils/plasma-docs-ui/src/components/PropsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC, HTMLAttributes, useMemo } from 'react';
import marked from 'marked';

import type { ComponentProps } from '../types';
import type { ComponentProps, ComponentProp } from '../types';

export interface PropsTableProps extends HTMLAttributes<HTMLTableElement> {
props: ComponentProps;
Expand All @@ -26,6 +26,18 @@ export const PropsTable: FC<PropsTableProps> = ({ props, exclude: propsExclude =
return null;
}

const getType = (type?: ComponentProp['type']) => {
if (!type) {
return '';
}

if (type.raw && type.value) {
return type.raw;
}

return type.name;
};

return (
<table>
<thead>
Expand All @@ -47,7 +59,7 @@ export const PropsTable: FC<PropsTableProps> = ({ props, exclude: propsExclude =
</code>
</td>
<td>
<code>{prop.type?.name}</code>
<code>{getType(prop.type)}</code>
</td>
<td>{prop.defaultValue && <code>{prop.defaultValue.value}</code>}</td>
<td dangerouslySetInnerHTML={{ __html: marked(prop.description || '') }} />
Expand Down
4 changes: 3 additions & 1 deletion utils/plasma-docs-ui/src/types/DocgenInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
interface ComponentProp {
export interface ComponentProp {
type: {
name: string;
raw: string;
value: any[];
};
defaultValue?: any;
description?: string;
Expand Down
2 changes: 1 addition & 1 deletion utils/plasma-docs-ui/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type { ComponentProps, ComponentDocgenInfo, DocgenInfo } from './DocgenInfo';
export type { ComponentProps, ComponentProp, ComponentDocgenInfo, DocgenInfo } from './DocgenInfo';
4 changes: 2 additions & 2 deletions website/plasma-web-docs/docs/components/Link.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PropsTable, Description, StorybookLink } from '@site/src/components';

# Link
<Description name="Link" />
<PropsTable name="Link" exclude={['$isHover', '$isPressed', '$isVisited']} />
<PropsTable name="Link" exclude={['css', 'focused']} />
<StorybookLink name="Link" />

```tsx live
Expand All @@ -17,7 +17,7 @@ import { P1, Link } from '@salutejs/plasma-web';
export function App() {
return (
<P1>
Скачайте <Link href="/" target="__blank">приложение</Link>.
Скачайте <Link href="/" target="_blank">приложение</Link>.
</P1>
);
}
Expand Down

0 comments on commit 598d486

Please sign in to comment.