This repository was archived by the owner on Sep 18, 2025. It is now read-only.
forked from nhsuk/nhsuk-frontend
-
Notifications
You must be signed in to change notification settings - Fork 2
Create Fieldset View, ViewComponent and Model #56
Merged
akdalin-hee
merged 1 commit into
main
from
feature/TD-5200-Create-fieldset-view-component
Jun 3, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
DotnetViewComponents/ViewComponents/FieldsetViewComponent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| namespace DotnetViewComponents.ViewComponents | ||
| { | ||
| using System.Collections.Generic; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using DotnetViewComponents.ViewModels; | ||
|
|
||
| public class FieldsetViewComponent : ViewComponent | ||
| { | ||
| public IViewComponentResult Invoke( | ||
| string title, | ||
| List<FieldViewModel> fieldList) | ||
| { | ||
| var model = new FieldsetViewModel(title, fieldList); | ||
|
|
||
| return View(model); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using Microsoft.AspNetCore.Html; | ||
|
|
||
| namespace DotnetViewComponents.ViewModels | ||
| { | ||
| public class FieldsetViewModel | ||
| { | ||
| public FieldsetViewModel( | ||
| string title, | ||
| List<FieldViewModel> fieldList) | ||
| { | ||
| Title = title; | ||
| FieldList = fieldList; | ||
| } | ||
|
|
||
| public string Title { get; set; } | ||
| public List<FieldViewModel> FieldList { get; set; } | ||
|
|
||
| } | ||
|
|
||
| public class FieldViewModel | ||
| { | ||
| public FieldViewModel(Func<object, IHtmlContent> content) | ||
| { | ||
| Content = content; | ||
| } | ||
|
|
||
| public Func<object, IHtmlContent> Content { get; set; } | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
DotnetViewComponents/Views/Shared/Components/Fieldset/Default.cshtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| @using DotnetViewComponents.ViewModels | ||
| @model FieldsetViewModel | ||
|
|
||
| <div class="nhsuk-tabs js-enabled" data-module="nhsuk-tabs"> | ||
| <fieldset class="nhsuk-fieldset"> | ||
| <legend class="nhsuk-fieldset__legend nhsuk-fieldset__legend--l"> | ||
| <h1 class="nhsuk-fieldset__heading"> | ||
| @Model.Title | ||
| </h1> | ||
| </legend> | ||
|
|
||
| @foreach (var field in Model.FieldList) | ||
| { | ||
| @field.Content(null) | ||
| } | ||
|
|
||
| </fieldset> | ||
| </div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be misunderstanding this, @akdalin-hee, so bear with me. Is this expecting raw html to be passed in for each field in the fieldset? If so, it probably doesn't make much sense to include Fieldset as a component. Fieldsets are pretty thin on markup but have complex child components, so we might want to leave them out of the view component library?