Skip to content

Commit

Permalink
Merge pull request #66 from Lewan24/main
Browse files Browse the repository at this point in the history
Add setting custom classes and styles to appointments
  • Loading branch information
valincius committed Jun 12, 2023
2 parents bcbb0aa + 3f92f6c commit 141142d
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 18 deletions.
2 changes: 2 additions & 0 deletions BlazorScheduler/Components/Appointment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public partial class Appointment : ComponentBase, IDisposable
[Parameter] public DateTime Start { get; set; }
[Parameter] public DateTime End { get; set; }
[Parameter] public string? Color { get; set; }
[Parameter] public string? Class { get; set; }
[Parameter] public string? Style { get; set; }

private bool _isVisible = true;
public bool IsVisible
Expand Down
2 changes: 1 addition & 1 deletion BlazorScheduler/Components/Scheduler.razor
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
@foreach (var week in GetDaysInRange().Chunk(7))
{
var (start, end) = (week.First(), week.Last());
<SchedulerWeek Start="start" End="end" Appointments="GetAppointmentsInRange(start, end)" @key="week" />
<SchedulerWeek Start="start" End="end" Appointments="GetAppointmentsInRange(start, end)" @key="week"/>
}
</CascadingValue>
</div>
Expand Down
5 changes: 4 additions & 1 deletion BlazorScheduler/Components/Scheduler.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public partial class Scheduler : IAsyncDisposable
[Parameter] public RenderFragment Appointments { get; set; } = null!;
[Parameter] public RenderFragment<Scheduler>? HeaderTemplate { get; set; }
[Parameter] public RenderFragment<DateTime>? DayTemplate { get; set; }

[Parameter] public string? RootDaysGroupInWeekStyle { get; set; }
[Parameter] public string? RootAppointmentOverflowStyle { get; set; }
[Parameter] public string? RootDayClass { get; set; }
[Parameter] public string? RootDayStyle { get; set; }
[Parameter] public Func<DateTime, DateTime, Task>? OnRequestNewData { get; set; }
[Parameter] public Func<DateTime, DateTime, Task>? OnAddingNewAppointment { get; set; }
[Parameter] public Func<DateTime, Task>? OnOverflowAppointmentClick { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@namespace BlazorScheduler.Internal.Components

<div class="appointment @Classes.AsString()"
style="--start: @Start; --end: @End; --order: @Order; background-color: @Appointment.Color;"
<div class="appointment @Classes.AsString() @Appointment.Class"
style="--start: @Start; --end: @End; --order: @Order; background-color: @Appointment.Color; @Appointment.Style"
@onmousedown="OnMouseDown" @onmouseup="OnMouseUp" @onmousemove="OnMouseMove">
@Appointment.RenderChildContent()
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@namespace BlazorScheduler.Internal.Components

<div class="appointment appointment-timed @Classes.AsString()" style="--start: @Start; --order: @Order;" @onmousedown="OnMouseDown" @onmouseup="OnMouseUp" @onmousemove="OnMouseMove">
<div class="appointment appointment-timed @Classes.AsString() @Appointment.Class" style="--start: @Start; --order: @Order; @Appointment.Style" @onmousedown="OnMouseDown" @onmouseup="OnMouseUp" @onmousemove="OnMouseMove">
<span class="dot" style="background-color: @Appointment.Color;"></span>
@Appointment.RenderChildContent()
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@namespace BlazorScheduler.Internal.Components

<div class="appointment" style="--start: @Start; --end: @Start; --order: @Order;" @onclick="e => Task.FromResult(Scheduler.OnOverflowAppointmentClick?.Invoke(Day))">
<div class="appointment" style="--start: @Start; --end: @Start; --order: @Order; @Style" @onclick="e => Task.FromResult(Scheduler.OnOverflowAppointmentClick?.Invoke(Day))">
@Scheduler.PlusOthersText.Replace("{n}", AppointmentCount.ToString())
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public partial class SchedulerAppointmentOverflow
[Parameter] public int AppointmentCount { get; set;}
[Parameter] public int Start { get; set; }
[Parameter] public int Order { get; set; }
[Parameter] public string? Style { get; set; }
}
}
2 changes: 1 addition & 1 deletion BlazorScheduler/Internal/Components/SchedulerDay.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@namespace BlazorScheduler.Internal.Components

<div class="day @Classes.AsString()" @onmousedown="OnMouseDown" data-date="@Day.Date.ToString("yyyyMMdd")">
<div class="day @Classes.AsString() @Scheduler.RootDayClass" style="@Scheduler.RootDayStyle" @onmousedown="OnMouseDown" data-date="@Day.Date.ToString("yyyyMMdd")">
@if (Scheduler.DayTemplate != null)
{
@Scheduler.DayTemplate(Day)
Expand Down
6 changes: 3 additions & 3 deletions BlazorScheduler/Internal/Components/SchedulerWeek.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@namespace BlazorScheduler.Internal.Components

<div class="week">
<div class="days" style="--maxAppointments: @MaxVisibleAppointmentsThisWeek">
<div class="days" style="--maxAppointments: @MaxVisibleAppointmentsThisWeek; @Scheduler.RootDaysGroupInWeekStyle">
@for (var dt = Start; dt <= End; dt = dt.AddDays(1))
{
<SchedulerDay Day="dt" @key="dt" />
<SchedulerDay Day="dt" @key="dt"/>
}
</div>

Expand Down Expand Up @@ -39,7 +39,7 @@
AppointmentCount="numOverFlowAppointments"
Start="(dt.DayOfWeek - Scheduler.StartDayOfWeek + 7) % 7"
Order="MaxNumOfAppointmentsPerDay"
@key="dt" />
@key="dt" Style="@Scheduler.RootAppointmentOverflowStyle" />
}
}
</div>
Expand Down
6 changes: 3 additions & 3 deletions BlazorScheduler/wwwroot/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
.scheduler > .month > .week > .days {
display: flex;
justify-content: space-around;
height: max(8.313rem, calc(1.5rem + 5px + 8px + var(--maxAppointments) * 1.2rem));
height: max(8.313rem, calc(1.5rem + 5px + 8px + var(--maxAppointments) * 1.5rem));
}

.scheduler > .month > .week.header {
Expand Down Expand Up @@ -120,12 +120,12 @@
.scheduler > .month > .week > .appointments > .appointment {
position: absolute;
left: calc(var(--start) / 7 * 100%);
top: max(10px, calc(15px + (var(--order) * 1.2rem)));
top: max(10px, calc(15px + (var(--order) * 1.5rem)));
border-radius: 2px;
margin-left: 2px;
width: calc((var(--end) - var(--start) + 1) / 7 * 100% - 4px);
padding-left: 4px;
font-size: .75rem;
font-size: .95rem;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
Expand Down
2 changes: 1 addition & 1 deletion DemoApp/AppointmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public IEnumerable<AppointmentDto> GetAppointments(DateTime start, DateTime end)

private readonly List<AppointmentDto> AllAppointments = new()
{
new AppointmentDto { Title = "Hello 1", Start = DateTime.Now, End = DateTime.Now.AddHours(1), Color = "yellow" },
new AppointmentDto { Title = "Hello 1", Start = DateTime.Now, End = DateTime.Now.AddHours(1), Color = "yellow", Class = "bg-dark text-white"},
new AppointmentDto { Title = "Hello 2", Start = DateTime.Now.AddDays(3), End = DateTime.Now.AddDays(3).AddHours(1), Color = "red" },

new AppointmentDto { Title = "Hello 3", Start = DateTime.Today, End = DateTime.Today.AddDays(1), Color = "yellow" },
Expand Down
1 change: 1 addition & 0 deletions DemoApp/Models/AppointmentDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public class AppointmentDto
public DateTime Start { get; set; }
public DateTime End { get; set; }
public string Color { get; set; }
public string? Class { get; set; }

Check warning on line 11 in DemoApp/Models/AppointmentDto.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-pages

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 11 in DemoApp/Models/AppointmentDto.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-pages

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 11 in DemoApp/Models/AppointmentDto.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-pages

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
}
}
2 changes: 1 addition & 1 deletion DemoApp/Pages/Basic.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Appointments>
@foreach (var app in _appointments)
{
<Appointment Start="@app.Start" End="@app.End" Color="@app.Color" OnReschedule="(start, end) => HandleReschedule(app, start, end)">
<Appointment Start="@app.Start" End="@app.End" Color="@app.Color" OnReschedule="(start, end) => HandleReschedule(app, start, end)" Class="@app.Class">
@app.Title
@if (context.IsTimed)
{
Expand Down
34 changes: 31 additions & 3 deletions DemoApp/Pages/Configuration.razor
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@
<MudItem xs="12" md="6">
<MudTextField @bind-Value="_newAppointmentText" Label="New Appointment Text" />
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="_classes" Label="Classes (set to every appointment) (eg. could be bootstrap if installed)" />
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="_styles" Label="Custom style (set to every appointment)" />
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="_rootDaysGroupInWeekStyles" Label="Custom style (add to global days group style)" />
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="_rootAppointmentOverflowStyle" Label="Custom style for overflow appointment (+{n} ...)" />
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="_rootDayClass" Label="Classes for root every day in weeks (eg. could be bootstrap if installed)" />
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="_rootDayStyle" Label="Custom style for every day in week" />
</MudItem>
<MudItem xs="12" md="6">
<MudButton OnClick="AddAppointments" Variant="Variant.Filled" Color="Color.Primary">Add appointments</MudButton>
<MudButton OnClick="ClearAppointments" Variant="Variant.Filled" Color="Color.Error">Clear appointments</MudButton>
Expand All @@ -63,11 +81,14 @@
TodayButtonText="@_todayButtonText"
PlusOthersText="@_plusOthersText"
NewAppointmentText="@_newAppointmentText"
EnableAppointmentsCreationFromScheduler="@_enableAppCreationFromScheduler">
EnableAppointmentsCreationFromScheduler="@_enableAppCreationFromScheduler"
RootDaysGroupInWeekStyle="@_rootDaysGroupInWeekStyles"
RootAppointmentOverflowStyle="@_rootAppointmentOverflowStyle"
RootDayClass="@_rootDayClass" RootDayStyle="@_rootDayStyle">
<Appointments>
@foreach (var app in _appointments)
{
<Appointment Start="@app.Start" End="@app.End" Color="@app.Color" OnReschedule="(start, end) => HandleReschedule(app, start, end)">
<Appointment Start="@app.Start" End="@app.End" Color="@app.Color" OnReschedule="(start, end) => HandleReschedule(app, start, end)" Class="@_classes" Style="@_styles">
@app.Title
</Appointment>
}
Expand All @@ -89,7 +110,14 @@
private string _todayButtonText = "Today";
private string _plusOthersText = "+ {n} others";
private string _newAppointmentText = "New Appointment";


private string _classes = "";
private string _styles = "";
private string _rootDaysGroupInWeekStyles = "";
private string _rootAppointmentOverflowStyle = "";
private string _rootDayClass = "";
private string _rootDayStyle = "";

Task OnAddingNewAppointment(DateTime start, DateTime end)
{
_appointments.Add(new AppointmentDto { Start = start, End = end, Title = "A newly added appointment!", Color = "aqua" });
Expand Down

0 comments on commit 141142d

Please sign in to comment.