import React from "react"; import { MaterialIcon } from "@shared/components/material-icon"; import { Button } from "@shared/contentful/blocks/button"; import { ButtonProps as ContentfulButtonProps } from "@shared/contentful/blocks/button/types"; type ComponentButtonGroup = { anchorId?: string | null; title?: string | null; items?: { items?: ContentfulButtonProps[] | null } | null; }; type Link = ContentfulButtonProps | ComponentButtonGroup; type LinkGroupsProps = { link?: Link; }; const isButton = (link: Link): link is ContentfulButtonProps => { // If your group never has `href`, this is a simple and effective guard return typeof (link as ContentfulButtonProps).href === "string"; }; export const MobileLinkGroups: React.FC = ({ link }) => { const [isOpen, setIsOpen] = React.useState(false); if (!link) return null; // Single button if (isButton(link)) { return ( {isOpen && subMenu.length > 0 && } ); }; const RenderSubMenu: React.FC<{ items: ContentfulButtonProps[] }> = ({ items, }) => ( );