Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to header.content #205

Open
PenguRinPrivate opened this issue Apr 2, 2022 · 4 comments
Open

Allow access to header.content #205

PenguRinPrivate opened this issue Apr 2, 2022 · 4 comments

Comments

@PenguRinPrivate
Copy link

export declare type HeaderUserConfig = Omit<ColumnUserConfig, 'verticalAlignment' | 'width'> & {
    readonly content: string;
};

Right now it's on readonly mode if you assign the TableUserConfig to your config file, however, this prevents reusability if you want to change the content only for another table.
Right now I have to either @ts-ignore the config file input if I want to change the content without assigning a type to it or I have to create a completely new config file.

@nam-hle
Copy link
Collaborator

nam-hle commented Apr 3, 2022

Hi @PenguRin, how about reuse the table body content somehow? Btw, a sample code would help so much. Thanks.

@PenguRinPrivate
Copy link
Author

Hey @nam-hle, reusing the content is not an option as they have different use cases but the same table layout. All that'd change would literally be the content in like 5 cases.
To make the use case more clear with an example:

config.header.content = 'xyz'
console.log(table(commandTable, config));

This is the desired outcome without resolving to @ts-ignore or creating multiple configuration files.

Thank you!

@nam-hle
Copy link
Collaborator

nam-hle commented Apr 3, 2022

Hey @PenguRin, thanks for clarification. What if we have a function like this:

function createTable(title: string, data: string[][]) {
  const config: TableUserConfig = {
    columnDefault: {
      width: 10,
    },
    header: {
      alignment: 'center',
      content: title,
    },
  }

  return table(data, config)
}

@PenguRinPrivate
Copy link
Author

Of course that works but as aforementioned, I basically don't see the point of factory functions or any hacky workarounds when we could simply access it, there should be no harm, right?
Unless I am missing something fundamental here that justifies the readonly property.

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

No branches or pull requests

2 participants