Skip to content

Commit

Permalink
Update lib/filters/core-filters.js
Browse files Browse the repository at this point in the history
Use nunjucks formatting in the example

Co-authored-by: Colin Rotherham <[email protected]>
  • Loading branch information
BenSurgisonGDS and colinrotherham authored Nov 29, 2023
1 parent b667f7d commit a198b9e
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions lib/filters/core-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ runWhenEnvIsAvailable(() => {
* Returns an array of objects for use in a macro that requires a list of items
* @param {String[]} an array of strings.
* @return {Object[]} an array of objects with each object containing text and value properties.
* @example {{ govukCheckboxes({
* name: "waste",
* fieldset: {
* legend: {
* text: "Which types of waste do you transport?",
* isPageHeading: true,
* classes: "govuk-fieldset__legend--l"
* }
* },
* hint: {
* text: "Select all that apply."
* },
* items: ['Rubble', 'Oil', 'Card'] | formatItems
* }) }}
* @example
* ```njk
* {{ govukCheckboxes({
* name: "waste",
* fieldset: {
* legend: {
* text: "Which types of waste do you transport?",
* isPageHeading: true,
* classes: "govuk-fieldset__legend--l"
* }
* },
* hint: {
* text: "Select all that apply."
* },
* items: ["Rubble", "Oil", "Card"] | formatItems
* }) }}
* ```
*/
addFilter('formatItems', (items = []) => Array.isArray(items) ? items.map(item => ({ text: item, value: item })) : [])
})

0 comments on commit a198b9e

Please sign in to comment.