@js-empire/emperor-ui 1.1.0 → 1.2.0
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/.storybook/vitest.setup.ts +3 -3
- package/.vscode/extensions.json +1 -3
- package/README.md +0 -21
- package/dist/emperor-ui.js +71 -0
- package/dist/emperor-ui.umd.cjs +49 -0
- package/dist/features-animation-D_Ss-HYx.js +1938 -0
- package/dist/globals.css +1 -0
- package/dist/icons/emperor-ui-logo.ico +0 -0
- package/dist/images/avatar-female.jpg +0 -0
- package/dist/images/avatar-male.jpg +0 -0
- package/dist/images/emperor-ui-logo.png +0 -0
- package/dist/index-C3mfrNCk.js +1630 -0
- package/dist/index-CZpTSGZs.js +5 -0
- package/dist/index-SRvFgjzo.js +26257 -0
- package/dist/index.d.ts +706 -0
- package/dist/src-UW24ZMRV-Ducut0ty.js +5 -0
- package/eslint.config.js +5 -14
- package/package.json +4 -4
- package/src/components/atoms/brand/brand.stories.tsx +3 -3
- package/src/components/atoms/brand/brand.tsx +3 -3
- package/src/components/atoms/column/column.stories.tsx +5 -4
- package/src/components/atoms/column/column.tsx +2 -2
- package/src/components/atoms/container/column.stories.tsx +5 -4
- package/src/components/atoms/container/container.tsx +2 -2
- package/src/components/atoms/portal/portal.stories.tsx +4 -4
- package/src/components/atoms/portal/portal.tsx +4 -2
- package/src/components/atoms/row/row.stories.tsx +5 -4
- package/src/components/atoms/row/row.tsx +2 -2
- package/src/components/atoms/uploader/avatar-label.tsx +2 -2
- package/src/components/atoms/uploader/stories/uploader.stories.tsx +127 -8
- package/src/components/atoms/uploader/upload-file-error-box.tsx +1 -1
- package/src/components/atoms/uploader/upload-file-input.tsx +2 -2
- package/src/components/atoms/uploader/upload-file-label.tsx +1 -1
- package/src/components/atoms/uploader/upload-file-listing.tsx +6 -4
- package/src/components/atoms/uploader/uploader.tsx +4 -4
- package/src/components/atoms/uploader/view-image-modal.tsx +6 -5
- package/src/components/molecules/filter/filter.tsx +2 -2
- package/src/components/molecules/item-card/item-card.tsx +2 -2
- package/src/components/molecules/nav-bar/nav-bar-item.tsx +3 -3
- package/src/components/molecules/nav-bar/nav-bar.tsx +4 -4
- package/src/components/molecules/nav-bar/stories/hover-effect/nav-bar-hover-effect.stories.tsx +4 -4
- package/src/components/molecules/nav-bar/stories/nav-bar.stories.tsx +4 -4
- package/src/components/molecules/nav-bar/styles/styles.ts +2 -1
- package/src/components/molecules/nav-bar/sub-items-box.tsx +2 -2
- package/src/components/molecules/scaffold/scaffold.stories.tsx +3 -3
- package/src/components/molecules/scaffold/scaffold.tsx +4 -4
- package/src/components/molecules/side-bar/compact-side-bar.tsx +5 -3
- package/src/components/molecules/side-bar/side-bar-drawer.tsx +3 -3
- package/src/components/molecules/side-bar/side-bar.stories.tsx +9 -8
- package/src/components/molecules/side-bar/side-bar.tsx +2 -2
- package/src/components/molecules/side-bar/styles/styles.ts +1 -1
- package/src/components/organisms/footer/copy-rights-box.tsx +27 -0
- package/src/components/organisms/footer/footer.tsx +69 -14
- package/src/components/organisms/footer/index.ts +4 -0
- package/src/components/organisms/footer/policies-box.tsx +26 -0
- package/src/components/organisms/footer/quick-links-box.tsx +45 -0
- package/src/components/organisms/footer/social-links-box.tsx +32 -0
- package/src/components/organisms/footer/stories/footer.stories.tsx +61 -0
- package/src/components/organisms/footer/styles/classes.ts +58 -2
- package/src/components/organisms/footer/styles/styles.ts +2 -5
- package/src/components/organisms/header/header.tsx +5 -5
- package/src/components/organisms/header/segmented-header-content.tsx +3 -3
- package/src/components/organisms/header/stories/header.stories.tsx +8 -7
- package/src/components/organisms/header/styles/styles.ts +1 -1
- package/src/components/organisms/index.ts +1 -1
- package/src/components/organisms/item-details/item-details.tsx +2 -2
- package/src/components/organisms/listings/listings.tsx +2 -2
- package/src/components/templates/landing-page/landing-page.stories.tsx +3 -3
- package/src/components/templates/landing-page/landing-page.tsx +5 -5
- package/src/constants/defaults.ts +1 -1
- package/src/constants/fake.ts +3 -0
- package/src/constants/footer.tsx +157 -0
- package/src/constants/index.ts +1 -0
- package/src/context/emperor-ui-context.ts +1 -1
- package/src/context/navigation-context.ts +1 -1
- package/src/context/uploader-context.ts +1 -1
- package/src/hooks/use-emperor-ui.ts +1 -1
- package/src/hooks/use-navigation.ts +1 -1
- package/src/hooks/use-uploader-context.ts +1 -1
- package/src/hooks/use-uploader.tsx +42 -106
- package/src/main.tsx +1 -1
- package/src/mocks/header.tsx +1 -1
- package/src/providers/config-provider.tsx +4 -4
- package/src/providers/emperor-ui-provider.tsx +2 -2
- package/src/providers/navigation-provider.tsx +3 -3
- package/src/providers/uploader-provider.tsx +2 -2
- package/src/types/components/atoms/brand.ts +1 -1
- package/src/types/components/atoms/column.ts +1 -1
- package/src/types/components/atoms/container.ts +1 -1
- package/src/types/components/atoms/portal.ts +1 -1
- package/src/types/components/atoms/row.ts +1 -1
- package/src/types/components/atoms/uploader.ts +4 -11
- package/src/types/components/molecules/filter/filter.ts +1 -1
- package/src/types/components/molecules/footer/footer.ts +60 -1
- package/src/types/components/molecules/header/header.ts +1 -1
- package/src/types/components/molecules/item-card/item-card.ts +1 -1
- package/src/types/components/molecules/item-details/item-details.ts +1 -1
- package/src/types/components/molecules/listings/listings.ts +1 -1
- package/src/types/components/molecules/nav-bar/nav-bar.ts +2 -1
- package/src/types/components/molecules/scaffold/scaffold.ts +1 -1
- package/src/types/components/molecules/side-bar/side-bar.ts +1 -1
- package/src/types/components/templates/landing-page.ts +1 -1
- package/src/types/context/navigation.ts +1 -1
- package/src/utils/compress-images.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/storybook.tsx +3 -3
- package/src/utils/uploader.ts +148 -0
- package/tsconfig.app.json +1 -10
- package/vite.config.ts +1 -10
- package/vitest.shims.d.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ButtonProps } from "@heroui/react";
|
|
2
|
-
import type { NavigationItem, SharedComponentProps } from "
|
|
2
|
+
import type { NavigationItem, SharedComponentProps } from "@/types";
|
|
3
3
|
import type { ReactNode } from "react";
|
|
4
4
|
|
|
5
5
|
export type SideBarVariant = "default" | "compact";
|
package/src/utils/index.ts
CHANGED
package/src/utils/storybook.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EmperorUIProvider } from "
|
|
2
|
-
import { defaultEmperorUIConfig } from "
|
|
3
|
-
import { EmperorUIConfig } from "
|
|
1
|
+
import { EmperorUIProvider } from "@/providers";
|
|
2
|
+
import { defaultEmperorUIConfig } from "@/constants";
|
|
3
|
+
import { EmperorUIConfig } from "@/types";
|
|
4
4
|
|
|
5
5
|
export const getStorybookDecorators = ({
|
|
6
6
|
config = defaultEmperorUIConfig,
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ALLOWED_DOC_TYPES,
|
|
3
|
+
ALLOWED_IMAGES_TYPES,
|
|
4
|
+
ALLOWED_PDF_TYPES,
|
|
5
|
+
ONE_MEGABYTE,
|
|
6
|
+
} from "@/constants";
|
|
7
|
+
import { FileObject, FileType } from "@/types";
|
|
8
|
+
import { addToast } from "@heroui/react";
|
|
9
|
+
import { compressImage } from "@/utils";
|
|
10
|
+
import { Dispatch, SetStateAction } from "react";
|
|
11
|
+
|
|
12
|
+
// get the corresponding FileType giving the extension of the uploaded file
|
|
13
|
+
export const mapFileType = (fileType: string): FileType | null => {
|
|
14
|
+
if (ALLOWED_IMAGES_TYPES.includes(fileType)) return "image";
|
|
15
|
+
if (ALLOWED_PDF_TYPES.includes(fileType)) return "pdf";
|
|
16
|
+
if (ALLOWED_DOC_TYPES.includes(fileType)) return "doc";
|
|
17
|
+
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// get the allowed file types according to the specified types from the 'fileTypes' array
|
|
22
|
+
export const getAllowedTypes = (fileTypes: FileType[]): string[] => {
|
|
23
|
+
const allowedTypes: string[] = [];
|
|
24
|
+
|
|
25
|
+
fileTypes.forEach((fileType) => {
|
|
26
|
+
if (fileType === "image") allowedTypes.push(...ALLOWED_IMAGES_TYPES);
|
|
27
|
+
if (fileType === "doc") allowedTypes.push(...ALLOWED_DOC_TYPES);
|
|
28
|
+
if (fileType === "pdf") allowedTypes.push(...ALLOWED_PDF_TYPES);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return allowedTypes;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const isFileDuplicated = ({
|
|
35
|
+
files,
|
|
36
|
+
fileName,
|
|
37
|
+
}: {
|
|
38
|
+
files: FileObject[];
|
|
39
|
+
fileName: string;
|
|
40
|
+
}): boolean => files?.filter(({ file }) => file?.name === fileName)?.length > 0;
|
|
41
|
+
|
|
42
|
+
// check if the file size exceeds the maxFileSize
|
|
43
|
+
export const isMaxFileSizeExceeded = ({
|
|
44
|
+
fileSize,
|
|
45
|
+
maxFileSize,
|
|
46
|
+
}: {
|
|
47
|
+
fileSize: number;
|
|
48
|
+
maxFileSize: number;
|
|
49
|
+
}): boolean => fileSize > maxFileSize * 1024;
|
|
50
|
+
|
|
51
|
+
export async function validateUploadedFiles({
|
|
52
|
+
uploadedFiles,
|
|
53
|
+
maxFileSize = ONE_MEGABYTE * 10,
|
|
54
|
+
compressFiles,
|
|
55
|
+
locale,
|
|
56
|
+
preventDuplicates,
|
|
57
|
+
files,
|
|
58
|
+
}: {
|
|
59
|
+
uploadedFiles: File[];
|
|
60
|
+
maxFileSize?: number;
|
|
61
|
+
compressFiles?: boolean;
|
|
62
|
+
locale?: Record<string, string> | undefined;
|
|
63
|
+
preventDuplicates?: boolean;
|
|
64
|
+
files: FileObject[];
|
|
65
|
+
}) {
|
|
66
|
+
let isInValid = false;
|
|
67
|
+
|
|
68
|
+
const compressedFiles = await Promise.all(
|
|
69
|
+
uploadedFiles?.map(async (file) => {
|
|
70
|
+
if (isMaxFileSizeExceeded({ fileSize: file?.size, maxFileSize })) {
|
|
71
|
+
addToast({
|
|
72
|
+
title: locale?.maxSizeExceededError
|
|
73
|
+
.replace("MAX_FILE_SIZE", (maxFileSize / 1024 || 0)?.toString())
|
|
74
|
+
.replace(
|
|
75
|
+
"UPLOADED_FILE_SIZE",
|
|
76
|
+
(file?.size / 1024 / 1024 || 0)?.toFixed(1)?.toString(),
|
|
77
|
+
),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (compressFiles) {
|
|
81
|
+
return (await compressImage({ file }))?.file;
|
|
82
|
+
} else {
|
|
83
|
+
isInValid = true;
|
|
84
|
+
return file;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (
|
|
89
|
+
preventDuplicates &&
|
|
90
|
+
isFileDuplicated({ fileName: file?.name, files })
|
|
91
|
+
) {
|
|
92
|
+
addToast({
|
|
93
|
+
title: locale?.duplicatesDenied,
|
|
94
|
+
});
|
|
95
|
+
isInValid = true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return file;
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
compressedFiles,
|
|
104
|
+
isInValid,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function refineUploadedFiles({
|
|
109
|
+
uploadedFiles,
|
|
110
|
+
locale,
|
|
111
|
+
allowedTypes,
|
|
112
|
+
isMulti,
|
|
113
|
+
setFiles,
|
|
114
|
+
}: {
|
|
115
|
+
uploadedFiles: (File | undefined)[];
|
|
116
|
+
locale?: Record<string, string> | undefined;
|
|
117
|
+
allowedTypes: string[];
|
|
118
|
+
isMulti: boolean;
|
|
119
|
+
setFiles: Dispatch<SetStateAction<FileObject[]>>;
|
|
120
|
+
}) {
|
|
121
|
+
return uploadedFiles?.map((uploadedFile) => {
|
|
122
|
+
if (uploadedFile) {
|
|
123
|
+
// validate the file extension according to the allowed extensions
|
|
124
|
+
const fileType = mapFileType(uploadedFile?.type);
|
|
125
|
+
if (!fileType) {
|
|
126
|
+
addToast({
|
|
127
|
+
title: `${locale?.errorUploadedTypes} ${allowedTypes.join(", ")}`,
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// set the file to be utilized, and the image to be viewed
|
|
133
|
+
const reader = new FileReader();
|
|
134
|
+
reader.onload = () => {
|
|
135
|
+
setFiles((prevFiles) => [
|
|
136
|
+
...(isMulti ? prevFiles : []),
|
|
137
|
+
{
|
|
138
|
+
file: uploadedFile,
|
|
139
|
+
view: reader.result as string,
|
|
140
|
+
type: fileType,
|
|
141
|
+
url: URL.createObjectURL(uploadedFile),
|
|
142
|
+
},
|
|
143
|
+
]);
|
|
144
|
+
};
|
|
145
|
+
reader.readAsDataURL(uploadedFile);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
package/tsconfig.app.json
CHANGED
|
@@ -25,16 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
"baseUrl": ".",
|
|
27
27
|
"paths": {
|
|
28
|
-
"
|
|
29
|
-
"@components": ["./src/components"],
|
|
30
|
-
"@constants": ["./src/constants"],
|
|
31
|
-
"@hooks": ["./src/hooks"],
|
|
32
|
-
"@context": ["./src/context"],
|
|
33
|
-
"@examples": ["./src/examples"],
|
|
34
|
-
"@providers": ["./src/providers"],
|
|
35
|
-
"@types": ["./src/types"],
|
|
36
|
-
"@mocks": ["./src/mocks"],
|
|
37
|
-
"@enums": ["./src/enums"]
|
|
28
|
+
"@/*": ["./src/*"]
|
|
38
29
|
}
|
|
39
30
|
},
|
|
40
31
|
"include": [
|
package/vite.config.ts
CHANGED
|
@@ -20,16 +20,7 @@ export default defineConfig({
|
|
|
20
20
|
],
|
|
21
21
|
resolve: {
|
|
22
22
|
alias: {
|
|
23
|
-
"@
|
|
24
|
-
"@components": path.resolve(__dirname, "./src/components"),
|
|
25
|
-
"@types": path.resolve(__dirname, "./src/types"),
|
|
26
|
-
"@providers": path.resolve(__dirname, "./src/providers"),
|
|
27
|
-
"@constants": path.resolve(__dirname, "./src/constants"),
|
|
28
|
-
"@hooks": path.resolve(__dirname, "./src/hooks"),
|
|
29
|
-
"@context": path.resolve(__dirname, "./src/context"),
|
|
30
|
-
"@examples": path.resolve(__dirname, "./src/examples"),
|
|
31
|
-
"@mocks": path.resolve(__dirname, "./src/mocks"),
|
|
32
|
-
"@enums": path.resolve(__dirname, "./src/enums"),
|
|
23
|
+
"@": path.resolve(__dirname, "./src"),
|
|
33
24
|
},
|
|
34
25
|
},
|
|
35
26
|
build: {
|
package/vitest.shims.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
/// <reference types="@vitest/browser-playwright" />
|
|
1
|
+
/// <reference types="@vitest/browser-playwright" />
|