69 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-11-01 17:27:41 +00:00
/* Copyright (C) 2024 Manuel Bustillo*/
2024-12-09 20:57:30 +01:00
import { Guest } from "@/app/lib/guest";
2024-11-01 18:25:00 +01:00
2024-11-03 08:18:24 +01:00
function Dish({ guest, rotation }: { guest: Guest, rotation?: number }) {
rotation = rotation || 0
return (
<div className={`m-3 w-24 h-24 rounded-full content-center text-center cursor-default`} style={{
rotate: `${360 - rotation}deg`,
backgroundColor: guest.color,
}}>
2024-11-03 08:18:24 +01:00
{guest.name}
</div>
)
}
2024-11-01 18:25:00 +01:00
function GuestRow({ guests }: { guests: Guest[] }) {
2024-11-03 08:18:24 +01:00
return (
<div className="justify-around flex flex-row">
{guests.map((guest) => <Dish key={guest.id} guest={guest} />)}
</div>
)
2024-11-01 18:25:00 +01:00
}
2024-11-03 08:18:24 +01:00
function RectangularTable({ guests }: { guests: Guest[] }) {
2024-11-01 18:25:00 +01:00
const halfwayThrough = Math.floor(guests.length / 2)
const arrayFirstHalf = guests.slice(0, halfwayThrough);
const arraySecondHalf = guests.slice(halfwayThrough, guests.length);
return (
2024-11-02 10:11:03 +01:00
<div className="m-12 h-64 bg-cyan-800 flex flex-col justify-between">
2024-11-01 18:25:00 +01:00
<GuestRow guests={arrayFirstHalf} />
<GuestRow guests={arraySecondHalf} />
</div>
)
2024-11-03 08:18:24 +01:00
}
function RoundedTable({ guests }: { guests: Guest[] }) {
const size = 500
const rotation = 360 / guests.length
return (
<div className={`m-12 rounded-full bg-cyan-800 relative z-0`} style={{ width: `${size}px`, height: `${size}px` }}>
{
guests.map((guest, index) => {
return (
<div key={guest.id} className={`border-dashed grid justify-items-center absolute inset-0`} style={{
rotate: `${index * rotation}deg`,
height: `${size}px`,
width: `${size}px`,
}}>
<Dish guest={guest} rotation={index * rotation} />
</div>
)
})
}
</div>
)
}
export function Table({ guests, style }: { guests: Guest[], style: "rectangular" | "rounded" }) {
return (
<>
{style === "rectangular" && <RectangularTable guests={guests} />}
{style === "rounded" && <RoundedTable guests={guests} />}
</>
)
2024-11-01 18:25:00 +01:00
}