-
Notifications
You must be signed in to change notification settings - Fork 0
[feat/checkbox] - 체크박스 컴포넌트 추가 + *Card-Image 컴포넌트 삭제* #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { test, expect, vi } from "vitest"; | ||
| import Button from "./Button"; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { test, expect, vi } from 'vitest'; | ||
|
|
||
| test("renders 버튼과 클릭", async () => { | ||
| import Button from './Button'; | ||
|
|
||
| test('renders 버튼과 클릭', async () => { | ||
| const onClick = vi.fn(); | ||
| render(<Button onClick={onClick}>클릭</Button>); | ||
| const btn = screen.getByRole("button", { name: /클릭/i }); | ||
| const btn = screen.getByRole('button', { name: /클릭/i }); | ||
| await userEvent.click(btn); | ||
| expect(onClick).toHaveBeenCalled(); | ||
| }); |
This file contains hidden or 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
This file contains hidden or 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,55 @@ | ||
| @use '../../styles/index' as s; | ||
| @use 'sass:map'; | ||
|
|
||
| .checkbox { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 8px; | ||
| position: relative; | ||
| width: fit-content; | ||
| height: fit-content; | ||
| } | ||
|
|
||
| .checkbox_png { | ||
| position: absolute; | ||
| left: 3px; | ||
| top: -5px; | ||
| width: 20px; | ||
| height: 20px; | ||
| background: url('../../assets/check-mark.svg') center center no-repeat; | ||
| background-size: contain; | ||
| pointer-events: none; | ||
| opacity: 0; | ||
| transition: opacity 0.2s; | ||
| z-index: 3; | ||
| @media (max-width: 640px) { | ||
| width: 16px; | ||
| height: 16px; | ||
| left: 4px; | ||
| top: -2px; | ||
| } | ||
| } | ||
|
|
||
| .checkbox_input { | ||
| appearance: none; | ||
| width: 18px; | ||
| height: 18px; | ||
| border-radius: 0; | ||
| border: 2px solid s.color(gray-400); | ||
| background: s.color(white); | ||
| cursor: pointer; | ||
| transition: | ||
| background-color 0.2s, | ||
| border-color 0.2s; | ||
|
|
||
| &:checked { | ||
| ~ .checkbox_png { | ||
| opacity: 1; | ||
| } | ||
| } | ||
|
|
||
| @media (max-width: 640px) { | ||
| width: 16px; | ||
| height: 16px; | ||
| } | ||
| } |
This file contains hidden or 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,24 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react-vite'; | ||
| import Checkbox from './Checkbox'; | ||
|
|
||
| const meta: Meta<typeof Checkbox> = { | ||
| title: 'Components/Checkbox', | ||
| component: Checkbox, | ||
| argTypes: { onClick: { action: 'changed' } } | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof Checkbox>; | ||
|
|
||
| export const Primary: Story = { | ||
| args: { | ||
| label: 'Checkbox Default' | ||
| } | ||
| }; | ||
|
|
||
| export const Secondary: Story = { | ||
| args: { | ||
| label: 'Checkbox Checked', | ||
| checked: true | ||
| } | ||
| }; |
This file contains hidden or 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,15 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { test, expect, vi } from 'vitest'; | ||
|
|
||
| import Checkbox from './Checkbox'; | ||
|
|
||
| test('체크박스 렌더링과 체크 이벤트', async () => { | ||
| const onChange = vi.fn(); | ||
| render(<Checkbox label="동의" onChange={onChange} />); | ||
| const checkbox = screen.getByRole('checkbox', { name: /동의/i }); | ||
| expect(checkbox).not.toBeChecked(); | ||
| await userEvent.click(checkbox); | ||
| expect(checkbox).toBeChecked(); | ||
| expect(onChange).toHaveBeenCalled(); | ||
| }); |
This file contains hidden or 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,21 @@ | ||
| import React from 'react'; | ||
| import './Checkbox.scss'; | ||
|
|
||
| export interface CheckboxProps | ||
| extends React.InputHTMLAttributes<HTMLInputElement> { | ||
| label: string; | ||
| } | ||
|
|
||
| const Checkbox: React.FC<CheckboxProps> = ({ label, ...rest }) => { | ||
| const reactId = React.useId(); | ||
| const id = rest.id ?? reactId; | ||
|
|
||
| return ( | ||
| <label htmlFor={id} className="checkbox"> | ||
| <input id={id} type="checkbox" className="checkbox_input" {...rest} /> | ||
| <span className="checkbox_png" /> | ||
| {label} | ||
| </label> | ||
| ); | ||
| }; | ||
| export default Checkbox; |
This file contains hidden or 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,10 @@ | ||
| @use 'sass:map'; | ||
| @use 'variables' as v; | ||
|
|
||
| @function color($name) { | ||
| $val: map.get(v.$colors, $name); | ||
| @if $val == null { | ||
| @error "Unknown color token: #{$name}"; | ||
| } | ||
| @return $val; | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| @forward "variables"; | ||
| @forward "mixins"; | ||
| @forward 'variables'; | ||
| @forward 'functions'; | ||
| @forward 'mixins'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mq믹스인은 존재하지 않는 breakpoint 값을 받았을 때 아무런 동작 없이 조용히 넘어갑니다. 이는 개발 중 실수를 알아차리기 어렵게 만들 수 있습니다.text-style믹스인처럼, 유효하지 않은 값이 전달되었을 때@error를 발생시켜 문제를 즉시 인지할 수 있도록 개선하는 것이 좋습니다.