Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EuiTreeView now accepts classes per node and has truncation built in #2627

Merged
merged 4 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src-docs/src/components/guide_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,8 @@ $guideZLevelHighest: $euiZLevel9 + 1000;
.euiDataGridHeaderCell--favoriteFranchise {
background: transparentize($color: #800080, $amount: .9) !important;
}

.euiTreeView__nodeInnerExample {
color: $euiColorDanger;
font-weight: $euiFontWeightBold;
}
5 changes: 3 additions & 2 deletions src-docs/src/views/tree_view/compressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ export class TreeViewCompressed extends React.Component {
icon: <EuiToken size="xs" iconType="tokenConstant" />,
},
{
label: 'mailOptions',
id: 'mailOptions',
label: 'A custom class is on this one',
id: 'cutomClass',
icon: <EuiToken size="xs" iconType="tokenObject" />,
className: 'euiTreeView__nodeInnerExample',
},
],
},
Expand Down
3 changes: 2 additions & 1 deletion src-docs/src/views/tree_view/tree_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export class TreeView extends React.Component {
icon: <EuiToken iconType="tokenConstant" />,
},
{
label: 'Another Bug',
label:
'This one is a really long string that we will check truncates correctly',
id: 'item_bug2',
icon: <EuiToken iconType="tokenEnum" />,
callback: this.showAlert,
Expand Down
5 changes: 5 additions & 0 deletions src-docs/src/views/tree_view/tree_view_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export const TreeViewExample = {
<EuiCode>expandByDefault</EuiCode> prop, as seen in the example
below.
</p>
<p>
Lastly, each node can also accept a custom{' '}
<EuiCode>className</EuiCode> should you need to style them
individually.
</p>
</div>
),
components: { EuiTreeView },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`EuiTreeView is rendered 1`] = `
class="euiText euiText--medium euiTreeView__wrapper"
>
<p
class="euiScreenReaderOnly"
id="htmlId--instruction"
>
You can quickly navigate this list using arrow keys.
Expand Down
6 changes: 6 additions & 0 deletions src/components/tree_view/tree_view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
}

.euiTreeView__nodeInner {
@include euiTextTruncate;

padding-left: $euiSizeS;
display: flex;
flex-direction: row;
Expand All @@ -44,6 +46,10 @@

}

.euiTreeView__nodeLabel {
@include euiTextTruncate;
}

.euiTreeView__iconWrapper {
margin-top: -($euiSizeXS / 2);
margin-right: $euiSizeS;
Expand Down
1 change: 1 addition & 0 deletions src/components/tree_view/tree_view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('EuiTreeView', () => {
label: "I'm a Bug",
id: 'item_bug',
icon: <EuiToken iconType="tokenEnum" />,
className: 'classForBug',
},
],
},
Expand Down
54 changes: 30 additions & 24 deletions src/components/tree_view/tree_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export interface Node {
/** Whether or not the item is expanded.
*/
isExpanded?: boolean;
/** Optional class to throw on the node
*/
className?: string;
/** Function to call when the item is clicked.
The open state of the item will always be toggled.
*/
Expand Down Expand Up @@ -232,15 +235,15 @@ export class EuiTreeView extends Component<EuiTreeViewProps, EuiTreeViewState> {
size={display === 'compressed' ? 's' : 'm'}
className="euiTreeView__wrapper">
{!this.isNested && (
<EuiScreenReaderOnly>
<EuiI18n
token="euiTreeView.listNavigationInstructions"
default="You can quickly navigate this list using arrow keys.">
{(listNavigationInstructions: string) => (
<EuiI18n
token="euiTreeView.listNavigationInstructions"
default="You can quickly navigate this list using arrow keys.">
{(listNavigationInstructions: string) => (
<EuiScreenReaderOnly>
<p id={instructionsId}>{listNavigationInstructions}</p>
)}
</EuiI18n>
</EuiScreenReaderOnly>
</EuiScreenReaderOnly>
)}
</EuiI18n>
)}
<ul
className={classes}
Expand Down Expand Up @@ -272,15 +275,26 @@ export class EuiTreeView extends Component<EuiTreeViewProps, EuiTreeViewState> {
}`,
};

const nodeClasses = classNames(
'euiTreeView__node',
display ? displayToClassNameMap[display] : null,
{ 'euiTreeView__node--expanded': this.isNodeOpen(node) }
);

const nodeButtonClasses = classNames(
'euiTreeView__nodeInner',
showExpansionArrows && node.children
? 'euiTreeView__nodeInner--withArrows'
: null,
this.state.activeItem === node.id
? 'euiTreeView__node--active'
: null,
node.className ? node.className : null
);

return (
<React.Fragment>
<li
className={classNames(
'euiTreeView__node',
this.isNodeOpen(node)
? 'euiTreeView__node--expanded'
: null
)}>
<li className={nodeClasses}>
<button
id={buttonId}
aria-controls={`euiNestedTreeView-${
Expand All @@ -295,15 +309,7 @@ export class EuiTreeView extends Component<EuiTreeViewProps, EuiTreeViewState> {
this.onKeyDown(event, node)
}
onClick={() => this.handleNodeClick(node)}
className={classNames(
'euiTreeView__nodeInner',
showExpansionArrows && node.children
? 'euiTreeView__nodeInner--withArrows'
: null,
this.state.activeItem === node.id
? 'euiTreeView__node--active'
: null
)}>
className={nodeButtonClasses}>
{showExpansionArrows && node.children ? (
<EuiIcon
className="euiTreeView__expansionArrow"
Expand Down