Skip to content

Instantly share code, notes, and snippets.

@colmtuite
Created June 24, 2020 15:46
Show Gist options
  • Save colmtuite/e9e7f6c589167df29616b4186b753140 to your computer and use it in GitHub Desktop.
Save colmtuite/e9e7f6c589167df29616b4186b753140 to your computer and use it in GitHub Desktop.
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