npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

familyhubs-frontend

v9.5.1

Published

FamilyHubs Frontend contains the code you need to start building a Family Hubs website on top of the GOVUK Design System

Downloads

672

Readme

Family Hub web framework and components

This package is designed to work in conjunction with the FamilyHubs.SharedKernel.Razor nuget package, to rapidly create new GOV.UK websites and add standard components.

It builds on top of these packages:

The package contains:

  • configurable standard GOV.UK layout (although only the DfE header is included)
  • configurable header and footer links
  • cookie banner and page with pluggable content
  • Google Analytics support
  • GOV.UK pagination support
  • Error handling, error pages and GOVUK error summary component
  • MOJ dashboard support
  • alternative configs for when pages need different layouts, headers, footers etc.
  • Url helpers for picking Urls from config, manipulating them and inheriting them from ancestor configs
  • a set of SASS files that import the above packages and add some additional styling
  • .NET distributed cache support for SQL Server and Redis
  • JavaScript postcode helpers
  • HTTP security header support

There is an example ASP.Net 7 site that shows how to use the packages.

Consuming the packages

Install the familyhubs-frontend package into the website project using the following command:

npm install familyhubs-frontend

Installing the package, will add files to the wwwroot folder. (todo document which files)

In the styles/application.scss file, add the following line:

@import "../node_modules/familyhubs-frontend/styles/all";

Add the FamilyHubs.SharedKernel.Razor package to the website project.

The FamilyHubs.SharedKernel.Razor package contains:

  • the layout
  • common shared partial views
  • todo add rest here

Check that the npm package and the Razor Class Library are on the same version.

Add the configuration section to the appsettings.json file of the website project.

Configuration

Here's an example configuration section that should be added to the appsettings.json file of a Family Hubs website:

  "FamilyHubsUi": {
    "ServiceName": "Manage family support services and accounts",
    "Phase": "Beta",
    "FeedbackUrl": "https://example.com/feedback",
    "SupportEmail": "[email protected]",
    "Analytics": {
      "CookieName": "manage_family_support_cookies_policy",
      "CookieVersion": 1,
      "MeasurementId": "",
      "ContainerId": ""
    },
    "Header": {
	  "NavigationLinks": [
		{ "Text": "Requests Sent", "Url": "https://dev.manage-connection-requests.education.gov.uk/" },
		{ "Text": "Search for service", "Url": "/ProfessionalReferral/Search" },
	  ],
      "ActionLinks": [
		{ "Text": "My account", "Url": "/account/my-account" },
		{ "Text": "Sign out", "Url": "/account/signout" }
	  ]
	},
    "Footer": {
      "Links": [
        { "Text": "Accessibility" },
        { "Text": "Contact Us" },
        { "Text": "Cookies" },
        { "Text": "Feedback", "ConfigUrl": "FamilyHubsUi:FeedbackUrl" },
        { "Text": "Terms and conditions" }
      ] 
    } 

Notes:

  • Google Analytics is only enabled if the MeasurementId and ContainerId are set.

  • The Options classes have XML documentation on the properties.

  • If your cookie page is at a different location to /cookies, you can set it using CookiePageUrl in the Analytics section.

Version numbers

To ease testing, we should keep the version number of the NPM package and the Razor Class Library in sync. Consumers should then ensure that both packages are on the same version.

The version of the familyhubs-frontend package is given in its package.json file, as the value of the version property.

The version of the FamilyHubs.SharedKernel.Razor package is given in its FamilyHubs.SharedKernel.Razor.csproj file, as the value of the VersionPrefix property.

familyhubs-frontend

To publish this npm package, you�ll need to follow these steps:

  • Create a user account on the npm website if you don�t already have one.
  • In your terminal or command prompt, navigate to the familyhubs-frontend directory, containing the package files.
  • Run the npm login command and enter your npm username, password, and email when prompted.
  • Update the package.json file in the package directory with the version number synced to the FamilyHubs.SharedKernel.Razor version.
  • Run the npm publish command to publish the package to the npm registry.

After publishing the package, it will be available for others to install and use nearly instantaneously.

It's best to reference the package using its exact version number, otherwise it might not pick up the latest, just published version.

FamilyHubs.SharedKernel.Razor

The package is automatically built when the solution is built.

It is not currently published automatically to the NuGet feed, and needs to be manually uploaded to NuGet.

Components

Cookie page

Call AddCookiePage() on your IServiceCollection, like so...

    services.AddCookiePage(configuration);

Create a new Razor Page. Inject ICookiePage into the PageModel's constructor, stash it away, then pass it to the cookie page partial in the View.

To add support for users running without Javascript, add an OnPost method as per the example.

E.g.

public class IndexModel : PageModel
{
    public readonly ICookiePage CookiePage;

    public IndexModel(ICookiePage cookiePage)
    {
        CookiePage = cookiePage;
    }

    public void OnPost(bool analytics)
    {
        CookiePage.OnPost(analytics, Request, Response);
    }
}

and add in your view...

    <partial name="~/Pages/Shared/_CookiePage.cshtml" model="Model.CookiePage"/>

Add a partial view called Pages/Shared/_CookiePolicy.cshtml and add the cookie policy content into it.

If you want to pick up the cookie policy content from a different partial view, pass its name into AddCookiePage(), e.g.

    services.AddCookiePage(configuration, "SomeOtherView.cshtml");

User-friendly, branded error pages

To add user-friendly Family Hub branded error pages, call UseErrorHandling() on WebApplication, e.g.

    app.UseErrorHandling();

By default, the error handling middleware will only be added if it's not the development environment. If you want to always add it, irrespective of the environment (useful for local testing), pass true as the first parameter.

If SupportEmail is set in the configuration, the error page will include a link to the given support email address.

To test the not found page, navigate to a URL that doesn't exist, e.g. /not-found.

To test the error page, navigate to /error/test, which is a fault-injection page included in the library, explicitly for testing the error page handling.

Release Notes

Possible Improvements