Skip to content

Commit 62f5647

Browse files
cocomarineCopilot
andauthored
Replace react-toggle with DS Switch (#1503)
Closes RaspberryPiFoundation/digital-editor-issues#1499 ### Changes - Bumped Design System React to 2.9.2 to use Switch component and updated colour variable. - Replaced react-toggle Toggle with Switch and removed react-toggle dependency - Increased height of colour and timer controls to match the minimum height applied to `.rpf-switch` for a WCAG AAA touch-target requirement - Updated colours as per Max's design ### Screen recordings - Before https://github.com/user-attachments/assets/4a280a36-b5d9-4a12-b461-30af7b64e854 - After https://github.com/user-attachments/assets/35745f4e-701e-4eaf-a8a3-2fe2eb7187fa --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 3c97fa0 commit 62f5647

5 files changed

Lines changed: 32 additions & 39 deletions

File tree

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@codemirror/view": "^6.3.0",
1515
"@hello-pangea/dnd": "^16.2.0",
1616
"@juggle/resize-observer": "^3.3.1",
17-
"@raspberrypifoundation/design-system-react": "^2.7.0",
17+
"@raspberrypifoundation/design-system-react": "^2.9.2",
1818
"@raspberrypifoundation/python-friendly-error-messages": "0.7.0",
1919
"@react-three/drei": "^10.0.0",
2020
"@react-three/fiber": "^9.6.1",
@@ -64,7 +64,6 @@
6464
"react-tabs": "^3.2.3",
6565
"react-timer-hook": "^3.0.5",
6666
"react-toastify": "^11.1.0",
67-
"react-toggle": "^4.1.3",
6867
"redux": "^4.2.1",
6968
"redux-oidc": "^4.0.0-beta1",
7069
"scratchReactDomVendor": "npm:react-dom@18.3.1",

src/assets/stylesheets/AstroPiModel.scss

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
font-family: var(--wc-font-family-monospace);
103103

104104
&-timer {
105+
flex: 1;
105106
margin-block-start: 0;
106107
padding: $space-0-5 0;
107108
inline-size: 100%;
@@ -120,6 +121,14 @@
120121
label {
121122
flex: 1;
122123
}
124+
125+
.rpf-input-field {
126+
margin-block-end: 0;
127+
}
128+
129+
.rpf-switch {
130+
gap: 0;
131+
}
123132
}
124133

125134
&-input {
@@ -209,11 +218,12 @@
209218
background-color: $rpf-grey-800;
210219
border: 1px solid $rpf-grey-500;
211220

212-
.react-toggle {
213-
&-thumb {
214-
border: 1px solid $rpf-white;
215-
background-color: $rpf-white;
216-
}
221+
.rpf-switch {
222+
--rpf-switch-on-color: var(--rpf-green-400);
223+
--rpf-switch-handle-on-color: var(--rpf-grey-600);
224+
--rpf-switch-off-color: var(--rpf-grey-150);
225+
--rpf-switch-icon-off-color: var(--rpf-text-primary);
226+
--rpf-switch-track-color: var(--rpf-grey-500);
217227
}
218228
}
219229
}
@@ -263,9 +273,8 @@
263273
background-color: $rpf-white;
264274
border: 2px solid $rpf-grey-300;
265275

266-
.react-toggle-thumb {
267-
border: 1px solid $rpf-grey-100;
268-
background-color: $rpf-grey-100;
276+
.rpf-switch {
277+
--rpf-switch-on-color: var(--rpf-green-800);
269278
}
270279
}
271280
}

src/assets/stylesheets/ExternalStyles.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@forward "../../../node_modules/@raspberrypifoundation/design-system-react/dist/scss/design-system-core";
22
@use "../../../node_modules/react-tabs/style/react-tabs.css";
3-
@use "../../../node_modules/react-toggle/style.css";
43
@use "../../../node_modules/prismjs/plugins/line-numbers/prism-line-numbers.css";
54
@use "../../../node_modules/prismjs/plugins/line-highlight/prism-line-highlight.css";
65
@use "../../../node_modules/react-toastify/dist/ReactToastify.css";

src/components/AstroPiModel/AstroPiControls/MotionInput.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from "react";
22
import { useEffect, useState, startTransition } from "react";
33
import { useSelector } from "react-redux";
4-
import Toggle from "react-toggle";
4+
import { Switch } from "@raspberrypifoundation/design-system-react";
55
import Sk from "skulpt";
66
import "../../../assets/stylesheets/AstroPiModel.scss";
7-
import "react-toggle/style.css";
87
import { useTranslation } from "react-i18next";
98

109
const MotionInput = (props) => {
@@ -45,9 +44,10 @@ const MotionInput = (props) => {
4544
<label htmlFor={`sense_hat_motion`}>
4645
{t("output.senseHat.controls.motionSensorOptions.no")}
4746
</label>
48-
<Toggle
47+
<Switch
4948
id="sense_hat_motion"
50-
icons={false}
49+
name="senseHatMotionToggle"
50+
icon
5151
checked={value}
5252
onChange={(e) => setValue(e.target.checked)}
5353
/>

yarn.lock

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4091,20 +4091,20 @@ __metadata:
40914091
languageName: node
40924092
linkType: hard
40934093

4094-
"@raspberrypifoundation/design-system-core@npm:^2.4.0":
4095-
version: 2.4.0
4096-
resolution: "@raspberrypifoundation/design-system-core@npm:2.4.0"
4094+
"@raspberrypifoundation/design-system-core@npm:^2.4.7":
4095+
version: 2.4.7
4096+
resolution: "@raspberrypifoundation/design-system-core@npm:2.4.7"
40974097
dependencies:
40984098
classnames: "npm:^2.3.2"
4099-
checksum: 10/4f989c48c9e93f57f65a6979c37c6b0cda69fb8e06c6dffb91dc5c407783775422b527907a081258aa16dab06977af9e74e053456b3d98680fc1f1c86218a417
4099+
checksum: 10/3692700108f69bb41df4d0e5c512e87efbd5b1c5d929f86bfb62bc80b2a24a71f48f9b232be748aea6c937331324677c58e5f90ce54eab32ae4f8752dd614fd5
41004100
languageName: node
41014101
linkType: hard
41024102

4103-
"@raspberrypifoundation/design-system-react@npm:^2.7.0":
4104-
version: 2.7.3
4105-
resolution: "@raspberrypifoundation/design-system-react@npm:2.7.3"
4103+
"@raspberrypifoundation/design-system-react@npm:^2.9.2":
4104+
version: 2.9.2
4105+
resolution: "@raspberrypifoundation/design-system-react@npm:2.9.2"
41064106
dependencies:
4107-
"@raspberrypifoundation/design-system-core": "npm:^2.4.0"
4107+
"@raspberrypifoundation/design-system-core": "npm:^2.4.7"
41084108
classnames: "npm:^2.5.1"
41094109
lucide-react: "npm:^0.553.0"
41104110
peerDependencies:
@@ -4116,7 +4116,7 @@ __metadata:
41164116
optional: false
41174117
react-dom:
41184118
optional: false
4119-
checksum: 10/28db4405bbb59c612308411f12201ec5b6437116078187286e76022822a6e41be54cb78a82b00857218f07f6e6aeb3efdebcfa7e87425ce0e9302f0043d1ed6c
4119+
checksum: 10/36ec7dc3ade7da08b0b2d7fbec6e7114cc84ab14c7fec566969ad5d30c8dbd694643295fbb97ed51f7a85b643fa9e06146e852860a68f563e81aea9941bb91f9
41204120
languageName: node
41214121
linkType: hard
41224122

@@ -4135,7 +4135,7 @@ __metadata:
41354135
"@codemirror/view": "npm:^6.3.0"
41364136
"@hello-pangea/dnd": "npm:^16.2.0"
41374137
"@juggle/resize-observer": "npm:^3.3.1"
4138-
"@raspberrypifoundation/design-system-react": "npm:^2.7.0"
4138+
"@raspberrypifoundation/design-system-react": "npm:^2.9.2"
41394139
"@raspberrypifoundation/python-friendly-error-messages": "npm:0.7.0"
41404140
"@react-three/drei": "npm:^10.0.0"
41414141
"@react-three/fiber": "npm:^9.6.1"
@@ -4233,7 +4233,6 @@ __metadata:
42334233
react-tabs: "npm:^3.2.3"
42344234
react-timer-hook: "npm:^3.0.5"
42354235
react-toastify: "npm:^11.1.0"
4236-
react-toggle: "npm:^4.1.3"
42374236
redux: "npm:^4.2.1"
42384237
redux-mock-store: "npm:^1.5.4"
42394238
redux-oidc: "npm:^4.0.0-beta1"
@@ -18321,19 +18320,6 @@ __metadata:
1832118320
languageName: node
1832218321
linkType: hard
1832318322

18324-
"react-toggle@npm:^4.1.3":
18325-
version: 4.1.3
18326-
resolution: "react-toggle@npm:4.1.3"
18327-
dependencies:
18328-
classnames: "npm:^2.2.5"
18329-
peerDependencies:
18330-
prop-types: ">= 15.3.0 < 19"
18331-
react: ">= 15.3.0 < 19"
18332-
react-dom: ">= 15.3.0 < 19"
18333-
checksum: 10/b63b7c3bd37431c4dc3cce741143a490239ba4981302a1af0f5aeb83635bf580bc1b142097eb28a4f52fef8dee40913085aa30d52579f355992689002d2602ca
18334-
languageName: node
18335-
linkType: hard
18336-
1833718323
"react-tooltip@npm:4.5.1":
1833818324
version: 4.5.1
1833918325
resolution: "react-tooltip@npm:4.5.1"

0 commit comments

Comments
 (0)