Skip to content

Commit

Permalink
feat: handle video preview
Browse files Browse the repository at this point in the history
Refs: PREV-102 (#100)
  • Loading branch information
CMazzilli authored Sep 13, 2024
1 parent 5a9e389 commit 797a59b
Show file tree
Hide file tree
Showing 28 changed files with 570 additions and 83 deletions.
2 changes: 0 additions & 2 deletions THIRDPARTIES
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ MIT License (MIT) applies to:
@testing-library/react, Copyright (c) 2017 Kent C. Dodds
@testing-library/user-event, Copyright (c) 2020 Giorgio Polvara
@types/jest, Copyright (c) Microsoft Corporation.
@types/lodash, Copyright (c) Microsoft Corporation.
@types/node, Copyright (c) Microsoft Corporation.
@types/react-dom, Copyright (c) Microsoft Corporation.
@types/react, Copyright (c) Microsoft Corporation.
Expand All @@ -29,7 +28,6 @@ is-ci, Copyright (c) 2016-2021 Thomas Watson Steen
jest-environment-jsdom, Copyright (c) Meta Platforms, Inc. and affiliates.
jest-fail-on-console, Copyright (c) 2022 Valentin Hervieu
jest, Copyright (c) Meta Platforms, Inc. and affiliates.
lodash, Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
react-dom, Copyright (c) Facebook, Inc. and its affiliates.
react-pdf, Copyright (c) 2017–2023 Wojciech Maj
react, Copyright (c) Facebook, Inc. and its affiliates.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/carbonio-ui-preview.imagepreview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Main component for rendering the preview of an image
**Signature:**

```typescript
ImagePreview: import("react").ForwardRefExoticComponent<ImagePreviewProps & import("react").RefAttributes<HTMLDivElement>>
ImagePreview: React.ForwardRefExoticComponent<ImagePreviewProps & React.RefAttributes<HTMLDivElement>>
```
11 changes: 10 additions & 1 deletion docs/api/carbonio-ui-preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ Description
</td><td>


</td></tr>
<tr><td>

[VideoPreviewProps](./carbonio-ui-preview.videopreviewprops.md)


</td><td>


</td></tr>
</tbody></table>

Expand Down Expand Up @@ -174,7 +183,7 @@ The context give access to the functions needed to manage multiple previews. It

</td><td>

Show the preview for either an image or a pdf. This component is just a wrapper on the two specific preview components.
Show the preview for a video, an image or a pdf. This component is just a wrapper on the two specific preview components.


</td></tr>
Expand Down
4 changes: 3 additions & 1 deletion docs/api/carbonio-ui-preview.previewitem.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ Define an item for the preview. It can be of type 'image' or 'pdf'. The id is re
```typescript
export type PreviewItem = ((MakeOptional<Omit<ImagePreviewProps, 'show'>, 'onClose'> & {
previewType: 'image';
}) | (MakeOptional<Omit<VideoPreviewProps, 'show'>, 'onClose'> & {
previewType: 'video';
}) | (MakeOptional<Omit<PdfPreviewProps, 'show'>, 'onClose'> & {
previewType: 'pdf';
})) & {
id: string;
};
```
**References:** [MakeOptional](./carbonio-ui-preview.makeoptional.md)<!-- -->, [ImagePreviewProps](./carbonio-ui-preview.imagepreviewprops.md)<!-- -->, [PdfPreviewProps](./carbonio-ui-preview.pdfpreviewprops.md)
**References:** [MakeOptional](./carbonio-ui-preview.makeoptional.md)<!-- -->, [ImagePreviewProps](./carbonio-ui-preview.imagepreviewprops.md)<!-- -->, [VideoPreviewProps](./carbonio-ui-preview.videopreviewprops.md)<!-- -->, [PdfPreviewProps](./carbonio-ui-preview.pdfpreviewprops.md)

2 changes: 1 addition & 1 deletion docs/api/carbonio-ui-preview.previewwrapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## PreviewWrapper variable

Show the preview for either an image or a pdf. This component is just a wrapper on the two specific preview components.
Show the preview for a video, an image or a pdf. This component is just a wrapper on the two specific preview components.

**Signature:**

Expand Down
4 changes: 3 additions & 1 deletion docs/api/carbonio-ui-preview.previewwrapperprops.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export type PreviewWrapperProps = (ImagePreviewProps & {
previewType: 'image';
}) | (PdfPreviewProps & {
previewType: 'pdf';
}) | (VideoPreviewProps & {
previewType: 'video';
});
```
**References:** [ImagePreviewProps](./carbonio-ui-preview.imagepreviewprops.md)<!-- -->, [PdfPreviewProps](./carbonio-ui-preview.pdfpreviewprops.md)
**References:** [ImagePreviewProps](./carbonio-ui-preview.imagepreviewprops.md)<!-- -->, [PdfPreviewProps](./carbonio-ui-preview.pdfpreviewprops.md)<!-- -->, [VideoPreviewProps](./carbonio-ui-preview.videopreviewprops.md)

13 changes: 13 additions & 0 deletions docs/api/carbonio-ui-preview.videopreviewprops.errorlabel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@zextras/carbonio-ui-preview](./carbonio-ui-preview.md) &gt; [VideoPreviewProps](./carbonio-ui-preview.videopreviewprops.md) &gt; [errorLabel](./carbonio-ui-preview.videopreviewprops.errorlabel.md)

## VideoPreviewProps.errorLabel property

Label shown when the preview cannot be shown

**Signature:**

```typescript
errorLabel?: string;
```
94 changes: 94 additions & 0 deletions docs/api/carbonio-ui-preview.videopreviewprops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@zextras/carbonio-ui-preview](./carbonio-ui-preview.md) &gt; [VideoPreviewProps](./carbonio-ui-preview.videopreviewprops.md)

## VideoPreviewProps interface

**Signature:**

```typescript
export interface VideoPreviewProps extends Omit<PreviewNavigatorProps, 'onOverlayClick'>
```
**Extends:** Omit&lt;[PreviewNavigatorProps](./carbonio-ui-preview.previewnavigatorprops.md)<!-- -->, 'onOverlayClick'&gt;
## Properties
<table><thead><tr><th>
Property
</th><th>
Modifiers
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[errorLabel?](./carbonio-ui-preview.videopreviewprops.errorlabel.md)
</td><td>
</td><td>
string
</td><td>
_(Optional)_ Label shown when the preview cannot be shown
</td></tr>
<tr><td>
[mimeType?](./carbonio-ui-preview.videopreviewprops.mimetype.md)
</td><td>
</td><td>
string
</td><td>
_(Optional)_ File mime type
</td></tr>
<tr><td>
[src](./carbonio-ui-preview.videopreviewprops.src.md)
</td><td>
</td><td>
string
</td><td>
Preview video source
</td></tr>
</tbody></table>
13 changes: 13 additions & 0 deletions docs/api/carbonio-ui-preview.videopreviewprops.mimetype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@zextras/carbonio-ui-preview](./carbonio-ui-preview.md) &gt; [VideoPreviewProps](./carbonio-ui-preview.videopreviewprops.md) &gt; [mimeType](./carbonio-ui-preview.videopreviewprops.mimetype.md)

## VideoPreviewProps.mimeType property

File mime type

**Signature:**

```typescript
mimeType?: string;
```
13 changes: 13 additions & 0 deletions docs/api/carbonio-ui-preview.videopreviewprops.src.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@zextras/carbonio-ui-preview](./carbonio-ui-preview.md) &gt; [VideoPreviewProps](./carbonio-ui-preview.videopreviewprops.md) &gt; [src](./carbonio-ui-preview.videopreviewprops.src.md)

## VideoPreviewProps.src property

Preview video source

**Signature:**

```typescript
src: string;
```
17 changes: 14 additions & 3 deletions etc/carbonio-ui-preview.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
```ts

import { ForwardRefExoticComponent } from 'react';
import * as React_2 from 'react';
import { RefAttributes } from 'react';
import { default as React_3 } from 'react';
import { Theme } from '@zextras/carbonio-design-system';
import { TooltipProps } from '@zextras/carbonio-design-system';

Expand All @@ -31,7 +30,7 @@ interface HeaderProps {
}

// @public
export const ImagePreview: ForwardRefExoticComponent<ImagePreviewProps & RefAttributes<HTMLDivElement>>;
export const ImagePreview: React_3.ForwardRefExoticComponent<ImagePreviewProps & React_3.RefAttributes<HTMLDivElement>>;

// Warning: (ae-forgotten-export) The symbol "PreviewNavigatorProps" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -84,10 +83,13 @@ interface PreviewCriteriaAlternativeContentProps {
}

// Warning: (ae-forgotten-export) The symbol "MakeOptional" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "VideoPreviewProps" needs to be exported by the entry point index.d.ts
//
// @public
export type PreviewItem = ((MakeOptional<Omit<ImagePreviewProps, 'show'>, 'onClose'> & {
previewType: 'image';
}) | (MakeOptional<Omit<VideoPreviewProps, 'show'>, 'onClose'> & {
previewType: 'video';
}) | (MakeOptional<Omit<PdfPreviewProps, 'show'>, 'onClose'> & {
previewType: 'pdf';
})) & {
Expand Down Expand Up @@ -130,9 +132,18 @@ export type PreviewWrapperProps = (ImagePreviewProps & {
previewType: 'image';
}) | (PdfPreviewProps & {
previewType: 'pdf';
}) | (VideoPreviewProps & {
previewType: 'video';
});

// @public
export const usePreview: () => PreviewManagerContextType;

// @public (undocumented)
interface VideoPreviewProps extends Omit<PreviewNavigatorProps, 'onOverlayClick'> {
errorLabel?: string;
mimeType?: string;
src: string;
}

```
2 changes: 0 additions & 2 deletions examples/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions examples/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const items = [
src: 'https://pdfobject.com/pdf/sample.pdf',
filename: 'A sample PDF file',
extension: 'pdf'
},
{
previewType: 'video',
id: 'video-file',
src: 'https://github.com/webrtc/samples/raw/gh-pages/src/video/chrome.mp4',
filename: 'A sample video',
extension: 'mp4'
}
] satisfies PreviewItem[];

Expand Down
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const config: Config = {
// cacheDirectory: "/tmp/jest_rs",

// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,
// clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
Expand Down Expand Up @@ -124,7 +124,7 @@ const config: Config = {
// resolver: undefined,

// Automatically restore mock state and implementation before every test
// restoreMocks: true,
restoreMocks: true,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,
Expand Down
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.4",
"@types/node": "^18.19.34",
"@types/react": "^17.0.80",
"@types/react-dom": "^17.0.25",
Expand All @@ -82,7 +81,6 @@
},
"peerDependencies": {
"@zextras/carbonio-design-system": ">=1.0.0",
"lodash": "^4.17.21",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
Expand Down
5 changes: 2 additions & 3 deletions src/preview/FocusWithin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import { useCallback, useEffect, useRef } from 'react';
import * as React from 'react';

import { last } from 'lodash';

import styles from './FocusWithin.module.css';

interface FocusContainerProps {
Expand All @@ -28,7 +26,8 @@ const FocusWithin = ({ children, returnFocus = true }: FocusContainerProps): Rea

const onStartSentinelFocus = useCallback(() => {
if (contentRef.current) {
const node = last(contentRef.current.querySelectorAll<HTMLElement>('[tabindex]'));
const nodeListOf = contentRef.current.querySelectorAll<HTMLElement>('[tabindex]');
const node = nodeListOf[nodeListOf.length - 1];
node?.focus();
}
}, []);
Expand Down
Loading

0 comments on commit 797a59b

Please sign in to comment.