@gobolt/genesis 0.4.4 → 0.4.5

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.
@@ -1,13 +1,17 @@
1
1
  import { default as React } from 'react';
2
+ import { OverflowMenuItemProps } from '../OverflowMenuItem';
2
3
  export interface OverflowMenuProps {
3
- children: React.ReactNode;
4
+ items?: OverflowMenuItemProps[];
5
+ children?: React.ReactNode;
4
6
  trigger: React.ReactNode;
5
7
  isOpen?: boolean;
6
8
  onOpenChange?: (open: boolean) => void;
7
9
  placement?: "bottom" | "top" | "left" | "right";
10
+ alignment?: "left" | "right";
8
11
  offset?: number;
9
12
  className?: string;
10
13
  style?: React.CSSProperties;
14
+ onItemClick?: (item: OverflowMenuItemProps) => void;
11
15
  }
12
16
  declare const OverflowMenu: React.FC<OverflowMenuProps>;
13
17
  export default OverflowMenu;
@@ -0,0 +1,8 @@
1
+ import { default as React } from 'react';
2
+ export interface OverflowMenuItemProps {
3
+ id?: string;
4
+ children: React.ReactNode;
5
+ onClick?: () => void;
6
+ }
7
+ declare const OverflowMenuItem: ({ children, onClick }: OverflowMenuItemProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default OverflowMenuItem;
@@ -0,0 +1,2 @@
1
+ export { default } from './OverflowMenuItem';
2
+ export type { OverflowMenuItemProps } from './OverflowMenuItem';
@@ -0,0 +1,6 @@
1
+ import { GenesisTheme } from '../../styles/theme/genesis-theme.types';
2
+ interface StyledOverflowMenuItemProperties {
3
+ theme?: GenesisTheme;
4
+ }
5
+ export declare const OverflowMenuItem: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledOverflowMenuItemProperties>> & string;
6
+ export {};
@@ -41,6 +41,8 @@ export { default as Notification } from './Notification';
41
41
  export type { NotificationProps } from './Notification';
42
42
  export { default as OverflowMenu } from './OverflowMenu';
43
43
  export type { OverflowMenuProps } from './OverflowMenu';
44
+ export { default as OverflowMenuItem } from './OverflowMenuItem';
45
+ export type { OverflowMenuItemProps } from './OverflowMenuItem';
44
46
  export { default as Popover } from './Popover';
45
47
  export type { PopoverProps } from './Popover';
46
48
  export { default as Progress } from './Progress';
package/dist/index.cjs CHANGED
@@ -80499,15 +80499,34 @@ const OverflowMenuContainer = styled.div`
80499
80499
  contain: layout style paint;
80500
80500
  isolation: isolate;
80501
80501
  `;
80502
+ const OverflowMenuItem$1 = styled.div`
80503
+ padding: 8px 12px;
80504
+ cursor: pointer;
80505
+ background-color: ${({ theme }) => theme.colors.surface.default?.backgroundColor || "#ffffff"};
80506
+
80507
+ &:hover {
80508
+ background-color: ${({ theme }) => theme.colors.surface.hover?.backgroundColor || "#F4F4F4"};
80509
+ }
80510
+
80511
+ &:active {
80512
+ background-color: ${({ theme }) => theme.colors.surface.active?.backgroundColor || "#E0E0E0"};
80513
+ }
80514
+ `;
80515
+ const OverflowMenuItem = ({ children: children2, onClick }) => {
80516
+ return /* @__PURE__ */ jsxRuntime.jsx(OverflowMenuItem$1, { onClick, children: children2 });
80517
+ };
80502
80518
  const OverflowMenu = ({
80519
+ items,
80503
80520
  children: children2,
80504
80521
  trigger,
80505
80522
  isOpen: controlledIsOpen,
80506
80523
  onOpenChange,
80507
80524
  placement = "bottom",
80525
+ alignment = "left",
80508
80526
  offset: offset2 = 8,
80509
80527
  className,
80510
- style: style2
80528
+ style: style2,
80529
+ onItemClick
80511
80530
  }) => {
80512
80531
  const [internalIsOpen, setInternalIsOpen] = React.useState(false);
80513
80532
  const [isAnimating, setIsAnimating] = React.useState(false);
@@ -80515,21 +80534,27 @@ const OverflowMenu = ({
80515
80534
  const menuRef = React.useRef(null);
80516
80535
  const { theme } = useGenesis();
80517
80536
  const isOpen = controlledIsOpen === void 0 ? internalIsOpen : controlledIsOpen;
80518
- const handleOpenChange = (open) => {
80519
- if (onOpenChange) {
80520
- onOpenChange(open);
80521
- } else {
80522
- setInternalIsOpen(open);
80523
- }
80524
- };
80537
+ const handleOpenChange = React.useCallback(
80538
+ (open) => {
80539
+ if (onOpenChange) {
80540
+ onOpenChange(open);
80541
+ } else {
80542
+ setInternalIsOpen(open);
80543
+ }
80544
+ },
80545
+ [onOpenChange]
80546
+ );
80525
80547
  const handleTriggerClick = () => {
80526
80548
  handleOpenChange(!isOpen);
80527
80549
  };
80528
- const handleClickOutside = (event) => {
80529
- if (triggerRef.current && menuRef.current && !triggerRef.current.contains(event.target) && !menuRef.current.contains(event.target)) {
80530
- handleOpenChange(false);
80531
- }
80532
- };
80550
+ const handleClickOutside = React.useCallback(
80551
+ (event) => {
80552
+ if (triggerRef.current && menuRef.current && !triggerRef.current.contains(event.target) && !menuRef.current.contains(event.target)) {
80553
+ handleOpenChange(false);
80554
+ }
80555
+ },
80556
+ [handleOpenChange]
80557
+ );
80533
80558
  React.useEffect(() => {
80534
80559
  if (isOpen) {
80535
80560
  const timer2 = setTimeout(() => {
@@ -80544,8 +80569,8 @@ const OverflowMenu = ({
80544
80569
  setIsAnimating(false);
80545
80570
  document.removeEventListener("mousedown", handleClickOutside);
80546
80571
  }
80547
- }, [isOpen]);
80548
- const getMenuStyle = () => {
80572
+ }, [isOpen, handleClickOutside]);
80573
+ const getMenuStyle = React.useMemo(() => {
80549
80574
  const baseStyle = {
80550
80575
  position: "absolute",
80551
80576
  zIndex: 1e3,
@@ -80556,37 +80581,68 @@ const OverflowMenu = ({
80556
80581
  return {
80557
80582
  ...baseStyle,
80558
80583
  top: `calc(100% + ${offset2}px)`,
80559
- left: 0,
80560
- right: 0
80584
+ ...alignment === "right" ? { right: 0 } : { left: 0 }
80561
80585
  };
80562
80586
  }
80563
80587
  case "top": {
80564
80588
  return {
80565
80589
  ...baseStyle,
80566
80590
  bottom: `calc(100% + ${offset2}px)`,
80567
- left: 0,
80568
- right: 0
80591
+ ...alignment === "right" ? { right: 0 } : { left: 0 }
80569
80592
  };
80570
80593
  }
80571
80594
  case "left": {
80572
80595
  return {
80573
80596
  ...baseStyle,
80574
80597
  top: 0,
80575
- right: `calc(100% + ${offset2}px)`
80598
+ right: `calc(100% + ${offset2}px)`,
80599
+ ...alignment === "right" ? { bottom: 0 } : {}
80576
80600
  };
80577
80601
  }
80578
80602
  case "right": {
80579
80603
  return {
80580
80604
  ...baseStyle,
80581
80605
  top: 0,
80582
- left: `calc(100% + ${offset2}px)`
80606
+ left: `calc(100% + ${offset2}px)`,
80607
+ ...alignment === "right" ? { bottom: 0 } : {}
80583
80608
  };
80584
80609
  }
80585
80610
  default: {
80586
80611
  return baseStyle;
80587
80612
  }
80588
80613
  }
80589
- };
80614
+ }, [placement, alignment, offset2, style2]);
80615
+ const handleItemClick = React.useCallback(
80616
+ (item) => {
80617
+ onItemClick?.(item);
80618
+ handleOpenChange(false);
80619
+ },
80620
+ [onItemClick, handleOpenChange]
80621
+ );
80622
+ if (items && items.length > 0) {
80623
+ return /* @__PURE__ */ jsxRuntime.jsxs(OverflowMenuWrapper, { children: [
80624
+ /* @__PURE__ */ jsxRuntime.jsx("div", { ref: triggerRef, onClick: handleTriggerClick, children: trigger }),
80625
+ isOpen && /* @__PURE__ */ jsxRuntime.jsx(
80626
+ OverflowMenuContainer,
80627
+ {
80628
+ ref: menuRef,
80629
+ theme,
80630
+ className,
80631
+ style: getMenuStyle,
80632
+ $isAnimating: isAnimating,
80633
+ $placement: placement,
80634
+ children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
80635
+ OverflowMenuItem,
80636
+ {
80637
+ ...item,
80638
+ onClick: () => handleItemClick(item)
80639
+ },
80640
+ item.id
80641
+ ))
80642
+ }
80643
+ )
80644
+ ] });
80645
+ }
80590
80646
  return /* @__PURE__ */ jsxRuntime.jsxs(OverflowMenuWrapper, { children: [
80591
80647
  /* @__PURE__ */ jsxRuntime.jsx("div", { ref: triggerRef, onClick: handleTriggerClick, children: trigger }),
80592
80648
  isOpen && /* @__PURE__ */ jsxRuntime.jsx(
@@ -80595,7 +80651,7 @@ const OverflowMenu = ({
80595
80651
  ref: menuRef,
80596
80652
  theme,
80597
80653
  className,
80598
- style: getMenuStyle(),
80654
+ style: getMenuStyle,
80599
80655
  $isAnimating: isAnimating,
80600
80656
  $placement: placement,
80601
80657
  children: children2
@@ -85075,6 +85131,7 @@ exports.LineChart = LineChart;
85075
85131
  exports.Message = Message;
85076
85132
  exports.Notification = Notification;
85077
85133
  exports.OverflowMenu = OverflowMenu;
85134
+ exports.OverflowMenuItem = OverflowMenuItem;
85078
85135
  exports.Popover = Popover;
85079
85136
  exports.Progress = Progress;
85080
85137
  exports.RadioGroup = RadioGroup;
package/dist/index.js CHANGED
@@ -80481,15 +80481,34 @@ const OverflowMenuContainer = styled.div`
80481
80481
  contain: layout style paint;
80482
80482
  isolation: isolate;
80483
80483
  `;
80484
+ const OverflowMenuItem$1 = styled.div`
80485
+ padding: 8px 12px;
80486
+ cursor: pointer;
80487
+ background-color: ${({ theme }) => theme.colors.surface.default?.backgroundColor || "#ffffff"};
80488
+
80489
+ &:hover {
80490
+ background-color: ${({ theme }) => theme.colors.surface.hover?.backgroundColor || "#F4F4F4"};
80491
+ }
80492
+
80493
+ &:active {
80494
+ background-color: ${({ theme }) => theme.colors.surface.active?.backgroundColor || "#E0E0E0"};
80495
+ }
80496
+ `;
80497
+ const OverflowMenuItem = ({ children: children2, onClick }) => {
80498
+ return /* @__PURE__ */ jsx(OverflowMenuItem$1, { onClick, children: children2 });
80499
+ };
80484
80500
  const OverflowMenu = ({
80501
+ items,
80485
80502
  children: children2,
80486
80503
  trigger,
80487
80504
  isOpen: controlledIsOpen,
80488
80505
  onOpenChange,
80489
80506
  placement = "bottom",
80507
+ alignment = "left",
80490
80508
  offset: offset2 = 8,
80491
80509
  className,
80492
- style: style2
80510
+ style: style2,
80511
+ onItemClick
80493
80512
  }) => {
80494
80513
  const [internalIsOpen, setInternalIsOpen] = useState(false);
80495
80514
  const [isAnimating, setIsAnimating] = useState(false);
@@ -80497,21 +80516,27 @@ const OverflowMenu = ({
80497
80516
  const menuRef = useRef(null);
80498
80517
  const { theme } = useGenesis();
80499
80518
  const isOpen = controlledIsOpen === void 0 ? internalIsOpen : controlledIsOpen;
80500
- const handleOpenChange = (open) => {
80501
- if (onOpenChange) {
80502
- onOpenChange(open);
80503
- } else {
80504
- setInternalIsOpen(open);
80505
- }
80506
- };
80519
+ const handleOpenChange = useCallback(
80520
+ (open) => {
80521
+ if (onOpenChange) {
80522
+ onOpenChange(open);
80523
+ } else {
80524
+ setInternalIsOpen(open);
80525
+ }
80526
+ },
80527
+ [onOpenChange]
80528
+ );
80507
80529
  const handleTriggerClick = () => {
80508
80530
  handleOpenChange(!isOpen);
80509
80531
  };
80510
- const handleClickOutside = (event) => {
80511
- if (triggerRef.current && menuRef.current && !triggerRef.current.contains(event.target) && !menuRef.current.contains(event.target)) {
80512
- handleOpenChange(false);
80513
- }
80514
- };
80532
+ const handleClickOutside = useCallback(
80533
+ (event) => {
80534
+ if (triggerRef.current && menuRef.current && !triggerRef.current.contains(event.target) && !menuRef.current.contains(event.target)) {
80535
+ handleOpenChange(false);
80536
+ }
80537
+ },
80538
+ [handleOpenChange]
80539
+ );
80515
80540
  useEffect(() => {
80516
80541
  if (isOpen) {
80517
80542
  const timer2 = setTimeout(() => {
@@ -80526,8 +80551,8 @@ const OverflowMenu = ({
80526
80551
  setIsAnimating(false);
80527
80552
  document.removeEventListener("mousedown", handleClickOutside);
80528
80553
  }
80529
- }, [isOpen]);
80530
- const getMenuStyle = () => {
80554
+ }, [isOpen, handleClickOutside]);
80555
+ const getMenuStyle = useMemo$1(() => {
80531
80556
  const baseStyle = {
80532
80557
  position: "absolute",
80533
80558
  zIndex: 1e3,
@@ -80538,37 +80563,68 @@ const OverflowMenu = ({
80538
80563
  return {
80539
80564
  ...baseStyle,
80540
80565
  top: `calc(100% + ${offset2}px)`,
80541
- left: 0,
80542
- right: 0
80566
+ ...alignment === "right" ? { right: 0 } : { left: 0 }
80543
80567
  };
80544
80568
  }
80545
80569
  case "top": {
80546
80570
  return {
80547
80571
  ...baseStyle,
80548
80572
  bottom: `calc(100% + ${offset2}px)`,
80549
- left: 0,
80550
- right: 0
80573
+ ...alignment === "right" ? { right: 0 } : { left: 0 }
80551
80574
  };
80552
80575
  }
80553
80576
  case "left": {
80554
80577
  return {
80555
80578
  ...baseStyle,
80556
80579
  top: 0,
80557
- right: `calc(100% + ${offset2}px)`
80580
+ right: `calc(100% + ${offset2}px)`,
80581
+ ...alignment === "right" ? { bottom: 0 } : {}
80558
80582
  };
80559
80583
  }
80560
80584
  case "right": {
80561
80585
  return {
80562
80586
  ...baseStyle,
80563
80587
  top: 0,
80564
- left: `calc(100% + ${offset2}px)`
80588
+ left: `calc(100% + ${offset2}px)`,
80589
+ ...alignment === "right" ? { bottom: 0 } : {}
80565
80590
  };
80566
80591
  }
80567
80592
  default: {
80568
80593
  return baseStyle;
80569
80594
  }
80570
80595
  }
80571
- };
80596
+ }, [placement, alignment, offset2, style2]);
80597
+ const handleItemClick = useCallback(
80598
+ (item) => {
80599
+ onItemClick?.(item);
80600
+ handleOpenChange(false);
80601
+ },
80602
+ [onItemClick, handleOpenChange]
80603
+ );
80604
+ if (items && items.length > 0) {
80605
+ return /* @__PURE__ */ jsxs(OverflowMenuWrapper, { children: [
80606
+ /* @__PURE__ */ jsx("div", { ref: triggerRef, onClick: handleTriggerClick, children: trigger }),
80607
+ isOpen && /* @__PURE__ */ jsx(
80608
+ OverflowMenuContainer,
80609
+ {
80610
+ ref: menuRef,
80611
+ theme,
80612
+ className,
80613
+ style: getMenuStyle,
80614
+ $isAnimating: isAnimating,
80615
+ $placement: placement,
80616
+ children: items.map((item) => /* @__PURE__ */ jsx(
80617
+ OverflowMenuItem,
80618
+ {
80619
+ ...item,
80620
+ onClick: () => handleItemClick(item)
80621
+ },
80622
+ item.id
80623
+ ))
80624
+ }
80625
+ )
80626
+ ] });
80627
+ }
80572
80628
  return /* @__PURE__ */ jsxs(OverflowMenuWrapper, { children: [
80573
80629
  /* @__PURE__ */ jsx("div", { ref: triggerRef, onClick: handleTriggerClick, children: trigger }),
80574
80630
  isOpen && /* @__PURE__ */ jsx(
@@ -80577,7 +80633,7 @@ const OverflowMenu = ({
80577
80633
  ref: menuRef,
80578
80634
  theme,
80579
80635
  className,
80580
- style: getMenuStyle(),
80636
+ style: getMenuStyle,
80581
80637
  $isAnimating: isAnimating,
80582
80638
  $placement: placement,
80583
80639
  children: children2
@@ -85058,6 +85114,7 @@ export {
85058
85114
  Message,
85059
85115
  Notification,
85060
85116
  OverflowMenu,
85117
+ OverflowMenuItem,
85061
85118
  Popover,
85062
85119
  Progress,
85063
85120
  RadioGroup,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobolt/genesis",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "genesis design system",
5
5
  "author": "gobolt",
6
6
  "license": "MIT",