Skip to content

Commit e11f9e2

Browse files
author
Gianmarco Manni
committed
fix recursive selection
1 parent e6afa6f commit e11f9e2

4 files changed

Lines changed: 36 additions & 32 deletions

File tree

CHANGELOG.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Possibility to dinamically open or close `sidebar`
1313
- Possibility to dinamically toggle `menu items`
14+
- Added support for `light`, `dark` and `blue` theme in PanelSideBarLayout.
1415

1516
### Changed
1617

1718
- `menuItems properties` are not locked by any states during the render process anymore. Changing externally the menu items will provide the correct menu
18-
- `topBarLeftCustomItems` and `topBarRigthCustomItems` renamed to `navbarLeftItems` and `navbarRightItems`
19-
- `UI elements` are now parameter of `SidebarLayout` and not of the context anymore
19+
- :boom: `topBarLeftCustomItems` and `topBarRigthCustomItems` renamed to `navbarLeftItems` and `navbarRightItems`
20+
- `navbarLeftItems` and `navbarRightItems` have not default margin by default
21+
- default sidebar `width` to `14rem`
22+
- :boom: `UI elements` are now parameter of `SidebarLayout` and not of the context anymore
2023
- PanelItem Id type changed from `string` to being strongly typed
2124

2225
### Fixed
2326

2427
- When `footer` is null, the whole section will not be rendered
2528
- Unique key prop in a list warning
29+
- menu items provided with `expanded` to true are correctly displayed in `PanelSideBarLayout`
30+
- Active panel is now recognized recursively and not until the third deep level anymore
2631

2732
### Removed
2833

29-
- `DeleteAction` component.
30-
- Built-in support for `userDropdown`. It should provided in the `navbarRightItems` items.
31-
- `localItems` property as menuItems can be fully controlled by the consumer.
34+
- :boom: `DeleteAction` component.
35+
- :boom: Built-in support for `userDropdown`. It should provided in the `navbarRightItems` items and define your style in your solution.
36+
- :boom: `localItems` property as menuItems can be fully controlled by the consumer.
37+
- :boom: removed `PanelSideBar` component and its relative contexts and should be replaced with `PanelSideBarLayout`. In order to migrate:
38+
- assign `items` to `menuItems` in the `PanelSideBarProvider`
39+
- set `renderFirstItemsLevelAsTiles` to false
40+
- set `useToggleButton` in `PanelSideBarLayout` to true
41+
- set `useResponsiveLayout` in `PanelSideBarLayout` to true
42+
- move `brand` to `PanelSideBarLayout`
43+
- move `footer` to `PanelSideBarLayout`
3244

3345
## [3.4.0] - 2024-03-12
3446

src/lib/Layout/PanelSideBarLayout/PanelSideBar/PanelSideBarItem.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useState, useRef, useEffect } from "react";
44
import { Collapse, NavItem } from "reactstrap";
55
import { PanelItem } from "./../PanelSideBar/Definitions/PanelItem";
66
import { usePanelSideBarContext } from "./Context/PanelSideBarContext";
7+
import { hasActiveChildren } from "./Utils/getActivePanel";
78

89
export interface PanelSideBarItemProps<TPanelItemId extends string, TPanelItem> {
910
children: PanelItem<TPanelItemId, TPanelItem>;
@@ -13,12 +14,13 @@ export interface PanelSideBarItemProps<TPanelItemId extends string, TPanelItem>
1314
toggledItemIds: string[];
1415
}
1516

17+
// eslint-disable-next-line complexity
1618
const PanelSideBarItem = <TPanelItemId extends string, TPanelItem>(props: PanelSideBarItemProps<TPanelItemId, TPanelItem>) => {
1719
const { depth = 0, children: item, onClick, toggledItemIds = [] } = props;
1820
const { LinkRenderer } = usePanelSideBarContext<TPanelItemId, TPanelItem>();
1921
const hasitem = !!item.children?.length;
20-
const isActive = item.children?.find((s) => s.active) || item.active;
21-
const [isOpen, setIsOpen] = useState(toggledItemIds?.includes(item.id) || item.expanded);
22+
const isActive = (hasitem && item.children && hasActiveChildren(item.children)) || item.active;
23+
const [isOpen, setIsOpen] = useState(isActive || toggledItemIds?.includes(item.id) || item.expanded);
2224
if (item.display === false) {
2325
return null;
2426
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { PanelItem } from "../Definitions/PanelItem";
22

3-
export const getActivePanel = <TPanelItemId extends string, TPanelItem>(items: PanelItem<TPanelItemId, TPanelItem>[], defaultActivePanelId?: TPanelItemId) => {
4-
const activePanel = items.find((x) =>
5-
x.children ? x.children.find((y) => (y.children ? y.children.find((s) => s.active) : y.active)) : x.active,
6-
);
7-
8-
return activePanel ?? items.find((x) => defaultActivePanelId ? x.id === defaultActivePanelId : x.id);
9-
};
3+
4+
const getActivePanelInternal = <TPanelItemId extends string, TPanelItem>(items: PanelItem<TPanelItemId, TPanelItem>[])
5+
: PanelItem<TPanelItemId, TPanelItem> | undefined => items.find((x) => x.children ? getActivePanelInternal(x.children) : x.active);
6+
7+
export const getActivePanel = <TPanelItemId extends string, TPanelItem>(items: PanelItem<TPanelItemId, TPanelItem>[], defaultActivePanelId?: TPanelItemId) => getActivePanelInternal(items) ?? items.find((x) => defaultActivePanelId ? x.id === defaultActivePanelId : x.id);
8+
9+
export const hasActiveChildren = <TPanelItemId extends string, TPanelItem>(items: PanelItem<TPanelItemId, TPanelItem>[]) => !!getActivePanelInternal(items);
10+

styles/Layout/_PanelSideBarLayout.scss

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ section.content:first-of-type {
113113

114114
&.sidenav-light {
115115
background-color: $sidenav-light-bg;
116+
117+
@include media-breakpoint-up(lg) {
118+
box-shadow: 0 0 0.5rem 0.125rem rgba($color: $gray-500, $alpha: 0.75);
119+
}
120+
116121
.side-nav {
117122
&__tiles {
118123
.tile {
@@ -195,7 +200,7 @@ section.content:first-of-type {
195200
}
196201
}
197202

198-
&.dropdown-toggle::after {
203+
.nav-link.dropdown-toggle::after {
199204
@include chevron-light-right();
200205
}
201206
}
@@ -328,7 +333,7 @@ section.content:first-of-type {
328333
&.menu-open .nav-link.dropdown-toggle::after {
329334
@include chevron-blue-down();
330335
}
331-
&.dropdown-toggle::after {
336+
.nav-link.dropdown-toggle::after {
332337
@include chevron-blue-right();
333338
}
334339
}
@@ -500,20 +505,4 @@ $zindex-topnav: 1039 !default;
500505
}
501506
}
502507
}
503-
504-
// Behavior for the sidenav collapse on screens larger than the med breakpoint
505-
#layout-sidenav.toggled {
506-
#layout-sidenav__nav {
507-
transform: translateX(-$sidenav-base-width);
508-
}
509-
510-
#layout-sidenav__content {
511-
margin-left: 0;
512-
513-
// Removes the sidenav overlay on screens larger than the med breakpoint
514-
&:before {
515-
display: none;
516-
}
517-
}
518-
}
519508
}

0 commit comments

Comments
 (0)