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

feat(TU-9582): Export correct prop types for react components #646

Merged
merged 3 commits into from
Apr 16, 2024

Conversation

leandro-serafim
Copy link
Contributor

@leandro-serafim leandro-serafim commented Apr 9, 2024

Exported correct types for reacting components props.

I used this wrapper as example to test it.

import React from 'react'
import { Popover, PopoverProps, PopupButton, PopupButtonProps, Sidetab, SidetabProps, SliderButton, SliderButtonProps, Widget, WidgetProps } from '@typeform/embed-react'

type EmbedReactProps =
  | { type: 'popover' } & PopoverProps
  | { type: 'popup' } & PopupButtonProps
  | { type: 'sidetab' } & SidetabProps
  | { type: 'slider' } & SliderButtonProps
  | { type: 'widget' } & WidgetProps

const EmbedReact = ({ type, ...rest }: EmbedReactProps) => {
  switch (type) {
    case 'popover':
      return <Popover {...rest} />
    case 'popup':
      return <PopupButton {...rest} />
    case 'sidetab':
      return <Sidetab {...rest} />
    case 'slider':
      return <SliderButton {...rest} />
    case 'widget':
      return <Widget {...rest} />
    default:
      return null
  }
}

export default function renderAll() {
  return <>
    <EmbedReact type="popover" id="my-popover" />
    <EmbedReact type="popup" id="my-popup-button">test</EmbedReact>
    <EmbedReact type="sidetab" id="my-sidetab" />
    <EmbedReact type="slider" id="my-slider-button" />
    <EmbedReact type="widget" id="my-popup-button" />
  </>
}

Fixes: #643

@leandro-serafim leandro-serafim force-pushed the feat/TU-9582/adding-missing-embed-types branch from 01a1b4b to 111270e Compare April 9, 2024 14:57
@leandro-serafim leandro-serafim force-pushed the feat/TU-9582/adding-missing-embed-types branch from 111270e to 8c7f1ae Compare April 9, 2024 15:01
@leandro-serafim leandro-serafim changed the title fix(TU-9582): Fix memoComponent type in the react lib feat(TU-9582): Export correct prop types for react components Apr 15, 2024
@mathio
Copy link
Collaborator

mathio commented Apr 16, 2024

Unit tests fail as they do not allow aria-label prop. Maybe it should be ariaLabel?

FAIL src/components/make-button-component.spec.tsx
  ● Test suite failed to run

    src/components/make-button-component.spec.tsx:[20](https://github.com/Typeform/embed/actions/runs/8689377407/job/23826940192?pr=646#step:8:21):55 - error TS2322: Type '{ 'aria-label': string; 'data-custom': string; }' is not assignable to type 'Partial<Omit<HTMLButtonElement, "style"> & AdditionalAttributes>'.
      Object literal may only specify known properties, and ''aria-label'' does not exist in type 'Partial<Omit<HTMLButtonElement, "style"> & AdditionalAttributes>'.

    20         <Button id="form-id" foo="bar" buttonProps={{ 'aria-label': 'aria-value-btn', 'data-custom': 'value-custom' }}>
                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      src/components/make-button-component.tsx:9:3
        9   buttonProps?: ButtonProps
            ~~~~~~~~~~~
        The expected type comes from property 'buttonProps' which is declared here on type 'IntrinsicAttributes & Props & ButtonComponentBaseProps & RefAttributes<unknown>'

@typeform-ops-gha
Copy link

[BOT] Preview available with hash 85ebfdfd8718a543ed51c94b14a33fe8e7d0914e here.

@leandro-serafim leandro-serafim marked this pull request as ready for review April 16, 2024 10:17
@leandro-serafim leandro-serafim requested a review from a team as a code owner April 16, 2024 10:17
@leandro-serafim leandro-serafim merged commit 02030ab into main Apr 16, 2024
11 checks passed
@leandro-serafim leandro-serafim deleted the feat/TU-9582/adding-missing-embed-types branch April 16, 2024 10:27
typeform-ops-gha pushed a commit that referenced this pull request Apr 16, 2024
# [@typeform/embed-v4.10.0](https://github.com/Typeform/embed/compare/@typeform/embed-v4.9.0...@typeform/embed-v4.10.0) (2024-04-16)

### Features

* **TU-9582:** Export correct prop types for react components ([#646](#646)) ([02030ab](02030ab)), closes [#643](#643)
@typeform-ops-gha
Copy link

🎉 This PR is included in version @typeform/embed-v4.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

typeform-ops-gha pushed a commit that referenced this pull request Apr 16, 2024
# [@typeform/embed-react-v3.17.0](https://github.com/Typeform/embed/compare/@typeform/embed-react-v3.16.0...@typeform/embed-react-v3.17.0) (2024-04-16)

### Features

* Bump @typeform/embed in @typeform/embed-react package [skip ci] ([29b1dc5](29b1dc5))
* **TU-9582:** Export correct prop types for react components ([#646](#646)) ([02030ab](02030ab)), closes [#643](#643)
@typeform-ops-gha
Copy link

🎉 This PR is included in version @typeform/embed-react-v3.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing react types for 4 of the components
3 participants