Skip to content

Commit 96b090c

Browse files
committed
Refactor HeaderBar to use styled components
1 parent 23457ba commit 96b090c

4 files changed

Lines changed: 54 additions & 33 deletions

File tree

src/components/Box/styles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ interface StyledBoxProps {
66
}
77

88
export const StyledBox = styled.div<StyledBoxProps>`
9-
display: "flex";
10-
align-items: "center";
9+
display: flex;
10+
align-items: center;
1111
flex-direction: ${(props) => (props.flow == "horizontal" ? "row" : "column")};
1212
gap: ${(props) => props.gap}px;
1313
padding: ${(props) => props.gap}px;
14-
box-sizing: "border-box";
14+
box-sizing: border-box;
1515
`;

src/components/HeaderBar/HeaderBar.scss

Whitespace-only changes.

src/components/HeaderBar/HeaderBar.tsx

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { CSSProperties } from "react";
2-
import "./HeaderBar.scss";
31
import useSystemSettings from "../../stores/systemSettingsStore";
42

3+
import { StyledHeaderBar } from "./styles";
4+
55
interface HeaderBarProps {
66
header: string;
77
position?: "left" | "centre" | "right";
@@ -20,37 +20,18 @@ function HeaderBar({
2020
borderRadiusBottom = 10,
2121
}: HeaderBarProps) {
2222
const settings = useSystemSettings();
23-
function getJustifyContent(): CSSProperties["justifyContent"] {
24-
switch (position) {
25-
case "left":
26-
return "flex-start";
27-
case "right":
28-
return "flex-end";
29-
case "centre":
30-
default:
31-
return "center";
32-
}
33-
}
23+
3424
return (
35-
<div
36-
className="header-bar__container"
37-
style={{
38-
display: "flex",
39-
alignItems: "center",
40-
justifyContent: getJustifyContent(),
41-
paddingTop: padVertical,
42-
paddingBottom: padVertical,
43-
paddingLeft: padHorizontal,
44-
paddingRight: padHorizontal,
45-
backgroundColor: settings.mainColor,
46-
borderTopLeftRadius: borderRadiusTop,
47-
borderTopRightRadius: borderRadiusTop,
48-
borderBottomLeftRadius: borderRadiusBottom,
49-
borderBottomRightRadius: borderRadiusBottom,
50-
}}
25+
<StyledHeaderBar
26+
backgroundColor={settings.mainColor}
27+
position={position}
28+
padVertical={padVertical}
29+
padHorizontal={padHorizontal}
30+
borderRadiusTop={borderRadiusTop}
31+
borderRadiusBottom={borderRadiusBottom}
5132
>
5233
<span className="header-bar__header">{header}</span>
53-
</div>
34+
</StyledHeaderBar>
5435
);
5536
}
5637

src/components/HeaderBar/styles.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import styled from "@emotion/styled";
2+
import { CSSProperties } from "react";
3+
4+
type Position = "left" | "centre" | "right";
5+
interface StyledHeaderBarProps {
6+
backgroundColor: string;
7+
position?: Position;
8+
padVertical?: number;
9+
padHorizontal?: number;
10+
borderRadiusTop?: number;
11+
borderRadiusBottom?: number;
12+
}
13+
function getJustifyContent(
14+
position?: Position
15+
): CSSProperties["justifyContent"] {
16+
switch (position) {
17+
case "left":
18+
return "flex-start";
19+
case "right":
20+
return "flex-end";
21+
case "centre":
22+
default:
23+
return "center";
24+
}
25+
}
26+
27+
export const StyledHeaderBar = styled.div<StyledHeaderBarProps>`
28+
display: flex;
29+
align-items: center;
30+
justify-content: ${(props) => getJustifyContent(props.position)};
31+
padding-top: ${(props) => props.padVertical}px;
32+
padding-bottom: ${(props) => props.padVertical}px;
33+
padding-left: ${(props) => props.padHorizontal}px;
34+
padding-right: ${(props) => props.padHorizontal}px;
35+
background-color: ${(props) => props.backgroundColor}px;
36+
border-top-left-radius: ${(props) => props.borderRadiusTop}px;
37+
border-top-right-radius: ${(props) => props.borderRadiusTop}px;
38+
border-bottom-left-radius: ${(props) => props.borderRadiusBottom}px;
39+
border-bottom-right-radius: ${(props) => props.borderRadiusBottom}px;
40+
`;

0 commit comments

Comments
 (0)