@js-empire/emperor-ui 1.0.1 → 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 +16 -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 +4 -0
- package/dist/emperor-ui.js +0 -3171
- package/dist/emperor-ui.umd.cjs +0 -6
- package/dist/index.d.ts +0 -200
- 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,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NavBarItemStylesProps,
|
|
3
|
+
NavBarMenuStylesProps,
|
|
4
|
+
NavBarStylesProps,
|
|
5
|
+
} from "@types";
|
|
6
|
+
import { CSSProperties } from "react";
|
|
7
|
+
|
|
8
|
+
export const navBarStyles = ({
|
|
9
|
+
primaryColor,
|
|
10
|
+
foregroundColor,
|
|
11
|
+
variant,
|
|
12
|
+
}: NavBarStylesProps): CSSProperties => {
|
|
13
|
+
if (variant === "solid") {
|
|
14
|
+
return {
|
|
15
|
+
backgroundColor: primaryColor,
|
|
16
|
+
color: foregroundColor,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const navBarMenuStyles = ({}: NavBarMenuStylesProps): CSSProperties => {
|
|
24
|
+
return {};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const navBarItemStyles = ({
|
|
28
|
+
foregroundColor,
|
|
29
|
+
hoverEffect,
|
|
30
|
+
primaryColor,
|
|
31
|
+
isHovered,
|
|
32
|
+
variant,
|
|
33
|
+
}: NavBarItemStylesProps): CSSProperties => {
|
|
34
|
+
if (hoverEffect === "solid") {
|
|
35
|
+
return {
|
|
36
|
+
color: foregroundColor,
|
|
37
|
+
backgroundColor: primaryColor,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (hoverEffect === "underline") {
|
|
42
|
+
return {
|
|
43
|
+
// color: primaryColor,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (hoverEffect === "ghost") {
|
|
48
|
+
return {
|
|
49
|
+
color: isHovered ? primaryColor : foregroundColor,
|
|
50
|
+
backgroundColor: isHovered ? "transparent" : primaryColor,
|
|
51
|
+
borderColor: isHovered ? primaryColor : "transparent",
|
|
52
|
+
borderWidth: "2px",
|
|
53
|
+
borderStyle: "solid",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (hoverEffect === "bordered") {
|
|
58
|
+
return {
|
|
59
|
+
color: isHovered ? foregroundColor : primaryColor,
|
|
60
|
+
backgroundColor: isHovered ? primaryColor : "transparent",
|
|
61
|
+
borderColor: isHovered ? "transparent" : primaryColor,
|
|
62
|
+
borderTopWidth: "2px",
|
|
63
|
+
borderBottomWidth: "2px",
|
|
64
|
+
borderRightWidth: "1px",
|
|
65
|
+
borderLeftWidth: "1px",
|
|
66
|
+
borderStyle: "solid",
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (variant === "bordered") {
|
|
71
|
+
return {
|
|
72
|
+
color: primaryColor,
|
|
73
|
+
backgroundColor: "transparent",
|
|
74
|
+
borderColor: primaryColor,
|
|
75
|
+
borderTopWidth: "2px",
|
|
76
|
+
borderBottomWidth: "2px",
|
|
77
|
+
borderRightWidth: "1px",
|
|
78
|
+
borderLeftWidth: "1px",
|
|
79
|
+
borderStyle: "solid",
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {};
|
|
84
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { cn, Link } from "@heroui/react";
|
|
2
|
+
import { useNavigation } from "@hooks";
|
|
3
|
+
import { SubItemsBoxProps } from "@types";
|
|
4
|
+
|
|
5
|
+
export const SubItemsBox = ({ subItemsColumns = 3 }: SubItemsBoxProps) => {
|
|
6
|
+
const {
|
|
7
|
+
hoveredItemId,
|
|
8
|
+
subItems,
|
|
9
|
+
isSubItemsBoxOpen,
|
|
10
|
+
subItemsBoxIsHovered,
|
|
11
|
+
setSubItemsBoxIsHovered,
|
|
12
|
+
setIsSubItemsBoxOpen,
|
|
13
|
+
} = useNavigation();
|
|
14
|
+
|
|
15
|
+
const isOpen = isSubItemsBoxOpen || subItemsBoxIsHovered;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div
|
|
19
|
+
className={cn(
|
|
20
|
+
"absolute top-full left-0 w-full overflow-hidden bg-background",
|
|
21
|
+
"transition-all duration-300 ease-in-out z-50",
|
|
22
|
+
)}
|
|
23
|
+
style={{
|
|
24
|
+
maxHeight: isOpen
|
|
25
|
+
? `${Number(subItems.length / subItemsColumns) * 70}px`
|
|
26
|
+
: "0px",
|
|
27
|
+
}}
|
|
28
|
+
onMouseEnter={() => {
|
|
29
|
+
setSubItemsBoxIsHovered(true);
|
|
30
|
+
setIsSubItemsBoxOpen(true);
|
|
31
|
+
}}
|
|
32
|
+
onMouseLeave={() => {
|
|
33
|
+
setSubItemsBoxIsHovered(false);
|
|
34
|
+
if (!hoveredItemId) setIsSubItemsBoxOpen(false);
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<ul
|
|
38
|
+
className="grid border border-gray-200"
|
|
39
|
+
style={{ gridTemplateColumns: `repeat(${subItemsColumns}, 1fr)` }}
|
|
40
|
+
>
|
|
41
|
+
{subItems?.map(({ id, href, label, Icon }) => (
|
|
42
|
+
<Link
|
|
43
|
+
key={id}
|
|
44
|
+
href={href}
|
|
45
|
+
className={cn(
|
|
46
|
+
" w-full flex items-center gap-2 text-foreground p-2 transition-all duration-300 ease-in-out",
|
|
47
|
+
"hover:text-background hover:bg-primary",
|
|
48
|
+
)}
|
|
49
|
+
>
|
|
50
|
+
{Icon && <Icon className="size-4" />}
|
|
51
|
+
{label && <p>{label}</p>}
|
|
52
|
+
</Link>
|
|
53
|
+
))}
|
|
54
|
+
</ul>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { Scaffold } from "@components";
|
|
3
|
+
import { getStorybookDecorators } from "@utils";
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Scaffold> = {
|
|
6
|
+
title: "Molecules/Scaffold",
|
|
7
|
+
component: Scaffold,
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: "fullscreen",
|
|
10
|
+
},
|
|
11
|
+
tags: ["autodocs"],
|
|
12
|
+
decorators: getStorybookDecorators({}),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default meta;
|
|
16
|
+
|
|
17
|
+
type Story = StoryObj<typeof meta>;
|
|
18
|
+
|
|
19
|
+
export const Default: Story = {
|
|
20
|
+
args: {},
|
|
21
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useEmperorUI } from "@hooks";
|
|
2
|
+
import type { ScaffoldProps } from "@types";
|
|
3
|
+
import { cn } from "@utils";
|
|
4
|
+
import { cva } from "class-variance-authority";
|
|
5
|
+
import { forwardRef } from "react";
|
|
6
|
+
|
|
7
|
+
const scaffoldStyles = cva(["flex flex-col min-h-screen w-full max-w-screen"], {
|
|
8
|
+
variants: {},
|
|
9
|
+
defaultVariants: {},
|
|
10
|
+
compoundVariants: [],
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const Scaffold = forwardRef<HTMLDivElement, ScaffoldProps>(
|
|
14
|
+
({ className, children, ...props }, ref) => {
|
|
15
|
+
const { config } = useEmperorUI();
|
|
16
|
+
|
|
17
|
+
const backgroundColor = config?.theme?.colors?.background;
|
|
18
|
+
const foregroundColor = config?.theme?.colors?.foreground;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div
|
|
22
|
+
ref={ref}
|
|
23
|
+
dir={config?.dir}
|
|
24
|
+
data-slot="scaffold"
|
|
25
|
+
className={cn(scaffoldStyles({ className }), className)}
|
|
26
|
+
style={{
|
|
27
|
+
backgroundColor: backgroundColor,
|
|
28
|
+
color: foregroundColor,
|
|
29
|
+
}}
|
|
30
|
+
{...props}
|
|
31
|
+
>
|
|
32
|
+
{children}
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createPortal } from "react-dom";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { cn } from "@utils";
|
|
4
|
+
import { Button, Divider, ScrollShadow } from "@heroui/react";
|
|
5
|
+
import { CompactSideBarProps } from "@types";
|
|
6
|
+
|
|
7
|
+
const CompactSideBarContent = ({
|
|
8
|
+
items = [],
|
|
9
|
+
isOpen,
|
|
10
|
+
onOpenChange,
|
|
11
|
+
triggerProps,
|
|
12
|
+
}: CompactSideBarProps) => {
|
|
13
|
+
const { content, ...restTriggerProps } = triggerProps || {};
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div
|
|
17
|
+
className={cn(
|
|
18
|
+
"flex flex-col gap-4 p-2",
|
|
19
|
+
"h-[calc(100vh-16px)] bg-gray-200 m-2 rounded-lg overflow-hidden",
|
|
20
|
+
"transition-width ease-in-out duration-300",
|
|
21
|
+
isOpen ? "w-[20vw]" : "w-[48px]",
|
|
22
|
+
)}
|
|
23
|
+
>
|
|
24
|
+
<div className="w-fit flex flex-col">
|
|
25
|
+
<Button
|
|
26
|
+
variant="light"
|
|
27
|
+
size="sm"
|
|
28
|
+
onPress={() => onOpenChange?.(true)}
|
|
29
|
+
className={cn("min-w-7 w-fit px-0.5")}
|
|
30
|
+
{...restTriggerProps}
|
|
31
|
+
>
|
|
32
|
+
{content}
|
|
33
|
+
</Button>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<Divider />
|
|
37
|
+
|
|
38
|
+
<ScrollShadow
|
|
39
|
+
as="ul"
|
|
40
|
+
hideScrollBar
|
|
41
|
+
className="max-h-[70vh] flex flex-col gap-4 p-0 overflow-y-auto"
|
|
42
|
+
>
|
|
43
|
+
{items?.map(({ id, Icon, label }) => (
|
|
44
|
+
<li
|
|
45
|
+
key={id}
|
|
46
|
+
className="w-fit flex items-center justify-center gap-3 ms-1.5 cursor-pointer"
|
|
47
|
+
>
|
|
48
|
+
{Icon && <Icon className="size-5" />}
|
|
49
|
+
|
|
50
|
+
{label && isOpen && (
|
|
51
|
+
<p className={cn("text-sm font-semibold")}>{label}</p>
|
|
52
|
+
)}
|
|
53
|
+
</li>
|
|
54
|
+
))}
|
|
55
|
+
</ScrollShadow>
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const CompactSideBar = (props: CompactSideBarProps) => {
|
|
61
|
+
const [container, setContainer] = useState<HTMLElement | null>(null);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
const element = document.getElementById("emperor-compact-sidebar");
|
|
65
|
+
setContainer(element);
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
if (!container) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return createPortal(<CompactSideBarContent {...props} />, container);
|
|
73
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./side-bar";
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { useEmperorUI } from "@hooks";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Drawer,
|
|
6
|
+
DrawerHeader,
|
|
7
|
+
DrawerBody,
|
|
8
|
+
DrawerContent,
|
|
9
|
+
ScrollShadow,
|
|
10
|
+
Divider,
|
|
11
|
+
DrawerFooter,
|
|
12
|
+
} from "@heroui/react";
|
|
13
|
+
import { SideBarProps } from "@types";
|
|
14
|
+
import { cn } from "@utils";
|
|
15
|
+
import { sideBarItemClasses, sideBarItemStyles } from "./styles";
|
|
16
|
+
|
|
17
|
+
export const SideBarDrawer = ({
|
|
18
|
+
isOpen,
|
|
19
|
+
onOpenChange,
|
|
20
|
+
triggerProps,
|
|
21
|
+
classNames,
|
|
22
|
+
header,
|
|
23
|
+
items = [],
|
|
24
|
+
actions = [],
|
|
25
|
+
variant = "default",
|
|
26
|
+
}: SideBarProps) => {
|
|
27
|
+
const { config } = useEmperorUI();
|
|
28
|
+
const [hoveredItem, setHoveredItem] = useState<string | null>(null);
|
|
29
|
+
const { content, ...restTriggerProps } = triggerProps || {};
|
|
30
|
+
|
|
31
|
+
const dir = config?.interLocalization?.dir;
|
|
32
|
+
const backgroundColor = config?.theme?.colors?.background;
|
|
33
|
+
const primaryColor = config?.theme?.colors?.primary;
|
|
34
|
+
const foregroundColor = config?.theme?.colors?.foreground;
|
|
35
|
+
|
|
36
|
+
const isRTL = dir === "rtl";
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
<Button
|
|
41
|
+
variant="ghost"
|
|
42
|
+
isIconOnly
|
|
43
|
+
size="sm"
|
|
44
|
+
onPress={() => onOpenChange?.(true)}
|
|
45
|
+
className={cn(classNames?.trigger)}
|
|
46
|
+
{...restTriggerProps}
|
|
47
|
+
>
|
|
48
|
+
{content}
|
|
49
|
+
</Button>
|
|
50
|
+
|
|
51
|
+
<Drawer
|
|
52
|
+
isOpen={isOpen}
|
|
53
|
+
onOpenChange={onOpenChange}
|
|
54
|
+
placement={isRTL ? "right" : "left"}
|
|
55
|
+
size="sm"
|
|
56
|
+
dir={dir}
|
|
57
|
+
className="p-0"
|
|
58
|
+
>
|
|
59
|
+
<DrawerContent
|
|
60
|
+
className="p-0"
|
|
61
|
+
style={{ backgroundColor, color: foregroundColor }}
|
|
62
|
+
>
|
|
63
|
+
<DrawerHeader className={cn("text-xl font-bold", classNames?.title)}>
|
|
64
|
+
{header}
|
|
65
|
+
</DrawerHeader>
|
|
66
|
+
|
|
67
|
+
<DrawerBody className={cn("p-0 mt-4 h-fit")}>
|
|
68
|
+
<ScrollShadow
|
|
69
|
+
as="ul"
|
|
70
|
+
hideScrollBar
|
|
71
|
+
data-slot="emperor-side-bar-menu"
|
|
72
|
+
className={cn("max-h-[60vh] overflow-y-auto", classNames?.menu)}
|
|
73
|
+
>
|
|
74
|
+
{items?.map(({ id, label, href, Icon }) => (
|
|
75
|
+
<li
|
|
76
|
+
key={href}
|
|
77
|
+
data-slot="emperor-side-bar-item"
|
|
78
|
+
style={sideBarItemStyles({
|
|
79
|
+
foregroundColor,
|
|
80
|
+
primaryColor,
|
|
81
|
+
isHovered: hoveredItem === id,
|
|
82
|
+
variant,
|
|
83
|
+
})}
|
|
84
|
+
className={cn(
|
|
85
|
+
sideBarItemClasses({ variant }),
|
|
86
|
+
classNames?.menuItem,
|
|
87
|
+
)}
|
|
88
|
+
onMouseEnter={() => setHoveredItem(id)}
|
|
89
|
+
onMouseLeave={() => setHoveredItem(null)}
|
|
90
|
+
>
|
|
91
|
+
{Icon && <Icon className="size-4" />}
|
|
92
|
+
{label && <p>{label}</p>}
|
|
93
|
+
</li>
|
|
94
|
+
))}
|
|
95
|
+
</ScrollShadow>
|
|
96
|
+
</DrawerBody>
|
|
97
|
+
|
|
98
|
+
{actions && actions?.length > 0 && (
|
|
99
|
+
<>
|
|
100
|
+
<Divider
|
|
101
|
+
className="m-auto w-11/12"
|
|
102
|
+
style={{ backgroundColor: foregroundColor + "20" }}
|
|
103
|
+
/>
|
|
104
|
+
|
|
105
|
+
<DrawerFooter className={cn(classNames?.actionsWrapper)}>
|
|
106
|
+
{actions?.map(({ key, label, ...props }) => (
|
|
107
|
+
<Button
|
|
108
|
+
key={key}
|
|
109
|
+
variant="ghost"
|
|
110
|
+
size="sm"
|
|
111
|
+
className={cn(classNames?.actionItem)}
|
|
112
|
+
{...props}
|
|
113
|
+
>
|
|
114
|
+
{label}
|
|
115
|
+
</Button>
|
|
116
|
+
))}
|
|
117
|
+
</DrawerFooter>
|
|
118
|
+
</>
|
|
119
|
+
)}
|
|
120
|
+
</DrawerContent>
|
|
121
|
+
</Drawer>
|
|
122
|
+
</>
|
|
123
|
+
);
|
|
124
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { Brand, SideBar } from "@components";
|
|
3
|
+
import { getStorybookDecorators } from "@utils";
|
|
4
|
+
import { MenuIcon } from "lucide-react";
|
|
5
|
+
import { useDisclosure } from "@heroui/react";
|
|
6
|
+
import { MOCK_HEADER_ACTIONS, MOCK_HEADER_ITEMS } from "@mocks";
|
|
7
|
+
|
|
8
|
+
const meta: Meta<typeof SideBar> = {
|
|
9
|
+
title: "Molecules/SideBar",
|
|
10
|
+
component: SideBar,
|
|
11
|
+
parameters: {
|
|
12
|
+
layout: "fullscreen",
|
|
13
|
+
},
|
|
14
|
+
tags: ["autodocs"],
|
|
15
|
+
decorators: getStorybookDecorators({
|
|
16
|
+
config: {
|
|
17
|
+
layout: {
|
|
18
|
+
withScaffold: false,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default meta;
|
|
25
|
+
|
|
26
|
+
type Story = StoryObj<typeof meta>;
|
|
27
|
+
|
|
28
|
+
export const Default: Story = {
|
|
29
|
+
args: {
|
|
30
|
+
header: <Brand className="text-white" />,
|
|
31
|
+
triggerProps: {
|
|
32
|
+
className: "m-5",
|
|
33
|
+
startContent: <MenuIcon className="size-4" />,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
render: (args) => {
|
|
37
|
+
const { isOpen, onOpenChange } = useDisclosure();
|
|
38
|
+
|
|
39
|
+
return <SideBar {...args} isOpen={isOpen} onOpenChange={onOpenChange} />;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const WithItems: Story = {
|
|
44
|
+
args: {
|
|
45
|
+
header: <Brand className="text-white" />,
|
|
46
|
+
triggerProps: {
|
|
47
|
+
className: "m-5",
|
|
48
|
+
startContent: <MenuIcon className="size-4" />,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
render: (args) => {
|
|
52
|
+
const { isOpen, onOpenChange } = useDisclosure();
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<SideBar
|
|
56
|
+
{...args}
|
|
57
|
+
isOpen={isOpen}
|
|
58
|
+
onOpenChange={onOpenChange}
|
|
59
|
+
items={MOCK_HEADER_ITEMS}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const WithActions: Story = {
|
|
66
|
+
args: {
|
|
67
|
+
header: <Brand className="text-white" />,
|
|
68
|
+
triggerProps: {
|
|
69
|
+
className: "m-5",
|
|
70
|
+
startContent: <MenuIcon className="size-4" />,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
render: (args) => {
|
|
74
|
+
const { isOpen, onOpenChange } = useDisclosure();
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<SideBar
|
|
78
|
+
{...args}
|
|
79
|
+
isOpen={isOpen}
|
|
80
|
+
onOpenChange={onOpenChange}
|
|
81
|
+
items={MOCK_HEADER_ITEMS}
|
|
82
|
+
actions={MOCK_HEADER_ACTIONS}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const Compact: Story = {
|
|
89
|
+
args: {
|
|
90
|
+
variant: "compact",
|
|
91
|
+
},
|
|
92
|
+
render: (args) => {
|
|
93
|
+
const { isOpen, onOpenChange } = useDisclosure();
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<SideBar
|
|
97
|
+
{...args}
|
|
98
|
+
isOpen={isOpen}
|
|
99
|
+
onOpenChange={onOpenChange}
|
|
100
|
+
items={MOCK_HEADER_ITEMS}
|
|
101
|
+
actions={MOCK_HEADER_ACTIONS}
|
|
102
|
+
triggerProps={{
|
|
103
|
+
content: (
|
|
104
|
+
<Brand classNames={{ logo: "size-7" }} isIconOnly={!isOpen} />
|
|
105
|
+
),
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
},
|
|
110
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { cn } from "@utils";
|
|
2
|
+
import { VariantProps } from "class-variance-authority";
|
|
3
|
+
import { forwardRef, ComponentProps } from "react";
|
|
4
|
+
import { sideBarClasses } from "./styles";
|
|
5
|
+
import type { SideBarProps } from "@types";
|
|
6
|
+
import { SideBarDrawer } from "./side-bar-drawer";
|
|
7
|
+
import { CompactSideBar } from "./compact-side-bar";
|
|
8
|
+
|
|
9
|
+
export const SideBar = forwardRef<
|
|
10
|
+
HTMLDivElement,
|
|
11
|
+
ComponentProps<"div"> & VariantProps<typeof sideBarClasses> & SideBarProps
|
|
12
|
+
>((props, ref) => {
|
|
13
|
+
const { variant = "default", className, classNames } = props;
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div
|
|
17
|
+
ref={ref}
|
|
18
|
+
data-slot="emperor-side-bar"
|
|
19
|
+
className={cn(
|
|
20
|
+
sideBarClasses({
|
|
21
|
+
variant,
|
|
22
|
+
className: cn(className, classNames?.base),
|
|
23
|
+
}),
|
|
24
|
+
)}
|
|
25
|
+
{...props}
|
|
26
|
+
>
|
|
27
|
+
{variant === "default" && <SideBarDrawer {...props} />}
|
|
28
|
+
{variant === "compact" && <CompactSideBar {...props} />}
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cva } from "class-variance-authority";
|
|
2
|
+
|
|
3
|
+
export const sideBarClasses = cva([""], {
|
|
4
|
+
variants: {
|
|
5
|
+
variant: {
|
|
6
|
+
default: [],
|
|
7
|
+
compact: [],
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
defaultVariants: {},
|
|
11
|
+
compoundVariants: [],
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const sideBarItemClasses = cva(
|
|
15
|
+
[
|
|
16
|
+
"w-full cursor-pointer px-6 py-2 transition-all font-semibold text-sm flex items-center gap-2",
|
|
17
|
+
],
|
|
18
|
+
{
|
|
19
|
+
variants: {
|
|
20
|
+
variant: {
|
|
21
|
+
default: [],
|
|
22
|
+
compact: [],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
defaultVariants: {},
|
|
26
|
+
compoundVariants: [],
|
|
27
|
+
},
|
|
28
|
+
);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SideBarItemStylesProps } from "@types";
|
|
2
|
+
import { CSSProperties } from "react";
|
|
3
|
+
|
|
4
|
+
export const sideBarItemStyles = ({
|
|
5
|
+
foregroundColor,
|
|
6
|
+
primaryColor,
|
|
7
|
+
isHovered,
|
|
8
|
+
}: SideBarItemStylesProps): CSSProperties => {
|
|
9
|
+
return {
|
|
10
|
+
color: isHovered ? foregroundColor : "inherit",
|
|
11
|
+
backgroundColor: isHovered ? primaryColor : "transparent",
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FooterProps } from "@types";
|
|
2
|
+
import { cn } from "@utils";
|
|
3
|
+
import { VariantProps } from "class-variance-authority";
|
|
4
|
+
import { ComponentProps, forwardRef } from "react";
|
|
5
|
+
import { footerClasses, footerStyles } from "./styles";
|
|
6
|
+
|
|
7
|
+
export const Footer = forwardRef<
|
|
8
|
+
HTMLElement,
|
|
9
|
+
ComponentProps<"footer"> & VariantProps<typeof footerClasses> & FooterProps
|
|
10
|
+
>(({ className, variant = "default", children, ...props }, ref) => {
|
|
11
|
+
return (
|
|
12
|
+
<footer
|
|
13
|
+
ref={ref}
|
|
14
|
+
data-slot="emperor-footer"
|
|
15
|
+
className={cn(footerClasses({ variant, className }))}
|
|
16
|
+
style={footerStyles({})}
|
|
17
|
+
{...props}
|
|
18
|
+
></footer>
|
|
19
|
+
);
|
|
20
|
+
});
|