Skip to content

Commit 5e93bb5

Browse files
authored
feat(DatetimeRange): simplify SCSS selectors for start and end (#7098)
* refactor: 精简代码 * refactor: 增加逻辑不是当前月日期不参与 Range
1 parent 164a42e commit 5e93bb5

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
@@ -57,16 +57,26 @@ private DateTime StartDate
5757
/// 获得/设置 日期样式
5858
/// </summary>
5959
private string? GetDayClass(DateTime day, bool overflow) => CssBuilder.Default()
60-
.AddClass("prev-month", day.Month < CurrentDate.Month)
61-
.AddClass("next-month", day.Month > CurrentDate.Month)
60+
.AddClass("prev-month", IsPrevMonth(day))
61+
.AddClass("next-month", IsNextMonth(day))
6262
.AddClass("current", day.Date == SelectValue.Date && Ranger == null && day.Month == SelectValue.Month && !overflow)
63-
.AddClass("start", Ranger != null && day == Ranger.SelectedValue.Start.Date)
64-
.AddClass("end", Ranger != null && day == Ranger.SelectedValue.End.Date)
65-
.AddClass("range", Ranger != null && day >= Ranger.SelectedValue.Start.Date && day <= Ranger.SelectedValue.End.Date)
63+
.AddClass("start", Ranger != null && day == Ranger.SelectedValue.Start.Date && IsCurrentMonth(day))
64+
.AddClass("end", Ranger != null && day == Ranger.SelectedValue.End.Date && IsCurrentMonth(day))
65+
.AddClass("range", IsRange(day) && IsCurrentMonth(day))
6666
.AddClass("today", day == DateTime.Today)
6767
.AddClass("disabled", IsDisabled(day) || overflow)
6868
.Build();
6969

70+
private bool IsPrevMonth(DateTime day) => day.Month < CurrentDate.Month;
71+
72+
private bool IsNextMonth(DateTime day) => day.Month > CurrentDate.Month;
73+
74+
private bool IsCurrentMonth(DateTime day) => day.Month == CurrentDate.Month;
75+
76+
private bool IsRange(DateTime day) => Ranger != null
77+
&& day >= Ranger.SelectedValue.Start.Date
78+
&& day <= Ranger.SelectedValue.End.Date;
79+
7080
private string? WrapperClassString => CssBuilder.Default("picker-panel-body-main-wrapper")
7181
.AddClass("is-open", _showClockPicker)
7282
.Build();

src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@use "../../wwwroot/scss/variables" as *;
1+
@use "../../wwwroot/scss/variables" as *;
22

33
.picker-panel {
44
--bb-picker-panel-body-width: 320px;
@@ -149,8 +149,8 @@
149149
}
150150

151151
&.current:not(.disabled),
152-
&.start:not(.next-month):not(.prev-month):not(.disabled),
153-
&.end:not(.next-month):not(.prev-month):not(.disabled) {
152+
&.start:not(.disabled),
153+
&.end:not(.disabled) {
154154
.cell {
155155
color: var(--bb-picker-panel-today-color);
156156

0 commit comments

Comments
 (0)