@@ -2,45 +2,41 @@ import { SETTINGS } from '@constants';
22import { AvatarOption } from '@types' ;
33
44interface IProps {
5- avatarOption : AvatarOption
6- setAvatarOption : ( newOption : AvatarOption ) => void
5+ avatarOption : AvatarOption ;
6+ setAvatarOption : ( newOption : AvatarOption ) => void ;
77}
8-
98export default function ColorListItem ( props : IProps ) {
10- const { setAvatarOption, avatarOption } = props ;
11- const onSwitchBgColor = ( bgColor : string ) => {
12- if ( bgColor !== avatarOption . background . color ) {
13- setAvatarOption ( {
14- ... avatarOption ,
15- background : { ...avatarOption . background , color : bgColor } ,
16- } )
17- }
9+ const { setAvatarOption, avatarOption } = props ;
10+
11+ const onSwitchBgColor = ( bgColor : string ) => {
12+ if ( bgColor !== avatarOption . background . color ) {
13+ setAvatarOption ( {
14+ ...avatarOption ,
15+ background : { ... avatarOption . background , color : bgColor } ,
16+ } ) ;
1817 }
19- return (
20- < ul className = 'color-list' >
21- {
22- SETTINGS . backgroundColor . map ( ( bgColor : string ) => {
23- return (
24- < li
25- key = { bgColor }
26- className = 'color-list__item'
27- onClick = { ( ) => onSwitchBgColor ( bgColor ) }
28- >
29- < div
30- style = { { background : bgColor } }
31- className = { `bg-color ${
32- bgColor === avatarOption . background . color
33- ? 'active'
34- : bgColor === 'transparent'
35- ? 'transparent'
36- : ''
37- } `}
18+ } ;
19+
20+ const getBgColorClass = ( bgColor : string ) => {
21+ if ( bgColor === avatarOption . background . color ) return 'active' ;
22+ if ( bgColor === 'transparent' ) return 'transparent' ;
23+ return '' ;
24+ } ;
3825
39- />
40- </ li >
41- )
42- } )
43- }
44- </ ul >
45- ) ;
26+ return (
27+ < ul className = "color-list" >
28+ { SETTINGS . backgroundColor . map ( ( bgColor : string ) => (
29+ < li
30+ key = { bgColor }
31+ className = "color-list__item"
32+ onClick = { ( ) => onSwitchBgColor ( bgColor ) }
33+ >
34+ < div
35+ style = { { background : bgColor } }
36+ className = { `bg-color ${ getBgColorClass ( bgColor ) } ` }
37+ />
38+ </ li >
39+ ) ) }
40+ </ ul >
41+ ) ;
4642}
0 commit comments