-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockViewComponent.cs
More file actions
223 lines (194 loc) · 8.61 KB
/
DockViewComponent.cs
File metadata and controls
223 lines (194 loc) · 8.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using System.Text.Json.Serialization;
namespace BootstrapBlazor.Components;
/// <summary>
/// <para lang="zh">DockContentItem 配置项子项对标 content 配置项内部 content 配置</para>
/// <para lang="en">DockContentItem configuration item sub-item corresponds to the content configuration item inside the content configuration item</para>
/// </summary>
public class DockViewComponent : DockViewComponentBase
{
/// <summary>
/// <para lang="zh">获得/设置 组件是否显示 Header 默认 true 显示</para>
/// <para lang="en">Gets or sets whether the component header is displayed. Default is true.</para>
/// </summary>
[Parameter]
public bool ShowHeader { get; set; } = true;
/// <summary>
/// <para lang="zh">获得/设置 组件 Title</para>
/// <para lang="en">Gets or sets the component title.</para>
/// </summary>
[Parameter]
public string? Title { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 组件 Title 宽度 默认 null 未设置</para>
/// <para lang="en">Gets or sets the component title width. Default is null (not set).</para>
/// </summary>
[Parameter]
public int? TitleWidth { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 组件 Title 样式 默认 null 未设置</para>
/// <para lang="en">Gets or sets the component title style. Default is null (not set).</para>
/// </summary>
[Parameter]
public string? TitleClass { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 Title 模板 默认 null 未设置</para>
/// <para lang="en">Gets or sets the title template. Default is null (not set).</para>
/// </summary>
[Parameter]
[JsonIgnore]
public RenderFragment? TitleTemplate { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 组件 Class 默认 null 未设置</para>
/// <para lang="en">Gets or sets the component class. Default is null (not set).</para>
/// </summary>
[Parameter]
public string? Class { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 组件是否可见 默认 true 可见</para>
/// <para lang="en">Gets or sets whether the component is visible. Default is true.</para>
/// </summary>
[Parameter]
public bool Visible { get; set; } = true;
/// <summary>
/// <para lang="zh">获得/设置 组件是否允许关闭 默认 null 使用 DockView 的配置</para>
/// <para lang="en">Gets or sets whether the component is allowed to be closed. Default is null (uses DockView configuration).</para>
/// </summary>
[Parameter]
public bool? ShowClose { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 组件唯一标识值 默认 null 未设置时取 Title 作为唯一标识</para>
/// <para lang="en">Gets or sets the unique identifier for the component. Default is null, uses Title as the identifier if not set.</para>
/// </summary>
[Parameter]
public string? Key { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 是否锁定 默认 null 未设置时取 DockView 的配置</para>
/// <para lang="en">Gets or sets whether the component is locked. Default is null (uses DockView configuration).</para>
/// </summary>
/// <remarks>锁定后无法拖动</remarks>
[Parameter]
public bool? IsLock { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 是否显示锁定按钮 默认 null 未设置时取 DockView 的配置</para>
/// <para lang="en">Gets or sets whether the lock button is displayed. Default is null (uses DockView configuration).</para>
/// </summary>
[Parameter]
public bool? ShowLock { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 是否悬浮 默认 null 未设置时取 DockView 的配置</para>
/// <para lang="en">Gets or sets whether the component is floating. Default is null (uses DockView configuration).</para>
/// </summary>
[Parameter]
public bool? IsFloating { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 是否显示可悬浮按钮 默认 null 未设置时取 DockView 的配置</para>
/// <para lang="en">Gets or sets whether the float button is displayed. Default is null (uses DockView configuration).</para>
/// </summary>
[Parameter]
public bool? ShowFloat { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 是否显示最大化按钮 默认 null 未设置时取 DockView 的配置</para>
/// <para lang="en">Gets or sets whether the maximize button is displayed. Default is null (uses DockView configuration).</para>
/// </summary>
[Parameter]
public bool? ShowMaximize { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 是否一直显示 默认 null 未设置时取 DockView 的配置</para>
/// <para lang="en">Gets or sets whether the component is always displayed. Default is null (uses DockView configuration).</para>
/// </summary>
[Parameter]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Renderer { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 是否显示标题前置图标 默认 false 不显示</para>
/// <para lang="en">Gets or sets whether the title bar icon is displayed. Default is false.</para>
/// </summary>
[Parameter]
[JsonIgnore]
public bool ShowTitleBar { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 标题前置图标 默认 null 未设置使用默认图标</para>
/// <para lang="en">Gets or sets the title bar icon. Default is null, uses the default icon if not set.</para>
/// </summary>
[Parameter]
[JsonIgnore]
public string? TitleBarIcon { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 标题前置图标 Url 默认 null 未设置使用默认图标</para>
/// <para lang="en">Gets or sets the title bar icon URL. Default is null, uses the default icon if not set.</para>
/// </summary>
[Parameter]
[JsonIgnore]
public string? TitleBarIconUrl { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 标题前置图标点击回调方法 默认 null</para>
/// <para lang="en">Gets or sets the callback method for clicking the title bar icon. Default is null.</para>
/// </summary>
[Parameter]
[JsonIgnore]
public Func<Task>? OnClickTitleBarCallback { get; set; }
[CascadingParameter]
[NotNull]
private DockViewV2? DockView { get; set; }
/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnInitialized()
{
base.OnInitialized();
Type = DockViewContentType.Component;
}
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="builder"></param>
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, "div");
builder.AddAttribute(10, "id", Id);
builder.AddAttribute(20, "class", "bb-dockview-panel");
builder.AddAttribute(30, "data-bb-key", Key);
builder.AddAttribute(40, "data-bb-title", Title);
if (TitleTemplate != null)
{
builder.OpenElement(50, "div");
builder.AddAttribute(51, "class", "bb-dockview-item-title");
builder.AddContent(53, TitleTemplate);
builder.CloseElement();
}
else if (ShowTitleBar)
{
builder.OpenComponent<DockViewTitleBar>(60);
builder.AddAttribute(61, nameof(DockViewTitleBar.BarIcon), TitleBarIcon);
builder.AddAttribute(62, nameof(DockViewTitleBar.BarIconUrl), TitleBarIconUrl);
builder.AddAttribute(63, nameof(DockViewTitleBar.OnClickBarCallback), OnClickBar);
builder.CloseComponent();
}
if (DockView.ShowTab(Key))
{
builder.AddContent(70, ChildContent);
}
builder.CloseElement();
}
private async Task OnClickBar()
{
if (OnClickTitleBarCallback != null)
{
await OnClickTitleBarCallback();
}
}
/// <summary>
/// <para lang="zh">设置 Visible 参数方法</para>
/// <para lang="en">Sets the Visible parameter.</para>
/// </summary>
/// <param name="visible"></param>
public void SetVisible(bool visible)
{
Visible = visible;
}
}