// // Copyright 2023 DXOS.org // import { CaretDown, CaretRight } from '@phosphor-icons/react'; import { Slot } from '@radix-ui/react-slot'; import React, { type ComponentPropsWithoutRef, type FC, forwardRef, type ForwardRefExoticComponent } from 'react'; import { List as ListPrimitive, type ListProps as ListPrimitiveProps, type ListScopedProps, ListItemHeading as ListPrimitiveItemHeading, type ListItemHeadingProps as ListPrimitiveItemHeadingProps, ListItemOpenTrigger as ListPrimitiveItemOpenTrigger, type ListItemOpenTriggerProps as ListPrimitiveItemOpenTriggerProps, ListItemCollapsibleContent, type ListItemCollapsibleContentProps, ListItem as ListPrimitiveItem, type ListItemProps as ListPrimitiveItemProps, type ListItemScopedProps, LIST_NAME, LIST_ITEM_NAME, useListContext, useListItemContext, } from '@dxos/react-list'; import { type Density } from '@dxos/react-ui-types'; import { ListDropIndicator } from './ListDropIndicator'; import { useDensityContext, useThemeContext } from '../../hooks'; import { type ThemedClassName } from '../../util'; import { DensityProvider } from '../DensityProvider'; type ListProps = ThemedClassName & { density?: Density }; const List = forwardRef(({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); const density = useDensityContext(props.density); return ( {children} ); }); type ListItemEndcapProps = ThemedClassName> & { asChild?: boolean }; const ListItemEndcap = forwardRef( ({ children, classNames, asChild, ...props }, forwardedRef) => { const Root = asChild ? Slot : 'div'; const density = useDensityContext(); const { tx } = useThemeContext(); return ( {children} ); }, ); const MockListItemOpenTrigger = ({ classNames, ...props }: ThemedClassName, 'children'>>) => { const density = useDensityContext(); const { tx } = useThemeContext(); return (
); }; type ListItemHeadingProps = ThemedClassName; const ListItemHeading = forwardRef( ({ children, classNames, ...props }, forwardedRef) => { const { tx } = useThemeContext(); const density = useDensityContext(); return ( {children} ); }, ); type ListItemOpenTriggerProps = ThemedClassName; const ListItemOpenTrigger = forwardRef( ({ __listItemScope, classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); const density = useDensityContext(); const { open } = useListItemContext(LIST_ITEM_NAME, __listItemScope); const Icon = open ? CaretDown : CaretRight; return ( {children || ( )} ); }, ); type ListItemRootProps = ThemedClassName; const ListItemRoot = forwardRef( ({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); const density = useDensityContext(); return ( {children} ); }, ); export const ListItem: { Root: ForwardRefExoticComponent; Endcap: ForwardRefExoticComponent; Heading: ForwardRefExoticComponent; OpenTrigger: ForwardRefExoticComponent; CollapsibleContent: ForwardRefExoticComponent; MockOpenTrigger: FC, 'children'>>>; DropIndicator: typeof ListDropIndicator; } = { Root: ListItemRoot, Endcap: ListItemEndcap, Heading: ListItemHeading, OpenTrigger: ListItemOpenTrigger, CollapsibleContent: ListItemCollapsibleContent, MockOpenTrigger: MockListItemOpenTrigger, DropIndicator: ListDropIndicator, }; export { List, useListContext, useListItemContext, LIST_NAME, LIST_ITEM_NAME }; export type { ListProps, ListScopedProps, ListItemRootProps, ListItemScopedProps, ListItemEndcapProps, ListItemHeadingProps, ListItemOpenTriggerProps, ListItemCollapsibleContentProps, };