alphagov / govuk-frontend

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.
https://frontend.design-system.service.gov.uk/
MIT License
1.16k stars 319 forks source link

Agree how to structure the cookie banner (one or two components) #2095

Closed vanitabarrett closed 3 years ago

vanitabarrett commented 3 years ago

What

Decide if the cookie banner and the confirmation banner are the same component. Could be:

  1. A single component which encapsulates the question banner and the confirmation banner
  2. Two components, one for the question banner and one for the confirmation banner

Why

Making a decision about this upfront will simplify the development process. We've done some prototyping of both options here: https://github.com/alphagov/govuk-frontend/pull/2081

Who needs to know about this

Developers Technical Writers / Content Design Designers

Done when

vanitabarrett commented 3 years ago

I think there's at least 3 different ways this component could be used, and they each probably need slightly different treatments…

Server-side

When the 'accept all' / 'reject all' buttons are pressed, the browser POSTs to the server, and a full page navigation occurs.

Client-side (synchronous)

When the 'accept all' / 'reject all' buttons are pressed, the client-side JavaScript provided by the service team sets any required cookies and fires any other events required, and the cookie banner is replaced by the 'accepted' / 'rejected' banner immediately.

This only works if cookies are only set from the client-side JS, and not from the server?

Client-side (asynchronous)

When the 'accept all' / 'reject all' buttons are pressed, an AJAX request is made to the server.

The 'accepted' / 'rejected' banner is either displayed immediately or after the request has completed (see below).

Originally posted by @36degrees in https://github.com/alphagov/design-system-team-internal/issues/402#issuecomment-739949168

vanitabarrett commented 3 years ago

Summary

There were 3 different options which we prototyped:

  1. One component - strict macro options which are different for each banner, e.g: a user would need to provide params for confirmationBanner and a questionBanner.
  2. One component - generic macro options which are the same for each banner, e.g: a user can pass an array of banners each with a number of actions.
  3. Two components - one question banner and one confirmation banner

The design of the banners means we should be able to make the options generic (apply to all), and this would also help to simplify the Nunjucks API. We've therefore decided to go with Option 2 for now, but to keep an open mind as we start building the component. If anything crops up, we may need to revisit this decision.

Example

An example of what Option 2 might look like. A fuller example has been implemented in the prototype here

We still need to make decisions on the following:

{{ govukCookieBanner({
    banners: [{
      title: "Cookies on [service name]",
      html: "<p>We use cookies to make this service work</p><p>We'd like to set some additional cookies so we can remember your settings, understand how you use the service and make improvements.</p>",
      attributes: {
        "data-module": "govuk-cookie-banner-question"
      },
      actions: [
        {
          text: "Accept cookies",
          attributes: {
            "data-accept-cookies": "accept"
          }
        },
        {
          text: "Reject cookies",
          attributes: {
            "data-reject-cookies": "reject"
          }
        },
        {
          text: "View cookies and set preferences",
          href: "/cookie-preferences"
        }
      ]
    }, {
      html: "<p>You've accepted additional cookies. You can <a href='/cookie-preferences'>change your cookie settings</a> at any time.</p>",
      attributes: {
        "data-module": "govuk-cookie-banner-accept",
        "tabindex": "-1"
      },
      hidden: true
    }, {
      html: "<p>You've rejected additional cookies. You can <a href='/cookie-preferences'>change your cookie settings</a> at any time.</p>",
      attributes: {
        "data-module": "govuk-cookie-banner-reject",
        "tabindex": "-1"
      },
      hidden: true
    }]
  }) }}