-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract props table block for docs
- Loading branch information
1 parent
00ceda6
commit a6bfbd2
Showing
10 changed files
with
103 additions
and
89 deletions.
There are no files selected for viewing
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
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
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,59 @@ | ||
import { Node, NodeChildren } from '../common/types'; | ||
|
||
export interface PropItem { | ||
name: string; | ||
isOptional: boolean; | ||
type: Node[]; | ||
description: string; | ||
} | ||
|
||
|
||
export const createPropsRow = ({ name, isOptional, type, description }: PropItem): NodeChildren => { | ||
return { type : 'tableRow' , children: [ | ||
{ type: 'tableCell', children: [ { type: 'inlineCode', value: `${name}${isOptional ? '': '*'}`}]}, | ||
{ | ||
type: 'tableCell', | ||
children: type, | ||
}, | ||
{ | ||
type: 'tableCell', | ||
children: [{ type: 'text', value: description }], | ||
} | ||
]} | ||
} | ||
|
||
export const createPropsTable = (title: string, children: PropItem[]): { propsTable: Node[], table?: NodeChildren} => { | ||
const propsTable: Node[] = []; | ||
let table: NodeChildren | undefined; | ||
if (children) { | ||
propsTable.push({ | ||
type: 'paragraph', | ||
children: [{ | ||
type: 'heading', | ||
depth: 3, | ||
children: [{ | ||
type: 'text', | ||
value: title, | ||
}] | ||
}] | ||
}) | ||
table = { | ||
type: 'table', | ||
children: [ | ||
{ type: 'tableRow', children: [ | ||
{ type: 'tableCell', children: [ { type: 'text', value: 'Name'}]}, | ||
{ type: 'tableCell', children: [ { type: 'text', value: 'Type'}]}, | ||
{ type: 'tableCell', children: [ { type: 'text', value: 'Description'}]}, | ||
]} | ||
] | ||
} | ||
propsTable.push({ | ||
type: 'paragraph', | ||
children: [table] | ||
}); | ||
table.children.push.apply(table.children, | ||
children.map((child: PropItem) => createPropsRow(child)) | ||
); | ||
} | ||
return { propsTable, table }; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
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
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