-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react-components): TreeView: Add info icon for clicking for furth…
…er info. Also add support for long names. (#4847) * Add info * XFix treenode * Update TreeView.stories.tsx * Add Generics * Update parent
- Loading branch information
1 parent
7a1313b
commit ec92a1b
Showing
11 changed files
with
126 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
react-components/src/components/Architecture/TreeView/components/TreeViewInfo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*! | ||
* Copyright 2024 Cognite AS | ||
*/ | ||
|
||
/* eslint-disable react/prop-types */ | ||
|
||
import { useState, type ReactElement } from 'react'; | ||
import { type TreeViewProps } from '../TreeViewProps'; | ||
import { type ITreeNode } from '../../../../architecture/base/treeView/ITreeNode'; | ||
import { InfoIcon } from '@cognite/cogs.js'; | ||
import { HOVER_INFO_COLOR, INFO_COLOR } from '../utilities/constants'; | ||
|
||
// ================================================== | ||
// MAIN COMPONENT | ||
// ================================================== | ||
|
||
export const TreeViewInfo = ({ | ||
node, | ||
props | ||
}: { | ||
node: ITreeNode; | ||
props: TreeViewProps; | ||
}): ReactElement => { | ||
const Icon = InfoIcon; | ||
const [isHoverOver, setHoverOver] = useState(false); | ||
const color = getColor(props, isHoverOver); | ||
return ( | ||
<Icon | ||
style={{ color, marginTop: '3px', marginLeft: '6px' }} | ||
onClick={() => { | ||
onClickInfo(node); | ||
}} | ||
onMouseEnter={() => { | ||
setHoverOver(true); | ||
}} | ||
onMouseLeave={() => { | ||
setHoverOver(false); | ||
}} | ||
/> | ||
); | ||
|
||
function onClickInfo(node: ITreeNode): void { | ||
if (props.onClickInfo === undefined) { | ||
return; | ||
} | ||
props.onClickInfo(node); | ||
} | ||
}; | ||
|
||
function getColor(props: TreeViewProps, isHoverOver: boolean): string | undefined { | ||
if (isHoverOver) { | ||
return props.hoverInfoColor ?? HOVER_INFO_COLOR; | ||
} | ||
return props.infoColor ?? INFO_COLOR; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.