@fangzsx/component-library 0.0.36 → 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.
@@ -0,0 +1,8 @@
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import { c as r } from "./createSvgIcon-C0YrvByi.js";
3
+ const c = r(/* @__PURE__ */ o("path", {
4
+ d: "M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
5
+ }), "Close");
6
+ export {
7
+ c as C
8
+ };
@@ -1,33 +1,31 @@
1
- import { jsx as t, jsxs as n } from "react/jsx-runtime";
2
- import { c as x } from "../../createSvgIcon-C0YrvByi.js";
1
+ import { jsx as i, jsxs as n } from "react/jsx-runtime";
2
+ import { C as x } from "../../Close-pjIlDyCW.js";
3
3
  import { Slide as d, Dialog as u, DialogTitle as g, IconButton as h, DialogContent as D, DialogActions as C } from "@mui/material";
4
- import { forwardRef as S } from "react";
5
- const j = x(/* @__PURE__ */ t("path", {
6
- d: "M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
7
- }), "Close"), y = S(function(i, e) {
8
- return /* @__PURE__ */ t(d, { direction: "up", ref: e, ...i });
4
+ import { forwardRef as j } from "react";
5
+ const y = j(function(t, o) {
6
+ return /* @__PURE__ */ i(d, { direction: "up", ref: o, ...t });
9
7
  });
10
- function v({
11
- open: o,
12
- onClose: i,
13
- title: e,
8
+ function w({
9
+ open: e,
10
+ onClose: t,
11
+ title: o,
14
12
  children: l,
15
13
  actions: r,
16
14
  maxWidth: s = "sm",
17
15
  fullWidth: a = !0,
18
16
  showCloseButton: p = !0,
19
- dividers: c = !0,
20
- fullScreen: m = !1,
17
+ dividers: m = !0,
18
+ fullScreen: c = !1,
21
19
  slideTransition: f = !1
22
20
  }) {
23
21
  return /* @__PURE__ */ n(
24
22
  u,
25
23
  {
26
- open: o,
27
- onClose: i,
24
+ open: e,
25
+ onClose: t,
28
26
  maxWidth: s,
29
27
  fullWidth: a,
30
- fullScreen: m,
28
+ fullScreen: c,
31
29
  scroll: "paper",
32
30
  slots: f ? { transition: y } : void 0,
33
31
  sx: {
@@ -49,23 +47,23 @@ function v({
49
47
  fontSize: "19px",
50
48
  pr: 1
51
49
  }, children: [
52
- e,
53
- p && /* @__PURE__ */ t(
50
+ o,
51
+ p && /* @__PURE__ */ i(
54
52
  h,
55
53
  {
56
- onClick: i,
54
+ onClick: t,
57
55
  size: "small",
58
56
  sx: { ml: 2 },
59
- children: /* @__PURE__ */ t(j, {})
57
+ children: /* @__PURE__ */ i(x, {})
60
58
  }
61
59
  )
62
60
  ] }),
63
- /* @__PURE__ */ t(D, { dividers: c, children: l }),
64
- r && /* @__PURE__ */ t(C, { sx: { px: 3, py: 2 }, children: r })
61
+ /* @__PURE__ */ i(D, { dividers: m, children: l }),
62
+ r && /* @__PURE__ */ i(C, { sx: { px: 3, py: 2 }, children: r })
65
63
  ]
66
64
  }
67
65
  );
68
66
  }
69
67
  export {
70
- v as ScrollableDialog
68
+ w as ScrollableDialog
71
69
  };
@@ -0,0 +1,15 @@
1
+ import { default as React } from 'react';
2
+
3
+ interface ImageUploadProps {
4
+ label?: string;
5
+ required?: boolean;
6
+ maxSizeMB?: number;
7
+ acceptedFormats?: string[];
8
+ error?: string;
9
+ forceError?: boolean;
10
+ helperText?: string;
11
+ disabled?: boolean;
12
+ onChange?: (file: File | null, error: string) => void;
13
+ }
14
+ declare const ImageUpload: React.FC<ImageUploadProps>;
15
+ export default ImageUpload;
@@ -0,0 +1,218 @@
1
+ import { jsx as e, jsxs as t } from "react/jsx-runtime";
2
+ import { C as H } from "../../Close-pjIlDyCW.js";
3
+ import { c as M } from "../../createSvgIcon-C0YrvByi.js";
4
+ import { FormControl as P, FormLabel as T, Box as i, Stack as U, Typography as l, IconButton as V, FormHelperText as E } from "@mui/material";
5
+ import { useState as g, useRef as q, useCallback as G } from "react";
6
+ const J = M(/* @__PURE__ */ e("path", {
7
+ d: "M19 5v14H5V5zm0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2m-4.86 8.86-3 3.87L9 13.14 6 17h12z"
8
+ }), "ImageOutlined"), K = (n) => {
9
+ const a = n.lastIndexOf(".");
10
+ return a <= 0 ? { baseName: n, extension: "" } : {
11
+ baseName: n.slice(0, a),
12
+ extension: n.slice(a)
13
+ };
14
+ }, rr = ({
15
+ label: n = "Logo",
16
+ required: a = !0,
17
+ maxSizeMB: d = 2,
18
+ acceptedFormats: s = ["png", "jpg", "jpeg"],
19
+ error: x = "",
20
+ forceError: y = !1,
21
+ helperText: b,
22
+ disabled: o = !1,
23
+ onChange: c
24
+ }) => {
25
+ const [v, h] = g(!1), [p, k] = g(null), [O, D] = g(""), m = q(null), w = d * 1024 * 1024, R = s.map((r) => `.${r}`).join(","), C = s.map(
26
+ (r) => `image/${r === "jpg" ? "jpeg" : r}`
27
+ ), j = G(
28
+ (r) => {
29
+ if (!r) return;
30
+ if (!C.some((f) => r.type === f)) {
31
+ c?.(null, `Only ${s.join(", ")} files are supported`);
32
+ return;
33
+ }
34
+ if (r.size > w) {
35
+ c?.(null, `File size must be less than ${d}MB`);
36
+ return;
37
+ }
38
+ const I = new FileReader();
39
+ I.onload = (f) => {
40
+ k(f.target?.result), D(r.name), c?.(r, "");
41
+ }, I.readAsDataURL(r);
42
+ },
43
+ [C, w, d, s, c]
44
+ ), S = (r) => {
45
+ r.preventDefault(), !o && (h(!1), j(r.dataTransfer.files?.[0] ?? null));
46
+ }, F = (r) => {
47
+ r.preventDefault(), o || h(!0);
48
+ }, L = () => h(!1), W = () => {
49
+ o || m.current?.click();
50
+ }, z = (r) => {
51
+ j(r.target.files?.[0] ?? null);
52
+ }, N = (r) => {
53
+ r.stopPropagation(), k(null), D(""), c?.(null, ""), m.current && (m.current.value = "");
54
+ }, u = !!x || y && !p, B = x || (y && !p ? `${n} can't be empty` : ""), { baseName: $, extension: A } = K(O);
55
+ return /* @__PURE__ */ t(P, { fullWidth: !0, error: u, disabled: o, children: [
56
+ n && /* @__PURE__ */ e(
57
+ T,
58
+ {
59
+ required: a,
60
+ sx: {
61
+ mb: 0.75,
62
+ fontSize: 14,
63
+ fontWeight: 500,
64
+ color: "text.primary",
65
+ "& .MuiFormLabel-asterisk": { color: "error.main" },
66
+ "&.Mui-focused": { color: "text.primary" },
67
+ "&.Mui-error": { color: "text.primary" }
68
+ },
69
+ children: n
70
+ }
71
+ ),
72
+ /* @__PURE__ */ t(
73
+ i,
74
+ {
75
+ onClick: W,
76
+ onDrop: S,
77
+ onDragOver: F,
78
+ onDragLeave: L,
79
+ sx: {
80
+ border: 2,
81
+ borderStyle: "dashed",
82
+ borderColor: u ? "error.main" : v ? "primary.main" : "grey.300",
83
+ borderRadius: 2,
84
+ p: p ? 1.5 : 4,
85
+ textAlign: "center",
86
+ cursor: o ? "default" : "pointer",
87
+ bgcolor: o ? "action.disabledBackground" : v ? "primary.50" : "grey.50",
88
+ transition: "all 0.2s ease",
89
+ opacity: o ? 0.6 : 1,
90
+ "&:hover": o ? {} : {
91
+ borderColor: u ? "error.main" : "primary.main",
92
+ bgcolor: "primary.50"
93
+ }
94
+ },
95
+ children: [
96
+ /* @__PURE__ */ e(
97
+ "input",
98
+ {
99
+ ref: m,
100
+ type: "file",
101
+ accept: R,
102
+ onChange: z,
103
+ hidden: !0,
104
+ disabled: o
105
+ }
106
+ ),
107
+ p ? /* @__PURE__ */ t(U, { direction: "row", alignItems: "center", spacing: 2, children: [
108
+ /* @__PURE__ */ e(
109
+ i,
110
+ {
111
+ component: "img",
112
+ src: p,
113
+ alt: "Preview",
114
+ sx: {
115
+ width: 80,
116
+ height: 80,
117
+ objectFit: "contain",
118
+ borderRadius: 1.5,
119
+ border: 1,
120
+ borderColor: "grey.200"
121
+ }
122
+ }
123
+ ),
124
+ /* @__PURE__ */ t(i, { sx: { flex: 1, minWidth: 0, textAlign: "left" }, children: [
125
+ /* @__PURE__ */ t(
126
+ l,
127
+ {
128
+ variant: "body2",
129
+ fontWeight: 500,
130
+ sx: {
131
+ display: "flex",
132
+ minWidth: 0
133
+ },
134
+ children: [
135
+ /* @__PURE__ */ e(
136
+ i,
137
+ {
138
+ component: "span",
139
+ sx: {
140
+ overflow: "hidden",
141
+ textOverflow: "ellipsis",
142
+ whiteSpace: "nowrap",
143
+ minWidth: 0
144
+ },
145
+ children: $
146
+ }
147
+ ),
148
+ /* @__PURE__ */ e(
149
+ i,
150
+ {
151
+ component: "span",
152
+ sx: {
153
+ flexShrink: 0
154
+ },
155
+ children: A
156
+ }
157
+ )
158
+ ]
159
+ }
160
+ ),
161
+ /* @__PURE__ */ e(l, { variant: "caption", color: "text.secondary", children: "Click to replace" })
162
+ ] }),
163
+ /* @__PURE__ */ e(
164
+ V,
165
+ {
166
+ onClick: N,
167
+ size: "small",
168
+ color: "error",
169
+ sx: {
170
+ border: 1,
171
+ borderColor: "grey.200",
172
+ borderRadius: 1.5,
173
+ "&:hover": { bgcolor: "error.50", borderColor: "error.200" }
174
+ },
175
+ children: /* @__PURE__ */ e(H, { fontSize: "small" })
176
+ }
177
+ )
178
+ ] }) : /* @__PURE__ */ t(i, { children: [
179
+ /* @__PURE__ */ e(
180
+ J,
181
+ {
182
+ sx: { fontSize: 40, color: "primary.main", mb: 1.5 }
183
+ }
184
+ ),
185
+ /* @__PURE__ */ t(l, { variant: "body2", color: "text.secondary", gutterBottom: !0, children: [
186
+ "Drop image here or",
187
+ " ",
188
+ /* @__PURE__ */ e(
189
+ l,
190
+ {
191
+ component: "span",
192
+ variant: "body2",
193
+ color: "primary",
194
+ fontWeight: 600,
195
+ sx: { textDecoration: "underline" },
196
+ children: "click to browse"
197
+ }
198
+ )
199
+ ] }),
200
+ /* @__PURE__ */ t(l, { variant: "caption", color: "text.disabled", display: "block", children: [
201
+ "File size should be less than ",
202
+ d,
203
+ "MB"
204
+ ] }),
205
+ /* @__PURE__ */ t(l, { variant: "caption", color: "text.disabled", display: "block", children: [
206
+ "Supports ",
207
+ s.join(", ")
208
+ ] })
209
+ ] })
210
+ ]
211
+ }
212
+ ),
213
+ (u || b) && /* @__PURE__ */ e(E, { sx: { mt: 0.75, mx: 0 }, children: B || b })
214
+ ] });
215
+ };
216
+ export {
217
+ rr as default
218
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@fangzsx/component-library",
3
3
  "author": "Jay Gilbert Garzon",
4
4
  "private": false,
5
- "version": "0.0.36",
5
+ "version": "0.0.37",
6
6
  "type": "module",
7
7
  "main": "dist/main.js",
8
8
  "types": "dist/main.d.ts",