-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from silinternational/develop
Release
- Loading branch information
Showing
7 changed files
with
152 additions
and
2 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,104 @@ | ||
<script> | ||
import { isAboveMobile } from '../../mdc' | ||
import { createEventDispatcher } from 'svelte' | ||
export let raised = false | ||
export let outlined = false | ||
export let uploading = false | ||
export let mimeType = 'application/pdf,image/*' | ||
let fileInput = {} | ||
let highlighted = false | ||
const dispatch = createEventDispatcher() | ||
function highlight() { | ||
highlighted = true | ||
} | ||
function unhighlight() { | ||
highlighted = false | ||
} | ||
function handleDrop(e) { | ||
unhighlight() | ||
let dt = e.dataTransfer | ||
let files = dt.files | ||
handleFiles(files) | ||
} | ||
function handleFiles(files) { | ||
if (!uploading) { | ||
uploading = true | ||
files = [...files] //turns files into an array so forEach works | ||
files.forEach(uploadFile) | ||
} | ||
} | ||
function uploadFile(file) { | ||
const formData = new FormData() | ||
formData.append('file', file) | ||
dispatch('upload', formData) | ||
} | ||
</script> | ||
|
||
<style> | ||
form > * { | ||
margin-top: 0; | ||
} | ||
#drop-area { | ||
border: 2px dashed #ccc; | ||
} | ||
#drop-area.highlighted { | ||
border-color: var(--mdc-theme-primary); | ||
} | ||
#fileElem { | ||
display: none; | ||
} | ||
.disabled { | ||
cursor: progress; | ||
} | ||
.icon { | ||
color: hsla(213, 6%, 55%, 1); | ||
} | ||
</style> | ||
|
||
<div | ||
id="drop-area" | ||
class="br-8px {$$props.class}" | ||
class:highlighted | ||
on:dragenter|preventDefault|stopPropagation={highlight} | ||
on:dragleave|preventDefault|stopPropagation={unhighlight} | ||
on:dragover|preventDefault|stopPropagation={highlight} | ||
on:drop|preventDefault|stopPropagation={handleDrop} | ||
> | ||
<form class="flex justify-between align-items-center my-1 px-1" class:column={!isAboveMobile()}> | ||
{#if !uploading} | ||
<input | ||
bind:this={fileInput} | ||
type="file" | ||
id="fileElem" | ||
multiple | ||
accept={mimeType} | ||
disabled={uploading} | ||
on:change={() => handleFiles(fileInput.files)} | ||
/> | ||
{/if} | ||
<label | ||
class="mdc-button m-8px" | ||
for="fileElem" | ||
class:custom-text-button={raised} | ||
class:mdc-button--outlined={outlined} | ||
class:disabled={uploading} | ||
class:mdc-button--raised={raised}>Choose files</label | ||
> | ||
<div class="m-8px">or drop files here</div> | ||
<i class="material-icons icon m-8px" id="upload-icon">cloud_upload</i> | ||
</form> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@use '@material/button/styles'; | ||
@use "@material/button"; | ||
|
||
label.custom-text-button { | ||
--mdc-theme-primary: var(--mdc-theme-upload-button-color, hsla(214, 11%, 37%, 1)); | ||
|
||
@include button.ink-color(var(--mdc-theme-upload-button-ink-color, hsla(0,0%, 100%, 1))); | ||
} |
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,4 @@ | ||
import './_index.scss' | ||
import FileDropArea from './FileDropArea.svelte' | ||
|
||
export default FileDropArea |
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
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,30 @@ | ||
<script> | ||
import { Meta, Template, Story } from '@storybook/addon-svelte-csf' | ||
import { FileDropArea } from '../components/custom' | ||
import { copyAndModifyArgs } from './helpers.js' | ||
const args = { | ||
raised: true, | ||
outlined: false, | ||
uploading: false, | ||
mimeType: 'application/pdf,image/*', | ||
class: '', | ||
'on:upload': () => alert('you uploaded'), | ||
} | ||
</script> | ||
|
||
<Meta title="Atoms/FileDropArea" component={FileDropArea} /> | ||
|
||
<Template let:args> | ||
<FileDropArea {...args} on:upload={args['on:upload']} /> | ||
</Template> | ||
|
||
<Story name="Default" {args} /> | ||
|
||
<Story name="Raised" args={copyAndModifyArgs(args, { raised: true })} /> | ||
|
||
<Story name="Outlined" args={copyAndModifyArgs(args, { outlined: true })} /> | ||
|
||
<Story name="Uploading" args={copyAndModifyArgs(args, { uploading: true })} /> | ||
|
||
<Story name="MimeType" args={copyAndModifyArgs(args, { mimeType: 'image/*' })} /> |
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