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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
leandro-serafim marked this conversation as resolved.
Show resolved Hide resolved
style?: CSSProperties
className?: string
children: ReactNode
children?: ReactNode
leandro-serafim marked this conversation as resolved.
Show resolved Hide resolved
}

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'))
leandro-serafim marked this conversation as resolved.
Show resolved Hide resolved

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'
Loading