-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat : storybook 모바일 뷰 세팅 * feat: selectWeek 컴포넌트 생성 * feat: border 색 추가 및 Jsdoc 추가 * chore: 내보내기 코드 작성
- Loading branch information
Showing
9 changed files
with
216 additions
and
19 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 |
---|---|---|
|
@@ -117,6 +117,7 @@ module.exports = { | |
pascalCase: true | ||
} | ||
} | ||
] | ||
], | ||
'unicorn/prevent-abbreviations': ['off'] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,51 @@ | ||
import type { Preview } from '@storybook/react' | ||
import { BrowserRouter } from 'react-router-dom' | ||
import '../src/styles/index.css' | ||
import React from 'react' | ||
|
||
const customViewports = { | ||
iPhone13: { | ||
name: 'iPhone 13', | ||
styles: { | ||
width: '390px', | ||
height: '844px' | ||
}, | ||
type: 'mobile' | ||
}, | ||
tablet: { | ||
name: 'iPad Pro 11', | ||
styles: { | ||
width: '834px', | ||
height: '1194px' | ||
}, | ||
type: 'tablet' | ||
} | ||
} | ||
|
||
const preview: Preview = { | ||
parameters: { | ||
layout: 'fullscreen', | ||
actions: { argTypesRegex: '^on[A-Z].*' }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/i | ||
} | ||
}, | ||
viewport: { | ||
viewports: customViewports, | ||
defaultViewport: 'iPhone13' | ||
} | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<BrowserRouter> | ||
<div> | ||
<Story /> | ||
</div> | ||
</BrowserRouter> | ||
) | ||
] | ||
} | ||
|
||
export default preview |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 @@ | ||
export * from './selectweek/SelectWeek' |
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,46 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { useEffect, useState } from 'react' | ||
import SelectWeek from './SelectWeek' | ||
|
||
const meta: Meta<typeof SelectWeek> = { | ||
component: SelectWeek, | ||
title: 'Atom/SelectWeek', | ||
tags: ['autodocs'], | ||
argTypes: { | ||
fixedDate: { | ||
control: 'multi-select', | ||
options: [0, 1, 2, 3, 4, 5, 6] | ||
}, | ||
selectedDate: { | ||
control: 'multi-select', | ||
options: [0, 1, 2, 3, 4, 5, 6] | ||
}, | ||
setSelectedDate: { | ||
control: { type: 'function' } | ||
} | ||
}, | ||
render: function Render(args) { | ||
const [selectedDate, setSelectedDate] = useState<number[]>([]) | ||
useEffect(() => { | ||
setSelectedDate([...args.selectedDate]) | ||
}, [args.selectedDate]) | ||
return ( | ||
<SelectWeek | ||
setSelectedDate={setSelectedDate} | ||
selectedDate={selectedDate} | ||
fixedDate={args.fixedDate} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof SelectWeek> | ||
|
||
export const Default: Story = { | ||
...meta, | ||
args: { | ||
fixedDate: [0], | ||
selectedDate: [1] | ||
} | ||
} |
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,71 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import { cva } from 'class-variance-authority' | ||
import cn from '../../../libs/utils/cn' | ||
|
||
export const SelectWeekVariant = cva( | ||
`flex justify-center items-center w-[39px] h-[39px]`, | ||
{ | ||
variants: { | ||
variant: { | ||
default: | ||
'bg-white-100 rounded-full body-16 text-black-900 border border-blue-500', | ||
selected: 'bg-blue-500 rounded-full body-16 text-white-100', | ||
fixed: 'cursor-default bg-gray-400 rounded-full body-16 text-white-100' | ||
}, | ||
defaultVariants: { | ||
variant: 'default' | ||
} | ||
} | ||
} | ||
) | ||
|
||
/** | ||
* @param selectedDate selectedDate값을 가지고 있는 state | ||
* @param setSelectedDate selectedDate 값을 변경할 수 있는 setState 함수 | ||
* @param fixedDate 고정된 주 선택 (이미 선택하여 수정하지 않아도 되는 것 / 다수 선택에 사용) | ||
*/ | ||
|
||
interface SelectWeekProperties { | ||
selectedDate: number[] | ||
setSelectedDate: React.Dispatch<React.SetStateAction<number[]>> | ||
fixedDate?: number[] | ||
} | ||
|
||
const SelectWeek = ({ | ||
fixedDate, | ||
setSelectedDate, | ||
selectedDate | ||
}: SelectWeekProperties) => { | ||
const week = ['일', '월', '화', '수', '목', '금', '토'] | ||
return ( | ||
<div className={'flex flex-row gap-2.5 w-full justify-center items-center'}> | ||
{week.map((day, index) => ( | ||
<button | ||
key={index} | ||
className={cn( | ||
SelectWeekVariant({ | ||
variant: | ||
fixedDate?.includes(index) | ||
? 'fixed' | ||
: selectedDate.includes(index) | ||
? 'selected' | ||
: 'default' | ||
}) | ||
)} | ||
onClick={() => { | ||
if (selectedDate.includes(index)) { | ||
const filteredDate = selectedDate.filter((data) => data !== index) | ||
setSelectedDate([...filteredDate]) | ||
} else { | ||
setSelectedDate([...selectedDate, index]) | ||
} | ||
}} | ||
> | ||
{day} | ||
</button> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
export default SelectWeek |
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,8 @@ | ||
import { ClassValue, clsx } from 'clsx' | ||
import { twMerge } from 'tailwind-merge' | ||
|
||
const cn = (...classes: ClassValue[]) => { | ||
return twMerge(clsx(classes)) | ||
} | ||
|
||
export default cn |