File tree 8 files changed +113
-24
lines changed
BootstrapBlazor/Components/Message 8 files changed +113
-24
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,22 @@ private MessageService? MessageService { get; set; }
76
76
<Message @ref =" Message1" Placement =" Placement.Bottom" />
77
77
</DemoBlock >
78
78
79
+ <DemoBlock Title =" @Localizer[" MessagesTemplateTitle " ]"
80
+ Introduction =" @Localizer[" MessagesTemplateIntro " ]"
81
+ Name =" Template" >
82
+ <button class =" btn btn-primary" @onclick =" @ShowTemplateMessage" >@Localizer ["MessagesTemplatePrompt"]</button >
83
+ <Message @ref =" Message1" Placement =" Placement.Bottom" />
84
+ </DemoBlock >
85
+
79
86
<AttributeTable Items =" @GetAttributes()" />
80
87
81
88
<AttributeTable Title =" @Localizer[" MessagesItem " ]" Items =" @GetMessageItemAttributes()" />
89
+
90
+ @code {
91
+ private RenderFragment RenderContent =>
92
+ @< div class = " message-custom" >
93
+ < p class = " text-primary" > Message Header < / p >
94
+ < p > Message Body < / p >
95
+ < div class = " text-warning" > Message Footer < / div >
96
+ < / div > ;
97
+ }
Original file line number Diff line number Diff line change @@ -77,6 +77,15 @@ await MessageService.Show(new MessageOption()
77
77
} , Message1 ) ;
78
78
}
79
79
80
+ private async Task ShowTemplateMessage ( )
81
+ {
82
+ await MessageService . Show ( new MessageOption ( )
83
+ {
84
+ Icon = "fa-solid fa-circle-info" ,
85
+ ChildContent = RenderContent
86
+ } ) ;
87
+ }
88
+
80
89
private static AttributeItem [ ] GetAttributes ( ) =>
81
90
[
82
91
new ( )
@@ -104,14 +113,6 @@ private static AttributeItem[] GetMessageItemAttributes() =>
104
113
DefaultValue = " — "
105
114
} ,
106
115
new ( )
107
- {
108
- Name = "Class" ,
109
- Description = "Style" ,
110
- Type = "string" ,
111
- ValueList = " — " ,
112
- DefaultValue = " — "
113
- } ,
114
- new ( )
115
116
{
116
117
Name = "Color" ,
117
118
Description = "Color" ,
@@ -142,6 +143,30 @@ private static AttributeItem[] GetMessageItemAttributes() =>
142
143
Type = "bool" ,
143
144
ValueList = "true|false" ,
144
145
DefaultValue = "false"
146
+ } ,
147
+ new ( )
148
+ {
149
+ Name = "ShowShadow" ,
150
+ Description = "Whether to show the shadow" ,
151
+ Type = "bool" ,
152
+ ValueList = "true|false" ,
153
+ DefaultValue = "false"
154
+ } ,
155
+ new ( )
156
+ {
157
+ Name = "ShowBorder" ,
158
+ Description = "Whether to show the border" ,
159
+ Type = "bool" ,
160
+ ValueList = "true|false" ,
161
+ DefaultValue = "false"
162
+ } ,
163
+ new ( )
164
+ {
165
+ Name = "OnDismiss" ,
166
+ Description = "The callback when click close button" ,
167
+ Type = "Func<Task>" ,
168
+ ValueList = " — " ,
169
+ DefaultValue = " — "
145
170
}
146
171
] ;
147
172
}
Original file line number Diff line number Diff line change 468
468
"MessagesDifferentColorSecondary" : " Secondary message" ,
469
469
"MessagesPositionTitle" : " message box pop-up location" ,
470
470
"MessagesPositionIntro" : " Specify the <code>Message</code> component that has set the bottom display position by setting the component parameter of the <code>MessageService</code> service" ,
471
- "MessagesItem" : " MessageItem property"
471
+ "MessagesItem" : " MessageOption property" ,
472
+ "MessagesTemplateTitle" : " Custom template" ,
473
+ "MessagesTemplateIntro" : " By setting the <code>ChildContent</code> template, rich custom styles and content prompt information can be achieved" ,
474
+ "MessagesTemplatePrompt" : " Custom message"
472
475
},
473
476
"BootstrapBlazor.Server.Components.Samples.Lights" : {
474
477
"LightsTitle" : " Light indicator" ,
Original file line number Diff line number Diff line change 468
468
"MessagesDifferentColorSecondary" : " Secondary 消息" ,
469
469
"MessagesPositionTitle" : " 消息框弹出位置" ,
470
470
"MessagesPositionIntro" : " 通过设置 <code>MessageService</code> 服务的组件参数,指定已经设置底部显示位置的 <code>Message</code> 组件" ,
471
- "MessagesItem" : " MessageItem 属性"
471
+ "MessagesItem" : " MessageOption 属性" ,
472
+ "MessagesTemplateTitle" : " 自定义模板" ,
473
+ "MessagesTemplateIntro" : " 通过设置 <code>ChildContent</code> 模板可以实现丰富的自定义样式与内容的提示信息" ,
474
+ "MessagesTemplatePrompt" : " 自定义消息"
472
475
},
473
476
"BootstrapBlazor.Server.Components.Samples.Lights" : {
474
477
"LightsTitle" : " Light 指示灯" ,
Original file line number Diff line number Diff line change 12
12
{
13
13
<i class =" @item.Icon" ></i >
14
14
}
15
- <span >@item.Content </span >
15
+ <div >
16
+ @if (item .ChildContent != null )
17
+ {
18
+ @item.ChildContent
19
+ }
20
+ else
21
+ {
22
+ @item.Content
23
+ }
24
+ </div >
16
25
@if (item .ShowDismiss )
17
26
{
18
27
<button type =" button" class =" btn-close" aria-label =" close" ></button >
30
39
{
31
40
<i class =" @item.Icon" ></i >
32
41
}
33
- <span >@item.Content </span >
42
+ <div >
43
+ @if (item .ChildContent != null )
44
+ {
45
+ @item.ChildContent
46
+ }
47
+ else
48
+ {
49
+ @item.Content
50
+ }
51
+ </div >
34
52
@if (item .ShowDismiss )
35
53
{
36
54
<button type =" button" class =" btn-close" aria-label =" close" ></button >
Original file line number Diff line number Diff line change 1
- .message {
1
+ .message {
2
2
position : fixed ;
3
3
left : 1rem ;
4
4
right : 1rem ;
5
5
z-index : 1090 ;
6
6
pointer-events : none ;
7
- }
8
7
9
- .message . alert {
8
+ .alert {
10
9
display : flex ;
11
10
align-items : baseline ;
12
11
min-width : 160px ;
18
17
margin : 1rem auto 0 auto ;
19
18
transition : opacity .3s linear , top .3s linear , bottom .3s linear ;
20
19
pointer-events : auto ;
21
- }
22
20
23
- .message .alert .show {
21
+ & .show {
24
22
opacity : 1 ;
25
23
bottom : unset ;
26
24
top : 20px ;
27
25
}
28
26
29
- .message .alert > i + span {
27
+ > i + div {
30
28
margin-left : .5rem ;
31
29
}
32
30
33
- .message .alert > span {
31
+ > div {
34
32
flex : 1 ;
35
33
flex-wrap : wrap ;
36
34
word-break : break-all ;
37
35
}
36
+ }
38
37
39
- .message .is-bottom .alert {
38
+ & .is-bottom .alert {
40
39
top : unset ;
41
40
bottom : -20px ;
42
41
}
43
42
44
- .message.is-bottom .alert.show {
45
- top : unset ;
46
- bottom : 20px ;
47
- }
43
+ & .is-bottom .alert.show {
44
+ top : unset ;
45
+ bottom : 20px ;
46
+ }
47
+ }
Original file line number Diff line number Diff line change @@ -43,4 +43,9 @@ public class MessageOption : PopupOptionBase
43
43
/// 获得/设置 关闭当前 MessageItem 回调委托 默认 null
44
44
/// </summary>
45
45
public Func < Task > ? OnDismiss { get ; set ; }
46
+
47
+ /// <summary>
48
+ /// 获得/设置 内容模板 默认 null 设置此参数后 <see cref="PopupOptionBase.Content"/> 将失效
49
+ /// </summary>
50
+ public RenderFragment ? ChildContent { get ; set ; }
46
51
}
Original file line number Diff line number Diff line change @@ -97,5 +97,24 @@ await cut.InvokeAsync(() => service.Show(new MessageOption()
97
97
98
98
await cut . Instance . Dismiss ( alert . Id ) ;
99
99
await cut . Instance . Dismiss ( "test_id" ) ;
100
+ await cut . InvokeAsync ( ( ) => cut . Instance . Clear ( ) ) ;
101
+
102
+ await cut . InvokeAsync ( ( ) => service . Show ( new MessageOption ( )
103
+ {
104
+ ChildContent = builder => builder . AddContent ( 0 , new MarkupString ( "<div class=\" custom-message-template\" >Custom Message</div>" ) )
105
+ } , cut . Instance ) ) ;
106
+ Assert . Contains ( "<div class=\" custom-message-template\" >Custom Message</div>" , cut . Markup ) ;
107
+ }
108
+
109
+ [ Fact ]
110
+ public async Task ChildContent_Ok ( )
111
+ {
112
+ var service = Context . Services . GetRequiredService < MessageService > ( ) ;
113
+ var cut = Context . RenderComponent < Message > ( ) ;
114
+ await cut . InvokeAsync ( ( ) => service . Show ( new MessageOption ( )
115
+ {
116
+ ChildContent = builder => builder . AddContent ( 0 , new MarkupString ( "<div class=\" custom-message-template\" >Custom Message</div>" ) )
117
+ } , cut . Instance ) ) ;
118
+ Assert . Contains ( "<div class=\" custom-message-template\" >Custom Message</div>" , cut . Markup ) ;
100
119
}
101
120
}
You can’t perform that action at this time.
0 commit comments