UNPKG

@jupyterlab/toc

Version:

JupyterLab - Table of Contents widget

47 lines 2.08 kB
// Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. import * as React from 'react'; import { TreeItem } from '@jupyter/react-components'; /** * React component for a table of contents entry. */ export class TableOfContentsItem extends React.PureComponent { /** * Renders a table of contents entry. * * @returns rendered entry */ render() { const { children, isActive, heading, onCollapse, onMouseDown } = this.props; // Handling toggle of collapse and expand const handleToggle = (event) => { // This will toggle the state and call the appropriate collapse or expand function if (!event.defaultPrevented && event.target.expanded !== !heading.collapsed) { event.preventDefault(); onCollapse(heading); } }; return (React.createElement(TreeItem, { className: 'jp-tocItem jp-TreeItem nested', selected: isActive, expanded: !heading.collapsed, onExpand: handleToggle, onMouseDown: (event) => { // React only on deepest item if (!event.defaultPrevented) { event.preventDefault(); onMouseDown(heading); } }, onKeyUp: event => { // React on key up because key down is used for tree view navigation // and therefore key-down on Enter is default prevented to change the // selection state if (!event.defaultPrevented && event.key === 'Enter' && !isActive) { event.preventDefault(); onMouseDown(heading); } } }, React.createElement("div", { className: "jp-tocItem-heading" }, React.createElement("span", { className: "jp-tocItem-content", title: heading.text, ...heading.dataset }, heading.prefix, heading.text)), children)); } } //# sourceMappingURL=tocitem.js.map