Skip to content

Commit 5cf9d21

Browse files
authored
Merge pull request #978 from eetu/feat/weather-anim-polish
Weather animation polish: overcast sky, ground effects, matched dividers
2 parents 257195e + c3e7eba commit 5cf9d21

4 files changed

Lines changed: 255 additions & 44 deletions

File tree

‎frontend/src/components/Box.tsx‎

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,21 @@ type BoxProps = {
88
className?: string;
99
drawer?: React.ReactElement;
1010
loading?: boolean;
11+
// full-bleed layer rendered behind header + footer; when set, those surfaces
12+
// turn transparent so it shows through continuously (e.g. weather animation)
13+
background?: React.ReactElement;
14+
// overrides the header/footer divider colour (e.g. to match a sky backdrop)
15+
borderColor?: string;
1116
} & React.HTMLAttributes<HTMLDivElement>;
1217

13-
const Box: React.FC<BoxProps> = ({ className, children, drawer, loading }) => {
18+
const Box: React.FC<BoxProps> = ({
19+
className,
20+
children,
21+
drawer,
22+
loading,
23+
background,
24+
borderColor,
25+
}) => {
1426
const [collapsed, setCollapsed] = useState(true);
1527
const theme = useTheme();
1628

@@ -35,6 +47,7 @@ const Box: React.FC<BoxProps> = ({ className, children, drawer, loading }) => {
3547
<div
3648
className={className}
3749
css={{
50+
position: "relative",
3851
cursor: expandable ? "pointer" : "default",
3952
minWidth: 0,
4053
overflow: "hidden",
@@ -43,11 +56,26 @@ const Box: React.FC<BoxProps> = ({ className, children, drawer, loading }) => {
4356
}}
4457
onClick={expandable ? () => setCollapsed(!collapsed) : undefined}
4558
>
46-
<BoxHeader hairline={expandable}>{children}</BoxHeader>
59+
{background && (
60+
<div css={{ position: "absolute", inset: 0, zIndex: 0 }}>
61+
{background}
62+
</div>
63+
)}
64+
<BoxHeader
65+
hairline={expandable}
66+
transparent={background !== undefined}
67+
borderColor={borderColor}
68+
>
69+
{children}
70+
</BoxHeader>
4771
{expandable && (
4872
<>
4973
<BoxDrawer collapsed={collapsed}>{drawer}</BoxDrawer>
50-
<BoxFooter collapsed={collapsed} />
74+
<BoxFooter
75+
collapsed={collapsed}
76+
transparent={background !== undefined}
77+
borderColor={borderColor}
78+
/>
5179
</>
5280
)}
5381
</div>
@@ -58,21 +86,33 @@ export default Box;
5886

5987
type BoxHeaderProps = {
6088
hairline: boolean;
89+
transparent?: boolean;
90+
borderColor?: string;
6191
} & React.HTMLAttributes<HTMLDivElement>;
6292

63-
const BoxHeader: React.FC<BoxHeaderProps> = ({ children, hairline }) => {
93+
const BoxHeader: React.FC<BoxHeaderProps> = ({
94+
children,
95+
hairline,
96+
transparent,
97+
borderColor,
98+
}) => {
6499
const theme = useTheme();
65100

66101
return (
67102
<div
68103
css={{
69104
position: "relative",
105+
zIndex: 1,
70106
overflow: "hidden",
71107
display: "flex",
72108
flexDirection: "column",
73-
backgroundColor: theme.colors.background.main,
109+
backgroundColor: transparent
110+
? "transparent"
111+
: theme.colors.background.main,
74112
padding: "1.5em",
75-
borderBottom: hairline ? `1px ${theme.colors.border} solid` : "none",
113+
borderBottom: hairline
114+
? `1px ${borderColor ?? theme.colors.border} solid`
115+
: "none",
76116
}}
77117
>
78118
{children}
@@ -92,6 +132,8 @@ const BoxDrawer: React.FC<BoxDrawerProps> = ({ children, collapsed }) => {
92132
<div
93133
ref={wrapperRef}
94134
css={{
135+
position: "relative",
136+
zIndex: 1,
95137
display: "grid",
96138
gridTemplateRows: collapsed ? "0fr" : "1fr",
97139
transition: "grid-template-rows 0.15s ease",
@@ -118,19 +160,31 @@ const BoxDrawer: React.FC<BoxDrawerProps> = ({ children, collapsed }) => {
118160

119161
type BoxFooterProps = {
120162
collapsed: boolean;
163+
transparent?: boolean;
164+
borderColor?: string;
121165
} & React.HTMLAttributes<HTMLDivElement>;
122166

123-
const BoxFooter: React.FC<BoxFooterProps> = ({ collapsed }) => {
167+
const BoxFooter: React.FC<BoxFooterProps> = ({
168+
collapsed,
169+
transparent,
170+
borderColor,
171+
}) => {
124172
const theme = useTheme();
125173

126174
return (
127175
<div
128176
css={{
177+
position: "relative",
178+
zIndex: 1,
129179
display: "flex",
130180
justifyContent: "center",
131181
height: "25px",
132-
backgroundColor: theme.colors.background.main,
133-
borderTop: collapsed ? "none" : `1px ${theme.colors.border} solid`,
182+
backgroundColor: transparent
183+
? "transparent"
184+
: theme.colors.background.main,
185+
borderTop: collapsed
186+
? "none"
187+
: `1px ${borderColor ?? theme.colors.border} solid`,
134188
color: theme.colors.text.light,
135189
}}
136190
>

‎frontend/src/components/FmiWeatherBox.tsx‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import useLocationSettings from "../hooks/useLocationSettings";
1010
import useScreenshotMode from "../hooks/useScreenshotMode";
1111
import { PvForecast } from "../types/pv";
1212
import { WeatherData } from "../types/weather/fmi";
13+
import { weatherBorderColor } from "../weather/asciiSky";
1314
import {
1415
getFmiWeatherDescription,
1516
getFmiWeatherIcon,
@@ -159,11 +160,24 @@ const WeatherBox: React.FC<WeatherBoxProps> = ({ className }) => {
159160
? testCase.precip
160161
: current.precipitation1h;
161162
const title = getFmiWeatherDescription(weatherSymbol);
163+
const borderColor = weatherBorderColor(
164+
weatherSymbol,
165+
isNight,
166+
theme.mode === "dark",
167+
);
162168

163169
return (
164170
<Box
165171
loading={!data}
166172
className={className}
173+
borderColor={borderColor}
174+
background={
175+
<WeatherAsciiBackground
176+
weatherSymbol={weatherSymbol}
177+
isNight={isNight}
178+
precipitation={precipitation}
179+
/>
180+
}
167181
drawer={
168182
<div
169183
css={{
@@ -177,11 +191,6 @@ const WeatherBox: React.FC<WeatherBoxProps> = ({ className }) => {
177191
</div>
178192
}
179193
>
180-
<WeatherAsciiBackground
181-
weatherSymbol={weatherSymbol}
182-
isNight={isNight}
183-
precipitation={precipitation}
184-
/>
185194
{demo && (
186195
<WeatherTestControls
187196
activeId={testCase?.id ?? "live"}
@@ -326,7 +335,7 @@ const WeatherBox: React.FC<WeatherBoxProps> = ({ className }) => {
326335
css={{
327336
display: "flex",
328337
flexDirection: "column",
329-
borderRight: `1px ${theme.colors.border} solid`,
338+
borderRight: `1px ${borderColor ?? theme.colors.border} solid`,
330339
width: "25%",
331340
textAlign: "center",
332341
"&:last-of-type": {

0 commit comments

Comments
 (0)