Skip to content

Comments

Export types and add addBackground function#55

Open
Ciaanh wants to merge 1 commit intonatancabral:mainfrom
Ciaanh:improve-types-declaration
Open

Export types and add addBackground function#55
Ciaanh wants to merge 1 commit intonatancabral:mainfrom
Ciaanh:improve-types-declaration

Conversation

@Ciaanh
Copy link

@Ciaanh Ciaanh commented Oct 28, 2022

In order to use the alternating row style with in a Typescript project the declaration for the function addBackground has been added.

Also exported the declared interfaces in order to facilitate the configuration in Typescript projects.

@Matheus-Campos1
Copy link

This is what this lib needs

@7doctor7
Copy link

I’m really looking forward to this PR merge

@VadimOvchinnikov
Copy link

@Ciaanh I left two comment to add missing/fix incorrect properties. Also, I suggest to move property comments to JSDoc comments so we have these 'default's available with IDE information.

Here's pdfkit-table.d.ts file I'm using in my projects

// pdfkit-table.d.ts
declare module 'pdfkit-table' {
  import PDFDocument from 'pdfkit';

  export interface Rect {
    x: number;
    y: number;
    width: number;
    height: number;
  }

  export interface Header {
    label?: string;
    property?: string;
    width?: number;
    /** default 'left' */
    align?: string;
    valign?: string;
    /** default '#BEBEBE' */
    headerColor?: string;
    /** default '0.5' */
    headerOpacity?: number;
    /** default 'left' */
    headerAlign?: string;
    columnColor?: string;
    columnOpacity?: number;
    backgroundColor?: string;
    backgroundOpacity?: number;
    background?: { color: string, opacity?: number };
    renderer?: (
      value: any,
      indexColumn?: number,
      indexRow?: number,
      row?: number,
      rectRow?: Rect,
      rectCell?: Rect
    ) => string;
  }

  export interface DataOptions {
    fontSize: number;
    fontFamily: string;
    separation: boolean;
  }

  export interface Data {
    [key: string]: string | { label: string; options?: DataOptions };
  }

  export interface Table {
    title?: string;
    subtitle?: string;
    headers?: (string | Header)[];
    datas?: Data[];
    rows?: string[][];
  }

  export interface DividerOptions {
    disabled?: boolean;
    width?: number;
    opacity?: number;
  }

  export interface Divider {
    header?: DividerOptions;
    horizontal?: DividerOptions;
  }

  export interface Title {
    label: string;
    fontSize?: number;
    fontFamily?: string;
    color?: string;
  }

  export interface Options {
    title?: string | Title;
    subtitle?: string | Title;
    width?: number;
    /** default doc.x */
    x?: number;
    /** default doc.y */
    y?: number;
    divider?: Divider;
    columnsSize?: number[];
    /** default 5 */
    columnSpacing?: number;
    padding?: number[];
    /** default false */
    addPage?: boolean;
    hideHeader?: boolean;
    minRowHeight?: number;
    prepareHeader?: () => PDFDocumentWithTables;
    prepareRow?: (
      row?: any,
      indexColumn?: number,
      indexRow?: number,
      rectRow?: Rect,
      rectCell?: Rect
    ) => PDFDocumentWithTables;
  }

  class PDFDocumentWithTables extends PDFDocument {
    public table(table: Table, options?: Options): Promise<void>;

    public addBackground(
      rect?: Rect,
      fillColor?: string,
      fillOpacity?: number,
      callback?: Function
    );
  }

  export default PDFDocumentWithTables;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants