import React from 'react'; import styled, { css } from 'styled-components'; import { CaretDownIcon } from '@redocly/theme/icons/CaretDownIcon/CaretDownIcon'; import { CaretUpIcon } from '@redocly/theme/icons/CaretUpIcon/CaretUpIcon'; import { useCatalogTableHeaderCellActions } from '@redocly/theme/core/hooks'; import { BaseEntity, CatalogColumn, } from '@redocly/theme/components/Catalog/CatalogTableView/CatalogTableView'; export type CatalogTableHeaderCellProps = { column: CatalogColumn; currentSortOption?: string | null; handleSortClick: (sortKey: string, direction: 'asc' | 'desc') => void; isColumnSorted: (sortKey: string, direction: 'asc' | 'desc') => boolean; }; export const CatalogTableHeaderCell = ({ column, currentSortOption, handleSortClick, isColumnSorted, }: CatalogTableHeaderCellProps) => { const { handleCellClick, sortKey, isUpActive, isDownActive } = useCatalogTableHeaderCellActions({ column, currentSortOption, handleSortClick, isColumnSorted, }); return ( {column.title} {column.sortable && sortKey && ( )} ); }; const TableHeaderCellWrapper = styled.div<{ $sortable: boolean }>` padding: var(--catalog-table-header-cell-padding); border-bottom: 1px solid var(--catalog-table-border-color); ${(props) => props.$sortable && css` cursor: pointer; user-select: none; `} `; const HeaderContent = styled.div` display: flex; align-items: center; width: 100%; `; const SortIndicator = styled.div` display: flex; flex-direction: column; align-items: center; justify-content: center; margin-left: 4px; gap: 2px; color: var(--catalog-table-header-sort-indicator-color); `; const SortArrow = styled.div<{ $isActive: boolean }>` display: flex; align-items: center; justify-content: center; width: 14px; height: 9px; border-radius: 2px; transition: background-color 0.2s ease; svg { display: block; } ${(props) => props.$isActive && css` background-color: var(--catalog-table-header-sort-arrow-bg-active); `} `;