-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
템플릿 공개 범위 설정(�visibility) 기능 구현 (#787)
* feat(components): Toggle 컴포넌트 * feat(images): PrivateIcon, PublicIcon 추가 * refactor(mocks): templateList mock data에 "visibility" 추가 * feat(src): visibility 기능 추가 * feat(src): visibility가 private인 경우 템플릿 카드, 상세 페이지에서 privateIcon 보이도록 설정 * refactor(TemplateCard): 사용하지 않는 스타일드 컴포넌트 제거 * refactor(src): PRIVATE 상수화 * refactor(Toggle): Toggle.style 에서 불필요한 calc() 제거 * refactor(src): ICON_SIZE 상수 선언 및 적용 * refactor(components): CategoryDropdown 스타일 변경 * refactor(Toggle): Toggle 스타일 변경 및 showOptions 생성 * refactor(pages): 템플릿 생성 및 수정 페이지 Toggle 변경사항 반영
- Loading branch information
Showing
36 changed files
with
392 additions
and
93 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions
7
frontend/src/components/CategoryDropdown/CategoryDropdown.style.ts
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,7 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export const CategoryDropdownContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
`; |
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
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
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
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
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,30 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { useState } from 'react'; | ||
|
||
import Toggle from './Toggle'; | ||
|
||
const meta: Meta<typeof Toggle> = { | ||
title: 'Toggle', | ||
component: Toggle, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Toggle>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
options: ['private', 'public'], | ||
selectedOption: 'private', | ||
}, | ||
|
||
render: (args) => { | ||
const [selectedOption, setSelectedOption] = useState(args.selectedOption); | ||
|
||
const handleToggle = (option: string) => { | ||
setSelectedOption(option); | ||
}; | ||
|
||
return <Toggle options={args.options} selectedOption={selectedOption} switchOption={handleToggle} />; | ||
}, | ||
}; |
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,55 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
import { theme } from '@/style/theme'; | ||
|
||
export const ToggleContainer = styled.div` | ||
cursor: pointer; | ||
position: relative; | ||
overflow: hidden; | ||
display: flex; | ||
max-width: 12rem; | ||
height: 2.375rem; /* Button medium size와 동일 */ | ||
background-color: ${theme.color.light.secondary_100}; | ||
border-radius: 20px; | ||
`; | ||
|
||
export const ToggleOption = styled.div<{ selected: boolean }>` | ||
z-index: 1; | ||
display: flex; | ||
flex: 1; | ||
gap: 1px; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 0 1rem; | ||
color: ${({ selected }) => (selected ? theme.color.light.white : theme.color.light.secondary_500)}; | ||
transition: color 0.3s ease; | ||
`; | ||
|
||
export const ToggleSlider = styled.div<{ | ||
isRight: boolean; | ||
optionSliderColor: [string | undefined, string | undefined]; | ||
}>` | ||
position: absolute; | ||
top: 2px; | ||
left: 2px; | ||
transform: ${({ isRight }) => (isRight ? 'translateX(calc(100% - 4px))' : 'translateX(0)')}; | ||
width: 50%; | ||
height: calc(100% - 4px); | ||
background-color: ${({ isRight, optionSliderColor: [leftColor, rightColor] }) => | ||
isRight ? (rightColor ?? theme.color.light.secondary_500) : (leftColor ?? theme.color.light.secondary_500)}; | ||
border-radius: 18px; | ||
transition: | ||
transform 0.3s ease, | ||
background-color 0.3s ease; | ||
`; |
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,48 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
import * as S from './Toggle.style'; | ||
|
||
type ToggleOption<T extends string> = T; | ||
|
||
export interface ToggleProps<T extends string> { | ||
showOptions?: boolean; | ||
options: [ToggleOption<T>, ToggleOption<T>]; | ||
optionSliderColor?: [string | undefined, string | undefined]; | ||
optionAdornments?: [ReactNode, ReactNode]; | ||
selectedOption: ToggleOption<T>; | ||
switchOption: (option: ToggleOption<T>) => void; | ||
} | ||
|
||
const Toggle = <T extends string>({ | ||
showOptions = true, | ||
options, | ||
optionAdornments = [undefined, undefined], | ||
optionSliderColor = [undefined, undefined], | ||
selectedOption, | ||
switchOption, | ||
}: ToggleProps<T>) => { | ||
const [leftOption, rightOption] = options; | ||
const [leftOptionAdornment, rightOptionAdornment] = optionAdornments; | ||
|
||
const handleToggle = () => { | ||
const newOption = selectedOption === leftOption ? rightOption : leftOption; | ||
|
||
switchOption(newOption); | ||
}; | ||
|
||
return ( | ||
<S.ToggleContainer onClick={handleToggle}> | ||
<S.ToggleSlider isRight={selectedOption === rightOption} optionSliderColor={optionSliderColor} /> | ||
<S.ToggleOption selected={selectedOption === leftOption}> | ||
{leftOptionAdornment ?? ''} | ||
{showOptions && leftOption} | ||
</S.ToggleOption> | ||
<S.ToggleOption selected={selectedOption === rightOption}> | ||
{showOptions && rightOption} | ||
{rightOptionAdornment ?? ''} | ||
</S.ToggleOption> | ||
</S.ToggleContainer> | ||
); | ||
}; | ||
|
||
export default Toggle; |
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
Oops, something went wrong.