Skip to content

Commit

Permalink
fix(statusbar): move statusbar to a new component
Browse files Browse the repository at this point in the history
status bar content animation
  • Loading branch information
Muhammed-Rahif committed Oct 2, 2024
1 parent 53c826e commit 629d145
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 24 deletions.
6 changes: 4 additions & 2 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
</script>

<!-- Actual UI -->
<MenuBar />
<Editors />
<div class="flex h-full flex-col">
<MenuBar />
<Editors />
</div>

<!-- Procedually -->
<SaveDialog />
Expand Down
14 changes: 9 additions & 5 deletions src/lib/components/Editors.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
}
$: isXS = innerWidth <= 450;
$: tabsMode = $editors.length > 1; // compact mode will not available on mobile width (w<=450), also on pc when multiple editors.
$: tabsClass = tabsMode ? 'h-[calc(100%-96px)] w-full' : 'h-[calc(100%-60px)] w-full';
$: tabsClass = tabsMode ? 'w-full' : 'w-full';
</script>

<svelte:window bind:innerWidth />

<Tabs.Root bind:value={$activeTabId} class={tabsClass}>
<Tabs.Root bind:value={$activeTabId} class={tabsClass} asChild>
{#if tabsMode || isXS}
<div transition:slide>
<Tabs.List class="w-full justify-start overflow-x-scroll rounded-t-none py-0.5 shadow">
<Tabs.List
class="w-full justify-start overflow-x-scroll
rounded-t-none py-0.5 shadow"
>
{#each $editors as editor}
<Tabs.Trigger value={editor.id} class={tabsMode ? 'pr-1' : ''}>
<EditorTitle {editor} />
Expand All @@ -64,10 +67,11 @@
{/if}

<!-- Only render one Textarea, which is focused based on selected tab -->
<Tabs.Content value={$activeTabId} class="mt-0 h-full">
<Tabs.Content asChild value={$activeTabId} class="mt-0 h-full">
<Textarea
bind:textarea
class="relative h-full w-full resize-none rounded-none !border-none bg-transparent text-base !outline-none !ring-0"
class="relative h-full w-full resize-none rounded-none
!border-none bg-transparent text-base !outline-none !ring-0"
spellcheck={false}
value={$editors.find((editor) => editor.id === $activeTabId)?.content}
on:keyup={onTextareaChange}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/MenuBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
{#if !isXS && !tabsMode}
<div
transition:fade
class="max-md:!ml-auto md:absolute md:left-1/2 md:top-1/2 md:-translate-x-1/2 md:-translate-y-1/2"
class="max-md:!ml-auto md:absolute md:left-1/2
md:top-1/2 md:-translate-x-1/2 md:-translate-y-1/2"
>
<EditorTitle editor={singleEditor} />
</div>
Expand Down
49 changes: 49 additions & 0 deletions src/lib/components/StatusBar.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script lang="ts">
import Separator from '@/components/ui/separator/separator.svelte';
import { slide } from 'svelte/transition';
export let lineNo = 1;
export let columnNo = 1;
export let characterCount = 0;
const inAnimation = {
duration: 80
};
</script>

<div
class="sticky bottom-0 z-10 h-[30px] w-full
bg-primary-foreground px-2"
>
<Separator />
<p
class="flex h-full w-full items-center justify-start
divide-x-2 text-sm [&>span]:px-4 first:[&>span]:pl-0 last:[&>span]:pr-0"
>
<span class="flex items-center justify-center">
Line:
{#key lineNo}
<span in:slide={inAnimation} class="ml-1 inline-block">
{lineNo}
</span>
{/key}
, Column:
{#key columnNo}
<span in:slide={inAnimation} class="ml-1 inline-block">
{columnNo}
</span>
{/key}
</span>

<span class="flex items-center justify-center">
{#key characterCount}
<span in:slide={inAnimation} class="mr-1 inline-block">
{characterCount}
</span>
{/key}
{characterCount <= 1 ? 'Character' : 'Characters'}
</span>

<span class="ml-auto">100%</span>
</p>
</div>
5 changes: 4 additions & 1 deletion src/lib/components/ui/menubar/menubar-checkbox-item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
on:pointermove
on:pointerdown
>
<span class="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<span
class="absolute left-2 flex h-3.5 w-3.5
items-center justify-center"
>
<MenubarPrimitive.CheckboxIndicator>
<Check class="h-4 w-4" />
</MenubarPrimitive.CheckboxIndicator>
Expand Down
5 changes: 4 additions & 1 deletion src/lib/components/ui/menubar/menubar-radio-item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
on:pointermove
on:pointerdown
>
<span class="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<span
class="absolute left-2 flex h-3.5 w-3.5
items-center justify-center"
>
<MenubarPrimitive.RadioIndicator>
<DotFilled class="h-4 w-4 fill-current" />
</MenubarPrimitive.RadioIndicator>
Expand Down
23 changes: 9 additions & 14 deletions src/lib/components/ui/textarea/textarea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import { cn } from '@/utils.js';
import { onMount } from 'svelte';
import throttle from 'lodash.throttle';
import Separator from '@/components/ui/separator/separator.svelte';
import StatusBar from '@/components/StatusBar.svelte';
export let textarea: HTMLTextAreaElement | null = null;
let fakeCaret: HTMLDivElement | null = null;
let caretPosition = { top: 10, left: 8, height: 24 };
let lineNo = 1;
let column = 1;
let characterCount = 0; // New variable for character count
let columnNo = 1;
let characterCount = 0;
// Import the textarea-caret module
let getCaretCoordinates: any;
Expand All @@ -25,7 +25,7 @@
textarea?.focus();
});
function updateLineAndColumn() {
function updateTextAreaInfo() {
if (textarea) {
const caretPosition = textarea.selectionStart;
const textBeforeCaret = textarea.value.slice(0, caretPosition);
Expand All @@ -34,7 +34,7 @@
lineNo = textBeforeCaret.split('\n').length;
// Calculate column (length of last line before caret)
column = textBeforeCaret.length - textBeforeCaret.lastIndexOf('\n');
columnNo = textBeforeCaret.length - textBeforeCaret.lastIndexOf('\n');
// Update character count
characterCount = textarea.value.length; // Update character count
Expand All @@ -57,7 +57,7 @@
};
// Update line and column numbers
updateLineAndColumn();
updateTextAreaInfo();
}
updateScheduled = false;
});
Expand Down Expand Up @@ -113,19 +113,14 @@
style="top: calc({caretPosition.top}px - 2px); left: {caretPosition.left}px; height: {caretPosition.height}px;"
/>
</div>
<div class="absolute bottom-0 z-10 h-[24px] w-full bg-primary-foreground px-1">
<Separator />
<p class="flex h-full w-full items-center justify-start text-sm">
Line: {lineNo}, Column: {column},
{characterCount <= 1 ? 'Character: ' : 'Characters: '}
{characterCount}
</p>
</div>

<StatusBar {lineNo} {columnNo} {characterCount} />

<style>
.fake-caret {
@apply absolute z-0 w-0.5 rounded-[2px] bg-primary duration-75;
}
@keyframes blink {
0% {
opacity: 1;
Expand Down

0 comments on commit 629d145

Please sign in to comment.