import cn from 'classnames'; import { MouseEventHandler, ReactNode, RefObject, useMemo } from 'react'; import { ButtonFunction, ButtonFunctionProps } from '@snack-uikit/button'; import { ChipToggle } from '@snack-uikit/chips'; import { Scroll } from '@snack-uikit/scroll'; import { SegmentedControl, SegmentedControlProps } from '@snack-uikit/segmented-control'; import { SkeletonContextProvider, WithSkeleton } from '@snack-uikit/skeleton'; import { TooltipProps } from '@snack-uikit/tooltip'; import { TruncateString } from '@snack-uikit/truncate-string'; import { Typography } from '@snack-uikit/typography'; import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils'; import { NotificationCardSkeleton } from '../NotificationCard/components'; import { NotificationCardStack, NotificationCardStackProps, NotificationPanelBlank, NotificationPanelBlankProps, NotificationPanelGroup, NotificationPanelGroupProps, NotificationPanelSettings, NotificationPanelSettingsProps, } from './components'; import { NotificationPanelDivider, NotificationPanelDividerProps } from './components/NotificationPanelDivider'; import { TEST_IDS } from './constants'; import { WithTooltip } from './helperComponents'; import styles from './styles.module.scss'; export type { NotificationPanelBlankProps }; export type NotificationPanelProps = WithSupportProps<{ /** Заголовок панели */ title: string; /** Кнопка настроек и выпадающий список */ settings?: NotificationPanelSettingsProps; /** Сегменты для фильтрации */ segments?: Omit; /** Переключатель для фильтрации */ chipToggle?: { label: string; checked: boolean; defaultChecked?: boolean; onChange(checked: boolean): void; }; /** Кнопка в "шапке" панели */ readAllButton?: Omit & { tooltip?: TooltipProps; }; /** Кнопка внизу панели */ footerButton?: { label: string; onClick: MouseEventHandler; }; className?: string; /** Состояние загрузки */ loading?: boolean; /** Контент для отрисовки (e.g NotificationCard | NotificationPanel.Blank) */ content?: ReactNode; /** Количество скелетонов карточек для отображения при загрузке */ skeletonsAmount?: number; /** Ссылка на элемент, обозначающий самый конец прокручиваемого списка */ scrollEndRef?: RefObject; /** Ссылка на контейнер, который скроллится */ scrollContainerRef?: RefObject; }>; /** Компонент панели для уведомлений */ export function NotificationPanel({ title, settings, segments, readAllButton, footerButton, content, loading, skeletonsAmount = 2, scrollEndRef, scrollContainerRef, className, chipToggle, ...rest }: NotificationPanelProps) { const skeletons = useMemo(() => Array.from({ length: skeletonsAmount }, (_, i) => i), [skeletonsAmount]); return (
{readAllButton && ( )} {settings && }
{segments && ( ({ ...item, disabled: item.disabled || loading, }))} data-test-id={TEST_IDS.segments} /> )} {chipToggle && ( )}
{content} {loading && ( {skeletons.map(skeleton => ( } /> ))} )}
{footerButton && ( )}
); } export namespace NotificationPanel { export const Blank: typeof NotificationPanelBlank = NotificationPanelBlank; export type BlankProps = NotificationPanelBlankProps; export const Divider: typeof NotificationPanelDivider = NotificationPanelDivider; export type DividerProps = NotificationPanelDividerProps; export const Stack: typeof NotificationCardStack = NotificationCardStack; export type StackProps = NotificationCardStackProps; export const Group: typeof NotificationPanelGroup = NotificationPanelGroup; export type GroupProps = NotificationPanelGroupProps; }