-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
b1dbf40
commit 8c7d014
Showing
9 changed files
with
3,999 additions
and
289 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
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 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 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,32 @@ | ||
// TODO: these types honestly make very little sense. "true" is not renderable, but is a value that can be passed in. "RenderableWithFunc" is just... bad nomenclature. this can and should be cleaned up whenever it might matter | ||
// a true "Renderable" type would really be JSX.Element | React.ReactNode | string | ||
type JSXEl = JSX.Element | React.ReactNode; | ||
export type Renderable = true | string | JSXEl; | ||
export type RenderableWithFunc = React.FC | Renderable; | ||
|
||
/** | ||
* | ||
* @param renderable some truthy value that either represents a render function, JSX, or other auto-renderable value | ||
* @param renderItem a specific end-renderable item (render func, string, or JSX element) | ||
* @param renderFunctionProps props for a renderable/ renderItem that is a render function | ||
* @returns | ||
*/ | ||
export const renderGeneric = ( | ||
renderable: RenderableWithFunc, | ||
renderItem?: Exclude<RenderableWithFunc, true>, | ||
renderFunctionProps = {} | ||
): string | JSXEl => { | ||
if (renderable === "true" && renderItem) { | ||
return renderGeneric(renderItem, undefined, renderFunctionProps); | ||
} | ||
|
||
if (typeof renderable === "string" || typeof renderable === "object") | ||
return renderable; | ||
|
||
if (typeof renderable === "function") { | ||
const RenderFunction = renderable; | ||
return <RenderFunction {...renderFunctionProps} />; | ||
} | ||
|
||
return null; | ||
}; |
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