@js-empire/emperor-ui 1.0.0 → 1.1.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/.husky/pre-commit +4 -0
- package/.storybook/main.ts +2 -11
- package/.storybook/preview.ts +1 -1
- package/.vscode/extensions.json +3 -0
- package/README.md +68 -1
- package/package.json +19 -4
- package/public/icons/emperor-ui-logo.ico +0 -0
- package/public/images/avatar-female.jpg +0 -0
- package/public/images/avatar-male.jpg +0 -0
- package/public/images/emperor-ui-logo.png +0 -0
- package/src/components/atoms/brand/brand.stories.tsx +27 -0
- package/src/components/atoms/brand/brand.tsx +56 -0
- package/src/components/atoms/brand/index.ts +1 -0
- package/src/components/atoms/brand/styles/classes.ts +9 -0
- package/src/components/atoms/brand/styles/index.ts +2 -0
- package/src/components/atoms/brand/styles/styles.ts +0 -0
- package/src/components/atoms/column/column.stories.tsx +36 -0
- package/src/components/atoms/column/column.tsx +21 -0
- package/src/components/atoms/column/index.ts +1 -0
- package/src/components/atoms/container/column.stories.tsx +36 -0
- package/src/components/atoms/container/container.tsx +28 -0
- package/src/components/atoms/container/index.ts +1 -0
- package/src/components/atoms/index.ts +6 -0
- package/src/components/atoms/portal/index.ts +1 -0
- package/src/components/atoms/portal/portal.stories.tsx +43 -0
- package/src/components/atoms/portal/portal.tsx +23 -0
- package/src/components/atoms/row/index.ts +1 -0
- package/src/components/atoms/row/row.stories.tsx +36 -0
- package/src/components/atoms/row/row.tsx +26 -0
- package/src/components/atoms/uploader/avatar-label.tsx +83 -0
- package/src/components/atoms/uploader/index.ts +7 -0
- package/src/components/atoms/uploader/stories/uploader.stories.tsx +41 -0
- package/src/components/atoms/uploader/upload-file-error-box.tsx +29 -0
- package/src/components/atoms/uploader/upload-file-input.tsx +36 -0
- package/src/components/atoms/uploader/upload-file-label.tsx +74 -0
- package/src/components/atoms/uploader/upload-file-listing.tsx +53 -0
- package/src/components/atoms/uploader/uploader.tsx +55 -0
- package/src/components/atoms/uploader/view-image-modal.tsx +39 -0
- package/src/components/index.ts +4 -8
- package/src/components/molecules/index.ts +5 -0
- package/src/components/molecules/item-card/item-card.tsx +6 -0
- package/src/components/molecules/nav-bar/index.ts +3 -0
- package/src/components/molecules/nav-bar/nav-bar-item.tsx +70 -0
- package/src/components/molecules/nav-bar/nav-bar.tsx +65 -0
- package/src/components/molecules/nav-bar/stories/hover-effect/nav-bar-hover-effect.stories.tsx +52 -0
- package/src/components/molecules/nav-bar/stories/nav-bar.stories.tsx +50 -0
- package/src/components/molecules/nav-bar/styles/classes.ts +68 -0
- package/src/components/molecules/nav-bar/styles/index.ts +2 -0
- package/src/components/molecules/nav-bar/styles/styles.ts +84 -0
- package/src/components/molecules/nav-bar/sub-items-box.tsx +57 -0
- package/src/components/molecules/scaffold/scaffold.stories.tsx +21 -0
- package/src/components/molecules/scaffold/scaffold.tsx +36 -0
- package/src/components/molecules/side-bar/compact-side-bar.tsx +73 -0
- package/src/components/molecules/side-bar/index.ts +1 -0
- package/src/components/molecules/side-bar/side-bar-drawer.tsx +124 -0
- package/src/components/molecules/side-bar/side-bar.stories.tsx +110 -0
- package/src/components/molecules/side-bar/side-bar.tsx +31 -0
- package/src/components/molecules/side-bar/styles/classes.ts +28 -0
- package/src/components/molecules/side-bar/styles/index.ts +2 -0
- package/src/components/molecules/side-bar/styles/styles.ts +13 -0
- package/src/components/organisms/footer/footer.tsx +20 -0
- package/src/components/organisms/footer/styles/classes.ts +15 -0
- package/src/components/organisms/footer/styles/index.ts +2 -0
- package/src/components/organisms/footer/styles/styles.ts +9 -0
- package/src/components/organisms/header/header.tsx +94 -0
- package/src/components/organisms/header/segmented-header-content.tsx +37 -0
- package/src/components/organisms/header/stories/header.stories.tsx +143 -0
- package/src/components/organisms/header/styles/classes.ts +22 -0
- package/src/components/organisms/header/styles/index.ts +2 -0
- package/src/components/organisms/header/styles/styles.ts +39 -0
- package/src/components/organisms/index.ts +4 -0
- package/src/components/templates/index.ts +1 -0
- package/src/components/templates/landing-page/index.ts +1 -0
- package/src/components/templates/landing-page/landing-page.stories.tsx +21 -0
- package/src/components/templates/landing-page/landing-page.tsx +57 -0
- package/src/components/templates/landing-page/styles/classes.ts +11 -0
- package/src/components/templates/landing-page/styles/index.ts +1 -0
- package/src/constants/defaults.ts +42 -7
- package/src/constants/fake.ts +2 -0
- package/src/constants/index.ts +2 -0
- package/src/constants/uploader.ts +27 -0
- package/src/context/emperor-ui-context.ts +4 -4
- package/src/context/index.ts +2 -0
- package/src/context/navigation-context.ts +6 -0
- package/src/context/uploader-context.ts +6 -0
- package/src/enums/index.ts +2 -0
- package/src/enums/placeholders.ts +4 -0
- package/src/enums/preserved-keys.ts +3 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/use-navigation.ts +12 -0
- package/src/hooks/use-uploader-context.ts +14 -0
- package/src/hooks/use-uploader.tsx +215 -0
- package/src/index.ts +9 -5
- package/src/main.tsx +3 -0
- package/src/mocks/header.tsx +118 -0
- package/src/mocks/index.ts +1 -0
- package/src/providers/config-provider.tsx +54 -0
- package/src/providers/emperor-ui-provider.tsx +17 -24
- package/src/providers/index.ts +3 -0
- package/src/providers/navigation-provider.tsx +42 -0
- package/src/providers/uploader-provider.tsx +53 -0
- package/src/styles/globals.css +13 -0
- package/src/styles/hero.ts +2 -0
- package/src/types/components/atoms/brand.ts +13 -0
- package/src/types/components/atoms/column.ts +3 -0
- package/src/types/components/atoms/container.ts +3 -0
- package/src/types/components/atoms/index.ts +6 -0
- package/src/types/components/atoms/portal.ts +6 -0
- package/src/types/components/atoms/row.ts +3 -0
- package/src/types/components/atoms/uploader.ts +104 -0
- package/src/types/components/index.ts +3 -8
- package/src/types/components/molecules/header/header.ts +51 -0
- package/src/types/components/molecules/index.ts +9 -0
- package/src/types/components/molecules/nav-bar/nav-bar.ts +65 -0
- package/src/types/components/molecules/side-bar/index.ts +1 -0
- package/src/types/components/molecules/side-bar/side-bar.ts +40 -0
- package/src/types/components/templates/index.ts +1 -0
- package/src/types/components/templates/landing-page.ts +10 -0
- package/src/types/context/config.ts +54 -0
- package/src/types/context/index.ts +2 -1
- package/src/types/context/navigation.ts +17 -0
- package/src/types/shared/components.ts +4 -0
- package/src/utils/compress-images.ts +36 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/storybook.tsx +15 -0
- package/tsconfig.app.json +3 -2
- package/tsconfig.node.json +0 -1
- package/vite.config.ts +5 -1
- package/dist/emperor-ui.js +0 -3171
- package/dist/emperor-ui.umd.cjs +0 -6
- package/dist/src/components/filter/filter.d.ts +0 -3
- package/dist/src/components/filter/index.d.ts +0 -1
- package/dist/src/components/footer/footer.d.ts +0 -3
- package/dist/src/components/footer/index.d.ts +0 -1
- package/dist/src/components/header/header.d.ts +0 -9
- package/dist/src/components/header/index.d.ts +0 -1
- package/dist/src/components/index.d.ts +0 -8
- package/dist/src/components/item-card/index.d.ts +0 -1
- package/dist/src/components/item-card/item-card.d.ts +0 -3
- package/dist/src/components/item-details/index.d.ts +0 -1
- package/dist/src/components/item-details/item-details.d.ts +0 -3
- package/dist/src/components/listings/index.d.ts +0 -1
- package/dist/src/components/listings/listings.d.ts +0 -3
- package/dist/src/components/nav-bar/index.d.ts +0 -1
- package/dist/src/components/nav-bar/nav-bar.d.ts +0 -3
- package/dist/src/components/scaffold/index.d.ts +0 -1
- package/dist/src/components/scaffold/scaffold.d.ts +0 -3
- package/dist/src/constants/defaults.d.ts +0 -4
- package/dist/src/constants/index.d.ts +0 -1
- package/dist/src/context/emperor-ui-context.d.ts +0 -3
- package/dist/src/context/index.d.ts +0 -1
- package/dist/src/examples/index.d.ts +0 -1
- package/dist/src/hooks/index.d.ts +0 -1
- package/dist/src/hooks/use-emperor-ui.d.ts +0 -1
- package/dist/src/index.d.ts +0 -8
- package/dist/src/providers/emperor-ui-provider.d.ts +0 -3
- package/dist/src/providers/index.d.ts +0 -1
- package/dist/src/types/components/filter/filter.d.ts +0 -8
- package/dist/src/types/components/filter/index.d.ts +0 -1
- package/dist/src/types/components/footer/footer.d.ts +0 -8
- package/dist/src/types/components/footer/index.d.ts +0 -1
- package/dist/src/types/components/header/header.d.ts +0 -19
- package/dist/src/types/components/header/index.d.ts +0 -1
- package/dist/src/types/components/index.d.ts +0 -8
- package/dist/src/types/components/item-card/index.d.ts +0 -1
- package/dist/src/types/components/item-card/item-card.d.ts +0 -8
- package/dist/src/types/components/item-details/index.d.ts +0 -1
- package/dist/src/types/components/item-details/item-details.d.ts +0 -8
- package/dist/src/types/components/listings/index.d.ts +0 -1
- package/dist/src/types/components/listings/listings.d.ts +0 -8
- package/dist/src/types/components/nav-bar/index.d.ts +0 -1
- package/dist/src/types/components/nav-bar/nav-bar.d.ts +0 -8
- package/dist/src/types/components/scaffold/index.d.ts +0 -1
- package/dist/src/types/components/scaffold/scaffold.d.ts +0 -8
- package/dist/src/types/context/emperor-ui.d.ts +0 -31
- package/dist/src/types/context/index.d.ts +0 -1
- package/dist/src/types/index.d.ts +0 -3
- package/dist/src/types/shared/components.d.ts +0 -6
- package/dist/src/types/shared/index.d.ts +0 -1
- package/dist/src/utils/cn.d.ts +0 -3
- package/dist/src/utils/index.d.ts +0 -1
- package/src/components/footer/footer.tsx +0 -6
- package/src/components/header/header.tsx +0 -49
- package/src/components/item-card/item-card.tsx +0 -6
- package/src/components/nav-bar/index.ts +0 -1
- package/src/components/nav-bar/nav-bar.tsx +0 -6
- package/src/components/scaffold/scaffold.tsx +0 -15
- package/src/index.css +0 -1
- package/src/types/components/header/header.ts +0 -21
- package/src/types/components/nav-bar/nav-bar.ts +0 -9
- package/src/types/context/emperor-ui.ts +0 -37
- package/tailwind.config.js +0 -6
- /package/src/components/{filter → molecules/filter}/filter.tsx +0 -0
- /package/src/components/{filter → molecules/filter}/index.ts +0 -0
- /package/src/components/{item-card → molecules/item-card}/index.ts +0 -0
- /package/src/components/{scaffold → molecules/scaffold}/index.ts +0 -0
- /package/src/components/{footer → organisms/footer}/index.ts +0 -0
- /package/src/components/{header → organisms/header}/index.ts +0 -0
- /package/src/components/{item-details → organisms/item-details}/index.ts +0 -0
- /package/src/components/{item-details → organisms/item-details}/item-details.tsx +0 -0
- /package/src/components/{listings → organisms/listings}/index.ts +0 -0
- /package/src/components/{listings → organisms/listings}/listings.tsx +0 -0
- /package/src/types/components/{filter → molecules/filter}/filter.ts +0 -0
- /package/src/types/components/{filter → molecules/filter}/index.ts +0 -0
- /package/src/types/components/{footer → molecules/footer}/footer.ts +0 -0
- /package/src/types/components/{footer → molecules/footer}/index.ts +0 -0
- /package/src/types/components/{header → molecules/header}/index.ts +0 -0
- /package/src/types/components/{item-card → molecules/item-card}/index.ts +0 -0
- /package/src/types/components/{item-card → molecules/item-card}/item-card.ts +0 -0
- /package/src/types/components/{item-details → molecules/item-details}/index.ts +0 -0
- /package/src/types/components/{item-details → molecules/item-details}/item-details.ts +0 -0
- /package/src/types/components/{listings → molecules/listings}/index.ts +0 -0
- /package/src/types/components/{listings → molecules/listings}/listings.ts +0 -0
- /package/src/types/components/{nav-bar → molecules/nav-bar}/index.ts +0 -0
- /package/src/types/components/{scaffold → molecules/scaffold}/index.ts +0 -0
- /package/src/types/components/{scaffold → molecules/scaffold}/scaffold.ts +0 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { addToast } from "@heroui/react";
|
|
4
|
+
import {
|
|
5
|
+
FileObject,
|
|
6
|
+
FileType,
|
|
7
|
+
UseUploadFileProps,
|
|
8
|
+
UseUploadFileReturn,
|
|
9
|
+
} from "@types";
|
|
10
|
+
import { useState } from "react";
|
|
11
|
+
import { useEmperorUI } from "@hooks";
|
|
12
|
+
import { compressImage } from "@utils";
|
|
13
|
+
import {
|
|
14
|
+
ALLOWED_IMAGES_TYPES,
|
|
15
|
+
ALLOWED_PDF_TYPES,
|
|
16
|
+
ALLOWED_DOC_TYPES,
|
|
17
|
+
ONE_MEGABYTE,
|
|
18
|
+
} from "@constants";
|
|
19
|
+
|
|
20
|
+
export const useUploader = ({
|
|
21
|
+
labelContent,
|
|
22
|
+
labelId,
|
|
23
|
+
fileTypes,
|
|
24
|
+
isRequired = true,
|
|
25
|
+
isDraggable = true,
|
|
26
|
+
isMulti = false,
|
|
27
|
+
preventDuplicates = true,
|
|
28
|
+
maxCount = 5,
|
|
29
|
+
maxFileSize = ONE_MEGABYTE * 10,
|
|
30
|
+
compressFiles = false,
|
|
31
|
+
onChange = () => {},
|
|
32
|
+
}: UseUploadFileProps): UseUploadFileReturn => {
|
|
33
|
+
const { config } = useEmperorUI();
|
|
34
|
+
const [files, setFiles] = useState<FileObject[]>([]);
|
|
35
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
36
|
+
|
|
37
|
+
const locales = config?.interLocalization?.locales;
|
|
38
|
+
const lang = config?.interLocalization?.lang;
|
|
39
|
+
|
|
40
|
+
const locale = locales?.[lang || "en"];
|
|
41
|
+
|
|
42
|
+
// remove all uploaded files
|
|
43
|
+
const handleClearFile = (fileName?: string) => {
|
|
44
|
+
setFiles((prev) => prev?.filter((file) => file?.file?.name !== fileName));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// get the corresponding FileType giving the extension of the uploaded file
|
|
48
|
+
const mapFileType = (fileType: string): FileType | null => {
|
|
49
|
+
if (ALLOWED_IMAGES_TYPES.includes(fileType)) return "image";
|
|
50
|
+
if (ALLOWED_PDF_TYPES.includes(fileType)) return "pdf";
|
|
51
|
+
if (ALLOWED_DOC_TYPES.includes(fileType)) return "doc";
|
|
52
|
+
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// get the allowed file types according to the specified types from the 'fileTypes' array
|
|
57
|
+
const getAllowedTypes = (): string[] => {
|
|
58
|
+
const allowedTypes: string[] = [];
|
|
59
|
+
|
|
60
|
+
fileTypes.forEach((fileType) => {
|
|
61
|
+
if (fileType === "image") allowedTypes.push(...ALLOWED_IMAGES_TYPES);
|
|
62
|
+
if (fileType === "doc") allowedTypes.push(...ALLOWED_DOC_TYPES);
|
|
63
|
+
if (fileType === "pdf") allowedTypes.push(...ALLOWED_PDF_TYPES);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return allowedTypes;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// check if the file size exceeds the maxFileSize
|
|
70
|
+
const isMaxFileSizeExceeded = (fileSize: number): boolean =>
|
|
71
|
+
fileSize > maxFileSize * 1024;
|
|
72
|
+
|
|
73
|
+
const isDuplicated = (name: string): boolean =>
|
|
74
|
+
files?.filter(({ file }) => file?.name === name)?.length > 0;
|
|
75
|
+
|
|
76
|
+
// handle the uploading process including the window upload and the drag-and-drop upload
|
|
77
|
+
const onInputChange = async (
|
|
78
|
+
event: React.ChangeEvent<HTMLInputElement> &
|
|
79
|
+
React.DragEvent<HTMLLabelElement>,
|
|
80
|
+
): Promise<void> => {
|
|
81
|
+
if (
|
|
82
|
+
(!event.target.files || !event.target.files?.[0]) &&
|
|
83
|
+
(!event?.dataTransfer?.files || !event?.dataTransfer?.files[0])
|
|
84
|
+
) {
|
|
85
|
+
addToast({
|
|
86
|
+
title: locale?.errorUploadingFile,
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// validate the file type according to the given allowed types
|
|
92
|
+
const allowedTypes = getAllowedTypes();
|
|
93
|
+
|
|
94
|
+
// verify if the files exist
|
|
95
|
+
if (!event.target.files && !event.dataTransfer.files) return;
|
|
96
|
+
|
|
97
|
+
// get the uploaded files
|
|
98
|
+
const uploadedFiles = Array.from(
|
|
99
|
+
event.target.files || event.dataTransfer.files,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// validate the files' length and prevent exceeded files only in the multiple-mode
|
|
103
|
+
if (
|
|
104
|
+
isMulti &&
|
|
105
|
+
(uploadedFiles?.length > maxCount ||
|
|
106
|
+
files?.length + uploadedFiles?.length > maxCount)
|
|
107
|
+
) {
|
|
108
|
+
addToast({
|
|
109
|
+
title: `${locale?.maxNumImages} ${maxCount}`,
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// validate the files' types according to the given allowed types
|
|
115
|
+
if (
|
|
116
|
+
!uploadedFiles
|
|
117
|
+
?.map((file) => file?.type)
|
|
118
|
+
?.every((type) => allowedTypes.includes(type))
|
|
119
|
+
) {
|
|
120
|
+
addToast({
|
|
121
|
+
title: `${locale?.errorUploadedTypes} ${allowedTypes.join(", ")}`,
|
|
122
|
+
});
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// validate the files' sizes if none of them exceeds the maximum allowed size
|
|
127
|
+
// validate files' names to ensure there are no duplicates if specified
|
|
128
|
+
let isInValid = false;
|
|
129
|
+
|
|
130
|
+
const compressedFiles = await Promise.all(
|
|
131
|
+
uploadedFiles?.map(async (file) => {
|
|
132
|
+
if (isMaxFileSizeExceeded(file?.size)) {
|
|
133
|
+
addToast({
|
|
134
|
+
title: locale?.maxSizeExceededError
|
|
135
|
+
.replace("MAX_FILE_SIZE", (maxFileSize / 1024 || 0)?.toString())
|
|
136
|
+
.replace(
|
|
137
|
+
"UPLOADED_FILE_SIZE",
|
|
138
|
+
(file?.size / 1024 / 1024 || 0)?.toFixed(1)?.toString(),
|
|
139
|
+
),
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
if (compressFiles) {
|
|
143
|
+
return (await compressImage({ file }))?.file;
|
|
144
|
+
} else {
|
|
145
|
+
isInValid = true;
|
|
146
|
+
return file;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (preventDuplicates && isDuplicated(file?.name)) {
|
|
151
|
+
addToast({
|
|
152
|
+
title: locale?.duplicatesDenied,
|
|
153
|
+
});
|
|
154
|
+
isInValid = true;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return file;
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
if (isInValid) return;
|
|
162
|
+
|
|
163
|
+
setIsLoading(true);
|
|
164
|
+
|
|
165
|
+
await Promise.all(
|
|
166
|
+
compressedFiles?.map((uploadedFile) => {
|
|
167
|
+
if (uploadedFile) {
|
|
168
|
+
// validate the file extension according to the allowed extensions
|
|
169
|
+
const fileType = mapFileType(uploadedFile?.type);
|
|
170
|
+
if (!fileType) {
|
|
171
|
+
addToast({
|
|
172
|
+
title: `${locale?.errorUploadedTypes} ${allowedTypes.join(", ")}`,
|
|
173
|
+
});
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// set the file to be utilized, and the image to be viewed
|
|
178
|
+
const reader = new FileReader();
|
|
179
|
+
reader.onload = () => {
|
|
180
|
+
setFiles((prevFiles) => [
|
|
181
|
+
...(isMulti ? prevFiles : []),
|
|
182
|
+
{
|
|
183
|
+
file: uploadedFile,
|
|
184
|
+
view: reader.result as string,
|
|
185
|
+
type: fileType,
|
|
186
|
+
url: URL.createObjectURL(uploadedFile),
|
|
187
|
+
},
|
|
188
|
+
]);
|
|
189
|
+
};
|
|
190
|
+
reader.readAsDataURL(uploadedFile);
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
).finally(() => {
|
|
194
|
+
setIsLoading(false);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
setTimeout(() => {
|
|
198
|
+
onChange();
|
|
199
|
+
}, 200);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
files,
|
|
204
|
+
fileTypes,
|
|
205
|
+
labelId,
|
|
206
|
+
isRequired,
|
|
207
|
+
labelContent,
|
|
208
|
+
isDraggable,
|
|
209
|
+
isMulti,
|
|
210
|
+
handleClearFile,
|
|
211
|
+
onInputChange,
|
|
212
|
+
setFiles,
|
|
213
|
+
isLoading,
|
|
214
|
+
};
|
|
215
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import "./styles/globals.css";
|
|
2
|
+
|
|
1
3
|
export * from "./components";
|
|
2
|
-
export type * from "./types";
|
|
3
|
-
export * from "./utils";
|
|
4
|
-
export * from "./providers";
|
|
5
|
-
export * from "./context";
|
|
6
|
-
export * from "./hooks";
|
|
7
4
|
export * from "./constants";
|
|
5
|
+
export * from "./context";
|
|
8
6
|
export * from "./examples";
|
|
7
|
+
export * from "./hooks";
|
|
8
|
+
export * from "./providers";
|
|
9
|
+
export type * from "./types";
|
|
10
|
+
export * from "./utils";
|
|
11
|
+
export * from "./mocks";
|
|
12
|
+
export * from "./enums";
|
package/src/main.tsx
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { SideBarAction, NavigationItem } from "@types";
|
|
2
|
+
import {
|
|
3
|
+
HelpCircleIcon,
|
|
4
|
+
HomeIcon,
|
|
5
|
+
InfoIcon,
|
|
6
|
+
LifeBuoyIcon,
|
|
7
|
+
LogOutIcon,
|
|
8
|
+
MailIcon,
|
|
9
|
+
ServerIcon,
|
|
10
|
+
SettingsIcon,
|
|
11
|
+
} from "lucide-react";
|
|
12
|
+
|
|
13
|
+
export const MOCK_HEADER_SUB_ITEMS: NavigationItem[] = [
|
|
14
|
+
{
|
|
15
|
+
id: "info",
|
|
16
|
+
label: "Info",
|
|
17
|
+
href: "#info",
|
|
18
|
+
Icon: InfoIcon,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "contact",
|
|
22
|
+
label: "Contact",
|
|
23
|
+
href: "#contact",
|
|
24
|
+
Icon: MailIcon,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "services",
|
|
28
|
+
label: "Services",
|
|
29
|
+
href: "#services",
|
|
30
|
+
Icon: ServerIcon,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "settings",
|
|
34
|
+
label: "Settings",
|
|
35
|
+
href: "#settings",
|
|
36
|
+
Icon: SettingsIcon,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "help",
|
|
40
|
+
label: "Help",
|
|
41
|
+
href: "#help",
|
|
42
|
+
Icon: HelpCircleIcon,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "support",
|
|
46
|
+
label: "Support",
|
|
47
|
+
href: "#support",
|
|
48
|
+
Icon: LifeBuoyIcon,
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
export const MOCK_HEADER_ITEMS: NavigationItem[] = [
|
|
53
|
+
{
|
|
54
|
+
id: "home",
|
|
55
|
+
label: "Home",
|
|
56
|
+
href: "#home",
|
|
57
|
+
Icon: HomeIcon,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "about",
|
|
61
|
+
label: "About",
|
|
62
|
+
href: "#about",
|
|
63
|
+
Icon: InfoIcon,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: "contact",
|
|
67
|
+
label: "Contact",
|
|
68
|
+
href: "#contact",
|
|
69
|
+
Icon: MailIcon,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: "services",
|
|
73
|
+
label: "Services",
|
|
74
|
+
href: "#services",
|
|
75
|
+
Icon: ServerIcon,
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
export const MOCK_HEADER_ITEMS_WITH_SUB_ITEMS: NavigationItem[] = [
|
|
80
|
+
{
|
|
81
|
+
id: "home",
|
|
82
|
+
label: "Home",
|
|
83
|
+
href: "#home",
|
|
84
|
+
Icon: HomeIcon,
|
|
85
|
+
subItems: MOCK_HEADER_SUB_ITEMS,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "about",
|
|
89
|
+
label: "About",
|
|
90
|
+
href: "#about",
|
|
91
|
+
Icon: InfoIcon,
|
|
92
|
+
subItems: MOCK_HEADER_SUB_ITEMS,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: "contact",
|
|
96
|
+
label: "Contact",
|
|
97
|
+
href: "#contact",
|
|
98
|
+
Icon: MailIcon,
|
|
99
|
+
subItems: MOCK_HEADER_SUB_ITEMS,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: "services",
|
|
103
|
+
label: "Services",
|
|
104
|
+
href: "#services",
|
|
105
|
+
Icon: ServerIcon,
|
|
106
|
+
subItems: MOCK_HEADER_SUB_ITEMS,
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
export const MOCK_HEADER_ACTIONS: SideBarAction[] = [
|
|
111
|
+
{
|
|
112
|
+
key: "logout",
|
|
113
|
+
label: "Logout",
|
|
114
|
+
color: "danger",
|
|
115
|
+
onPress: () => console.log("logout"),
|
|
116
|
+
startContent: <LogOutIcon />,
|
|
117
|
+
},
|
|
118
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./header";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Scaffold } from "@components";
|
|
2
|
+
import { defaultEmperorUIConfig } from "@constants";
|
|
3
|
+
import { EmperorUIContext } from "@context";
|
|
4
|
+
import type {
|
|
5
|
+
ConfigContextState,
|
|
6
|
+
ConfigProviderProps,
|
|
7
|
+
EmperorUIConfig,
|
|
8
|
+
} from "@types";
|
|
9
|
+
import { useMemo } from "react";
|
|
10
|
+
|
|
11
|
+
export function ConfigProvider({
|
|
12
|
+
children,
|
|
13
|
+
config = defaultEmperorUIConfig,
|
|
14
|
+
}: ConfigProviderProps) {
|
|
15
|
+
const emperorUIProviderValue: ConfigContextState = useMemo(() => {
|
|
16
|
+
const mergedConfig: EmperorUIConfig = {
|
|
17
|
+
layout: {
|
|
18
|
+
...defaultEmperorUIConfig?.layout,
|
|
19
|
+
...config?.layout,
|
|
20
|
+
},
|
|
21
|
+
theme: {
|
|
22
|
+
...defaultEmperorUIConfig?.theme,
|
|
23
|
+
...config?.theme,
|
|
24
|
+
colors: {
|
|
25
|
+
...defaultEmperorUIConfig?.theme?.colors,
|
|
26
|
+
...config?.theme?.colors,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
interLocalization: {
|
|
30
|
+
...defaultEmperorUIConfig?.interLocalization,
|
|
31
|
+
...config?.interLocalization,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
config: mergedConfig,
|
|
37
|
+
};
|
|
38
|
+
}, [config]);
|
|
39
|
+
|
|
40
|
+
const withScaffold = config.layout?.withScaffold ?? true;
|
|
41
|
+
|
|
42
|
+
if (withScaffold)
|
|
43
|
+
return (
|
|
44
|
+
<EmperorUIContext.Provider value={emperorUIProviderValue}>
|
|
45
|
+
<Scaffold>{children}</Scaffold>
|
|
46
|
+
</EmperorUIContext.Provider>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<EmperorUIContext.Provider value={emperorUIProviderValue}>
|
|
51
|
+
{children}
|
|
52
|
+
</EmperorUIContext.Provider>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { ConfigProviderProps } from "@types";
|
|
2
|
+
import { ConfigProvider, NavigationProvider } from "@providers";
|
|
3
|
+
import { HeroUIProvider, ToastProvider } from "@heroui/react";
|
|
4
|
+
import { Fragment } from "react";
|
|
5
|
+
|
|
6
|
+
type EmperorUIProviderProps = ConfigProviderProps & {};
|
|
6
7
|
|
|
7
8
|
export function EmperorUIProvider({
|
|
8
9
|
children,
|
|
9
|
-
|
|
10
|
+
...props
|
|
10
11
|
}: EmperorUIProviderProps) {
|
|
11
|
-
const emperorUIProviderValue: EmperorUIContextState = useMemo(() => {
|
|
12
|
-
return {
|
|
13
|
-
config,
|
|
14
|
-
};
|
|
15
|
-
}, [config]);
|
|
16
|
-
|
|
17
|
-
const withScaffold = config.layout?.withScaffold ?? true;
|
|
18
|
-
|
|
19
|
-
if (withScaffold)
|
|
20
|
-
return (
|
|
21
|
-
<EmperorUIContext.Provider value={emperorUIProviderValue}>
|
|
22
|
-
<Scaffold>{children}</Scaffold>
|
|
23
|
-
</EmperorUIContext.Provider>
|
|
24
|
-
);
|
|
25
|
-
|
|
26
12
|
return (
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
<ConfigProvider {...props}>
|
|
14
|
+
<HeroUIProvider>
|
|
15
|
+
<NavigationProvider>
|
|
16
|
+
<Fragment>
|
|
17
|
+
<ToastProvider {...props?.config?.toast} />
|
|
18
|
+
{children}
|
|
19
|
+
</Fragment>
|
|
20
|
+
</NavigationProvider>
|
|
21
|
+
</HeroUIProvider>
|
|
22
|
+
</ConfigProvider>
|
|
30
23
|
);
|
|
31
24
|
}
|
package/src/providers/index.ts
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
NavigationProviderProps,
|
|
3
|
+
NavigationContextState,
|
|
4
|
+
NavigationItem,
|
|
5
|
+
} from "@types";
|
|
6
|
+
import { useMemo, useState } from "react";
|
|
7
|
+
import { NavigationContext } from "@context";
|
|
8
|
+
import { PreservedKeys } from "@enums";
|
|
9
|
+
|
|
10
|
+
export function NavigationProvider({ children }: NavigationProviderProps) {
|
|
11
|
+
const [hoveredItemId, setHoveredItemId] = useState<string | null>(null);
|
|
12
|
+
const [subItems, setSubItems] = useState<NavigationItem[]>([]);
|
|
13
|
+
const [isSubItemsBoxOpen, setIsSubItemsBoxOpen] = useState(false);
|
|
14
|
+
const [subItemsBoxIsHovered, setSubItemsBoxIsHovered] = useState(false);
|
|
15
|
+
|
|
16
|
+
const navigationProviderValue: NavigationContextState = useMemo(() => {
|
|
17
|
+
return {
|
|
18
|
+
hoveredItemId,
|
|
19
|
+
subItems,
|
|
20
|
+
isSubItemsBoxOpen,
|
|
21
|
+
subItemsBoxIsHovered,
|
|
22
|
+
setHoveredItemId,
|
|
23
|
+
setSubItems,
|
|
24
|
+
setIsSubItemsBoxOpen,
|
|
25
|
+
setSubItemsBoxIsHovered,
|
|
26
|
+
};
|
|
27
|
+
}, [hoveredItemId, subItems, isSubItemsBoxOpen, subItemsBoxIsHovered]);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<NavigationContext.Provider
|
|
31
|
+
value={navigationProviderValue}
|
|
32
|
+
data-slot="emperor-navigation-provider"
|
|
33
|
+
>
|
|
34
|
+
<div
|
|
35
|
+
id={PreservedKeys.COMPACT_SIDEBAR_ID}
|
|
36
|
+
data-slot="emperor-compact-sidebar"
|
|
37
|
+
/>
|
|
38
|
+
|
|
39
|
+
{children}
|
|
40
|
+
</NavigationContext.Provider>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
UploaderProviderProps,
|
|
3
|
+
UploaderContextState,
|
|
4
|
+
FileObject,
|
|
5
|
+
} from "@types";
|
|
6
|
+
import { useMemo, useState } from "react";
|
|
7
|
+
import { UploaderContext } from "@context";
|
|
8
|
+
import { useDisclosure } from "@heroui/react";
|
|
9
|
+
|
|
10
|
+
export function UploaderProvider({
|
|
11
|
+
children,
|
|
12
|
+
...props
|
|
13
|
+
}: UploaderProviderProps) {
|
|
14
|
+
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
|
15
|
+
const [selectedFile, setSelectedFile] = useState<FileObject | null>(null);
|
|
16
|
+
|
|
17
|
+
const isFileViewable = useMemo(
|
|
18
|
+
() =>
|
|
19
|
+
!!selectedFile?.view &&
|
|
20
|
+
!!selectedFile?.file?.name &&
|
|
21
|
+
selectedFile?.type === "image",
|
|
22
|
+
[selectedFile],
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const uploaderProviderValue: UploaderContextState = useMemo(() => {
|
|
26
|
+
return {
|
|
27
|
+
isOpen,
|
|
28
|
+
onOpen,
|
|
29
|
+
onOpenChange,
|
|
30
|
+
selectedFile,
|
|
31
|
+
setSelectedFile,
|
|
32
|
+
isFileViewable,
|
|
33
|
+
...props,
|
|
34
|
+
};
|
|
35
|
+
}, [
|
|
36
|
+
isOpen,
|
|
37
|
+
isFileViewable,
|
|
38
|
+
selectedFile,
|
|
39
|
+
onOpen,
|
|
40
|
+
onOpenChange,
|
|
41
|
+
setSelectedFile,
|
|
42
|
+
props,
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<UploaderContext.Provider
|
|
47
|
+
value={uploaderProviderValue}
|
|
48
|
+
data-slot="emperor-uploader-provider"
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
</UploaderContext.Provider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
@plugin './hero.ts';
|
|
3
|
+
@source '../../node_modules/@heroui/theme/dist/**/*.{js,ts,jsx,tsx}';
|
|
4
|
+
@custom-variant dark (&:is(.dark *));
|
|
5
|
+
|
|
6
|
+
.scrollbar-hide {
|
|
7
|
+
-ms-overflow-style: none; /* IE and Edge */
|
|
8
|
+
scrollbar-width: none; /* Firefox */
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.scrollbar-hide::-webkit-scrollbar {
|
|
12
|
+
display: none; /* Chrome, Safari, Opera */
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SharedComponentProps } from "@types";
|
|
2
|
+
|
|
3
|
+
export type BrandProps = SharedComponentProps & {
|
|
4
|
+
src?: string;
|
|
5
|
+
alt?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
isIconOnly?: boolean;
|
|
8
|
+
classNames?: {
|
|
9
|
+
base?: string;
|
|
10
|
+
logo?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
};
|
|
13
|
+
};
|