nhsuk-decorated-components 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/decorate.js +7 -3
- package/package.json +7 -12
- package/x-nhsuk/decorated/button/macro.njk +1 -1
- package/x-nhsuk/decorated/checkboxes/macro.njk +1 -1
- package/x-nhsuk/decorated/date-input/macro.njk +1 -1
- package/x-nhsuk/decorated/input/macro.njk +1 -1
- package/x-nhsuk/decorated/radios/macro.njk +1 -1
- package/x-nhsuk/decorated/select/macro.njk +1 -1
- package/x-nhsuk/decorated/textarea/macro.njk +1 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ To add them to the NHS.UK Prototype Kit, follow these steps:
|
|
|
36
36
|
var nunjucksAppEnv = nunjucks.configure(appViews, nunjucksConfig)
|
|
37
37
|
|
|
38
38
|
// Add Nunjucks Globals
|
|
39
|
-
+
|
|
39
|
+
+ import { decorate } from 'nhsuk-decorated-components'
|
|
40
40
|
+ nunjucksAppEnv.addGlobal('decorate', decorate)
|
|
41
41
|
|
|
42
42
|
// Add Nunjucks filters
|
package/lib/decorate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import _ from 'lodash'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Add `name`, `value`, `id`, `idPrefix` and `checked`/`selected` attributes
|
|
@@ -10,7 +10,7 @@ const _ = require('lodash')
|
|
|
10
10
|
* @param {string} [componentName] - Name of component calling decorate
|
|
11
11
|
* @returns {Object} Updated component parameters
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
export function decorate(params, keyPath, componentName) {
|
|
14
14
|
if (typeof keyPath === 'undefined') {
|
|
15
15
|
return params
|
|
16
16
|
}
|
|
@@ -107,7 +107,11 @@ exports.decorate = function (params, keyPath, componentName) {
|
|
|
107
107
|
let checkedValue = ''
|
|
108
108
|
let selectedValue = ''
|
|
109
109
|
|
|
110
|
-
if (
|
|
110
|
+
if (storedValue === undefined) {
|
|
111
|
+
// Stored value undefined, defer to `checked` or `selected` params
|
|
112
|
+
checkedValue = item.checked
|
|
113
|
+
selectedValue = item.selected
|
|
114
|
+
} else if (Array.isArray(storedValue)) {
|
|
111
115
|
// Stored value is an array, check it exists in the array
|
|
112
116
|
if (storedValue.indexOf(item.value) !== -1) {
|
|
113
117
|
checkedValue = 'checked'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhsuk-decorated-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Form components for the NHS.UK Design System that require less parameters to collect data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nhsuk",
|
|
@@ -40,19 +40,14 @@
|
|
|
40
40
|
"lodash": "^4.17.21"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"eslint": "^
|
|
44
|
-
"
|
|
45
|
-
"eslint-config-standard": "^17.1.0",
|
|
46
|
-
"eslint-plugin-import": "^2.29.1",
|
|
47
|
-
"eslint-plugin-jsdoc": "^50.0.0",
|
|
48
|
-
"eslint-plugin-n": "^16.6.2",
|
|
49
|
-
"eslint-plugin-prettier": "^5.1.3",
|
|
50
|
-
"eslint-plugin-promise": "^6.1.1",
|
|
51
|
-
"nhsuk-frontend": "^9.0.0",
|
|
43
|
+
"@x-govuk/eslint-config": "^0.0.1",
|
|
44
|
+
"nhsuk-frontend": "^10.0.0-internal.0",
|
|
52
45
|
"np": "^10.0.0",
|
|
53
|
-
"nunjucks": "^3.2.3"
|
|
46
|
+
"nunjucks": "^3.2.3",
|
|
47
|
+
"prettier": "^3.1.0"
|
|
54
48
|
},
|
|
55
49
|
"engines": {
|
|
56
50
|
"node": ">=20"
|
|
57
|
-
}
|
|
51
|
+
},
|
|
52
|
+
"type": "module"
|
|
58
53
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{% from "components/button/macro.njk" import button as source -%}
|
|
1
|
+
{% from "nhsuk/components/button/macro.njk" import button as source -%}
|
|
2
2
|
{%- macro button(params) -%}
|
|
3
3
|
{{- source(params) if params.href else source(decorate(params, params.decorate)) -}}
|
|
4
4
|
{%- endmacro %}
|