UNPKG

gadgets

Version:

Reusable React UI widgets - This is my widget library. There are many like it, but this one is mine...

78 lines (77 loc) 2.64 kB
/** * Takes a string of a markup language (asciidoc, markdown, or * restructuredtext), converts it to HTML, and presents it in a webview control. * * The componet uses the [util.markup](https://github.com/jmquigley/util.markup) * package for parsing content into a proper HTML document. * * ## Screen: * <img src="https://github.com/jmquigley/gadgets/blob/master/images/preview.png" width="60%" /> * * ## Examples: * * ```javascript * <Preview * content={markup content string} * css={css string to apply} * mode={PreviewMode.markdown} * /> * ``` * * ## API * #### Events * - `onChange(content: string, html: string)` - invoked when the content is * changed in the control. It will contain the content parsed and the * resulting HTML, both as strings. * * #### Styles * - `ui-preview` - Applied to the div container surrounding the webview * component * - `ui-preview-content` - Applied to the underlying webview component. This * is an id * * #### Properties * - `content="" {string}` - The markup document content as a string * - `css="" {string}` - The CSS that will be applied to the parsed content HTML. * - `mode=PreviewMode.markdown {PreviewMode}` - The markup format of the given * content. It has three possible values: `PreviewMode.asciidoc`, * `PreviewMoode.markdown`, `PreviewMode.restructuredtext}` * * @module Preview */ /// <reference types="react" /> import { MarkupMode } from "util.markup"; import { BaseComponent, BaseProps, BaseState } from "../shared"; export declare const PreviewMode: { [x: number]: string; asciidoc: MarkupMode.asciidoc; markdown: MarkupMode.markdown; md: MarkupMode.markdown; restructuredtext: MarkupMode.restructuredtext; rst: MarkupMode.restructuredtext; }; export declare type PreviewMode = MarkupMode; export interface PreviewProps extends BaseProps { content?: string; css?: string; mode?: PreviewMode; onChange?: (content: string, html: string) => void; } export interface PreviewState extends BaseState { content: string; html: string; } export declare class Preview extends BaseComponent<PreviewProps, PreviewState> { static readonly defaultProps: PreviewProps; private static readonly parsers; private _preview; private _webview; constructor(props: PreviewProps); private handleRef; static getDerivedStateFromProps(props: PreviewProps, state: PreviewState): any; componentDidMount(): void; componentDidUpdate(_prevProps: PreviewProps, prevState?: PreviewState): void; private parseContent; render(): JSX.Element; } export default Preview;