Skip to content

Instantly share code, notes, and snippets.

@el3um4s
el3um4s / Language.ts
Created October 19, 2022 10:28
MEDIUM - Implementing Multi Language Without Any Library in Svelte - 02
export const languages = {
Home: {
Encrypt: {
en: "Encrypt",
it: "Cifra",
},
"Encrypt your text": {
en: "Encrypt your text",
it: "Cifra un messaggio di testo",
},
@el3um4s
el3um4s / store.ts
Created October 19, 2022 10:26
MEDIUM - Implementing Multi Language Without Any Library in Svelte - 01
import { writable } from "svelte/store";
import type { Writable } from "svelte/store";
const languageStore: Writable<string> = writable("en");
const lang = {
subscribe: languageStore.subscribe,
set: (language: string) => {
languageStore.set(language);
},
@el3um4s
el3um4s / notifications.ts
Created October 15, 2022 14:07
MEDIUM - How To Show Notifications in Web Application - 15
// ...
import notifications from "../Notification/Notification";
const goHome = () => {
page.set("Home");
if ($password != "") {
password.set("");
notifications.send({
message: "Password cleared",
type: "danger",
@el3um4s
el3um4s / notifications.ts
Last active October 15, 2022 14:06
MEDIUM - How To Show Notifications in Web Application - 14
import notifications from "./Notification";
const copyText = () => {
navigator.clipboard.writeText(cipherText);
notifications.send({
message: "Copied to clipboard",
type: "success",
timeout: 1500,
});
};
@el3um4s
el3um4s / App.svelte
Created October 15, 2022 14:05
MEDIUM - How To Show Notifications in Web Application - 13
<script>
// ...
import Notification from "./Notification.svelte";
// ...
</script>
<Notification />
<Header />
<main>
<!-- ... -->
@el3um4s
el3um4s / Notification.svelte
Created October 15, 2022 14:04
MEDIUM - How To Show Notifications in Web Application - 12
<script lang="ts">
import { flip } from "svelte/animate";
import { fly } from "svelte/transition";
import notifications from "./Notification";
export let themes = {
danger: "#E26D69",
success: "#1f8c34",
warning: "#f0ad4e",
@el3um4s
el3um4s / Notification.svelte
Created October 15, 2022 14:03
MEDIUM - How To Show Notifications in Web Application - 11
<script>
import { flip } from "svelte/animate";
import { fly } from "svelte/transition";
</script>
<!-- ... -->
<div
animate:flip
class="toast"
style="background: {themes[notification.msg.type]};"
@el3um4s
el3um4s / Notification.svelte
Created October 15, 2022 14:03
MEDIUM - How To Show Notifications in Web Application - 10
<script>
export let themes = {
danger: "#E26D69",
success: "#1f8c34",
warning: "#f0ad4e",
info: "#5bc0de",
default: "#aaaaaa",
};
</script>
@el3um4s
el3um4s / Notification.css
Created October 15, 2022 14:02
MEDIUM - How To Show Notifications in Web Application - 09
.notifications {
position: fixed;
top: 64px;
left: 0;
right: 8px;
margin: 0 auto;
padding: 0;
z-index: 9999;
display: flex;
flex-direction: column;
@el3um4s
el3um4s / Notification.svelte
Created October 15, 2022 14:01
MEDIUM - How To Show Notifications in Web Application - 08
<div class="notifications">
{#each $notifications as notification (notification.id)}
<div class="toast">
<div class="content">{notification.msg.message}</div>
</div>
{/each}
</div>