- Add jscodeshift-based codemod to convert arrow function components to function declarations - Support React.FC, observer-wrapped, and forwardRef components - Include comprehensive test suite covering edge cases - Add npm script to run transformer across codebase - Target only .tsx files in source directories, excluding node_modules and declaration files * [WEB-5459] chore: updates after running codemod --------- Co-authored-by: sriramveeraghanta <veeraghanta.sriram@gmail.com>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import * as React from "react";
|
|
import { cn } from "../utils";
|
|
import type { TButtonVariant, TButtonSizes } from "./helper";
|
|
import { getIconStyling, getButtonStyling } from "./helper";
|
|
|
|
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
variant?: TButtonVariant;
|
|
size?: TButtonSizes;
|
|
className?: string;
|
|
loading?: boolean;
|
|
disabled?: boolean;
|
|
appendIcon?: any;
|
|
prependIcon?: any;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
const Button = React.forwardRef(function Button(props: ButtonProps, ref: React.ForwardedRef<HTMLButtonElement>) {
|
|
const {
|
|
variant = "primary",
|
|
size = "md",
|
|
className = "",
|
|
type = "button",
|
|
loading = false,
|
|
disabled = false,
|
|
prependIcon = null,
|
|
appendIcon = null,
|
|
children,
|
|
...rest
|
|
} = props;
|
|
|
|
const buttonStyle = getButtonStyling(variant, size, disabled || loading);
|
|
const buttonIconStyle = getIconStyling(size);
|
|
|
|
return (
|
|
<button ref={ref} type={type} className={cn(buttonStyle, className)} disabled={disabled || loading} {...rest}>
|
|
{prependIcon && <div className={buttonIconStyle}>{React.cloneElement(prependIcon, { strokeWidth: 2 })}</div>}
|
|
{children}
|
|
{appendIcon && <div className={buttonIconStyle}>{React.cloneElement(appendIcon, { strokeWidth: 2 })}</div>}
|
|
</button>
|
|
);
|
|
});
|
|
|
|
Button.displayName = "plane-ui-button";
|
|
|
|
export { Button };
|