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

forwardRef helper #102

Closed
sebald opened this issue Mar 13, 2020 · 1 comment
Closed

forwardRef helper #102

sebald opened this issue Mar 13, 2020 · 1 comment
Assignees
Labels
type:feature New feature or component
Milestone

Comments

@sebald
Copy link
Member

sebald commented Mar 13, 2020

Reach-UI has incredible typings. We could steal + adapt the following typings for us to make creating components easier regarding typings:

https://github.com/reach/reach-ui/blob/4cb497f530b0f83f80c6f6f2da46ab55b1160cb6/packages/utils/src/index.tsx#L185-L209

/**
 * This is a hack for sure. The thing is, getting a component to intelligently
 * infer props based on a component or JSX string passed into an `as` prop is
 * kind of a huge pain. Getting it to work and satisfy the constraints of
 * `forwardRef` seems dang near impossible. To avoid needing to do this awkward
 * type song-and-dance every time we want to forward a ref into a component
 * that accepts an `as` prop, we abstract all of that mess to this function for
 * the time time being.
 *
 * TODO: Eventually we should probably just try to get the type defs above
 * working across the board, but ain't nobody got time for that mess!
 *
 * @param Comp
 */
export function forwardRefWithAs<Props, ComponentType extends As>(
  comp: (
    props: PropsFromAs<ComponentType, Props>,
    ref: React.RefObject<any>
  ) => React.ReactElement | null
) {
  return (React.forwardRef(comp as any) as unknown) as ComponentWithAs<
    ComponentType,
    Props
  >;
}
@sebald sebald added the type:feature New feature or component label Mar 13, 2020
@sebald sebald added this to the ⍺-lpha milestone Mar 13, 2020
sebald added a commit that referenced this issue Mar 13, 2020
@sebald sebald self-assigned this Mar 13, 2020
ti10le pushed a commit that referenced this issue Mar 18, 2020
* wip: helper to write system components

#102

* make system typings smore consistent

* use system helper inside <Box>

* hide forwardref API 🤫

* add variant prop and docs
@sebald
Copy link
Member Author

sebald commented Mar 18, 2020

Closed via #106

@sebald sebald closed this as completed Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or component
Projects
None yet
Development

No branches or pull requests

1 participant