-
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.
Merge remote-tracking branch 'origin/main' into main
- Loading branch information
Showing
8 changed files
with
152 additions
and
16 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 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