Skip to content

refactor(card): add custom ratio for better flexibility#101

Merged
froggy1014 merged 7 commits intomainfrom
refactor/card-ratio-addition
Jan 14, 2025
Merged

refactor(card): add custom ratio for better flexibility#101
froggy1014 merged 7 commits intomainfrom
refactor/card-ratio-addition

Conversation

@froggy1014
Copy link
Copy Markdown
Contributor

@froggy1014 froggy1014 commented Jan 12, 2025

Changes

기존에 반드시 aspect-ratio가 default로 들어가는 문제가 있어서 사용자가 Card 컴포넌트로 UI를 좀 더 유연하게 구현하기 힘들다는 피드백이 있어서 이에 수정합니다.

export type CardRatio = 'rectangle' | 'square' | 'wide' | 'portrait' | 'auto';

function getAspectRatio(ratio: CardRatio) {
  switch (ratio) {
    case 'square':
      return '1 / 1';
    case 'rectangle':
      return '16 / 9';
    case 'wide':
      return '21 / 9';
    case 'portrait':
      return '3 / 4';
    default:
      return 'auto';
  }
}

Visuals

Checklist

  • Have you written the functional specifications?
  • Have you written the test code?

Additional Discussion Points

Summary by CodeRabbit

  • 새로운 기능

    • 카드 컴포넌트에 사용자 정의 비율 옵션 추가
    • 카드의 레이아웃 유연성 향상
  • 변경 사항

    • 기본 카드 비율을 'rectangle'에서 'auto'로 변경
    • 새로운 카드 비율 유형 'auto' 도입
    • 가로세로 비율 계산 로직 업데이트
  • 테스트

    • 카드 컴포넌트의 비율 및 변형 속성에 대한 새로운 테스트 케이스 추가

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 12, 2025

🦋 Changeset detected

Latest commit: 39ef0a5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@sipe-team/card Minor
@sipe-team/side Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 12, 2025

Warning

Rate limit exceeded

@froggy1014 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 24 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between ec55c39 and 39ef0a5.

📒 Files selected for processing (1)
  • README.md (1 hunks)

워크스루

이 풀 리퀘스트는 @sipe-team/card 컴포넌트에 대한 업데이트를 포함하고 있습니다. 카드 컴포넌트에 새로운 커스텀 비율 옵션을 추가하여 레이아웃의 유연성을 향상시켰습니다. 또한 package.json의 lint-staged 구성을 수정하고, Storybook의 기본 스토리 구성을 변경했습니다.

변경 사항

파일 변경 요약
.changeset/eighty-apricots-punch.md 카드 컴포넌트의 커스텀 비율 기능 추가
package.json lint-staged 구성에서 markdown 파일 제외
packages/card/src/Card.stories.tsx 스토리북에서 카드 컴포넌트의 비율 및 변형 속성 추가
packages/card/src/Card.tsx - CardRatio 타입에 'auto' 추가
- 기본 비율을 'rectangle'에서 'auto'로 변경
- getAspectRatio 함수 업데이트
packages/card/src/Card.test.tsx 카드 컴포넌트의 비율 및 변형 속성에 대한 테스트 추가

관련 가능성 있는 PR

제안된 리뷰어

  • noahluftyang
  • bae-sh
  • heeji289
  • synuns
  • developerjhp
  • kimdaeyeobbb

토끼의 시 🐰

카드야, 너의 새 옷은 특별해
비율은 자유, 스타일은 날개
커스텀의 마법, 유연함의 춤
디자인의 세계에 반짝이는 꿈 🌈


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.changeset/eighty-apricots-punch.md (1)

1-5: 변경사항 설명을 더 자세히 작성해주세요

현재 설명이 너무 간단합니다. 다음과 같은 내용을 포함하면 좋을 것 같습니다:

  • 커스텀 비율 기능의 사용 사례
  • 기존 비율과의 차이점
  • 마이그레이션 가이드 (필요한 경우)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ad7591 and 236954d.

📒 Files selected for processing (4)
  • .changeset/eighty-apricots-punch.md (1 hunks)
  • package.json (1 hunks)
  • packages/card/src/Card.stories.tsx (1 hunks)
  • packages/card/src/Card.tsx (3 hunks)
🔇 Additional comments (4)
packages/card/src/Card.stories.tsx (1)

18-18: 기본 비율 변경에 대한 검토가 필요합니다

기본 스토리의 비율이 'rectangle'에서 'portrait'로 변경되었습니다. 이는 커스텀 비율 기능 추가라는 PR의 주요 목적과 맞지 않아 보입니다. 'custom' 비율을 보여주는 새로운 스토리를 추가하는 것이 더 적절할 것 같습니다.

packages/card/src/Card.tsx (2)

12-12: 타입 정의가 적절해 보입니다

CardRatio 타입에 'custom' 옵션을 추가한 것이 적절합니다.


24-24: 기본값 변경에 대한 주의가 필요합니다

기본값을 'custom'으로 변경하는 것은 기존 사용자에게 영향을 줄 수 있습니다. 다음 사항을 고려해주세요:

  • 기존 코드의 호환성
  • 마이그레이션 가이드 필요성
  • 기본값으로 'rectangle' 유지 검토
package.json (1)

62-62: Markdown 파일 린트 제외에 대한 검토가 필요합니다

lint-staged 설정에서 Markdown 파일이 제외되었습니다. 이는 다음과 같은 영향을 줄 수 있습니다:

  • 문서 포맷팅 일관성 저하
  • 문서 품질 관리의 어려움

가능하다면 Markdown 파일을 린트 대상에 포함하는 것을 고려해주세요.

Comment on lines +78 to +81
case 'custom':
return 'auto';
default:
return '16 / 9';
return 'auto';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

getAspectRatio 함수의 개선이 필요합니다

'custom'과 default case 모두 'auto'를 반환하고 있습니다. 다음과 같은 개선을 제안합니다:

  1. 'custom' 케이스에서 사용자 정의 비율을 받을 수 있도록 함수 시그니처 수정
  2. default case에서 적절한 fallback 값 설정

예시 구현:

-function getAspectRatio(ratio: CardRatio) {
+function getAspectRatio(ratio: CardRatio, customRatio?: string) {
   switch (ratio) {
     case 'square':
       return '1 / 1';
     case 'rectangle':
       return '16 / 9';
     case 'wide':
       return '21 / 9';
     case 'portrait':
       return '3 / 4';
     case 'custom':
-      return 'auto';
+      return customRatio ?? 'auto';
     default:
-      return 'auto';
+      return '16 / 9';
   }
 }

Committable suggestion skipped: line range outside the PR's diff.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
packages/card/src/Card.test.tsx 100.00% <100.00%> (ø)
packages/card/src/Card.tsx 100.00% <100.00%> (ø)

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/card/src/Card.test.tsx (2)

40-53: 비율 관련 테스트 케이스 보완이 필요합니다

현재 테스트는 기본적인 케이스만 다루고 있습니다. 다음과 같은 추가 테스트 케이스가 필요해 보입니다:

  • 잘못된 ratio 값이 전달되었을 때의 동작
  • ratio prop이 undefined일 때의 동작

예시 테스트 케이스:

test('ratio prop이 없을 때 기본값으로 rectangle이 적용된다.', () => {
  render(<Card>Card</Card>);
  expect(screen.getByText('Card')).toHaveStyle('aspect-ratio: 16 / 9');
});

test('잘못된 ratio 값이 전달되면 기본값이 적용된다.', () => {
  render(<Card ratio={'invalid' as CardRatio}>Card</Card>);
  expect(screen.getByText('Card')).toHaveStyle('aspect-ratio: 16 / 9');
});

69-81: variant 배경색 테스트의 가독성 개선이 필요합니다

현재 테스트 설명에 템플릿 리터럴로 색상 값이 포함되어 있어 가독성이 떨어집니다.

다음과 같이 개선하는 것을 제안드립니다:

- test(`variant가 filled일 때 배경색이 ${color.gray100}이다.`, () => {
+ test('variant가 filled일 때 올바른 배경색이 적용된다.', () => {

- test(`variant가 outline일 때 배경색이 ${color.gray50}이다.`, () => {
+ test('variant가 outline일 때 올바른 배경색이 적용된다.', () => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 236954d and 0b834f0.

📒 Files selected for processing (2)
  • packages/card/src/Card.test.tsx (2 hunks)
  • packages/card/src/Card.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: chromatic
🔇 Additional comments (2)
packages/card/src/Card.tsx (2)

79-79: ⚠️ Potential issue

getAspectRatio의 default case 처리 방식 개선이 필요합니다

default case에서 'auto'를 반환하는 것은 예측하기 어려운 동작을 초래할 수 있습니다. 이는 이전 버전과의 호환성 문제도 발생시킬 수 있습니다.

다음과 같은 개선을 제안드립니다:

    default:
-      return 'auto';
+      return '16 / 9';  // 이전 버전과의 호환성 유지

Likely invalid or redundant comment.


12-12: CardRatio 타입에 'auto' 추가에 대한 검토가 필요합니다

'auto' 값의 추가는 좋은 개선이지만, 이전 리뷰에서 논의된 'custom' 비율 지원에 대한 요구사항이 해결되지 않았습니다.

사용자 정의 비율을 지원하기 위해 다음과 같은 접근 방식을 고려해보시는 것은 어떨까요?

export type CardRatio = 
  | 'rectangle' 
  | 'square' 
  | 'wide' 
  | 'portrait' 
  | 'auto' 
  | { width: number; height: number };
✅ Verification successful

'auto' 타입 추가는 적절하며, 커스텀 비율은 향후 개선사항으로 고려하시면 좋겠습니다

현재 구현된 'auto' 옵션은 기존 기능을 해치지 않으면서 유연성을 제공합니다. 커스텀 비율 지원은 좋은 제안이지만, 이는 별도의 기능 개선으로 다루는 것이 적절해 보입니다.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Find all usages of CardRatio
rg "CardRatio" -B 2 -A 2

# Check if there was any previous custom ratio implementation
ast-grep --pattern 'type CardRatio = $$$'

# Look for ratio-related logic in Card component
ast-grep --pattern 'function getAspectRatio($$$) {
  $$$
}'

Length of output: 1692

Copy link
Copy Markdown

@Huinno-ParkJinHyun Huinno-ParkJinHyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍👍👍!!!

@kimdaeyeob
Copy link
Copy Markdown
Contributor

LGTM 👍

Copy link
Copy Markdown
Member

@synuns synuns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!!

@froggy1014 froggy1014 merged commit 9903559 into main Jan 14, 2025
@froggy1014 froggy1014 deleted the refactor/card-ratio-addition branch January 14, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants