@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.
Files changed (110) hide show
  1. package/.storybook/vitest.setup.ts +3 -3
  2. package/.vscode/extensions.json +1 -3
  3. package/README.md +0 -21
  4. package/dist/emperor-ui.js +71 -0
  5. package/dist/emperor-ui.umd.cjs +49 -0
  6. package/dist/features-animation-D_Ss-HYx.js +1938 -0
  7. package/dist/globals.css +1 -0
  8. package/dist/icons/emperor-ui-logo.ico +0 -0
  9. package/dist/images/avatar-female.jpg +0 -0
  10. package/dist/images/avatar-male.jpg +0 -0
  11. package/dist/images/emperor-ui-logo.png +0 -0
  12. package/dist/index-C3mfrNCk.js +1630 -0
  13. package/dist/index-CZpTSGZs.js +5 -0
  14. package/dist/index-SRvFgjzo.js +26257 -0
  15. package/dist/index.d.ts +706 -0
  16. package/dist/src-UW24ZMRV-Ducut0ty.js +5 -0
  17. package/eslint.config.js +5 -14
  18. package/package.json +4 -4
  19. package/src/components/atoms/brand/brand.stories.tsx +3 -3
  20. package/src/components/atoms/brand/brand.tsx +3 -3
  21. package/src/components/atoms/column/column.stories.tsx +5 -4
  22. package/src/components/atoms/column/column.tsx +2 -2
  23. package/src/components/atoms/container/column.stories.tsx +5 -4
  24. package/src/components/atoms/container/container.tsx +2 -2
  25. package/src/components/atoms/portal/portal.stories.tsx +4 -4
  26. package/src/components/atoms/portal/portal.tsx +4 -2
  27. package/src/components/atoms/row/row.stories.tsx +5 -4
  28. package/src/components/atoms/row/row.tsx +2 -2
  29. package/src/components/atoms/uploader/avatar-label.tsx +2 -2
  30. package/src/components/atoms/uploader/stories/uploader.stories.tsx +127 -8
  31. package/src/components/atoms/uploader/upload-file-error-box.tsx +1 -1
  32. package/src/components/atoms/uploader/upload-file-input.tsx +2 -2
  33. package/src/components/atoms/uploader/upload-file-label.tsx +1 -1
  34. package/src/components/atoms/uploader/upload-file-listing.tsx +6 -4
  35. package/src/components/atoms/uploader/uploader.tsx +4 -4
  36. package/src/components/atoms/uploader/view-image-modal.tsx +6 -5
  37. package/src/components/molecules/filter/filter.tsx +2 -2
  38. package/src/components/molecules/item-card/item-card.tsx +2 -2
  39. package/src/components/molecules/nav-bar/nav-bar-item.tsx +3 -3
  40. package/src/components/molecules/nav-bar/nav-bar.tsx +4 -4
  41. package/src/components/molecules/nav-bar/stories/hover-effect/nav-bar-hover-effect.stories.tsx +4 -4
  42. package/src/components/molecules/nav-bar/stories/nav-bar.stories.tsx +4 -4
  43. package/src/components/molecules/nav-bar/styles/styles.ts +2 -1
  44. package/src/components/molecules/nav-bar/sub-items-box.tsx +2 -2
  45. package/src/components/molecules/scaffold/scaffold.stories.tsx +3 -3
  46. package/src/components/molecules/scaffold/scaffold.tsx +4 -4
  47. package/src/components/molecules/side-bar/compact-side-bar.tsx +5 -3
  48. package/src/components/molecules/side-bar/side-bar-drawer.tsx +3 -3
  49. package/src/components/molecules/side-bar/side-bar.stories.tsx +9 -8
  50. package/src/components/molecules/side-bar/side-bar.tsx +2 -2
  51. package/src/components/molecules/side-bar/styles/styles.ts +1 -1
  52. package/src/components/organisms/footer/copy-rights-box.tsx +27 -0
  53. package/src/components/organisms/footer/footer.tsx +69 -14
  54. package/src/components/organisms/footer/index.ts +4 -0
  55. package/src/components/organisms/footer/policies-box.tsx +26 -0
  56. package/src/components/organisms/footer/quick-links-box.tsx +45 -0
  57. package/src/components/organisms/footer/social-links-box.tsx +32 -0
  58. package/src/components/organisms/footer/stories/footer.stories.tsx +61 -0
  59. package/src/components/organisms/footer/styles/classes.ts +58 -2
  60. package/src/components/organisms/footer/styles/styles.ts +2 -5
  61. package/src/components/organisms/header/header.tsx +5 -5
  62. package/src/components/organisms/header/segmented-header-content.tsx +3 -3
  63. package/src/components/organisms/header/stories/header.stories.tsx +8 -7
  64. package/src/components/organisms/header/styles/styles.ts +1 -1
  65. package/src/components/organisms/index.ts +1 -1
  66. package/src/components/organisms/item-details/item-details.tsx +2 -2
  67. package/src/components/organisms/listings/listings.tsx +2 -2
  68. package/src/components/templates/landing-page/landing-page.stories.tsx +3 -3
  69. package/src/components/templates/landing-page/landing-page.tsx +5 -5
  70. package/src/constants/defaults.ts +1 -1
  71. package/src/constants/fake.ts +3 -0
  72. package/src/constants/footer.tsx +157 -0
  73. package/src/constants/index.ts +1 -0
  74. package/src/context/emperor-ui-context.ts +1 -1
  75. package/src/context/navigation-context.ts +1 -1
  76. package/src/context/uploader-context.ts +1 -1
  77. package/src/hooks/use-emperor-ui.ts +1 -1
  78. package/src/hooks/use-navigation.ts +1 -1
  79. package/src/hooks/use-uploader-context.ts +1 -1
  80. package/src/hooks/use-uploader.tsx +42 -106
  81. package/src/main.tsx +1 -1
  82. package/src/mocks/header.tsx +1 -1
  83. package/src/providers/config-provider.tsx +4 -4
  84. package/src/providers/emperor-ui-provider.tsx +2 -2
  85. package/src/providers/navigation-provider.tsx +3 -3
  86. package/src/providers/uploader-provider.tsx +2 -2
  87. package/src/types/components/atoms/brand.ts +1 -1
  88. package/src/types/components/atoms/column.ts +1 -1
  89. package/src/types/components/atoms/container.ts +1 -1
  90. package/src/types/components/atoms/portal.ts +1 -1
  91. package/src/types/components/atoms/row.ts +1 -1
  92. package/src/types/components/atoms/uploader.ts +4 -11
  93. package/src/types/components/molecules/filter/filter.ts +1 -1
  94. package/src/types/components/molecules/footer/footer.ts +60 -1
  95. package/src/types/components/molecules/header/header.ts +1 -1
  96. package/src/types/components/molecules/item-card/item-card.ts +1 -1
  97. package/src/types/components/molecules/item-details/item-details.ts +1 -1
  98. package/src/types/components/molecules/listings/listings.ts +1 -1
  99. package/src/types/components/molecules/nav-bar/nav-bar.ts +2 -1
  100. package/src/types/components/molecules/scaffold/scaffold.ts +1 -1
  101. package/src/types/components/molecules/side-bar/side-bar.ts +1 -1
  102. package/src/types/components/templates/landing-page.ts +1 -1
  103. package/src/types/context/navigation.ts +1 -1
  104. package/src/utils/compress-images.ts +1 -1
  105. package/src/utils/index.ts +1 -0
  106. package/src/utils/storybook.tsx +3 -3
  107. package/src/utils/uploader.ts +148 -0
  108. package/tsconfig.app.json +1 -10
  109. package/vite.config.ts +1 -10
  110. package/vitest.shims.d.ts +1 -1
@@ -1,4 +1,4 @@
1
- import type { SharedComponentProps } from "@types";
1
+ import type { SharedComponentProps } from "@/types";
2
2
 
3
3
  export type ScaffoldClassnames = {
4
4
  base?: string;
@@ -1,5 +1,5 @@
1
1
  import { ButtonProps } from "@heroui/react";
2
- import type { NavigationItem, SharedComponentProps } from "@types";
2
+ import type { NavigationItem, SharedComponentProps } from "@/types";
3
3
  import type { ReactNode } from "react";
4
4
 
5
5
  export type SideBarVariant = "default" | "compact";
@@ -1,4 +1,4 @@
1
- import type { SharedComponentProps } from "@types";
1
+ import type { SharedComponentProps } from "@/types";
2
2
 
3
3
  export type LandingPageClassnames = {
4
4
  base?: string;
@@ -1,4 +1,4 @@
1
- import { NavigationItem } from "@types";
1
+ import { NavigationItem } from "@/types";
2
2
  import { ReactNode } from "react";
3
3
 
4
4
  export type NavigationContextState = {
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { FileObject } from "@types";
3
+ import { FileObject } from "@/types";
4
4
  /**
5
5
  * Compress an image to reduce its size
6
6
  *
@@ -1,3 +1,4 @@
1
1
  export * from "./cn";
2
2
  export * from "./storybook";
3
3
  export * from "./compress-images";
4
+ export * from "./uploader";
@@ -1,6 +1,6 @@
1
- import { EmperorUIProvider } from "@providers";
2
- import { defaultEmperorUIConfig } from "@constants";
3
- import { EmperorUIConfig } from "@types";
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
- "@utils": ["./src/utils"],
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
- "@utils": path.resolve(__dirname, "./src/utils"),
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" />