@mailstep/design-system 0.11.0 → 0.11.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mailstep/design-system",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "main": "./ui/index.js",
@@ -0,0 +1,2 @@
1
+ export declare const IMAGE_MIME_PREFIX = "image/";
2
+ export declare const INVALID_FORMAT_MESSAGE = "Unsupported file format";
@@ -0,0 +1,5 @@
1
+ //#region packages/ui/Blocks/ImageList/components/AddPhoto/constants.ts
2
+ const IMAGE_MIME_PREFIX = "image/";
3
+ const INVALID_FORMAT_MESSAGE = "Unsupported file format";
4
+ //#endregion
5
+ export { IMAGE_MIME_PREFIX, INVALID_FORMAT_MESSAGE };
@@ -0,0 +1,11 @@
1
+ import { type ChangeEvent } from 'react';
2
+ import { type ImageUploadProps } from '../../../types';
3
+ type Props = {
4
+ onImageUpload?: (props: ImageUploadProps) => Promise<void>;
5
+ };
6
+ type HookType = (props: Props) => {
7
+ handleImageUpload: (event: ChangeEvent<HTMLInputElement>) => void;
8
+ hasInvalidFormat: boolean;
9
+ };
10
+ export declare const useImageUpload: HookType;
11
+ export {};
@@ -0,0 +1,34 @@
1
+ import "../constants.js";
2
+ import { useCallback, useState } from "react";
3
+ //#region packages/ui/Blocks/ImageList/components/AddPhoto/hooks/useImageUpload.ts
4
+ const useImageUpload = ({ onImageUpload }) => {
5
+ const [hasInvalidFormat, setHasInvalidFormat] = useState(false);
6
+ return {
7
+ handleImageUpload: useCallback((event) => {
8
+ const input = event.target;
9
+ const file = input?.files?.[0];
10
+ if (!file) {
11
+ setHasInvalidFormat(false);
12
+ return;
13
+ }
14
+ if (!file.type.startsWith("image/")) {
15
+ input.value = "";
16
+ setHasInvalidFormat(true);
17
+ return;
18
+ }
19
+ setHasInvalidFormat(false);
20
+ const reader = new FileReader();
21
+ reader.readAsDataURL(file);
22
+ reader.onload = async () => {
23
+ await onImageUpload?.({
24
+ base64image: reader.result?.split(",").pop(),
25
+ base64WithDataDeclaration: reader.result,
26
+ file
27
+ });
28
+ };
29
+ }, [onImageUpload]),
30
+ hasInvalidFormat
31
+ };
32
+ };
33
+ //#endregion
34
+ export { useImageUpload };
@@ -1,9 +1,9 @@
1
1
  import { type FC } from 'react';
2
2
  import { type ImageUploadProps } from '../../types';
3
- interface AddPhotoProps {
3
+ type AddPhotoProps = {
4
4
  onImageUpload?: (props: ImageUploadProps) => Promise<void>;
5
5
  isDisabled?: boolean;
6
6
  hasRemove?: boolean;
7
- }
7
+ };
8
8
  export declare const AddPhoto: FC<AddPhotoProps>;
9
9
  export {};
@@ -1,29 +1,15 @@
1
1
  import { AddPhoto as AddPhoto$1 } from "../../../../Elements/Icon/icons/AddPhoto.js";
2
- import { Container, HiddenInput } from "./styles.js";
3
- import { useCallback } from "react";
2
+ import ErrorMessage from "../../../../Elements/ErrorMessage/ErrorMessage.js";
3
+ import "../../../../Elements/ErrorMessage/index.js";
4
+ import "./constants.js";
5
+ import { useImageUpload } from "./hooks/useImageUpload.js";
6
+ import { Container, ErrorWrapper, HiddenInput, Wrapper } from "./styles.js";
4
7
  import { jsx, jsxs } from "react/jsx-runtime";
5
8
  //#region packages/ui/Blocks/ImageList/components/AddPhoto/index.tsx
6
- const IMAGE_MIME_PREFIX = "image/";
7
9
  const AddPhoto = ({ onImageUpload, isDisabled, hasRemove }) => {
8
- const handleImageUpload = useCallback((event) => {
9
- const input = event.target;
10
- const file = input?.files?.[0];
11
- if (!file?.type.startsWith(IMAGE_MIME_PREFIX)) {
12
- input.value = "";
13
- return;
14
- }
15
- const reader = new FileReader();
16
- reader.readAsDataURL(file);
17
- reader.onload = async () => {
18
- await onImageUpload?.({
19
- base64image: reader.result?.split(",").pop(),
20
- base64WithDataDeclaration: reader.result,
21
- file
22
- });
23
- };
24
- }, [onImageUpload]);
10
+ const { handleImageUpload, hasInvalidFormat } = useImageUpload({ onImageUpload });
25
11
  if (!onImageUpload) return null;
26
- return /* @__PURE__ */ jsxs(Container, {
12
+ return /* @__PURE__ */ jsxs(Wrapper, { children: [/* @__PURE__ */ jsxs(Container, {
27
13
  isDisabled,
28
14
  hasRemove,
29
15
  children: [/* @__PURE__ */ jsx(HiddenInput, {
@@ -36,7 +22,13 @@ const AddPhoto = ({ onImageUpload, isDisabled, hasRemove }) => {
36
22
  width: "36",
37
23
  height: "36"
38
24
  })]
39
- });
25
+ }), hasInvalidFormat && /* @__PURE__ */ jsx(ErrorWrapper, {
26
+ hasRemove,
27
+ children: /* @__PURE__ */ jsx(ErrorMessage, {
28
+ appearance: "inline",
29
+ children: "Unsupported file format"
30
+ })
31
+ })] });
40
32
  };
41
33
  //#endregion
42
34
  export { AddPhoto };
@@ -3,3 +3,7 @@ export declare const Container: import("styled-components").StyledComponent<"div
3
3
  hasRemove?: boolean;
4
4
  }, never>;
5
5
  export declare const HiddenInput: import("styled-components").StyledComponent<"input", import("@xstyled/styled-components").Theme, {}, never>;
6
+ export declare const Wrapper: import("styled-components").StyledComponent<"div", import("@xstyled/styled-components").Theme, {}, never>;
7
+ export declare const ErrorWrapper: import("styled-components").StyledComponent<"div", import("@xstyled/styled-components").Theme, {
8
+ hasRemove?: boolean;
9
+ }, never>;
@@ -26,5 +26,17 @@ const HiddenInput = styled$1.input`
26
26
  height: 100%;
27
27
  cursor: pointer;
28
28
  `;
29
+ const Wrapper = styled$1.div`
30
+ position: relative;
31
+ flex-shrink: 0;
32
+ `;
33
+ const ErrorWrapper = styled$1.div`
34
+ position: absolute;
35
+ top: ${({ hasRemove }) => hasRemove ? "100px" : "85px"};
36
+ left: 0;
37
+ width: 85px;
38
+ line-height: 1.2;
39
+ text-align: center;
40
+ `;
29
41
  //#endregion
30
- export { Container, HiddenInput };
42
+ export { Container, ErrorWrapper, HiddenInput, Wrapper };