-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(component): add link button component
fix #428
- Loading branch information
1 parent
ec88a66
commit 4ce924a
Showing
7 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,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 | |
This file contains 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,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 |
This file contains 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,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" | ||
})}} |
This file contains 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
This file contains 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,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" | ||
})}} | ||
``` |
This file contains 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,3 @@ | ||
{% macro mojLinkButton(csrfToken, params) %} | ||
{%- include "./template.njk" -%} | ||
{% endmacro %} |
This file contains 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,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> |