-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui-kit): Selection 컴포넌트 추가 (#32)
* feat(ui-kit): Selection 컴포넌트 추가 * feat(ui-kit): Selection 컴포넌트에 아이콘 추가 * feat(ui-kit): Selection 컴포넌트 스토리 추가 * feat(ui-kit): 타입 픽스 * 타입 픽스 * feat(ui-kit): Selection 컴포넌트를 Borderless로 변경 * feat(ui-kit): 리뷰 반영
- Loading branch information
Showing
16 changed files
with
267 additions
and
18 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
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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
import React, { useMemo } from 'react'; | ||
import classnames from 'classnames'; | ||
import { Colors, colors } from 'src/constants/colors'; | ||
|
||
/** | ||
* UI Kit 내부에서만 사용 | ||
*/ | ||
|
||
interface Props { | ||
icon: string; | ||
size?: number; | ||
type: 'outline' | 'filled'; | ||
color?: Colors; | ||
} | ||
|
||
const Icon = ({ icon, size = 16, type, color = colors.gray100 }: Props) => { | ||
const svgTag = useMemo(() => { | ||
return icon.replace(/data:image\/svg\+xml;utf8,/, ''); | ||
}, [icon]); | ||
|
||
const coloredSvg = useMemo(() => { | ||
const targetAttr = type === 'outline' ? 'stroke' : 'fill'; | ||
return svgTag.replace(/(<path\s)\b/gm, `$1${targetAttr}="${color}" `); | ||
}, [svgTag, color]); | ||
|
||
return ( | ||
<span | ||
className={classnames('lubycon-icon', { | ||
'lubycon-icon--outline': type === 'outline', | ||
'lubycon-icon--filled': type === 'filled', | ||
})} | ||
style={{ width: size, height: size }} | ||
dangerouslySetInnerHTML={{ __html: coloredSvg }} | ||
/> | ||
); | ||
}; | ||
|
||
export default Icon; |
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,63 @@ | ||
import React, { forwardRef, Ref } from 'react'; | ||
import { CombineElementProps } from 'src/types/utils'; | ||
import classnames from 'classnames'; | ||
import { chevronDownOutline } from 'ionicons/icons'; | ||
import Icon from 'components/Icon'; | ||
import { colors } from 'src/constants/colors'; | ||
import { useState } from 'react'; | ||
import { useEffect } from 'react'; | ||
import { Typographys } from '../Text/types'; | ||
|
||
interface SelectionBaseProps { | ||
placeholder?: string; | ||
size?: 'small' | 'medium' | 'large'; | ||
} | ||
type SelectionProps = Omit<CombineElementProps<'select', SelectionBaseProps>, 'multiple'>; | ||
|
||
const Selection = ( | ||
{ | ||
placeholder = '옵션을 선택하세요', | ||
disabled, | ||
children, | ||
value, | ||
onChange, | ||
size = 'medium', | ||
...props | ||
}: SelectionProps, | ||
ref: Ref<HTMLSelectElement> | ||
) => { | ||
const [innerValue, setInnerValue] = useState(value ?? ''); | ||
const iconColor = disabled ? colors.gray60 : colors.gray40; | ||
const typography: Typographys = size === 'large' ? 'content' : 'content2'; | ||
|
||
useEffect(() => setInnerValue(value ?? ''), [value]); | ||
|
||
return ( | ||
<div | ||
className={classnames('lubycon-selection', `lubycon-selection--size-${size}`, { | ||
'lubycon-selection--disabled': disabled, | ||
'lubycon-selection--empty': innerValue === '', | ||
})} | ||
> | ||
<select | ||
ref={ref} | ||
multiple={false} | ||
{...props} | ||
value={innerValue} | ||
className={classnames('lubycon-selection__select', `lubycon-typography--${typography}`)} | ||
onChange={(e) => { | ||
onChange?.(e); | ||
setInnerValue(e.target.value ?? ''); | ||
}} | ||
> | ||
<option value="" hidden={true} className="lubycon-selection__placeholder"> | ||
{placeholder} | ||
</option> | ||
{children} | ||
</select> | ||
<Icon icon={chevronDownOutline} type="outline" color={iconColor} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default forwardRef(Selection) as typeof Selection; |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export { default as Button } from './Button'; | ||
export { default as Text } from './Text'; | ||
export { Row, Column } from './Grid'; | ||
export { default as Checkbox } from './Checkbox'; | ||
export { Row, Column } from './Grid'; | ||
export { default as Radio } from './Radio'; | ||
export { default as Selection } from './Selection'; | ||
export { default as Switch } from './Switch'; | ||
export { default as Text } from './Text'; |
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,17 @@ | ||
.lubycon-icon { | ||
display: inline-block; | ||
&--outline { | ||
path { | ||
fill: transparent; | ||
} | ||
} | ||
&--filled { | ||
path { | ||
stroke: transparent; | ||
} | ||
} | ||
svg { | ||
width: 100%; | ||
vertical-align: top; | ||
} | ||
} |
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,57 @@ | ||
.lubycon-selection { | ||
position: relative; | ||
display: inline-block; | ||
background-color: white; | ||
border-radius: 8px; | ||
cursor: pointer; | ||
transition: background-color 0.2s ease-in-out; | ||
|
||
&:hover { | ||
background-color: get-color('gray20'); | ||
} | ||
|
||
&--disabled { | ||
background-color: get-color('gray40'); | ||
cursor: not-allowed; | ||
&:hover { | ||
background-color: get-color('gray40'); | ||
} | ||
} | ||
|
||
&--empty select.lubycon-selection__select { | ||
color: get-color('gray50'); | ||
} | ||
|
||
&--size-small { | ||
.lubycon-selection__select { | ||
padding: 4px 32px 4px 16px; | ||
} | ||
} | ||
&--size-medium { | ||
.lubycon-selection__select { | ||
padding: 8px 36px 8px 16px; | ||
} | ||
} | ||
&--size-large { | ||
.lubycon-selection__select { | ||
padding: 12px 60px 12px 20px; | ||
} | ||
} | ||
|
||
.lubycon-selection__select { | ||
width: 100%; | ||
background-color: transparent; | ||
appearance: none; | ||
outline: none; | ||
border: none; | ||
cursor: inherit; | ||
} | ||
|
||
.lubycon-icon { | ||
position: absolute; | ||
right: 12px; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
stroke: get-color('grey40'); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
@import './Column'; | ||
@import './Checkbox'; | ||
@import './Switch'; | ||
@import './Selection'; | ||
@import './Icon'; |
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,63 @@ | ||
import React, { useMemo, useState } from 'react'; | ||
import { Meta } from '@storybook/react/types-6-0'; | ||
import Selection from 'components/Selection'; | ||
import Text from 'components/Text'; | ||
|
||
export default { | ||
title: 'Lubycon UI Kit/Selection', | ||
} as Meta; | ||
|
||
export const Default = () => { | ||
const [state, setState] = useState(''); | ||
|
||
return ( | ||
<div> | ||
<Selection onChange={(e) => setState(e.target.value)}> | ||
<option>옵션1</option> | ||
<option>옵션2</option> | ||
<option>옵션3</option> | ||
</Selection> | ||
<Text style={{ display: 'block' }}>선택된 값은 {state}입니다.</Text> | ||
</div> | ||
); | ||
}; | ||
|
||
export const Sizes = () => { | ||
const selections = useMemo(() => { | ||
return ['small', 'medium', 'large'].map((size) => ( | ||
<li key={size} style={{ marginBottom: 16, listStyle: ' none' }}> | ||
<Selection placeholder={size} size={size as any}> | ||
<option>옵션1</option> | ||
<option>옵션2</option> | ||
<option>옵션3</option> | ||
</Selection> | ||
</li> | ||
)); | ||
}, []); | ||
return <ul>{selections}</ul>; | ||
}; | ||
|
||
export const Disabled = () => { | ||
return ( | ||
<div> | ||
<Selection disabled> | ||
<option>옵션1</option> | ||
<option>옵션2</option> | ||
<option>옵션3</option> | ||
</Selection> | ||
</div> | ||
); | ||
}; | ||
|
||
export const Placeholder = () => { | ||
return ( | ||
<div> | ||
<Selection placeholder="어느 곳에 사시나요?"> | ||
<option>서울</option> | ||
<option>경기</option> | ||
<option>인천</option> | ||
<option>충남</option> | ||
</Selection> | ||
</div> | ||
); | ||
}; |
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