Skip to content

Commit

Permalink
feat(component): add link button component
Browse files Browse the repository at this point in the history
fix #428
  • Loading branch information
alex-hedley committed Dec 28, 2022
1 parent ec88a66 commit 4ce924a
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 1 deletion.
21 changes: 21 additions & 0 deletions docs/_includes/arguments/link-button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### csrfToken

| Name | Type | Required | Description |
| ---- | ------ | -------- | ----------- |
| | object | Yes | |

Setup

`const csrf = csurf()`

`res.locals.csrfToken = req.csrfToken()`

- [csurf](https://www.npmjs.com/package/csurf)

### container

| Name | Type | Required | Description |
| ------ | ------ | -------- | ----------------- |
| id | string | Yes | id of the control |
| text | string | Yes | Button text |
| action | string | Yes | POST URL |
25 changes: 25 additions & 0 deletions docs/components/link-button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
layout: layouts/component.njk
title: Link Button
---

{% lastUpdated "link-button" %}

{% example "/examples/link-button", 300 %}

## When to use

Use the _link button_ component to ....

## When not to use

...

## How to use

...

- id: The button Id
- text: The button text
- action: the URL of the POST
- csrfToken: Cross Site Request Forgery Token
16 changes: 16 additions & 0 deletions docs/examples/link-button/index.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
layout: layouts/example.njk
title: Link Button (example)
arguments: link-button
---

{%- from "moj/components/link-button/macro.njk" import mojLinkButton -%}

{% set csrfToken = "ABC123" %}
{% set baseUrl = "http://localhost" %}

{{ mojLinkButton(csrfToken, {
text: "Activate",
action: baseUrl + "/activate",
id: "activate-button"
})}}
6 changes: 5 additions & 1 deletion package/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![moj-frontend](https://circleci.com/gh/ministryofjustice/moj-frontend.svg?style=shield)](https://circleci.com/gh/ministryofjustice/moj-frontend)
![NPM License](https://img.shields.io/npm/l/@ministryofjustice/frontend)

![GitHub Workflow Status](https://img.shields.io/github/workflow/status/ministryofjustice/moj-frontend/Build%20and%20deploy%20docs)
![NPM Downloads](https://img.shields.io/npm/v/@ministryofjustice/frontend)
![NPM Downloads](https://img.shields.io/npm/dw/@ministryofjustice/frontend)

# Ministry of Justice Frontend

Expand Down
13 changes: 13 additions & 0 deletions src/moj/components/link-button/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Link Button

- [Guidance](https://design-patterns.service.justice.gov.uk/components/link-button)

## Examples

```
{{ mojLinkButton(csrfToken, {
text: "Activate",
action: baseUrl + "/activate",
id: "activate-button"
})}}
```
3 changes: 3 additions & 0 deletions src/moj/components/link-button/macro.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro mojLinkButton(csrfToken, params) %}
{%- include "./template.njk" -%}
{% endmacro %}
12 changes: 12 additions & 0 deletions src/moj/components/link-button/template.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<form method="post" action="{{ params.action }}">
<input type="hidden" name="_csrf" value="{{ csrfToken }}" />
<button type="submit"
name="{{ params.id }}"
class="link-button govuk-body-m govuk-link"
data-qa="{{ params.id }}"
data-prevent-double-click="true"
data-module="govuk-button"
>
{{ params.text }}
</button>
</form>

0 comments on commit 4ce924a

Please sign in to comment.