Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
#
# * b. Generate a new token and add it to your Github repository's secrets using the name SONAR_TOKEN
# (On SonarCloud, click on your avatar on top-right > My account > Security
# or go directly to https://sonarcloud.io/account/security/)
# or go directly to

# Feel free to take a look at our documentation (https://docs.sonarcloud.io/getting-started/github/)
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/help/sc/9)
# Feel free to take a look at our documentation (
# or reach out to our community forum if you need some help (

name: SonarCloud analysis

on:
push:
branches: [ "main", "develop" ]
branches: [ '*' ] # 모든 브랜치에서 푸시 이벤트 발생 시 분석
pull_request:
branches: [ "main", "develop" ]
branches: [ '*' ] # 모든 브랜치에 대한 PR 발생 시 분석
workflow_dispatch:

permissions:
Expand All @@ -46,7 +46,6 @@ jobs:
- name: Analyze with SonarCloud

# You can pin the exact commit or the version.
# uses: SonarSource/sonarcloud-github-action@v2.2.0
uses: SonarSource/sonarcloud-github-action@4006f663ecaf1f8093e8e4abb9227f6041f52216
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Generate a token on Sonarcloud.io, add it to the secrets of this repo with the name SONAR_TOKEN (Settings > Secrets > Actions > add new repository secret)
Expand All @@ -60,7 +59,7 @@ jobs:
# Comma-separated paths to directories containing main source files.
#-Dsonar.sources= # optional, default is project base directory
# Comma-separated paths to directories containing test source files.
#-Dsonar.tests= # optional. For more info about Code Coverage, please refer to https://docs.sonarcloud.io/enriching/test-coverage/overview/
#-Dsonar.tests= # optional. For more info about Code Coverage, please refer to
# Adds more detail to both client and server-side analysis logs, activating DEBUG mode for the scanner, and adding client-side environment variables and system properties to the server-side log of analysis report processing.
#-Dsonar.verbose= # optional, default is false
# When you need the analysis to take place in a directory other than the one from which it was launched, default is .
Expand Down
688 changes: 344 additions & 344 deletions .pnp.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app/styles/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './globalText.css'
export * from './reset.css'
export * from './reset.css'
85 changes: 85 additions & 0 deletions src/shared/lib/hooks/useModal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {
IExtendedModalConfig,
IModalConfig,
IModalReturn,
} from '@/shared/types/modal.types'
import { useState } from 'react'

const defaultModalConfig: IModalConfig = {
open: false,
btnSize: 24,
outerTouchClose: true,
}

/**
* 동적 모달 관리를 위한 커스텀 훅
* @param {IExtendedModalConfig} config 모달 기본 설정을 할 수 있는 객체(optional)
* - [open=false]: 모달이 열려있는지 여부
* - [showCloseButton=true]: 모달 내부 버튼 유무
* - [btnSize=24]: 모달 내부 버튼 크기 (24, 32 only)
* @returns 모달 설정을 변경할 수 있는 객체
* - {void} toggleModal: 모달을 열거나 닫는 함수
* - {void} showModal: 모달을 열어주는 함수
* - {void} hideModal: 모달을 닫아주는 함수
* - {void} updateModalConfig: 모달 설정을 업데이트하는 함수
* - {object} modalConfig: 모달 설정 - 세부 타입 IModalConfig 참고
*/

const useModal = (config?: IModalConfig): IModalReturn => {
const [modalConfig, setModalConfig] = useState<IModalConfig>({
...defaultModalConfig,
...config,
})

// 모달을 열거나 닫는 함수
const toggleModal = () => {
setModalConfig((prev) => {
return {
...prev,
open: !prev.open,
}
})
}
// 모달을 열어주는 함수
const showModal = () => {
setModalConfig((prev) => {
return {
...prev,
open: true,
}
})
}
// 모달을 닫아주는 함수
const hideModal = () => {
setModalConfig((prev) => {
return {
...prev,
open: false,
}
})
}
// 모달 설정을 업데이트하는 함수
const updateModalConfig = (config: Partial<IModalConfig>) => {
setModalConfig((prev) => {
return {
...prev,
...config,
}
})
}
// 닫기 함수 사용을 위한 모달 설정을 확장
const extendConfig: IExtendedModalConfig = {
...modalConfig,
handleClose: hideModal,
}
// 모달 설정과 함수들을 반환
return {
toggleModal,
showModal,
hideModal,
updateModalConfig,
modalConfig: extendConfig,
}
}

export { useModal }
25 changes: 25 additions & 0 deletions src/shared/types/modal.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export interface IModalConfig {
// 모달이 열려있는지 여부
open?: boolean
// 모달 내부 버튼 유무
showCloseButton?: boolean
// 모달 내부 버튼 크기
btnSize?: 24 | 32
// 외부 클릭으로 모달 닫기
outerTouchClose?: boolean
}

export interface IModalReturn {
// @shared/lib/hooks/useModal 참고
toggleModal: () => void
showModal: () => void
hideModal: () => void
updateModalConfig: (config: Partial<IModalConfig>) => void
modalConfig: IExtendedModalConfig
}
// close 추가한 모달 설정
export interface IExtendedModalConfig extends IModalConfig {
handleClose: () => void
}

export type ModalProps = Readonly<IExtendedModalConfig>
25 changes: 12 additions & 13 deletions src/shared/ui/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { Sprinkles, sprinkles } from '@/app/sprinkle/sprinkle.css'
import { AllHTMLAttributes, ElementType, forwardRef } from 'react'

export interface BoxProps
extends Omit<AllHTMLAttributes<HTMLElement>, 'as' | 'color'>, Sprinkles {
children?: React.ReactNode // 하위 React 노드
className?: string // 클래스 이름
as?: ElementType // HTML 엘리먼트 타입 (기본값: div)
}
import { forwardRef } from 'react'
import { BoxProps } from './box.types'

/**
* Box 컴포넌트는 shared UI 컴포넌트 중 가장 기본이 되는 컴포넌트입니다.
* @param as HTML 엘리먼트 타입 (기본값: div)
* @param children 하위 React 노드
* @param className 클래스 이름
* @param props Sprinkles 속성 및 기타 속성
* @returns Box 컴포넌트
* @param {string} [as = 'div'] HTML 엘리먼트 타입(optional)
* @param {ReactNode} children 하위 React 노드(optional)
* @param {string} className 클래스 이름(optional)
* @param {any} props Sprinkles 속성 및 기타 속성
* @returns {JsxElement} Box 컴포넌트
* @example
* <Box as={'div' | 'span' | ...} className="example"">
* <p>example</p>
* </Box>
*/

export const Box = forwardRef<HTMLElement, BoxProps>(
(
{
Expand Down
12 changes: 12 additions & 0 deletions src/shared/ui/Box/box.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AllHTMLAttributes, ElementType } from 'react'
import { Sprinkles } from '@/app/sprinkle/sprinkle.css'

export interface IBox
extends Omit<AllHTMLAttributes<HTMLElement>, 'as' | 'color'>,
Sprinkles {
children?: React.ReactNode // 하위 React 노드
className?: string // 클래스 이름
as?: ElementType // HTML 엘리먼트 타입 (기본값: div)
}

export type BoxProps = Readonly<IBox>
3 changes: 2 additions & 1 deletion src/shared/ui/Box/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Box'
export * from './Box'
export * from './box.types'
49 changes: 49 additions & 0 deletions src/shared/ui/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { IExtendedModalConfig } from '@/shared/types/modal.types'
import { Box } from '../Box'
import { modalBackdrop, modalContent } from './modal.css'

/**
* 공용 모달 컴포넌트
* @param {ReactNode} children 모달 내부에 들어갈 컨텐츠 (optional)
* @parms modalConfig 모달 설정 - useModal에서 반환된 modalConfig
* @returns {JsxElement}닫기 버튼이 존재하지 않는 모달
* @example
* const { modalConfig, toggleModal } = useModal({ open: true });
* <Modal modalConfig={modalConfig}>
* <p>example</p>
* <button onClick={toggleModal}>toggle</button>
* </Modal>
*/

export default function Modal({
children,
modalConfig,
}: Readonly<{
children?: React.ReactNode
modalConfig: IExtendedModalConfig
}>) {
if (modalConfig.open === false) return null
return (
<Box
as={'div'}
onClick={() =>
modalConfig.outerTouchClose && modalConfig.handleClose()
}
role="presentation"
className={modalBackdrop}
display="flex"
justifyContent="center"
alignItems="center"
>
<Box
as={'dialog'}
onClick={(e) => e.stopPropagation()}
className={modalContent}
display="flex"
flexDirection="column"
>
{children}
</Box>
</Box>
)
}
16 changes: 16 additions & 0 deletions src/shared/ui/Modal/modal.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { style } from '@vanilla-extract/css'

export const modalBackdrop = style({
position: 'fixed',
top: 0,
left: 0,
width: '100%',
height: '100%',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
})

export const modalContent = style({
minWidth: '300px',
backgroundColor: 'white',
borderRadius: '4px',
})