From 2d4c8da048c022dde3f3ee3584338bdee9412be4 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Tue, 4 Apr 2023 23:52:24 +0000 Subject: [PATCH] support multiple bottom items --- .../src/components/Layout/sidebar/index.jsx | 104 ++++++++++++------ .../src/components/Layout/sidebar/index.less | 34 ++---- 2 files changed, 79 insertions(+), 59 deletions(-) diff --git a/packages/app/src/components/Layout/sidebar/index.jsx b/packages/app/src/components/Layout/sidebar/index.jsx index 42684428..b8644966 100755 --- a/packages/app/src/components/Layout/sidebar/index.jsx +++ b/packages/app/src/components/Layout/sidebar/index.jsx @@ -107,6 +107,13 @@ const CustomRender = (props) => { } +const handleRenderIcon = (icon) => { + if (typeof icon === "undefined") { + return null + } + return createIconRender(icon) +} + export default class Sidebar extends React.Component { constructor(props) { super(props) @@ -119,32 +126,54 @@ export default class Sidebar extends React.Component { isExpanded: () => this.state.expanded, setCustomRender: this.setRender, closeCustomRender: this.closeRender, - updateBackgroundItem: (children, props) => { - let updatedValue = this.state.backgroundItem + updateBottomItemProps: (id, newProps) => { + let updatedValue = this.state.bottomItems - if (typeof children !== "undefined") { - updatedValue.children = children - } - - if (typeof props !== "undefined") { - updatedValue.props = props - } + updatedValue = updatedValue.map((item) => { + if (item.id === id) { + item.props = { + ...item.props, + ...newProps, + } + } + }) this.setState({ - backgroundItem: updatedValue + bottomItems: updatedValue }) }, - setBackgroundItem: (children, props) => { + attachBottomItem: (id, children, options) => { + if (!id) { + throw new Error("ID is required") + } + + if (!children) { + throw new Error("Children is required") + } + + if (this.state.bottomItems.find((item) => item.id === id)) { + throw new Error("Item already exists") + } + + let updatedValue = this.state.bottomItems + + updatedValue.push({ + id, + children, + ...options + }) + this.setState({ - backgroundItem: { - children: children, - props: props, - }, + bottomItems: updatedValue }) }, - clearBackgroundItem: () => { + removeBottomItem: (id) => { + let updatedValue = this.state.bottomItems + + updatedValue = updatedValue.filter((item) => item.id !== id) + this.setState({ - backgroundItem: null, + bottomItems: updatedValue }) } } @@ -158,7 +187,8 @@ export default class Sidebar extends React.Component { customRenderTitle: null, customRender: null, - backgroundItem: null, + + bottomItems: [], } // handle sidedrawer open/close @@ -225,13 +255,6 @@ export default class Sidebar extends React.Component { } renderMenuItems(items) { - const handleRenderIcon = (icon) => { - if (typeof icon === "undefined") { - return null - } - return createIconRender(icon) - } - return items.map((item) => { if (Array.isArray(item.children)) { return { this.setState({ expanded: to ?? !this.state.expanded }) + + app.eventBus.emit("sidebar.expanded", to ?? !this.state.expanded) } toggleVisibility = (to) => { @@ -382,16 +407,25 @@ export default class Sidebar extends React.Component {
- - { - this.state.backgroundItem?.children - } - + { + this.state.bottomItems.map((item) => { + if (item.noContainer) { + return React.createElement(item.children, item.childrenProps) + } + + return + { + React.createElement(item.children, item.childrenProps) + } + + }) + } } > {(t) => t("Search")} diff --git a/packages/app/src/components/Layout/sidebar/index.less b/packages/app/src/components/Layout/sidebar/index.less index 5755d354..2de0900d 100755 --- a/packages/app/src/components/Layout/sidebar/index.less +++ b/packages/app/src/components/Layout/sidebar/index.less @@ -35,6 +35,11 @@ .app_sidebar_menu_wrapper { .ant-menu { + #sidebar_item_content { + opacity: 1; + width: 100%; + } + .ant-menu-item:not(.user_avatar) { .ant-menu-title-content { opacity: 1; @@ -136,6 +141,11 @@ transition: all 150ms ease-in-out; + #sidebar_item_content { + opacity: 0; + width: 0; + } + .ant-menu-item { display: inline-flex; @@ -182,30 +192,6 @@ } } - .background_item { - width: 100%; - - opacity: 0; - - transition: all 150ms ease-in-out; - - padding-bottom: 10px; - - background-color: transparent; - - &:hover{ - background-color: unset!important; - } - - &:active{ - background-color: unset!important; - } - - &.active { - opacity: 1; - } - } - .render_content_wrapper { display: flex; flex-direction: column;