Skip to content

Commit 0eea201

Browse files
authored
FE-1048: Petrinaut use ds toggle (#8891)
1 parent fd129ea commit 0eea201

10 files changed

Lines changed: 151 additions & 243 deletions

File tree

libs/@hashintel/ds-components/src/components/Switch/switch.tsx

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

libs/@hashintel/ds-components/src/components/Toggle/toggle.recipe.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ export const styles = sva({
2222
flexShrink: "0",
2323
width: "var(--toggle-width)",
2424
height: "var(--toggle-height)",
25-
padding: "var(--toggle-padding)",
25+
padding: "[calc(var(--toggle-padding) + 1px)]",
2626
borderRadius: "full",
27-
border: "[1px solid]",
28-
borderColor: "black.a15",
29-
boxShadow: "[inset 0 2px 4px rgba(0, 0, 0, 0.05)]",
27+
boxShadow:
28+
"[inset 0 2px 4px rgba(0, 0, 0, 0.05), inset 0 0 0 1px var(--colors-black-a10)]",
3029
outlineColor: "black.a40",
3130
transition:
3231
"[background-color 0.15s ease, outline 0.15s ease, box-shadow 0.15s ease]",
@@ -87,7 +86,11 @@ export const styles = sva({
8786
"--toggle-width": "[24px]",
8887
"--toggle-height": "[14px]",
8988
"--toggle-padding": "[2px]",
90-
"--toggle-thumb-size": "[10px]",
89+
"--toggle-thumb-size": "[9px]",
90+
},
91+
thumb: {
92+
boxShadow:
93+
"[0 0.5px 2.5px 0 rgba(0, 0, 0, 0.1), 0 0.5px 1.5px -1px rgba(0, 0, 0, 0.1)]",
9194
},
9295
label: { fontSize: "[12px]" },
9396
},
@@ -96,9 +99,13 @@ export const styles = sva({
9699
"--toggle-width": "[28px]",
97100
"--toggle-height": "[16px]",
98101
"--toggle-padding": "[2px]",
99-
"--toggle-thumb-size": "[12px]",
102+
"--toggle-thumb-size": "[11px]",
100103
},
101104
label: { fontSize: "[12px]" },
105+
thumb: {
106+
boxShadow:
107+
"[0 0.5px 2.5px 0 rgba(0, 0, 0, 0.1), 0 0.5px 1.5px -1px rgba(0, 0, 0, 0.1)]",
108+
},
102109
},
103110
sm: {
104111
control: {
@@ -200,7 +207,8 @@ export const styles = sva({
200207
invalid: {
201208
true: {
202209
control: {
203-
borderColor: "red.s70",
210+
boxShadow:
211+
"[0 0 0 1px var(--colors-red-s70), inset 0 2px 4px rgba(0, 0, 0, 0.05)]",
204212
"&::after": {
205213
content: '""',
206214
position: "absolute",

libs/@hashintel/ds-components/src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export {
3232
type SelectProps,
3333
} from "./components/Select/select";
3434
export { Slider, type SliderProps } from "./components/Slider/slider";
35-
export { Switch, type SwitchProps } from "./components/Switch/switch";
3635
export { TextInput } from "./components/TextInput/text-input";
3736
export { TextMark } from "./components/TextMark/text-mark";
3837
export { Toggle, type ToggleProps } from "./components/Toggle/toggle";

libs/@hashintel/petrinaut/src/ui/components/switch.tsx

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

libs/@hashintel/petrinaut/src/ui/views/Editor/panels/BottomPanel/subviews/simulation-settings.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { use, useState } from "react";
22

3-
import { Button, Icon, NumberInput, Select } from "@hashintel/ds-components";
3+
import {
4+
Button,
5+
Icon,
6+
NumberInput,
7+
Select,
8+
Toggle,
9+
} from "@hashintel/ds-components";
410
import { css } from "@hashintel/ds-helpers/css";
511

612
import { SimulationContext } from "../../../../../../react/simulation/context";
713
import { EditorContext } from "../../../../../../react/state/editor-context";
814
import { SDCPNContext } from "../../../../../../react/state/sdcpn-context";
915
import { InfoIconTooltip } from "../../../../../components/info-icon-tooltip";
1016
import { Slider } from "../../../../../components/slider";
11-
import { Switch } from "../../../../../components/switch";
1217
import { CreateScenarioDrawer } from "../../SimulateView/scenarios/create-scenario-drawer";
1318
import { ViewScenarioDrawer } from "../../SimulateView/scenarios/view-scenario-drawer";
1419

@@ -303,12 +308,13 @@ const SimulationSettingsContent: React.FC = () => {
303308
</div>
304309
</div>
305310
{param.type === "boolean" && selectedScenario ? (
306-
<Switch
307-
checked={
311+
<Toggle
312+
size="xs"
313+
value={
308314
(scenarioParameterValues[param.variableName] ??
309315
param.defaultValue) !== "0"
310316
}
311-
onCheckedChange={(checked) =>
317+
onChange={(checked) =>
312318
setScenarioParameterValue(
313319
param.variableName,
314320
checked ? "1" : "0",

libs/@hashintel/petrinaut/src/ui/views/Editor/panels/PropertiesPanel/place-properties/subviews/main.tsx

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Icon,
77
Select,
88
TextInput,
9+
Toggle,
910
Tooltip,
1011
} from "@hashintel/ds-components";
1112
import { css } from "@hashintel/ds-helpers/css";
@@ -15,7 +16,6 @@ import { usePetrinautMutations } from "../../../../../../../react";
1516
import { EditorContext } from "../../../../../../../react/state/editor-context";
1617
import { SDCPNContext } from "../../../../../../../react/state/sdcpn-context";
1718
import { Section, SectionList } from "../../../../../../components/section";
18-
import { Switch } from "../../../../../../components/switch";
1919
import { PlaceIcon } from "../../../../../../constants/entity-icons";
2020
import { UI_MESSAGES } from "../../../../../../constants/ui-messages";
2121
import { useDraftField } from "../../../../../../hooks/use-draft-field";
@@ -233,46 +233,55 @@ const PlaceMainContent: React.FC = () => {
233233
<Section
234234
title="Dynamics"
235235
tooltip="Token data can dynamically change over time when tokens remain in a place, governed by a differential equation."
236-
renderHeaderAction={() => (
237-
<Switch
238-
checked={!!place.colorId && place.dynamicsEnabled}
239-
disabled={
240-
isReadOnly ||
241-
place.colorId === null ||
242-
availableDiffEqs.length === 0
243-
}
244-
tooltip={
245-
isReadOnly
246-
? UI_MESSAGES.READ_ONLY_MODE
247-
: place.colorId === null
248-
? UI_MESSAGES.DYNAMICS_REQUIRES_TYPE
249-
: availableDiffEqs.length === 0
250-
? "Create a differential equation for this type first"
251-
: undefined
252-
}
253-
onCheckedChange={(checked) => {
254-
const update: {
255-
dynamicsEnabled: boolean;
256-
differentialEquationId?: string | null;
257-
} = { dynamicsEnabled: checked };
236+
renderHeaderAction={() => {
237+
const dynamicsTooltip = isReadOnly
238+
? UI_MESSAGES.READ_ONLY_MODE
239+
: place.colorId === null
240+
? UI_MESSAGES.DYNAMICS_REQUIRES_TYPE
241+
: availableDiffEqs.length === 0
242+
? "Create a differential equation for this type first"
243+
: undefined;
258244

259-
if (checked) {
260-
// Auto-select first available diff eq if none selected or previous no longer exists
261-
const currentIsValid = availableDiffEqs.some(
262-
(eq) => eq.id === place.differentialEquationId,
263-
);
264-
if (!currentIsValid && availableDiffEqs.length > 0) {
265-
update.differentialEquationId = availableDiffEqs[0]!.id;
245+
return (
246+
<Tooltip
247+
content={dynamicsTooltip}
248+
disableTooltip={!dynamicsTooltip}
249+
>
250+
<Toggle
251+
size="sm"
252+
tone="success"
253+
value={!!place.colorId && place.dynamicsEnabled}
254+
disabled={
255+
isReadOnly ||
256+
place.colorId === null ||
257+
availableDiffEqs.length === 0
266258
}
267-
}
259+
onChange={(checked) => {
260+
const update: {
261+
dynamicsEnabled: boolean;
262+
differentialEquationId?: string | null;
263+
} = { dynamicsEnabled: checked };
268264

269-
updatePlace({
270-
placeId: place.id,
271-
update,
272-
});
273-
}}
274-
/>
275-
)}
265+
if (checked) {
266+
// Auto-select first available diff eq if none selected or previous no longer exists
267+
const currentIsValid = availableDiffEqs.some(
268+
(eq) => eq.id === place.differentialEquationId,
269+
);
270+
if (!currentIsValid && availableDiffEqs.length > 0) {
271+
update.differentialEquationId =
272+
availableDiffEqs[0]!.id;
273+
}
274+
}
275+
276+
updatePlace({
277+
placeId: place.id,
278+
update,
279+
});
280+
}}
281+
/>
282+
</Tooltip>
283+
);
284+
}}
276285
>
277286
{place.colorId === null ? (
278287
<div className={hintTextStyle}>

0 commit comments

Comments
 (0)