hygraph / rich-text

A set of companion packages for Hygraph's Rich Text Field
MIT License
93 stars 18 forks source link

Video Props typings are not correct #116

Closed joelpierre closed 8 months ago

joelpierre commented 8 months ago

The Video Node Renderer has the following types: type VideoNodeRenderer = (props: Partial<VideoProps>) => JSX.Element;

VideoProps is as follows:

export interface VideoProps {
    src: string;
    title?: string;
    width?: number;
    height?: number;
    handle?: string;
}

However the RichText response is

...
          src: 'https://media.graphassets.com/CGcmuQqOSDKd88lYEApe',
          type: 'video',
          title: 'lifetime-membership.mp4',
          width: null,
          handle: 'CGcmuQqOSDKd88lYEApe',
          height: null,
          children: [{ text: '' }],
          mimeType: 'video/mp4',
...

I can't without fudging the types on my end access the mimeType or "type" properties. Also the width and height are not types correctly. They probably should be Maybe<number>

I am happy to raise a pull request to fix if needed? I assume we should look at more of the responses too like Image and Audio?

jpedroschmitz commented 8 months ago

Hey @joelpierre, indeed this has changed and the types don't match anymore. It should look something like this:

export interface VideoProps {
    src: string;
    type: 'video';
    title?: string;
    width: number | null;
    height: number | null;
    handle?: string;
    mimeType: string // we could also have a more restrict type here, but I'm not sure about all the options
}

If you could open a PR, this would be very much appreciated.

joelpierre commented 8 months ago

Nice one will do when I get a second. I will try today 👍🏽

joelpierre commented 8 months ago

I think mimeType being a string is fine FWIW too

joelpierre commented 8 months ago

@jpedroschmitz - PR here https://github.com/hygraph/rich-text/pull/117 not sure how you do your version bumps etc

jpedroschmitz commented 8 months ago

Merged and release, @joelpierre! Thanks 🙏🏻