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
@@ -2,6 +2,7 @@
import * as proj from "@app/project";
import { formatCommit } from "@app/utils";
import type { Commit } from "@app/commit";
import Badge from "@app/Badge.svelte";
import Changeset from "@app/base/projects/SourceBrowser/Changeset.svelte";
import CommitAuthorship from "@app/base/projects/Commit/CommitAuthorship.svelte";
@@ -40,9 +41,6 @@
color: var(--color-foreground-80);
font-size: 0.875rem;
}
.badge {
margin: 0;
}
.authorship {
display: flex;
align-items: center;
@@ -71,7 +69,7 @@
<div class="authorship">
<CommitAuthorship {commit} />
{#if commit.context?.committer}
<span class="badge tertiary">Verified</span>
<Badge variant="tertiary">Verified</Badge>
{/if}
</div>
</header>
+5 -1
View File
@@ -94,7 +94,11 @@
<CommitAuthorship {commit} />
</div>
<div class="column-right">
<CommitVerifiedBadge {commit} />
{#if commit.context.committer}
<div class="desktop">
<CommitVerifiedBadge {commit} />
</div>
{/if}
<span class="secondary hash">{formatCommit(commit.header.sha1)}</span>
<div class="browse" title="View file" on:click|stopPropagation={() => browseCommit(commit.header.sha1)}>
<Icon name="browse" />
@@ -1,69 +1,67 @@
<script lang="ts">
import type { CommitMetadata } from "@app/commit";
import Popup from "@app/Popup.svelte";
import CommitAuthorship from "./CommitAuthorship.svelte";
import Badge from "@app/Badge.svelte";
export let commit: CommitMetadata;
let hover = false;
</script>
<style>
.badge {
margin: 0;
}
.badge:hover .verified-popup {
display: block;
}
.verified-popup {
display: none;
.wrapper {
position: absolute;
}
.verified-popup-header {
.popup {
width: 14rem;
left: -1rem;
z-index: 99;
color: var(--color-foreground);
font-size: 0.75rem;
}
.header {
display: flex;
padding: 1rem 0.75rem;
gap: 0.5rem;
}
.verified-popup-highlight {
.highlight {
color: var(--color-tertiary);
}
.verified-popup-committer {
.committer {
border-top: 1px dashed var(--color-foreground-subtle);
padding: 0.75rem;
}
.verified-popup-checkmark {
margin-right: 0.5rem;
}
.verified-popup-peer {
.peer {
padding-top: 0.5rem;
word-break: break-all;
}
@media (max-width: 720px) {
.badge {
display: none !important;
}
}
</style>
{#if commit.context.committer}
<span class="badge tertiary">
Verified
<div class="verified-popup">
<Popup>
<div class="verified-popup-header">
<div class="verified-popup-checkmark verified-popup-highlight">
✔
</div>
<div class="verified-popup-body">
This commit was <span class="verified-popup-highlight">signed</span>
with the committer's radicle key.</div>
<Badge
variant="tertiary"
on:mouseenter={() => {hover = true;}}
on:mouseleave={() => {hover = false;}}>
Verified
</Badge>
{#if hover}
<div class="wrapper">
<div class="popup">
<div class="header">
<div class="highlight">✔</div>
<div>
This commit was <span class="highlight">signed</span>
with the committer's radicle key.
</div>
<div class="verified-popup-committer">
<CommitAuthorship {commit} showAuthor={false} showTime={false} />
<div class="verified-popup-peer">
<span class="text-faded">{commit.context.committer?.peer.id}</span>
</div>
<div class="committer">
<CommitAuthorship {commit} showAuthor={false} showTime={false} />
{#if commit.context.committer}
<div class="peer">
<span class="text-faded">{commit.context.committer.peer.id}</span>
</div>
</div>
</Popup>
{/if}
</div>
</div>
</span>
</div>
{/if}
+2 -4
View File
@@ -5,6 +5,7 @@
import { formatSeedId } from "@app/utils";
import type { Peer } from "@app/project";
import Floating from "@app/Floating.svelte";
import Badge from "@app/Badge.svelte";
export let peer: string | null = null;
export let peers: Peer[];
@@ -52,9 +53,6 @@
.selector .peer.not-allowed {
cursor: not-allowed;
}
.selector .badge {
margin: 0;
}
.peer-id {
margin: 0 0.5rem;
}
@@ -80,7 +78,7 @@
{meta.person?.name ?? formatSeedId(meta.id)}
</span>
{#if meta.delegate}
<span class="badge primary">delegate</span>
<Badge variant="primary">delegate</Badge>
{/if}
<!-- If the delegate metadata is not found -->
{:else if peer}