-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathCharacter.tsx
More file actions
81 lines (68 loc) · 1.49 KB
/
Character.tsx
File metadata and controls
81 lines (68 loc) · 1.49 KB
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
import React from 'react';
import styled from 'styled-components';
import svgBody from './body';
import svgFace from './face';
import svgHead from './head';
import { theme as t } from '../../css/theme';
export * from './Characters';
const StyledCharacter = styled.div`
position: relative;
width: 200px;
svg {
position: absolute;
transform: translateX(-50%);
overflow: visible;
.ink {
fill: ${t.color('primary.300')};
}
.background {
fill: ${t.color('white')};
}
}
:after {
content: '';
display: block;
padding-bottom: 130%;
}
`;
interface SvgProps {
value: string;
obj: any;
}
const Svg: React.FC<SvgProps> = ({ value, obj, ...props }) => {
const S = obj[value];
if (!S) throw new Error(`Could not find character part '${value}'`);
return <S {...props} width="auto" height="260" />;
};
const StyledBody = styled(Svg)`
width: 100%;
bottom: 0;
left: 50%;
`;
const StyledHead = styled(Svg)`
width: 50%;
left: 56%;
bottom: 50%;
`;
const StyledFace = styled(Svg)`
width: 34%;
left: 61%;
bottom: 48%;
`;
export interface CharacterProps {
body: keyof typeof svgBody;
head: keyof typeof svgHead;
face?: keyof typeof svgFace;
}
export const Character: React.FC<CharacterProps> = ({
body,
head,
face,
...props
}) => (
<StyledCharacter {...props}>
<StyledBody value={body} obj={svgBody} />
<StyledHead value={head} obj={svgHead} />
{face && <StyledFace value={face} obj={svgFace} />}
</StyledCharacter>
);