Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/accordion view step by step #528

Merged
merged 20 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Dfe.PlanTech.Domain/Content/Interfaces/IAccordion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Dfe.PlanTech.Domain.Content.Interfaces;

public interface IAccordion
{
public int Order { get; set; }
public string Title { get; set; }
public string Heading { get; set; }
}
11 changes: 11 additions & 0 deletions src/Dfe.PlanTech.Domain/Content/Models/Accordion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Dfe.PlanTech.Domain.Content.Interfaces;

namespace Dfe.PlanTech.Domain.Content.Models;

public class Accordion : IAccordion
{
public int Order { get; set; }
public string Title { get; set; }

public string Heading { get; set; }
}
6 changes: 6 additions & 0 deletions src/Dfe.PlanTech.Web.Node/esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ await esbuild.build({
}),
],
outfile: "out/css/application.css",

});

await esbuild.build({
Expand Down Expand Up @@ -97,6 +98,11 @@ copyFileSync(
"./out/js/govuk-frontend.min.js"
);

copyFileSync(
".//node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.css",
"./out/css/govuk-frontend.min.css"
);

//Copy to Dfe.PlanTech.Web
const targetDir = "../Dfe.PlanTech.Web/wwwroot";
const folders = ["css", "assets", "js"];
Expand Down
10 changes: 8 additions & 2 deletions src/Dfe.PlanTech.Web.Node/styles/scss/application.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
@use "../../node_modules/govuk-frontend/dist/govuk/all.scss";
@use "../../node_modules/dfe-frontend-alpha/packages/dfefrontend";
@import "../../node_modules/govuk-frontend/dist/govuk/all.scss";
@import "../../node_modules/dfe-frontend-alpha/packages/dfefrontend";

//Step-by-step navigation pattern. See https://design-system.service.gov.uk/patterns/step-by-step-navigation/
@import "../../node_modules/@govuk-prototype-kit/step-by-step/sass/_step-by-step-navigation.scss";
@import "../../node_modules/@govuk-prototype-kit/step-by-step/sass/_step-by-step-navigation-related.scss";
@import "../../node_modules/@govuk-prototype-kit/step-by-step/sass/_step-by-step-navigation-header.scss";


@import "overrides";
@import "app-task-list";
12 changes: 12 additions & 0 deletions src/Dfe.PlanTech.Web/ViewComponents/AccordionViewComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Dfe.PlanTech.Domain.Content.Interfaces;
using Microsoft.AspNetCore.Mvc;

namespace Dfe.PlanTech.Web.ViewComponents;

public class AccordionViewComponent : ViewComponent
{
public IViewComponentResult Invoke(IEnumerable<IAccordion> accordionBlock)
{
return View(accordionBlock);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@model IEnumerable<Dfe.PlanTech.Domain.Content.Interfaces.IAccordion>

<div class="govuk-grid-column-one-third">

<div data-module="appstepnav" id="step-by-step-navigation" class="app-step-nav govuk-!-display-none-print app-step-nav--active" data-show-text="Show" data-hide-text="Hide" data-show-all-text="Show all actions" data-hide-all-text="Hide all steps">
<ol class="app-step-nav__steps">
@foreach (var accordion in Model)
{
<li class="app-step-nav__step js-step" aria-current="step">
<div class="app-step-nav__header js-toggle-panel" data-position="1">
<h3 class="app-step-nav__title">
<span class="app-step-nav__circle app-step-nav__circle--number">
<span class="app-step-nav__circle-inner">
<span class="app-step-nav__circle-background">
<span class="govuk-visually-hidden govuk-!-display-none-print">Step</span>@accordion.Order<span class="govuk-visually-hidden govuk-!-display-none-print" aria-hidden="true">:</span>
</span>
</span>
</span>

<span class="js-step-title">
@accordion.Title
</span>
</h3>
</div>

<div class="app-step-nav__panel js-panel js-hidden">

<ol class="app-step-nav__list " data-length="3">
<li class="app-step-nav__list-item js-list-item ">
<a class="app-step-nav__link js-link" href="#@accordion.Heading">
@accordion.Heading
</a>
</li>
</ol>

</div>
</li>
}
</ol>
</div>
</div>
1 change: 1 addition & 0 deletions src/Dfe.PlanTech.Web/Views/Shared/Components/Page.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
categoriesList.Add(category);
}
}

if (showRecommendations)
{
@await Component.InvokeAsync("Recommendations", new { categories = categoriesList.ToArray() })
Expand Down
14 changes: 10 additions & 4 deletions src/Dfe.PlanTech.Web/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

@section Head {
<link rel="stylesheet" href="~/css/application.css">
<link rel="stylesheet" href="~/css/govuk-frontend.min.css">

@Html.Raw(GtmConfiguration.Analytics)
@Html.Raw(GtmConfiguration.Head)
@RenderSection("Head", false)
@Html.Raw(GtmConfiguration.Analytics)
@Html.Raw(GtmConfiguration.Head)
@RenderSection("Head", false)
}

@{
Expand All @@ -35,7 +36,9 @@

@section BeforeContent {
<script>document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : '');</script>

<script src="/js/step-by-step-navigation.js"></script>
<script src="/js/step-by-step-polyfills.js"></script>

@{
await Html.RenderPartialAsync("BetaHeader");
}
Expand All @@ -53,9 +56,12 @@
@section BodyEnd {
<script src="~/js/app.js"></script>
<script src="~/js/govuk-frontend.min.js" type="module"></script>

<script type="module">
import { initAll } from '/js/govuk-frontend.min.js';

initAll();
var $element = document.querySelector('#step-by-step-navigation')
var stepByStepNavigation = new GOVUK.Modules.AppStepNav($element).init()
</script>
}
2 changes: 1 addition & 1 deletion src/Dfe.PlanTech.Web/wwwroot/css/application.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Dfe.PlanTech.Web/wwwroot/css/application.css.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Dfe.PlanTech.Domain.Content.Interfaces;
using Dfe.PlanTech.Domain.Content.Models;
using Dfe.PlanTech.Web.ViewComponents;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Xunit;

namespace Dfe.PlanTech.Web.UnitTests.ViewComponents;

public class AccordionViewComponentTest
{
[Fact]
public void Accordion_view_component_not_null()
{
IEnumerable<IAccordion> accordionBlock = new List<IAccordion>
{
new Accordion() { Order = 1, Title = "Test Header 1", Heading = "Heading 1" },
new Accordion() { Order = 2, Title = "Test Header 2", Heading = "Heading 2" },
new Accordion() { Order = 3, Title = "Test Header 3", Heading = "Heading 3" },
new Accordion() { Order = 4, Title = "Test Header 4", Heading = "Heading 4" }
};

var accordionComponent = new AccordionViewComponent();

var result = accordionComponent.Invoke(accordionBlock);

var model = (result as ViewViewComponentResult)?.ViewData?.Model;

Assert.NotNull(model);
}
}