UNPKG

jsx-md

Version:

Generate markdown files with a React-like syntax.

52 lines (51 loc) 1.67 kB
import { Component, MarkdownChildren } from ".."; export declare enum TableAlignment { LEFT = "left", CENTER = "center", RIGHT = "right" } /** @internal */ interface TableHeader { title: MarkdownChildren; alignment?: TableAlignment; } /** @internal */ interface Props<Headers extends string> { body: Record<Headers, MarkdownChildren>[]; headers: Record<Headers, MarkdownChildren | TableHeader>; } /** * Creates a markdown table based on a headers object and an array of rows. * Columns are ordered in the order in which the header keys were created. * * @paramType A union of possible keys for headers and body * @example * ```js * const headers = { * foo: "Foo header", * bar: { title: "Bar header", alignment: TableAlignment.CENTER }, * baz: { title: "Baz header" }, * }; * const body = [ * { foo: "Foo body 1", bar: "Bar body 1", baz: "Baz body 1" }, * { foo: "Foo body 2", bar: "Bar body 2", baz: "Baz body 2" }, * ]; * render(<Table headers={headers} body={body} />) * === * ` * | Foo header | Bar header | Baz header | * | ---------- | :--------: | ---------- | * | Foo body 1 | Bar body 1 | Baz body 1 | * | Foo body 2 | Bar body 2 | Baz body 2 | * ` */ export declare function Table<Headers extends string>({ /** An array of data objects with the same keys as the headers to be displayed as rows. */ body, /** * An object giving the headers for each column. The order in which the keys * of this object were created determines the order in which the columns * are rendered. */ headers, }: Props<Headers>): ReturnType<Component<Props<Headers>>>; export {};