x-govuk / govuk-prototype-components

Use common components that are not yet part of the GOV.UK Design System.
https://x-govuk.github.io/govuk-prototype-components/
MIT License
3 stars 2 forks source link

Conditional navigation items #238

Closed paulrobertlloyd closed 4 months ago

paulrobertlloyd commented 4 months ago

Makes it possible to add conditions to navigation items:

{{ xGovukSecondaryNavigation({
  classes: "nhsuk-u-margin-bottom-6",
  items: [
    {
      text: "Apples",
      href: "/apples/"
    } if role == "juicer",
    {
      text: "Bananas",
      href: "/bananas/"
    },
    {
      text: "Oranges",
      href: "/oranges/"
    } if role == "juicer"
  ]
}) }}

Without this change, an empty object is returned, which in turn creates an empty HTML list item.

The Primary navigation component previously checked for the presence of item.href, but have made this consistent so that only item need be present.

Also updated the indentation to be a bit more consistent across the navigation components, see edbb9f6f44288973b5c0c55ba8bb438d9cb9e040 for the actual changes.

paulrobertlloyd commented 4 months ago

Hard to review as you changed all the indentation at the same time 😛

Cough:

Also updated the indentation to be a bit more consistent across the navigation components, see https://github.com/x-govuk/govuk-prototype-components/commit/edbb9f6f44288973b5c0c55ba8bb438d9cb9e040 for the actual changes.

frankieroberto commented 4 months ago

@paulrobertlloyd heh, I somehow missed that last para and went straight to the Files changed tab... 🤦