Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/components/data-grid/headings.tsx
Views: 687
import Draggable from "react-draggable";1import { CSSProperties, ReactNode, useRef, useState } from "react";2import { Icon } from "@cocalc/frontend/components";34export type SortDirection = "ascending" | "descending";5export function nextSortState(direction?: SortDirection | null) {6if (direction == "descending") {7return "ascending";8} else if (direction == "ascending") {9return null;10} else {11return "descending";12}13}1415const DIRECTION_STYLE = {16float: "right",17marginTop: "2.5px",18cursor: "pointer",19} as CSSProperties;2021export function ColumnHeading({22width = 150,23title,24direction,25onSortClick,26setWidth,27}: {28width?: number;29title?: ReactNode;30direction?: SortDirection;31onSortClick?: () => void;32setWidth?: (number) => void;33}) {34const ignoreClickRef = useRef<boolean>(false);35return (36<th37style={{38cursor: "pointer",39color: "#428bca",40background: "rgb(250, 250, 250)",41padding: "10px 5px",42border: "1px solid #eee",43position: "relative",44}}45>46<div47style={{ width: width ?? 150 }}48onClick={49onSortClick50? () => {51if (ignoreClickRef.current) {52ignoreClickRef.current = false;53return;54}55onSortClick();56}57: undefined58}59>60{title ? title : <> </>}61{direction && (62<Icon63style={DIRECTION_STYLE}64name={direction == "ascending" ? "caret-down" : "caret-up"}65/>66)}67{setWidth && (68<ResizeHandle69setWidth={setWidth}70width={width}71ignoreClick={() => {72ignoreClickRef.current = true;73}}74/>75)}76</div>77</th>78);79}8081function ResizeHandle({ setWidth, width, ignoreClick }) {82const [pos, setPos] = useState<any>(undefined);83return (84<Draggable85onMouseDown={ignoreClick}86position={pos}87axis="x"88onStop={() => {89setPos({ x: 0, y: 0 });90}}91onDrag={(_, data) => {92setPos({ x: 0, y: 0 });93ignoreClick();94setWidth(width + data.deltaX);95}}96>97<span className="cocalc-data-grid-column-resizer"></span>98</Draggable>99);100}101102103