Robert-Fairley / apple-news-format

Types and basic validation methods for Apple News Format
MIT License
4 stars 6 forks source link

Using padding object in table cell #53

Open d3v1an7 opened 1 month ago

d3v1an7 commented 1 month ago

Hey! First off, thanks heaps for this, super helpful :) I'm using this in a non-standard way, vanilla JS + JSdoc/checkJs -- feel free to close if that is the cause.

Code example:

/**
 * @param {object} params
 * @param {string} params.text
 * @returns {import('apple-news-format').AppleNews.HTMLTable} Valid HTMLTable object.
 */
function generateKicker({ text }) {
  return {
    role: "htmltable",
    html: `<table><tr><td>Foo</td><td>${text}</td></tr></table>`,
    style: {
      tableStyle: {
        cells: {
          textStyle: {
            textTransform: "uppercase",
          },
          conditional: [
            {
              selectors: [{ descriptor: null, evenColumns: true }],
              backgroundColor: "#E9FF5C",
              padding: {
                left: 6,
                right: 4,
                bottom: 2,
                top: 2,
              },
            },
            {
              selectors: [{ descriptor: null, oddColumns: true }],
              width: 1,
              padding: {
                left: 12,
              },
            },
          ],
        },
      },
    },
  };
}

I'm getting the following error on padding:

Type '{ left: number; right: number; bottom: number; top: number; }' is not assignable to type 'string | number'.ts(2322) table-cell-style-base.d.ts(10, 5): The expected type comes from property 'padding' which is declared here on type 'ConditionalTableCellStyle'

Screenshot 2024-06-04 at 1 07 34 PM

I believe the padding object should be supported, as per: https://developer.apple.com/documentation/apple_news/padding

Robert-Fairley commented 1 week ago

Hi Ben, I wrote a response already but I was mistaken. It looks like the type needs a quick update. I'll notify you again here when there's a new patch published