Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,44 @@
<title>Calendar</title>
<link
rel="stylesheet"
href="styles/index.scss"
href="styles/main.scss"
/>
</head>
<body>
<h1>Calendar</h1>
<div class="calendar calendar--start-day-sun calendar--month-length-31">
<div class="calendar__container">
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
<div class="calendar__day"></div>
</div>
</div>
</body>
</html>
8 changes: 8 additions & 0 deletions src/styles/base/base.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*::before,
*::after {
box-sizing: border-box;
}

body {
margin: 0;
}
56 changes: 56 additions & 0 deletions src/styles/blocks/calendar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.calendar {
@include flex-center;

min-height: 100vh;

&__container {
display: flex;
flex-wrap: wrap;
gap: $gap;
width: $calendar-width;
padding: $padding;
box-sizing: border-box;
}

&__day {
width: $day-size;
height: $day-size;
background-color: $color-light-gray;
border: $border solid $color-black;
box-sizing: border-box;
transition:
transform 0.5s ease,
background-color 0.5s ease;

@include flex-center;

font-family: Arial, sans-serif;
font-size: 30px;

@for $i from 1 through 31 {
&:nth-child(#{$i})::before {
content: '#{$i}';
}
}

&:hover {
background-color: $color-pink;
transform: translateY(-20px);
cursor: pointer;
}
}

@each $day, $index in $days {
&--start-day-#{$day} .calendar__day:first-child {
margin-left: $index * ($day-size + $gap);
}
}

@for $length from 28 through 31 {
&--month-length-#{$length} {
.calendar__day:nth-child(n + #{$length + 1}) {
display: none;
}
}
}
}
3 changes: 0 additions & 3 deletions src/styles/index.scss

This file was deleted.

4 changes: 4 additions & 0 deletions src/styles/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import './utils/variables';
@import './utils/mixins';
@import './base/base';
@import './blocks/calendar';
5 changes: 5 additions & 0 deletions src/styles/utils/mixins.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@mixin flex-center {
display: flex;
justify-content: center;
align-items: center;
}
18 changes: 18 additions & 0 deletions src/styles/utils/variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$day-size: 100px;
$columns: 7;
$gap: 1px;
$border: 1px;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates the implementation detail "Each day is a grey (#eee) 100px square (including 1px black border)."

$border is declared as 1 without a unit. When used as border: $border solid $color-black; this will produce an invalid CSS value (e.g. 1 solid #000). Add the unit: $border: 1px; so the output becomes 1px solid #000.

$padding: 10px;
$days: (
sun: 0,
mon: 1,
tue: 2,
wed: 3,
thu: 4,
fri: 5,
sat: 6
);
Comment on lines 6 to 14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the requirement "The month should start at the correct column (Monday is the 1st, Friday is the 5th)."

The $days map currently maps mon: 0, tue: 1, ... sun: 6. Since the calendar layout uses Sunday as the first column, the map values must represent column indices starting from Sunday = 0. With the current mapping a --start-day-mon modifier will set margin-left to 0 columns (placing the 1st on Sunday) instead of Monday. Change the map to reflect column indices from Sunday, e.g.:
( sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 ) so @each produces correct offsets.

$color-pink: #FFBFCB;
$color-black: #000;
$color-light-gray: #eee;
$calendar-width: ($day-size * $columns) + ($gap * ($columns - 1)) + ($padding * 2);
Loading