Skip to content

Commit

Permalink
TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Nov 25, 2024
1 parent a66aac5 commit 1372f28
Show file tree
Hide file tree
Showing 11 changed files with 911 additions and 596 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
label: 'Data grid'
collapsed: true
position: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { useMemo, FC, ReactNode } from 'react';
import {
EuiBasicTable,
EuiBasicTableColumn,
EuiMarkdownFormat,
getDefaultEuiMarkdownPlugins,
EuiCodeBlock,
EuiLink,
EuiSpacer,
} from '@elastic/eui';
import { ProcessedComponent } from '@elastic/eui-docgen';

type DataGridPropSnippetTableProps = {
propSnippetMap: Record<string, string | ReactNode>;
linksMap?: Record<string, string>;
docgen: ProcessedComponent;
};

const { processingPlugins, parsingPlugins } = getDefaultEuiMarkdownPlugins({
exclude: ['lineBreaks'],
});

const columns: Array<EuiBasicTableColumn<{}>> = [
{
name: 'Prop',
render: ({ propName, propDescription }) => (
<>
{propName}
{propDescription && (
<>
<EuiSpacer size="s" />
<EuiMarkdownFormat
textSize="s"
processingPluginList={processingPlugins}
parsingPluginList={parsingPlugins}
>
{propDescription}
</EuiMarkdownFormat>
</>
)}
</>
),
textOnly: true,
valign: 'top',
},
{
field: 'snippet',
name: 'Sample snippet',
render: (snippet: string | ReactNode) =>
typeof snippet === 'string' ? (
<EuiCodeBlock
fontSize="s"
paddingSize="s"
className="eui-fullWidth"
isCopyable
language="tsx"
>
{snippet}
</EuiCodeBlock>
) : (
snippet
),
valign: 'top',
},
];

export const DataGridPropSnippetTable: FC<DataGridPropSnippetTableProps> = ({
propSnippetMap,
linksMap,
docgen,
}) => {
const items = useMemo(
() =>
Object.entries(propSnippetMap).map(([prop, snippet]) => {
const propLink = linksMap?.[prop];
const propName = propLink ? (
<EuiLink href={propLink}>
<strong>{prop}</strong>
</EuiLink>
) : (
<strong>{prop}</strong>
);
const propDescription = docgen.props[prop]?.description;

return { propName, propDescription, snippet };
}),
[propSnippetMap]
);

return <EuiBasicTable items={items} columns={columns} />;
};
Loading

0 comments on commit 1372f28

Please sign in to comment.