-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(web): Add TabButton component (#464)
Co-authored-by: 長田淳史 <> Co-authored-by: keiya sasaki <[email protected]>
- Loading branch information
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import TabButton from "."; | ||
|
||
const meta: Meta<typeof TabButton> = { | ||
component: TabButton, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof TabButton>; | ||
|
||
export const Close: Story = { | ||
args: { | ||
label: "Editor", | ||
selected: false, | ||
}, | ||
}; | ||
|
||
export const Open: Story = { | ||
args: { | ||
label: "Editor", | ||
selected: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
import { render, screen } from "@reearth/test/utils"; | ||
|
||
import TabButton from "."; | ||
|
||
const handleClick = () => { | ||
}; | ||
|
||
test("1. should be rendered", () => { | ||
render(<TabButton label="test1" onClick={handleClick} selected={false} />); | ||
}); | ||
|
||
test("2. should display button label", () => { | ||
render(<TabButton label="test2" onClick={handleClick} selected={false} />); | ||
expect(screen.getByRole("button")).toBeInTheDocument(); | ||
expect(screen.getByText(/test2/)).toBeInTheDocument(); | ||
}); | ||
|
||
test("3. should disabled true button", () => { | ||
render(<TabButton label="test3" onClick={handleClick} selected={true} />); | ||
expect(screen.getByRole("button")).toBeDisabled(); | ||
}); | ||
|
||
test("4. should disabled false button", () => { | ||
render(<TabButton label="test4" onClick={handleClick} selected={false} />); | ||
expect(screen.getByRole("button")).not.toBeDisabled(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { FC } from "react"; | ||
|
||
import { styled } from "@reearth/services/theme"; | ||
|
||
export type Props = { | ||
label: string; | ||
onClick?: () => void; | ||
selected?: boolean; | ||
}; | ||
|
||
const TabButton: FC<Props> = ({ label, onClick, selected }) => { | ||
return ( | ||
<Button onClick={onClick} disabled={selected}> | ||
{label} | ||
</Button> | ||
); | ||
}; | ||
|
||
type ButtonProps = { | ||
disabled?: boolean; | ||
}; | ||
|
||
const Button = styled.button<ButtonProps>` | ||
background: ${({ disabled }) => (disabled ? "#232226" : "inherit")}; | ||
padding: 8px 12px; | ||
height: 35px; | ||
border-radius: 4px; | ||
:hover { | ||
background: #232226; | ||
transition: all 0.5s ease; | ||
} | ||
color: ${({ disabled }) => (disabled ? "#C7C5C5" : "#4A4A4A")}; | ||
font-size: 14px; | ||
line-height: 19px; | ||
text-align: center; | ||
`; | ||
|
||
export default TabButton; |