MCPcopy
hub / github.com/janhq/jan / DropDrawerSub

Function DropDrawerSub

web-app/src/components/ui/dropdrawer.tsx:690–785  ·  view source on GitHub ↗
({
  children,
  id,
  ...props
}: React.ComponentProps<typeof DropdownMenuSub> & {
  id?: string;
})

Source from the content-addressed store, hash-verified

688let submenuIdCounter = 0;
689
690function DropDrawerSub({
691 children,
692 id,
693 ...props
694}: React.ComponentProps<typeof DropdownMenuSub> & {
695 id?: string;
696}) {
697 const { isMobile } = useDropDrawerContext();
698 const { registerSubmenuContent } = React.useContext(SubmenuContext);
699
700 // Generate a simple numeric ID instead of using React.useId()
701 const [generatedId] = React.useState(() => `submenu-${submenuIdCounter++}`);
702 const submenuId = id || generatedId;
703
704 // Extract submenu content to register with parent
705 React.useEffect(() => {
706 if (!registerSubmenuContent) return;
707
708 // Find the SubContent within this Sub
709 const contentItems: React.ReactNode[] = [];
710 React.Children.forEach(children, (child) => {
711 if (React.isValidElement(child) && child.type === DropDrawerSubContent) {
712 // Add all children of the SubContent to the result
713 React.Children.forEach(
714 (child.props as { children?: React.ReactNode }).children,
715 (contentChild) => {
716 contentItems.push(contentChild);
717 },
718 );
719 }
720 });
721
722 // Register the content with the parent
723 if (contentItems.length > 0) {
724 registerSubmenuContent(submenuId, contentItems);
725 }
726 }, [children, registerSubmenuContent, submenuId]);
727
728 if (isMobile) {
729 // For mobile, we'll use the context to manage submenu state
730 // Process children to pass the submenu ID to the trigger and content
731 const processedChildren = React.Children.map(children, (child) => {
732 if (!React.isValidElement(child)) return child;
733
734 if (child.type === DropDrawerSubTrigger) {
735 return React.cloneElement(
736 child as React.ReactElement,
737 {
738 ...(child.props as object),
739 "data-parent-submenu-id": submenuId,
740 "data-submenu-id": submenuId,
741 // Use only data attributes, not custom props
742 "data-parent-submenu": submenuId,
743 } as React.HTMLAttributes<HTMLElement>,
744 );
745 }
746
747 if (child.type === DropDrawerSubContent) {

Callers

nothing calls this directly

Calls 4

useDropDrawerContextFunction · 0.85
forEachMethod · 0.45
pushMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected