@weareconceptstudio/form 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FormConfig.d.ts +5 -0
- package/dist/FormConfig.js +19 -0
- package/dist/checkbox/BaseCheckbox.d.ts +3 -0
- package/dist/checkbox/BaseCheckbox.js +51 -0
- package/dist/checkbox/index.d.ts +1 -1
- package/dist/checkbox/index.js +16 -5
- package/dist/color-picker/index.d.ts +5 -2
- package/dist/color-picker/index.js +4 -4
- package/dist/date-picker/index.d.ts +7 -2
- package/dist/date-picker/index.js +4 -4
- package/dist/error-message/index.d.ts +3 -0
- package/dist/error-message/index.js +9 -6
- package/dist/form/BaseForm.d.ts +22 -17
- package/dist/form/BaseForm.js +41 -55
- package/dist/form/Builder/index.d.ts +9 -0
- package/dist/form/Builder/index.js +46 -0
- package/dist/form/Builder/style.d.ts +2 -0
- package/dist/form/Builder/style.js +3 -0
- package/dist/form/Item/index.d.ts +12 -10
- package/dist/form/Item/index.js +26 -19
- package/dist/form/hooks/rules.d.ts +3 -0
- package/dist/form/hooks/rules.js +44 -0
- package/dist/form/hooks/useEvent.d.ts +1 -0
- package/dist/form/hooks/useEvent.js +12 -0
- package/dist/form/hooks/useFormInstance.js +4 -1
- package/dist/form/hooks/useInput.d.ts +12 -0
- package/dist/form/hooks/useInput.js +46 -0
- package/dist/form/index.d.ts +6 -16
- package/dist/form/index.js +3 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/input/BaseInput/index.d.ts +5 -3
- package/dist/input/BaseInput/index.js +28 -39
- package/dist/input/Input.d.ts +5 -2
- package/dist/input/Input.js +18 -16
- package/dist/input/Number/index.d.ts +5 -2
- package/dist/input/Number/index.js +27 -4
- package/dist/input/Password/icons.d.ts +1 -1
- package/dist/input/Password/icons.js +6 -6
- package/dist/input/Password/index.d.ts +5 -2
- package/dist/input/Password/index.js +8 -8
- package/dist/input/TextArea/index.d.ts +5 -2
- package/dist/input/TextArea/index.js +8 -9
- package/dist/input/index.d.ts +11 -2
- package/dist/input/index.js +6 -4
- package/dist/phone-number/index.d.ts +7 -0
- package/dist/phone-number/index.js +13 -0
- package/dist/radio/BaseRadio.d.ts +1 -1
- package/dist/radio/BaseRadio.js +20 -7
- package/dist/radio/Group.d.ts +1 -1
- package/dist/radio/Group.js +24 -4
- package/dist/radio/context.d.ts +1 -1
- package/dist/radio/context.js +3 -3
- package/dist/radio/index.js +2 -2
- package/dist/select/icons.d.ts +3 -0
- package/dist/select/icons.js +6 -0
- package/dist/select/index.d.ts +5 -2
- package/dist/select/index.js +57 -20
- package/dist/styles/formStyle.d.ts +2 -0
- package/dist/styles/formStyle.js +585 -0
- package/dist/styles/theme.d.ts +2 -0
- package/dist/styles/theme.js +113 -0
- package/dist/styles/variables.d.ts +2 -0
- package/dist/styles/variables.js +246 -0
- package/dist/translations/en.d.ts +52 -0
- package/dist/translations/en.js +52 -0
- package/dist/translations/index.d.ts +54 -0
- package/dist/translations/index.js +2 -0
- package/dist/upload/UploadButton/index.d.ts +3 -0
- package/dist/upload/UploadButton/index.js +41 -0
- package/dist/upload/UploadButton/style.d.ts +2 -0
- package/dist/upload/UploadButton/style.js +24 -0
- package/dist/upload/UploadList/ListItem/index.d.ts +5 -0
- package/dist/upload/UploadList/ListItem/index.js +11 -0
- package/dist/upload/UploadList/index.d.ts +3 -0
- package/dist/upload/UploadList/index.js +11 -0
- package/dist/upload/UploadList/style.d.ts +2 -0
- package/dist/upload/UploadList/style.js +13 -0
- package/dist/upload/index.d.ts +5 -2
- package/dist/upload/index.js +18 -5
- package/dist/upload/utils.d.ts +9 -0
- package/dist/upload/utils.js +64 -0
- package/package.json +31 -34
package/dist/upload/index.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import UploadButton from './UploadButton';
|
|
3
|
+
import UploadList from './UploadList';
|
|
4
|
+
const Upload = (props) => {
|
|
5
|
+
const { accept, disabled, multiple } = props;
|
|
6
|
+
const [fileList, setFileList] = useState([]);
|
|
7
|
+
const uploadProps = {
|
|
8
|
+
accept,
|
|
9
|
+
disabled,
|
|
10
|
+
multiple,
|
|
11
|
+
};
|
|
12
|
+
return (React.createElement("span", null,
|
|
13
|
+
React.createElement(UploadButton, { ...uploadProps, setFileList: setFileList }),
|
|
14
|
+
React.createElement(UploadList, { items: fileList })));
|
|
15
|
+
};
|
|
16
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
17
|
+
Upload.displayName = 'Upload';
|
|
18
|
+
}
|
|
6
19
|
export default Upload;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function typeFromMime(mime: any): "document" | "image" | "video" | "audio" | "pdf";
|
|
2
|
+
export function rawFileToAsset({ rawFile, isReplace }: {
|
|
3
|
+
rawFile: any;
|
|
4
|
+
isReplace?: boolean;
|
|
5
|
+
}): Promise<{
|
|
6
|
+
replace: boolean;
|
|
7
|
+
upload: boolean;
|
|
8
|
+
filename: any;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const typeFromMime = (mime) => {
|
|
2
|
+
if (mime.includes('image')) {
|
|
3
|
+
return 'image';
|
|
4
|
+
}
|
|
5
|
+
if (mime.includes('video')) {
|
|
6
|
+
return 'video';
|
|
7
|
+
}
|
|
8
|
+
if (mime.includes('audio')) {
|
|
9
|
+
return 'audio';
|
|
10
|
+
}
|
|
11
|
+
if (mime.includes('pdf')) {
|
|
12
|
+
return 'pdf';
|
|
13
|
+
}
|
|
14
|
+
return 'document';
|
|
15
|
+
};
|
|
16
|
+
export const rawFileToAsset = async ({ rawFile, isReplace = false }) => {
|
|
17
|
+
const fileName = rawFile.name.split('.').shift();
|
|
18
|
+
const aggregate_type = typeFromMime(rawFile.type);
|
|
19
|
+
let data = {};
|
|
20
|
+
let dimensions = '';
|
|
21
|
+
if (aggregate_type == 'image') {
|
|
22
|
+
dimensions = await imageDimensions(rawFile);
|
|
23
|
+
}
|
|
24
|
+
data = {
|
|
25
|
+
size: rawFile.size,
|
|
26
|
+
createdAt: new Date().toLocaleDateString('fr'),
|
|
27
|
+
aggregate_type: aggregate_type,
|
|
28
|
+
url: URL.createObjectURL(rawFile),
|
|
29
|
+
extension: rawFile.name.split('.').pop(),
|
|
30
|
+
mime_type: rawFile.type,
|
|
31
|
+
dimensions: dimensions,
|
|
32
|
+
alt: fileName,
|
|
33
|
+
caption: fileName,
|
|
34
|
+
rawFile,
|
|
35
|
+
replace: false,
|
|
36
|
+
upload: true,
|
|
37
|
+
};
|
|
38
|
+
if (isReplace) {
|
|
39
|
+
data.replace = true;
|
|
40
|
+
data.upload = false;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
data.filename = fileName;
|
|
44
|
+
data.replace = false;
|
|
45
|
+
data.upload = true;
|
|
46
|
+
}
|
|
47
|
+
return data;
|
|
48
|
+
};
|
|
49
|
+
const imageDimensions = (file) => new Promise((resolve, reject) => {
|
|
50
|
+
const img = new Image();
|
|
51
|
+
img.onload = () => {
|
|
52
|
+
const { naturalWidth: width, naturalHeight: height } = img;
|
|
53
|
+
resolve(`${width}x${height}`);
|
|
54
|
+
};
|
|
55
|
+
img.onerror = () => {
|
|
56
|
+
useNotification({
|
|
57
|
+
type: 'warning',
|
|
58
|
+
message: 'Error',
|
|
59
|
+
description: 'There was some problem with the image.',
|
|
60
|
+
});
|
|
61
|
+
reject('There was some problem with the image.');
|
|
62
|
+
};
|
|
63
|
+
img.src = URL.createObjectURL(file);
|
|
64
|
+
});
|
package/package.json
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
1
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
|
-
"typescript": "5.3.3"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
2
|
+
"name": "@weareconceptstudio/form",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "Concept Studio Form",
|
|
5
|
+
"author": "Concept Studio",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"clean": "rimraf ./dist",
|
|
19
|
+
"build": "npm run clean && tsc -m es6",
|
|
20
|
+
"watch": "tsc -m es6 --watch"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@weareconceptstudio/core": "*",
|
|
24
|
+
"react-hook-form": "^7.52.1",
|
|
25
|
+
"react-phone-number-input": "3.4.8",
|
|
26
|
+
"react-select": "5.8.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"rimraf": "6.0.1",
|
|
30
|
+
"typescript": "5.3.3"
|
|
31
|
+
}
|
|
32
|
+
}
|