fix: add input store, refactor color system

This commit is contained in:
Artemy Egorov 2024-07-29 16:53:15 +03:00
parent c206dbf40a
commit 9dfd66c14a
5 changed files with 48 additions and 40 deletions

View file

@ -3,17 +3,15 @@
@tailwind utilities; @tailwind utilities;
:root { :root {
--c0: #274f21; --min: #96e28a;
--c1: #448939; --max: #193815;
--c2: #73bf67;
--c3: #193815; /* --min: #8a9fe2;
--c4: #56aa49; --max: #151a38; */
--c5: #96e28a;
} }
body { body {
@apply bg-main text-main; @apply bg-vigi-90 text-vigi-10;
user-select: none; user-select: none;
} }
@ -44,14 +42,14 @@ body {
@apply p-1 rounded-lg; @apply p-1 rounded-lg;
@apply ease-out duration-150; @apply ease-out duration-150;
@apply hover:bg-main; @apply hover:bg-vigi-90;
@apply hover:px-2 hover:mx-1 hover:scale-125 hover:cursor-pointer; @apply hover:px-2 hover:mx-1 hover:scale-125 hover:cursor-pointer;
@apply active:bg-dark; @apply active:bg-vigi-100;
} }
.block { .block {
@apply p-2 rounded-xl bg-block; @apply p-2 rounded-xl bg-vigi-60;
} }
.sidebar { .sidebar {
@ -72,18 +70,18 @@ body {
.search-input { .search-input {
@apply ms-2 px-2 py-1 rounded-xl grow; @apply ms-2 px-2 py-1 rounded-xl grow;
@apply bg-block outline-none; @apply bg-vigi-60 outline-none;
@apply focus:bg-blockLight focus:text-light; @apply focus:bg-vigi-50 focus:text-vigi-0 hover:bg-vigi-55;
@apply ease-out duration-100; @apply ease-out duration-100;
} }
input::placeholder { input::placeholder {
@apply text-main focus:text-light; @apply text-vigi-40 focus:text-vigi-20;
} }
::selection { ::selection {
@apply bg-block; @apply bg-vigi-60;
} }
/* width */ /* width */
@ -98,12 +96,12 @@ input::placeholder {
/* Handle */ /* Handle */
::-webkit-scrollbar-thumb { ::-webkit-scrollbar-thumb {
@apply rounded-xl bg-main bg-clip-content; @apply rounded-xl bg-vigi-90 bg-clip-content;
border: 6px solid transparent; border: 6px solid transparent;
} }
/* Handle on hover */ /* Handle on hover */
::-webkit-scrollbar-thumb:hover { ::-webkit-scrollbar-thumb:hover {
@apply bg-dark; @apply bg-vigi-100;
border: 5px solid transparent; border: 5px solid transparent;
} }

View file

@ -4,6 +4,8 @@
import Reload from "$lib/icons/Reload.svelte"; import Reload from "$lib/icons/Reload.svelte";
import SidebarLeft from "$lib/icons/SidebarLeft.svelte"; import SidebarLeft from "$lib/icons/SidebarLeft.svelte";
import SidebarRight from "$lib/icons/SidebarRight.svelte"; import SidebarRight from "$lib/icons/SidebarRight.svelte";
import { topBarInput } from "$lib/stores";
import { get } from "svelte/store";
import Block from "./Block.svelte"; import Block from "./Block.svelte";
import Button from "./Button.svelte"; import Button from "./Button.svelte";
@ -12,11 +14,15 @@
export let onInput = () => {}; export let onInput = () => {};
export let sidebarOpen = true; export let sidebarOpen = true;
export let inputValue = "";
let currentInputValue = ""; let currentInput = "";
let input = "";
let input: HTMLInputElement; topBarInput.subscribe((val) => {
input = val;
});
let iEl: HTMLInputElement;
</script> </script>
<div class="top-bar"> <div class="top-bar">
@ -37,20 +43,23 @@
type="text" type="text"
placeholder="Search or enter URL" placeholder="Search or enter URL"
class="search-input" class="search-input"
bind:value={currentInputValue} bind:value={currentInput}
bind:this={input} bind:this={iEl}
on:keypress={(e) => { on:keypress={(e) => {
if (e.key === "Enter") { if (e.key === "Enter") {
inputValue = currentInputValue; topBarInput.set(currentInput);
onInput(); onInput();
} }
}} }}
on:focus={() => { on:focus={() => {
currentInputValue = inputValue; currentInput = input;
setTimeout(() => input.select(), 1); setTimeout(() => {
iEl.select();
iEl.scrollLeft = iEl.scrollWidth;
}, 1);
}} }}
on:focusout={() => { on:focusout={() => {
currentInputValue = decodeURIComponent(inputValue); currentInput = decodeURIComponent(input);
}} }}
/> />
</div> </div>

3
src/lib/stores.ts Normal file
View file

@ -0,0 +1,3 @@
import { writable } from "svelte/store";
export const topBarInput = writable("");

View file

@ -7,6 +7,7 @@
import type { Root } from "@txtdot/dalet"; import type { Root } from "@txtdot/dalet";
import { invoke } from "@tauri-apps/api/tauri"; import { invoke } from "@tauri-apps/api/tauri";
import { topBarInput } from "$lib/stores";
let sidebarOpen = true; let sidebarOpen = true;
@ -23,9 +24,9 @@
if (e.key === "q") sidebarOpen = !sidebarOpen; if (e.key === "q") sidebarOpen = !sidebarOpen;
}); });
function processInput() { topBarInput.subscribe((input) => {
isLoading = true; isLoading = true;
invoke("process_input", { input: inputValue }) invoke("process_input", { input })
.then((res) => { .then((res) => {
data = res as Root; data = res as Root;
isLoading = false; isLoading = false;
@ -34,7 +35,7 @@
data = [{ id: 0, body: "Error: " + err, argument: null }]; data = [{ id: 0, body: "Error: " + err, argument: null }];
isLoading = false; isLoading = false;
}); });
} });
</script> </script>
<div <div
@ -44,7 +45,7 @@
<Sidebar bind:sidebarOpen /> <Sidebar bind:sidebarOpen />
<div class="main-window"> <div class="main-window">
<TopBar bind:sidebarOpen bind:inputValue onInput={processInput} /> <TopBar bind:sidebarOpen />
<BrowserWindow {data} bind:isLoading /> <BrowserWindow {data} bind:isLoading />
</div> </div>
</div> </div>

View file

@ -1,19 +1,16 @@
let colors = {};
for (let i = 0; i <= 100; i += 5) {
colors[`vigi-${i}`] = `color-mix(in hsl, var(--max) ${i}%, var(--min))`;
}
/** @type {import('tailwindcss').Config} */ /** @type {import('tailwindcss').Config} */
export default { export default {
content: ["./src/**/*.{html,js,svelte,ts}"], content: ["./src/**/*.{html,js,svelte,ts}"],
theme: { theme: {
extend: { extend: {
colors: { colors,
main: "var(--c0)", textColor: colors,
block: "var(--c1)",
light: "var(--c2)",
dark: "var(--c3)",
blockLight: "var(--c4)",
},
textColor: {
main: "var(--c2)",
light: "var(--c5)",
},
}, },
}, },
plugins: [], plugins: [],