'use client' import { forwardRef, useMemo } from 'react' import * as React from 'react' import { ChevronSmallDownIcon, ChevronSmallRightIcon, isBezierIcon, } from '@channel.io/bezier-icons' import classNames from 'classnames' import { createContext } from '~/src/utils/react' import { isEmpty, isNil } from '~/src/utils/type' import { BaseButton } from '~/src/components/BaseButton' import { Icon } from '~/src/components/Icon' import { Text } from '~/src/components/Text' import { type OutlineItemContextProps, type OutlineItemProps, } from './OutlineItem.types' import styles from './OutlineItem.module.scss' const [OutlineItemContextProvider, useOutlineItemContext] = createContext< OutlineItemContextProps | undefined >(undefined) const DEFAULT_INDENT = 16 export const OUTLINE_ITEM_TEST_ID = 'bezier-outline-item' export const OutlineItem = forwardRef( function OutlineItem( { children, style, className, as, open = false, disableChevron = false, active = false, focused = false, clickable: clickableProp = false, leftContent, content, rightContent, href, onClick, ...rest }, forwardedRef ) { const context = useOutlineItemContext() const isRoot = isNil(context) const indent = isRoot ? 0 : context.indent + DEFAULT_INDENT const isLink = !isEmpty(href) const isButton = !isNil(onClick) const Comp = isLink ? 'a' : isButton ? BaseButton : ((as ?? 'div') as 'div') const clickable = isLink || clickableProp || isButton return ( <> {!disableChevron && (
{!isNil(children) && ( )}
)} {leftContent && (
{isBezierIcon(leftContent) ? ( ) : ( leftContent )}
)} {content} {rightContent}
({ indent }), [indent])} > {open && children} ) } )