2021-08-05 13:36:47 -07:00
|
|
|
/*
|
|
|
|
Copyright (c) Microsoft Corporation.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
export const TreeItem: React.FunctionComponent<{
|
|
|
|
title: JSX.Element,
|
|
|
|
loadChildren?: () => JSX.Element[],
|
|
|
|
onClick?: () => void,
|
|
|
|
expandByDefault?: boolean,
|
|
|
|
depth: number,
|
|
|
|
selected?: boolean
|
|
|
|
}> = ({ title, loadChildren, onClick, expandByDefault, depth, selected }) => {
|
|
|
|
const [expanded, setExpanded] = React.useState(expandByDefault || false);
|
|
|
|
const className = selected ? 'tree-item-title selected' : 'tree-item-title';
|
2021-09-14 16:26:31 -07:00
|
|
|
return <div style={{ display: 'flex', flexDirection: 'column', width: '100%', flex: 'none' }}>
|
2021-09-14 13:55:31 -07:00
|
|
|
<div className={className} style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', whiteSpace: 'nowrap', paddingLeft: depth * 16 + 4 }} onClick={() => { onClick?.(); setExpanded(!expanded); }} >
|
2021-08-05 13:36:47 -07:00
|
|
|
<div className={'codicon codicon-' + (expanded ? 'chevron-down' : 'chevron-right')}
|
2021-08-10 17:06:25 -07:00
|
|
|
style={{ cursor: 'pointer', color: 'var(--color)', visibility: loadChildren ? 'visible' : 'hidden' }} />
|
2021-08-05 13:36:47 -07:00
|
|
|
{title}
|
|
|
|
</div>
|
|
|
|
{expanded && loadChildren?.()}
|
|
|
|
</div>;
|
|
|
|
};
|