-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve typescript documentation: enums & aliases! (#1982)
* tag renderers are just SFCs! remove page arg from renderBlock * add context to Documentation component to expose renderers and docs data to children * rewrite all tag renderers to be simple SFCs and use context for rendering * typescript tag supports enums and type aliases too!! * type IDocsData requires markdown, optional typescript & kss data. * ApiHeader component now includes kind, inheritance, package/source link * don't use ApiLink yet (next PR) * createDefaultRenderers() * documentalist 1.0.0-beta.2, add docs-data script to root, fix dev:docs * minor code cleanup * tsconfigPath option fixes interface inheritance!!! * context docs * documentalist beta.4, sourceUrl, react class * markdownCode util * Documentation renderViewSourceLinkText prop * remove unnecessary dependency * DeprecatedTag SFC * class CssExample * tag renderers can be SFCs or classes
- Loading branch information
Showing
28 changed files
with
536 additions
and
255 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
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 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,77 @@ | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
|
||
import { Utils } from "@blueprintjs/core"; | ||
import { | ||
IBlock, | ||
IKssPluginData, | ||
IMarkdownPluginData, | ||
ITsDocBase, | ||
ITypescriptPluginData, | ||
} from "documentalist/dist/client"; | ||
|
||
/** This docs theme requires Markdown data and optionally supports Typescript and KSS data. */ | ||
export type IDocsData = IMarkdownPluginData & (ITypescriptPluginData | {}) & (IKssPluginData | {}); | ||
|
||
export function hasTypescriptData(docs: IDocsData): docs is IMarkdownPluginData & ITypescriptPluginData { | ||
return docs != null && (docs as ITypescriptPluginData).typescript != null; | ||
} | ||
|
||
export function hasKssData(docs: IDocsData): docs is IMarkdownPluginData & IKssPluginData { | ||
return docs != null && (docs as IKssPluginData).css != null; | ||
} | ||
|
||
/** | ||
* Use React context to transparently provide helpful functions to children. | ||
* This is basically the pauper's Redux store connector: some central state from the root | ||
* `Documentation` component is exposed to its children so those in the know can speak | ||
* directly to their parent. | ||
*/ | ||
export interface IDocumentationContext { | ||
/** | ||
* Get the Documentalist data. | ||
* Use the `hasTypescriptData` and `hasKssData` typeguards before accessing those plugins' data. | ||
*/ | ||
getDocsData(): IDocsData; | ||
|
||
/** Render a block of Documentalist documentation to a React node. */ | ||
renderBlock(block: IBlock): React.ReactNode; | ||
|
||
/** Render a Documentalist Typescript type string to a React node. */ | ||
renderType(type: string): React.ReactNode; | ||
|
||
/** Render the text of a "View source" link. */ | ||
renderViewSourceLinkText(entry: ITsDocBase): React.ReactNode; | ||
} | ||
|
||
/** | ||
* To enable context access in a React component, assign `static contextTypes` and declare `context` type: | ||
* | ||
* ```tsx | ||
* export class ContextComponent extends React.PureComponent<IApiLinkProps> { | ||
* public static contextTypes = DocumentationContextTypes; | ||
* public context: IDocumentationContext; | ||
* | ||
* public render() { | ||
* return this.context.renderBlock(this.props.block); | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
export const DocumentationContextTypes: React.ValidationMap<IDocumentationContext> = { | ||
getDocsData: assertFunctionProp, | ||
renderBlock: assertFunctionProp, | ||
renderType: assertFunctionProp, | ||
renderViewSourceLinkText: assertFunctionProp, | ||
}; | ||
|
||
// simple alternative to prop-types dependency | ||
function assertFunctionProp<T>(obj: T, key: keyof T) { | ||
if (obj[key] != null && Utils.isFunction(obj[key])) { | ||
return undefined; | ||
} | ||
return new Error(`[Blueprint] Documentation context ${key} must be function.`); | ||
} |
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
Oops, something went wrong.
02c4a98
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve typescript documentation: enums & aliases! (#1982)
Preview: documentation | landing | table