-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathdocs.stories.tsx
127 lines (118 loc) Β· 3.04 KB
/
docs.stories.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { Box, Button, Center, Stack, Tag, Text } from '@chakra-ui/react';
import { Formiz, useForm } from '@formiz/core';
import { FiImage } from 'react-icons/fi';
import { FieldImageUpload } from '@/components/FieldImageUpload';
import { Icon } from '@/components/Icons';
export default {
title: 'Fields/FieldImageUpload',
};
export const Default = () => {
const form = useForm({
onValidSubmit(formValues) {
console.log(formValues);
},
});
return (
<Formiz connect={form} autoForm>
<Stack spacing={6}>
<FieldImageUpload
name="demo"
label="Profil picture"
helper="This is an helper"
required="Profil picture is required"
width="360px"
/>
<FieldImageUpload
name="demo-default-value"
label="Default value"
defaultValue="https://bit.ly/dan-abramov"
width="360px"
/>
<FieldImageUpload
name="demo-ratio"
label="Custom aspect ratio and size"
imageUploadProps={{ ratio: 1 }}
w="240px"
/>
<Box>
<Button type="submit">Submit</Button>
</Box>
</Stack>
</Formiz>
);
};
export const CustomPlaceholder = () => {
const form = useForm({
onValidSubmit(formValues) {
console.log(formValues);
},
});
const PlaceholderComponent = () => (
<Center bgColor="gray.50" overflow="hidden">
<Stack textAlign="center" spacing={2}>
<Icon
fontSize="48px"
textColor="gray.400"
icon={FiImage}
alignSelf="center"
/>
<Text textColor="gray.600" fontWeight="medium" fontSize="md">
Upload a photo
</Text>
</Stack>
</Center>
);
return (
<Formiz connect={form} autoForm>
<Stack spacing={6}>
<FieldImageUpload
name="demo"
label="Image with placeholder"
imageUploadProps={{ placeholder: <PlaceholderComponent /> }}
w="480px"
/>
<Box>
<Button type="submit">Submit</Button>
</Box>
</Stack>
</Formiz>
);
};
export const InvalidateFormWhileUploading = () => {
const form = useForm({
onValidSubmit(formValues) {
console.log(formValues);
},
});
return (
<Formiz connect={form} autoForm>
<Stack spacing={2}>
<FieldImageUpload
name="demo"
label="Invalidate during uploading"
w="360px"
imageUploadProps={{
onUploadStateChange: (isUploading) =>
isUploading && form.setErrors({ demo: 'Image is uploading' }),
}}
/>
<Box>
{form.isValid ? (
<Tag size="lg" colorScheme="green">
Valid
</Tag>
) : (
<Tag size="lg" colorScheme="red">
Invalid
</Tag>
)}
</Box>
<Box>
<Button type="submit" isDisabled={!form.isValid && form.isSubmitted}>
Submit
</Button>
</Box>
</Stack>
</Formiz>
);
};