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

[Emotion] Convert EuiSideNav #7521

Merged
merged 19 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Convert euiSideNavItem__items
+ remove unnecessary CSS and replace let with inline conditional JSX
  • Loading branch information
cee-chen committed Feb 9, 2024
commit 84e9d506f8f86f810753d37c8995b00677e4e106
55 changes: 0 additions & 55 deletions src/components/side_nav/_side_nav_item.scss
Original file line number Diff line number Diff line change
@@ -1,58 +1,3 @@
.euiSideNavItem--root {
&.euiSideNavItem--rootIcon > .euiSideNavItem__items {
margin-left: $euiSizeL;
}

& > .euiSideNavItem__items {
position: static;
margin-left: 0;

&::after {
display: none;
}
}

& + & {
margin-top: $euiSizeXL;
}
}

.euiSideNavItem--trunk {
color: $euiSideNavRootTextcolor; /* 2 */

& > .euiSideNavItem__items {
margin-left: $euiSizeS;
width: 100%;
}
}

.euiSideNavItem--branch {
/**
* 1. Draw the vertical line to group an expanded item's child items together.
*/
position: relative;
color: $euiSideNavBranchTextcolor; /* 2 */

&::after { /* 1 */
position: absolute;
content: '';
top: 0;
bottom: 0;
width: 1px;
background: $euiBorderColor;
left: 0;
}

// If this is actually the last item, we don't want the vertical line to stretch all the way down
&:last-of-type::after {
height: $euiSizeM;
}

& > .euiSideNavItem__items {
margin-left: $euiSize;
}
}

.euiSideNavItem--emphasized {
background: $euiSideNavEmphasizedBackgroundColor;
color: $euiSideNavRootTextcolor;
Expand Down
13 changes: 13 additions & 0 deletions src/components/side_nav/side_nav_item.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ export const euiSideNavItemStyles = (euiThemeContext: UseEuiTheme) => {
${logicalCSS('height', euiTheme.size.m)}
}
`,

items: {
euiSideNavItem__items: css``,
rootWithIcon: css`
${logicalCSS('margin-left', euiTheme.size.l)}
`,
trunk: css`
${logicalCSS('margin-left', euiTheme.size.s)}
`,
branch: css`
${logicalCSS('margin-left', euiTheme.size.base)}
`,
},
};
};

Expand Down
19 changes: 13 additions & 6 deletions src/components/side_nav/side_nav_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ export const EuiSideNavItem = <
setItemIsOpen((isOpen) => !isOpen);
};

let childItems;
if (items && itemIsOpen) {
childItems = <div className="euiSideNavItem__items">{items}</div>;
}
const hasChildItems = items && itemIsOpen;

let buttonIcon;
if (icon) {
Expand All @@ -205,7 +202,7 @@ export const EuiSideNavItem = <
'euiSideNavItem--rootIcon': depth === 0 && icon,
'euiSideNavItem--trunk': depth === 1,
'euiSideNavItem--branch': depth > 1,
'euiSideNavItem--hasChildItems': !!childItems,
'euiSideNavItem--hasChildItems': hasChildItems,
'euiSideNavItem--emphasized': emphasize,
},
className
Expand All @@ -217,6 +214,12 @@ export const EuiSideNavItem = <
depth === 1 && styles.trunk,
depth > 1 && styles.branch,
];
const itemsStyles = hasChildItems && [
styles.items.euiSideNavItem__items,
depth === 0 && icon && styles.items.rootWithIcon,
depth === 1 && styles.items.trunk,
depth > 1 && styles.items.branch,
];

const buttonClasses = classNames(
'euiSideNavItemButton',
Expand Down Expand Up @@ -277,7 +280,11 @@ export const EuiSideNavItem = <
{caret}
</RenderItem>

{childItems}
{hasChildItems && (
<div css={itemsStyles} className="euiSideNavItem__items">
{items}
</div>
)}
</div>
);
};