Skip to content

Commit 8476b98

Browse files
committed
feat: Add tooltips to buttons in Announcement management, minor UI improvements and fixes
1 parent 9221d8c commit 8476b98

File tree

8 files changed

+61
-35
lines changed

8 files changed

+61
-35
lines changed

src/lib/components/Button.svelte

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts">
2+
import ToolTip from './ToolTip.svelte';
3+
24
export let type: 'filled' | 'tonal' | 'text' | 'outlined' | 'icon' = 'filled';
35
export let variant: 'default' | 'danger' | 'onDangerBackground' = 'default';
46
export let functionType: typeof HTMLButtonElement.prototype.type = 'button';
@@ -9,28 +11,31 @@
911
export let target: string = '';
1012
export let label: string = '';
1113
export let disabled: boolean = false;
14+
export let toolTipText: string | undefined = undefined;
1215
1316
$: type = $$slots.default ? type : 'icon';
1417
</script>
1518

16-
{#if href}
17-
<a {href} {target} aria-label={label} class={`${type} ${variant}`} class:disabled>
18-
<svelte:component this={icon} size={iconSize} color={iconColor} />
19-
<slot />
20-
</a>
21-
{:else}
22-
<button
23-
on:click
24-
class={`${type} ${variant}`}
25-
class:disabled
26-
aria-label={label}
27-
type={functionType}
28-
{disabled}
29-
>
30-
<svelte:component this={icon} size={iconSize} color={iconColor} />
31-
<slot />
32-
</button>
33-
{/if}
19+
<ToolTip content={toolTipText} html={false}>
20+
{#if href}
21+
<a {href} {target} aria-label={label} class={`${type} ${variant}`} class:disabled>
22+
<svelte:component this={icon} size={iconSize} color={iconColor} />
23+
<slot />
24+
</a>
25+
{:else}
26+
<button
27+
on:click
28+
class={`${type} ${variant}`}
29+
class:disabled
30+
aria-label={label}
31+
type={functionType}
32+
{disabled}
33+
>
34+
<svelte:component this={icon} size={iconSize} color={iconColor} />
35+
<slot />
36+
</button>
37+
{/if}
38+
</ToolTip>
3439

3540
<style lang="scss">
3641
a,

src/lib/components/ToolTip.svelte

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22
import { tooltip } from 'svooltip';
33
import '../styles/ToolTip.scss';
44
5-
export let content: string;
5+
export let content: string | undefined;
66
export let html: boolean = false;
77
</script>
88

9-
<div
10-
use:tooltip={{
11-
content: content,
12-
html: html
13-
}}
14-
>
9+
{#if content}
10+
<div
11+
use:tooltip={{
12+
content: content,
13+
html: html
14+
}}
15+
>
16+
<slot />
17+
</div>
18+
{:else}
1519
<slot />
16-
</div>
20+
{/if}
1721

1822
<style>
1923
:root {

src/routes/announcements/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
</div>
8888
<main class="wrapper" in:fly={{ y: 10, easing: quintOut, duration: 750 }}>
8989
<Query query={tagsQuery} let:data>
90-
<TagsHost tags={data.tags} />
90+
<TagsHost tags={data.tags} expandable={true} />
9191
</Query>
9292

9393
<Query {query} let:data>
@@ -110,7 +110,7 @@
110110
on:keypress={() => (expanded = !expanded)}
111111
tabindex="0"
112112
>
113-
<h4>Archived announcements</h4>
113+
<h4>Archive</h4>
114114

115115
<div id="arrow" style:transform={expanded ? 'rotate(-180deg)' : 'rotate(0deg)'}>
116116
<ChevronDown size="24px" color="var(--surface-six)" />

src/routes/announcements/TagChip.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
2727
gap: 8px;
2828
height: 32px;
29-
padding: 0 16px;
29+
padding: 0 12px;
3030
3131
border-radius: 8px;
3232
border: none;

src/routes/announcements/TagsHost.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
div {
6868
display: flex;
6969
align-items: center;
70+
flex-wrap: wrap;
71+
white-space: nowrap;
7072
gap: 4px;
7173
7274
li {

src/routes/announcements/[slug]/+page.svelte

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts">
2-
import Footer from '$layout/Footer/FooterHost.svelte';
32
import { fly } from 'svelte/transition';
43
import { quintOut } from 'svelte/easing';
54
import { createQuery } from '@tanstack/svelte-query';
@@ -46,6 +45,4 @@
4645
{:else}
4746
<Announcement {isCreating} {announcement} {announcementIdNumber} />
4847
{/if}
49-
</main>
50-
51-
<Footer />
48+
</main>

src/routes/announcements/[slug]/AdminButtons.svelte

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,22 @@
109109
<div>
110110
{#if isEditing || isCreating}
111111
<Button
112+
toolTipText={isPreviewing ? 'Hide preview' : 'Show preview'}
112113
icon={isPreviewing ? Hide : Show}
113114
iconColor="var(--secondary)"
114115
on:click={() => (isPreviewing = !isPreviewing)}
115116
/>
117+
116118
<Button
119+
toolTipText={archivedAtInput ? 'Disable archive field' : 'Enable archive field'}
117120
icon={archivedAtInput ? Unarchive : Archive}
118121
iconColor="var(--secondary)"
119122
on:click={toggleArchived}
120123
/>
124+
121125
{#if isEditing}
122126
<Button
127+
toolTipText="Cancel editing"
123128
icon={Close}
124129
iconColor="var(--secondary)"
125130
on:click={() => {
@@ -128,18 +133,27 @@
128133
}}
129134
/>
130135
{/if}
136+
131137
<Button
138+
toolTipText={isEditing ? 'Save changes' : 'Create announcement'}
132139
icon={Check}
133140
iconColor="var(--secondary)"
134141
on:click={isEditing ? save : createAnnouncement}
135142
/>
136143
{:else}
137144
<Button
145+
toolTipText="Delete announcement"
138146
icon={Delete}
139147
iconColor="var(--secondary)"
140148
on:click={() => (showDeleteConfirm = !showDeleteConfirm)}
141149
/>
142-
<Button icon={Edit} iconColor="var(--secondary)" on:click={() => (isEditing = !isEditing)} />
150+
151+
<Button
152+
toolTipText="Edit announcement"
153+
icon={Edit}
154+
iconColor="var(--secondary)"
155+
on:click={() => (isEditing = !isEditing)}
156+
/>
143157
{/if}
144158
</div>
145159

src/routes/announcements/[slug]/Date.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
}
1919
2020
$: displayCreatedAt = isPreviewing ? createdAtInput : createdAt;
21-
$: displayArchivedAt = isPreviewing ? archivedAtInput : archivedAt;
21+
22+
$: displayArchivedAt = (() => {
23+
const date = isPreviewing ? archivedAtInput : archivedAt;
24+
return date && moment(date).isBefore() ? date : null;
25+
})();
2226
</script>
2327

2428
{#if (isEditing || isCreating) && !isPreviewing}

0 commit comments

Comments
 (0)