forked from rer-github/govuk-design-system-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GovUkHtmlHelperExtensions.cs
296 lines (263 loc) · 11.4 KB
/
GovUkHtmlHelperExtensions.cs
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using GovUkDesignSystem.GovUkDesignSystemComponents;
using GovUkDesignSystem.GovUkDesignSystemComponents.SubComponents;
using GovUkDesignSystem.HtmlGenerators;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace GovUkDesignSystem
{
public static class GovUkHtmlHelperExtensions
{
public static IHtmlContent GovUkBackLink(
this IHtmlHelper htmlHelper,
BackLinkViewModel backLinkViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/BackLink.cshtml", backLinkViewModel);
}
public static IHtmlContent GovUkBreadcrumbs(
this IHtmlHelper htmlHelper,
BreadcrumbsViewModel breadcrumbsViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Breadcrumbs.cshtml", breadcrumbsViewModel);
}
public static IHtmlContent GovUkButton(
this IHtmlHelper htmlHelper,
ButtonViewModel buttonViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Button.cshtml", buttonViewModel);
}
public static IHtmlContent GovUkCharacterCount(
this IHtmlHelper htmlHelper,
CharacterCountViewModel characterCountViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/CharacterCount.cshtml", characterCountViewModel);
}
public static IHtmlContent GovUkCharacterCountFor<TModel>(
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, string>> propertyLambdaExpression,
int? rows = null,
LabelViewModel labelOptions = null,
HintViewModel hintOptions = null,
FormGroupViewModel formGroupOptions = null)
where TModel : GovUkViewModel
{
return CharacterCountHtmlGenerator.GenerateHtml(
htmlHelper,
propertyLambdaExpression,
rows,
labelOptions,
hintOptions,
formGroupOptions);
}
public static IHtmlContent GovUkCheckboxes(
this IHtmlHelper htmlHelper,
CheckboxesViewModel checkboxesViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Checkboxes.cshtml", checkboxesViewModel);
}
public static IHtmlContent GovUkCheckboxesFor<TModel, TPropertyListItem>(
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, List<TPropertyListItem>>> propertyLambdaExpression,
FieldsetViewModel fieldsetOptions = null,
HintViewModel hintOptions = null,
Dictionary<TPropertyListItem, Func<object, object>> conditionalOptions = null
)
where TModel : GovUkViewModel
where TPropertyListItem : struct, IConvertible // A fairly good check that TPropertyListItem is an Enum
{
return CheckboxesHtmlGenerator.GenerateHtml(
htmlHelper,
propertyLambdaExpression,
fieldsetOptions,
hintOptions,
conditionalOptions);
}
public static IHtmlContent GovUkCheckboxItem(
this IHtmlHelper htmlHelper,
CheckboxItemViewModel checkboxItemViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/CheckboxItem.cshtml", checkboxItemViewModel);
}
public static IHtmlContent GovUkErrorMessage(
this IHtmlHelper htmlHelper,
ErrorMessageViewModel errorMessageViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/ErrorMessage.cshtml", errorMessageViewModel);
}
public static IHtmlContent GovUkErrorSummary(
this IHtmlHelper htmlHelper,
ErrorSummaryViewModel errorSummaryViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/ErrorSummary.cshtml", errorSummaryViewModel);
}
public static IHtmlContent GovUkErrorSummary<TModel>(
this IHtmlHelper<TModel> htmlHelper,
string[] optionalOrderOfPropertyNamesInTheView = null)
where TModel : GovUkViewModel
{
// Give 'optionalOrderOfPropertiesInTheView' a default value (of an empty array)
var orderOfPropertyNamesInTheView = optionalOrderOfPropertyNamesInTheView ?? new string[0];
return ErrorSummaryHtmlGenerator.GenerateHtml(htmlHelper, orderOfPropertyNamesInTheView);
}
public static IHtmlContent GovUkFieldset(
this IHtmlHelper htmlHelper,
FieldsetViewModel fieldsetViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Fieldset.cshtml", fieldsetViewModel);
}
public static IHtmlContent GovUkFooter(
this IHtmlHelper htmlHelper,
FooterViewModel footerViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Footer.cshtml", footerViewModel);
}
public static IHtmlContent GovUkHeader(
this IHtmlHelper htmlHelper,
HeaderViewModel headerViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Header.cshtml", headerViewModel);
}
public static IHtmlContent GovUkHint(
this IHtmlHelper htmlHelper,
HintViewModel hintViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Hint.cshtml", hintViewModel);
}
public static IHtmlContent GovUkHtmlText(
this IHtmlHelper htmlHelper,
IHtmlText htmlText)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/SubComponents/HtmlText.cshtml", htmlText);
}
public static IHtmlContent GovUkInsetText(
this IHtmlHelper htmlHelper,
InsetTextViewModel insetTextViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/InsetText.cshtml", insetTextViewModel);
}
public static IHtmlContent GovUkItem(
this IHtmlHelper htmlHelper,
ItemViewModel itemViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Item.cshtml", itemViewModel);
}
public static IHtmlContent GovUkItemSet(
this IHtmlHelper htmlHelper,
ItemSetViewModel itemSetViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/ItemSet.cshtml", itemSetViewModel);
}
public static IHtmlContent GovUkLabel(
this IHtmlHelper htmlHelper,
LabelViewModel labelViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Label.cshtml", labelViewModel);
}
public static IHtmlContent GovUkLegend(
this IHtmlHelper htmlHelper,
LegendViewModel legendViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Legend.cshtml", legendViewModel);
}
public static IHtmlContent GovUkPhaseBanner(
this IHtmlHelper htmlHelper,
PhaseBannerViewModel phaseBannerViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/PhaseBanner.cshtml", phaseBannerViewModel);
}
public static IHtmlContent GovUkRadiosFor<TModel, TProperty>(
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> propertyLambdaExpression,
FieldsetViewModel fieldsetOptions = null,
HintViewModel hintOptions = null)
where TModel : GovUkViewModel
{
return RadiosHtmlGenerator.GenerateHtml(
htmlHelper,
propertyLambdaExpression,
fieldsetOptions,
hintOptions);
}
public static IHtmlContent GovUkRadioItem(
this IHtmlHelper htmlHelper,
RadioItemViewModel radioItemViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/RadioItem.cshtml", radioItemViewModel);
}
public static IHtmlContent GovUkTag(
this IHtmlHelper htmlHelper,
TagViewModel tagViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/Tag.cshtml", tagViewModel);
}
public static IHtmlContent GovUkTextArea(
this IHtmlHelper htmlHelper,
TextAreaViewModel textAreaViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/TextArea.cshtml", textAreaViewModel);
}
public static IHtmlContent GovUkTextAreaFor<TModel>(
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, string>> propertyLambdaExpression,
int? rows = null,
LabelViewModel labelOptions = null,
HintViewModel hintOptions = null,
FormGroupViewModel formGroupOptions = null)
where TModel : GovUkViewModel
{
return TextAreaHtmlGenerator.GenerateHtml(
htmlHelper,
propertyLambdaExpression,
rows,
labelOptions,
hintOptions,
formGroupOptions);
}
public static IHtmlContent GovUkTextInput(
this IHtmlHelper htmlHelper,
TextInputViewModel textInputViewModel)
{
return htmlHelper.Partial("/GovUkDesignSystemComponents/TextInput.cshtml", textInputViewModel);
}
public static IHtmlContent GovUkTextInputFor<TModel>(
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, string>> propertyLambdaExpression,
LabelViewModel labelOptions = null,
HintViewModel hintOptions = null,
FormGroupViewModel formGroupOptions = null,
string classes = null,
TextInputAppendixViewModel textInputAppendix = null)
where TModel : GovUkViewModel
{
return TextInputHtmlGenerator.GenerateHtml(
htmlHelper,
propertyLambdaExpression,
labelOptions,
hintOptions,
formGroupOptions,
classes,
textInputAppendix);
}
public static IHtmlContent GovUkTextInputFor<TModel>(
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, int?>> propertyLambdaExpression,
LabelViewModel labelOptions = null,
HintViewModel hintOptions = null,
FormGroupViewModel formGroupOptions = null,
string classes = null,
TextInputAppendixViewModel textInputAppendix = null)
where TModel : GovUkViewModel
{
return TextInputHtmlGenerator.GenerateHtml(
htmlHelper,
propertyLambdaExpression,
labelOptions,
hintOptions,
formGroupOptions,
classes,
textInputAppendix);
}
}
}