-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): adding progress bar component (#337)
- Loading branch information
1 parent
23488f8
commit a36a1ef
Showing
6 changed files
with
109 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script lang="ts"> | ||
type BarSizeType = 'sm' | 'md' | 'lg' | 'xl' | ||
type UnitType = 'Cores' | 'GB' | ||
export let size: BarSizeType = 'sm' | ||
export let progress: number = 0 | ||
export let capacity: number = 0 | ||
export let unit: UnitType = 'GB' | ||
let calculatedWidth = 0 | ||
let fixedProgress: string | ||
let fixedCapacity: string | ||
$: { | ||
let percentage = (progress / capacity) * 100 | ||
fixedProgress = progress.toFixed(2) | ||
fixedCapacity = capacity.toFixed(2) | ||
// Need a minimum width set for rounded corners to look right | ||
calculatedWidth = percentage < 2 ? 2 : percentage | ||
} | ||
$: progressText = `${fixedProgress} ${unit} of ${fixedCapacity} ${unit} used` | ||
const sizeMapping = { | ||
sm: 'h-1.5', | ||
md: 'h-2.5', | ||
lg: 'h-4', | ||
xl: 'h-6', | ||
} | ||
</script> | ||
|
||
<div class="flex flex-col"> | ||
<div class="w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700 mt-3"> | ||
<div | ||
class={`bg-${unit === 'GB' ? 'green' : 'blue'}-600 rounded-full ${sizeMapping[size]}`} | ||
style={`width: ${calculatedWidth}%`} | ||
></div> | ||
</div> | ||
|
||
<span class="text-xs mt-1 font-normal text-gray-500 dark:text-gray-400 truncate overflow-ellipsis"> | ||
{progressText} | ||
</span> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script lang="ts"> | ||
import { goto } from '$app/navigation' | ||
import { Card } from '$components' | ||
export let path: string | ||
</script> | ||
|
||
<Card> | ||
<button class="flex flex-col" on:click={() => goto(path)}> | ||
<slot /> | ||
</button> | ||
</Card> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div | ||
class="bg-white dark:bg-gray-800 overflow-hidden shadow rounded-lg hover:dark:bg-gray-700 flex flex-col p-5 sm:p-6" | ||
> | ||
<slot /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters