-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
911 additions
and
596 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
packages/website/docs/components/tabular_content/data_grid/_category_.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
label: 'Data grid' | ||
collapsed: true | ||
position: 2 |
91 changes: 91 additions & 0 deletions
91
packages/website/docs/components/tabular_content/data_grid/_prop_snippet_table.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />; | ||
}; |
Oops, something went wrong.