@sikka/hawa 0.0.34 → 0.0.37

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.
Files changed (69) hide show
  1. package/README.md +11 -0
  2. package/es/index.es.js +1 -1
  3. package/lib/index.js +1 -1
  4. package/package.json +12 -9
  5. package/src/elements/AdaptiveButton.js +1 -1
  6. package/src/elements/DragDropImages.js +135 -143
  7. package/src/elements/DraggableCard.js +36 -0
  8. package/src/elements/HawaSelectInput.js +30 -0
  9. package/src/elements/HawaSnackbar.js +32 -3
  10. package/src/elements/index.js +2 -0
  11. package/src/index.js +1 -0
  12. package/src/layout/HawaAppLayout.js +197 -173
  13. package/src/layout/HawaAppLayout2.js +260 -0
  14. package/src/theme/HawaTheme.js +882 -0
  15. package/src/theme/index.js +2 -0
  16. package/storybook-static/0.a2c13f8ca8477800b11f.manager.bundle.js +2 -0
  17. package/storybook-static/{0.0d994c92.iframe.bundle.js.LICENSE.txt → 0.a2c13f8ca8477800b11f.manager.bundle.js.LICENSE.txt} +0 -0
  18. package/storybook-static/0.d94b248f.iframe.bundle.js +3 -0
  19. package/storybook-static/{4.0fcda1281dc1961dbe94.manager.bundle.js.LICENSE.txt → 0.d94b248f.iframe.bundle.js.LICENSE.txt} +0 -0
  20. package/storybook-static/0.d94b248f.iframe.bundle.js.map +1 -0
  21. package/storybook-static/1.37f89487.iframe.bundle.js +1 -0
  22. package/storybook-static/1.d522251f2377f7751924.manager.bundle.js +1 -0
  23. package/storybook-static/{2.430bf1e3.iframe.bundle.js → 2.89943a03.iframe.bundle.js} +1 -1
  24. package/storybook-static/5.a331b0a36ded1c541923.manager.bundle.js +2 -0
  25. package/storybook-static/5.a331b0a36ded1c541923.manager.bundle.js.LICENSE.txt +31 -0
  26. package/storybook-static/6.3a1fb0c3.iframe.bundle.js +3 -0
  27. package/storybook-static/6.3a1fb0c3.iframe.bundle.js.LICENSE.txt +31 -0
  28. package/storybook-static/6.3a1fb0c3.iframe.bundle.js.map +1 -0
  29. package/storybook-static/6.aee6c4935c69d480fc0d.manager.bundle.js +1 -0
  30. package/storybook-static/7.5b8a4de4b5fa42d8de02.manager.bundle.js +1 -0
  31. package/storybook-static/7.f33530b1.iframe.bundle.js +1 -0
  32. package/storybook-static/8.a3dec9c37e8951a17939.manager.bundle.js +2 -0
  33. package/storybook-static/{6.a6d45262f7e98f3f18d3.manager.bundle.js.LICENSE.txt → 8.a3dec9c37e8951a17939.manager.bundle.js.LICENSE.txt} +0 -0
  34. package/storybook-static/8.b569e86b.iframe.bundle.js +1 -0
  35. package/storybook-static/{8.76c3cbf398692028e834.manager.bundle.js → 9.d04fdaada645cd23cb4b.manager.bundle.js} +1 -1
  36. package/storybook-static/9.f9db5c90.iframe.bundle.js +3 -0
  37. package/storybook-static/{7.9ce807e3.iframe.bundle.js.LICENSE.txt → 9.f9db5c90.iframe.bundle.js.LICENSE.txt} +0 -0
  38. package/storybook-static/9.f9db5c90.iframe.bundle.js.map +1 -0
  39. package/storybook-static/iframe.html +19 -3
  40. package/storybook-static/index.html +2 -2
  41. package/storybook-static/main.1a0e1257.iframe.bundle.js +1 -0
  42. package/storybook-static/main.750dea0e0e515fd26844.manager.bundle.js +1 -0
  43. package/storybook-static/project.json +1 -0
  44. package/storybook-static/runtime~main.1bd817501fb34a0cb56b.manager.bundle.js +1 -0
  45. package/storybook-static/runtime~main.9be73be4.iframe.bundle.js +1 -0
  46. package/storybook-static/vendors~main.826e89a1.iframe.bundle.js +76 -0
  47. package/storybook-static/{vendors~main.a7262b49.iframe.bundle.js.LICENSE.txt → vendors~main.826e89a1.iframe.bundle.js.LICENSE.txt} +15 -0
  48. package/storybook-static/vendors~main.826e89a1.iframe.bundle.js.map +1 -0
  49. package/storybook-static/vendors~main.ed8bc18573e141ab3b26.manager.bundle.js +2 -0
  50. package/storybook-static/{vendors~main.a697e07137d366f95f76.manager.bundle.js.LICENSE.txt → vendors~main.ed8bc18573e141ab3b26.manager.bundle.js.LICENSE.txt} +18 -18
  51. package/storybook-static/0.0d994c92.iframe.bundle.js +0 -3
  52. package/storybook-static/0.0d994c92.iframe.bundle.js.map +0 -1
  53. package/storybook-static/0.f47eb24a4893a96ec307.manager.bundle.js +0 -1
  54. package/storybook-static/1.aabc3f3a.iframe.bundle.js +0 -1
  55. package/storybook-static/4.0fcda1281dc1961dbe94.manager.bundle.js +0 -2
  56. package/storybook-static/5.63ab4f94d50a3acf080d.manager.bundle.js +0 -1
  57. package/storybook-static/6.13a534cb.iframe.bundle.js +0 -1
  58. package/storybook-static/6.a6d45262f7e98f3f18d3.manager.bundle.js +0 -2
  59. package/storybook-static/7.097710753af9a1c41b80.manager.bundle.js +0 -1
  60. package/storybook-static/7.9ce807e3.iframe.bundle.js +0 -3
  61. package/storybook-static/7.9ce807e3.iframe.bundle.js.map +0 -1
  62. package/storybook-static/8.1bf48ea7.iframe.bundle.js +0 -1
  63. package/storybook-static/main.9d5968bcf15d21f5487c.manager.bundle.js +0 -1
  64. package/storybook-static/main.e9b7f5c4.iframe.bundle.js +0 -1
  65. package/storybook-static/runtime~main.708d7ac1.iframe.bundle.js +0 -1
  66. package/storybook-static/runtime~main.c8dac23bc753439736f0.manager.bundle.js +0 -1
  67. package/storybook-static/vendors~main.a697e07137d366f95f76.manager.bundle.js +0 -2
  68. package/storybook-static/vendors~main.a7262b49.iframe.bundle.js +0 -76
  69. package/storybook-static/vendors~main.a7262b49.iframe.bundle.js.map +0 -1
@@ -1,11 +1,11 @@
1
1
  import React, { useEffect, useState } from "react";
2
2
  // import axios from "axios";
3
- import { getToken } from "../token";
4
3
  import { useDropzone } from "react-dropzone";
5
- import useTranslation from "next-translate/useTranslation";
6
- import Badge from "@mui/material/Badge";
7
4
  import CloseIcon from "@mui/icons-material/Close";
8
- import styles from "../styles/Theme.module.css";
5
+ // import styled from "@emotion/styled";
6
+ import { Button, Container, IconButton, Typography } from "@mui/material";
7
+ import { useTheme } from "@mui/system";
8
+ import { HawaAlert } from "./HawaAlert";
9
9
 
10
10
  const thumbsContainer = {
11
11
  display: "flex",
@@ -14,23 +14,37 @@ const thumbsContainer = {
14
14
  marginTop: 10
15
15
  };
16
16
 
17
- const DragDropItemImage = ({
17
+ export const DragDropImages = ({
18
+ texts,
18
19
  files,
19
20
  setFiles,
20
- itemId,
21
21
  setDeletedFiles,
22
- refetchSingleMenu
23
- }) => {
24
- const token = getToken();
25
- const [cmp, setCmp] = useState(0);
26
- //const [thumbs, setThumbs] = useState("");
27
- const { t } = useTranslation("common");
28
- const { getRootProps, getInputProps, fileRejections, acceptedFiles } =
29
- useDropzone({
30
- multiple: token.Pack?.image_per_item_limit > 1,
31
- accept: "image/*",
32
- maxSize: 5000000,
33
- maxFiles: token.Pack?.image_per_item_limit,
22
+ maxFiles,
23
+ accept,
24
+ onAcceptedFiles,
25
+ showPreview,
26
+ onDeleteFile,
27
+ onClearFiles,
28
+ maxSize,
29
+ errorMessages
30
+ }) =>
31
+ // props
32
+ {
33
+ const [cmp, setCmp] = useState(0);
34
+ const [max, setMax] = useState(0);
35
+ //const [thumbs, setThumbs] = useState("");
36
+ const theme = useTheme();
37
+ const {
38
+ getRootProps,
39
+ getInputProps,
40
+ fileRejections,
41
+ acceptedFiles,
42
+ isDragActive
43
+ } = useDropzone({
44
+ multiple: true,
45
+ accept: accept,
46
+ maxSize: maxSize,
47
+ maxFiles: maxFiles,
34
48
  onDrop: (acceptedFiles) => {
35
49
  setFiles(
36
50
  acceptedFiles.map((file, index) =>
@@ -41,140 +55,118 @@ const DragDropItemImage = ({
41
55
  );
42
56
  }
43
57
  });
44
- const handleRemoveFile = async (file) => {
45
- console.log("fezafezaf", acceptedFiles[file]);
46
- if (acceptedFiles[file]?.isFromDB) {
47
- setDeletedFiles((old) => [
48
- ...old,
49
- {
50
- img_url: acceptedFiles[file]?.img_url,
51
- _id: acceptedFiles[file]?._id
52
- }
53
- ]);
54
- try {
55
- // await axios.post(
56
- // `${process.env.NEXT_PUBLIC_QAWAIM_API_URL}/deleteImages`,
57
- // {
58
- // deletedFiles: [
59
- // {
60
- // img_url: acceptedFiles[file]?.img_url,
61
- // _id: acceptedFiles[file]?._id
62
- // }
63
- // ],
64
- // itemId: itemId
65
- // }
66
- // );
67
- refetchSingleMenu();
68
- acceptedFiles.splice(file, 1);
69
- setFiles(acceptedFiles);
70
- } catch (err) {
71
- console.error(err);
72
- }
73
- console.log("accepted files after delete : ", acceptedFiles);
74
- setCmp((old) => old + 1);
75
- return;
76
- }
77
- // if (file.hasOwnProperty("_id")) {
78
- // console.log("Yes");
79
- // return;
80
- // }
81
- acceptedFiles.splice(file, 1);
82
-
83
- setFiles(
84
- acceptedFiles.map((f) =>
85
- Object.assign(f, { preview: URL.createObjectURL(f) })
86
- )
58
+ useEffect(
59
+ () => () => {
60
+ files?.forEach((file) => {
61
+ URL.revokeObjectURL(file.preview);
62
+ });
63
+ },
64
+ [files]
87
65
  );
88
- // setFiles(acceptedFiles);
89
- };
90
- useEffect(
91
- () => () => {
92
- files.forEach((file) => {
93
- URL.revokeObjectURL(file.preview);
94
- });
95
- },
96
66
 
97
- [files]
98
- );
99
- useEffect(() => {
100
- if (files[0]?.hasOwnProperty("_id")) {
101
- files?.map((file, index) => {
102
- acceptedFiles.push({
103
- preview: `https://qawaim-images.s3-ap-southeast-1.amazonaws.com/${file.image_url}`,
104
- isFromDB: true,
105
- _id: file._id,
106
- img_url: file.image_url
107
- });
108
- });
109
- console.log("accepted files : ", acceptedFiles);
67
+ useEffect(() => {
110
68
  setFiles(acceptedFiles);
111
- }
112
- return () => {
113
- acceptedFiles.splice(0, acceptedFiles?.length);
69
+ }, [acceptedFiles, cmp]);
70
+
71
+ onClearFiles = () => {
72
+ acceptedFiles.length = 0;
73
+ acceptedFiles.splice(0, acceptedFiles.length);
74
+ setFiles([]);
114
75
  };
115
- }, []);
116
- const errs = fileRejections.map((rej, i) => {
117
- return (
118
- <div key={i} className={styles.upload_error_container}>
119
- <div>{rej.file.name}</div>
120
- <div>{t(rej.errors[0].code)}</div>
76
+
77
+ useEffect(() => {
78
+ if (maxSize > 0) {
79
+ const k = 1024;
80
+ const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
81
+ const i = Math.floor(Math.log(maxSize) / Math.log(1024));
82
+
83
+ setMax(
84
+ parseFloat((maxSize / Math.pow(1024, i)).toFixed(2)) + " " + sizes[i]
85
+ );
86
+ }
87
+ }, [maxSize]);
88
+ const errs = fileRejections.map((rej, i) => {
89
+ return (
90
+ <div key={i}>
91
+ <div>{rej.file.name}</div>
92
+ <div>{rej.errors[0].code}</div>
93
+ </div>
94
+ );
95
+ });
96
+ const thumbs = files?.map((file, index) => (
97
+ <div style={{ position: "relative", margin: 10 }}>
98
+ <IconButton
99
+ onClick={(e) => {
100
+ e.stopPropagation();
101
+ acceptedFiles.splice(acceptedFiles.indexOf(file), 1);
102
+ setCmp(Math.random);
103
+ onDeleteFile(file);
104
+ }}
105
+ size="small"
106
+ variant="contained"
107
+ style={{
108
+ position: "absolute",
109
+ top: -10,
110
+ right: -10,
111
+ backgroundColor: theme.primaryActionColor,
112
+ color: "white",
113
+ padding: 3
114
+ }}
115
+ >
116
+ <CloseIcon fontSize="small" />
117
+ </IconButton>
118
+ <div
119
+ style={{
120
+ display: "flex",
121
+ justifyContent: "center",
122
+ alignItems: "center",
123
+ overflow: "hidden",
124
+ height: 100,
125
+ width: 100,
126
+ backgroundImage: `url(${file.preview})`,
127
+ backgroundSize: "cover",
128
+ backgroundPosition: "center",
129
+ border: "1px solid black"
130
+ }}
131
+ key={file.name}
132
+ />
121
133
  </div>
122
- );
123
- });
134
+ ));
124
135
 
125
- const thumbs = files.map((file, index) => (
126
- <Badge
127
- key={index}
128
- onClick={(e) => {
129
- e.preventDefault();
130
- e.stopPropagation();
131
- console.log("Clicking", index);
132
- handleRemoveFile(index);
133
- }}
134
- badgeContent={<CloseIcon fontSize="small" />}
135
- color="primary"
136
- style={{
137
- margin: 10,
138
- width: 100,
139
- height: 100
140
- }}
141
- >
142
- <div
143
- style={{
144
- display: "flex",
145
- justifyContent: "center",
146
- alignItems: "center",
147
- overflow: "hidden",
148
- height: 100,
149
- width: 100,
150
- backgroundImage: `url(${file.preview})`,
151
- backgroundSize: "cover",
152
- backgroundPosition: "center"
153
- }}
154
- key={file.name}
155
- />
156
- </Badge>
157
- ));
136
+ console.log("error", fileRejections);
158
137
 
159
- return (
160
- <section className={styles.upload_main_container}>
161
- <div
138
+ return (
139
+ <Container
140
+ variant="drop-area"
162
141
  {...getRootProps({
163
- onClick: (e) => {
164
- console.log("e : ", e);
165
- e.preventDefault(), console.log("khobza");
166
- },
167
- style: { height: "100%", width: "100%", padding: 10 }
142
+ style: { backgroundColor: isDragActive && "white" }
168
143
  })}
169
144
  >
170
145
  <input {...getInputProps()} />
171
- <div style={{ fontSize: 13 }}>{t("drag-n-drop")}</div>
172
- <div style={{ fontSize: 13, marginTop: 5 }}>{t("max-file-size")}</div>
173
- {thumbs ? <aside style={thumbsContainer}>{thumbs}</aside> : null}
174
- {errs}
175
- </div>
176
- </section>
177
- );
178
- };
146
+ <Typography>Click here or drop files here to upload</Typography>
147
+ <Typography>Max file size is {max}</Typography>
148
+ {acceptedFiles.length > 0 && (
149
+ <Button
150
+ style={{ color: "black" }}
151
+ onClick={(e) => {
152
+ e.stopPropagation();
153
+ onClearFiles(acceptedFiles);
154
+ }}
155
+ >
156
+ Clear All
157
+ </Button>
158
+ )}
179
159
 
180
- export default DragDropItemImage;
160
+ {thumbs && showPreview ? <aside style={thumbsContainer}>{thumbs}</aside> : null}
161
+ {fileRejections[0]?.errors[0]?.code === "too-many-files" ? (
162
+ // <Typography variant="">{texts.tooManyFiles}</Typography>
163
+ <HawaAlert text={texts.tooManyFiles} severity="error" />
164
+ ) : fileRejections[0]?.errors[0]?.code === "file-too-large" ? (
165
+ <HawaAlert text={texts.fileTooLarge} severity="error" />
166
+ ) : (
167
+ errs
168
+ )}
169
+ {}
170
+ </Container>
171
+ );
172
+ };
@@ -0,0 +1,36 @@
1
+ import { MoreVert } from "@mui/icons-material";
2
+ import { Container, Stack } from "@mui/material";
3
+ import React from "react";
4
+
5
+ export const DraggableCard = (props) => {
6
+ return (
7
+ <Stack
8
+ variant="card"
9
+ direction="row"
10
+ maxWidth={props.maxWidth}
11
+ style={{ paddingLeft: 5 }}
12
+ >
13
+ <div
14
+ style={{
15
+ // backgroundColor: "blue",
16
+ display: "flex",
17
+ alignItems: "center",
18
+ // paddingRight: 5,
19
+ borderRight: "1px solid grey",
20
+ marginRight: 20
21
+ }}
22
+ >
23
+ <MoreVert />
24
+ </div>
25
+
26
+ <div
27
+ style={{
28
+ // backgroundColor: "red",
29
+ width: "100%"
30
+ }}
31
+ >
32
+ {props.children}
33
+ </div>
34
+ </Stack>
35
+ );
36
+ };
@@ -0,0 +1,30 @@
1
+ import Select from "react-select";
2
+ import Creatable from "react-select/creatable";
3
+
4
+ export default function HawaSelectInput(props) {
5
+ return (
6
+ <>
7
+ {!props.isCreatable && (
8
+ <Select
9
+ options={props.options}
10
+ isClearable={props.isClearable}
11
+ isMulti={props.isMulti}
12
+ isSearchable={props.isSearchable}
13
+ onChange={(newValue, action) => props.onChange(newValue, action)}
14
+ />
15
+ )}
16
+ {props.isCreatable && (
17
+ <Creatable
18
+ options={props.options}
19
+ isClearable={props.isClearable}
20
+ isMulti={props.isMulti}
21
+ isSearchable={props.isSearchable}
22
+ onChange={(newValue, action) => props.onChange(newValue, action)}
23
+ onInputChange={(newValue, action) =>
24
+ props.onInputChange(newValue, action)
25
+ }
26
+ />
27
+ )}
28
+ </>
29
+ );
30
+ }
@@ -1,12 +1,41 @@
1
- import React from "react";
1
+ import React, { useEffect, useState } from "react";
2
2
  import Snackbar from "@mui/material/Snackbar";
3
3
  import AlertTitle from "@mui/material/AlertTitle";
4
4
  import Alert from "@mui/material/Alert";
5
+ import { IconButton } from "@mui/material";
6
+ import CloseIcon from "@mui/icons-material/Close";
5
7
 
6
8
  export const HawaSnackbar = (props) => {
9
+
10
+ const [position, setPosition] = useState({vertical : "", horizontal : ""});
11
+
12
+ useEffect(() => {
13
+ if(props.position){
14
+ const p = props.position.split("-");
15
+ setPosition({vertical : p[0], horizontal : p[1]});
16
+ }
17
+ }, [props.position])
18
+
7
19
  return (
8
- <Snackbar open={props.open} onClose={props.handleClose}>
9
- <Alert icon={false} severity={props.severity}>
20
+ <Snackbar
21
+ open={props.open}
22
+ autoHideDuration={props.duration ? props.duration : null}
23
+ onClose={props.handleClose}
24
+ anchorOrigin={position}
25
+ action={
26
+ <>
27
+ <IconButton
28
+ aria-label="close"
29
+ style={{color: "black"}}
30
+ sx={{ p: 0.5 }}
31
+ onClick={props.handleClose}
32
+ >
33
+ <CloseIcon />
34
+ </IconButton>
35
+ </>
36
+ }
37
+ >
38
+ <Alert icon={false} severity={props.severity} onClose={props.isClosable ? props.handleClose : null}>
10
39
  {props.title && <AlertTitle>{props.title}</AlertTitle>}
11
40
  {props.text}
12
41
  </Alert>
@@ -19,3 +19,5 @@ export * from "./HawaTable";
19
19
  export * from "./HawaColorPicker";
20
20
  export * from "./HawaSearchBar";
21
21
  export * from "./HawaAccordian";
22
+ export * from "./DragDropImages";
23
+ export * from "./DraggableCard";
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./blocks";
2
2
  export * from "./elements";
3
3
  export * from "./layout";
4
+ export * from "./theme";