Skip to content

Commit

Permalink
feat(TU-9582): Export correct prop types for react components (#646)
Browse files Browse the repository at this point in the history
Features:
* Export new types for react components (PopoverProps, PopupButtonProps, SidetabProp, SliderButtonProps, WidgetProps) - closes #643 

Bug fixes:
* Make children prop optional in the PopupButton and SliderButton
  • Loading branch information
leandro-serafim authored Apr 16, 2024
1 parent f8c2a74 commit 02030ab
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
9 changes: 5 additions & 4 deletions packages/embed-react/src/components/make-button-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ import React, {
useMemo,
useRef,
ReactHTML,
HTMLAttributes,
AriaAttributes,
} from 'react'
import { ButtonProps } from '@typeform/embed'

import { InlineStyle } from './inline-style'

type ButtonComponentBaseProps = {
id: string
as?: keyof ReactHTML
buttonProps?: HTMLAttributes<HTMLElement> & Record<string, string>
buttonProps?: ButtonProps & AriaAttributes
style?: CSSProperties
className?: string
children: ReactNode
children?: ReactNode
}

type ButtonComponentProps<T> = T & ButtonComponentBaseProps
export type ButtonComponentProps<T> = T & ButtonComponentBaseProps

type CreateFnProps<T> = Omit<ButtonComponentProps<T>, keyof ButtonComponentBaseProps>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type InitializerComponentBaseProps = {
id: string
}

type InitializerComponentProps<T> = T & InitializerComponentBaseProps
export type InitializerComponentProps<T> = T & InitializerComponentBaseProps

type CreateFnProps<T> = Omit<InitializerComponentProps<T>, keyof InitializerComponentBaseProps>

Expand Down
2 changes: 1 addition & 1 deletion packages/embed-react/src/components/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createWidget, WidgetOptions } from '@typeform/embed'

import { InlineStyle } from './inline-style'

type WidgetProps = Omit<WidgetOptions, 'container'> & {
export type WidgetProps = Omit<WidgetOptions, 'container'> & {
id: string
style?: CSSProperties
className?: string
Expand Down
26 changes: 18 additions & 8 deletions packages/embed-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,27 @@ import {
SidetabOptions,
} from '@typeform/embed'

import { makeButtonComponent, makeInitializerComponent, Widget as WidgetComponent } from './components'
import {
ButtonComponentProps,
InitializerComponentProps,
makeButtonComponent,
makeInitializerComponent,
Widget as WidgetComponent,
WidgetProps,
} from './components'
import { memoComponent } from './utils'

const Widget = memoComponent(WidgetComponent)

const PopupButton = memoComponent(makeButtonComponent<PopupOptions>(createPopup, 'popup'))
export { WidgetProps }
export const Widget = memoComponent<WidgetProps>(WidgetComponent)

const SliderButton = memoComponent(makeButtonComponent<SliderOptions>(createSlider, 'slider'))
export type PopupButtonProps = ButtonComponentProps<PopupOptions>
export const PopupButton = memoComponent<PopupButtonProps>(makeButtonComponent<PopupOptions>(createPopup, 'popup'))

const Popover = memoComponent(makeInitializerComponent<PopoverOptions>(createPopover, 'popover'))
export type SliderButtonProps = ButtonComponentProps<SliderOptions>
export const SliderButton = memoComponent<SliderButtonProps>(makeButtonComponent<SliderOptions>(createSlider, 'slider'))

const Sidetab = memoComponent(makeInitializerComponent<SidetabOptions>(createSidetab, 'sidetab'))
export type PopoverProps = InitializerComponentProps<PopoverOptions>
export const Popover = memoComponent<PopoverProps>(makeInitializerComponent<PopoverOptions>(createPopover, 'popover'))

export { Widget, PopupButton, SliderButton, Popover, Sidetab }
export type SidetabProps = InitializerComponentProps<SidetabOptions>
export const Sidetab = memoComponent<SidetabProps>(makeInitializerComponent<SidetabOptions>(createSidetab, 'sidetab'))
1 change: 1 addition & 0 deletions packages/embed/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './factories/create-popup'
export * from './factories/create-slider'
export * from './factories/create-widget'
export * from './factories/create-sidetab'
export { ButtonProps } from './base'

0 comments on commit 02030ab

Please sign in to comment.