Skip to content

feat: upload file Area bs component #2523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import { DeleteIcon, EditIcon, UploadIcon } from "@sparrow/library/assets";
import { DeleteIcon, EditIcon } from "@sparrow/library/assets";
import { base64ToURL, imageDataToURL } from "@sparrow/common/utils";
import FileTypeIcon from "../../../../../../@sparrow-library/src/icons/FileTypeIcon.svelte";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't import it like this, import it like @sparrow/library/src/icons.

import { NewUploadIcon } from "@sparrow/library/icons";

export let value: any = [];
export let inputId: string;
Expand All @@ -19,7 +21,10 @@
export let height = "auto";
export let iconHeight = 12;
export let iconWidth = 12;
export let disabled = false;
export let fileTypes = ["JPG", "PNG", "JPEG"];
let isDragOver = false;
let isFocused = false;

const generateAcceptString = (): string => {
const acceptString = supportedFileTypes.map((type) => `${type}`).join(", ");
Expand All @@ -36,59 +41,91 @@
</script>

<div class="sparrow-text-input-container mb-2">
<div class="d-flex">
<div class="d-flex flex-column">
{#if value.length == 0 || value.size === 0}
<div
style="width:{width} !important; height:{height} !important; border: 3px dashed {isError
? 'var(--border-danger-200)'
: 'var(--border-secondary-200)'}; border-width: 2px;"
class="sparrow-file-input w-100 px-auto bg-tertiary-300 {isDragOver &&
'opacity-75 '}"
style="
width: ${width} !important;
height: ${height} !important;
border: {isError ? '2px' : '1px'} dashed {isError
? 'var(--border-ds-danger-300)'
: 'var(--border-ds-surface-100)'};
background-color: ${!disabled
? isError && isFocused
? 'var(--bg-ds-surface-400)'
: 'transparent'
: 'var(--bg-ds-surface-600)'};
"
class="sparrow-file-input p-2 w-100 px-auto bg-ds-surface-400 {isDragOver
? 'drag-over'
: ''}"
tabindex="0"
on:dragover={(e) => {
e.preventDefault();
isDragOver = true;
if (!disabled) {
e.preventDefault();
isDragOver = true;
}
}}
on:dragleave={() => {
isDragOver = false;
if (!disabled) isDragOver = false;
}}
on:drop={(e) => {
e.preventDefault();
isDragOver = false;
handleDrop(e, maxFileSize, supportedFileTypes);
if (!disabled) {
e.preventDefault();
isDragOver = false;
handleDrop(e, maxFileSize, supportedFileTypes);
}
}}
on:focus={() => {
if (!disabled) isFocused = true;
}}
on:blur={() => {
if (!disabled) isFocused = false;
}}
>
<span
class="sparrow-file-input-placeholder fw-normal d-flex justify-content-center mt-4"
>{inputPlaceholder}</span
>

<div
class="sparrow-choose-file-input-button d-flex justify-content-center my-4"
class="sparrow-choose-file-input-button d-flex justify-content-center"
>
<label for={inputId} class="d-flex">
<UploadIcon
classProp="my-auto"
width={iconWidth}
height={iconHeight}
color={"var(--icon-primary-300)"}
<div class="d-flex text-center row justify-content-center">
<label for={inputId} class="d-flex justify-content-center">
<NewUploadIcon />
</label>
<label for={inputId} class="sparrow-choose-file-label my-2 ps-2"
>Drag & Drop or <span class="sparrow-upload-text text-fs-14"
>Upload File</span
> here</label
>
<div for={inputId} class="d-flex justify-content-center text-fs-12">
<div class="file-type-container-one pe-2 pt-1 pb-1">
<FileTypeIcon />
<span class="file-type-text">{fileTypes[0]}</span>
</div>
{#each fileTypes.slice(1, -1) as fileType, index}
<div class="file-type-container-two px-2 pt-1 pb-1" key={index}>
<FileTypeIcon />
<span class="file-type-text">{fileType}</span>
</div>
{/each}
<div class="ps-2 pt-1 pb-1">
<FileTypeIcon />
<span class="file-type-text"
>{fileTypes[fileTypes.length - 1]}</span
>
</div>
</div>
<input
class="sparrow-choose-file-input visually-hidden"
type="file"
{value}
id={inputId}
placeholder={inputPlaceholder}
accept={generateAcceptString()}
{disabled}
on:change={(e) => {
onChange(e, maxFileSize, supportedFileTypes);
}}
/>
</label>

<label for={inputId} class="sparrow-choose-file-label ps-2"
>Choose File</label
>

<input
class="sparrow-choose-file-input visually-hidden"
type="file"
{value}
id={inputId}
placeholder={inputPlaceholder}
accept={generateAcceptString()}
on:change={(e) => {
onChange(e, maxFileSize, supportedFileTypes);
}}
/>
</div>
</div>
</div>
{/if}
Expand Down Expand Up @@ -122,6 +159,7 @@
id={inputId}
placeholder={inputPlaceholder}
accept={generateAcceptString()}
{disabled}
on:change={(e) => {
onChange(e, maxFileSize, supportedFileTypes);
}}
Expand All @@ -130,25 +168,59 @@
</div>

<style lang="scss">
.sparrow-input-label {
font-size: var(--base-text);
}
.sparrow-input-required {
color: var(--dangerColor);
.sparrow-choose-file-input-button {
margin-top: 22px;
margin-bottom: 22px;
}
.sparrow-file-input {
outline: none;
height: 164px;
min-width: 240px;
max-width: 540px;
border-radius: 4px;
font-size: var(--base-text);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take color as per new norms for example like this --text-ds-

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure I will update it.

transition:
border 0.2s ease-in-out,
background-color 0.2s ease-in-out;

&:hover {
border: 1px dashed var(--border-ds-neutral-300) !important;
cursor: pointer;
}

&:focus {
border: 1px dashed var(--border-ds-primary-300) !important;
background-color: var(--bg-ds-surface-500);
}
}
.sparrow-input-label-desc {
color: var(--request-arc);
font-size: var(--small-text);

.sparrow-file-input.drag-over {
border: 1px dashed var(--border-ds-primary-300) !important;
background-color: var(--bg-ds-surface-500);
}
.sparrow-file-input-placeholder {
color: var(--request-arc);
.sparrow-input-label {
font-size: var(--base-text);
}
.sparrow-file-input:hover {
border: 1px solid var(--border-ds-neutral-300);
cursor: pointer;
}
.sparrow-upload-text {
color: var(--text-ds-primary-300);
font-family: "Inter", sans-serif;
text-align: center;
cursor: pointer;
}
.file-type-text {
color: var(--text-ds-neutral-400);
font-family: "Inter", sans-serif;
text-align: left;
}
.file-type-container-one {
border-right: 1px solid var(--border-ds-surface-100);
}
.file-type-container-two {
border-right: 1px solid var(--border-ds-surface-100);
}
.sparrow-choose-file-input::file-selector-button {
background-color: transparent;
color: var(--primary-btn-color);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same take color as per new norm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update it.

Expand All @@ -157,7 +229,7 @@
}

.sparrow-choose-file-label {
color: var(--text-primary-300);
color: var(--text-ds-neutral-400);
}

.sparrow-input-image-preview > img {
Expand All @@ -180,12 +252,4 @@
background-color: var(--bg-tertiary-300);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here color

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update it.

}
}
.sparrow-file-input-error-text {
color: var(--dangerColor);
font-size: var(--small-text);
}

.sparrow-input-file-type {
border: 1px solid var(--border-color);
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
import type { TeamForm } from "../../types";
import { platform } from "@tauri-apps/plugin-os";
import { onMount } from "svelte";
import MessageTextIcon from "../../../../../../@sparrow-library/src/icons/MessageTextIcon.svelte";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update it.


/**
* Exports
*/
export let teamForm: TeamForm;
export let maxFileSizeText = 2;

/**
* Data
Expand Down Expand Up @@ -128,13 +130,13 @@
<!--
-- Title
-->
<span class="text-fs-14 text-secondary-1000">{ICON_CONFIG.TITLE}</span>
<span class="text-fs-14 upload-file-title">{ICON_CONFIG.TITLE}</span>

<!--
-- Description
-->
{#if !(!Array.isArray(teamForm.file.value) && teamForm.file.value.size > 0)}
<p class="mb-2 text-fs-12 text-secondary-200">
<p class="mb-2 text-fs-12 upload-file-description">
{ICON_CONFIG.DESCRIPTION}
</p>
{/if}
Expand All @@ -157,25 +159,70 @@
<!--
-- Error Messages
-->
<div>
{#if teamForm.file.showFileSizeError}
<p class="mb-2 mt-1 text-fs-12 text-danger-200">
{ICON_CONFIG.SIZE_EXCEED_ERROR_MESSAGE}
</p>
{:else if teamForm.file.showFileTypeError}
<p class="mb-2 mt-1 text-fs-12 text-danger-200">
{ICON_CONFIG.WRONG_FILE_ERROR_MESSAGE}
</p>
<!--
<div class="d-flex col justify-content-between">
<div>
{#if teamForm.file.showFileSizeError}
<div class="d-flex col gap-1">
<MessageTextIcon visible={false} />
<p class="mb-2 text-fs-12 message-error-text">
{ICON_CONFIG.SIZE_EXCEED_ERROR_MESSAGE}
</p>
</div>
{:else if teamForm.file.showFileTypeError}
<div class="d-flex col gap-1">
<MessageTextIcon visible={false} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using this MessageTextIcon we need pass the whole icon from prop and use that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Astitva877 This messageTextIcon component can take an SVG as a prop and should display it in place of the default icon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will take the icon as component as use here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I will update it.

<p class="mb-2 text-fs-12 message-error-text">
{ICON_CONFIG.WRONG_FILE_ERROR_MESSAGE}
</p>
</div>
<!--
-- Supportes File Types Button
-->
<div class="d-flex">
{#each ICON_CONFIG.FILE_TYPES as fileType (fileType)}
<span class="me-4">
<FileType {fileType} />
</span>
{/each}
</div>
{/if}
<div class="d-flex">
{#each ICON_CONFIG.FILE_TYPES as fileType (fileType)}
<span class="me-2">
<FileType {fileType} />
</span>
{/each}
</div>
{/if}
</div>
<div class="upload-max-file-content">
<p
class={`mb-2 text-fs-12 ${teamForm.file.showFileSizeError ? "upload-max-file-text-error" : "upload-max-file-text"}`}
>
Max file size: {maxFileSizeText}MB
</p>
</div>
</div>
</div>

<style lang="scss">
.upload-file-title {
font-family: "Inter", sans-serif;
font-weight: 400;
line-height: 20.02px;
text-align: left;
color: var(--text-ds-neutral-200);
}
.upload-file-description {
color: var(--text-ds-neutral-400);
font-weight: 400;
line-height: 18px;
}
.message-error-text {
color: var(--text-ds-danger-300);
word-break: break-word;
}
.upload-max-file-content {
font-family: "Inter", sans-serif;
line-height: 18px;
white-space: nowrap;
}
.upload-max-file-text {
color: var(--text-ds-neutral-400);
}
.upload-max-file-text-error {
color: var(--text-ds-danger-300);
}
</style>
18 changes: 18 additions & 0 deletions packages/@sparrow-library/src/icons/FileTypeIcon.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
export let height = 13;
export let width = 12;
export let color = "#82858A";
</script>

<svg
{width}
{height}
viewBox="0 0 13 12"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M9.99999 3.50207C9.99999 4.0555 9.55135 4.50414 8.99792 4.50414C8.44449 4.50414 7.99585 4.0555 7.99585 3.50207C7.99585 2.94864 8.44449 2.5 8.99792 2.5C9.55135 2.5 9.99999 2.94864 9.99999 3.50207ZM0.5 2.5C0.5 1.11929 1.61929 0 3 0H10C11.3807 0 12.5 1.11929 12.5 2.5V9.5C12.5 10.8807 11.3807 12 10 12H3C1.61929 12 0.5 10.8807 0.5 9.5V2.5ZM3 1C2.17157 1 1.5 1.67157 1.5 2.5V9.5C1.5 9.73159 1.55248 9.95092 1.6462 10.1467L5.29796 6.49499C5.96185 5.8311 7.03823 5.8311 7.70212 6.49499L11.3538 10.1467C11.4475 9.95088 11.5 9.73157 11.5 9.5V2.5C11.5 1.67157 10.8284 1 10 1H3ZM10.6467 10.8538L6.99501 7.2021C6.72164 6.92873 6.27843 6.92873 6.00506 7.2021L2.35333 10.8538C2.54914 10.9475 2.76844 11 3 11H10C10.2316 11 10.4509 10.9475 10.6467 10.8538Z"
fill={color}
/>
</svg>
Loading
Loading