summaryrefslogtreecommitdiffstats
path: root/packages/excalidraw/components/dropdownMenu/dropdownMenuUtils.ts
blob: 10d91fb856ffbb5e86b802f22cf7a770e54e65d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React from "react";

export const getMenuTriggerComponent = (children: React.ReactNode) => {
  const comp = React.Children.toArray(children).find(
    (child) =>
      React.isValidElement(child) &&
      typeof child.type !== "string" &&
      //@ts-ignore
      child?.type.displayName &&
      //@ts-ignore
      child.type.displayName === "DropdownMenuTrigger",
  );
  if (!comp) {
    return null;
  }
  //@ts-ignore
  return comp;
};

export const getMenuContentComponent = (children: React.ReactNode) => {
  const comp = React.Children.toArray(children).find(
    (child) =>
      React.isValidElement(child) &&
      typeof child.type !== "string" &&
      //@ts-ignore
      child?.type.displayName &&
      //@ts-ignore
      child.type.displayName === "DropdownMenuContent",
  );
  if (!comp) {
    return null;
  }
  //@ts-ignore
  return comp;
};