# GDS Design System Templates for Formio

This project provides the templates required to implement the GDS Design System for Formio form renderer.

This release is to support Node 20 and GDS (`govuk-frontend`) 5.x

## Set up and configuration

### Prerequisites

NodeJS version 24

### Installation

```bash
   npm install @ukhomeoffice/formio-gds-template
```

The compiled `lib/` directory is generated during packaging and is intentionally not committed to the repository. To publish a local build to an application using Yalc, run:

```bash
npm run yalc:push
```

This builds the package before pushing it, so the consuming application imports the same compiled files that would be included in an npm package.

## Usage

Using vanilla formio

```javascript
import gds from '@ukhomeoffice/formio-gds-template';
import {Formio} from 'formiojs';

Formio.use(gds);
```

Using react-formio

```javascript
import gds from '@ukhomeoffice/formio-gds-template';
import {Formio} from "react-formio";

Formio.use(gds);
```

### Calculated numbers

Register the plugin with `Formio.use(gds)` (or `window.Formio.use(window.gds)` for the browser bundle). The plugin patches the registering renderer's Number class, including Currency, even when the application and library have separate Form.io runtimes. Its existing `templates`, `components` and installer properties remain available.

Calculated values are rounded before storage using `decimalLimit`, the decimal places in `validate.step`, or 10 decimal places when neither is configured. Scientific notation is displayed as a plain decimal. Existing read-only submissions are not migrated or rewritten.

### Hidden fields and commented-out conditions

Matching Form.io v4, a field that is hidden and set to clear when hidden is not given a default value, so it stays out of the submission. A `customConditional` that is only a commented-out condition (for example `// show = data.mode === 'contain';`) is treated as hidden, as it was in v4.

Fix such conditions in the form so they do what is intended. To list them in a form definition:

```javascript
import { findCommentOnlyConditionals } from '@ukhomeoffice/formio-gds-template';

findCommentOnlyConditionals(formJson).forEach(({ path, customConditional }) =>
  console.warn(`${path}: commented-out customConditional`, customConditional));
```

## How to publish to NPM registry

Publishing to the NPM registry is done through GitHub actions. This is triggered by creating a release through GitHub as documented in the steps below.

As a prerequisite, push a feature branch or merge into the `main` branch (providing the change has been tested). Ensure the `version` in `package.json` has been incremented accordingly. To follow best practices, use the semantic versioning system: <https://semver.org/>
> [!NOTE]
> Changes which are pre-releases i.e. changes in feature branches which are not ready to be released as general availability, should be [marked as a pre-release](https://semver.org/#spec-item-9) e.g. `1.2.3-alpha`
>
> Pre-release versions are published to npm under the `next` tag, never `latest`. Install one with the `@next` tag or the exact version.

1. Create a release through GitHub by going to <https://github.com/UKHomeOffice/formio-gds-template/releases/new>
2. Create a new tag version to match the version in `package.json` prefixing with a `v` e.g. `v1.2.3-alpha`
3. Title the release with the same tag version as created in the previous step
4. Choose the appropriate branch, be it a feature branch or the primary branch as the target
5. For simplicity, select the `Generate release notes` button or for more granularity, populate the release note as relevant
6. Optionally, mark the release as a pre-release if publishing from a feature branch
7. Click `publish release`. This will trigger a GitHub action workflow run
8. Wait for the GitHub action to finish

> [!TIP]
> Optionally, verify the new version has been published by heading over to <https://www.npmjs.com/package/@ukhomeoffice/formio-gds-template> to check the new version is present (you may need to reload your browser cache when visiting <https://www.npmjs.com>). Alternatively, verify it exists through the CLI by running `npm view @ukhomeoffice/formio-gds-template versions` locally and checking to see if the new version exists

### Notes

For additional information on GitHub releases, [see the GitHub Documentation](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository?tool=webui#creating-a-release)
