import React from "react"; import { observer } from "mobx-react"; import classNames from "classnames"; import { Icon } from "eez-studio-ui/icon"; export interface IListNode { id: string; label?: React.ReactNode; data: T; selected: boolean; } export const ListItem = observer( class ListItem extends React.Component< { leftIcon?: React.ReactNode; leftIconSize?: number; leftIconClassName?: string; label: React.ReactNode; rightIcon?: React.ReactNode; rightIconSize?: number; rightIconClassName?: string; }, {} > { render() { let leftIcon; if (this.props.leftIcon) { if (typeof this.props.leftIcon == "string") { leftIcon = ( ); } else { leftIcon = this.props.leftIcon; } } let rightIcon; if (this.props.rightIcon) { if (typeof this.props.rightIcon == "string") { rightIcon = ( ); } else { rightIcon = this.props.rightIcon; } } return ( <>
{leftIcon}
{this.props.label}
{rightIcon &&
{rightIcon}
} ); } } ); export const List = observer( class List extends React.Component< { nodes: IListNode[]; selectNode?: (node: IListNode) => void; renderNode?: (node: IListNode) => React.ReactNode; onContextMenu?: (node: IListNode) => void; onDoubleClick?: (node: IListNode) => void; tabIndex?: any; className?: string; style?: React.CSSProperties; }, {} > { render() { const { renderNode, tabIndex } = this.props; let nodes = this.props.nodes.map(node => { let className = classNames("EezStudio_ListItem", { EezStudio_Selected: node.selected }); return (
{ e.preventDefault(); e.stopPropagation(); if (this.props.selectNode) { this.props.selectNode(node); } } : undefined } onDoubleClick={ this.props.onDoubleClick ? (e: any) => { e.preventDefault(); e.stopPropagation(); if (this.props.onDoubleClick) { this.props.onDoubleClick(node); } } : undefined } onContextMenu={ this.props.onContextMenu ? (event: React.MouseEvent) => { event.preventDefault(); event.stopPropagation(); this.props.onContextMenu!(node); } : undefined } > {renderNode ? renderNode(node) : node.label}
); }); let className = classNames( "EezStudio_List", { EezStudio_List_Selectable: !!this.props.selectNode }, this.props.className ); return (
{nodes}
); } } ); export const ListContainer = observer( class ListContainer extends React.Component<{ children?: React.ReactNode; tabIndex: any; minHeight?: number; maxHeight?: number; maxWidth?: number; className?: string; }> { render() { const { minHeight, maxHeight, maxWidth } = this.props; return (
{this.props.children}
); } } );