forked from cgross/avataaars-customizer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
110 lines (106 loc) · 3.89 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React from 'react'
import Avatar, { Piece } from '@schoolhouse/avatars'
import map from 'lodash/map'
import styles from './styles.css'
import options from './options'
export default function AvatarsCustomizer(props) {
const [selectedTab, setSelectedTab] = React.useState('top')
function pieceClicked(attr, val) {
var newAttributes = {
...props.value,
[attr]: val,
}
if (props.onChange) {
props.onChange(newAttributes)
}
}
return (
<div className={styles.container}>
<div className={styles.avatar}>
<Avatar style={{ width: '200px', height: '200px' }} avatarStyle="Circle" {...props.value} />
</div>
<div className={styles.tabs}>
{map(options, option => {
return (
<div
key={option.type}
className={styles.tab + ' ' + (selectedTab == option.type ? styles.selectedTab : '')}
onClick={() => setSelectedTab(option.type)}
>
{option.label}
</div>
)
})}
</div>
<div className={styles.tabpanes}>
{map(options, option => {
return (
<div
key={option.type}
className={styles.tabpane + ' ' + (selectedTab == option.type ? styles.visible : '')}
>
{map(option.values, val => {
var attr = {}
attr[option.attribute] = val
if (option.transform) {
attr.style = { transform: option.transform }
}
if (option.type === 'clothe' && attr[option.colorAttribute] == null) {
attr[option.colorAttribute] = 'Black'
}
return (
<div
key={val}
className={styles.piece}
onClick={() => pieceClicked(option.attribute, val)}
>
<Piece pieceSize="50" pieceType={option.type} {...attr} />
{(val === 'Blank' || val === 'NoHair') && (
<div className={styles.none}>(none)</div>
)}
</div>
)
})}
<div className={styles.colorContainer}>
{option.colors &&
(option.type !== 'top' || option.hats.indexOf(props.value.topType) === -1) &&
props.value.topType !== 'Eyepatch' &&
props.value.topType !== 'LongHairShavedSides' &&
props.value.topType !== 'LongHairFrida' &&
map(option.colors, (color, colorName) => {
return (
<div
key={colorName}
className={styles.color}
style={{
backgroundColor: color,
border: color === '#FFFFFF' ? '1px solid #ccc' : '1px solid ' + color,
}}
onClick={() => pieceClicked(option.colorAttribute, colorName)}
/>
)
})}
{option.hatColors &&
option.hats.indexOf(props.value.topType) !== -1 &&
props.value.topType !== 'Hat' &&
map(option.hatColors, (color, colorName) => {
return (
<div
key={colorName}
className={styles.color}
style={{
backgroundColor: color,
border: color === '#FFFFFF' ? '1px solid #ccc' : '1px solid ' + color,
}}
onClick={() => pieceClicked('hatColor', colorName)}
/>
)
})}
</div>
</div>
)
})}
</div>
</div>
)
}