@onsvisual/svelte-components 0.1.58 → 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.
|
@@ -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";
|
|
@@ -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
|
+
};
|
|
@@ -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>
|