Created
June 24, 2020 15:46
-
-
Save colmtuite/e9e7f6c589167df29616b4186b753140 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from "react"; | |
import { cssReset, CssResetTagName } from "../utils/cssReset"; | |
import { withInteropStyledSystem } from "@interop/styled-system"; | |
| |
const defaultRenderElement = "button"; | |
| |
type ButtonDOMProps = React.ComponentPropsWithRef<typeof defaultRenderElement>; | |
type ButtonOwnProps = {}; | |
type ButtonProps = ButtonDOMProps & | |
ButtonOwnProps & { as?: React.ElementType<any> }; | |
| |
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Button( | |
props, | |
forwardedRef | |
) { | |
const { as: asProp, style, ...buttonProps } = props; | |
const Comp = asProp || defaultRenderElement; | |
| |
return <Comp {...buttonProps} ref={forwardedRef} />; | |
}); | |
| |
Button.displayName = "Button"; | |
| |
const reset = (renderElement: CssResetTagName = defaultRenderElement) => ({ | |
...cssReset(renderElement), | |
lineHeight: "1", | |
userSelect: "none", | |
"&:disabled": { | |
pointerEvents: "none", | |
}, | |
}); | |
| |
const styles = reset(); | |
| |
const StyledButton = withInteropStyledSystem(Button, reset); | |
| |
export { reset, styles, StyledButton as Button }; | |
export type { ButtonProps }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment