cozy-viewer 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/LICENSE +21 -0
- package/Readme.md +44 -0
- package/babel.config.js +23 -0
- package/dist/Footer/BottomSheetContent.d.ts +12 -0
- package/dist/Footer/BottomSheetContent.js +45 -0
- package/dist/Footer/DownloadButton.d.ts +16 -0
- package/dist/Footer/DownloadButton.js +113 -0
- package/dist/Footer/FooterActionButtons.d.ts +13 -0
- package/dist/Footer/FooterActionButtons.js +33 -0
- package/dist/Footer/FooterActionButtons.spec.d.ts +1 -0
- package/dist/Footer/FooterContent.d.ts +16 -0
- package/dist/Footer/FooterContent.js +120 -0
- package/dist/Footer/ForwardButton.d.ts +20 -0
- package/dist/Footer/ForwardButton.js +177 -0
- package/dist/Footer/ForwardButton.spec.d.ts +1 -0
- package/dist/Footer/ForwardOrDownloadButton.d.ts +11 -0
- package/dist/Footer/ForwardOrDownloadButton.js +42 -0
- package/dist/Footer/Sharing.d.ts +16 -0
- package/dist/Footer/Sharing.js +79 -0
- package/dist/Footer/helpers.d.ts +8 -0
- package/dist/Footer/helpers.js +179 -0
- package/dist/Footer/helpers.spec.d.ts +1 -0
- package/dist/NoViewer/DownloadButton.d.ts +2 -0
- package/dist/NoViewer/DownloadButton.js +52 -0
- package/dist/NoViewer/FileIcon.d.ts +4 -0
- package/dist/NoViewer/FileIcon.js +76 -0
- package/dist/NoViewer/NoViewer.d.ts +18 -0
- package/dist/NoViewer/NoViewer.js +64 -0
- package/dist/NoViewer/NoViewer.spec.d.ts +1 -0
- package/dist/NoViewer/index.d.ts +1 -0
- package/dist/NoViewer/index.js +15 -0
- package/dist/Panel/ActionMenuDesktop.d.ts +3 -0
- package/dist/Panel/ActionMenuDesktop.js +91 -0
- package/dist/Panel/ActionMenuMobile.d.ts +20 -0
- package/dist/Panel/ActionMenuMobile.js +95 -0
- package/dist/Panel/ActionMenuWrapper.d.ts +3 -0
- package/dist/Panel/ActionMenuWrapper.js +155 -0
- package/dist/Panel/Certifications.d.ts +2 -0
- package/dist/Panel/Certifications.js +80 -0
- package/dist/Panel/PanelContent.d.ts +2 -0
- package/dist/Panel/PanelContent.js +71 -0
- package/dist/Panel/Qualification.d.ts +2 -0
- package/dist/Panel/Qualification.js +148 -0
- package/dist/Panel/QualificationListItemContact.d.ts +10 -0
- package/dist/Panel/QualificationListItemContact.js +123 -0
- package/dist/Panel/QualificationListItemDate.d.ts +3 -0
- package/dist/Panel/QualificationListItemDate.js +90 -0
- package/dist/Panel/QualificationListItemInformation.d.ts +3 -0
- package/dist/Panel/QualificationListItemInformation.js +84 -0
- package/dist/Panel/QualificationListItemInformation.spec.d.ts +1 -0
- package/dist/Panel/QualificationListItemOther.d.ts +3 -0
- package/dist/Panel/QualificationListItemOther.js +78 -0
- package/dist/Panel/QualificationListItemText.d.ts +13 -0
- package/dist/Panel/QualificationListItemText.js +42 -0
- package/dist/Panel/getPanelBlocks.d.ts +26 -0
- package/dist/Panel/getPanelBlocks.js +79 -0
- package/dist/Panel/getPanelBlocks.spec.d.ts +1 -0
- package/dist/Viewer.d.ts +39 -0
- package/dist/Viewer.js +191 -0
- package/dist/ViewerContainer.d.ts +22 -0
- package/dist/ViewerContainer.js +221 -0
- package/dist/ViewerExposer.d.ts +2 -0
- package/dist/ViewerExposer.js +13 -0
- package/dist/ViewerInformationsWrapper.d.ts +20 -0
- package/dist/ViewerInformationsWrapper.js +68 -0
- package/dist/ViewerInformationsWrapper.spec.d.ts +1 -0
- package/dist/ViewerWithCustomPanelAndFooter.d.ts +2 -0
- package/dist/ViewerWithCustomPanelAndFooter.js +78 -0
- package/dist/ViewersByFile/AudioViewer.d.ts +74 -0
- package/dist/ViewersByFile/AudioViewer.js +57 -0
- package/dist/ViewersByFile/AudioViewer.spec.d.ts +1 -0
- package/dist/ViewersByFile/BlankPaperViewer.d.ts +2 -0
- package/dist/ViewersByFile/BlankPaperViewer.js +97 -0
- package/dist/ViewersByFile/ImageViewer.d.ts +31 -0
- package/dist/ViewersByFile/ImageViewer.js +385 -0
- package/dist/ViewersByFile/ImageViewer.spec.d.ts +1 -0
- package/dist/ViewersByFile/NoNetworkViewer.d.ts +2 -0
- package/dist/ViewersByFile/NoNetworkViewer.js +54 -0
- package/dist/ViewersByFile/OnlyOfficeViewer.d.ts +2 -0
- package/dist/ViewersByFile/OnlyOfficeViewer.js +46 -0
- package/dist/ViewersByFile/PdfJsViewer.d.ts +31 -0
- package/dist/ViewersByFile/PdfJsViewer.js +283 -0
- package/dist/ViewersByFile/PdfJsViewer.spec.d.ts +1 -0
- package/dist/ViewersByFile/PdfMobileViewer.d.ts +4 -0
- package/dist/ViewersByFile/PdfMobileViewer.js +185 -0
- package/dist/ViewersByFile/PdfMobileViewer.spec.d.ts +1 -0
- package/dist/ViewersByFile/ShortcutViewer.d.ts +2 -0
- package/dist/ViewersByFile/ShortcutViewer.js +61 -0
- package/dist/ViewersByFile/ShortcutViewer.spec.d.ts +4 -0
- package/dist/ViewersByFile/TextViewer.d.ts +90 -0
- package/dist/ViewersByFile/TextViewer.js +250 -0
- package/dist/ViewersByFile/TextViewer.spec.d.ts +1 -0
- package/dist/ViewersByFile/VideoViewer.d.ts +74 -0
- package/dist/ViewersByFile/VideoViewer.js +46 -0
- package/dist/ViewersByFile/VideoViewer.spec.d.ts +1 -0
- package/dist/assets/IlluGenericNewPage.svg +10 -0
- package/dist/components/ExpirationAlert.d.ts +2 -0
- package/dist/components/ExpirationAlert.js +129 -0
- package/dist/components/ExpirationAnnotation.d.ts +10 -0
- package/dist/components/ExpirationAnnotation.js +56 -0
- package/dist/components/Footer.d.ts +4 -0
- package/dist/components/Footer.js +41 -0
- package/dist/components/InformationPanel.d.ts +12 -0
- package/dist/components/InformationPanel.js +36 -0
- package/dist/components/Navigation.d.ts +18 -0
- package/dist/components/Navigation.js +63 -0
- package/dist/components/PdfToolbarButton.d.ts +16 -0
- package/dist/components/PdfToolbarButton.js +40 -0
- package/dist/components/PrintButton.d.ts +16 -0
- package/dist/components/PrintButton.js +163 -0
- package/dist/components/Toolbar.d.ts +2 -0
- package/dist/components/Toolbar.js +146 -0
- package/dist/components/ToolbarButtons.d.ts +5 -0
- package/dist/components/ToolbarButtons.js +20 -0
- package/dist/components/ToolbarFilePath.d.ts +3 -0
- package/dist/components/ToolbarFilePath.js +92 -0
- package/dist/components/ViewerByFile.d.ts +7 -0
- package/dist/components/ViewerByFile.js +137 -0
- package/dist/components/ViewerByFile.spec.d.ts +1 -0
- package/dist/components/ViewerControls.d.ts +9 -0
- package/dist/components/ViewerControls.js +251 -0
- package/dist/components/ViewerControls.spec.d.ts +1 -0
- package/dist/components/ViewerSpinner.d.ts +2 -0
- package/dist/components/ViewerSpinner.js +31 -0
- package/dist/docs/DemoProvider.d.ts +6 -0
- package/dist/docs/DemoProvider.js +159 -0
- package/dist/helpers.d.ts +37 -0
- package/dist/helpers.js +190 -0
- package/dist/helpers.spec.d.ts +1 -0
- package/dist/hoc/withFileUrl.d.ts +75 -0
- package/dist/hoc/withFileUrl.js +231 -0
- package/dist/hoc/withViewerLocales.d.ts +1 -0
- package/dist/hoc/withViewerLocales.js +15 -0
- package/dist/hooks/useReferencedContactName.d.ts +5 -0
- package/dist/hooks/useReferencedContactName.js +45 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +75 -0
- package/dist/locales/index.d.ts +6 -0
- package/dist/locales/index.js +18 -0
- package/dist/proptypes.d.ts +7 -0
- package/dist/proptypes.js +25 -0
- package/dist/providers/ActionMenuProvider.d.ts +13 -0
- package/dist/providers/ActionMenuProvider.js +47 -0
- package/dist/providers/EncryptedProvider.d.ts +8 -0
- package/dist/providers/EncryptedProvider.js +43 -0
- package/dist/queries.d.ts +15 -0
- package/dist/queries.js +40 -0
- package/dist/stylesheet.css +218 -0
- package/jest.config.js +23 -0
- package/package.json +62 -0
- package/preprocess.js +16 -0
- package/src/Footer/BottomSheetContent.jsx +30 -0
- package/src/Footer/DownloadButton.jsx +66 -0
- package/src/Footer/FooterActionButtons.jsx +22 -0
- package/src/Footer/FooterActionButtons.spec.jsx +30 -0
- package/src/Footer/FooterContent.jsx +102 -0
- package/src/Footer/ForwardButton.jsx +95 -0
- package/src/Footer/ForwardButton.spec.jsx +87 -0
- package/src/Footer/ForwardOrDownloadButton.jsx +24 -0
- package/src/Footer/Sharing.jsx +59 -0
- package/src/Footer/helpers.js +106 -0
- package/src/Footer/helpers.spec.js +77 -0
- package/src/NoViewer/DownloadButton.jsx +28 -0
- package/src/NoViewer/FileIcon.jsx +46 -0
- package/src/NoViewer/NoViewer.jsx +30 -0
- package/src/NoViewer/NoViewer.spec.jsx +44 -0
- package/src/NoViewer/__snapshots__/NoViewer.spec.jsx.snap +82 -0
- package/src/NoViewer/index.jsx +1 -0
- package/src/Panel/ActionMenuDesktop.jsx +69 -0
- package/src/Panel/ActionMenuMobile.jsx +76 -0
- package/src/Panel/ActionMenuWrapper.jsx +104 -0
- package/src/Panel/Certifications.jsx +63 -0
- package/src/Panel/PanelContent.jsx +50 -0
- package/src/Panel/Qualification.jsx +114 -0
- package/src/Panel/QualificationListItemContact.jsx +85 -0
- package/src/Panel/QualificationListItemDate.jsx +78 -0
- package/src/Panel/QualificationListItemInformation.jsx +68 -0
- package/src/Panel/QualificationListItemInformation.spec.jsx +73 -0
- package/src/Panel/QualificationListItemOther.jsx +61 -0
- package/src/Panel/QualificationListItemText.jsx +30 -0
- package/src/Panel/getPanelBlocks.jsx +56 -0
- package/src/Panel/getPanelBlocks.spec.jsx +79 -0
- package/src/Panel/styles.styl +13 -0
- package/src/Readme.md +352 -0
- package/src/Viewer.jsx +135 -0
- package/src/ViewerContainer.jsx +170 -0
- package/src/ViewerExposer.js +3 -0
- package/src/ViewerInformationsWrapper.jsx +70 -0
- package/src/ViewerInformationsWrapper.spec.jsx +63 -0
- package/src/ViewerWithCustomPanelAndFooter.jsx +57 -0
- package/src/ViewersByFile/AudioViewer.jsx +22 -0
- package/src/ViewersByFile/AudioViewer.spec.jsx +40 -0
- package/src/ViewersByFile/BlankPaperViewer.jsx +47 -0
- package/src/ViewersByFile/ImageViewer.jsx +331 -0
- package/src/ViewersByFile/ImageViewer.spec.jsx +73 -0
- package/src/ViewersByFile/NoNetworkViewer.jsx +18 -0
- package/src/ViewersByFile/OnlyOfficeViewer.jsx +29 -0
- package/src/ViewersByFile/PdfJsViewer.jsx +210 -0
- package/src/ViewersByFile/PdfJsViewer.spec.jsx +161 -0
- package/src/ViewersByFile/PdfMobileViewer.jsx +106 -0
- package/src/ViewersByFile/PdfMobileViewer.spec.jsx +76 -0
- package/src/ViewersByFile/ShortcutViewer.jsx +38 -0
- package/src/ViewersByFile/ShortcutViewer.spec.jsx +32 -0
- package/src/ViewersByFile/TextViewer.jsx +126 -0
- package/src/ViewersByFile/TextViewer.spec.jsx +118 -0
- package/src/ViewersByFile/VideoViewer.jsx +13 -0
- package/src/ViewersByFile/VideoViewer.spec.jsx +40 -0
- package/src/ViewersByFile/__snapshots__/AudioViewer.spec.jsx.snap +43 -0
- package/src/ViewersByFile/__snapshots__/ShortcutViewer.spec.jsx.snap +57 -0
- package/src/ViewersByFile/__snapshots__/TextViewer.spec.jsx.snap +100 -0
- package/src/ViewersByFile/__snapshots__/VideoViewer.spec.jsx.snap +19 -0
- package/src/ViewersByFile/styles.styl +87 -0
- package/src/assets/IlluGenericNewPage.svg +10 -0
- package/src/components/ExpirationAlert.jsx +86 -0
- package/src/components/ExpirationAnnotation.jsx +39 -0
- package/src/components/Footer.jsx +14 -0
- package/src/components/InformationPanel.jsx +26 -0
- package/src/components/Navigation.jsx +40 -0
- package/src/components/PdfToolbarButton.jsx +26 -0
- package/src/components/PrintButton.jsx +89 -0
- package/src/components/Toolbar.jsx +111 -0
- package/src/components/ToolbarButtons.jsx +11 -0
- package/src/components/ToolbarFilePath.jsx +61 -0
- package/src/components/ViewerByFile.jsx +112 -0
- package/src/components/ViewerByFile.spec.jsx +100 -0
- package/src/components/ViewerControls.jsx +191 -0
- package/src/components/ViewerControls.spec.jsx +54 -0
- package/src/components/ViewerSpinner.jsx +17 -0
- package/src/components/styles.styl +93 -0
- package/src/docs/DemoProvider.jsx +90 -0
- package/src/helpers.js +131 -0
- package/src/helpers.spec.js +136 -0
- package/src/hoc/withFileUrl.jsx +93 -0
- package/src/hoc/withViewerLocales.jsx +5 -0
- package/src/hooks/useReferencedContactName.jsx +26 -0
- package/src/index.jsx +12 -0
- package/src/locales/en.json +66 -0
- package/src/locales/fr.json +66 -0
- package/src/locales/index.js +4 -0
- package/src/proptypes.js +12 -0
- package/src/providers/ActionMenuProvider.jsx +35 -0
- package/src/providers/EncryptedProvider.jsx +25 -0
- package/src/queries.js +20 -0
- package/src/styles.styl +22 -0
- package/src/vars.styl +6 -0
- package/test/__mocks__/fileMock.js +3 -0
- package/test/jestLib/setup.js +5 -0
- package/tsconfig-build.json +13 -0
- package/tsconfig.json +34 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export namespace toolbarPropsPropType {
|
|
2
|
+
const showToolbar: PropTypes.Requireable<boolean>;
|
|
3
|
+
const showClose: PropTypes.Requireable<boolean>;
|
|
4
|
+
const toolbarRef: PropTypes.Requireable<object>;
|
|
5
|
+
const showFilePath: PropTypes.Requireable<boolean>;
|
|
6
|
+
}
|
|
7
|
+
import PropTypes from "prop-types";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.toolbarPropsPropType = void 0;
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var toolbarPropsPropType = {
|
|
13
|
+
/** Whether to show the toolbar or not. Note that the built-in close button is in the toolbar */
|
|
14
|
+
showToolbar: _propTypes.default.bool,
|
|
15
|
+
|
|
16
|
+
/** Whether to show close button in toolbar */
|
|
17
|
+
showClose: _propTypes.default.bool,
|
|
18
|
+
|
|
19
|
+
/** React reference of the toolbar node */
|
|
20
|
+
toolbarRef: _propTypes.default.object,
|
|
21
|
+
|
|
22
|
+
/** Whether to show file path below his name */
|
|
23
|
+
showFilePath: _propTypes.default.bool
|
|
24
|
+
};
|
|
25
|
+
exports.toolbarPropsPropType = toolbarPropsPropType;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default useActionMenuContext;
|
|
2
|
+
export type useActionMenuContextReturn = {
|
|
3
|
+
information: string;
|
|
4
|
+
page: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @returns {useActionMenuContextReturn}
|
|
8
|
+
*/
|
|
9
|
+
declare function useActionMenuContext(): useActionMenuContextReturn;
|
|
10
|
+
export function ActionMenuProvider({ children, editPathByModelProps }: {
|
|
11
|
+
children: any;
|
|
12
|
+
editPathByModelProps?: {} | undefined;
|
|
13
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.ActionMenuProvider = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
+
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} useActionMenuContextReturn
|
|
16
|
+
* @property {string} information
|
|
17
|
+
* @property {string} page
|
|
18
|
+
*/
|
|
19
|
+
var ActionMenuContext = /*#__PURE__*/(0, _react.createContext)();
|
|
20
|
+
|
|
21
|
+
var ActionMenuProvider = function ActionMenuProvider(_ref) {
|
|
22
|
+
var children = _ref.children,
|
|
23
|
+
_ref$editPathByModelP = _ref.editPathByModelProps,
|
|
24
|
+
editPathByModelProps = _ref$editPathByModelP === void 0 ? {} : _ref$editPathByModelP;
|
|
25
|
+
return /*#__PURE__*/_react.default.createElement(ActionMenuContext.Provider, {
|
|
26
|
+
value: editPathByModelProps
|
|
27
|
+
}, children);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @returns {useActionMenuContextReturn}
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
exports.ActionMenuProvider = ActionMenuProvider;
|
|
35
|
+
|
|
36
|
+
var useActionMenuContext = function useActionMenuContext() {
|
|
37
|
+
var actionMenuContext = (0, _react.useContext)(ActionMenuContext);
|
|
38
|
+
|
|
39
|
+
if (!actionMenuContext) {
|
|
40
|
+
throw new Error('ActionMenuContext must be used within a ActionMenuProvider');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return actionMenuContext;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
var _default = useActionMenuContext;
|
|
47
|
+
exports.default = _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const EncryptedContext: React.Context<any>;
|
|
2
|
+
export function useEncrypted(): any;
|
|
3
|
+
declare var _default: React.MemoExoticComponent<({ url, children }: {
|
|
4
|
+
url: any;
|
|
5
|
+
children: any;
|
|
6
|
+
}) => JSX.Element>;
|
|
7
|
+
export default _default;
|
|
8
|
+
import React from "react";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useEncrypted = exports.default = exports.EncryptedContext = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
+
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
+
|
|
14
|
+
var EncryptedContext = /*#__PURE__*/_react.default.createContext();
|
|
15
|
+
|
|
16
|
+
exports.EncryptedContext = EncryptedContext;
|
|
17
|
+
|
|
18
|
+
var useEncrypted = function useEncrypted() {
|
|
19
|
+
var context = (0, _react.useContext)(EncryptedContext);
|
|
20
|
+
|
|
21
|
+
if (!context) {
|
|
22
|
+
throw new Error('useEncrypted must be used within a EncryptedProvider');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return context;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.useEncrypted = useEncrypted;
|
|
29
|
+
|
|
30
|
+
var EncryptedProvider = function EncryptedProvider(_ref) {
|
|
31
|
+
var url = _ref.url,
|
|
32
|
+
children = _ref.children;
|
|
33
|
+
var contextValue = {
|
|
34
|
+
url: url
|
|
35
|
+
};
|
|
36
|
+
return /*#__PURE__*/_react.default.createElement(EncryptedContext.Provider, {
|
|
37
|
+
value: contextValue
|
|
38
|
+
}, children);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var _default = /*#__PURE__*/_react.default.memo(EncryptedProvider);
|
|
42
|
+
|
|
43
|
+
exports.default = _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function buildContactByIdsQuery(ids?: any[]): {
|
|
2
|
+
definition: () => import("cozy-client").QueryDefinition;
|
|
3
|
+
options: {
|
|
4
|
+
as: string;
|
|
5
|
+
fetchPolicy: Function;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export function buildFileByIdQuery(fileId: any): {
|
|
9
|
+
definition: () => import("cozy-client").QueryDefinition;
|
|
10
|
+
options: {
|
|
11
|
+
as: string;
|
|
12
|
+
fetchPolicy: Function;
|
|
13
|
+
singleDocData: boolean;
|
|
14
|
+
};
|
|
15
|
+
};
|
package/dist/queries.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildFileByIdQuery = exports.buildContactByIdsQuery = void 0;
|
|
7
|
+
|
|
8
|
+
var _cozyClient = require("cozy-client");
|
|
9
|
+
|
|
10
|
+
var defaultFetchPolicy = _cozyClient.fetchPolicies.olderThan(30 * 1000);
|
|
11
|
+
|
|
12
|
+
var buildContactByIdsQuery = function buildContactByIdsQuery() {
|
|
13
|
+
var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
14
|
+
return {
|
|
15
|
+
definition: function definition() {
|
|
16
|
+
return (0, _cozyClient.Q)('io.cozy.contacts').getByIds(ids);
|
|
17
|
+
},
|
|
18
|
+
options: {
|
|
19
|
+
as: "io.cozy.contacts/".concat(ids.join('')),
|
|
20
|
+
fetchPolicy: defaultFetchPolicy
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.buildContactByIdsQuery = buildContactByIdsQuery;
|
|
26
|
+
|
|
27
|
+
var buildFileByIdQuery = function buildFileByIdQuery(fileId) {
|
|
28
|
+
return {
|
|
29
|
+
definition: function definition() {
|
|
30
|
+
return (0, _cozyClient.Q)('io.cozy.files').getById(fileId);
|
|
31
|
+
},
|
|
32
|
+
options: {
|
|
33
|
+
as: "io.cozy.files/".concat(fileId),
|
|
34
|
+
fetchPolicy: defaultFetchPolicy,
|
|
35
|
+
singleDocData: true
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.buildFileByIdQuery = buildFileByIdQuery;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/* imported from styles.styl */
|
|
2
|
+
|
|
3
|
+
.viewer-imageviewer,
|
|
4
|
+
.viewer-noviewer,
|
|
5
|
+
.viewer-audioviewer,
|
|
6
|
+
.viewer-videoviewer,
|
|
7
|
+
.viewer-pdfviewer,
|
|
8
|
+
.viewer-textviewer,
|
|
9
|
+
.viewer-canceled {
|
|
10
|
+
position: relative;
|
|
11
|
+
display: flex;
|
|
12
|
+
width: 60%;
|
|
13
|
+
max-height: calc(100% - 4rem);
|
|
14
|
+
justify-content: center;
|
|
15
|
+
align-items: center;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
margin-top: 4rem;
|
|
18
|
+
}
|
|
19
|
+
.viewer-imageviewer h2,
|
|
20
|
+
.viewer-noviewer h2,
|
|
21
|
+
.viewer-audioviewer h2,
|
|
22
|
+
.viewer-videoviewer h2,
|
|
23
|
+
.viewer-pdfviewer h2,
|
|
24
|
+
.viewer-textviewer h2,
|
|
25
|
+
.viewer-canceled h2 {
|
|
26
|
+
max-width: 90%;
|
|
27
|
+
}
|
|
28
|
+
@media (max-width: 63.938rem) {
|
|
29
|
+
.viewer-imageviewer,
|
|
30
|
+
.viewer-noviewer,
|
|
31
|
+
.viewer-audioviewer,
|
|
32
|
+
.viewer-videoviewer,
|
|
33
|
+
.viewer-pdfviewer,
|
|
34
|
+
.viewer-textviewer,
|
|
35
|
+
.viewer-canceled {
|
|
36
|
+
margin-left: 0;
|
|
37
|
+
width: 100%;
|
|
38
|
+
max-height: calc(100% - 6.5rem);
|
|
39
|
+
margin-top: -0.5rem;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
.viewer-videoviewer video {
|
|
43
|
+
width: 100%;
|
|
44
|
+
max-width: 31.25rem;
|
|
45
|
+
height: auto;
|
|
46
|
+
}
|
|
47
|
+
.viewer-textviewer .viewer-textviewer-content {
|
|
48
|
+
white-space: pre-line;
|
|
49
|
+
width: 100%;
|
|
50
|
+
max-height: 70%;
|
|
51
|
+
overflow: auto;
|
|
52
|
+
}
|
|
53
|
+
.viewer-textviewer a {
|
|
54
|
+
color: var(--azure);
|
|
55
|
+
}
|
|
56
|
+
@media (max-width: 63.938rem) {
|
|
57
|
+
.viewer-textviewer {
|
|
58
|
+
width: 90%;
|
|
59
|
+
margin-left: 5%;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
.viewer-filename {
|
|
63
|
+
max-width: 90%;
|
|
64
|
+
text-overflow: ellipsis;
|
|
65
|
+
overflow: hidden;
|
|
66
|
+
}
|
|
67
|
+
.viewer-pdfviewer-pdf {
|
|
68
|
+
overflow: auto;
|
|
69
|
+
width: 100%;
|
|
70
|
+
}
|
|
71
|
+
.viewer-pdfviewer-page > * {
|
|
72
|
+
margin: auto;
|
|
73
|
+
}
|
|
74
|
+
.viewer-pdfviewer-toolbar {
|
|
75
|
+
position: absolute;
|
|
76
|
+
bottom: 2rem;
|
|
77
|
+
background: var(--charcoalGrey);
|
|
78
|
+
color: var(--white);
|
|
79
|
+
border-radius: 0.5rem;
|
|
80
|
+
}
|
|
81
|
+
.viewer-imageviewer {
|
|
82
|
+
flex: 1 1 100%;
|
|
83
|
+
width: auto;
|
|
84
|
+
max-width: 100%;
|
|
85
|
+
}
|
|
86
|
+
.viewer-imageviewer img {
|
|
87
|
+
display: block;
|
|
88
|
+
max-width: 100%;
|
|
89
|
+
max-height: 100%;
|
|
90
|
+
box-shadow: 0 0.375rem 1.5rem 0 rgba(0,0,0,0.5);
|
|
91
|
+
}
|
|
92
|
+
.viewer-pdfMobile {
|
|
93
|
+
width: 100%;
|
|
94
|
+
height: calc(100% - 6.5rem - var(--flagship-top-height));
|
|
95
|
+
margin-top: calc(var(--flagship-top-height, 0rem) + -0.5rem);
|
|
96
|
+
}
|
|
97
|
+
.viewer-pdfMobile--image {
|
|
98
|
+
width: 100%;
|
|
99
|
+
}
|
|
100
|
+
/* imported from styles.styl */
|
|
101
|
+
|
|
102
|
+
.ActionMenuDesktop-ActionMenu a {
|
|
103
|
+
padding: 0 !important;
|
|
104
|
+
}
|
|
105
|
+
.ActionMenuDesktop-ActionMenu .ActionMenuDesktop-ActionMenu-link-disabled > div {
|
|
106
|
+
cursor: default;
|
|
107
|
+
}
|
|
108
|
+
.ActionMenuDesktop-ActionMenu .ActionMenuDesktop-ActionMenu-link-disabled > div:hover {
|
|
109
|
+
background-color: initial;
|
|
110
|
+
}
|
|
111
|
+
.ActionMenuDesktop-ActionMenu .ActionMenuDesktop-ActionMenu-link-disabled > div > div svg {
|
|
112
|
+
fill: var(--disabledTextColor);
|
|
113
|
+
}
|
|
114
|
+
.ActionMenuDesktop-ActionMenu .ActionMenuDesktop-ActionMenu-link-disabled > div > div p {
|
|
115
|
+
color: var(--disabledTextColor);
|
|
116
|
+
}
|
|
117
|
+
/* imported from styles.styl */
|
|
118
|
+
|
|
119
|
+
@media (max-width: 48rem) {
|
|
120
|
+
}
|
|
121
|
+
@media (max-width: 63.938rem) {
|
|
122
|
+
}
|
|
123
|
+
.viewer-nav {
|
|
124
|
+
position: absolute;
|
|
125
|
+
top: 4rem;
|
|
126
|
+
bottom: 0;
|
|
127
|
+
z-index: var(--zIndex-modal-toolbar);
|
|
128
|
+
width: 20%;
|
|
129
|
+
cursor: pointer;
|
|
130
|
+
background-color: transparent;
|
|
131
|
+
transition: 0.4s opacity ease-out;
|
|
132
|
+
opacity: 0;
|
|
133
|
+
display: flex;
|
|
134
|
+
align-items: center;
|
|
135
|
+
justify-content: center;
|
|
136
|
+
flex-direction: column;
|
|
137
|
+
}
|
|
138
|
+
.viewer-nav--visible:hover {
|
|
139
|
+
opacity: 1;
|
|
140
|
+
transition: none;
|
|
141
|
+
}
|
|
142
|
+
.viewer-nav--previous {
|
|
143
|
+
left: 0;
|
|
144
|
+
}
|
|
145
|
+
.viewer-nav--previous .viewer-nav-arrow {
|
|
146
|
+
align-self: flex-start;
|
|
147
|
+
margin-left: 2.5rem;
|
|
148
|
+
transform: rotate(180deg);
|
|
149
|
+
}
|
|
150
|
+
.viewer-nav--next {
|
|
151
|
+
right: 0;
|
|
152
|
+
}
|
|
153
|
+
.viewer-nav--next .viewer-nav-arrow {
|
|
154
|
+
align-self: flex-end;
|
|
155
|
+
margin-right: 2.5rem;
|
|
156
|
+
}
|
|
157
|
+
@media (max-width: 63.938rem) {
|
|
158
|
+
.viewer-nav {
|
|
159
|
+
display: none;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
.viewer-nav-arrow {
|
|
163
|
+
opacity: 0.7;
|
|
164
|
+
}
|
|
165
|
+
.viewer-controls {
|
|
166
|
+
position: relative;
|
|
167
|
+
display: flex;
|
|
168
|
+
flex-direction: column;
|
|
169
|
+
justify-content: center;
|
|
170
|
+
align-items: center;
|
|
171
|
+
width: 100%;
|
|
172
|
+
height: 100%;
|
|
173
|
+
}
|
|
174
|
+
.viewer-controls._--expanded .viewer-nav {
|
|
175
|
+
margin-top: 0;
|
|
176
|
+
width: 40%;
|
|
177
|
+
}
|
|
178
|
+
@media (max-width: 63.938rem) {
|
|
179
|
+
.viewer-controls--display-content-top {
|
|
180
|
+
justify-content: flex-start;
|
|
181
|
+
padding-top: 4.5rem;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
.viewer-toolbar {
|
|
185
|
+
position: absolute;
|
|
186
|
+
top: 0;
|
|
187
|
+
z-index: var(--zIndex-modal-toolbar);
|
|
188
|
+
display: flex;
|
|
189
|
+
flex-shrink: 0;
|
|
190
|
+
width: calc(100% - 1rem);
|
|
191
|
+
padding: 0 0.5rem;
|
|
192
|
+
height: 4rem;
|
|
193
|
+
transition: 0.4s opacity ease-out;
|
|
194
|
+
background: linear-gradient(to bottom, var(--charcoalGrey), rgba(50,54,63,0));
|
|
195
|
+
justify-content: flex-start;
|
|
196
|
+
align-items: center;
|
|
197
|
+
}
|
|
198
|
+
.viewer-toolbar--hidden {
|
|
199
|
+
opacity: 0;
|
|
200
|
+
}
|
|
201
|
+
@media (max-width: 63.938rem) {
|
|
202
|
+
.viewer-toolbar {
|
|
203
|
+
height: 3rem;
|
|
204
|
+
width: 100%;
|
|
205
|
+
padding: var(--flagship-top-height) 1rem 0 0;
|
|
206
|
+
background: var(--paperBackgroundColor);
|
|
207
|
+
border-bottom: 1px solid var(--dividerColor);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
.viewer-footer {
|
|
211
|
+
position: fixed;
|
|
212
|
+
bottom: 0;
|
|
213
|
+
z-index: var(--zIndex-modal-footer);
|
|
214
|
+
width: 100%;
|
|
215
|
+
height: 3.5rem;
|
|
216
|
+
padding-bottom: var(--flagship-bottom-height, env(safe-area-inset-bottom));
|
|
217
|
+
background: var(--paperBackgroundColor);
|
|
218
|
+
}
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
testPathIgnorePatterns: ['node_modules', 'dist'],
|
|
3
|
+
testEnvironment: 'jest-environment-jsdom-sixteen',
|
|
4
|
+
testURL: 'http://localhost/',
|
|
5
|
+
moduleFileExtensions: ['js', 'jsx', 'json', 'styl', 'ts', 'tsx'],
|
|
6
|
+
moduleDirectories: ['src', 'node_modules'],
|
|
7
|
+
moduleNameMapper: {
|
|
8
|
+
'\\.(png|gif|jpe?g|svg)$': '<rootDir>/test/__mocks__/fileMock.js',
|
|
9
|
+
'\\.styl$': 'identity-obj-proxy',
|
|
10
|
+
'react-pdf/dist/esm/entry.webpack': 'react-pdf',
|
|
11
|
+
'^cozy-client$': 'cozy-client/dist/index'
|
|
12
|
+
},
|
|
13
|
+
transformIgnorePatterns: ['node_modules/(?!(cozy-ui|cozy-harvest-lib))'],
|
|
14
|
+
transform: {
|
|
15
|
+
'^.+\\.(ts|tsx|js|jsx)?$': 'babel-jest'
|
|
16
|
+
},
|
|
17
|
+
globals: {
|
|
18
|
+
__ALLOW_HTTP__: false,
|
|
19
|
+
cozy: {}
|
|
20
|
+
},
|
|
21
|
+
setupFilesAfterEnv: ['<rootDir>/test/jestLib/setup.js', 'jest-canvas-mock'],
|
|
22
|
+
snapshotSerializers: ['enzyme-to-json/serializer']
|
|
23
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cozy-viewer",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Cozy-Viewer provides a component to show files in a viewer.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/cozy/cozy-libs/blob/master/packages/cozy-scanner/README.md",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/cozy/cozy-libs.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/cozy/cozy-libs/issues"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rm -rf ./dist && tsc -p tsconfig-build.json && env BABEL_ENV=transpilation babel --extensions .ts,.tsx,.js,.jsx,.md,.styl,.json,.snap ./src -d ./dist --copy-files --no-copy-ignored --verbose",
|
|
17
|
+
"start": "yarn build --watch",
|
|
18
|
+
"test": "env NODE_ENV='test' jest",
|
|
19
|
+
"lint": "cd .. && yarn eslint --ext js,jsx packages/cozy-viewer"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@testing-library/jest-dom": "^5.14.1",
|
|
23
|
+
"@testing-library/react": "11.2.7",
|
|
24
|
+
"@testing-library/react-hooks": "^3.2.1",
|
|
25
|
+
"babel-preset-cozy-app": "2.1.0",
|
|
26
|
+
"cozy-client": "48.8.0",
|
|
27
|
+
"cozy-device-helper": "2.0.0",
|
|
28
|
+
"cozy-harvest-lib": "^6.7.3",
|
|
29
|
+
"cozy-intent": "^1.16.1",
|
|
30
|
+
"cozy-logger": "^1.9.0",
|
|
31
|
+
"cozy-sharing": "14.1.0",
|
|
32
|
+
"cozy-ui": "^111.9.0",
|
|
33
|
+
"enzyme": "3.11.0",
|
|
34
|
+
"enzyme-adapter-react-16": "1.15.6",
|
|
35
|
+
"enzyme-to-json": "3.6.2",
|
|
36
|
+
"identity-obj-proxy": "3.0.0",
|
|
37
|
+
"jest-canvas-mock": "2.3.1",
|
|
38
|
+
"prop-types": "15.8.1",
|
|
39
|
+
"react-dom": "16.12.0",
|
|
40
|
+
"react-test-renderer": "16.12.0",
|
|
41
|
+
"stylus": "0.63.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"classnames": "^2.2.5",
|
|
45
|
+
"hammerjs": "^2.0.8",
|
|
46
|
+
"lodash": "4.17.21",
|
|
47
|
+
"react-markdown": "^4.0.8",
|
|
48
|
+
"react-pdf": "^5.7.2"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"cozy-client": ">=48.8.0",
|
|
52
|
+
"cozy-device-helper": ">=2.0.0",
|
|
53
|
+
"cozy-harvest-lib": ">=6.7.3",
|
|
54
|
+
"cozy-intent": ">=1.16.1",
|
|
55
|
+
"cozy-logger": ">=1.9.0",
|
|
56
|
+
"cozy-sharing": ">=14.1.0",
|
|
57
|
+
"cozy-ui": ">=111.9.0",
|
|
58
|
+
"react": ">=16.12.0",
|
|
59
|
+
"react-dom": ">=16.12.0"
|
|
60
|
+
},
|
|
61
|
+
"gitHead": "dd811f957ba647453ca753bd78bff8fd7661a366"
|
|
62
|
+
}
|
package/preprocess.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const stylus = require('stylus')
|
|
2
|
+
|
|
3
|
+
const cozyStylusPlugin = require('cozy-ui/stylus')
|
|
4
|
+
|
|
5
|
+
const renderStylus = function (css, filename) {
|
|
6
|
+
try {
|
|
7
|
+
return stylus(css)
|
|
8
|
+
.use(cozyStylusPlugin())
|
|
9
|
+
.set('filename', filename)
|
|
10
|
+
.render()
|
|
11
|
+
} catch (e) {
|
|
12
|
+
console.log(e) // eslint-disable-line no-console
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = renderStylus
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { BottomSheetItem } from 'cozy-ui/transpiled/react/BottomSheet'
|
|
5
|
+
|
|
6
|
+
import getPanelBlocks, { getPanelBlocksSpecs } from '../Panel/getPanelBlocks'
|
|
7
|
+
|
|
8
|
+
const BottomSheetContent = ({ file, isPublic }) => {
|
|
9
|
+
const panelBlocks = getPanelBlocks({
|
|
10
|
+
panelBlocksSpecs: getPanelBlocksSpecs(isPublic),
|
|
11
|
+
file
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return panelBlocks.map((PanelBlock, index) => (
|
|
15
|
+
<BottomSheetItem
|
|
16
|
+
key={index}
|
|
17
|
+
disableGutters
|
|
18
|
+
disableElevation={index === panelBlocks.length - 1}
|
|
19
|
+
>
|
|
20
|
+
<PanelBlock file={file} />
|
|
21
|
+
</BottomSheetItem>
|
|
22
|
+
))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
BottomSheetContent.propTypes = {
|
|
26
|
+
file: PropTypes.object.isRequired,
|
|
27
|
+
isPublic: PropTypes.bool
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default BottomSheetContent
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useClient } from 'cozy-client'
|
|
5
|
+
import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
6
|
+
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
7
|
+
import IconButton from 'cozy-ui/transpiled/react/IconButton'
|
|
8
|
+
import DownloadIcon from 'cozy-ui/transpiled/react/Icons/Download'
|
|
9
|
+
import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter'
|
|
10
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
|
|
11
|
+
|
|
12
|
+
const DownloadButton = ({ file, variant }) => {
|
|
13
|
+
const client = useClient()
|
|
14
|
+
const { t } = useI18n()
|
|
15
|
+
|
|
16
|
+
const icon = <Icon icon={DownloadIcon} />
|
|
17
|
+
const label = t('Viewer.download')
|
|
18
|
+
|
|
19
|
+
const handleClick = async () => {
|
|
20
|
+
try {
|
|
21
|
+
await client.collection('io.cozy.files').download(file)
|
|
22
|
+
} catch (error) {
|
|
23
|
+
Alerter.info('Viewer.error.generic')
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (variant === 'iconButton') {
|
|
28
|
+
return (
|
|
29
|
+
<IconButton className="u-white" aria-label={label} onClick={handleClick}>
|
|
30
|
+
{icon}
|
|
31
|
+
</IconButton>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (variant === 'buttonIcon') {
|
|
36
|
+
return (
|
|
37
|
+
<Button
|
|
38
|
+
variant="secondary"
|
|
39
|
+
label={icon}
|
|
40
|
+
aria-label={label}
|
|
41
|
+
onClick={handleClick}
|
|
42
|
+
/>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Button
|
|
48
|
+
fullWidth
|
|
49
|
+
variant="secondary"
|
|
50
|
+
startIcon={icon}
|
|
51
|
+
label={label}
|
|
52
|
+
onClick={handleClick}
|
|
53
|
+
/>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
DownloadButton.propTypes = {
|
|
58
|
+
file: PropTypes.object,
|
|
59
|
+
variant: PropTypes.oneOf(['default', 'iconButton', 'buttonIcon'])
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
DownloadButton.defaultProptypes = {
|
|
63
|
+
variant: 'default'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default DownloadButton
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import { cloneElement } from 'react'
|
|
3
|
+
|
|
4
|
+
import { mapToAllChildren } from './helpers'
|
|
5
|
+
|
|
6
|
+
const FooterActionButtons = ({ children, file }) => {
|
|
7
|
+
if (!children) return null
|
|
8
|
+
|
|
9
|
+
return mapToAllChildren(children, child => cloneElement(child, { file }))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
FooterActionButtons.displayName = 'FooterActionButtons'
|
|
13
|
+
|
|
14
|
+
FooterActionButtons.propTypes = {
|
|
15
|
+
children: PropTypes.oneOfType([
|
|
16
|
+
PropTypes.node,
|
|
17
|
+
PropTypes.arrayOf(PropTypes.node)
|
|
18
|
+
]),
|
|
19
|
+
file: PropTypes.object
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default FooterActionButtons
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import FooterActionButtons from './FooterActionButtons'
|
|
5
|
+
|
|
6
|
+
describe('FooterActionButtons', () => {
|
|
7
|
+
it('should not return children', () => {
|
|
8
|
+
const { container } = render(<FooterActionButtons />)
|
|
9
|
+
|
|
10
|
+
expect(container).toMatchInlineSnapshot('<div />')
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('should render all childrens', () => {
|
|
14
|
+
const { getByText } = render(
|
|
15
|
+
<FooterActionButtons>
|
|
16
|
+
<div>
|
|
17
|
+
<p>First child</p>
|
|
18
|
+
<div>
|
|
19
|
+
<p>Sub first children</p>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
<div>Second child</div>
|
|
23
|
+
</FooterActionButtons>
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
expect(getByText('First child'))
|
|
27
|
+
expect(getByText('Sub first children'))
|
|
28
|
+
expect(getByText('Second child'))
|
|
29
|
+
})
|
|
30
|
+
})
|