-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: changeLog 추가 * chore: modify template * input 매개변수 및 마진 값 수정 (#12) * (#11) refactor: setState -> onChange로 변경 * (#11) fix: margin left 6px 추가 * (#14) feat: modal 매개변수로 children 추가 (#15) * fix: input label 옵셔널 * fix: modal children 옵셔널 * fix: search setState -> onChange * fix: index에서 name CheckBox로 export * (#19) feat: Segmented Button * fix: margin 로직 수정 * fix: input 에러메시지 빈 값일 때에도 추가
- Loading branch information
조상현
authored
Dec 21, 2022
1 parent
7a0204c
commit 7670d58
Showing
7 changed files
with
139 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
import { useState } from 'react'; | ||
import { SegmentedBtn } from '.'; | ||
|
||
export default { | ||
title: 'component/segmentedBtn', | ||
component: SegmentedBtn, | ||
} as ComponentMeta<typeof SegmentedBtn>; | ||
|
||
const selectedArr = ['A', 'B', 'C']; | ||
|
||
const Template: ComponentStory<typeof SegmentedBtn> = (args) => { | ||
const [state, setState] = useState<string | number>(selectedArr[0]); | ||
const onChange = (selected: string | number) => { | ||
setState(selected); | ||
}; | ||
return ( | ||
<SegmentedBtn | ||
onChange={onChange} | ||
selectedArr={selectedArr} | ||
cur={state} | ||
{...args} | ||
/> | ||
); | ||
}; | ||
|
||
export const segmentedBtn = Template.bind({}); |
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,71 @@ | ||
import styled, { css } from 'styled-components'; | ||
import { marginCssType, marginToCss } from '../../utils/distance'; | ||
import { Text } from '../styleGuide/text/Text'; | ||
|
||
interface PropsType<T> extends marginCssType { | ||
selectedArr: T[]; | ||
cur: T; | ||
onChange: (selected: T) => void; | ||
} | ||
|
||
export const SegmentedBtn = <T extends string | number>({ | ||
selectedArr, | ||
cur, | ||
onChange, | ||
margin, | ||
}: PropsType<T>) => { | ||
return ( | ||
<_Wrapper margin={margin}> | ||
{selectedArr.map((selected) => ( | ||
<_SelectedItem | ||
onClick={() => onChange(selected)} | ||
display="inline-block" | ||
key={selected} | ||
> | ||
<_SelectedInner cur={selected === cur}>{selected}</_SelectedInner> | ||
</_SelectedItem> | ||
))} | ||
</_Wrapper> | ||
); | ||
}; | ||
|
||
const _Wrapper = styled.div<marginCssType>` | ||
${({ margin }) => marginToCss({ margin })}; | ||
display: inline-block; | ||
height: 48px; | ||
border: 1px solid ${({ theme }) => theme.color.primaryLighten1}; | ||
cursor: pointer; | ||
border-radius: 4px; | ||
> div { | ||
:first-of-type { | ||
left: -1px; | ||
} | ||
:last-of-type { | ||
right: -1px; | ||
} | ||
} | ||
`; | ||
|
||
const _SelectedItem = styled(Text)` | ||
color: ${({ theme }) => theme.color.gray4}; | ||
width: 110px; | ||
height: 48px; | ||
transition: 0.15s; | ||
position: relative; | ||
top: -1px; | ||
`; | ||
|
||
const _SelectedInner = styled.div<{ cur: boolean }>` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
transition: 0.15s; | ||
${({ theme, cur }) => | ||
cur && | ||
css` | ||
background-color: ${theme.color.primary}; | ||
border-radius: 4px; | ||
color ${theme.color.gray1} | ||
`}; | ||
`; |
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