Skip to content

Commit

Permalink
refactor(ui): SelectV2 TriggerContent 내 커스텀 Icon을 적용할 수 있도록 icon prop…
Browse files Browse the repository at this point in the history
… 추가. (#228)

* refactor: 커스텀 Icon을 적용할 수 있도록 icon prop 추가.

* cs
  • Loading branch information
Brokyeom authored Dec 15, 2024
1 parent da32f45 commit 161f23a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-owls-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sopt-makers/ui': patch
---

SelectV2 TriggerContent 내 커스텀 Icon을 적용할 수 있도록 icon prop 추가.
26 changes: 17 additions & 9 deletions packages/ui/Input/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ReactNode } from 'react';
import { useState, useRef, useEffect, useCallback, createContext, useContext } from 'react';
import { IconChevronDown, IconUser } from '@sopt-makers/icons';
import { createPortal } from 'react-dom';
Expand Down Expand Up @@ -147,25 +148,32 @@ function SelectTrigger({ children }: SelectTriggerProps) {
interface SelectTriggerContentProps {
placeholder?: string;
className?: string;
icon?: ReactNode;
}

// Select.TriggerContent 컴포넌트: trigger의 미리 정의된 UI
function SelectTriggerContent({ placeholder, className }: SelectTriggerContentProps) {
function SelectTriggerContent(props: SelectTriggerContentProps) {
const { placeholder, className, icon } = props;

const { open, selected } = useSelectContext();

const selectedLabel = selected ? selected.label : placeholder;

return (
<div className={`${S.select} ${open ? S.focus : ''} ${className}`}>
<p className={!selected ? S.selectPlaceholder : ''}>{selectedLabel}</p>
<IconChevronDown
style={{
width: 20,
height: 20,
transform: open ? 'rotate(-180deg)' : '',
transition: 'all 0.3s ease',
}}
/>
{icon ? (
icon
) : (
<IconChevronDown
style={{
width: 20,
height: 20,
transform: open ? 'rotate(-180deg)' : '',
transition: 'all 0.3s ease',
}}
/>
)}
</div>
);
}
Expand Down

0 comments on commit 161f23a

Please sign in to comment.