Skip to content

Commit

Permalink
feat(editor-content): working on preview component #29872
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobytes committed Sep 23, 2024
1 parent dea1913 commit fb7c358
Show file tree
Hide file tree
Showing 10 changed files with 427 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@
}
@case (fieldTypes.FILE) {
<dot-edit-content-file-field
[fieldVariable]="field.variable"
[contentlet]="contentlet"
[formControlName]="field.variable"
[attr.data-testId]="'field-' + field.variable"
[field]="field" />
}
@case (fieldTypes.IMAGE) {
<dot-edit-content-file-field
[fieldVariable]="field.variable"
[contentlet]="contentlet"
[formControlName]="field.variable"
[attr.data-testId]="'field-' + field.variable"
[field]="field" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,85 @@
<p>Preview</p>
@let previewFile = $previewFile();
@let metadata = $metadata();

<div class="preview-container">
<div class="preview-image__container">
@if (previewFile.source === 'temp') {
<dot-temp-file-thumbnail
[tempFile]="previewFile.file"
[iconSize]="'48px'"
data-testId="temp-file-thumbnail" />
} @else {
<dot-contentlet-thumbnail
[fieldVariable]="$fieldVariable()"
[iconSize]="'48px'"
[contentlet]="previewFile.file"
[playableVideo]="true"
data-testId="contentlet-thumbnail" />
}
</div>
<div class="preview-metadata__container">
@if (metadata) {
<span class="preview-metadata_header">{{ metadata.title }}</span>
@if (metadata.width && metadata.height) {
<div class="preview-metadata__info">
<i class="pi pi-arrows-alt"></i>
<span>{{ metadata.width }} x {{ metadata.height }}</span>
</div>
}
@if (metadata.fileSize) {
<div class="preview-metadata__info">
<i class="pi pi-file"></i>
<span>{{ metadata.fileSize | dotFileSizeFormat }}</span>
</div>
}
}
</div>
<div class="preview-resource-links__actions">
<p-button
(click)="toggleShowDialog()"
styleClass="p-button-rounded p-button-sm p-button-outlined"
data-testId="info-btn"
icon="pi pi-info" />
</div>
<div class="preview-metadata__actions">
<p-button
(click)="removeFile.emit()"
[label]="'dot.common.remove' | dm"
styleClass="p-button-link p-button-sm"
data-testId="remove-button"
icon="pi pi-trash" />
</div>
</div>

<p-dialog
[(visible)]="$showDialog"
[closeOnEscape]="true"
[dismissableMask]="true"
[modal]="true"
[header]="metadata.title"
[appendTo]="'body'"
[style]="{ maxWidth: '582px', width: '100%' }">
<div class="file-info__item">
<span class="file-info__title">{{ 'Size' | dm }}:</span>
<div class="file-info__link">
@if (metadata.width && metadata.height) {
<div class="file-info__size" data-testId="file-resolution">
<i class="pi pi-arrows-alt"></i>
<span>{{ metadata.width }}px, {{ metadata.height }}px</span>
</div>
}
<div class="file-info__size">
<i class="pi pi-file"></i>
<span>{{ metadata.fileSize | dotFileSizeFormat }}</span>
</div>
</div>
</div>

<ng-template pTemplate="footer">
<p-button
(click)="$showDialog.set(false)"
[label]="'Cancel' | dm"
styleClass="p-button-outlined"
data-testId="dialog-cancel" />
</ng-template>
</p-dialog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
@use "variables" as *;

:host {
display: block;
width: 100%;
height: 100%;
}

.preview-container {
display: flex;
gap: $spacing-1;
align-items: flex-start;
justify-content: center;
height: 100%;
width: 100%;
position: relative;
container-type: inline-size;
container-name: preview;

&:only-child {
gap: 0;
}
}

.preview-image__container {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
background: $color-palette-gray-200;
}

.preview-metadata__info {
display: flex;
justify-content: flex-start;
align-items: center;
gap: $spacing-0;
}

.preview-metadata__container {
flex-grow: 1;
padding: $spacing-1;
padding-right: $spacing-6;
flex-direction: column;
overflow: hidden;
gap: $spacing-2;
min-width: 150px;

span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.preview-metadata_header {
font-size: $font-size-md;
font-weight: $font-weight-semi-bold;
margin: 0;
color: $black;
}
}

.preview-metadata__actions {
position: absolute;
bottom: $spacing-1;
right: 0;
justify-content: flex-end;
align-items: center;
gap: $spacing-1;
z-index: 100;
}

.file-info__item {
display: flex;
padding: $spacing-0 0;
flex-direction: column;
justify-content: center;
align-items: flex-start;
gap: $spacing-0;

&:not(:last-child)::after {
content: "";
display: block;
width: 100%;
height: 1px;
background: $color-palette-gray-200;
margin: $spacing-1 0;
}
}

.file-info__link {
display: flex;
align-items: center;
gap: $spacing-1;
min-height: 32px;
font-size: $font-size-sm;
width: 100%;

a {
color: $black;
text-decoration: none;
flex: 1 0 0;
}
}

.file-info__title {
font-size: $font-size-sm;
font-style: normal;
font-weight: 600;
}

.file-info__size {
display: flex;
align-items: center;
gap: $spacing-0;
}

@container preview (min-width: 376px) {
.preview-metadata__container {
display: flex;
}

.preview-metadata__action--responsive {
display: none;
}

.preview-image__container {
height: 100%;
max-width: 17.5rem;
}

.preview-resource-links__actions {
display: flex;
}

.preview-overlay__container {
display: none;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
import { CUSTOM_ELEMENTS_SCHEMA, ChangeDetectionStrategy, Component } from '@angular/core';
import {
CUSTOM_ELEMENTS_SCHEMA,
ChangeDetectionStrategy,
Component,
computed,
input,
output,
signal
} from '@angular/core';

import { ButtonModule } from 'primeng/button';
import { DialogModule } from 'primeng/dialog';

import { DotTempFileThumbnailComponent, DotFileSizeFormatPipe, DotMessagePipe } from '@dotcms/ui';

import { PreviewFile } from '../../models';
import { getFileMetadata } from '../../utils';

@Component({
selector: 'dot-file-field-preview',
standalone: true,
imports: [],
imports: [
DotTempFileThumbnailComponent,
DotFileSizeFormatPipe,
DotMessagePipe,
ButtonModule,
DialogModule
],
providers: [],
templateUrl: './dot-file-field-preview.component.html',
styleUrls: ['./dot-file-field-preview.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class DotFileFieldPreviewComponent {}
export class DotFileFieldPreviewComponent {
$previewFile = input.required<PreviewFile>({ alias: 'previewFile' });
$fieldVariable = input.required<string>({ alias: 'fieldVariable' });
removeFile = output();
$showDialog = signal(false);

$metadata = computed(() => {
const previewFile = this.$previewFile();
if (previewFile.source === 'temp') {
return previewFile.file.metadata;
}

return getFileMetadata(previewFile.file, this.$fieldVariable());
});

toggleShowDialog() {
this.$showDialog.set(!this.$showDialog());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@
<div
[class.file-field__drop-zone--active]="store.dropZoneActive()"
class="file-field__drop-zone">
<dot-drop-zone data-testId="dropzone">
<input
#inputFile
[accept]="store.acceptedFiles().join(',')"
(change)="store.handleUploadFile(inputFile.files)"
data-testId="file-field__file-input"
type="file" />
<dot-drop-zone
[accept]="store.acceptedFiles()"
[maxFileSize]="store.maxFileSize()"
(fileDragLeave)="store.setDropZoneState(false)"
(fileDragOver)="store.setDropZoneState(true)"
(fileDropped)="handleFileDrop($event)"
data-testId="dropzone">
@if (store.uiMessage()) {
<dot-file-field-ui-message [uiMessage]="store.uiMessage()">
<button
(click)="inputFile.click()"
class="file-field__drop-zone-btn"
data-testId="choose-file-btn"
type="button">
Expand All @@ -19,7 +32,6 @@
</dot-file-field-ui-message>
}
</dot-drop-zone>
<input #inputFile data-testId="file-field__file-input" type="file" />
</div>

<div class="file-field__actions">
Expand Down Expand Up @@ -76,7 +88,12 @@
<dot-spinner data-testId="loading" />
}
@case ('preview') {
<dot-file-field-preview />
@if (store.previewFile()) {
<dot-file-field-preview
(removeFile)="store.removeFile()"
[previewFile]="store.previewFile()"
[fieldVariable]="store.fieldVariable()" />
}
}
}
</div>
Loading

0 comments on commit fb7c358

Please sign in to comment.