Skip to content

Commit 11fcf96

Browse files
committed
Add documentation for new display modes fro ListAttachments
1 parent 0ce075f commit 11fcf96

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

25.9 KB
Loading
25.1 KB
Loading

docs/documentation/docs/controls/ListItemAttachments.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ListItemAttachments control
22

3-
This control allows you to manage list item attachments, you can add or delete associated attachments. The attachments are listed in tile view.
3+
This control allows you to manage list item attachments, you can add or delete associated attachments. The attachments can be displayed in different modes: tiles (default), list, or compact list.
44

55
Here is an example of the control:
66

@@ -12,6 +12,10 @@ Here is an example of the control:
1212

1313
![ListItemAttachments Attachment Deleted ](../assets/ListItemAttachementDeletedMsg.png)
1414

15+
![ListItemAttachments Details List ](../assets/ListItemAttachmentsDetailsList.png)
16+
17+
![ListItemAttachments Details List Compact ](../assets/ListItemAttachmentsDetailsListCompact.png)
18+
1519
## How to use this control in your solutions
1620

1721
- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../../#getting-started) page for more information about installing the dependency.
@@ -30,6 +34,30 @@ import { ListItemAttachments } from '@pnp/spfx-controls-react/lib/ListItemAttach
3034
disabled={false} />
3135
```
3236

37+
- You can customize the display mode of attachments. Import the `AttachmentsDisplayMode` enum and use it:
38+
39+
```TypeScript
40+
import { ListItemAttachments, AttachmentsDisplayMode } from '@pnp/spfx-controls-react/lib/ListItemAttachments';
41+
42+
// Tiles view (default)
43+
<ListItemAttachments listId='dfa283f4-5faf-4d54-b6b8-5bcaf2725af5'
44+
itemId={1}
45+
context={this.props.context}
46+
displayMode={AttachmentsDisplayMode.Tiles} />
47+
48+
// List view
49+
<ListItemAttachments listId='dfa283f4-5faf-4d54-b6b8-5bcaf2725af5'
50+
itemId={1}
51+
context={this.props.context}
52+
displayMode={AttachmentsDisplayMode.DetailsList} />
53+
54+
// Compact list view
55+
<ListItemAttachments listId='dfa283f4-5faf-4d54-b6b8-5bcaf2725af5'
56+
itemId={1}
57+
context={this.props.context}
58+
displayMode={AttachmentsDisplayMode.DetailsListCompact} />
59+
```
60+
3361
- If you want to use `ListItemAttachments` controls with new form you have to use React.createRef.
3462

3563
Following example will add selected attachments to list item with id = 1
@@ -61,10 +89,21 @@ The `ListItemAttachments` control can be configured with the following propertie
6189
| webUrl | string | no | URL of the site. By default it uses the current site URL. |
6290
| label | string | no | Main text to display on the placeholder, next to the icon. |
6391
| description | string | no | Description text to display on the placeholder, below the main text and icon. |
92+
| displayMode | AttachmentsDisplayMode | no | Display mode for rendering attachments. Options: `AttachmentsDisplayMode.Tiles` (default), `AttachmentsDisplayMode.DetailsList`, or `AttachmentsDisplayMode.DetailsListCompact`. |
6493
| disabled | boolean | no | Specifies if the control is disabled or not. |
6594
| openAttachmentsInNewWindow | boolean | no | Specifies if the attachment should be opened in a separate browser tab. Use this property set to `true` if you plan to use the component in Microsoft Teams. |
6695
| onAttachmentChange | (itemData: any) => void | no | Callback function invoked when attachments are added or removed. Receives the updated item data including the new ETag. This is useful when using the control within a form (like DynamicForm) that tracks ETags for optimistic concurrency control. |
6796

97+
enum `AttachmentsDisplayMode`
98+
99+
Display mode for rendering attachments.
100+
101+
| Value | Description |
102+
| ---- | ---- |
103+
| Tiles | Displays attachments as tiles/thumbnails using DocumentCard components. This is the default mode. |
104+
| DetailsList | Displays attachments in a list format with file type icons, file names, and delete actions. |
105+
| DetailsListCompact | Displays attachments in a compact list format with reduced row height and padding. |
106+
68107
## Usage with DynamicForm
69108

70109
When using `ListItemAttachments` within a `DynamicForm` or any component that uses ETags for optimistic concurrency control, you should use the `onAttachmentChange` callback to update the ETag when attachments are modified:

src/controls/listItemAttachments/ListItemAttachments.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
362362
if (openAttachmentsInNewWindow) {
363363
return (
364364
<Link
365+
className={styles.detailsListLink}
365366
onClick={() => window.open(`${file.ServerRelativeUrl}?web=1`, "_blank")}
366367
>
367368
{file.FileName}
@@ -370,7 +371,7 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
370371
}
371372

372373
return (
373-
<Link href={`${file.ServerRelativeUrl}?web=1`}>
374+
<Link className={styles.detailsListLink} href={`${file.ServerRelativeUrl}?web=1`}>
374375
{file.FileName}
375376
</Link>
376377
);

0 commit comments

Comments
 (0)