Skip to content

Commit e53b005

Browse files
authored
feat(Calendar): update today cell style (#7381)
* style: 调整选中样式 * refactor: 重构代码 * refactor: 移除过期属性 * style: 更新样式 * refactor: 更新当日样式 * refactor: 更新代码
1 parent add522a commit e53b005

4 files changed

Lines changed: 38 additions & 25 deletions

File tree

src/BootstrapBlazor/Components/Calendar/Calendar.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@namespace BootstrapBlazor.Components
1+
@namespace BootstrapBlazor.Components
22
@inherits BootstrapComponentBase
33

44
<div @attributes="AdditionalAttributes" class="@ClassString">
@@ -33,7 +33,7 @@
3333
</div>
3434
</div>
3535
<div class="calendar-body">
36-
<table cellspacing="0" cellpadding="0" class="calendar-table">
36+
<table class="calendar-table">
3737
<thead>
3838
@if (HeaderTemplate != null)
3939
{
@@ -97,7 +97,7 @@
9797
</div>
9898
</div>
9999
<div class="calendar-body">
100-
<table cellspacing="0" cellpadding="0" class="calendar-table table-week">
100+
<table class="calendar-table table-week">
101101
<thead>
102102
@if (HeaderTemplate != null)
103103
{

src/BootstrapBlazor/Components/Calendar/Calendar.razor.cs

Lines changed: 4 additions & 18 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(argo@live.ca) Website: https://www.blazor.zone
@@ -9,7 +9,7 @@
99
namespace BootstrapBlazor.Components;
1010

1111
/// <summary>
12-
///
12+
/// 日历框组件
1313
/// </summary>
1414
public partial class Calendar
1515
{
@@ -243,14 +243,7 @@ protected async Task OnChangeYear(int offset)
243243
/// <param name="offset"></param>
244244
protected async Task OnChangeMonth(int offset)
245245
{
246-
if (offset == 0)
247-
{
248-
Value = DateTime.Today;
249-
}
250-
else
251-
{
252-
Value = Value.AddMonths(offset);
253-
}
246+
Value = offset == 0 ? DateTime.Today : Value.AddMonths(offset);
254247
if (ValueChanged.HasDelegate)
255248
{
256249
await ValueChanged.InvokeAsync(Value);
@@ -267,14 +260,7 @@ protected async Task OnChangeMonth(int offset)
267260
/// <param name="offset"></param>
268261
protected async Task OnChangeWeek(int offset)
269262
{
270-
if (offset == 0)
271-
{
272-
Value = DateTime.Today;
273-
}
274-
else
275-
{
276-
Value = Value.AddDays(offset);
277-
}
263+
Value = offset == 0 ? DateTime.Today : Value.AddDays(offset);
278264
WeekNumberText = Localizer[nameof(WeekNumberText), GetWeekCount()];
279265
if (ValueChanged.HasDelegate)
280266
{

src/BootstrapBlazor/Components/Calendar/Calendar.razor.scss

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
@use "../../wwwroot/scss/variables" as *;
1+
@use "../../wwwroot/scss/variables" as *;
2+
3+
[data-bs-theme='dark'] .calendar {
4+
--bb-calendar-selected-bg: #{$bb-calendar-selected-bg-dark};
5+
}
26

37
.calendar {
48
--bb-calendar-padding: #{$bb-calendar-padding};
@@ -21,6 +25,7 @@
2125
--bb-calendar-cell-hover-bg: #{$bb-calendar-cell-hover-bg};
2226
--bb-calendar-header-padding: #{$bb-calendar-header-padding};
2327
--bb-calendar-today-color: #{$bb-calendar-today-color};
28+
--bb-calendar-today-border-color: #{$bb-calendar-today-border-color};
2429
--bb-calendar-selected-color: #{$bb-calendar-selected-color};
2530
--bb-calendar-selected-bg: #{$bb-calendar-selected-bg};
2631
--bb-calendar-week-header-border-bottom: #{$bb-calendar-week-header-border-bottom};
@@ -111,6 +116,26 @@
111116

112117
&.is-today {
113118
color: var(--bb-calendar-today-color);
119+
120+
span {
121+
position: relative;
122+
123+
&::after {
124+
position: absolute;
125+
width: 2rem;
126+
height: 2rem;
127+
top: -6px;
128+
left: -8px;
129+
border-radius: 50%;
130+
border: 1px solid var(--bb-calendar-today-border-color);
131+
}
132+
}
133+
134+
&:not(.is-selected) {
135+
span::after {
136+
content: "";
137+
}
138+
}
114139
}
115140

116141
&.is-selected {

src/BootstrapBlazor/wwwroot/scss/variables.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// :root
1+
// :root
22
$bb-primary-color: #409eff;
33
$bb-primary-color-rgb: 64, 158, 255;
44
$bb-border-focus-color: #86b7fe;
@@ -114,8 +114,10 @@ $bb-calendar-cell-height: 85px;
114114
$bb-calendar-cell-hover-bg: rgba(var(--bs-body-color-rgb),.08);
115115
$bb-calendar-header-padding: 12px 0;
116116
$bb-calendar-today-color: #409eff;
117-
$bb-calendar-selected-color: #409eff;
118-
$bb-calendar-selected-bg: rgba(var(--bs-body-color-rgb),.12);
117+
$bb-calendar-selected-color: #fff;
118+
$bb-calendar-selected-bg: #409eff;
119+
$bb-calendar-selected-bg-dark: #15325b;
120+
$bb-calendar-today-border-color: #0078d4;
119121
$bb-calendar-week-header-border-bottom: 2px solid var(--bs-border-color);
120122
$bb-calendar-week-header-min-width: 52px;
121123
$bb-calendar-week-header-padding: 4px;

0 commit comments

Comments
 (0)