@ministryofjustice/hmpps-mpop-frontend-components-lib 0.0.36 → 0.0.38

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.
@@ -0,0 +1 @@
1
+ export {};
package/dist/js/all.js ADDED
@@ -0,0 +1,6 @@
1
+ /* global document */
2
+ import * as personHeader from './person-header.js'
3
+
4
+ export function initAll(scope = document) {
5
+ personHeader.init(scope)
6
+ }
@@ -0,0 +1,33 @@
1
+ /* global document */
2
+ const MODULE_NAME = 'mpop-risk-flags-toggle'
3
+
4
+ /*
5
+ * Show/hide toggle for the person header's NDelius risk flags (transactional variant).
6
+ * The toggle is rendered hidden so that without JS the risk flags are always shown.
7
+ * State is not persisted - the flags are shown again on every page load.
8
+ */
9
+
10
+ function setExpanded($toggle, $flags, expanded) {
11
+ $toggle.setAttribute('aria-expanded', String(expanded))
12
+ $toggle.replaceChildren($toggle.getAttribute(expanded ? 'data-hide-text' : 'data-show-text'))
13
+ $flags.toggleAttribute('hidden', !expanded)
14
+ }
15
+
16
+ function initToggle($toggle) {
17
+ const $flags = $toggle.parentElement.querySelector(`[id="${$toggle.getAttribute('aria-controls')}"]`)
18
+
19
+ if (!$flags || $toggle.hasAttribute(`data-${MODULE_NAME}-init`)) {
20
+ return
21
+ }
22
+
23
+ $toggle.setAttribute(`data-${MODULE_NAME}-init`, '')
24
+ $toggle.addEventListener('click', () =>
25
+ setExpanded($toggle, $flags, $toggle.getAttribute('aria-expanded') !== 'true'),
26
+ )
27
+ setExpanded($toggle, $flags, true)
28
+ $toggle.removeAttribute('hidden')
29
+ }
30
+
31
+ export function init(scope = document) {
32
+ scope.querySelectorAll(`[data-module="${MODULE_NAME}"]`).forEach(initToggle)
33
+ }
@@ -55,4 +55,24 @@
55
55
  .person-header__risk-panel + .person-header__risk-panel {
56
56
  margin-top: 0 !important;
57
57
  padding-top: 0 !important;
58
- }
58
+ }
59
+
60
+ .person-header__risk-tags[hidden] {
61
+ display: none;
62
+ }
63
+
64
+ .person-header__risk-flags-toggle {
65
+ @include govuk-font($size: 19);
66
+ align-self: flex-start;
67
+ margin: -2px 0;
68
+ padding: 2px 0;
69
+ border: 0;
70
+ background: none;
71
+ color: govuk-functional-colour(link);
72
+ text-align: left;
73
+ cursor: pointer;
74
+
75
+ @media (forced-colors: active) {
76
+ color: LinkText;
77
+ }
78
+ }
@@ -60,12 +60,17 @@ $risk-badge-very-high: #711a0d;
60
60
  $risk-badge-high: #d4351c;
61
61
  $risk-badge-medium: #f2590d;
62
62
  $risk-badge-low: #85994b;
63
+ $cohort-risk-badge: #54319f;
64
+ $misc-risk-badge: #484949;
63
65
 
66
+ /* Map badge classes to their border and hover colours */
64
67
  $risk-badge-colours: (
65
68
  'very-high': $risk-badge-very-high,
66
69
  'high': $risk-badge-high,
67
70
  'medium': $risk-badge-medium,
68
71
  'low': $risk-badge-low,
72
+ 'cohort': $cohort-risk-badge,
73
+ 'misc': $misc-risk-badge,
69
74
  );
70
75
 
71
76
  @each $level, $colour in $risk-badge-colours {
@@ -75,19 +80,23 @@ $risk-badge-colours: (
75
80
  &:hover {
76
81
  background-color: $colour;
77
82
  color: #fff;
78
- text-decoration-thickness: 2px;
79
83
  }
80
84
  }
81
85
  }
82
86
 
83
- .person-header__risk-tags .dps-alert-status:focus {
84
- outline: 3px solid transparent;
85
- color: #0b0c0c;
86
- background-color: #ffdd00;
87
- box-shadow: 0 -2px #ffdd00, 0 4px #0b0c0c;
88
- text-decoration: none;
87
+ /* Keyboard focus state and Mouse hover state */
88
+ .person-header__risk-tags a.dps-alert-status {
89
+ &:hover,
90
+ &:focus,
91
+ &:focus-visible {
92
+ border: 3px solid #0b0c0c !important;
93
+ outline: none !important;
94
+ box-shadow: 0 0 0 3px #ffdd00 !important;
95
+ }
89
96
  }
90
97
 
98
+ /* More risk flags link */
91
99
  .person-header__risk-tags .risk-badge-more {
100
+ @include govuk-font($size: 19);
92
101
  white-space: nowrap;
93
102
  }
@@ -1,5 +1,5 @@
1
1
 
2
- <div class='person-header'>
2
+ <div class='person-header govuk-body'>
3
3
  <div class='person-header__band{% if params.photo %} person-header__band--with-photo{% endif %}'>
4
4
  {% if params.photo %}
5
5
  <img
@@ -103,8 +103,12 @@
103
103
  params.personRiskFlags.groups and
104
104
  (params.personRiskFlags.groups | length) > 0 %}
105
105
 
106
+ {# Unique per person so each toggle's aria-controls points at its own risk flags #}
107
+ {% set riskFlagsId = 'person-header-risk-flags-' + params.crn %}
108
+
106
109
  <div class='person-header__risk-panel'>
107
110
  <div
111
+ {% if params.collapsibleRiskFlags %}id='{{ riskFlagsId }}'{% endif %}
108
112
  class='person-header__risk-tags'
109
113
  data-qa='personRiskBadges'
110
114
  >
@@ -117,6 +121,8 @@
117
121
  >
118
122
  {% if risk.text | replace(' - Very High', '') != risk.text %}
119
123
  {{ risk.text | replace(' - Very High', ' -&nbsp;<strong>Very High</strong>') | safe }}
124
+ {% elif risk.text | replace(' - Very high', '') != risk.text %}
125
+ {{ risk.text | replace(' - Very high', ' -&nbsp;<strong>Very high</strong>') | safe }}
120
126
  {% elif risk.text | replace(' - High', '') != risk.text %}
121
127
  {{ risk.text | replace(' - High', ' -&nbsp;<strong>High</strong>') | safe }}
122
128
  {% elif risk.text | replace(' - Medium', '') != risk.text %}
@@ -140,6 +146,22 @@
140
146
  </a>
141
147
  {% endif %}
142
148
  </div>
149
+
150
+ {% if params.collapsibleRiskFlags %}
151
+ <button
152
+ type='button'
153
+ class='govuk-link person-header__risk-flags-toggle'
154
+ data-module='mpop-risk-flags-toggle'
155
+ data-show-text='Show active NDelius risk flags'
156
+ data-hide-text='Hide active NDelius risk flags'
157
+ aria-controls='{{ riskFlagsId }}'
158
+ aria-expanded='true'
159
+ data-qa='riskFlagsToggle'
160
+ hidden
161
+ >
162
+ Hide active NDelius risk flags
163
+ </button>
164
+ {% endif %}
143
165
  </div>
144
166
  {% endif %}
145
167
  {% endif %}
@@ -1,3 +1,5 @@
1
+ {% set appointmentsRemaining = (params.currentYear.appointments.allowance | int) - (params.earlyEngagement.weeks | int) %}
2
+
1
3
  {% if forename and (params.earlyEngagement.completed | int < params.earlyEngagement.weeks | int) %}
2
4
  <p class='govuk-body'>
3
5
  You should see {{ forename }} every week for the first {{ params.earlyEngagement.weeks }} weeks of the sentence.
@@ -10,7 +12,7 @@
10
12
 
11
13
  {% if params.currentYear.appointments.allowance is defined and params.earlyEngagement.weeks is defined %}
12
14
  <p class='govuk-body'>
13
- {{ forename }} will then have a maximum of {{ (params.currentYear.appointments.allowance | int) - (params.earlyEngagement.weeks | int) }} supervision appointments for the rest of this sentence year.
15
+ {{ forename }} will then have a maximum of {{ (appointmentsRemaining) if appointmentsRemaining > 0 else 0 }} supervision appointments for the rest of this sentence year.
14
16
  </p>
15
17
  {% endif %}
16
18
 
@@ -98,8 +98,9 @@
98
98
  {% if completed < required %}
99
99
  <p class="govuk-body">You should see {{ forename }} every week for the first {{ params.earlyEngagement.weeks }} weeks of the sentence.</p>
100
100
  {% endif %}
101
- <p class="govuk-body">Early engagement is expected to end on {{ params.earlyEngagement.endDate | dateWithYear }} if {{ forename }} attends the required appointments by then.</p>
102
- <p class="govuk-body">{{ forename }} will then have a maximum of {{ (params.currentYear.appointments.allowance | int(0)) - (params.earlyEngagement.weeks | int(0)) }} supervision appointments for the rest of this sentence year.</p>
101
+ <p class="govuk-body">Early engagement is expected to end on {{ params.earlyEngagement.endDate | dateWithYear }}{% if completed < required %} if {{ forename }} attends the required appointments by then{% endif %}.</p>
102
+ {% set appointmentsRemaining = (params.currentYear.appointments.allowance | int(0)) - (params.earlyEngagement.weeks | int(0)) %}
103
+ <p class="govuk-body">{{ forename }} will then have a maximum of {{ (appointmentsRemaining) if appointmentsRemaining > 0 else 0 }} supervision appointments for the rest of this sentence year.</p>
103
104
  {% endif %}
104
105
  {% if params.currentPhase.phase.code == 'STD' %}
105
106
  <p class="govuk-body">{{ forename }} has a maximum of {{ remaining }} appointments remaining.</p>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-mpop-frontend-components-lib",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "description": "MPOP front-end components library",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",
@@ -35,10 +35,22 @@
35
35
  },
36
36
  "jest": {
37
37
  "transform": {
38
- "^.+\\.(ts|js|mjs|tsx|jsx)$": "babel-jest"
38
+ "^.+\\.(ts|js|mjs|tsx|jsx)$": [
39
+ "ts-jest",
40
+ {
41
+ "tsconfig": {
42
+ "allowJs": true,
43
+ "ignoreDeprecations": "6.0",
44
+ "module": "commonjs",
45
+ "moduleResolution": "node",
46
+ "esModuleInterop": true,
47
+ "allowSyntheticDefaultImports": true
48
+ }
49
+ }
50
+ ]
39
51
  },
40
52
  "transformIgnorePatterns": [
41
- "/node_modules/(?!(@exodus|@csstools|jsdom|parse5|abab|entities|nunjucks|@asamuzakjp)/)"
53
+ "/node_modules/(?!(@exodus|@csstools|parse5|abab|entities|nunjucks|@asamuzakjp)/)"
42
54
  ],
43
55
  "testMatch": [
44
56
  "<rootDir>/**/**/?(*.)(cy|test).{ts,js,jsx,mjs}"
@@ -60,9 +72,6 @@
60
72
  "author": "",
61
73
  "license": "ISC",
62
74
  "devDependencies": {
63
- "@babel/core": "^7.29.7",
64
- "@babel/preset-env": "^7.29.7",
65
- "@babel/preset-typescript": "^7.29.7",
66
75
  "@ministryofjustice/eslint-config-hmpps": "1.0.3",
67
76
  "@ministryofjustice/hmpps-npm-script-allowlist": "0.0.6",
68
77
  "@ministryofjustice/hmpps-precommit-hooks": "3.0.2",
@@ -74,7 +83,6 @@
74
83
  "@types/luxon": "3.7.5",
75
84
  "@types/node": "25.9.5",
76
85
  "@typescript-eslint/eslint-plugin": "8.69.0",
77
- "babel-jest": "^30.5.1",
78
86
  "dotenv": "17.4.2",
79
87
  "eslint-import-resolver-typescript": "4.4.5",
80
88
  "eslint-plugin-no-only-tests": "3.4.0",
@@ -85,8 +93,8 @@
85
93
  "nunjucks": "^3.2.4",
86
94
  "prettier": "3.9.6",
87
95
  "rollup": "^4.63.1",
88
- "rollup-plugin-copy": "3.5.0",
89
96
  "rollup-plugin-dts": "^6.5.1",
97
+ "ts-jest": "^29.4.14",
90
98
  "tslib": "^2.8.1",
91
99
  "tsx": "4.23.13",
92
100
  "typescript": "^6.0.3"
@@ -106,11 +114,13 @@
106
114
  "brace-expansion@1": "1.1.21",
107
115
  "brace-expansion@2": "2.1.7",
108
116
  "brace-expansion@5": "5.0.12",
117
+ "handlebars": "4.7.10",
109
118
  "jsdom": {
110
119
  "undici": "7.29.1"
111
120
  },
112
121
  "node-gyp": {
113
122
  "undici": "6.28.1"
114
- }
123
+ },
124
+ "source-map-js": "1.2.2"
115
125
  }
116
126
  }