'use client'; import { Autocomplete, OverlayTriggerStateContext, Provider, Dialog as RACDialog, DialogProps as RACDialogProps, Tab as RACTab, TabList as RACTabList, TabPanel as RACTabPanel, TabPanelProps as RACTabPanelProps, TabProps as RACTabProps, Tabs as RACTabs, SelectionIndicator, TabRenderProps } from 'react-aria-components'; import {baseColor, focusRing, style} from '@react-spectrum/s2/style' with {type: 'macro'}; import {CloseButton, SearchField, TextContext} from '@react-spectrum/s2'; import {ColorSearchSkeleton} from './colorSearchData'; import {ComponentCardView} from './ComponentCardView'; import { getResourceTags, LazyColorSearchView, LazyIconSearchView, SearchEmptyState, useFilteredColors, useSearchMenuState } from './searchUtils'; import {IconSearchSkeleton, useIconFilter} from './IconSearchView'; import {type Library} from './constants'; import React, { cloneElement, CSSProperties, ReactElement, ReactNode, Suspense, useContext, useEffect, useRef, useState } from 'react'; import {SearchTagGroups} from './SearchTagGroups'; import {TypographySearchView} from './TypographySearchView'; import {useId} from '@react-aria/utils'; import {useRouter} from './Router'; interface MobileDialogProps extends Omit { size?: 'S' | 'M' | 'L' | 'fullscreen' | 'fullscreenTakeover'; isDismissible?: boolean; isKeyboardDismissDisabled?: boolean; padding?: 'default' | 'none'; } const dialogStyle = style({ padding: { padding: { default: { default: 24, sm: 32 }, none: 0 } }, boxSizing: 'border-box', outlineStyle: 'none', borderRadius: 'inherit', overflow: 'auto', position: 'relative', size: 'full', maxSize: 'inherit' }); // Mobile tabs styles - horizontal layout with scrolling const mobileTabsWrapper = style({ height: 'full', position: 'relative', display: 'flex', flexDirection: 'column', font: 'ui', backgroundColor: 'layer-1' }); const mobileTabListContainer = style({ flexShrink: 0 }); const mobileTabListWrapper = style({ position: 'relative', display: 'flex', alignItems: 'center', gap: 8 }); const mobileTabList = style({ display: { default: 'flex', '::-webkit-scrollbar': 'none' }, flexDirection: 'row', gap: 8, paddingX: 12, paddingY: 8, overflow: 'auto', flexGrow: 1, scrollbarWidth: 'none' }); const mobileTab = style({ ...focusRing(), display: 'flex', gap: 8, color: { default: baseColor('neutral-subdued'), isSelected: baseColor('neutral'), forcedColors: { isSelected: 'Highlight' } }, borderRadius: 'sm', paddingX: 8, paddingY: 8, alignItems: 'center', position: 'relative', cursor: 'default', flexShrink: 0, transition: 'default', disableTapHighlight: true, whiteSpace: 'nowrap', fontSize: 'body', fontWeight: 'bold' }); const mobileSelectionIndicator = style({ position: 'absolute', left: 0, bottom: 0, width: 'full', height: 2, backgroundColor: { default: 'neutral', forcedColors: 'Highlight' }, borderStyle: 'none', borderRadius: 'full', transition: '[translate, width, height]' }); const mobileTabPanel = style({ ...focusRing(), flexGrow: 1, minHeight: 0, display: 'flex', flexDirection: 'column', outlineStyle: 'none' }); const stickySearchContainer = style({ width: 'full', display: 'flex', flexDirection: 'column', gap: 8, paddingTop: 8, flexShrink: 0, overflow: 'auto' }); function MobileTab(props: Omit & {children: ReactNode}) { let contentId = useId(); return ( mobileTab(renderProps)}> {props.children} ); } interface MobileTabListProps { children: ReactNode; } function MobileTabList({children}: MobileTabListProps) { return (
{children}
{}} />
); } function MobileTabPanel(props: Omit & {children: ReactNode}) { return ( {props.children} ); } export function MobileSearchMenu({initialTag}: {initialTag?: string}) { return ( ); } const MobileCustomDialog = function MobileCustomDialog(props: MobileDialogProps) { let {padding = 'default'} = props; return ( {props.children} ); }; function MobileNav({initialTag}: {initialTag?: string}) { let {pages, currentPage} = useRouter(); let overlayTriggerState = useContext(OverlayTriggerStateContext); let [searchFocused, setSearchFocused] = useState(false); let iconFilter = useIconFilter(); let isOpen = !!overlayTriggerState?.isOpen; const { selectedLibrary, setSelectedLibrary, orderedLibraries: libraries, searchValue, setSearchValue, sectionTagsForDisplay: sectionTags, selectedTagId: selectedSection, setSelectedTagId: setSelectedSection, handleTagSelectionChange, filteredIcons, isIconsSelected, selectedItems, getPlaceholderText } = useSearchMenuState({ pages, currentPage, initialTag, isOpen }); const filteredColors = useFilteredColors(searchValue); const isColorsSelected = selectedSection === 'colors'; const isTypographySelected = selectedSection === 'typography'; let handleSearchFocus = () => { setSearchFocused(true); }; let handleSearchBlur = () => { if (searchValue === '') { setSearchFocused(false); } }; let handleSearchChange = (value: string) => { setSearchValue(value); if (value === '' && !searchFocused) { setSearchFocused(false); } }; // Delay closing until the page updates (or the skeleton shows). let lastPage = useRef(currentPage); useEffect(() => { if (currentPage !== lastPage.current && overlayTriggerState?.isOpen) { overlayTriggerState?.close(); } lastPage.current = currentPage; }, [currentPage, overlayTriggerState]); // Wait to update selection until after close animation. let [currentUrl, setCurrentUrl] = useState(currentPage.url); if (currentPage.url !== currentUrl && !isOpen) { setCurrentUrl(currentPage.url); } return (
{ let newLib = key as Library; setSelectedLibrary(newLib); if (!searchFocused) { setSelectedSection('components'); } }}>
{libraries.map((library, i) => (
{cloneElement(library.icon as ReactElement, {styles: style({size: 20})})}
{library.label}
))}
{libraries.map(library => { const libraryResourceTags = getResourceTags(library.id); const placeholderText = getPlaceholderText(library.label); const showIcons = isIconsSelected && library.id === 'react-spectrum'; return (
{showIcons && ( }> )} {!showIcons && isColorsSelected && library.id === 'react-spectrum' && ( }> )} {!showIcons && isTypographySelected && library.id === 'react-spectrum' && ( )} {!showIcons && !isColorsSelected && !isTypographySelected && ( { if (key === currentPage.url) { overlayTriggerState?.close(); } }} items={library.id === selectedLibrary ? selectedItems : []} ariaLabel="Pages" size="S" renderEmptyState={() => ( )} /> )}
); })}
); }