Skip to content

Commit

Permalink
Drop the term calendar-grid, replace it with time-grid
Browse files Browse the repository at this point in the history
This generalizes the CSS somewhat so that it applies to
the new timeline without too much boilerplate.
  • Loading branch information
nilmerg committed May 9, 2024
1 parent cf8c52d commit e760e2c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 21 deletions.
3 changes: 3 additions & 0 deletions library/Notifications/Widget/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@ public function getGrid(): BaseGrid
if ($this->grid === null) {
if ($this->getControls()->getViewMode() === self::MODE_MONTH) {
$this->grid = new MonthGrid($this, $this->getStyle(), $this->getModeStart());
$this->getAttributes()->get('class')->addValue('month');
} elseif ($this->getControls()->getViewMode() === self::MODE_WEEK) {
$this->grid = new WeekGrid($this, $this->getStyle(), $this->getModeStart());
$this->getAttributes()->get('class')->addValue('week');
} else {
$this->grid = new DayGrid($this, $this->getStyle(), $this->getModeStart());
$this->getAttributes()->get('class')->addValue('day');
}
}

Expand Down
14 changes: 13 additions & 1 deletion library/Notifications/Widget/Calendar/BaseGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ abstract class BaseGrid extends BaseHtmlElement
{
use Translation;

/** @var string The chronological order of entries is oriented horizontally */
protected const HORIZONTAL_FLOW_OF_TIME = 'horizontal-flow';

/** @var string The chronological order of entries is oriented vertically */
protected const VERTICAL_FLOW_OF_TIME = 'vertical-flow';

/** @var string Continuation of an entry that started on the previous grid */
protected const FROM_PREV_GRID = 'from-prev-grid';

Expand All @@ -54,7 +60,10 @@ abstract class BaseGrid extends BaseHtmlElement

protected $tag = 'div';

protected $defaultAttributes = ['class' => 'calendar-grid'];
protected $defaultAttributes = ['class' => ['time-grid']];

/** @var string The orientation of this grid's chronological order of entries */
protected $flowOfTime = self::HORIZONTAL_FLOW_OF_TIME;

/** @var EntryProvider */
protected $provider;
Expand Down Expand Up @@ -86,6 +95,9 @@ public function __construct(EntryProvider $provider, Style $style, DateTime $sta
$this->provider = $provider;
$this->style = $style;
$this->setGridStart($start);

// It's done here as there's no real need for this being dynamic
$this->defaultAttributes['class'][] = $this->flowOfTime;
}

public function getGridStart(): DateTime
Expand Down
4 changes: 2 additions & 2 deletions library/Notifications/Widget/Calendar/DayGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

class DayGrid extends BaseGrid
{
protected $flowOfTime = BaseGrid::VERTICAL_FLOW_OF_TIME;

public function setGridStart(DateTime $start): BaseGrid
{
if ($start->format('H:i:s') !== '00:00:00') {
Expand Down Expand Up @@ -114,8 +116,6 @@ protected function createSidebar(): BaseHtmlElement

protected function assemble()
{
$this->getAttributes()->add('class', 'day');

$this->addHtml(
$this->createHeader(),
$this->createSidebar(),
Expand Down
2 changes: 0 additions & 2 deletions library/Notifications/Widget/Calendar/DynamicGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ protected function createGridSteps(): Traversable

protected function assemble()
{
$this->getAttributes()->add('class', 'dynamic');

$this->style->addFor($this, [
'--primaryColumns' => $this->days,
'--columnsPerStep' => 48,
Expand Down
2 changes: 0 additions & 2 deletions library/Notifications/Widget/Calendar/MonthGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ protected function createSidebar(): BaseHtmlElement

protected function assemble()
{
$this->getAttributes()->add('class', 'month');

$this->addHtml(
$this->createHeader(),
$this->createSidebar(),
Expand Down
4 changes: 2 additions & 2 deletions library/Notifications/Widget/Calendar/WeekGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

class WeekGrid extends BaseGrid
{
protected $flowOfTime = BaseGrid::VERTICAL_FLOW_OF_TIME;

public function setGridStart(DateTime $start): BaseGrid
{
if ($start->format('w:H:i:s') !== '1:00:00:00') {
Expand Down Expand Up @@ -123,8 +125,6 @@ protected function createSidebar(): BaseHtmlElement

protected function assemble()
{
$this->getAttributes()->add('class', 'week');

$this->addHtml(
$this->createHeader(),
$this->createSidebar(),
Expand Down
22 changes: 11 additions & 11 deletions public/css/calendar.less
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
}

/**
* Basic rules for a calendar grid
* Basic rules for a time grid
*
* Required variables:
* - --primaryColumns: Number of primary columns
* - --primaryRows: Number of primary rows
* - --columnsPerStep: Number of columns per step
* - --rowsPerStep: Number of rows per step
*/
.calendar-grid {
.time-grid {
--sidebarWidth: 4em;
--headerHeight: 1.5em;
--minimumPrimaryColumnWidth: 2em;
Expand Down Expand Up @@ -175,7 +175,7 @@
}
}

.calendar-grid.month {
.calendar.month .time-grid {
--primaryColumns: 7; // days
--primaryRows: 6; // weeks
--columnsPerStep: 48; // 24 hours
Expand All @@ -189,7 +189,7 @@
}
}

.calendar-grid.week {
.calendar.week .time-grid {
--primaryColumns: 7; // days
--primaryRows: 24; // hours
--columnsPerStep: 4;
Expand All @@ -203,7 +203,7 @@
}
}

.calendar-grid.day {
.calendar.day .time-grid {
--primaryColumns: 1; // days
--primaryRows: 24; // hours
--columnsPerStep: 28;
Expand All @@ -217,7 +217,7 @@
}
}

.calendar-grid {
.time-grid {
display: grid;
grid-template-columns: var(--sidebarWidth) minmax(0, 1fr);
grid-template-rows: var(--headerHeight) minmax(0, 1fr);
Expand Down Expand Up @@ -258,9 +258,10 @@
font-size: 1.5em;
font-weight: normal;
}
}

.calendar-grid.month,
.calendar-grid.dynamic {
.time-grid {
&.horizontal-flow {
.entry {
&.two-way-gradient {
border-radius: 0;
Expand All @@ -283,8 +284,7 @@
}
}

.calendar-grid.week,
.calendar-grid.day {
&.vertical-flow {
.entry {
&.two-way-gradient {
border-radius: 0;
Expand Down Expand Up @@ -373,7 +373,7 @@
}

@light-mode: {
.calendar .entry {
.time-grid .entry {
mix-blend-mode: revert;
}
};
2 changes: 1 addition & 1 deletion public/css/schedule.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
display: flex;
flex-direction: column;

.calendar-grid {
.time-grid {
flex: 1 1 auto;
height: 0;
}
Expand Down

0 comments on commit e760e2c

Please sign in to comment.