Skip to content

Commit 2f48fa6

Browse files
committed
Simplify Button logic
1 parent 06fc9fe commit 2f48fa6

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programmer_network/yail",
3-
"version": "1.0.25",
3+
"version": "1.0.26",
44
"description": "Programmer Network's official UI library for React",
55
"author": "Aleksandar Grbic - (https://programmer.network)",
66
"publishConfig": {

src/Components/Button/Button.stories.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import Button from ".";
55
const meta = {
66
title: "Core/Button",
77
component: Button,
8-
parameters: {
9-
layout: "centered"
10-
},
118
tags: ["autodocs"],
129
argTypes: {}
1310
} satisfies Meta<typeof Button>;

src/Components/Button/Button.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ describe("Button component", () => {
4343
test("has correct styles when disabled and filled", () => {
4444
render(<Button disabled>Disabled Button</Button>);
4545
const button = screen.getByRole("button");
46-
expect(button).toHaveClass("text-primary-background-color");
4746
expect(button).toHaveClass("!text-bg-primary-background-color");
4847
expect(button).toHaveClass("!bg-primary");
4948
});

src/Components/Button/__snapshots__/Button.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`Button component > renders correctly - snapshot test 1`] = `
44
<DocumentFragment>
55
<button
6-
class="select-none border-2 border-primary px-3 py-2 text-sm font-semibold uppercase tracking-tight shadow-lg text-primary-background-color bg-primary hover:bg-transparent hover:text-primary"
6+
class="relative select-none border-2 border-primary px-3 py-2 text-sm font-semibold uppercase tracking-tight shadow-lg bg-primary text-primary-background-color hover:bg-transparent hover:text-primary"
77
type="button"
88
>
99
<div

src/Components/Button/index.tsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,40 @@ const Button: React.FC<IButtonProps> = ({
1414
isLoading = false,
1515
outlined = false
1616
}) => {
17+
let buttonClasses =
18+
"select-none border-2 border-primary px-3 py-2 text-sm font-semibold uppercase tracking-tight shadow-lg";
19+
20+
if (outlined) {
21+
if (disabled) {
22+
buttonClasses +=
23+
" cursor-not-allowed opacity-70 !bg-transparent !text-primary";
24+
} else {
25+
buttonClasses +=
26+
" text-primary hover:bg-primary hover:text-primary-background-color";
27+
}
28+
} else {
29+
if (disabled) {
30+
buttonClasses +=
31+
" cursor-not-allowed opacity-70 !text-bg-primary-background-color !bg-primary";
32+
} else {
33+
buttonClasses +=
34+
" bg-primary text-primary-background-color hover:bg-transparent hover:text-primary";
35+
if (isLoading) {
36+
buttonClasses += " hover:bg-transparent";
37+
}
38+
}
39+
}
40+
41+
if (className) {
42+
buttonClasses += ` ${className}`;
43+
}
44+
1745
return (
1846
<button
1947
disabled={disabled}
2048
onClick={onClick}
2149
type={type}
22-
className={classNames(
23-
"select-none border-2 border-primary px-3 py-2 text-sm font-semibold uppercase tracking-tight shadow-lg",
24-
className,
25-
{
26-
"cursor-not-allowed opacity-70": disabled,
27-
"text-primary": outlined && !disabled,
28-
"text-primary-background-color": !outlined || disabled,
29-
"!text-bg-primary-background-color !bg-primary":
30-
!outlined && disabled,
31-
"hover:bg-transparent": !outlined && isLoading,
32-
"bg-primary hover:bg-transparent hover:text-primary":
33-
!outlined && !disabled,
34-
"hover:bg-primary hover:text-primary-background-color":
35-
outlined && !disabled,
36-
"!bg-transparent !text-primary": outlined && disabled
37-
}
38-
)}
50+
className={classNames("relative", buttonClasses)}
3951
>
4052
<div className='relative flex items-center justify-center'>
4153
<span

0 commit comments

Comments
 (0)