Extract global .badge class into a component

By encapsulating the global `.badge` class into a component we make reasoning
about how badges look a bit easier, because now there's a single place
where it is defined. Otherwise it is not guaranteed that the class is
going to be applied to the correct html tag. This also makes combining
global CSS classes that don't make sense from a design perspective
impossible.

Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Rūdolfs Ošiņš
2022-08-30 12:12:19 +02:00
committed by Alexis Sellier
parent ffabc3091c
commit 93b7b6b2a0
12 changed files with 129 additions and 118 deletions
+2 -4
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
import Badge from "@app/Badge.svelte";
export let items: { key: string; title: string; value: string; badge: string | null }[];
export let selected: string | null = null;
@@ -19,9 +20,6 @@
.dropdown-item:hover, .selected {
background-color: var(--color-foreground-background-lighter);
}
.dropdown .badge {
margin: 0;
}
@media (max-width: 720px) {
.dropdown {
@@ -36,7 +34,7 @@
{#if key && value}
<div class="dropdown-item" class:selected={value === selected} on:click={() => onSelect(value)} {title}>{@html key}
{#if badge}
<span class="badge primary">{badge}</span>
<Badge variant="primary">{badge}</Badge>
{/if}
</div>
{/if}