|
1 | | -import React, { forwardRef, Ref } from 'react' |
| 1 | +import React, { forwardRef, Ref, PropsWithoutRef } from 'react' |
2 | 2 | import { Button as A11yButton, ButtonProps as A11yProps } from 'reakit' |
| 3 | +import { PropsWithAs, As } from 'reakit-utils/types' |
3 | 4 | import { |
4 | 5 | Button as ThemeAwareButton, |
5 | 6 | ButtonProps as ThemeAwareProps, |
6 | 7 | } from 'theme-ui' |
7 | 8 |
|
8 | | -type Props = A11yProps & ThemeAwareProps |
| 9 | +type Component<DefaultAs extends As, DefaultProps> = { |
| 10 | + <T extends As = DefaultAs>( |
| 11 | + props: PropsWithAs<PropsWithoutRef<DefaultProps>, T> |
| 12 | + ): JSX.Element |
| 13 | +} |
| 14 | + |
| 15 | +type ButtonProps = A11yProps & { as?: As } |
9 | 16 |
|
10 | | -function Button({ as, ...props }: Props, ref: Ref<HTMLButtonElement>) { |
11 | | - return <A11yButton {...props} ref={ref} as={as ?? ThemeAwareButton} /> |
| 17 | +const Button = ( |
| 18 | + { as = ThemeAwareButton, ...props }: ButtonProps, |
| 19 | + ref: Ref<As> |
| 20 | +) => { |
| 21 | + return <A11yButton ref={ref} as={as} {...props} /> |
12 | 22 | } |
13 | 23 |
|
14 | | -export { A11yProps, ThemeAwareProps } |
15 | | -export default forwardRef(Button) |
| 24 | +export { ButtonProps, A11yProps, ThemeAwareProps } |
| 25 | + |
| 26 | +export default forwardRef(Button) as Component< |
| 27 | + typeof ThemeAwareButton, |
| 28 | + A11yProps |
| 29 | +> |
0 commit comments