-
Notifications
You must be signed in to change notification settings - Fork 1
[FE-Feat] 세그먼트 컨트롤 구현 수정 #192
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
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThis update introduces several enhancements to the segment control feature. New components, including a Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant CB as ControlButton
participant SC as SegmentControlContext
participant C as Content
U->>CB: Click on button
CB->>SC: Invoke handleSelect(value)
SC->>C: Update selectedValue in context
C-->>U: Conditionally render content if value matches
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
frontend/src/components/SegmentControl/index.tsx (1)
10-16: Consider validating emptyvalues.If
valuesis empty,defaultValuebecomes an empty string. This might cause unexpected behavior (e.g., no button is selected). You could display a fallback or throw an error to ensure a functional SegmentControl.export interface SegmentControlProps extends PropsWithChildren { values: string[]; style?: 'weak' | 'filled'; shadow?: boolean; defaultValue?: string; onValueChange?: (value: string) => void; }; +// Consider adding a runtime check or fallback +// if (!values?.length) { +// throw new Error("SegmentControl requires a non-empty 'values' array."); +// }frontend/src/components/SegmentControl/SegmentControlContext.ts (1)
8-8: Initialized context with null default.This is a common pattern, ensures consumers can handle a null context if unwrapped incorrectly. Consider using a safer approach that warns if context is used without a provider.
frontend/src/components/SegmentControl/Content.tsx (1)
9-24: Conditional content rendering is clean and extensible.• The
Contentcomponent gracefully renders children only ifselectedValue === value.
• Using the local context ensures a straightforward user experience.
• Consider adding a test case to ensure correct behavior when multipleContentcomponents appear with different values.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
frontend/src/components/SegmentControl/Content.tsx(1 hunks)frontend/src/components/SegmentControl/ControlButton.tsx(1 hunks)frontend/src/components/SegmentControl/SegmentControl.stories.tsx(1 hunks)frontend/src/components/SegmentControl/SegmentControlContext.ts(1 hunks)frontend/src/components/SegmentControl/index.css.ts(2 hunks)frontend/src/components/SegmentControl/index.tsx(1 hunks)frontend/src/features/shared-schedule/ui/UnConfirmedSchedules/index.tsx(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Send PR Notification to Reviewers
🔇 Additional comments (18)
frontend/src/components/SegmentControl/index.tsx (6)
1-1: Good use ofPropsWithChildren.Using
PropsWithChildrenclarifies that this component can wrap child elements, making the component flexible and self-contained.
4-8: Imports look appropriate and consistent.All imported modules are relevant for layout, context, and styling. No issues found.
19-24: Destructure props carefully.The usage of
defaultValue = values[0] ?? ''is neat, but see the earlier suggestion about validatingvalues. Otherwise, this is a clean and idiomatic approach.
30-30: Optional callback usage looks correct.
onValueChange?.(value)is a safe optional call that prevents errors if no callback is passed.
34-53: Good usage of context and composition.Providing
selectedValueandhandleSelectthrough a context fosters an extendable design. Rendering buttons and children inside a<Flex>container is straightforward.
57-57: AttachingContentas a static property.Exporting
SegmentControl.Contentis a convenient approach to nest related components. This pattern might be less discoverable for some developers, but it’s a neat pattern for your library.frontend/src/components/SegmentControl/SegmentControlContext.ts (2)
1-1: Context creation is straightforward.
createContextis correctly imported from React. No issues here.
3-6: Context props nicely typed.Defining
selectedValueandhandleSelecton the context makes the API clear.frontend/src/components/SegmentControl/Content.tsx (1)
1-7: Imports align with usage needs.
PropsWithChildren, customuseSafeContexthook, and local utilities/styles are properly imported.frontend/src/components/SegmentControl/index.css.ts (2)
6-30: LGTM! Clear and descriptive style name.The rename from
segmentControlContainertocontrolButtonContainerStylebetter reflects the style's purpose and improves code readability.
32-34: LGTM! Simple and effective content style.The
contentContainerStylewithwidth: '100%'ensures content spans the full width of its container.frontend/src/components/SegmentControl/SegmentControl.stories.tsx (2)
20-25: LGTM! Simplified API with direct values.The Default story now uses a simpler
valuesarray instead of complex options objects, making the API more intuitive.
27-33: LGTM! Clear demonstration of content functionality.The WithContent story effectively demonstrates how to define content within the segment control, aligning with the PR objectives.
frontend/src/features/shared-schedule/ui/UnConfirmedSchedules/index.tsx (2)
10-10: LGTM! Clean implementation of the new SegmentControl API.The component has been updated to use the simplified SegmentControl API with direct values and defaultValue.
Also applies to: 22-22
12-12: Verify the empty schedule objects.The schedules array contains empty objects which might indicate incomplete implementation or placeholder data.
Could you clarify if this is intentional or if it needs to be updated with actual schedule data?
frontend/src/components/SegmentControl/ControlButton.tsx (3)
7-11: LGTM! Clear and typed props interface.The ControlButtonProps interface clearly defines the required and optional props.
13-33: LGTM! Well-structured component with proper event handling.The component effectively uses context and handles click events. The button styling is appropriately configured.
35-39: LGTM! Clean and maintainable style selection logic.The getButtonStyle function provides a clear and maintainable way to determine button styles based on selection state.
| const ControlButton = ({ | ||
| value, | ||
| segmentControlStyle, | ||
| key, |
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.
p2; key 삭제좀요
#️⃣ 연관된 이슈>
📝 작업 내용> 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)
🙏 여기는 꼭 봐주세요! > 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요
Summary by CodeRabbit
New Features
ContentandControlButtoncomponents for enhanced segmented control functionality.Refactor
Style