Skip to content

Commit

Permalink
client: Created the button component
Browse files Browse the repository at this point in the history
This commit creates a button component which is reusable and customizable like mentioned in the issue
Note:Things like hover effect,focus etc. has still not been implemented as it was not mentioned in the issue

fixes:#20
  • Loading branch information
ritwik-69 committed Jun 1, 2024
1 parent 44927c8 commit 2314476
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions frontend/src/library/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,49 @@
type ButtonProps = {
onClick: () => void;
children: React.ReactNode;
size?:'small' |'medium' | 'large';
textColor?: string;
bgColor?: string;
borderColor?: string;
shape?:'rectangle' | 'rounded' | 'circle';

};



function Button({ children, onClick,size="medium",bgColor="bg-blue-500",textColor="text-white",borderColor="border-red-500",shape }: ButtonProps) {

const getSizeClass = () => {
switch (size) {
case 'small':
return 'px-2 py-1 text-sm';
case 'large':
return 'px-4 py-2 text-lg';
case 'medium':
return 'px-3 py-2 text-base';
default:
return 'px-3 py-2 text-base';
}
};

const getShapeClass = () => {
switch (shape) {
case 'rounded':
return 'rounded-lg';
case 'rectangle':
return 'rounded-none';
case 'circle':
return 'rounded-full';
default:
return 'rounded-lg';
}
};

function Button({ onClick, children }: ButtonProps) {
return <button onClick={onClick}>{children}</button>;
const shapeClass = getShapeClass();
const sizeClass = getSizeClass();


return <button onClick={onClick} className={`${bgColor} ${textColor} border ${borderColor} ${sizeClass} ${shapeClass} `}>{children}</button>;
}

export default Button;

0 comments on commit 2314476

Please sign in to comment.