Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 097a1cc

Browse files
Notifications (#52)
* Notifications * fix docs
1 parent 625511d commit 097a1cc

13 files changed

+207
-4
lines changed

docs/.vitepress/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ export default {
4242
{ text: 'Promotion', link: '/components/promotion' },
4343
{ text: 'Markdown', link: '/components/markdown' },
4444
{ text: 'Copy Code', link: '/components/copy-code' },
45+
{ text: 'Notifications', link: '/components/notifications' },
4546
],
4647
},
4748
],
4849
footer: {
4950
message:
50-
'Released under the <a href="https://github.com/modrinth/omoprhia/blob/main/LICENSE">GPLv3 License</a>.',
51+
'Released under the <a href="https://github.com/modrinth/omoprhia/blob/main/LICENSE">AGPLv3 License</a>.',
5152
copyright: 'Copyright © 2023-present <a href="https://modrinth.com">Rinth, Inc.</a>',
5253
},
5354
},

docs/components/notifications.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Notifications
2+
3+
<script setup>
4+
import { ref } from "vue";
5+
6+
const notifsContainer = ref(null);
7+
8+
function addNotification(type) {
9+
console.log(notifsContainer);
10+
notifsContainer.value.addNotification({
11+
title: 'Test Notification',
12+
text: 'This is a test! Random number: ' + Math.random(),
13+
type,
14+
});
15+
}
16+
</script>
17+
<DemoContainer>
18+
<Notifications ref="notifsContainer" />
19+
<Button color="primary" @click="addNotification('success')">Success</Button>
20+
<Button color="highlight" @click="addNotification('warn')">Warning</Button>
21+
<Button color="danger" @click="addNotification('error')">Error</Button>
22+
<Button @click="addNotification('info')">Info</Button>
23+
</DemoContainer>
24+
25+
```vue
26+
<script setup>
27+
import { ref } from "vue";
28+
29+
const notifsContainer = ref(null);
30+
31+
function addNotification(type) {
32+
console.log(notifsContainer);
33+
notifsContainer.value.addNotification({
34+
title: 'Test Notification',
35+
text: 'This is a test! Random number: ' + Math.random(),
36+
type,
37+
});
38+
}
39+
</script>
40+
41+
<Notifications ref="notifsContainer" />
42+
<Button color="primary" @click="addNotification('success')">Success</Button>
43+
<Button color="highlight" @click="addNotification('warn')">Warning</Button>
44+
<Button color="danger" @click="addNotification('error')">Error</Button>
45+
<Button @click="addNotification('info')">Info</Button>
46+
```

lib/assets/icons/exit.svg

-1
This file was deleted.

lib/assets/icons/folder-open.svg

+4
Loading

lib/assets/icons/folder-search.svg

+6
Loading

lib/assets/icons/hammer.svg

+1
Loading

lib/assets/icons/log-in.svg

+1
Loading

lib/assets/icons/stop-circle.svg

+1
Loading

lib/assets/icons/terminal-square.svg

+1
Loading

lib/assets/icons/x-circle.svg

+6
Loading

lib/components/base/Notifications.vue

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<template>
2+
<div class="vue-notification-group">
3+
<transition-group name="notifs">
4+
<div
5+
v-for="(item, index) in notifications"
6+
:key="item.id"
7+
class="vue-notification-wrapper"
8+
@click="notifications.splice(index, 1)"
9+
@mouseenter="stopTimer(item)"
10+
@mouseleave="setNotificationTimer(item)"
11+
>
12+
<div class="vue-notification-template vue-notification" :class="{ [item.type]: true }">
13+
<div class="notification-title" v-html="item.title"></div>
14+
<div class="notification-content" v-html="item.text"></div>
15+
</div>
16+
</div>
17+
</transition-group>
18+
</div>
19+
</template>
20+
<script setup>
21+
import { ref } from 'vue'
22+
23+
const notifications = ref([])
24+
25+
defineExpose({
26+
addNotification: (notification) => {
27+
const existingNotif = notifications.value.find(
28+
(x) =>
29+
x.text === notification.text &&
30+
x.title === notification.title &&
31+
x.type === notification.type
32+
)
33+
if (existingNotif) {
34+
setNotificationTimer(existingNotif)
35+
36+
return
37+
}
38+
39+
notification.id = new Date()
40+
41+
setNotificationTimer(notification)
42+
notifications.value.push(notification)
43+
},
44+
})
45+
46+
function setNotificationTimer(notification) {
47+
if (!notification) return
48+
49+
if (notification.timer) {
50+
clearTimeout(notification.timer)
51+
}
52+
53+
notification.timer = setTimeout(() => {
54+
notifications.value.splice(notifications.value.indexOf(notification), 1)
55+
}, 30000)
56+
}
57+
58+
function stopTimer(notif) {
59+
clearTimeout(notif.timer)
60+
}
61+
</script>
62+
<style lang="scss" scoped>
63+
.vue-notification {
64+
background: var(--color-blue) !important;
65+
color: var(--color-accent-contrast) !important;
66+
67+
box-sizing: border-box;
68+
text-align: left;
69+
font-size: 12px;
70+
padding: 10px;
71+
margin: 0 5px 5px;
72+
73+
&.success {
74+
background: var(--color-green) !important;
75+
}
76+
77+
&.warn {
78+
background: var(--color-orange) !important;
79+
}
80+
81+
&.error {
82+
background: var(--color-red) !important;
83+
}
84+
}
85+
86+
.vue-notification-group {
87+
position: fixed;
88+
right: 25px;
89+
bottom: 25px;
90+
z-index: 99999999;
91+
width: 300px;
92+
93+
.vue-notification-wrapper {
94+
width: 100%;
95+
overflow: hidden;
96+
margin-bottom: 10px;
97+
98+
.vue-notification-template {
99+
border-radius: var(--radius-md);
100+
margin: 0;
101+
102+
.notification-title {
103+
font-size: var(--font-size-lg);
104+
margin-right: auto;
105+
font-weight: 600;
106+
}
107+
108+
.notification-content {
109+
margin-right: auto;
110+
font-size: var(--font-size-md);
111+
}
112+
}
113+
114+
&:last-child {
115+
margin: 0;
116+
}
117+
}
118+
}
119+
120+
.notifs-enter-active,
121+
.notifs-leave-active,
122+
.notifs-move {
123+
transition: all 0.5s;
124+
}
125+
.notifs-enter-from,
126+
.notifs-leave-to {
127+
opacity: 0;
128+
}
129+
</style>

lib/components/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export { default as FileInput } from './base/FileInput.vue'
1919
export { default as DropArea } from './base/DropArea.vue'
2020
export { default as Toggle } from './base/Toggle.vue'
2121
export { default as CopyCode } from './base/CopyCode.vue'
22+
export { default as Notifications } from './base/Notifications.vue'
2223

2324
export { default as Categories } from './search/Categories.vue'
2425
export { default as SearchFilter } from './search/SearchFilter.vue'
@@ -52,19 +53,22 @@ export { default as DashboardIcon } from '@/assets/icons/dashboard.svg'
5253
export { default as DownloadIcon } from '@/assets/icons/download.svg'
5354
export { default as DropdownIcon } from '@/assets/icons/dropdown.svg'
5455
export { default as EditIcon } from '@/assets/icons/edit.svg'
55-
export { default as ExitIcon } from '@/assets/icons/exit.svg'
56+
export { default as ExitIcon } from '@/assets/icons/x.svg'
5657
export { default as ExpandIcon } from '@/assets/icons/expand.svg'
5758
export { default as ExternalIcon } from '@/assets/icons/external.svg'
5859
export { default as EyeIcon } from '@/assets/icons/eye.svg'
5960
export { default as EyeOffIcon } from '@/assets/icons/eye-off.svg'
6061
export { default as FileIcon } from '@/assets/icons/file.svg'
6162
export { default as FileTextIcon } from '@/assets/icons/file-text.svg'
6263
export { default as FilterIcon } from '@/assets/icons/filter.svg'
64+
export { default as FolderOpenIcon } from '@/assets/icons/folder-open.svg'
65+
export { default as FolderSearchIcon } from '@/assets/icons/folder-search.svg'
6366
export { default as GapIcon } from '@/assets/icons/gap.svg'
6467
export { default as GitHubIcon } from '@/assets/icons/github.svg'
6568
export { default as GlobeIcon } from '@/assets/icons/globe.svg'
6669
export { default as GridIcon } from '@/assets/icons/grid.svg'
6770
export { default as HamburgerIcon } from '@/assets/icons/hamburger.svg'
71+
export { default as HammerIcon } from '@/assets/icons/hammer.svg'
6872
export { default as HashIcon } from '@/assets/icons/hash.svg'
6973
export { default as HeartIcon } from '@/assets/icons/heart.svg'
7074
export { default as HeartHandshakeIcon } from '@/assets/icons/heart-handshake.svg'
@@ -78,6 +82,7 @@ export { default as LightBulbIcon } from '@/assets/icons/light-bulb.svg'
7882
export { default as LinkIcon } from '@/assets/icons/link.svg'
7983
export { default as ListIcon } from '@/assets/icons/list.svg'
8084
export { default as LockIcon } from '@/assets/icons/lock.svg'
85+
export { default as LogInIcon } from '@/assets/icons/log-in.svg'
8186
export { default as LogOutIcon } from '@/assets/icons/log-out.svg'
8287
export { default as MoonIcon } from '@/assets/icons/moon.svg'
8388
export { default as OmorphiaIcon } from '@/assets/icons/omorphia.svg'
@@ -95,10 +100,12 @@ export { default as SettingsIcon } from '@/assets/icons/settings.svg'
95100
export { default as ShieldIcon } from '@/assets/icons/shield.svg'
96101
export { default as SlashIcon } from '@/assets/icons/slash.svg'
97102
export { default as StarIcon } from '@/assets/icons/star.svg'
103+
export { default as StopCircleIcon } from '@/assets/icons/stop-circle.svg'
98104
export { default as SunIcon } from '@/assets/icons/sun.svg'
99105
export { default as SunriseIcon } from '@/assets/icons/sunrise.svg'
100106
export { default as TagIcon } from '@/assets/icons/tag.svg'
101107
export { default as TagsIcon } from '@/assets/icons/tags.svg'
108+
export { default as TerminalSquareIcon } from '@/assets/icons/terminal-square.svg'
102109
export { default as TransferIcon } from '@/assets/icons/transfer.svg'
103110
export { default as TrashIcon } from '@/assets/icons/trash.svg'
104111
export { default as UndoIcon } from '@/assets/icons/undo.svg'
@@ -113,5 +120,6 @@ export { default as UsersIcon } from '@/assets/icons/users.svg'
113120
export { default as VersionIcon } from '@/assets/icons/version.svg'
114121
export { default as WikiIcon } from '@/assets/icons/wiki.svg'
115122
export { default as XIcon } from '@/assets/icons/x.svg'
123+
export { default as XCircleIcon } from '@/assets/icons/x-circle.svg'
116124

117125
export { default as ModrinthIcon } from '@/assets/branding/logo.svg'

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "omorphia",
33
"type": "module",
4-
"version": "0.4.16",
4+
"version": "0.4.17",
55
"files": [
66
"dist"
77
],

0 commit comments

Comments
 (0)