Skip to content

Commit 48289a4

Browse files
authored
feat(FlipClock): add ShowMonth parameter (#6222)
* feat: 增加 ShowMonth 参数 * doc: 增加示例 * test: 增加单元测试 * refactor: 更新变量名称
1 parent 1c0abc4 commit 48289a4

File tree

8 files changed

+53
-3
lines changed

8 files changed

+53
-3
lines changed

src/BootstrapBlazor.Server/Components/Samples/FlipClocks.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<FlipClock></FlipClock>
1010
</DemoBlock>
1111

12+
<DemoBlock Title="@Localizer["ShowMonthText"]" Introduction="@Localizer["ShowMonthIntro"]" Name="ShowDay">
13+
<FlipClock ShowMonth="true" ShowDay="true"></FlipClock>
14+
</DemoBlock>
15+
1216
<DemoBlock Title="@Localizer["ShowDayText"]" Introduction="@Localizer["ShowDayIntro"]" Name="ShowDay">
1317
<FlipClock ShowDay="true"></FlipClock>
1418
</DemoBlock>

src/BootstrapBlazor.Server/Components/Samples/FlipClocks.razor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ private Task OnCompletedAsync()
5050
/// <returns></returns>
5151
private AttributeItem[] GetAttributes() =>
5252
[
53+
new()
54+
{
55+
Name = nameof(FlipClock.ShowMonth),
56+
Description = Localizer["ShowMonth_Description"],
57+
Type = "boolean",
58+
ValueList = "true|false",
59+
DefaultValue = "false"
60+
},
5361
new()
5462
{
5563
Name = nameof(FlipClock.ShowDay),

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6802,6 +6802,8 @@
68026802
"FlipClocksDescription": "Used for website timing or countdown",
68036803
"BaseUsageText": "Basic usage",
68046804
"BaseUsageIntro": "Synchronize display of current time",
6805+
"ShowMonthText": "Show Month",
6806+
"ShowMonthIntro": "Display month information by setting <code>ShowMonth=\"true\"</code>",
68056807
"ShowDayText": "Show Day",
68066808
"ShowDayIntro": "Display day information by setting <code>ShowDay=\"true\"</code>",
68076809
"ShowMinuteText": "not display hours and minutes",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6804,6 +6804,8 @@
68046804
"BaseUsageIntro": "同步显示当前时间",
68056805
"ShowDayText": "显示日",
68066806
"ShowDayIntro": "通过设置 <code>ShowDay=\"true\"</code> 显示日信息",
6807+
"ShowMonthText": "显示月",
6808+
"ShowMonthIntro": "通过设置 <code>ShowMonth=\"true\"</code> 显示月信息",
68076809
"ShowMinuteText": "不显示时、分",
68086810
"ShowMinuteIntro": "通过设置 <code>ShowHour=\"false\"</code> <code>ShowMinute=\"false\"</code> 不显示小时、分钟信息",
68096811
"ShowSecondText": "不显示秒",

src/BootstrapBlazor/Components/FlipClock/FlipClock.razor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
@attribute [BootstrapModuleAutoLoader(JSObjectReference = true)]
44

55
<div @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" id="@Id">
6+
@if (ShowMonth)
7+
{
8+
<div class="bb-flip-clock-list month">
9+
@RenderItem(3)
10+
@RenderItem(10)
11+
</div>
12+
}
13+
614
@if (ShowDay)
715
{
816
<div class="bb-flip-clock-list day">

src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ namespace BootstrapBlazor.Components;
1111
/// </summary>
1212
public partial class FlipClock
1313
{
14+
/// <summary>
15+
/// 获得/设置 是否显示 Month 默认 false
16+
/// </summary>
17+
[Parameter]
18+
public bool ShowMonth { get; set; }
19+
1420
/// <summary>
1521
/// 获得/设置 是否显示 Day 默认 false
1622
/// </summary>

src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function init(id, options) {
1414
return;
1515
}
1616

17+
const listMonth = el.querySelector('.bb-flip-clock-list.month');
1718
const listDay = el.querySelector('.bb-flip-clock-list.day');
1819
const listHour = el.querySelector('.bb-flip-clock-list.hour');
1920
const listMinute = el.querySelector('.bb-flip-clock-list.minute');
@@ -37,6 +38,7 @@ export function init(id, options) {
3738
else {
3839
now = new Date();
3940
return {
41+
months: now.getMonth() + 1,
4042
days: now.getDate(),
4143
hours: now.getHours(),
4244
minutes: now.getMinutes(),
@@ -48,15 +50,16 @@ export function init(id, options) {
4850
const minutes = Math.floor(totalMilliseconds / (1000 * 60)) % 60;
4951
const hours = Math.floor(totalMilliseconds / (1000 * 60 * 60)) % 24;
5052
const days = Math.floor(totalMilliseconds / (1000 * 60 * 60 * 24));
51-
return { days, hours, minutes, seconds };
53+
return { months, days, hours, minutes, seconds };
5254
}
5355

56+
let lastMonth;
5457
let lastDay;
5558
let lastHour;
5659
let lastMinute;
5760
let lastSecond;
5861
const go = () => {
59-
const { days, hours, minutes, seconds } = getDate();
62+
const { months, days, hours, minutes, seconds } = getDate();
6063

6164
if (lastSecond !== seconds) {
6265
lastSecond = seconds;
@@ -74,7 +77,11 @@ export function init(id, options) {
7477
lastDay = days;
7578
setTime(listDay, days, countDown);
7679
}
77-
return { days, hours, minutes, seconds }
80+
if (lastMonth !== months) {
81+
lastDay = days;
82+
setTime(listMonth, months, countDown);
83+
}
84+
return { months, days, hours, minutes, seconds }
7885
}
7986

8087
let start = void 0

test/UnitTest/Components/FlipClockTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ public void ShowDay_Ok()
5959
cut.Contains("bb-flip-clock-list day");
6060
}
6161

62+
[Fact]
63+
public void ShowMonth_Ok()
64+
{
65+
var cut = Context.RenderComponent<FlipClock>();
66+
cut.DoesNotContain("bb-flip-clock-list month");
67+
68+
cut.SetParametersAndRender(pb =>
69+
{
70+
pb.Add(a => a.ShowMonth, true);
71+
});
72+
cut.Contains("bb-flip-clock-list month");
73+
}
74+
6275
[Fact]
6376
public async Task ViewMode_Ok()
6477
{

0 commit comments

Comments
 (0)