File tree Expand file tree Collapse file tree 4 files changed +129
-0
lines changed
src/page/mandal/component/Toggle Expand file tree Collapse file tree 4 files changed +129
-0
lines changed Original file line number Diff line number Diff line change 1+ import { style } from '@vanilla-extract/css' ;
2+
3+ import { colors } from '@/style/token' ;
4+ import { fonts } from '@/style/token/typography.css' ;
5+
6+ export const toggleWrapper = style ( {
7+ display : 'flex' ,
8+ width : '16rem' ,
9+ height : '4.2rem' ,
10+ borderRadius : '0.8rem' ,
11+ backgroundColor : colors . grey3 ,
12+ } ) ;
13+
14+ export const toggleButton = style ( [
15+ fonts . body01 ,
16+ {
17+ display : 'flex' ,
18+ width : '50%' ,
19+ height : '100%' ,
20+ justifyContent : 'center' ,
21+ alignItems : 'center' ,
22+ color : colors . white01 ,
23+ cursor : 'pointer' ,
24+ border : 'none' ,
25+ backgroundColor : 'transparent' ,
26+ } ,
27+ ] ) ;
28+
29+ const activeButtonBase = style ( {
30+ backgroundImage : colors . gradient05 ,
31+ } ) ;
32+
33+ export const leftActiveButton = style ( [
34+ activeButtonBase ,
35+ {
36+ borderRadius : '8px 0 0 8px' ,
37+ } ,
38+ ] ) ;
39+
40+ export const rightActiveButton = style ( [
41+ activeButtonBase ,
42+ {
43+ borderRadius : '0 8px 8px 0' ,
44+ } ,
45+ ] ) ;
Original file line number Diff line number Diff line change 1+ import type { Meta , StoryObj } from '@storybook/react-vite' ;
2+
3+ import Toggle from './Toggle' ;
4+
5+ const meta = {
6+ title : 'Mandal/Toggle' ,
7+ component : Toggle ,
8+ parameters : {
9+ layout : 'centered' ,
10+ backgrounds : {
11+ default : 'dark' ,
12+ } ,
13+ } ,
14+ tags : [ 'autodocs' ] ,
15+ argTypes : {
16+ defaultValue : {
17+ control : 'radio' ,
18+ options : [ 'onlygoal' , 'whole' ] ,
19+ } ,
20+ onChange : { action : 'changed' } ,
21+ } ,
22+ } satisfies Meta < typeof Toggle > ;
23+
24+ export default meta ;
25+ type Story = StoryObj < typeof meta > ;
26+
27+ export const OnlyGoal : Story = {
28+ name : '목표만' ,
29+ args : {
30+ defaultValue : 'onlygoal' ,
31+ } ,
32+ } ;
33+
34+ export const Whole : Story = {
35+ name : '전체' ,
36+ args : {
37+ defaultValue : 'whole' ,
38+ } ,
39+ } ;
Original file line number Diff line number Diff line change 1+ import { useState } from 'react' ;
2+
3+ import * as styles from './Toggle.css' ;
4+
5+ type ToggleType = 'onlygoal' | 'whole' ;
6+
7+ interface ToggleProps {
8+ defaultValue ?: ToggleType ;
9+ onChange ?: ( type : ToggleType ) => void ;
10+ }
11+
12+ const Toggle = ( { defaultValue = 'onlygoal' , onChange } : ToggleProps ) => {
13+ const [ activeType , setActiveType ] = useState < ToggleType > ( defaultValue ) ;
14+
15+ const handleClick = ( type : ToggleType ) => {
16+ setActiveType ( type ) ;
17+ onChange ?.( type ) ;
18+ } ;
19+
20+ return (
21+ < div className = { styles . toggleWrapper } >
22+ < button
23+ type = "button"
24+ className = { `${ styles . toggleButton } ${
25+ activeType === 'onlygoal' ? styles . leftActiveButton : ''
26+ } `}
27+ onClick = { ( ) => handleClick ( 'onlygoal' ) }
28+ >
29+ 목표만
30+ </ button >
31+ < button
32+ type = "button"
33+ className = { `${ styles . toggleButton } ${
34+ activeType === 'whole' ? styles . rightActiveButton : ''
35+ } `}
36+ onClick = { ( ) => handleClick ( 'whole' ) }
37+ >
38+ 전체
39+ </ button >
40+ </ div >
41+ ) ;
42+ } ;
43+
44+ export default Toggle ;
Original file line number Diff line number Diff line change 1+ export { default } from './Toggle' ;
You can’t perform that action at this time.
0 commit comments