-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utility types Props and Components to reuse in another packages
- Loading branch information
1 parent
8c0de2a
commit 14f5b07
Showing
2 changed files
with
29 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
import React, { forwardRef, Ref, PropsWithoutRef } from 'react' | ||
import React, { forwardRef, Ref } from 'react' | ||
import { Button as A11yButton, ButtonProps as A11yProps } from 'reakit' | ||
import { PropsWithAs, As } from 'reakit-utils/types' | ||
import { | ||
Button as ThemeAwareButton, | ||
ButtonProps as ThemeAwareProps, | ||
} from 'theme-ui' | ||
import { As, Props, Component } from '@vtex-components/types' | ||
|
||
type Component<DefaultAs extends As, DefaultProps> = { | ||
<T extends As = DefaultAs>( | ||
props: PropsWithAs<PropsWithoutRef<DefaultProps>, T> | ||
): JSX.Element | ||
} | ||
|
||
type ButtonProps = A11yProps & { as?: As } | ||
type ButtonProps<T extends As = typeof ThemeAwareButton> = Props<T, A11yProps> | ||
|
||
const Button = ( | ||
{ as = ThemeAwareButton, ...props }: ButtonProps, | ||
{ as = ThemeAwareButton, ...props }: ButtonProps<As>, | ||
ref: Ref<As> | ||
) => { | ||
return <A11yButton ref={ref} as={as} {...props} /> | ||
} | ||
|
||
export { ButtonProps, A11yProps, ThemeAwareProps } | ||
|
||
export default forwardRef(Button) as Component< | ||
typeof ThemeAwareButton, | ||
A11yProps | ||
> | ||
export default forwardRef(Button) as Component<ButtonProps> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters