Make calendar stack like a normal calendar.

This commit is contained in:
2023-01-02 23:29:44 -05:00
parent 858d96f842
commit 7b9998e48a
2 changed files with 14 additions and 9 deletions

View File

@@ -11,6 +11,8 @@ import {
startOfMonth, startOfMonth,
} from "date-fns" } from "date-fns"
import { getDateColumnOffset } from "utils/date"
import { SIZES } from "styles/constants" import { SIZES } from "styles/constants"
import { AppLink as Link } from "components/elements" import { AppLink as Link } from "components/elements"
@@ -18,8 +20,8 @@ import Seek from "components/Seek"
const DayCardGrid = styled.div` const DayCardGrid = styled.div`
display: grid; display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); grid-template-columns: repeat(7, 1fr);
grid-gap: 20px; grid-gap: min(1.5vw, 20px);
margin-top: 20px; margin-top: 20px;
` `
const DayCard = styled.div` const DayCard = styled.div`
@@ -48,7 +50,7 @@ const DayCardBanner = styled.div`
padding: 5px 0px; padding: 5px 0px;
` `
const DayCardContent = styled.div` const DayCardContent = styled.div`
padding: 20px 25px; padding: 20%
` `
class Month extends Component { class Month extends Component {
@@ -64,12 +66,13 @@ class Month extends Component {
let dayCards = [] let dayCards = []
for (let i = 0; i < getDaysInMonth(currentDay); i++) { for (let i = 0; i < getDaysInMonth(currentDay); i++) {
const isDisabled = dayIndexesToInclude <= i && isThisMonth(currentDay) const isDisabled = dayIndexesToInclude <= i && isThisMonth(currentDay);
const day = new Date(year, month - 1, i + 1);
if (isDisabled) { if (isDisabled) {
dayCards.push( dayCards.push(
<DayCard disabled={isDisabled} key={i}> <DayCard disabled={isDisabled} key={i} style={{ gridColumnStart: getDateColumnOffset(i, day) }}>
<DayCardBanner> <DayCardBanner>
{format(new Date(year, month - 1, i + 1), "ddd")} {format(day, "ddd")}
</DayCardBanner> </DayCardBanner>
<DayCardContent>{i + 1}</DayCardContent> <DayCardContent>{i + 1}</DayCardContent>
</DayCard> </DayCard>
@@ -78,12 +81,12 @@ class Month extends Component {
dayCards.push( dayCards.push(
<Link <Link
key={i} key={i}
to={format(new Date(year, month - 1, i + 1), "/YYYY/MM/DD")} to={format(day, "/YYYY/MM/DD")}
style={{ textDecoration: "none" }} style={{ textDecoration: "none", gridColumnStart: getDateColumnOffset(i, day) }}
> >
<DayCard key={i}> <DayCard key={i}>
<DayCardBanner> <DayCardBanner>
{format(new Date(year, month - 1, i + 1), "ddd")} {format(day, "ddd")}
</DayCardBanner> </DayCardBanner>
<DayCardContent>{i + 1}</DayCardContent> <DayCardContent>{i + 1}</DayCardContent>
</DayCard> </DayCard>

View File

@@ -10,3 +10,5 @@ export const months = {
new Date(0, index).toLocaleDateString("en-US", { month: "long" }) new Date(0, index).toLocaleDateString("en-US", { month: "long" })
), ),
} }
export const getDateColumnOffset = (index, date) => index === 0 ? date.getDay() + 1 : undefined;