import React, { useState } from "react"; import { filterAttrs } from "@arc-ui/community-utils/filter-attrs"; import styles from "./BusinessSegmentSwitcher.module.css"; import { ContentSwitcher, ContentSwitcherList, ContentSwitcherTab, ContentSwitcherContent, } from "@arc-ui/components/ContentSwitcher"; import { ContentSwitcherDropdown, ContentSwitcherDropdownContent, } from "@arc-ui/components/ContentSwitcherDropdown"; import { InformationCard } from "@arc-ui/components/InformationCard"; import { TypographyCard } from "@arc-ui/components/TypographyCard"; import { renderCard } from "./helpers/renderCard"; import { renderBusinessSegmentSwitcherCarousel } from "./helpers/renderBusinessSegmentSwitcherCarousel"; import { type BentoGridContent } from "./types/types"; /** * BusinessSegmentSwitcher displays tabbed content with a bento grid layout made up of 3 - 4 cards. * Renders as tabs on desktop and a dropdown with carousel on mobile (below 1024px). */ export const BusinessSegmentSwitcher = ({ tabs, defaultValue, ...props }: BusinessSegmentSwitcherProps) => { const initialTab = defaultValue ?? tabs[0]?.value ?? ""; const [selectedTab, setSelectedTab] = useState(initialTab); return (
setSelectedTab(value)} > {tabs.map(({ label, value }, index) => ( ))} {tabs.map(({ value, content, label }, index) => ( ))}
setSelectedTab(value)} > {tabs.map(({ value, content, label }, index) => (
{renderBusinessSegmentSwitcherCarousel({ content, label })}
))}
); }; export interface BusinessSegmentSwitcherProps { /** * Default to an initial value of a tab. If this is left blank it will default to first tab. */ defaultValue?: string; /** * Array of tabs to render. Each tab requires a unique `value`, a `label` for display, and `content` containing card configurations for the bento grid layout. */ tabs: { value: string; label: string; content: BentoGridContent; }[]; }