mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: show and allow to expand crd sub-menus / sidebar refactoring
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
1818c5d733
commit
cd1749f331
@ -7,22 +7,18 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
|
||||||
.nav-item {
|
> .nav-item {
|
||||||
|
text-decoration: none;
|
||||||
padding: $itemSpacing;
|
padding: $itemSpacing;
|
||||||
border: none;
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
color: inherit;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 25px;
|
|
||||||
|
|
||||||
a {
|
> .link-text {
|
||||||
grid-row: 2;
|
|
||||||
grid-column: 1 / span 2;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
text-decoration: none;
|
white-space: nowrap;
|
||||||
vertical-align: middle;
|
|
||||||
flex-grow: 1;
|
|
||||||
min-width: 100px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.active, &:hover {
|
&.active, &:hover {
|
||||||
@ -32,45 +28,35 @@
|
|||||||
|
|
||||||
.expand-icon {
|
.expand-icon {
|
||||||
--size: 20px;
|
--size: 20px;
|
||||||
grid-row: 2;
|
|
||||||
grid-column: 2;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.sub-menu {
|
.sub-menu {
|
||||||
border-left: 4px solid transparent;
|
$borderSize: 4px;
|
||||||
|
border-left: $borderSize solid transparent;
|
||||||
&:empty, .compact & {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
border-left-color: $lensBlue;
|
border-left-color: $lensBlue;
|
||||||
}
|
}
|
||||||
|
|
||||||
a, .SidebarItem {
|
> .SidebarItem {
|
||||||
display: block;
|
|
||||||
border: none;
|
|
||||||
text-decoration: none;
|
|
||||||
color: $textColorPrimary;
|
color: $textColorPrimary;
|
||||||
font-weight: normal;
|
padding-left: 30px + $borderSize;
|
||||||
padding-left: 40px; // parent icon width
|
line-height: 22px;
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
line-height: 0px; // hidden by default
|
|
||||||
height: 0px;
|
|
||||||
opacity: 0;
|
|
||||||
transition: 125ms line-height ease-out, 200ms 100ms opacity;
|
|
||||||
|
|
||||||
&.visible {
|
.SidebarItem {
|
||||||
line-height: 28px;
|
padding-left: $padding * 2; // 3rd+ menu level
|
||||||
height: auto;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.active, &:hover {
|
.nav-item {
|
||||||
color: $sidebarSubmenuActiveColor;
|
&.expandable {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active, &:hover {
|
||||||
|
color: $sidebarSubmenuActiveColor;
|
||||||
|
background: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import { NavLink } from "react-router-dom";
|
|||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { TabLayoutRoute } from "./tab-layout";
|
import { TabLayoutRoute } from "./tab-layout";
|
||||||
import { sidebarStorage } from "./sidebar-storage";
|
import { sidebarStorage } from "./sidebar-storage";
|
||||||
|
import { isActiveRoute } from "../../navigation";
|
||||||
|
|
||||||
interface SidebarItemProps {
|
interface SidebarItemProps {
|
||||||
id: string; // Used to save nav item collapse/expand state in local storage
|
id: string; // Used to save nav item collapse/expand state in local storage
|
||||||
@ -18,7 +19,6 @@ interface SidebarItemProps {
|
|||||||
isHidden?: boolean;
|
isHidden?: boolean;
|
||||||
isActive?: boolean;
|
isActive?: boolean;
|
||||||
subMenus?: TabLayoutRoute[];
|
subMenus?: TabLayoutRoute[];
|
||||||
onToggle?(id: string, meta: { props: SidebarItemProps, event: React.MouseEvent }): void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -29,63 +29,66 @@ export class SidebarItem extends React.Component<SidebarItemProps> {
|
|||||||
return this.props.id; // unique id, used in storage and integration tests
|
return this.props.id; // unique id, used in storage and integration tests
|
||||||
}
|
}
|
||||||
|
|
||||||
get expanded(): boolean {
|
|
||||||
return Boolean(sidebarStorage.get().expanded[this.id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
get compact(): boolean {
|
get compact(): boolean {
|
||||||
return Boolean(sidebarStorage.get().compact);
|
return Boolean(sidebarStorage.get().compact);
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleExpand = prevDefault((event: React.MouseEvent) => {
|
get expanded(): boolean {
|
||||||
sidebarStorage.merge(draft => {
|
return Boolean(sidebarStorage.get().expanded[this.id]);
|
||||||
draft.expanded[this.id] = !draft.expanded[this.id];
|
}
|
||||||
});
|
|
||||||
|
|
||||||
this.props.onToggle?.(this.id, {
|
@computed get isExpandable(): boolean {
|
||||||
props: this.props,
|
|
||||||
event,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
@computed get showSubMenus(): boolean {
|
|
||||||
const { subMenus, children } = this.props;
|
const { subMenus, children } = this.props;
|
||||||
const hasContent = subMenus?.length > 0 || children;
|
const hasContent = subMenus?.length > 0 || children;
|
||||||
|
|
||||||
return Boolean(hasContent && !this.compact) /*not available in compact-mode*/;
|
return Boolean(hasContent && !this.compact) /*not available in compact-mode*/;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleExpand = () => {
|
||||||
|
sidebarStorage.merge(draft => {
|
||||||
|
draft.expanded[this.id] = !draft.expanded[this.id];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isHidden, isActive, subMenus = [], icon, text, children, url, className } = this.props;
|
const { isHidden, isActive, subMenus = [], icon, text, children, url, className } = this.props;
|
||||||
|
|
||||||
if (isHidden) return null;
|
if (isHidden) return null;
|
||||||
|
|
||||||
const { id: testId, expanded, compact, showSubMenus, toggleExpand } = this;
|
const { id, compact, expanded, isExpandable, toggleExpand } = this;
|
||||||
const classNames = cssNames(SidebarItem.displayName, className, { compact });
|
const classNames = cssNames(SidebarItem.displayName, className, {
|
||||||
|
compact,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames} data-test-id={testId}>
|
<div className={classNames} data-test-id={id}>
|
||||||
<div className={cssNames("nav-item flex align-center", { active: isActive })}>
|
<NavLink
|
||||||
<NavLink to={url} isActive={() => isActive} onClick={showSubMenus ? toggleExpand : undefined}>
|
to={url}
|
||||||
{icon} <span className="link-text">{text}</span>
|
className={cssNames("nav-item flex gaps align-center", { active: isActive, expandable: isExpandable })}
|
||||||
</NavLink>
|
onClick={isExpandable ? prevDefault(toggleExpand) : undefined}>
|
||||||
{showSubMenus && <Icon
|
{icon}
|
||||||
|
<span className="link-text box grow">{text}</span>
|
||||||
|
{isExpandable && <Icon
|
||||||
className="expand-icon box right"
|
className="expand-icon box right"
|
||||||
material={expanded ? "keyboard_arrow_up" : "keyboard_arrow_down"}
|
material={expanded ? "keyboard_arrow_up" : "keyboard_arrow_down"}
|
||||||
/>}
|
/>}
|
||||||
</div>
|
</NavLink>
|
||||||
{showSubMenus && (
|
{isExpandable && expanded && (
|
||||||
<ul className={cssNames("sub-menu", { active: isActive })}>
|
<ul className={cssNames("sub-menu", { active: isActive })}>
|
||||||
{subMenus.map(({ title, url }) => (
|
{subMenus.map(({ url, title, routePath }) => {
|
||||||
<NavLink key={url} to={url} className={cssNames({ visible: expanded })}>
|
const subItemId = `${id}${routePath}`;
|
||||||
{title}
|
|
||||||
</NavLink>
|
return (
|
||||||
))}
|
<SidebarItem
|
||||||
{React.Children.toArray(children).map((child: React.ReactElement<any>) => {
|
key={subItemId}
|
||||||
return React.cloneElement(child, {
|
id={subItemId}
|
||||||
className: cssNames(child.props.className, { visible: expanded }),
|
url={url}
|
||||||
});
|
text={title}
|
||||||
|
isActive={isActiveRoute({ exact: true, path: routePath })}
|
||||||
|
/>
|
||||||
|
);
|
||||||
})}
|
})}
|
||||||
|
{children}
|
||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -55,50 +55,11 @@
|
|||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link-text {
|
|
||||||
flex: 1;
|
|
||||||
margin-left: $margin;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
|
|
||||||
> a {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
text-decoration: none;
|
|
||||||
border: none;
|
|
||||||
padding: $itemSpacing;
|
|
||||||
|
|
||||||
&.active, &:hover {
|
|
||||||
background: $lensBlue;
|
|
||||||
color: $sidebarActiveColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hr {
|
hr {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.SidebarItem {
|
|
||||||
&.crd-group {
|
|
||||||
padding-left: 27px;
|
|
||||||
font-weight: 500;
|
|
||||||
|
|
||||||
.nav-item {
|
|
||||||
&:hover {
|
|
||||||
background: transparent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.sub-menu {
|
|
||||||
a {
|
|
||||||
padding-left: $padding * 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.loading {
|
.loading {
|
||||||
padding: $padding;
|
padding: $padding;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
@ -62,8 +62,7 @@ export class Sidebar extends React.Component<Props> {
|
|||||||
return (
|
return (
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
key={group}
|
key={group}
|
||||||
id={`crd-${group}`}
|
id={`crd-group:${group}`}
|
||||||
className="crd-group"
|
|
||||||
url={crdURL({ query: { groups: group } })}
|
url={crdURL({ query: { groups: group } })}
|
||||||
subMenus={submenus}
|
subMenus={submenus}
|
||||||
text={group}
|
text={group}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user