Skip to content
Open
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
@use '@siemens/element-theme/src/styles/variables';

:host {
--attachment-list-bg: #{variables.$element-base-1-hover};
--attachment-list-bg: #{variables.$element-base-1};
--attachment-list-bg-hover: #{variables.$element-base-1-hover};
--attachment-name-color: #{variables.$element-text-primary};
}

Expand All @@ -23,6 +24,10 @@
text-align: inherit;
color: inherit;
cursor: pointer;

&:hover {
background-color: var(--attachment-list-bg-hover);
}
}

.attachment-icon {
Expand Down
70 changes: 44 additions & 26 deletions src/app/examples/si-chat-messages/si-attachment-list.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
<div class="p-2">
<si-attachment-list
alignment="start"
removeLabel="Remove attachment"
[attachments]="attachments"
[removable]="true"
(remove)="onRemoveAttachment($event)"
/>

<div class="m-4">
<div class="si-h5 mt-4">Removable attachments</div>
<div class="mt-5">
<si-attachment-list alignment="start" [attachments]="readOnlyAttachments" [removable]="false" />
</div>
</div>
<si-attachment-list
alignment="start"
removeLabel="Remove attachment"
[attachments]="attachments"
[removable]="true"
(remove)="onRemoveAttachment($event)"
/>

<div class="si-h5 mt-8">Read-only attachments</div>

<ng-template #modalTemplate let-modalRef="modalRef" let-attachment="attachment">
<div class="modal-header">
<h4 class="modal-title" id="sample-modal-title">{{ attachment.name }}</h4>
<button
type="button"
class="btn btn-circle btn-ghost element-cancel"
aria-label="Close modal"
(click)="modalRef.hide('cancel')"
>
</button>
<div class="mt-5">
<si-attachment-list
alignment="start"
[attachments]="readOnlyAttachments"
[removable]="false"
/>
</div>

<div class="si-h5 mt-8">Non-previewable attachments</div>

<div class="mt-5">
<si-attachment-list
alignment="start"
[attachments]="noPreviewAttachments"
[removable]="false"
/>
</div>
</div>
<div class="modal-body">
<span>This is a sample modal to demonstrate attachment preview functionality.</span>
</div></ng-template
>
<ng-template #modalTemplate let-modalRef="modalRef" let-attachment="attachment">
<div class="modal-header">
<h4 class="modal-title" id="sample-modal-title">{{ attachment.name }}</h4>
<button
type="button"
class="btn btn-circle btn-ghost element-cancel"
aria-label="Close modal"
(click)="modalRef.hide('cancel')"
>
</button>
</div>
<div class="modal-body">
<span>This is a sample modal to demonstrate attachment preview functionality.</span>
</div>
</ng-template>
</div>
15 changes: 15 additions & 0 deletions src/app/examples/si-chat-messages/si-attachment-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ export class SampleComponent {
}
];

noPreviewAttachments: Attachment[] = [
{
name: 'budget-quarterly.pptx'
},
{
name: 'data.json'
},
{
name: 'barchart.png'
},
{
name: 'event.ics'
}
];
Comment on lines +57 to +70
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

According to the repository's style guide (line 34), signals should be used for local component state. Consider converting noPreviewAttachments, and other state properties like attachments and readOnlyAttachments, to use signals. This would align with modern Angular practices and the project's conventions.

For example, you could define noPreviewAttachments as a signal:

import { signal } from '@angular/core';
// ...
  noPreviewAttachments = signal<Attachment[]>([
    {
      name: 'budget-quarterly.pptx'
    },
    // ... other attachments
  ]);

Then in your template, you would access it by calling the signal: [attachments]="noPreviewAttachments()".

Similarly, for the mutable attachments property, you could change it to a signal and update it like this:

// In SampleComponent
attachments = signal<Attachment[]>([]);

onRemoveAttachment(attachment: Attachment): void {
  this.logEvent(`Remove attachment: ${attachment.name}`);
  this.attachments.update(attachments => attachments.filter(a => a !== attachment));
}
References
  1. The style guide recommends using signals for local component state (line 34). (link)


onRemoveAttachment(attachment: Attachment): void {
this.logEvent(`Remove attachment: ${attachment.name}`);

Expand Down
Loading