-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor-content): working on preview component #29872
- Loading branch information
Showing
10 changed files
with
427 additions
and
22 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
86 changes: 85 additions & 1 deletion
86
...ontent-file-field/components/dot-file-field-preview/dot-file-field-preview.component.html
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 |
---|---|---|
@@ -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> |
140 changes: 140 additions & 0 deletions
140
...ontent-file-field/components/dot-file-field-preview/dot-file-field-preview.component.scss
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,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; | ||
} | ||
} |
47 changes: 44 additions & 3 deletions
47
...-content-file-field/components/dot-file-field-preview/dot-file-field-preview.component.ts
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 |
---|---|---|
@@ -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()); | ||
} | ||
} |
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
Oops, something went wrong.