@onsvisual/svelte-components 0.1.57 → 0.1.59
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.
- package/dist/@types/js/utils.d.ts +1 -0
- package/dist/@types/layout/ErrorPage/ErrorPage.svelte.d.ts +2 -0
- package/dist/@types/layout/Titleblock/Titleblock.svelte.d.ts +2 -0
- package/dist/decorators/Em/Em.svelte +2 -11
- package/dist/js/utils.js +12 -0
- package/dist/layout/ErrorPage/ErrorPage.svelte +12 -8
- package/dist/layout/Titleblock/Titleblock.svelte +13 -3
- package/package.json +1 -1
|
@@ -10,3 +10,4 @@ export function format(val: any, dp?: any): any;
|
|
|
10
10
|
export function ascending(a: any, b: any): number;
|
|
11
11
|
export function descending(a: any, b: any): number;
|
|
12
12
|
export function sleep(ms?: number): Promise<any>;
|
|
13
|
+
export function contrastColor(color: any): "black" | "white";
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
export default class ErrorPage extends SvelteComponentTyped<{
|
|
5
5
|
page?: any;
|
|
6
6
|
status?: number;
|
|
7
|
+
message?: string;
|
|
7
8
|
}, {
|
|
8
9
|
[evt: string]: CustomEvent<any>;
|
|
9
10
|
}, {}> {
|
|
@@ -16,6 +17,7 @@ declare const __propDef: {
|
|
|
16
17
|
props: {
|
|
17
18
|
page?: any;
|
|
18
19
|
status?: number;
|
|
20
|
+
message?: string;
|
|
19
21
|
};
|
|
20
22
|
events: {
|
|
21
23
|
[evt: string]: CustomEvent<any>;
|
|
@@ -12,6 +12,7 @@ export default class Titleblock extends SvelteComponentTyped<{
|
|
|
12
12
|
censusLogo?: boolean;
|
|
13
13
|
titleBadge?: string;
|
|
14
14
|
titleBadgeAriaLabel?: string;
|
|
15
|
+
titleBadgeColor?: string;
|
|
15
16
|
}, {
|
|
16
17
|
[evt: string]: CustomEvent<any>;
|
|
17
18
|
}, {
|
|
@@ -37,6 +38,7 @@ declare const __propDef: {
|
|
|
37
38
|
censusLogo?: boolean;
|
|
38
39
|
titleBadge?: string;
|
|
39
40
|
titleBadgeAriaLabel?: string;
|
|
41
|
+
titleBadgeColor?: string;
|
|
40
42
|
};
|
|
41
43
|
events: {
|
|
42
44
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import
|
|
2
|
+
import { contrastColor } from "../../js/utils";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Any valid CSS colour
|
|
@@ -12,16 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export let nowrap = true;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
const rgb = parse(color).rgb;
|
|
17
|
-
if (rgb) {
|
|
18
|
-
const brightness = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
|
|
19
|
-
return brightness > 125 ? "black" : "white";
|
|
20
|
-
}
|
|
21
|
-
return "black";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
$: text = textColor(color);
|
|
15
|
+
$: text = contrastColor(color);
|
|
25
16
|
</script>
|
|
26
17
|
|
|
27
18
|
<mark
|
package/dist/js/utils.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import parse from "parse-color";
|
|
2
|
+
|
|
1
3
|
const randomString = () => {
|
|
2
4
|
return Math.random().toString(16).slice(2, 8);
|
|
3
5
|
};
|
|
@@ -51,3 +53,13 @@ export const descending = (a, b) =>
|
|
|
51
53
|
a == null || b == null ? NaN : b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
|
52
54
|
|
|
53
55
|
export const sleep = (ms = 1000) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
56
|
+
|
|
57
|
+
export const contrastColor = (color) => {
|
|
58
|
+
if (!color || typeof color !== "string") return "black";
|
|
59
|
+
const rgb = parse(color).rgb;
|
|
60
|
+
if (rgb) {
|
|
61
|
+
const brightness = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
|
|
62
|
+
return brightness > 125 ? "black" : "white";
|
|
63
|
+
}
|
|
64
|
+
return "black";
|
|
65
|
+
};
|
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
* (Optional) Explicitly pass a page status number, eg. 404 or 500.
|
|
9
9
|
* @type {number}
|
|
10
10
|
*/
|
|
11
|
-
export let status = $page ? $page
|
|
11
|
+
export let status = $page ? $page?.status : null;
|
|
12
|
+
/**
|
|
13
|
+
* (Optional) Explicitly pass a page status message.
|
|
14
|
+
* @type {string}
|
|
15
|
+
*/
|
|
16
|
+
export let message = $page ? $page?.error?.message : "";
|
|
12
17
|
</script>
|
|
13
18
|
|
|
14
19
|
<div class="ons-page__container ons-container">
|
|
@@ -16,20 +21,19 @@
|
|
|
16
21
|
<div class="ons-grid__col ons-col-12@m">
|
|
17
22
|
<main id="main-content" class="ons-page__main">
|
|
18
23
|
{#if status === 404}
|
|
19
|
-
<h1>Page not found</h1>
|
|
24
|
+
<h1>{message || "Page not found"}</h1>
|
|
20
25
|
<p>If you entered a web address, check it is correct.</p>
|
|
21
26
|
<p>If you pasted the web address, check you copied the whole address.</p>
|
|
22
27
|
<p>
|
|
23
|
-
If the web address is correct or you selected a link or button, <a
|
|
24
|
-
>contact us</a
|
|
28
|
+
If the web address is correct or you selected a link or button, <a
|
|
29
|
+
href="https://www.ons.gov.uk/feedback">contact us</a
|
|
25
30
|
> for more help.
|
|
26
31
|
</p>
|
|
27
32
|
{:else}
|
|
28
|
-
<h1>Sorry, there is a problem with the service</h1>
|
|
29
|
-
<p>Try again later.</p>
|
|
33
|
+
<h1>{message || "Sorry, there is a problem with the service"}</h1>
|
|
30
34
|
<p>
|
|
31
|
-
If you continue to experience problems with this service, please <a
|
|
32
|
-
>contact us</a
|
|
35
|
+
If you continue to experience problems with this service, please <a
|
|
36
|
+
href="https://www.ons.gov.uk/feedback">contact us</a
|
|
33
37
|
>.
|
|
34
38
|
</p>
|
|
35
39
|
{/if}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { contrastColor } from "../../js/utils";
|
|
2
3
|
import Container from "../../wrappers/Container/Container.svelte";
|
|
3
4
|
import Meta from "./Meta.svelte";
|
|
4
5
|
|
|
@@ -52,6 +53,13 @@
|
|
|
52
53
|
* @type {string}
|
|
53
54
|
*/
|
|
54
55
|
export let titleBadgeAriaLabel = null;
|
|
56
|
+
/**
|
|
57
|
+
* Set a colour for the title badge
|
|
58
|
+
* @type {string}
|
|
59
|
+
*/
|
|
60
|
+
export let titleBadgeColor = "#003C57";
|
|
61
|
+
|
|
62
|
+
$: titleBadgeTextColor = contrastColor(titleBadgeColor);
|
|
55
63
|
</script>
|
|
56
64
|
|
|
57
65
|
<Container
|
|
@@ -68,8 +76,11 @@
|
|
|
68
76
|
<h1 class="ons-u-fs-xxxl ons-u-mt-s ons-u-mb-m ons-u-pb-no ons-u-pt-no">
|
|
69
77
|
{#if titleBadge}
|
|
70
78
|
<span style="margin-right: 6px">{@html title}</span>
|
|
71
|
-
<span
|
|
72
|
-
|
|
79
|
+
<span
|
|
80
|
+
class="title-badge"
|
|
81
|
+
aria-label="{titleBadgeAriaLabel ?? titleBadge}"
|
|
82
|
+
style:background="{titleBadgeColor}"
|
|
83
|
+
style:color="{titleBadgeTextColor}">{titleBadge}</span
|
|
73
84
|
>
|
|
74
85
|
{:else}
|
|
75
86
|
{@html title}
|
|
@@ -131,7 +142,6 @@
|
|
|
131
142
|
font-size: 40%;
|
|
132
143
|
font-weight: bold;
|
|
133
144
|
color: white;
|
|
134
|
-
background-color: #003c57;
|
|
135
145
|
padding: 2px 8px 4px 8px;
|
|
136
146
|
border-radius: 4px;
|
|
137
147
|
}</style>
|