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/labeled-row.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import React from "react";6import { Row, Col, Descriptions } from "antd";78interface Props {9label_cols?: number;10label?: string | React.ReactNode;11style?: React.CSSProperties;12className?: string;13children: React.ReactNode;14extra?: React.ReactNode;15extra_cols?: number;16innerStyle?: React.CSSProperties;17vertical?: boolean;18}1920export const LabeledRow: React.FC<Props> = ({21children,22style,23label,24className,25label_cols = 4,26extra,27extra_cols = 1,28innerStyle = { marginTop: "8px" },29vertical = false,30}) => {31const spanLabel = 2 * label_cols;32const spanExtra = extra != null ? extra_cols : 0;33const spanChildren = 24 - spanLabel - spanExtra;3435function renderExtra() {36if (extra == null) return;37return (38<Col span={spanExtra} style={{ ...innerStyle, textAlign: "right" }}>39{extra}40</Col>41);42}4344function renderHorizontal() {45return (46<Row style={style} className={className}>47<Col span={spanLabel} style={innerStyle}>48{label}49</Col>50<Col span={spanChildren} style={innerStyle}>51{children}52</Col>53{renderExtra()}54</Row>55);56}5758function renderVertical() {59return (60<Descriptions style={style} layout="vertical" column={1} size={"small"}>61<Descriptions.Item label={label} style={innerStyle}>62{children}63{extra != null ? (64<div style={{ textAlign: "right" }}>{extra}</div>65) : undefined}66</Descriptions.Item>67</Descriptions>68);69}7071return vertical ? renderVertical() : renderHorizontal();72};737475