gbs-add-block 0.0.76 → 0.0.79

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # GBS Building Blocks 2.0 (v0.0.70)
1
+ # GBS Building Blocks 2.0 (v0.0.79)
2
2
 
3
3
  Latest and upgraded version of GBS building blocks with headless UI and removed dependencies.
4
4
 
@@ -6,9 +6,10 @@ Latest and upgraded version of GBS building blocks with headless UI and removed
6
6
 
7
7
  For detailed documentation on usage and props, Please visit: [Building Block Documentation v2.0](https://blackmax-designs.gitbook.io/building-block-v2.0)
8
8
 
9
- ## What's New 🎉 (Ver 0.0.70)
9
+ ## What's New 🎉 (Ver 0.0.79)
10
10
 
11
11
  - Updated for bug fixes.
12
+ - New Component Card & SideBar Added
12
13
 
13
14
  ## Authors
14
15
 
package/index.cjs CHANGED
@@ -10,6 +10,7 @@ const CONFIG = {
10
10
  components: [
11
11
  "Card",
12
12
  "Select",
13
+ "SideBar",
13
14
  "Grid",
14
15
  "MultiSelect",
15
16
  "Button",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gbs-add-block",
3
- "version": "0.0.76",
3
+ "version": "0.0.79",
4
4
  "description": "React Component Library",
5
5
  "type": "module",
6
6
  "files": [
@@ -4,6 +4,7 @@ import { ContextMenuProps, Position } from "./types";
4
4
  export const ContextMenu: React.FC<ContextMenuProps> = ({ children }) => {
5
5
  const [isVisible, setIsVisible] = useState<boolean>(false);
6
6
  const [position, setPosition] = useState<Position>({ x: 0, y: 0 });
7
+ const [viewportSize, setViewportSize] = useState<Position>({ x: 0, y: 0 });
7
8
 
8
9
  const handleContextMenu = useCallback(
9
10
  (event: MouseEvent | globalThis.MouseEvent) => {
@@ -22,25 +23,48 @@ export const ContextMenu: React.FC<ContextMenuProps> = ({ children }) => {
22
23
  }, [isVisible]);
23
24
 
24
25
  useEffect(() => {
25
- document.addEventListener("click", handleClick);
26
- document.addEventListener("contextmenu", handleContextMenu);
26
+ if (typeof window !== "undefined") {
27
+ setViewportSize({
28
+ x: window.innerWidth,
29
+ y: window.innerHeight,
30
+ });
31
+
32
+ const handleResize = () => {
33
+ setViewportSize({
34
+ x: window.innerWidth,
35
+ y: window.innerHeight,
36
+ });
37
+ };
27
38
 
28
- return () => {
29
- document.removeEventListener("click", handleClick);
30
- document.removeEventListener("contextmenu", handleContextMenu);
31
- };
39
+ window.addEventListener("resize", handleResize);
40
+ return () => window.removeEventListener("resize", handleResize);
41
+ }
42
+ }, []);
43
+
44
+ useEffect(() => {
45
+ if (typeof document !== "undefined") {
46
+ document.addEventListener("click", handleClick);
47
+ document.addEventListener("contextmenu", handleContextMenu);
48
+
49
+ return () => {
50
+ document.removeEventListener("click", handleClick);
51
+ document.removeEventListener("contextmenu", handleContextMenu);
52
+ };
53
+ }
32
54
  }, [handleClick, handleContextMenu]);
33
55
 
34
- // Ensure menu stays within viewport bounds
35
- const adjustedPosition = useCallback((position: Position): Position => {
36
- const menuWidth = 160; // min-width from CSS
37
- const menuHeight = 200; // approximate max height
56
+ const adjustedPosition = useCallback(
57
+ (pos: Position): Position => {
58
+ const menuWidth = 160; // min-width from CSS
59
+ const menuHeight = 200; // approximate max height
38
60
 
39
- return {
40
- x: Math.min(position.x, window.innerWidth - menuWidth),
41
- y: Math.min(position.y, window.innerHeight - menuHeight),
42
- };
43
- }, []);
61
+ return {
62
+ x: Math.min(pos.x, Math.max(viewportSize.x - menuWidth, 0)),
63
+ y: Math.min(pos.y, Math.max(viewportSize.y - menuHeight, 0)),
64
+ };
65
+ },
66
+ [viewportSize]
67
+ );
44
68
 
45
69
  const finalPosition = adjustedPosition(position);
46
70
 
@@ -113,7 +113,7 @@ const MultiSelect = forwardRef<MultiSelectHandle, MultiSelectProps>(
113
113
  return (
114
114
  <div className="relative w-full" ref={selectRef}>
115
115
  <div
116
- className={`relative border w-full flex items-center px-4 py-2 rounded-lg ${
116
+ className={`relative border border-gary-300 w-full flex items-center px-4 py-2 rounded-lg ${
117
117
  error && "border-red-500"
118
118
  }`}
119
119
  >
@@ -186,7 +186,7 @@ const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
186
186
  </div>
187
187
  )}
188
188
  {filteredItems.length > 0 ? (
189
- filteredItems.map(({ value, label }, index) => (
189
+ filteredItems.map(({ value, label }, index: number) => (
190
190
  <button
191
191
  key={value}
192
192
  ref={(el: any) => (itemRefs.current[index] = el)}
@@ -0,0 +1,81 @@
1
+ import { MenuItem, IconComponent } from "../type";
2
+
3
+ type MenuItemProps = {
4
+ item: MenuItem;
5
+ iconMap: Record<string, IconComponent>;
6
+ onToggle: () => void;
7
+ };
8
+
9
+ export const MenuItemComponent = ({
10
+ item,
11
+ iconMap,
12
+ onToggle,
13
+ }: MenuItemProps) => {
14
+ const IconComponent = iconMap[item.icon] || (() => null);
15
+
16
+ return (
17
+ <li>
18
+ <a
19
+ href={item.path}
20
+ onClick={
21
+ item.expandable
22
+ ? (e) => {
23
+ e.preventDefault();
24
+ onToggle();
25
+ }
26
+ : undefined
27
+ }
28
+ className={`flex items-center py-2 px-3 rounded-md text-sm ${
29
+ item.active
30
+ ? "bg-gray-100 text-black font-medium"
31
+ : "text-gray-700 hover:bg-gray-50"
32
+ }`}
33
+ >
34
+ <span className="mr-3">
35
+ <IconComponent />
36
+ </span>
37
+ <span className="flex-grow">{item.name}</span>
38
+ {item.badge && (
39
+ <span className="bg-black text-white text-xs px-2 py-0.5 rounded-full">
40
+ {item.badge}
41
+ </span>
42
+ )}
43
+ {item.expandable && (
44
+ <svg
45
+ className={`h-4 w-4 transform ${item.expanded ? "rotate-180" : ""}`}
46
+ fill="none"
47
+ viewBox="0 0 24 24"
48
+ stroke="currentColor"
49
+ >
50
+ <path
51
+ strokeLinecap="round"
52
+ strokeLinejoin="round"
53
+ strokeWidth={2}
54
+ d="M19 9l-7 7-7-7"
55
+ />
56
+ </svg>
57
+ )}
58
+ </a>
59
+ {item.expandable && item.expanded && (
60
+ <ul className="pl-10 mt-1 space-y-1">
61
+ <li>
62
+ <a
63
+ href="#"
64
+ className="block py-1 text-sm text-gray-600 hover:text-teal-600"
65
+ >
66
+ Submenu Item 1
67
+ </a>
68
+ </li>
69
+ <li>
70
+ <a
71
+ href="#"
72
+ className="block py-1 text-sm text-gray-600 hover:text-teal-600"
73
+ >
74
+ Submenu Item 2
75
+ </a>
76
+ </li>
77
+ </ul>
78
+ )}
79
+ </li>
80
+ );
81
+ };
@@ -0,0 +1,34 @@
1
+ import { MenuSection as MenuSectionType, IconComponent } from "../type";
2
+ import { MenuItemComponent } from "./MenuItem";
3
+
4
+ type MenuSectionProps = {
5
+ section: MenuSectionType;
6
+ sectionIndex: number;
7
+ iconMap: Record<string, IconComponent>;
8
+ toggleItem: (sectionIndex: number, itemId: number) => void;
9
+ };
10
+
11
+ export const MenuSection = ({
12
+ section,
13
+ sectionIndex,
14
+ iconMap,
15
+ toggleItem,
16
+ }: MenuSectionProps) => {
17
+ return (
18
+ <div className="mb-6">
19
+ <div className="text-xs font-medium text-gray-400 mb-2">
20
+ {section.title}
21
+ </div>
22
+ <ul className="space-y-1">
23
+ {section.items.map((item) => (
24
+ <MenuItemComponent
25
+ key={item.id}
26
+ item={item}
27
+ iconMap={iconMap}
28
+ onToggle={() => toggleItem(sectionIndex, item.id)}
29
+ />
30
+ ))}
31
+ </ul>
32
+ </div>
33
+ );
34
+ };
@@ -0,0 +1,66 @@
1
+ import { MenuItem, IconComponent } from "../type";
2
+
3
+ type SidebarFooterProps = {
4
+ footerItems?: MenuItem[];
5
+ iconMap: Record<string, IconComponent>;
6
+ toggleProMode: () => void;
7
+ };
8
+
9
+ export const SidebarFooter = ({
10
+ footerItems,
11
+ iconMap,
12
+ toggleProMode,
13
+ }: SidebarFooterProps) => {
14
+ if (!footerItems) return null;
15
+ if (!iconMap) return null;
16
+
17
+ return (
18
+ <div className="border-t border-gray-200">
19
+ <ul className="px-4 py-2 space-y-1">
20
+ {footerItems?.map((item) => {
21
+ const IconComponent = iconMap[item.icon] || (() => null);
22
+
23
+ if (item.toggle) {
24
+ return (
25
+ <li
26
+ key={item.id}
27
+ className="flex items-center py-2 px-3 text-sm text-gray-700"
28
+ >
29
+ <span className="mr-3">
30
+ <IconComponent />
31
+ </span>
32
+ <span className="flex-grow">{item.name}</span>
33
+ <button
34
+ onClick={toggleProMode}
35
+ className={`w-10 h-5 flex items-center rounded-full p-1 ${
36
+ item.active ? "bg-black" : "bg-gray-300"
37
+ }`}
38
+ >
39
+ <span
40
+ className={`bg-white w-4 h-4 rounded-full shadow-md transform transition-transform ${
41
+ item.active ? "translate-x-5" : ""
42
+ }`}
43
+ />
44
+ </button>
45
+ </li>
46
+ );
47
+ }
48
+
49
+ return (
50
+ <li key={item.id}>
51
+ <a
52
+ href={item.path}
53
+ className="flex items-center py-2 px-3 rounded-md text-sm text-gray-700 hover:bg-gray-50"
54
+ >
55
+ <span className="mr-3">
56
+ <IconComponent />
57
+ </span>
58
+ <span>{item?.name}</span>
59
+ </a>
60
+ </li>
61
+ );
62
+ })}
63
+ </ul>
64
+ </div>
65
+ );
66
+ };
@@ -0,0 +1,24 @@
1
+ import { MenuData } from "../type";
2
+
3
+ type SidebarLogoProps = {
4
+ logo: MenuData["logo"];
5
+ };
6
+
7
+ export const SidebarLogo = ({ logo }: SidebarLogoProps) => {
8
+ if (!logo) return null;
9
+
10
+ return (
11
+ <div className="p-4 flex items-center">
12
+ <div className="flex-shrink-0 mr-2">
13
+ <div className="h-6 w-6 bg-black text-white rounded flex items-center justify-center">
14
+ <img
15
+ src={logo?.logoUrl}
16
+ alt={logo?.name}
17
+ className="h-4 w-4 text-white"
18
+ />
19
+ </div>
20
+ </div>
21
+ <span className="text-gray-800 font-semibold text-lg">{logo?.name}</span>
22
+ </div>
23
+ );
24
+ };
@@ -0,0 +1,28 @@
1
+ import { IconComponent, MenuSection } from "../type";
2
+ import { MenuSection as MenuSectionComponent } from "./MenuSection";
3
+
4
+ type SidebarMenuProps = {
5
+ sections?: MenuSection[];
6
+ iconMap: Record<string, IconComponent>;
7
+ toggleItem: (sectionIndex: number, itemId: number) => void;
8
+ };
9
+
10
+ export const SidebarMenu = ({
11
+ sections,
12
+ iconMap,
13
+ toggleItem,
14
+ }: SidebarMenuProps) => {
15
+ return (
16
+ <div className="flex-grow overflow-y-auto px-4 py-2">
17
+ {sections?.map((section, sectionIndex) => (
18
+ <MenuSectionComponent
19
+ key={section.title}
20
+ section={section}
21
+ sectionIndex={sectionIndex}
22
+ iconMap={iconMap}
23
+ toggleItem={toggleItem}
24
+ />
25
+ ))}
26
+ </div>
27
+ );
28
+ };
@@ -0,0 +1,31 @@
1
+ import { MenuData } from "../type";
2
+
3
+ type UserProfileProps = {
4
+ profile: MenuData["profile"];
5
+ };
6
+
7
+ export const UserProfile = ({ profile }: UserProfileProps) => {
8
+ if (!profile) return null;
9
+
10
+ return (
11
+ <div className="border-t border-gray-200 px-4 py-3 flex flex-col gap-2">
12
+ <div className="flex">
13
+ <div className="w-8 h-8 rounded-full bg-orange-100 text-orange-700 flex items-center justify-center mr-3">
14
+ <span className="text-xs font-medium">
15
+ {profile?.name
16
+ .split(" ")
17
+ .map((n) => n[0])
18
+ .join("")}
19
+ </span>
20
+ </div>
21
+ <div className="flex-grow">
22
+ <div className="text-sm font-medium text-gray-700">
23
+ {profile?.name}
24
+ </div>
25
+ <div className="text-xs text-gray-400">{profile?.email}</div>
26
+ </div>
27
+ </div>
28
+ <div className="text-xs text-gray-400">© 2024 Sequence Inc.</div>
29
+ </div>
30
+ );
31
+ };
@@ -0,0 +1,38 @@
1
+ import { useState } from "react";
2
+ import { MenuData } from "../type";
3
+
4
+ export const useSidebarState = (menuData: MenuData) => {
5
+ const [sidebarData, setSidebarData] = useState<MenuData>(menuData);
6
+
7
+ const toggleItem = (sectionIndex: number, itemId: number): void => {
8
+ const newData = { ...sidebarData };
9
+
10
+ const section = newData.sections?.[sectionIndex];
11
+ if (!section) return;
12
+
13
+ const itemIndex = section.items.findIndex((item) => item.id === itemId);
14
+ if (itemIndex === -1) return;
15
+
16
+ if (section.items[itemIndex].expandable) {
17
+ section.items[itemIndex].expanded = !section.items[itemIndex].expanded;
18
+ setSidebarData({ ...newData });
19
+ }
20
+ };
21
+
22
+ const toggleProMode = (): void => {
23
+ const newData = { ...sidebarData };
24
+ if (!newData.footer) return;
25
+
26
+ const proModeIndex = newData.footer.findIndex((item) => item.toggle);
27
+ if (proModeIndex === -1) return;
28
+
29
+ newData.footer[proModeIndex].active = !newData.footer[proModeIndex].active;
30
+ setSidebarData({ ...newData });
31
+ };
32
+
33
+ return {
34
+ sidebarData,
35
+ toggleItem,
36
+ toggleProMode,
37
+ };
38
+ };
@@ -0,0 +1,27 @@
1
+ import { SidebarProps } from "./type";
2
+ import { useSidebarState } from "./hooks/useSidebarState";
3
+ import { SidebarLogo } from "./components/SidebarLogo";
4
+ import { SidebarMenu } from "./components/SidebarMenu";
5
+ import { SidebarFooter } from "./components/SidebarFooter";
6
+ import { UserProfile } from "./components/UserProfile";
7
+
8
+ export function Sidebar({ menuData, iconMap }: SidebarProps) {
9
+ const { sidebarData, toggleItem, toggleProMode } = useSidebarState(menuData);
10
+
11
+ return (
12
+ <div className="hidden md:flex flex-col h-screen bg-white w-64 border-r border-gray-200">
13
+ <SidebarLogo logo={sidebarData.logo} />
14
+ <SidebarMenu
15
+ sections={sidebarData.sections}
16
+ iconMap={iconMap}
17
+ toggleItem={toggleItem}
18
+ />
19
+ <SidebarFooter
20
+ footerItems={sidebarData.footer}
21
+ iconMap={iconMap}
22
+ toggleProMode={toggleProMode}
23
+ />
24
+ <UserProfile profile={sidebarData.profile} />
25
+ </div>
26
+ );
27
+ }
@@ -0,0 +1,37 @@
1
+ export type IconComponent = React.FC;
2
+
3
+ export type MenuItem = {
4
+ id: number;
5
+ name: string;
6
+ icon: string;
7
+ path: string;
8
+ active?: boolean;
9
+ expandable?: boolean;
10
+ expanded?: boolean;
11
+ badge?: string;
12
+ toggle?: boolean;
13
+ };
14
+
15
+ export type MenuSection = {
16
+ title: string;
17
+ items: MenuItem[];
18
+ };
19
+
20
+ export type MenuData = {
21
+ logo?: {
22
+ name: string;
23
+ logoUrl: string;
24
+ };
25
+ sections?: MenuSection[];
26
+ footer?: MenuItem[];
27
+ profile?: {
28
+ name: string;
29
+ email: string;
30
+ avatarUrl: string;
31
+ };
32
+ };
33
+
34
+ export type SidebarProps = {
35
+ menuData: MenuData;
36
+ iconMap: Record<string, IconComponent>;
37
+ };
@@ -20,7 +20,7 @@ interface SkeletonProps {
20
20
  keyframes?: string;
21
21
  }
22
22
 
23
- const Skeleton: React.FC<SkeletonProps> = memo(
23
+ export const Skeleton: React.FC<SkeletonProps> = memo(
24
24
  ({
25
25
  type = "text",
26
26
  lines = 1,
@@ -93,5 +93,3 @@ const Skeleton: React.FC<SkeletonProps> = memo(
93
93
  );
94
94
 
95
95
  Skeleton.displayName = "Skeleton";
96
-
97
- export default Skeleton;