@communitiesuk/svelte-component-library 0.1.19-beta.7.0 → 0.1.19-beta.9

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.
@@ -23,6 +23,7 @@
23
23
  class="c inline h-16 w-16"
24
24
  viewBox="0 0 48 48"
25
25
  style={`transform: rotate(${rotation}deg)`}
26
+ aria-hidden={true}
26
27
  >
27
28
  {#each paths as path}
28
29
  <path d={path}></path>
@@ -41,16 +41,15 @@ left: {markerRect?.x +
41
41
  border-radius: 5px;"
42
42
  >
43
43
  {#if tooltipContent}
44
- <div>
44
+ <div role="tooltip">
45
45
  {activeMarkerId[tooltipContent]}
46
46
  </div>
47
47
  {:else}
48
- <div>
49
- <div>{activeMarkerId?.value ?? activeMarkerId}</div>
50
- </div>{/if}
48
+ <div role="tooltip">{activeMarkerId?.value ?? activeMarkerId}</div>
49
+ {/if}
51
50
  </div>
52
51
  {:else}
53
- <div>
52
+ <div role="tooltip">
54
53
  {@render tooltipSnippet(activeMarkerId)}
55
54
  </div>
56
55
  {/if}
@@ -12,7 +12,7 @@
12
12
  showAxis = true,
13
13
  chartWidth = $bindable(500), // the 'chart' is the bar and the marker
14
14
  chartHeight = 24,
15
- colour = "#CA357C",
15
+ color = "#CA357C",
16
16
  nSegments = 10,
17
17
  startColor = "#8EB8DC",
18
18
  endColor = "#0F385C",
@@ -27,7 +27,7 @@
27
27
  rowData = [
28
28
  {
29
29
  value: value,
30
- colour: colour,
30
+ color: color,
31
31
  opacity: opacity,
32
32
  annotation: annotation,
33
33
  },
@@ -79,10 +79,12 @@
79
79
  activeMarkerId = null;
80
80
  },
81
81
  activeMarkerId = undefined,
82
+ ariaLabel,
83
+ axisTextSize,
82
84
  } = $props();
83
85
 
84
86
  // base defaults that apply to every row
85
- const baseRow = { value, colour, opacity, annotation };
87
+ const baseRow = { value, color, opacity, annotation };
86
88
 
87
89
  // base defaults that apply to every chart
88
90
  const baseChart = { label, chartHeight, min, max, showAxis };
@@ -234,218 +236,244 @@
234
236
  ),
235
237
  );
236
238
 
239
+ $inspect(allDataNormalized, "allDataNormalized");
240
+
237
241
  let gridTemplateRows = $derived(
238
242
  allDataNormalized
239
243
  .map((item, i) => {
240
- const sizes = ["minmax(0,1fr)"];
241
- if (moreInfoTogglesArray[i]) sizes.push("minmax(0,auto)");
242
- if (item.divider === "true") sizes.push("minmax(0,auto)");
244
+ const sizes = ["minmax(28px,1fr)"];
245
+ if (moreInfoTogglesArray[i]) sizes.push("minmax(50px,auto)");
246
+ if (item.divider) sizes.push("0px");
243
247
  return sizes.join(" "); // still fine because number of rows matches
244
248
  })
245
- .concat(showAxis ? ["minmax(0,auto)"] : [])
249
+ .concat(showAxis ? ["minmax(0px,auto)"] : [])
246
250
  .join(" "),
247
251
  );
248
252
  </script>
249
253
 
250
- {#if annotations.length}
251
- {#each annotations as d (d.value)}
252
- <div bind:clientWidth={topWidth}>
253
- <svg width={topWidth} height="60">
254
- <g>
255
- <text
256
- font-family="GDS Transport"
257
- id="label"
258
- x={d.value}
259
- y="20"
260
- fill={d.colour}
261
- font-size="18"
262
- opacity={typeof activeMarkerId !== "undefined" && activeMarkerId
263
- ? 0.2
264
- : 1}
265
- >
266
- {d.annotation}
267
- </text>
268
- </g>
269
- <defs>
270
- <marker
271
- id="arrow-down"
272
- markerWidth="10"
273
- markerHeight="10"
274
- refX="3"
275
- refY="3"
276
- orient="auto"
277
- markerUnits="strokeWidth"
254
+ <div role="img" aria-label={ariaLabel}>
255
+ {#if annotations.length}
256
+ {#each annotations as d (d.value)}
257
+ <div bind:clientWidth={topWidth} aria-hidden={true}>
258
+ <svg width={topWidth} height="60">
259
+ <g>
260
+ <text
261
+ font-family="GDS Transport"
262
+ id="label"
263
+ x={d.value}
264
+ y="20"
265
+ fill={d.color}
266
+ font-size="18"
267
+ opacity={typeof activeMarkerId !== "undefined" && activeMarkerId
268
+ ? 0.2
269
+ : 1}
270
+ >
271
+ {d.annotation}
272
+ </text>
273
+ </g>
274
+ <defs>
275
+ <marker
276
+ id="arrow-down"
277
+ markerWidth="10"
278
+ markerHeight="10"
279
+ refX="3"
280
+ refY="3"
281
+ orient="auto"
282
+ markerUnits="strokeWidth"
283
+ opacity={typeof activeMarkerId !== "undefined" && activeMarkerId
284
+ ? 0.2
285
+ : 1}
286
+ >
287
+ <path d="M 0 0 L 6 3 L 0 6 z" fill={d.color}></path>
288
+ </marker>
289
+ </defs>
290
+ <path
291
+ d="M 4 25 v 10 h {xFunction(min, max)(d.value) +
292
+ markerRadius -
293
+ 4 +
294
+ (topWidth - chartWidth)} v 15"
295
+ fill="none"
296
+ stroke={d.color}
297
+ stroke-width="1.5"
298
+ marker-end="url(#arrow-down)"
278
299
  opacity={typeof activeMarkerId !== "undefined" && activeMarkerId
279
300
  ? 0.2
280
301
  : 1}
281
- >
282
- <path d="M 0 0 L 6 3 L 0 6 z" fill={d.colour}></path>
283
- </marker>
284
- </defs>
285
- <path
286
- d="M 4 25 v 10 h {xFunction(min, max)(d.value) +
287
- markerRadius -
288
- 4 +
289
- (topWidth - chartWidth)} v 15"
290
- fill="none"
291
- stroke={d.colour}
292
- stroke-width="1.5"
293
- marker-end="url(#arrow-down)"
294
- opacity={typeof activeMarkerId !== "undefined" && activeMarkerId
295
- ? 0.2
296
- : 1}
297
- ></path>
298
- </svg>
299
- </div>
300
- {/each}
301
- {/if}
302
+ ></path>
303
+ </svg>
304
+ </div>
305
+ {/each}
306
+ {/if}
302
307
 
303
- <div
304
- class="grid-container"
305
- bind:this={container}
306
- style="
308
+ <div
309
+ class="grid-container"
310
+ bind:this={container}
311
+ style="
307
312
  position: relative;
308
313
  grid-template-columns: {gridTemplateColumns};
309
314
  grid-template-rows: {gridTemplateRows};
310
315
  "
311
- >
312
- {#each allDataNormalized as positionChart, i}
313
- {#if showLabel}
314
- <p
315
- class="govuk-body-s"
316
- style=" text-align: right;
316
+ >
317
+ {#each allDataNormalized as positionChart, i}
318
+ {#if showLabel}
319
+ <p
320
+ aria-hidden={true}
321
+ class="govuk-body-s"
322
+ style=" text-align: right;
317
323
  margin: 0;
318
324
  line-height: 1.05;"
319
- >
320
- {positionChart.label}
321
- </p>
322
- {/if}
323
- {#if showIcon}
324
- <div class="button-container">
325
+ >
326
+ {positionChart.label}
327
+ </p>
328
+ {/if}
329
+ {#if showIcon}
325
330
  <Button
326
331
  textContent="i"
327
332
  buttonType="moreInfo"
328
333
  noPadding={true}
329
334
  onClickFunction={() => updateMoreInfoTogglesArray(i)}
335
+ ariaExpanded={moreInfoTogglesArray[i]}
330
336
  ></Button>
331
- </div>
332
- {/if}
333
- <div
334
- class="chart"
335
- style="height: {positionChart.chartHeight}px"
336
- bind:clientWidth={chartWidth}
337
- >
338
- <svg width={chartWidth} height={positionChart.chartHeight}>
339
- {#each range as number}
340
- <g
341
- transform="translate({markerRadius +
342
- (barWidth * number) / nSegments},{(positionChart.chartHeight -
343
- barHeight) /
344
- 2})"
345
- ><rect
346
- width={barWidth / nSegments}
347
- height={barHeight}
348
- fill={colorScale && colorScale.length > 0
349
- ? colorScale[number]
350
- : interpolateColors(startColor, endColor, nSegments, midColor)[
351
- number
352
- ]}
353
- ></rect></g
354
- >{/each}
355
- {#each Object.entries(positionChart.rowData) as [tier, points]}
356
- {#each points as rowValue, i}
357
- {#if !isNaN(Number(rowValue.value))}
358
- {@const markerId = "marker-" + rowValue.value}
359
- <g
360
- data-id={markerId}
361
- onclick={interactiveMarkers
362
- ? (event) => onClickMarker(event, rowValue, markerId)
363
- : null}
364
- onmouseenter={interactiveMarkers
365
- ? (event) =>
366
- onMouseEnterMarker(
367
- event,
368
- rowValue,
369
- markerId,
370
- event.currentTarget.getBoundingClientRect(),
371
- )
372
- : null}
373
- onmouseleave={interactiveMarkers
374
- ? (event) => onMouseLeaveMarker(event, rowValue, markerId)
375
- : null}
376
- role="button"
377
- tabindex="0"
378
- onkeydown={interactiveMarkers
379
- ? (e) => e.key === "Enter" && onClickMarker(e, value)
380
- : null}
381
- pointer-events={interactiveMarkers ? null : "none"}
382
- transform="translate({xFunction(
383
- positionChart.min,
384
- positionChart.max,
385
- )(rowValue.value) + markerRadius},{positionChart.chartHeight /
386
- 2})"
387
- >
388
- <circle
389
- r={markerRadius}
390
- cx="0"
391
- cy="0"
392
- fill={rowValue.colour}
393
- stroke="white"
394
- opacity={rowValue.opacity}
395
- ></circle>
396
- </g>
397
- {/if}
398
- {/each}
399
- {/each}
400
- </svg>
401
- </div>
402
- {#if moreInfoTogglesArray[i]}
403
- <div class="accordion" style="grid-column:1 / -1">
404
- <InsetText content={positionChart.moreInfo} renderStringAsHTML={true}
405
- ></InsetText>
406
- </div>
407
- {/if}
408
- {#if positionChart.divider}
409
- <div style="grid-column:1 / -1">
410
- <svg width="100%" height="5">
411
- <line
412
- x1="0"
413
- y1="2.5"
414
- x2="100%"
415
- y2="2.55"
337
+ {/if}
338
+ <div
339
+ class="chart"
340
+ style="height: {positionChart.chartHeight}px"
341
+ bind:clientWidth={chartWidth}
342
+ >
343
+ <svg
344
+ width={chartWidth}
345
+ height={positionChart.chartHeight}
346
+ aria-hidden={true}
347
+ >
348
+ <rect
349
+ x={markerRadius}
350
+ y={(positionChart.chartHeight - barHeight) / 2}
351
+ width={barWidth}
352
+ height={barHeight}
353
+ fill="none"
416
354
  stroke="grey"
417
- stroke-width="0.5"
418
- ></line>
355
+ stroke-width="1"
356
+ ></rect>
357
+ {#each range as number}
358
+ <g
359
+ transform="translate({markerRadius +
360
+ (barWidth * number) / nSegments},{(positionChart.chartHeight -
361
+ barHeight) /
362
+ 2})"
363
+ ><rect
364
+ width={barWidth / nSegments}
365
+ height={barHeight}
366
+ fill={colorScale && colorScale.length > 0
367
+ ? colorScale[number]
368
+ : interpolateColors(
369
+ startColor,
370
+ endColor,
371
+ nSegments,
372
+ midColor,
373
+ )[number]}
374
+ ></rect></g
375
+ >{/each}
376
+
377
+ {#each Object.entries(positionChart.rowData) as [tier, points]}
378
+ {#each points as rowValue, i}
379
+ {#if !isNaN(Number(rowValue.value))}
380
+ {@const markerId = "marker-" + rowValue.value}
381
+ <g
382
+ data-id={markerId}
383
+ onclick={interactiveMarkers
384
+ ? (event) => onClickMarker(event, rowValue, markerId)
385
+ : null}
386
+ onmouseenter={interactiveMarkers
387
+ ? (event) =>
388
+ onMouseEnterMarker(
389
+ event,
390
+ rowValue,
391
+ markerId,
392
+ event.currentTarget.getBoundingClientRect(),
393
+ )
394
+ : null}
395
+ onmouseleave={interactiveMarkers
396
+ ? (event) => onMouseLeaveMarker(event, rowValue, markerId)
397
+ : null}
398
+ onfocus={interactiveMarkers
399
+ ? (event) =>
400
+ onMouseEnterMarker(
401
+ event,
402
+ rowValue,
403
+ markerId,
404
+ event.currentTarget.getBoundingClientRect(),
405
+ )
406
+ : null}
407
+ onblur={interactiveMarkers
408
+ ? (event) => onMouseLeaveMarker(event, rowValue, markerId)
409
+ : null}
410
+ role="button"
411
+ aria-label={tooltipContent}
412
+ tabindex="0"
413
+ onkeydown={interactiveMarkers
414
+ ? (event) => onClickMarker(event, rowValue, markerId)
415
+ : null}
416
+ pointer-events={interactiveMarkers ? null : "none"}
417
+ transform="translate({xFunction(
418
+ positionChart.min,
419
+ positionChart.max,
420
+ )(rowValue.value) + markerRadius},{positionChart.chartHeight /
421
+ 2})"
422
+ >
423
+ <circle
424
+ r={markerRadius}
425
+ cx="0"
426
+ cy="0"
427
+ fill={rowValue.color}
428
+ stroke="white"
429
+ opacity={rowValue.opacity}
430
+ ></circle>
431
+ </g>
432
+ {/if}
433
+ {/each}
434
+ {/each}
419
435
  </svg>
420
- </div>{/if}
421
- {/each}
436
+ </div>
437
+ {#if moreInfoTogglesArray[i]}
438
+ <div class="accordion" style="grid-column:1 / -1" aria-live="assertive">
439
+ <InsetText content={positionChart.moreInfo} renderStringAsHTML={true}
440
+ ></InsetText>
441
+ </div>
442
+ {/if}
443
+ {#if positionChart.divider}
444
+ <div
445
+ style="grid-column:1 / -1; border-bottom: solid 1px #d5dade;"
446
+ ></div>{/if}
447
+ {/each}
422
448
 
423
- {#if showAxis}
424
- {#if showIcon}
425
- <div class="empty"></div>
449
+ {#if showAxis}
450
+ {#if showIcon}
451
+ <div class="empty"></div>
452
+ {/if}
453
+ {#if showLabel}
454
+ <div class="empty"></div>
455
+ {/if}
456
+ <div class="axis" aria-hidden="true">
457
+ <PositionChartAxis {markerRadius} {barWidth} textSize={axisTextSize}
458
+ ></PositionChartAxis>
459
+ </div>
426
460
  {/if}
427
- {#if showLabel}
428
- <div class="empty"></div>
461
+ {#if activeMarkerId}
462
+ <ValueLabel
463
+ {activeMarkerId}
464
+ labelColor="lightgrey"
465
+ labelTextColor="black"
466
+ {labelText}
467
+ {tooltipContent}
468
+ {xFunction}
469
+ {yFunction}
470
+ {x}
471
+ {y}
472
+ {markerRect}
473
+ {tooltipSnippet}
474
+ ></ValueLabel>
429
475
  {/if}
430
- <div class="axis">
431
- <PositionChartAxis {markerRadius} {barWidth}></PositionChartAxis>
432
- </div>
433
- {/if}
434
- {#if activeMarkerId}
435
- <ValueLabel
436
- {activeMarkerId}
437
- labelColor="lightgrey"
438
- labelTextColor="black"
439
- {labelText}
440
- {tooltipContent}
441
- {xFunction}
442
- {yFunction}
443
- {x}
444
- {y}
445
- {markerRect}
446
- {tooltipSnippet}
447
- ></ValueLabel>
448
- {/if}
476
+ </div>
449
477
  </div>
450
478
 
451
479
  <style>
@@ -11,7 +11,7 @@ declare const PositionChart: import("svelte").Component<{
11
11
  showAxis?: boolean;
12
12
  chartWidth?: number;
13
13
  chartHeight?: number;
14
- colour?: string;
14
+ color?: string;
15
15
  nSegments?: number;
16
16
  startColor?: string;
17
17
  endColor?: string;
@@ -42,6 +42,8 @@ declare const PositionChart: import("svelte").Component<{
42
42
  onMouseEnterMarker?: Function;
43
43
  onMouseLeaveMarker?: Function;
44
44
  activeMarkerId?: any;
45
+ ariaLabel: any;
46
+ axisTextSize: any;
45
47
  }, {}, "chartWidth">;
46
48
  type $$ComponentProps = {
47
49
  value?: any;
@@ -51,7 +53,7 @@ type $$ComponentProps = {
51
53
  showAxis?: boolean;
52
54
  chartWidth?: number;
53
55
  chartHeight?: number;
54
- colour?: string;
56
+ color?: string;
55
57
  nSegments?: number;
56
58
  startColor?: string;
57
59
  endColor?: string;
@@ -82,4 +84,6 @@ type $$ComponentProps = {
82
84
  onMouseEnterMarker?: Function;
83
85
  onMouseLeaveMarker?: Function;
84
86
  activeMarkerId?: any;
87
+ ariaLabel: any;
88
+ axisTextSize: any;
85
89
  };
@@ -1,19 +1,27 @@
1
1
  <script>
2
- let { markerRadius = undefined, barWidth = undefined } = $props();
2
+ let {
3
+ markerRadius = undefined,
4
+ barWidth = undefined,
5
+ textSize = "s",
6
+ } = $props();
3
7
  </script>
4
8
 
5
- <div class="axis" style="--axis-padding:{markerRadius}px; width: {barWidth}">
9
+ <div
10
+ class="axis govuk-body-{textSize}"
11
+ style="--axis-padding:{markerRadius}px; width: {barWidth}"
12
+ >
6
13
  <div class="more-deprived">
7
14
  <svg
8
15
  xmlns="http://www.w3.org/2000/svg"
9
- width="11"
16
+ width="18"
10
17
  height="16"
11
- viewBox="0 0 11 16"
18
+ viewBox="0 0 11 20"
12
19
  fill="none"
13
20
  >
14
21
  <path
15
- d="M0.292893 7.29289C-0.0976315 7.68342 -0.0976314 8.31658 0.292893 8.70711L6.65685 15.0711C7.04738 15.4616 7.68054 15.4616 8.07107 15.0711C8.46159 14.6805 8.46159 14.0474 8.07107 13.6569L2.41421 8L8.07107 2.34315C8.46159 1.95262 8.46159 1.31946 8.07107 0.928932C7.68054 0.538408 7.04738 0.538408 6.65685 0.928933L0.292893 7.29289ZM11 8L11 7L1 7L1 8L1 9L11 9L11 8Z"
16
- fill="#555555"
22
+ transform="translate(20,21)rotate(180)"
23
+ d="M 19.7071 12.7071 C 20.0976 12.3166 20.0976 11.6834 19.7071 11.2929 L 13.3431 4.9289 C 12.9526 4.5384 12.3195 4.5384 11.9289 4.9289 C 11.5384 5.3195 11.5384 5.9526 11.9289 6.3431 L 17.5858 12 L 11.9289 17.6568 C 11.5384 18.0474 11.5384 18.6805 11.9289 19.0711 C 12.3195 19.4616 12.9526 19.4616 13.3431 19.0711 L 19.7071 12.7071 Z M 4 12 L 4 13 L 19 13 L 19 12 L 19 11 L 9 11 L 4 11 Z"
24
+ fill="black"
17
25
  ></path>
18
26
  </svg>
19
27
  <span class="axis-text">More deprived</span>
@@ -22,14 +30,15 @@
22
30
  <span class="axis-text">Less deprived</span>
23
31
  <svg
24
32
  xmlns="http://www.w3.org/2000/svg"
25
- width="12"
33
+ width="18"
26
34
  height="16"
27
- viewBox="0 0 12 16"
35
+ viewBox="0 0 11 20"
28
36
  fill="none"
29
37
  >
30
38
  <path
31
- d="M11.2071 8.70711C11.5976 8.31658 11.5976 7.68342 11.2071 7.2929L4.84315 0.928933C4.45262 0.538409 3.81946 0.538408 3.42893 0.928933C3.03841 1.31946 3.03841 1.95262 3.42893 2.34315L9.08579 8L3.42893 13.6569C3.03841 14.0474 3.03841 14.6805 3.42893 15.0711C3.81946 15.4616 4.45262 15.4616 4.84314 15.0711L11.2071 8.70711ZM0.5 8L0.5 9L10.5 9L10.5 8L10.5 7L0.5 7L0.5 8Z"
32
- fill="#555555"
39
+ transform="translate(-5,-3)"
40
+ d="M 19.7071 12.7071 C 20.0976 12.3166 20.0976 11.6834 19.7071 11.2929 L 13.3431 4.9289 C 12.9526 4.5384 12.3195 4.5384 11.9289 4.9289 C 11.5384 5.3195 11.5384 5.9526 11.9289 6.3431 L 17.5858 12 L 11.9289 17.6568 C 11.5384 18.0474 11.5384 18.6805 11.9289 19.0711 C 12.3195 19.4616 12.9526 19.4616 13.3431 19.0711 L 19.7071 12.7071 Z M 4 12 L 4 13 L 19 13 L 19 12 L 19 11 L 9 11 L 4 11 Z"
41
+ fill="black"
33
42
  ></path>
34
43
  </svg>
35
44
  </div>
@@ -47,7 +56,18 @@
47
56
  .more-deprived {
48
57
  display: flex;
49
58
  align-items: top;
50
- gap: 5px;
59
+
60
+ gap: 2px;
61
+ }
62
+
63
+ .more-deprived {
64
+ width: 45%;
65
+ }
66
+
67
+ .less-deprived {
68
+ text-align: end;
69
+ justify-content: end;
70
+ width: 43%;
51
71
  }
52
72
 
53
73
  /* Tell the parent to act as a container */
@@ -58,19 +78,7 @@
58
78
  .axis-text {
59
79
  font-family: "GDS Transport";
60
80
  line-height: 0.9;
61
- color: #444444;
62
- }
63
-
64
- /* Container query: hide the child if parent's width is less than 400px */
65
- @container (max-width: 18rem) {
66
- .less-deprived {
67
- display: none;
68
- }
69
- }
70
-
71
- @container (max-width: 25rem) {
72
- .average {
73
- display: none;
74
- }
81
+ color: black;
82
+ font-style: italic;
75
83
  }
76
84
  </style>
@@ -6,8 +6,10 @@ type PositionChartAxis = {
6
6
  declare const PositionChartAxis: import("svelte").Component<{
7
7
  markerRadius?: any;
8
8
  barWidth?: any;
9
+ textSize?: string;
9
10
  }, {}, "">;
10
11
  type $$ComponentProps = {
11
12
  markerRadius?: any;
12
13
  barWidth?: any;
14
+ textSize?: string;
13
15
  };
@@ -1,5 +1,4 @@
1
1
  <script lang="ts">
2
- import legacyDefaultCopyrightLogo from "./../../assets/images/govuk-crest.svg";
3
2
  // Define component props with default values
4
3
  // sections: array of footer navigation sections
5
4
  // inlineLinks: array of inline footer links
@@ -227,7 +226,7 @@
227
226
  ]}
228
227
  href={copyrightHref}
229
228
  style={copyrightLogoUrl || !rebrand
230
- ? `background-image: url(${copyrightLogoUrl ?? legacyDefaultCopyrightLogo}); display: block; width: 100%; padding-top: 112px; background-repeat: no-repeat; background-position: 50% 0; background-size: 125px 102px; text-align: center;`
229
+ ? `background-image: url(${copyrightLogoUrl ?? "/images/govuk-crest.svg"}); display: block; width: 100%; padding-top: 112px; background-repeat: no-repeat; background-position: 50% 0; background-size: 125px 102px; text-align: center;`
231
230
  : ""}
232
231
  >
233
232
  {copyrightText}