Skip to content

Commit 8e13c34

Browse files
Refactor SidebarPanel to pass in buttons as elements (#1271)
Closes RaspberryPiFoundation/digital-editor-issues#991
1 parent d01c6dd commit 8e13c34

File tree

6 files changed

+43
-42
lines changed

6 files changed

+43
-42
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1414
### Changed
1515

1616
- Changed the horizontal scrollbar to show without needing to scroll to the bottom of the editor window (#1257)
17-
- Changed SidebarPanel to accept an array of buttons (#1270)
1817
- Updated Design System react to v2.6.2 (#1261)
18+
- Changed SidebarPanel to accept an array of buttons (#1270)
19+
- Changed SidebarPanel to use an array of buttons as elements (#1271)
1920

2021
### Fixed
2122

src/components/Menus/Sidebar/FilePanel/FilePanel.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ const FilePanel = ({ isMobile }) => {
5151
const buttons = readOnly
5252
? []
5353
: [
54-
{
55-
text: t("filePanel.newFileButton"),
56-
textAlways: true,
57-
icon: <PlusIcon />,
58-
onClick: openNewFileModal,
59-
className: "btn--primary",
60-
fill: true,
61-
},
54+
<DesignSystemButton
55+
text={t("filePanel.newFileButton")}
56+
textAways={true}
57+
icon={<PlusIcon />}
58+
onClick={openNewFileModal}
59+
className="btn--primary"
60+
fill={true}
61+
/>,
6262
];
6363

6464
if (!project || !project.components) {

src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.jsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,27 @@ const InstructionsPanel = () => {
147147
instructionsEditable
148148
? hasInstructions
149149
? [
150-
{
151-
className: "btn--secondary",
152-
text: t("instructionsPanel.removeInstructions"),
153-
onClick: () => setShowModal(true),
154-
fill: true,
155-
textAlways: true,
156-
small: true,
157-
},
150+
<DesignSystemButton
151+
className="btn--secondary"
152+
text={t("instructionsPanel.removeInstructions")}
153+
onClick={() => setShowModal(true)}
154+
fill={true}
155+
textAlways={true}
156+
small={true}
157+
/>,
158158
]
159159
: [
160-
{
161-
className: "btn--primary",
162-
icon: "add",
163-
text: t("instructionsPanel.emptyState.addInstructions"),
164-
onClick: addInstructions,
165-
fill: true,
166-
textAlways: true,
167-
small: true,
168-
},
160+
<DesignSystemButton
161+
className="btn--primary"
162+
icon="add"
163+
text={t("instructionsPanel.emptyState.addInstructions")}
164+
onClick={addInstructions}
165+
fill={true}
166+
textAlways={true}
167+
small={true}
168+
/>,
169169
]
170-
: null
170+
: []
171171
}
172172
{...{ Footer: hasMultipleSteps && ProgressBar }}
173173
>

src/components/Menus/Sidebar/ProjectsPanel/ProjectsPanel.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { MOBILE_MEDIA_QUERY } from "../../../../utils/mediaQueryBreakpoints";
1313
import { useMediaQuery } from "react-responsive";
1414
import SaveStatus from "../../../SaveStatus/SaveStatus";
1515
import { navigateToProjectsPageEvent } from "../../../../events/WebComponentCustomEvents";
16+
import DesignSystemButton from "../../../DesignSystemButton/DesignSystemButton";
1617

1718
const ProjectsPanel = () => {
1819
const { t } = useTranslation();
@@ -38,12 +39,13 @@ const ProjectsPanel = () => {
3839

3940
const buttons = isLoggedIn
4041
? [
41-
{
42-
className: "btn--primary projects-panel__your-projects-button",
43-
onClick: navigateToProjectsPage,
44-
text: t("projectsPanel.yourProjectsButton"),
45-
textAlways: true,
46-
},
42+
<DesignSystemButton
43+
key="your-projects"
44+
className="btn--primary projects-panel__your-projects-button"
45+
onClick={navigateToProjectsPage}
46+
text={t("projectsPanel.yourProjectsButton")}
47+
textAlways
48+
/>,
4749
]
4850
: [];
4951

src/components/Menus/Sidebar/SidebarPanel.jsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import classNames from "classnames";
44
import PropTypes from "prop-types";
55
import { MOBILE_MEDIA_QUERY } from "../../../utils/mediaQueryBreakpoints";
66
import { useMediaQuery } from "react-responsive";
7-
import DesignSystemButton from "../../DesignSystemButton/DesignSystemButton";
87

98
const SidebarPanel = (props) => {
109
const {
@@ -22,11 +21,7 @@ const SidebarPanel = (props) => {
2221
<div className="sidebar__panel-header">
2322
<h2 className="sidebar__panel-heading">{heading}</h2>
2423
{buttons?.length > 0 && (
25-
<div className="sidebar__panel-buttons">
26-
{buttons.map((btn, i) => (
27-
<DesignSystemButton key={i} {...btn} />
28-
))}
29-
</div>
24+
<div className="sidebar__panel-buttons">{buttons}</div>
3025
)}
3126
</div>
3227
<div className="sidebar__panel-content">{children}</div>
@@ -68,7 +63,7 @@ SidebarPanel.propTypes = {
6863
children: PropTypes.any.isRequired,
6964
heading: PropTypes.string.isRequired,
7065
className: PropTypes.string,
71-
buttons: PropTypes.arrayOf(PropTypes.object),
66+
buttons: PropTypes.arrayOf(PropTypes.node),
7267
};
7368

7469
export default SidebarPanel;

src/components/Menus/Sidebar/SidebarPanel.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test("Renders footer", () => {
2626

2727
test("Renders a single button", () => {
2828
render(
29-
<SidebarPanel heading="heading" buttons={[{ text: "button" }]}>
29+
<SidebarPanel heading="heading" buttons={[<button key="1">button</button>]}>
3030
some content
3131
</SidebarPanel>,
3232
);
@@ -37,7 +37,10 @@ test("Renders multiple buttons", () => {
3737
render(
3838
<SidebarPanel
3939
heading="heading"
40-
buttons={[{ text: "button one" }, { text: "button two" }]}
40+
buttons={[
41+
<button key="1">button one</button>,
42+
<button key="2">button two</button>,
43+
]}
4144
>
4245
some content
4346
</SidebarPanel>,

0 commit comments

Comments
 (0)