Skip to content

Commit

Permalink
Merge pull request #27 from Villy-P:Villy-P/issue8
Browse files Browse the repository at this point in the history
Add Button, TextArea, Checkbox, Badge, Tooltip, Dropdown, and Option components
  • Loading branch information
Villy-P authored Oct 29, 2024
2 parents 9c7a9b5 + 4e2309b commit c3fba2d
Show file tree
Hide file tree
Showing 10 changed files with 960 additions and 29 deletions.
54 changes: 26 additions & 28 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import "@vscode-elements/elements/dist/vscode-button/index.js";
import { onMount } from "svelte";
import type { FileType, OptionCheckBox, Directory } from "./types";
Expand All @@ -9,6 +8,13 @@
import './styles/style.css'
import "./app.css";
import Button from "./ui/Button.svelte";
import TextArea from "./ui/TextArea.svelte";
import Checkbox from "./ui/Checkbox.svelte";
import Badge from "./ui/Badge.svelte";
import Tooltip from "./ui/Tooltip.svelte";
import Dropdown from "./ui/Dropdown.svelte";
import Option from "./ui/Option.svelte";
let cwd = ""; // The current working directory the user is in. Is set on runtime.
let directory: Directory; // Current Working Directory the user is in represented in class form
Expand All @@ -18,7 +24,7 @@
let ignore: string[] = []; // List of items to ignore, found in the text box within the UI
let chart: Chart<"pie", any[], any>; // The chart of items that is visualized.
let textarea: HTMLTextAreaElement; // The UI Element of the text box for ignore folders
let textareavalue: string; // The value for UI Element of the text box for ignore folders
let isFile: boolean = true; // Whether or not the graph shows number of files with extension or size of files
let fileOfType: string[]; // List of files that match the clicked element
Expand Down Expand Up @@ -119,7 +125,7 @@
// Updates the graph with data
function update() {
ignore = textarea.value.split("\n");
ignore = textareavalue.split("\n");
fileData.clear();
readFileAndChildren(directory.children!);
Expand Down Expand Up @@ -155,15 +161,11 @@
</script>

<main class="flex flex-col justify-center items-start h-full">
<h1 class="text-2xl font-bold py-2">File Makeup for {cwd}</h1>
<div class="flex items-center">
<button class="type type-left" on:click={() => {isFile = true; update()}} class:active={isFile}>File</button>
<button class="type type-right" on:click={() => {isFile = false; update()}} class:active={!isFile}>Size</button>
<div class="question tooltip-container">
<div>?</div>
<div class="tooltip-text">File will show the amount of files with the extension name, size will show the bytes of data located within these files.</div>
</div>
</div>
<h1 class="main-header font-bold py-2">File Makeup for {cwd}</h1>
<Dropdown>
<Option on:click={() => {isFile = true; update()}}>Display File Count</Option>
<Option on:click={() => {isFile = false; update()}}>Display Byte Count</Option>
</Dropdown>
<div style="width: 700px; height: 700px;">
<canvas id="myChart" role="img"></canvas>
</div>
Expand All @@ -175,25 +177,21 @@
{/if}
<div class="flex justify-center text-gray-500 flex-col pt-[10px]">
{#each options as option}
<div class="flex items-center">
<input type="checkbox" id="show-hidden" bind:checked={option.checked} on:change={() => update()}/>
<label for="show-hidden">{ option.label }</label>
<div class="question tooltip-container">
<div>?</div>
<div class="tooltip-text">{ option.tooltip }</div>
<div class="flex items-center h-6">
<Checkbox label={option.label} bind:checked={option.checked} onclickcheck={() => update()}/>
<Badge>?<Tooltip tooltipContainerClass="w-40">{option.tooltip}</Tooltip></Badge>
</div>
</div>
{/each}
<br>
<div class="flex items-center">
<h2>Ignore Folders</h2>
<div class="question tooltip-container">
<div>?</div>
<div class="tooltip-text">Each line will ignore a folder with that name. Do not include any slashes -- just use the name itself (like src or lib). Press Update to see changes</div>
</div>
</div>
<textarea class="max-w-[500px] h-[150px] py-3 px-5 box-border border-2 border-white rounded-md bg-gray-500 text-lg resize-none font-serif text-gray-400" id="textarea" bind:this={textarea}></textarea><br>
<TextArea
textareaclass="h-40"
placeholder="node_modules, build/, etc."
label="Ignore Folders"
id="textarea"
tooltiptext="Each line will ignore a folder with that name. Do not include any slashes -- just use the name itself (like src or lib). Press Update to see changes"
bind:value={textareavalue}>
</TextArea><br>
</div>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<vscode-button role="button" tabindex="0" on:click={() => update()}>Update</vscode-button><br><br>
<Button on:click={() => update()}>Update</Button><br><br>
</main>
11 changes: 10 additions & 1 deletion src/app.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind utilities;

.main-header {
display: block;
color: var(--vscode-foreground, #ccc);
font-size: 30px;
line-height: var(--type-ramp-base-line-height, normal);
margin-bottom: 2px;
width: fit-content;
}
10 changes: 10 additions & 0 deletions src/types/ui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type AccordionAppearance = "primary" | "secondary" | "item";

export type ButtonAppearance = "primary" | "secondary" | "icon";
export type ButtonType = "button" | "submit" | "reset";

export type DividerRole = "seperator" | "presentation";

export type DropdownPosition = "above" | "below";

export type TextAreaResize = "none" | "vertical" | "horizontal" | "both";
35 changes: 35 additions & 0 deletions src/ui/Badge.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="badge" {...$$restProps}>
<div class="control">
<slot />
</div>
</div>

<style>
.badge {
box-sizing: border-box;
font-family: var(
--vscode-font-family,
"-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol"
);
font-size: var(--type-ramp-minus1-font-size, 11px);
line-height: var(--type-ramp-minus1-line-height, 16px);
text-align: center;
display: inline-block;
}
.control {
align-items: center;
background-color: var(--vscode-badge-background, "#4d4d4d");
border: calc(var(--border-width, 1) * 1px) solid
var(--vscode-button-border, transparent);
border-radius: 11px;
box-sizing: border-box;
color: var(--vscode-badge-foreground, #fff);
display: flex;
height: calc(var(--design-unit, 4) * 4px);
justify-content: center;
min-width: calc(var(--design-unit, 4) * 4px + 2px);
min-height: calc(var(--design-unit, 4) * 4px + 2px);
padding: 3px 6px;
}
</style>
208 changes: 208 additions & 0 deletions src/ui/Button.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
<script lang="ts">
import type { ButtonAppearance, ButtonType } from "../types/ui";
export let appearance: ButtonAppearance = "primary";
export let ariaLabel: string | undefined = undefined;
export let autofocus: boolean = false;
export let disabled: boolean = false;
export let start: boolean = false;
export let form: string | undefined = undefined;
export let formaction: string | undefined = undefined;
export let formenctype: string | undefined = undefined;
export let formmethod: string | undefined = undefined;
export let formnovalidate: boolean | undefined = undefined;
export let formtarget: string | undefined = undefined;
export let name: string | undefined = undefined;
export let type: ButtonType | undefined = undefined;
export let value: string | undefined = undefined;
export let btnControlClass = "";
</script>

<div
class="button"
data-appearance={appearance}
data-disabled={disabled}
aria-label={ariaLabel}
{...$$restProps}
>
<!-- svelte-ignore a11y-autofocus -->
<button
class="btn-control {btnControlClass}"
{autofocus}
{form}
{formaction}
{formenctype}
{formmethod}
{formnovalidate}
{formtarget}
{name}
{type}
{value}
on:click
on:change
on:keydown
on:keyup
on:touchstart|passive
on:touchend
on:touchcancel
on:mouseenter
on:mouseleave
>
{#if start}
<span class="btn-start">
<slot name="start" />
</span>
{/if}
<div class="btn-content">
<slot />
</div>
</button>
</div>

<style>
.button {
display: inline-flex;
outline: none;
font-family: var(--vscode-font-family, "-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol");
font-size: var(--type-ramp-minus1-font-size, 11px);
line-height: var(--type-ramp-minus1-line-height, 16px);
color: var(--vscode-button-foreground, #fff);
background: var(--vscode-button-background, #0e639c);
border-radius: calc(var(--corner-radius-round, 2) * 1px);
fill: currentColor;
cursor: pointer;
}
.button:hover {
background: var(--vscode-button-hoverBackground, #1177bb);
}
.button:active {
background: var(--vscode-button-background, #0e639c);
}
.button[data-disabled="true"] {
opacity: var(--disabled-opacity, 0.4);
background: var(--vscode-button-background, #0e639c);
cursor: not-allowed;
}
.button[data-appearance="primary"] {
background: var(--vscode-button-background, #0e639c);
color: var(--vscode-button-foreground, #fff);
}
.button[data-appearance="primary"]:hover {
background: var(--vscode-button-hoverBackground, #1177bb);
}
.button[data-appearance="primary"]:active .btn-control:active {
background: var(--vscode-button-background, #0e639c);
}
.button[data-appearance="primary"] .btn-control:focus-visible {
outline: calc(var(--border-width, 1) * 1px) solid var(--vscode-focusBorder, #007fd4);
outline-offset: calc(var(--border-width, 1px) * 2px);
}
.button[data-appearance="primary"][data-disabled="true"] {
background: var(--vscode-button-background, #0e639c);
}
.button[data-appearance="secondary"] {
background: var(--vscode-button-secondaryBackground, #3a3d41);
color: var(--vscode-button-secondaryForeground, #fff);
}
.button[data-appearance="secondary"]:hover {
background: var(--vscode-button-secondaryHoverBackground, #45494e);
}
.button[data-appearance="secondary"]:active .btn-control:active {
background: var(--vscode-button-secondaryBackground, #3a3d41);
}
.button[data-appearance="secondary"] .btn-control:focus-visible {
outline: calc(var(--border-width, 1) * 1px) solid var(--vscode-focusBorder, #007fd4);
outline-offset: calc(var(--border-width, 1) * 2px);
}
.button[data-appearance="secondary"][data-disabled="true"] {
background: var(--vscode-button-secondaryBackground, #3a3d41);
}
.button[data-appearance="icon"] {
background: var(--button-icon-background, transparent);
border-radius: var(--button-icon-corner-radius, 5px);
color: var(--vscode-foreground, #cccccc);
aspect-ratio: 1 / 1;
}
.button[data-appearance="icon"]:hover {
background: var(--button-icon-hover-background, rgba(90, 93, 94, 0.31));
}
.button[data-appearance="icon"]:active .btn-control:active {
background: var(--button-icon-hover-background, rgba(90, 93, 94, 0.31));
}
.button[data-appearance="icon"] .btn-control {
padding: var(--button-icon-padding, 3px);
border: none;
}
.button[data-appearance="icon"] .btn-control:focus-visible {
outline: calc(var(--border-width, 1) * 1px) solid var(--vscode-focusBorder, #007fd4);
outline-offset: calc(var(--border-width, 1) * 2px);
}
.button[data-appearance="icon"][data-disabled="true"] {
background: var(--button-icon-background, transparent);
}
.btn-control {
background: transparent;
height: inherit;
flex-grow: 1;
box-sizing: border-box;
display: inline-flex;
justify-content: center;
align-items: center;
padding: var(--button-padding-vertical, 4px) var(--button-padding-horizontal, 11px);
white-space: wrap;
outline: none;
text-decoration: none;
border: calc(var(--border-width, 1) * 1px) solid var(--vscode-button-border, transparent);
color: inherit;
border-radius: inherit;
fill: inherit;
cursor: inherit;
font-family: inherit;
}
.btn-control:focus-visible {
outline: calc(var(--border-width, 1) * 1px) solid var(--vscode-focusBorder, #007fd4);
outline-offset: calc(var(--border-width, 1px) * 2px);
}
.btn-control::-moz-focus-inner {
border: 0;
}
.btn-content {
display: flex;
}
.btn-start {
display: flex;
margin-inline-end: 8px;
}
.btn-start span {
width: calc(var(--design-unit, 4) * 4px);
height: calc(var(--design-unit, 4) * 4px);
}
</style>
Loading

0 comments on commit c3fba2d

Please sign in to comment.