File size: 2,765 Bytes
09bd8f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<script lang="ts">
	export let show_label = true;
    export let show_legend = true;
    export let show_legend_label = true;
    export let legend_label: string | undefined = "Highlights:";
    export let _color_map: Record<string, { primary: string; secondary: string }> = {};
	export let info: string | undefined = undefined;
</script>

<div class="title-container">
    <span
        class:sr-only={!show_label}
        class:hide={!show_label}
        class:has-info={info != null}
        data-testid="block-info"
    >
        <slot />
    </span>
    {#if Object.keys(_color_map).length !== 0}
        <span
            class="legend-separator"
            class:hide={!show_legend}
            class:has-info={info != null}
        >
        ·
        </span>
        <div
            class="category-legend"
            data-testid="highlighted-text:category-legend"
            class:hide={!show_legend}
        >
            <span class:hide={!show_legend_label} class:has-info={info != null}>
                {legend_label}
            </span>
            {#each Object.entries(_color_map) as [category, color], i}
                <!-- svelte-ignore a11y-no-static-element-interactions -->
                <div class="category-label" style={"background-color:" + color.secondary}>
                    {category}
                </div>
            {/each}
        </div>
    {/if}
</div>
{#if info}
    <div class="title-with-highlights-info">
        {info}
    </div>
{/if}

<style>
	span.has-info {
		margin-bottom: var(--spacing-xs);
	}
	span:not(.has-info) {
		margin-bottom: var(--spacing-lg);
	}
	span {
		display: inline-block;
		position: relative;
		z-index: var(--layer-4);
		border: solid var(--block-title-border-width)
			var(--block-title-border-color);
		border-radius: var(--block-title-radius);
		background: var(--block-title-background-fill);
		padding: var(--block-title-padding);
		color: var(--block-title-text-color);
		font-weight: var(--block-title-text-weight);
		font-size: var(--block-title-text-size);
		line-height: var(--line-sm);
	}

	.hide {
		margin: 0;
		height: 0;
	}

    .category-legend {
		display: flex;
		flex-wrap: wrap;
		gap: var(--spacing-sm);
		color: black;
	}

	.category-label {
		border-radius: var(--radius-xs);
		padding-right: var(--size-2);
		padding-left: var(--size-2);
		font-weight: var(--weight-semibold);
	}

	.title-container {
        display: flex;
    }

    .legend-separator {
        margin: 0 var(--spacing-md) 0 var(--spacing-md);
    }

    .title-with-highlights-info {
		margin-bottom: var(--spacing-xs);
		color: var(--block-info-text-color);
		font-weight: var(--block-info-text-weight);
		font-size: var(--block-info-text-size);
		line-height: var(--line-sm);
    }
</style>