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

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}
@@ -79,6 +79,7 @@
79
79
  activeMarkerId = null;
80
80
  },
81
81
  activeMarkerId = undefined,
82
+ ariaLabel,
82
83
  } = $props();
83
84
 
84
85
  // base defaults that apply to every row
@@ -247,205 +248,237 @@
247
248
  );
248
249
  </script>
249
250
 
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"
251
+ <div role="img" aria-label={ariaLabel}>
252
+ {#if annotations.length}
253
+ {#each annotations as d (d.value)}
254
+ <div bind:clientWidth={topWidth} aria-hidden={true}>
255
+ <svg width={topWidth} height="60">
256
+ <g>
257
+ <text
258
+ font-family="GDS Transport"
259
+ id="label"
260
+ x={d.value}
261
+ y="20"
262
+ fill={d.colour}
263
+ font-size="18"
264
+ opacity={typeof activeMarkerId !== "undefined" && activeMarkerId
265
+ ? 0.2
266
+ : 1}
267
+ >
268
+ {d.annotation}
269
+ </text>
270
+ </g>
271
+ <defs>
272
+ <marker
273
+ id="arrow-down"
274
+ markerWidth="10"
275
+ markerHeight="10"
276
+ refX="3"
277
+ refY="3"
278
+ orient="auto"
279
+ markerUnits="strokeWidth"
280
+ opacity={typeof activeMarkerId !== "undefined" && activeMarkerId
281
+ ? 0.2
282
+ : 1}
283
+ >
284
+ <path d="M 0 0 L 6 3 L 0 6 z" fill={d.colour}></path>
285
+ </marker>
286
+ </defs>
287
+ <path
288
+ d="M 4 25 v 10 h {xFunction(min, max)(d.value) +
289
+ markerRadius -
290
+ 4 +
291
+ (topWidth - chartWidth)} v 15"
292
+ fill="none"
293
+ stroke={d.colour}
294
+ stroke-width="1.5"
295
+ marker-end="url(#arrow-down)"
262
296
  opacity={typeof activeMarkerId !== "undefined" && activeMarkerId
263
297
  ? 0.2
264
298
  : 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"
278
- opacity={typeof activeMarkerId !== "undefined" && activeMarkerId
279
- ? 0.2
280
- : 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}
299
+ ></path>
300
+ </svg>
301
+ </div>
302
+ {/each}
303
+ {/if}
302
304
 
303
- <div
304
- class="grid-container"
305
- bind:this={container}
306
- style="
305
+ <div
306
+ class="grid-container"
307
+ bind:this={container}
308
+ style="
307
309
  position: relative;
308
310
  grid-template-columns: {gridTemplateColumns};
309
311
  grid-template-rows: {gridTemplateRows};
310
312
  "
311
- >
312
- {#each allDataNormalized as positionChart, i}
313
- {#if showLabel}
314
- <p
315
- class="govuk-body-s"
316
- style=" text-align: right;
313
+ >
314
+ {#each allDataNormalized as positionChart, i}
315
+ {#if showLabel}
316
+ <p
317
+ aria-hidden={true}
318
+ class="govuk-body-s"
319
+ style=" text-align: right;
317
320
  margin: 0;
318
321
  line-height: 1.05;"
319
- >
320
- {positionChart.label}
321
- </p>
322
- {/if}
323
- {#if showIcon}
324
- <div class="button-container">
322
+ >
323
+ {positionChart.label}
324
+ </p>
325
+ {/if}
326
+ {#if showIcon}
325
327
  <Button
326
328
  textContent="i"
327
329
  buttonType="moreInfo"
328
330
  noPadding={true}
329
331
  onClickFunction={() => updateMoreInfoTogglesArray(i)}
332
+ ariaExpanded={moreInfoTogglesArray[i]}
330
333
  ></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"
334
+ {/if}
335
+ <div
336
+ class="chart"
337
+ style="height: {positionChart.chartHeight}px"
338
+ bind:clientWidth={chartWidth}
339
+ >
340
+ <svg
341
+ width={chartWidth}
342
+ height={positionChart.chartHeight}
343
+ aria-hidden={true}
344
+ >
345
+ <rect
346
+ x={markerRadius}
347
+ y={(positionChart.chartHeight - barHeight) / 2}
348
+ width={barWidth}
349
+ height={barHeight}
350
+ fill="none"
416
351
  stroke="grey"
417
- stroke-width="0.5"
418
- ></line>
352
+ stroke-width="1"
353
+ ></rect>
354
+ {#each range as number}
355
+ <g
356
+ transform="translate({markerRadius +
357
+ (barWidth * number) / nSegments},{(positionChart.chartHeight -
358
+ barHeight) /
359
+ 2})"
360
+ ><rect
361
+ width={barWidth / nSegments}
362
+ height={barHeight}
363
+ fill={colorScale && colorScale.length > 0
364
+ ? colorScale[number]
365
+ : interpolateColors(
366
+ startColor,
367
+ endColor,
368
+ nSegments,
369
+ midColor,
370
+ )[number]}
371
+ ></rect></g
372
+ >{/each}
373
+
374
+ {#each Object.entries(positionChart.rowData) as [tier, points]}
375
+ {#each points as rowValue, i}
376
+ {#if !isNaN(Number(rowValue.value))}
377
+ {@const markerId = "marker-" + rowValue.value}
378
+ <g
379
+ data-id={markerId}
380
+ onclick={interactiveMarkers
381
+ ? (event) => onClickMarker(event, rowValue, markerId)
382
+ : null}
383
+ onmouseenter={interactiveMarkers
384
+ ? (event) =>
385
+ onMouseEnterMarker(
386
+ event,
387
+ rowValue,
388
+ markerId,
389
+ event.currentTarget.getBoundingClientRect(),
390
+ )
391
+ : null}
392
+ onmouseleave={interactiveMarkers
393
+ ? (event) => onMouseLeaveMarker(event, rowValue, markerId)
394
+ : null}
395
+ onfocus={interactiveMarkers
396
+ ? (event) =>
397
+ onMouseEnterMarker(
398
+ event,
399
+ rowValue,
400
+ markerId,
401
+ event.currentTarget.getBoundingClientRect(),
402
+ )
403
+ : null}
404
+ onblur={interactiveMarkers
405
+ ? (event) => onMouseLeaveMarker(event, rowValue, markerId)
406
+ : null}
407
+ role="button"
408
+ aria-label={tooltipContent}
409
+ tabindex="0"
410
+ onkeydown={interactiveMarkers
411
+ ? (event) => onClickMarker(event, rowValue, markerId)
412
+ : null}
413
+ pointer-events={interactiveMarkers ? null : "none"}
414
+ transform="translate({xFunction(
415
+ positionChart.min,
416
+ positionChart.max,
417
+ )(rowValue.value) + markerRadius},{positionChart.chartHeight /
418
+ 2})"
419
+ >
420
+ <circle
421
+ r={markerRadius}
422
+ cx="0"
423
+ cy="0"
424
+ fill={rowValue.colour}
425
+ stroke="white"
426
+ opacity={rowValue.opacity}
427
+ ></circle>
428
+ </g>
429
+ {/if}
430
+ {/each}
431
+ {/each}
419
432
  </svg>
420
- </div>{/if}
421
- {/each}
433
+ </div>
434
+ {#if moreInfoTogglesArray[i]}
435
+ <div class="accordion" style="grid-column:1 / -1" aria-live="assertive">
436
+ <InsetText content={positionChart.moreInfo} renderStringAsHTML={true}
437
+ ></InsetText>
438
+ </div>
439
+ {/if}
440
+ {#if positionChart.divider}
441
+ <div style="grid-column:1 / -1">
442
+ <svg width="100%" height="5">
443
+ <line
444
+ x1="0"
445
+ y1="2.5"
446
+ x2="100%"
447
+ y2="2.55"
448
+ stroke="grey"
449
+ stroke-width="0.5"
450
+ ></line>
451
+ </svg>
452
+ </div>{/if}
453
+ {/each}
422
454
 
423
- {#if showAxis}
424
- {#if showIcon}
425
- <div class="empty"></div>
455
+ {#if showAxis}
456
+ {#if showIcon}
457
+ <div class="empty"></div>
458
+ {/if}
459
+ {#if showLabel}
460
+ <div class="empty"></div>
461
+ {/if}
462
+ <div class="axis" aria-hidden="true">
463
+ <PositionChartAxis {markerRadius} {barWidth}></PositionChartAxis>
464
+ </div>
426
465
  {/if}
427
- {#if showLabel}
428
- <div class="empty"></div>
466
+ {#if activeMarkerId}
467
+ <ValueLabel
468
+ {activeMarkerId}
469
+ labelColor="lightgrey"
470
+ labelTextColor="black"
471
+ {labelText}
472
+ {tooltipContent}
473
+ {xFunction}
474
+ {yFunction}
475
+ {x}
476
+ {y}
477
+ {markerRect}
478
+ {tooltipSnippet}
479
+ ></ValueLabel>
429
480
  {/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}
481
+ </div>
449
482
  </div>
450
483
 
451
484
  <style>
@@ -42,6 +42,7 @@ declare const PositionChart: import("svelte").Component<{
42
42
  onMouseEnterMarker?: Function;
43
43
  onMouseLeaveMarker?: Function;
44
44
  activeMarkerId?: any;
45
+ ariaLabel: any;
45
46
  }, {}, "chartWidth">;
46
47
  type $$ComponentProps = {
47
48
  value?: any;
@@ -82,4 +83,5 @@ type $$ComponentProps = {
82
83
  onMouseEnterMarker?: Function;
83
84
  onMouseLeaveMarker?: Function;
84
85
  activeMarkerId?: any;
86
+ ariaLabel: any;
85
87
  };
@@ -7,6 +7,7 @@
7
7
  componentNameProp = undefined,
8
8
  onClickFunction = undefined,
9
9
  noPadding = false,
10
+ ariaExpanded = false,
10
11
  } = $props();
11
12
 
12
13
  let buttonClass = $derived(
@@ -25,7 +26,12 @@
25
26
  {#if noPadding}
26
27
  {#if buttonType === "moreInfo"}
27
28
  <div>
28
- <button class="more-info-button" onclick={onClickFunction}>
29
+ <button
30
+ aria-label={textContent}
31
+ aria-expanded={ariaExpanded}
32
+ class="more-info-button"
33
+ onclick={onClickFunction}
34
+ >
29
35
  <Icon kind="info" />
30
36
  </button>
31
37
  </div>
@@ -99,7 +105,18 @@
99
105
  {/if}
100
106
  {:else}
101
107
  <div class="p-4">
102
- {#if buttonType === "start"}
108
+ {#if buttonType === "moreInfo"}
109
+ <div>
110
+ <button
111
+ aria-label={textContent}
112
+ aria-expanded={ariaExpanded}
113
+ class="more-info-button"
114
+ onclick={onClickFunction}
115
+ >
116
+ <Icon kind="info" />
117
+ </button>
118
+ </div>
119
+ {:else if buttonType === "start"}
103
120
  <a
104
121
  href={"#"}
105
122
  role="button"
@@ -9,6 +9,7 @@ declare const Button: import("svelte").Component<{
9
9
  componentNameProp?: any;
10
10
  onClickFunction?: any;
11
11
  noPadding?: boolean;
12
+ ariaExpanded?: boolean;
12
13
  }, {}, "">;
13
14
  type $$ComponentProps = {
14
15
  textContent?: any;
@@ -16,4 +17,5 @@ type $$ComponentProps = {
16
17
  componentNameProp?: any;
17
18
  onClickFunction?: any;
18
19
  noPadding?: boolean;
20
+ ariaExpanded?: boolean;
19
21
  };