Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 016890f

Browse files
authored
Merge branch 'main' into bugfix/250
2 parents bfbc2b5 + 88793ef commit 016890f

6 files changed

Lines changed: 723 additions & 371 deletions

File tree

Lines changed: 158 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
@page "/components/calendar"
22

3-
<PageHeader Title="Calendar 日历">
4-
按照日历形式展示数据或日期的容器。
5-
</PageHeader>
6-
7-
<LayoutContent AnchorItems="@(new[]{"示例"})">
3+
<PageLayout Title="Calendar 日历" Description="按照日历形式展示数据或日期的容器。"
4+
Anchors="@(new[]{"事项日历面板","卡片日历","自定义高亮显示的日期","自定义日期的范围","更改每周的第一天","设置周的文本","自定义标题","自定义单元格的内容"})"
5+
ComponentType="typeof(TCalendar)">
86
<Example Title="事项日历面板">
97
<Description>在日期中可显示事项的日期显示容器。常用于有足够空间,且需要承载或显示事项信息时使用。</Description>
108
<RunContent>
@@ -13,8 +11,162 @@
1311
<CodeContent>
1412
@Code.Create(@"
1513
```cshtml-razor
14+
<TCalendar />
15+
```
16+
")
17+
</CodeContent>
18+
</Example>
19+
<Example Title="卡片日历">
20+
<Description></Description>
21+
<RunContent>
22+
<TCalendar Card/>
23+
</RunContent>
24+
<CodeContent>
25+
@Code.Create(@"
26+
```cshtml-razor
27+
<TCalendar Card/>
28+
```
29+
")
30+
</CodeContent>
31+
</Example>
32+
<Example Title="自定义高亮显示的日期">
33+
<Description>组件默认高亮“今天”或“当前月份”</Description>
34+
<RunContent>
35+
<TCalendar Multiple SelectedDates="new(){ new(2023,8,7), new(2023,9,6), new(2023,7,14) }"/>
36+
</RunContent>
37+
<CodeContent>
38+
@Code.Create(@"
39+
```cshtml-razor
40+
<TCalendar Multiple SelectedDates=""new(){ new(2023,8,7), new(2023,9,6), new(2023,7,14) }""/>
41+
```
42+
")
43+
</CodeContent>
44+
</Example>
45+
<Example Title="自定义日期的范围">
46+
<Description>
47+
<code>StartDate</code> 开始日期,<code>EndDate</code> 结束日期,超出范围的日期将不可选中
48+
</Description>
49+
<RunContent>
50+
<TCalendar StartDate="new(2023,7,1)" EndDate="new(2024,5,18)"/>
51+
</RunContent>
52+
<CodeContent>
53+
@Code.Create(@"
54+
```cshtml-razor
55+
<TCalendar StartDate=""new(2023,7,1)"" EndDate=""new(2024,5,18)""/>
56+
```
57+
")
58+
</CodeContent>
59+
</Example>
60+
<Example Title="更改每周的第一天">
61+
<Description></Description>
62+
<RunContent>
63+
<TCalendar FirstDayOfWeek="DayOfWeek.Wednesday"/>
64+
</RunContent>
65+
<CodeContent>
66+
@Code.Create(@"
67+
```cshtml-razor
68+
<TCalendar FirstDayOfWeek=""DayOfWeek.Wednesday""/>
69+
```
70+
")
71+
</CodeContent>
72+
</Example>
73+
<Example Title="设置周的文本">
74+
<Description></Description>
75+
<RunContent>
76+
<TCalendar>
77+
<WeekContent>
78+
@if ( context == DayOfWeek.Sunday )
79+
{
80+
<text>
81+
<span style="color:red">星期天</span>
82+
</text>
83+
}
84+
else
85+
{
86+
@($"星期{(int)context}")
87+
}
88+
</WeekContent>
89+
</TCalendar>
90+
</RunContent>
91+
<CodeContent>
92+
@Code.Create(@"
93+
```cshtml-razor
94+
<TCalendar>
95+
<WeekContent>
96+
@if ( context == DayOfWeek.Sunday )
97+
{
98+
<text>
99+
<span style=""color:red"">星期天</span>
100+
</text>
101+
}
102+
else
103+
{
104+
@($""星期{(int)context}"")
105+
}
106+
</WeekContent>
107+
</TCalendar>
108+
```
109+
")
110+
</CodeContent>
111+
</Example>
112+
<Example Title="自定义标题">
113+
<Description></Description>
114+
<RunContent>
115+
<TCalendar TitleText="TDesignBlazor 开发计划" />
116+
117+
<TCalendar>
118+
<TitleContent>
119+
<TIcon Name="IconName.Calendar"/> 2.0发布计划
120+
</TitleContent>
121+
</TCalendar>
122+
</RunContent>
123+
<CodeContent>
124+
@Code.Create(@"
125+
```cshtml-razor
126+
<TCalendar TitleText=""TDesignBlazor 开发计划"" />
127+
128+
<TCalendar>
129+
<TitleContent>
130+
<TIcon Name=""IconName.Calendar""/> 2.0发布计划
131+
</TitleContent>
132+
</TCalendar>
133+
```
134+
")
135+
</CodeContent>
136+
</Example>
137+
<Example Title="自定义单元格的内容">
138+
<Description></Description>
139+
<RunContent>
140+
<TCalendar>
141+
<CellContent>
142+
@if ( context.date.Day == 9 && context.date.Month == 8 && context.mode == CalendarMode.Month )
143+
{
144+
<TTag Theme="Theme.Primary">立秋</TTag>
145+
}
146+
@if ( context.date.Month == 8 && context.mode == CalendarMode.Year )
147+
{
148+
<TTag Theme="Theme.Danger">父亲的生日</TTag>
149+
}
150+
</CellContent>
151+
</TCalendar>
152+
</RunContent>
153+
<CodeContent>
154+
@Code.Create(@"
155+
```cshtml-razor
156+
<TCalendar>
157+
<CellContent>
158+
@if ( context.date.Day == 9 && context.date.Month == 8 && context.mode == CalendarMode.Month )
159+
{
160+
<TTag Theme=""Theme.Primary"">立秋</TTag>
161+
}
162+
@if ( context.date.Month == 8 && context.mode == CalendarMode.Year )
163+
{
164+
<TTag Theme=""Theme.Danger"">父亲的生日</TTag>
165+
}
166+
</CellContent>
167+
</TCalendar>
16168
```
17169
")
18170
</CodeContent>
19171
</Example>
20-
</LayoutContent>
172+
</PageLayout>

doc/TDesign.Docs.Shared/Pages/TestPage.razor

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@
33
@layout EmptyLayout
44

55
@*<div style="width:180px">
6-
<TSelect @bind-Value="Value">
7-
<TSelectOption Value="1" Label="选项1">选项1</TSelectOption>
8-
<TSelectOption Value="2" Label="选项2">选项2</TSelectOption>
9-
</TSelect>
6+
<TSelect @bind-Value="Value">
7+
@for ( var i = 1; i < 11; i++ )
8+
{
9+
int index = i;
10+
<TSelectOption @key="i" Value="@index" Label="@($"选项{index}")"/>
11+
}
12+
</TSelect>
1013
</div>
11-
12-
@code{
14+
Choose: @Value
15+
@code {
1316
int Value { get; set; } = 1;
1417
}*@
18+
19+
<TCalendar Card FirstDayOfWeek="DayOfWeek.Sunday" />
20+
<TCalendar Card FirstDayOfWeek="DayOfWeek.Monday" />
21+
<TCalendar Card FirstDayOfWeek="DayOfWeek.Tuesday" />
22+
<TCalendar Card FirstDayOfWeek="DayOfWeek.Wednesday" />
23+
<TCalendar Card FirstDayOfWeek="DayOfWeek.Thursday" />
24+
<TCalendar Card FirstDayOfWeek="DayOfWeek.Friday" />
25+
<TCalendar Card FirstDayOfWeek="DayOfWeek.Saturday" />

src/TDesign/Components/Forms/TSelect.razor

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
<ChildContent>
77
<div class="t-select__wrap">
88
<div class="@GetCssClassString()">
9-
<TInputText @bind-Value="SelectedLabel" Readonly SuffixIcon="@(RefPopup.Visible?IconName.ChevronUp:IconName.ChevronDown)" AutoWidth="AutoWidth" placeholder="@Placeholder" Disabled="Disabled" Size="Size" />
10-
9+
<TInputText @bind-Value="SelectedLabel" Readonly SuffixIcon="@(RefPopup.Visible?IconName.ChevronUp:IconName.ChevronDown)" AutoWidth="AutoWidth" placeholder="@Placeholder" Disabled="Disabled" Size="Size" AdditionalClass="@InputClass" AdditionalStyle="@InputStyle" />
1110
</div>
1211
</div>
1312
</ChildContent>

src/TDesign/Components/Forms/TSelect.razor.cs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,22 @@ public partial class TSelect<TValue>
2323
[ParameterApiDoc("无边框样式")]
2424
[Parameter][CssClass("t-select-input--borderless")] public bool Borderless { get; set; }
2525

26-
[ParameterApiDoc("占位符")]
27-
[Parameter] public string? Placeholder { get; set; }
26+
/// <summary>
27+
/// 文本框占位字符串。
28+
/// </summary>
29+
[ParameterApiDoc("占位符",Value="请选择")]
30+
[Parameter] public string? Placeholder { get; set; } = "请选择";
31+
32+
/// <summary>
33+
/// 文本框的额外 class。
34+
/// </summary>
35+
[ParameterApiDoc("文本框的额外 class")]
36+
[Parameter]public string? InputClass { get; set; }
37+
/// <summary>
38+
/// 文本框的额外 style。
39+
/// </summary>
40+
[ParameterApiDoc("文本框的额外 style")]
41+
[Parameter] public string? InputStyle { get; set; }
2842
/// <summary>
2943
/// Popup 组件的引用。
3044
/// </summary>
@@ -35,24 +49,32 @@ public partial class TSelect<TValue>
3549
/// </summary>
3650
internal string? SelectedLabel { get; set; }
3751

38-
protected override async Task OnAfterRenderAsync(bool firstRender)
52+
bool _initValue;
53+
54+
protected override void OnAfterRender(bool firstRender)
3955
{
40-
await base.OnAfterRenderAsync(firstRender);
4156
if ( firstRender )
4257
{
43-
if ( Value is not null )
58+
if ( Value is not null && !_initValue )
4459
{
4560
var initialSelectedOption = ChildComponents.OfType<TSelectOption<TValue>>().FirstOrDefault(m => Value.Equals(m.Value));
4661

4762
if ( initialSelectedOption != null )
4863
{
49-
await SelectValue(initialSelectedOption.Value, initialSelectedOption.Label);
50-
await this.Refresh();
64+
Value = initialSelectedOption.Value;
65+
SelectedLabel = initialSelectedOption.Label;
66+
_initValue = true;
67+
StateHasChanged();
5168
}
5269
}
5370
}
5471
}
5572

73+
protected override async Task OnAfterRenderAsync(bool firstRender)
74+
{
75+
76+
}
77+
5678

5779
/// <summary>
5880
/// 选择指定的值。
@@ -65,6 +87,7 @@ public async Task SelectValue(TValue? value, string? label)
6587
await ValueChanged.InvokeAsync(value);
6688
await OnValueSelected.InvokeAsync(value);
6789
SelectedLabel = label;
90+
StateHasChanged();
6891
}
6992

7093
protected override void BuildCssClass(ICssClassBuilder builder)

0 commit comments

Comments
 (0)