-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SimplePropsTable & ComponentDoc to functional components
- Loading branch information
Showing
21 changed files
with
2,967 additions
and
8,343 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,13 @@ | ||
import React from "react"; | ||
|
||
import { PropDoc } from "../simple-props-table/types"; | ||
|
||
export const asDoc: PropDoc = { | ||
description: ( | ||
<span> | ||
the React Component or JSX Element (e.g. <code>"div"</code> or{" "} | ||
<code>span</code>) to render as | ||
</span> | ||
), | ||
typeName: "ReactType", | ||
}; |
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,38 @@ | ||
// tslint:disable:no-submodule-imports | ||
import React from "react"; | ||
|
||
import { Title } from "src/elements"; | ||
|
||
import { ComponentFeatures, ComponentFeaturesProps } from "../feature"; | ||
import { | ||
SimplePropsTable, | ||
SimplePropsTableProps, | ||
} from "../simple-props-table/simple-props-table"; | ||
|
||
export type ComponentDocProps = { | ||
asType: string; | ||
customize?: ComponentFeaturesProps["customize"]; | ||
docPath?: ComponentFeaturesProps["docPath"]; | ||
name: string; | ||
props: SimplePropsTableProps["props"]; | ||
}; | ||
|
||
export const ComponentDoc = ({ | ||
asType, | ||
customize, | ||
docPath, | ||
name, | ||
props, | ||
}: ComponentDocProps) => { | ||
const componentFeaturesProps = { asType, customize, docPath }; | ||
|
||
return ( | ||
<React.Fragment> | ||
<Title as="h4" size={4}> | ||
{name} | ||
</Title> | ||
<ComponentFeatures {...componentFeaturesProps} /> | ||
<SimplePropsTable props={props} /> | ||
</React.Fragment> | ||
); | ||
}; |
56 changes: 56 additions & 0 deletions
56
src/__docs__/components/component-doc/forward-ref-as-exotic-component-doc.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,56 @@ | ||
// tslint:disable:no-submodule-imports | ||
import React from "react"; | ||
|
||
import { ForwardRefAsExoticComponent } from "src/base/exotic"; | ||
|
||
import { ComponentFeaturesProps } from "../feature"; | ||
import { SimplePropsTableProps } from "../simple-props-table/simple-props-table"; | ||
import { ComponentDoc, ComponentDocProps } from "./component-doc"; | ||
import { asDoc } from "./as-doc"; | ||
import { refDoc } from "./ref-doc"; | ||
|
||
export type ForwardRefAsExoticComponentDocProps = { | ||
// tslint:disable-next-line:no-any | ||
component: ForwardRefAsExoticComponent<any, any>; | ||
customize: ComponentDocProps["customize"]; | ||
docPath?: ComponentFeaturesProps["docPath"]; | ||
props: SimplePropsTableProps["props"]; | ||
}; | ||
|
||
export const ForwardRefAsExoticComponentDoc = ({ | ||
component, | ||
customize, | ||
docPath, | ||
props, | ||
}: ForwardRefAsExoticComponentDocProps) => { | ||
const asType = component.defaultProps.as as React.ReactType; | ||
const asTypeString = | ||
typeof asType === "string" | ||
? asType | ||
: asType.displayName !== undefined | ||
? asType.displayName | ||
: JSON.stringify(asType); | ||
|
||
const extendedProps: SimplePropsTableProps["props"] = { | ||
as: asDoc, | ||
ref: refDoc, | ||
...props, | ||
}; | ||
|
||
for (const propName of Object.keys(extendedProps)) { | ||
const defaultValue = component.defaultProps[propName]; | ||
if (defaultValue !== undefined) { | ||
extendedProps[propName].defaultValue = JSON.stringify(defaultValue); | ||
} | ||
} | ||
|
||
return ( | ||
<ComponentDoc | ||
asType={asTypeString} | ||
customize={customize} | ||
docPath={docPath} | ||
name={component.displayName} | ||
props={extendedProps} | ||
/> | ||
); | ||
}; |
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,6 @@ | ||
export { asDoc } from "./as-doc"; | ||
export { ComponentDoc } from "./component-doc"; | ||
export { | ||
ForwardRefAsExoticComponentDoc, | ||
} from "./forward-ref-as-exotic-component-doc"; | ||
export { refDoc } from "./ref-doc"; |
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,13 @@ | ||
import React from "react"; | ||
|
||
import { PropDoc } from "../simple-props-table/types"; | ||
|
||
export const refDoc: PropDoc = { | ||
description: ( | ||
<span> | ||
a handle to the underlying <code>React Component</code> or{" "} | ||
<code>JSX Element</code> | ||
</span> | ||
), | ||
typeName: "Ref", | ||
}; |
Oops, something went wrong.