Skip to content

Commit 9184ba8

Browse files
manni497GitHub Release Bot
andauthored
Fully Controlled ReactPatterUI (#55)
Co-authored-by: GitHub Release Bot <release-bot@neolution.ch>
1 parent 7e16567 commit 9184ba8

30 files changed

Lines changed: 1090 additions & 1456 deletions

CHANGELOG.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Possibility to dinamically open or close `sidebar`
13+
- Possibility to dinamically toggle `menu items`
14+
- Added support for `light`, `dark` and `blue` theme in PanelSideBarLayout.
15+
16+
### Changed
17+
18+
- `menuItems properties` are not locked by any states during the render process anymore. Changing externally the menu items will provide the correct menu
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 `16rem`
22+
- :boom: `UI elements` are now parameter of `SidebarLayout` and not of the context anymore
23+
- PanelItem Id type changed from `string` to being strongly typed
24+
25+
### Fixed
26+
27+
- When `footer` is null, the whole section will not be rendered
28+
- 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
31+
32+
### Removed
33+
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`
44+
1045
## [3.4.0] - 2024-03-12
1146

1247
### Added

cypress/cypress/component/DeleteAction/DeleteAction.cy.tsx

Lines changed: 0 additions & 48 deletions
This file was deleted.

cypress/cypress/component/PanelSidebar/PanelSidebar.cy.tsx

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,42 @@ import React from "react";
22
import { PanelSideBarProvider, PanelSideBarLayout, PanelItem, PanelLinkRendererProps } from "react-pattern-ui";
33
import { faBars, faCogs } from "@fortawesome/free-solid-svg-icons";
44

5-
type CustomPanelItem<TLocalPanelIds = ""> = {
6-
id: "home" | "settings" | TLocalPanelIds;
5+
type AppRoutes = "home" | "settings" | "dropdownTest" | "dropdown-test1" | "dropdown-test2";
6+
type TSideBarMenuItem = PanelItem<AppRoutes>;
7+
8+
// Configuration object for avoiding duplicated code
9+
interface PanelSideBarConfiguration {
10+
renderFirstItemsLevelAsTiles?: boolean;
11+
useToggleButton?: boolean;
12+
}
13+
14+
const getPanelSidebarInternal = (items: TSideBarMenuItem[], config?: PanelSideBarConfiguration) => {
15+
const { renderFirstItemsLevelAsTiles = true, useToggleButton = false } = config ?? {};
16+
return (
17+
<PanelSideBarProvider
18+
menuItems={items}
19+
renderFirstItemsLevelAsTiles={renderFirstItemsLevelAsTiles}
20+
LinkRenderer={(elem: PanelLinkRendererProps<AppRoutes, Record<string, unknown>>) => (
21+
<div
22+
id={elem.item.id}
23+
onClick={() => {
24+
const pageContent = document.getElementById("pageContent");
25+
if (pageContent) {
26+
pageContent.innerText = elem.item.id;
27+
}
28+
}}
29+
>
30+
<>{elem.item.title}</>
31+
</div>
32+
)}
33+
>
34+
<PanelSideBarLayout useToggleButton={useToggleButton}>
35+
<div id="pageContent">Cypress</div>
36+
</PanelSideBarLayout>
37+
</PanelSideBarProvider>
38+
);
739
};
840

9-
type TSideBarMenuItem<TLocalPanelIds = ""> = PanelItem<CustomPanelItem<TLocalPanelIds>>;
10-
11-
const PanelSidebar = (items: TSideBarMenuItem[]) => (
12-
<PanelSideBarProvider
13-
globalItems={items}
14-
LinkRenderer={(elem: PanelLinkRendererProps<Record<string, unknown>>) => (
15-
<div
16-
id={elem.item.id}
17-
onClick={() => {
18-
const pageContent = document.getElementById("pageContent");
19-
if (pageContent) {
20-
pageContent.innerText = elem.item.id;
21-
}
22-
}}
23-
>
24-
<>{elem.item.title}</>
25-
</div>
26-
)}
27-
>
28-
<PanelSideBarLayout>
29-
<div id="pageContent">Cypress</div>
30-
</PanelSideBarLayout>
31-
</PanelSideBarProvider>
32-
);
33-
3441
const getSidebarItems = (active?: boolean, disabled?: boolean): TSideBarMenuItem[] => [
3542
{
3643
id: "home",
@@ -74,10 +81,20 @@ const getSidebarItems = (active?: boolean, disabled?: boolean): TSideBarMenuItem
7481
},
7582
];
7683

84+
const PanelSideBarWithTiles = (props: { active?: boolean; disabled?: boolean }) => {
85+
const { active, disabled } = props;
86+
return getPanelSidebarInternal(getSidebarItems(active, disabled));
87+
};
88+
89+
const PanelSideBarNoTiles = (props: { active?: boolean; disabled?: boolean }) => {
90+
const { active, disabled } = props;
91+
return getPanelSidebarInternal(getSidebarItems(active, disabled), { renderFirstItemsLevelAsTiles: false, useToggleButton: true });
92+
};
93+
7794
describe("PanelSidebar.cy.tsx", () => {
7895
it("icon and titles rendered correctly", () => {
7996
const sidebarItems = getSidebarItems();
80-
cy.mount(PanelSidebar(sidebarItems));
97+
cy.mount(<PanelSideBarWithTiles />);
8198

8299
// Check if icon are rendered
83100
cy.get('[data-icon="bars"]').should("be.visible");
@@ -90,8 +107,7 @@ describe("PanelSidebar.cy.tsx", () => {
90107
});
91108

92109
it("flat menu entry", () => {
93-
const sidebarItems = getSidebarItems();
94-
cy.mount(PanelSidebar(sidebarItems));
110+
cy.mount(<PanelSideBarWithTiles />);
95111

96112
// Check page content changes
97113
cy.get("#home").click();
@@ -102,8 +118,7 @@ describe("PanelSidebar.cy.tsx", () => {
102118
});
103119

104120
it("nested menu entries", () => {
105-
const sidebarItems = getSidebarItems();
106-
cy.mount(PanelSidebar(sidebarItems));
121+
cy.mount(<PanelSideBarWithTiles />);
107122

108123
// Check page content changes
109124
cy.get("button[title=Settings]").click();
@@ -116,8 +131,7 @@ describe("PanelSidebar.cy.tsx", () => {
116131
});
117132

118133
it("disabled entries", () => {
119-
const sidebarItems = getSidebarItems(false, true);
120-
cy.mount(PanelSidebar(sidebarItems));
134+
cy.mount(<PanelSideBarWithTiles disabled />);
121135

122136
// Check are disabled and page content not doesn't change
123137
cy.get("button[title=Home]").should("have.attr", "disabled");
@@ -130,7 +144,7 @@ describe("PanelSidebar.cy.tsx", () => {
130144

131145
it("toggle sidebar", () => {
132146
const sidebarItems = getSidebarItems();
133-
cy.mount(PanelSidebar(sidebarItems));
147+
cy.mount(<PanelSideBarWithTiles />);
134148

135149
// Check toggle sidebar
136150
cy.get('[data-icon="angle-left"]').should("be.visible");
@@ -141,10 +155,21 @@ describe("PanelSidebar.cy.tsx", () => {
141155
});
142156

143157
it("selected flat entry", () => {
144-
const sidebarItems = getSidebarItems(true);
145-
cy.mount(PanelSidebar(sidebarItems));
158+
cy.mount(<PanelSideBarWithTiles active />);
146159

147160
// Check active entries
148161
cy.get("#home").parent("div").parent("li").should("have.class", "active");
149162
});
163+
164+
it("render correctly menu without tiles", () => {
165+
cy.mount(<PanelSideBarNoTiles />);
166+
cy.get("#main-section").should("have.class", "section-no-tiles");
167+
cy.get(".side.nav__tiles").should("not.exist");
168+
});
169+
170+
it("render correctly toggle button", () => {
171+
cy.mount(<PanelSideBarNoTiles />);
172+
cy.get("#sidebar-toggle").click();
173+
cy.get("#side-nav").should("have.css", "width", "0px");
174+
});
150175
});

src/index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
export * from "./lib/DeleteAction/DeleteAction";
21
export * from "./lib/Layout/AuthenticationLayout";
2+
export * from "./lib/Paging/Paging";
33

44
// Panel sidebar layout
55
export * from "./lib/Layout/PanelSideBarLayout/PanelSideBarLayout";
66
export * from "./lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContext";
77
export * from "./lib/Layout/PanelSideBarLayout/PanelSideBar/Definitions/PanelItem";
8-
9-
// Sidebar layout
10-
export * from "./lib/Layout/SideBarLayout/SideBarLayout";
11-
export * from "./lib/Layout/SideBarLayout/SideBarLayoutContext";
12-
export * from "./lib/SideBar/SideBarMenuContext";
13-
export * from "./lib/Paging/Paging";
14-
export * from "./lib/SideBar/ISideBarMenuItem";
8+
export * from "./lib/Layout/PanelSideBarLayout/PanelSideBar/Definitions/PanelLinkRenderer";

src/lib/DeleteAction/DeleteAction.tsx

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)