Skip to content
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

Tweak file upload layout, add filepond-plugin-media-preview, add disable preview option #1626

Merged
merged 15 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"filepond-plugin-image-preview": "^4.6.7",
"filepond-plugin-image-resize": "^2.0.10",
"filepond-plugin-image-transform": "^3.8.6",
"filepond-plugin-media-preview": "^1.0.9",
"imask": "^6.1.0",
"laravel-mix": "^6.0.37",
"marked": "^4.0.10",
Expand Down
29 changes: 28 additions & 1 deletion packages/forms/resources/css/components/file-upload.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,37 @@
@apply bg-white border border-gray-300 rounded-lg shadow-sm;
}

.filepond--drip-blob {
@apply bg-gray-900;
}

.dark .filepond--drop-label {
@apply bg-gray-700 text-gray-200 rounded-md;
@apply text-gray-200;
}

.dark .filepond--panel-root {
@apply border-gray-600 text-white bg-gray-700;
}

.dark .filepond--drip-blob {
@apply bg-gray-100;
}

/* Compact-only styles, excluding compact circle layouts */

.filepond--root[data-style-panel-layout='compact'] .filepond--item + .filepond--item {
@apply mt-0.5;
}

.filepond--root[data-style-panel-layout='compact'] .filepond--drop-label label {
@apply text-sm;
}

.filepond--root[data-style-panel-layout='compact'] .filepond--drop-label {
min-height: 2.625em;
}

.filepond--root[data-style-panel-layout='compact'] .filepond--file {
padding-top: 0.5em;
padding-bottom: 0.5em;
}
9 changes: 8 additions & 1 deletion packages/forms/resources/js/components/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import FilePondPluginImageExifOrientation from 'filepond-plugin-image-exif-orien
import FilePondPluginImagePreview from 'filepond-plugin-image-preview'
import FilePondPluginImageResize from 'filepond-plugin-image-resize'
import FilePondPluginImageTransform from 'filepond-plugin-image-transform'
import FilePondPluginMediaPreview from 'filepond-plugin-media-preview'

import 'filepond/dist/filepond.min.css'
import 'filepond-plugin-image-preview/dist/filepond-plugin-image-preview.css'
import 'filepond-plugin-media-preview/dist/filepond-plugin-media-preview.css';
import '../../css/components/file-upload.css'

FilePond.registerPlugin(FilePondPluginFileValidateSize)
Expand All @@ -18,11 +20,13 @@ FilePond.registerPlugin(FilePondPluginImageExifOrientation)
FilePond.registerPlugin(FilePondPluginImagePreview)
FilePond.registerPlugin(FilePondPluginImageResize)
FilePond.registerPlugin(FilePondPluginImageTransform)
FilePond.registerPlugin(FilePondPluginMediaPreview)

export default (Alpine) => {
Alpine.data('fileUploadFormComponent', ({
acceptedFileTypes,
canReorder,
canPreview,
deleteUploadedFileUsing,
getUploadedFileUrlUsing,
imageCropAspectRatio,
Expand Down Expand Up @@ -80,6 +84,9 @@ export default (Alpine) => {
this.pond = FilePond.create(this.$refs.input, {
acceptedFileTypes,
allowReorder: canReorder,
allowImagePreview: canPreview,
allowVideoPreview: canPreview,
allowAudioPreview: canPreview,
credits: false,
files: shouldAppendFiles ? this.files : this.files.reverse(),
imageCropAspectRatio,
Expand Down Expand Up @@ -164,7 +171,7 @@ export default (Alpine) => {

this.pond.files = shouldAppendFiles ? files : files.reverse()
})

this.pond.on('reorderfiles', async (files) => {
const orderedFileKeys = files
.map(file => file.source instanceof File ? file.serverId : this.uploadedFileUrlIndex[file.source] ?? null) // file.serverId is null for a file that is not yet uploaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
x-data="fileUploadFormComponent({
acceptedFileTypes: {{ json_encode($getAcceptedFileTypes()) }},
canReorder: {{ $canReorder() ? 'true' : 'false' }},
canPreview: {{ $canPreview() ? 'true' : 'false' }},
deleteUploadedFileUsing: async (fileKey) => {
return await $wire.deleteUploadedFile('{{ $getStatePath() }}', fileKey)
},
Expand Down Expand Up @@ -46,7 +47,7 @@
},
})"
wire:ignore
style="min-height: 76px"
style="min-height: {{ $isAvatar() ? '8em' : ($getPanelLayout() === 'compact' ? '2.625em' : '4.75em') }}"
{{ $attributes->merge($getExtraAttributes())->class([
'filament-forms-file-upload-component',
'w-32 mx-auto' => $isAvatar(),
Expand Down
14 changes: 14 additions & 0 deletions packages/forms/src/Components/BaseFileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class BaseFileUpload extends Field

protected bool | Closure $canReorder = false;

protected bool | Closure $canPreview = true;

protected string | Closure | null $directory = null;

protected string | Closure | null $diskName = null;
Expand Down Expand Up @@ -149,6 +151,13 @@ public function enableReordering(bool | Closure $condition = true): static
return $this;
}

public function disablePreview(bool | Closure $condition = false): static
{
$this->canPreview = $condition;

return $this;
}

public function preserveFilenames(bool | Closure $condition = true): static
{
$this->shouldPreserveFilenames = $condition;
Expand Down Expand Up @@ -243,6 +252,11 @@ public function canReorder(): bool
return $this->evaluate($this->canReorder);
}

public function canPreview(): bool
{
return $this->evaluate($this->canPreview);
}

public function getAcceptedFileTypes(): ?array
{
$types = $this->evaluate($this->acceptedFileTypes);
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/src/Components/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FileUpload extends BaseFileUpload

protected string | Closure | null $panelAspectRatio = null;

protected string | Closure | null $panelLayout = null;
protected string | Closure | null $panelLayout = 'compact';

protected string | Closure $removeUploadedFileButtonPosition = 'left';

Expand Down