Skip to content

Commit

Permalink
Style foods placement
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-karlsson committed Mar 23, 2024
1 parent c0b6425 commit 4e39335
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
Binary file added client/public/images/council-background-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function App() {
backgroundPosition: "center",
height: "100vh",
width: "100vw",
minWidth: "0px",
};

const isActive = currentView !== "council";
Expand All @@ -33,7 +34,7 @@ function App() {
setTopic(topic);
setFoods(foods);

setBackgroundImageURL("/images/council-background.jpg");
setBackgroundImageURL("/images/council-background-test.png");

setCurrentView("council");
}
Expand Down
49 changes: 48 additions & 1 deletion client/src/components/Council.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,58 @@ function Council({ options }) {
alignItems: "center",
};

// Styles for the table container
const foodsContainerStyle = {
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: "80%",
display: "flex",
justifyContent: "space-around",
alignItems: "center",
};

const calculateShadow = (index, total) => {
const angle = (360 / total) * index;
const x = Math.cos((angle * Math.PI) / 180).toFixed(2);
const y = Math.sin((angle * Math.PI) / 180).toFixed(2);
return `${x * 3}px ${y * 3}px 5px rgba(0,0,0,0.5)`;
};

const foodItemStyle = (index, total) => {
const archHeightVW = 3; // Arch height in vw units
const verticalOffsetVW = 7; // Default value for wider screens

const middleIndex = (total - 1) / 2;

const a = archHeightVW / middleIndex ** 2;

const topValueVW = a * (index - middleIndex) ** 2;

return {
position: "absolute",
left: `${(index / (total - 1)) * 100}%`,
top: `calc(${topValueVW}vw - ${verticalOffsetVW}vw)`, // Use calc() to combine vw units and the fixed pixel offset
transform: "translate(-50%, -50%)",
boxShadow: calculateShadow(index, total),
};
};

return (
<div style={councilStyle}>
<h1>Welcome to the council {name}</h1>
<h1>Topic: {topic}</h1>
<h1>Foods: {foods.join(", ")}</h1>
<div style={foodsContainerStyle}>
{foods.map((food, index) => (
<div
key={index}
style={foodItemStyle(index, foods.length)}
>
{food}
</div>
))}
</div>
</div>
);
}
Expand Down
8 changes: 7 additions & 1 deletion client/src/components/Overlay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ function Overlay({ isActive, children }) {
backgroundColor: "rgba(0, 0, 0, 0.5)",
});
} else {
setOverlayStyle({});
setOverlayStyle({
position: "relative",
top: 0,
left: 0,
height: "100%",
width: "100%",
});
}
}, [isActive]);

Expand Down

0 comments on commit 4e39335

Please sign in to comment.