Skip to content

Commit be7ebb1

Browse files
Move read only config to breast diagram
1 parent cedaf6b commit be7ebb1

5 files changed

Lines changed: 42 additions & 49 deletions

File tree

manage_breast_screening/assets/js/breast-diagram.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export class BreastDiagram extends ConfigurableComponent {
3838
constructor($root, config = {}) {
3939
super($root, config)
4040

41+
const { readOnly } = this.config
42+
4143
const $input = this.$root.querySelector('input[name="features"]')
4244
if (!($input instanceof HTMLInputElement)) {
4345
throw new ElementError({
@@ -56,7 +58,6 @@ export class BreastDiagram extends ConfigurableComponent {
5658
ImageMap,
5759
{
5860
imageClass: 'app-breast-diagram__svg',
59-
readOnly: $input.readOnly,
6061
selectors: [
6162
'.app-breast-diagram__regions path',
6263
'.app-breast-diagram__regions polygon'
@@ -74,7 +75,7 @@ export class BreastDiagram extends ConfigurableComponent {
7475

7576
this.$imageMap = $imageMaps[0]
7677

77-
if (!this.$imageMap.config.readOnly) {
78+
if (!readOnly) {
7879
this.$imageMap.addEventListener('click', (event) => this.onClick(event))
7980
this.$imageMap.addEventListener('hover', (event) => this.log(event))
8081
}
@@ -282,7 +283,8 @@ export class BreastDiagram extends ConfigurableComponent {
282283
* @type {BreastDiagramConfig}
283284
*/
284285
static defaults = Object.freeze({
285-
debug: false
286+
debug: false,
287+
readOnly: false
286288
})
287289

288290
/**
@@ -293,7 +295,8 @@ export class BreastDiagram extends ConfigurableComponent {
293295
*/
294296
static schema = Object.freeze({
295297
properties: {
296-
debug: { type: 'boolean' }
298+
debug: { type: 'boolean' },
299+
readOnly: { type: 'boolean' }
297300
}
298301
})
299302
}
@@ -354,6 +357,7 @@ function isValid(value) {
354357
* @see {@link BreastDiagram.defaults}
355358
* @typedef {object} BreastDiagramConfig
356359
* @property {boolean} debug - Whether to show debug information
360+
* @property {boolean} readOnly - Whether image map is read only
357361
*/
358362

359363
/**

manage_breast_screening/assets/js/image-map.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import { ConfigurableComponent, ElementError } from 'nhsuk-frontend'
88
export class ImageMap extends ConfigurableComponent {
99
/**
1010
* @param {Element | null} $root - HTML element to use for component
11-
* @param {Partial<Pick<ImageMapConfig, 'imageClass' | 'readOnly' | 'selectors'>>} [config] - Image map config
11+
* @param {Partial<Pick<ImageMapConfig, 'imageClass' | 'selectors'>>} [config] - Image map config
1212
*/
1313
constructor($root, config = {}) {
1414
super($root, config)
1515

16-
const { imageClass, readOnly, selectorsQuery, selectorsFormatted } =
17-
this.config
16+
const { imageClass, selectorsQuery, selectorsFormatted } = this.config
1817

1918
const $image = this.$root.querySelector(`.${imageClass}`)
2019
if (!$image || !($image instanceof SVGSVGElement)) {
@@ -39,10 +38,8 @@ export class ImageMap extends ConfigurableComponent {
3938
this.$paths = Array.from($paths).reverse()
4039
this.$image = $image
4140

42-
if (!readOnly) {
43-
this.$image.addEventListener('mousemove', this.onMouseMove.bind(this))
44-
this.$image.addEventListener('click', this.onClick.bind(this))
45-
}
41+
this.$image.addEventListener('mousemove', this.onMouseMove.bind(this))
42+
this.$image.addEventListener('click', this.onClick.bind(this))
4643
}
4744

4845
/**
@@ -230,7 +227,6 @@ export class ImageMap extends ConfigurableComponent {
230227
*/
231228
static defaults = Object.freeze({
232229
imageClass: 'nhsuk-image__img',
233-
readOnly: false,
234230
selectors: ['path', 'polygon'],
235231
selectorsQuery: '',
236232
selectorsFormatted: ''
@@ -245,7 +241,6 @@ export class ImageMap extends ConfigurableComponent {
245241
static schema = Object.freeze({
246242
properties: {
247243
imageClass: { type: 'string' },
248-
readOnly: { type: 'boolean' },
249244
selectors: { type: 'array' },
250245
selectorsQuery: { type: 'string' },
251246
selectorsFormatted: { type: 'string' }
@@ -259,7 +254,6 @@ export class ImageMap extends ConfigurableComponent {
259254
* @see {@link ImageMap.defaults}
260255
* @typedef {object} ImageMapConfig
261256
* @property {string} imageClass - Image class
262-
* @property {boolean} readOnly - Whether image map is read only
263257
* @property {string[]} selectors - Image map region selectors
264258
* @property {string} selectorsQuery - Image map region selectors (for DOM query selector)
265259
* @property {string} selectorsFormatted - Image map region selectors (formatted for error messages)

manage_breast_screening/assets/sass/components/_breast-diagram.scss

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,44 @@ $state-active: nhsuk-tint(nhsuk-colour("blue"), 50%);
2525

2626
.app-breast-diagram__svg {
2727
display: block;
28-
}
2928

30-
.app-breast-diagram__regions [data-active] {
31-
[data-debug] & {
32-
fill: $state-active;
29+
.app-breast-diagram:not([data-read-only]) & {
30+
pointer-events: all;
31+
cursor: crosshair;
3332
}
3433
}
3534

36-
.app-breast-diagram__image-map:not([data-read-only]) {
37-
.app-breast-diagram__svg {
38-
pointer-events: all;
39-
cursor: crosshair;
35+
.app-breast-diagram__diagram {
36+
pointer-events: none;
37+
}
38+
39+
.app-breast-diagram[data-debug] {
40+
.app-breast-diagram__regions [data-active] {
41+
fill: $state-active;
4042
}
43+
}
4144

45+
.app-breast-diagram[data-debug]:not([data-read-only]) {
4246
.app-breast-diagram__regions path,
4347
.app-breast-diagram__regions polygon {
44-
[data-debug] & {
45-
// Slow fade out (default)
46-
transition: fill 0.3s ease-in;
47-
}
48+
// Slow fade out (default)
49+
transition: fill 0.3s ease-in;
4850
}
4951

5052
.app-breast-diagram__regions path:hover,
5153
.app-breast-diagram__regions polygon:hover,
5254
.app-breast-diagram__regions [data-active] {
53-
[data-debug] & {
54-
// Fast fade in (on hover)
55-
transition-duration: 0.05s;
56-
transition-timing-function: ease-out;
57-
}
55+
// Fast fade in (on hover)
56+
transition-duration: 0.05s;
57+
transition-timing-function: ease-out;
5858
}
5959

6060
.app-breast-diagram__regions path:hover,
6161
.app-breast-diagram__regions polygon:hover {
62-
[data-debug] & {
63-
fill: $state-highlight;
64-
}
62+
fill: $state-highlight;
6563
}
6664

6765
.app-breast-diagram__regions [data-active]:hover {
68-
[data-debug] & {
69-
fill: color.adjust(color.mix($state-active, $state-highlight, 75%), $lightness: 10%, $saturation: 25%);
70-
}
66+
fill: color.adjust(color.mix($state-active, $state-highlight, 75%), $lightness: 10%, $saturation: 25%);
7167
}
7268
}
73-
74-
.app-breast-diagram__diagram {
75-
pointer-events: none;
76-
}

manage_breast_screening/core/jinja2/components/breast-diagram/template.jinja

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
<figure
99
{{- nhsukAttributes({
1010
"class": "app-breast-diagram__image-map nhsuk-u-width-full",
11-
"data-module": "app-image-map",
12-
"data-read-only": {
13-
"value": "true" if params.read_only else false,
14-
"optional": true
15-
}
11+
"data-module": "app-image-map"
1612
}) -}}
1713

1814
{{- nhsukAttributes(params.attributes) -}}>

manage_breast_screening/mammograms/jinja2/mammograms/medical_information/breast_features/form.jinja

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@
99

1010
{% from "components/breast-diagram/macro.jinja" import app_breast_diagram %}
1111

12+
{% set diagram_debug = "debug" in request.GET %}
13+
{% set diagram_read_only = false %}
14+
1215
{% set form_attributes = {
1316
"class": "app-breast-diagram",
1417
"action": request.path,
1518
"method": "post",
1619
"data-module": "app-breast-diagram",
1720
"data-debug": {
18-
"value": "true" if "debug" in request.GET else false,
21+
"value": "true" if diagram_debug else false,
22+
"optional": true
23+
},
24+
"data-read-only": {
25+
"value": "true" if diagram_read_only else false,
1926
"optional": true
2027
},
2128
"novalidate": {
@@ -49,8 +56,8 @@
4956
</div>
5057

5158
{{ app_breast_diagram({
52-
"debug": "debug" in request.GET,
53-
"read_only": false,
59+
"debug": diagram_debug,
60+
"read_only": diagram_read_only,
5461
"version": diagram_version,
5562
"attributes": {
5663
"aria-labelledby": "breast-diagram-description"

0 commit comments

Comments
 (0)