Skip to content

Commit 2e7b330

Browse files
committed
Refactor DrawerRow into a shared component and update TemperatureBox drawer style
Extracts the DrawerRow component from SolisBox to the base Box component for reuse. Updates TemperatureBox to use DrawerRow, replacing its table-based layout with a flexbox-based design for consistent spacing and styling across the dashboard.
1 parent e6e20e8 commit 2e7b330

3 files changed

Lines changed: 63 additions & 44 deletions

File tree

‎frontend/src/components/Box.tsx‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,24 @@ const BoxFooter: React.FC<BoxFooterProps> = ({ collapsed }) => {
165165
</div>
166166
);
167167
};
168+
169+
export const DrawerRow: React.FC<{
170+
label: React.ReactNode;
171+
value: React.ReactNode;
172+
}> = ({ label, value }) => {
173+
const theme = useTheme();
174+
return (
175+
<div
176+
css={{
177+
width: "100%",
178+
display: "flex",
179+
flexDirection: "row",
180+
justifyContent: "space-between",
181+
alignItems: "center",
182+
}}
183+
>
184+
<span css={{ color: theme.colors.text.muted }}>{label}</span>
185+
<span>{value}</span>
186+
</div>
187+
);
188+
};

‎frontend/src/components/SolisBox.tsx‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import useSWR from "swr";
44

55
import { api, fetcher } from "../api";
66
import { SolisData } from "../types/solis";
7-
import Box from "./Box";
7+
import Box, { DrawerRow } from "./Box";
88
import Icon from "./Icon";
99

1010
type SolisBoxProps = {
@@ -120,17 +120,4 @@ const SolisBox: React.FC<SolisBoxProps> = ({ className }) => {
120120
);
121121
};
122122

123-
const DrawerRow: React.FC<{ label: string; value: string }> = ({
124-
label,
125-
value,
126-
}) => {
127-
const theme = useTheme();
128-
return (
129-
<div css={{ display: "flex", justifyContent: "space-between", gap: "1em" }}>
130-
<span css={{ color: theme.colors.text.muted }}>{label}</span>
131-
<span>{value}</span>
132-
</div>
133-
);
134-
};
135-
136123
export default memo(SolisBox);

‎frontend/src/components/TemperatureBox.tsx‎

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { memo } from "react";
55
import useSensorTrend from "../hooks/useSensorTrend";
66
import { mq } from "../mq";
77
import { Sensor } from "../types/hue";
8-
import Box from "./Box";
8+
import Box, { DrawerRow } from "./Box";
99
import Icon from "./Icon";
1010
import TrendIndicator from "./TrendIndicator";
1111

@@ -57,8 +57,12 @@ const TemperatureBox: React.FC<TemperatureBoxProps> = ({
5757
drawer={
5858
<div
5959
css={{
60-
display: "table",
61-
fontSize: "16px",
60+
backgroundColor: theme.colors.background.light,
61+
padding: "5px",
62+
display: "flex",
63+
flexDirection: "column",
64+
gap: "0.5em",
65+
fontSize: "14px",
6266
}}
6367
>
6468
{sensors.map((r) => {
@@ -67,36 +71,43 @@ const TemperatureBox: React.FC<TemperatureBoxProps> = ({
6771
<div
6872
key={r.id}
6973
css={{
70-
display: "table-row",
71-
whiteSpace: "nowrap",
72-
overflow: "hidden",
73-
textOverflow: "ellipsis",
74+
display: "flex",
75+
flexDirection: "column",
76+
gap: 5,
7477
backgroundColor: theme.colors.background.light,
75-
"& span": {
76-
display: "table-cell",
77-
padding: "5px",
78-
opacity: r.enabled && r.connected ? 1 : 0.25,
79-
width: "100%",
80-
},
8178
}}
8279
>
83-
<span>{r.name}</span>
84-
{isSensorBatteryLow ? (
85-
<Icon
86-
size={18}
87-
css={{
88-
color: theme.colors.error,
89-
transform: "rotate(90deg)",
90-
}}
91-
>{`battery_${getBatteryStr(r.battery)}`}</Icon>
92-
) : (
93-
<span>&nbsp;</span>
94-
)}
95-
<span>
96-
{r.temperature !== undefined
97-
? `${Math.round(r.temperature)}°`
98-
: ""}
99-
</span>
80+
<DrawerRow
81+
label={
82+
<div
83+
css={{
84+
display: "flex",
85+
flexDirection: "row",
86+
alignItems: "center",
87+
gap: 5,
88+
}}
89+
>
90+
{r.name}
91+
{isSensorBatteryLow && (
92+
<Icon
93+
size={18}
94+
css={{
95+
color: theme.colors.error,
96+
}}
97+
>{`battery_${getBatteryStr(r.battery)}`}</Icon>
98+
)}
99+
</div>
100+
}
101+
value={
102+
<>
103+
<span>
104+
{r.temperature !== undefined
105+
? `${Math.round(r.temperature)}°`
106+
: ""}
107+
</span>
108+
</>
109+
}
110+
/>
100111
</div>
101112
);
102113
})}

0 commit comments

Comments
 (0)