-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfield-image.tsx
97 lines (94 loc) · 2.37 KB
/
field-image.tsx
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
import React from 'react';
import { HiOutlineUser } from 'react-icons/hi';
import {
Box,
Label,
Input,
FieldProps,
Text,
Image,
Flex,
ForwardRef,
InputProps,
ThemeUIStyleObject,
} from 'theme-ui';
import { getMargin, getPos, omitMargin, omitPos } from '../util';
export interface UserProps {
photoUrl: string;
firstName: string;
lastName: string;
roles: string[];
}
// TODO correctly type this interface and implement it to type props
export interface FieldImageProps {
as: ForwardRef<any, InputProps>;
label: string;
name: string;
error: any;
sx: ThemeUIStyleObject;
userData: Partial<UserProps>;
children: any;
}
export const FieldImage = React.forwardRef(
(
{ as: Control = Input, label, name, error, sx, userData, ...props }: FieldProps<any>,
ref
) => {
return (
<Flex
{...getMargin(props)}
sx={{
p: 3,
mt: 3,
mb: 3,
borderRadius: '8px',
border: '3px solid',
borderColor: 'primary',
backgroundColor: 'background',
...getPos(sx),
}}
>
<Flex
sx={{
width: '48px',
height: '48px',
alignItems: 'center',
justifyContent: 'center',
border: '2px dashed',
borderRadius: '50%',
borderColor: 'accent',
mr: 4,
fontSize: '20px',
}}
>
{/* TODO: replace with Avatar component (shows user image or initials) */}
{userData ? (
<Image
src={
userData?.photoUrl ||
`https://eu.ui-avatars.com/api/?name=${userData?.firstName}+${userData?.lastName}&background=749F97&size=512`
}
variant="rounded"
sx={{ minWidth: 52, width: 52, height: 52 }}
/>
) : (
<HiOutlineUser />
)}
</Flex>
<Box sx={{ flexGrow: 1 }}>
<Label sx={{ fontWeight: 'bold', fontSize: 1 }} htmlFor={name}>
{label}
</Label>
<Control
ref={ref}
id={name}
name={name}
sx={{ border: 0, outline: 'none', p: 0, ...omitPos(sx) }}
{...omitMargin(props)}
/>
{!!error && <Text sx={{ color: 'lightRed' }}>{error}</Text>}
</Box>
</Flex>
);
}
);