Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/component/button'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieantono committed Oct 12, 2023
2 parents 73d2c91 + f11790f commit 9487b92
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions components/Buttons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';

/**
* AButton component's props definitions.
*/
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
text: string
// Add your custom properties here.
}

/**
* Default style for buttons using Tailwind CSS.
*/
const buttonStyle = "text-white font-bold py-2 px-4 rounded";

const defaultColor = "bg-gray-500 hover:bg-gray-700 ";
const primaryColor = "bg-blue-500 hover:bg-blue-700 ";
const cancelColor = "bg-red-500 hover:bg-red-700 ";

const disabledButton = " opacity-50 cursor-not-allowed";

/**
* Function for conditionally assigning the button's style.
* @param buttonType Type for the button (reset | submit | cancel)
* @param disabled The disabled flag for marking the button disabled state. (true | false).
* @returns Named class name for the button component.
*/
function getButtonClassNames(buttonType?: string, disabled?: boolean): string {
let className: string;
if (buttonType === "reset") {
className = cancelColor + buttonStyle + (disabled ? disabledButton : "")
}
else if (buttonType == "submit") {
className = primaryColor + buttonStyle + (disabled ? disabledButton : "")
}
else {
className = defaultColor + buttonStyle + (disabled ? disabledButton : "")
}
return className;
}

/**
* AButton component definitions.
*/
export const AButton: React.FC<ButtonProps> = (
props
) => {
return (
<button {...props} className={getButtonClassNames(props.type, props.disabled)}>
{props.text}
</button>
)
}

0 comments on commit 9487b92

Please sign in to comment.