Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h4>@Localizer["SubTitle"]</h4>

<DemoBlock Title="@Localizer["BasicUsageTitle"]" Introduction="@Localizer["BasicUsageIntro"]" Name="Normal">
<Calendar ValueChanged="@OnValueChanged" />
<Calendar ValueChanged="@OnValueChanged" FirstDayOfWeek="DayOfWeek.Monday" />
<ConsoleLogger @ref="NormalLogger" />
</DemoBlock>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ private AttributeItem[] GetAttributes() =>
Type = "RenderFragment<CalendarCellValue>",
ValueList = " — ",
DefaultValue = " — "
},
new()
{
Name = nameof(Calendar.FirstDayOfWeek),
Description = Localizer["FirstDayOfWeek"],
Type = "DayOfWeek",
ValueList = " — ",
DefaultValue = "Sunday"
}
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ private AttributeItem[] GetAttributes() =>
DefaultValue = " — "
},
new()
{
Name = nameof(DateTimePicker<DateTime>.FirstDayOfWeek),
Description = Localizer["AttrFirstDayOfWeek"],
Type = "DayOfWeek",
ValueList = " — ",
DefaultValue = "Sunday"
},
new()
{
Name = "ViewMode",
Description = Localizer["Att9"],
Expand Down
6 changes: 4 additions & 2 deletions src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2572,7 +2572,8 @@
"FeatureShowHolidaysIntro": "<code>ShowHolidays</code> Whether to display holidays",
"OnGetDisabledDaysCallbackEvent": "Disable date callback method",
"AttrEnableDisabledDaysCache": "Whether to enable custom disabled date cache",
"AttrDisplayDisabledDayAsEmpty": "Display disabled date as an empty string"
"AttrDisplayDisabledDayAsEmpty": "Display disabled date as an empty string",
"AttrFirstDayOfWeek": "The first day of the week"
},
"BootstrapBlazor.Server.Components.Samples.TimePickers": {
"Title": "TimePicker",
Expand Down Expand Up @@ -3768,7 +3769,8 @@
"Chinese": "Chinese",
"Math": "Math",
"English": "English",
"Study": "Study"
"Study": "Study",
"FirstDayOfWeek": "The first day of the week"
},
"BootstrapBlazor.Server.Components.Samples.Cameras": {
"Title": "Camera",
Expand Down
6 changes: 4 additions & 2 deletions src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2572,7 +2572,8 @@
"FeatureShowHolidaysIntro": "<code>ShowHolidays</code> 是否显示假日",
"OnGetDisabledDaysCallbackEvent": "获得自定义禁用日期回调方法",
"AttrEnableDisabledDaysCache": "是否启用获得自定义禁用日期缓存",
"AttrDisplayDisabledDayAsEmpty": "显示禁用日期为空字符串"
"AttrDisplayDisabledDayAsEmpty": "显示禁用日期为空字符串",
"AttrFirstDayOfWeek": "设置每周第一天"
},
"BootstrapBlazor.Server.Components.Samples.TimePickers": {
"Title": "TimePicker 时间选择器",
Expand Down Expand Up @@ -3768,7 +3769,8 @@
"Chinese": "语文",
"Math": "数学",
"English": "英语",
"Study": "自习"
"Study": "自习",
"FirstDayOfWeek": "设置每周第一天"
},
"BootstrapBlazor.Server.Components.Samples.Cameras": {
"Title": "Camera 摄像头拍照组件",
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.5.0-beta11</Version>
<Version>9.4.11</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 16 additions & 2 deletions src/BootstrapBlazor/Components/Calendar/Calendar.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected override void OnInitialized()
PreviousMonth = Localizer[nameof(PreviousMonth)];
NextMonth = Localizer[nameof(NextMonth)];
Today = Localizer[nameof(Today)];
WeekLists = [.. Localizer[nameof(WeekLists)].Value.Split(',')];
WeekLists = GetWeekList();
PreviousWeek = Localizer[nameof(PreviousWeek)];
NextWeek = Localizer[nameof(NextWeek)];
WeekText = Localizer[nameof(WeekText)];
Expand All @@ -124,7 +124,7 @@ protected DateTime StartDate
get
{
var d = Value.AddDays(1 - Value.Day);
d = d.AddDays(0 - (int)d.DayOfWeek);
d = d.AddDays((int)FirstDayOfWeek - (int)d.DayOfWeek);
return d;
}
}
Expand Down Expand Up @@ -197,6 +197,12 @@ protected int GetWeekCount()
[Parameter]
public bool ShowYearButtons { get; set; } = true;

/// <summary>
/// 获得/设置 星期第一天 默认 <see cref="DayOfWeek.Sunday"/>
/// </summary>
[Parameter]
public DayOfWeek FirstDayOfWeek { get; set; } = DayOfWeek.Sunday;

/// <summary>
/// 选中日期时回调此方法
/// </summary>
Expand Down Expand Up @@ -297,4 +303,12 @@ private BodyTemplateContext GetBodyTemplateContext(DateTime week)
context.Values.AddRange(Enumerable.Range(0, 7).Select(i => CreateCellValue(week.AddDays(i))));
return context;
}
private List<string> GetWeekList()
{
var list = Localizer[nameof(WeekLists)].Value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();

// 调整顺序
var firstDayIndex = (int)FirstDayOfWeek;
return [.. list.Skip(firstDayIndex), .. list.Take(firstDayIndex)];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ private List<string> GetWeekList()

// 调整顺序
var firstDayIndex = (int)FirstDayOfWeek;
return list.Skip(firstDayIndex).Concat(list.Take(firstDayIndex)).ToList();
return [.. list.Skip(firstDayIndex), .. list.Take(firstDayIndex)];
}

private async Task UpdateDisabledDaysCache(bool force)
Expand Down