@lnco-ai/ui 1.0.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 +1323 -0
- package/LICENSE +661 -0
- package/README.md +60 -0
- package/dist/Authorization/PreventGuestWrapper.d.ts +19 -0
- package/dist/Authorization/PreventGuestWrapper.js +15 -0
- package/dist/Authorization/RedirectionContent.d.ts +9 -0
- package/dist/Authorization/RedirectionContent.js +24 -0
- package/dist/Authorization/SignedInWrapper.d.ts +10 -0
- package/dist/Authorization/SignedInWrapper.js +21 -0
- package/dist/Avatar/Avatar.d.ts +24 -0
- package/dist/Avatar/Avatar.js +22 -0
- package/dist/Avatar/stringToColor.d.ts +12 -0
- package/dist/Avatar/stringToColor.js +31 -0
- package/dist/Avatar/stringToColor.test.d.ts +1 -0
- package/dist/Avatar/stringToColor.test.js +8 -0
- package/dist/Card/Card.d.ts +39 -0
- package/dist/Card/Card.js +76 -0
- package/dist/Card/CardHeader.d.ts +12 -0
- package/dist/Card/CardHeader.js +8 -0
- package/dist/Card/CardThumbnail.d.ts +10 -0
- package/dist/Card/CardThumbnail.js +14 -0
- package/dist/Card/FolderCard.d.ts +14 -0
- package/dist/Card/FolderCard.js +44 -0
- package/dist/Card/LinkCard.d.ts +11 -0
- package/dist/Card/LinkCard.js +41 -0
- package/dist/Card/components/CardThumbnail.d.ts +8 -0
- package/dist/Card/components/CardThumbnail.js +15 -0
- package/dist/Card/constants.d.ts +1 -0
- package/dist/Card/constants.js +1 -0
- package/dist/Collapse/Collapse.d.ts +10 -0
- package/dist/Collapse/Collapse.js +48 -0
- package/dist/Collapse/withCollapse.d.ts +7 -0
- package/dist/Collapse/withCollapse.js +8 -0
- package/dist/CookiesBanner/CookiesBanner.d.ts +10 -0
- package/dist/CookiesBanner/CookiesBanner.js +60 -0
- package/dist/CreativeCommons/CreativeCommons.d.ts +14 -0
- package/dist/CreativeCommons/CreativeCommons.js +75 -0
- package/dist/CreativeCommons/icons/By.d.ts +3 -0
- package/dist/CreativeCommons/icons/By.js +3 -0
- package/dist/CreativeCommons/icons/CCIconsProps.d.ts +3 -0
- package/dist/CreativeCommons/icons/CCIconsProps.js +1 -0
- package/dist/CreativeCommons/icons/Cc.d.ts +3 -0
- package/dist/CreativeCommons/icons/Cc.js +3 -0
- package/dist/CreativeCommons/icons/Cc0.d.ts +3 -0
- package/dist/CreativeCommons/icons/Cc0.js +3 -0
- package/dist/CreativeCommons/icons/Nc.d.ts +3 -0
- package/dist/CreativeCommons/icons/Nc.js +3 -0
- package/dist/CreativeCommons/icons/Nd.d.ts +3 -0
- package/dist/CreativeCommons/icons/Nd.js +3 -0
- package/dist/CreativeCommons/icons/Sa.d.ts +3 -0
- package/dist/CreativeCommons/icons/Sa.js +3 -0
- package/dist/CustomInitialLoader/CustomInitialLoader.d.ts +5 -0
- package/dist/CustomInitialLoader/CustomInitialLoader.js +25 -0
- package/dist/DrawerHeader/DrawerHeader.d.ts +7 -0
- package/dist/DrawerHeader/DrawerHeader.js +16 -0
- package/dist/GraaspLogo/EpflLogo.d.ts +5 -0
- package/dist/GraaspLogo/EpflLogo.js +3 -0
- package/dist/GraaspLogo/GraaspLogo.d.ts +8 -0
- package/dist/GraaspLogo/GraaspLogo.js +5 -0
- package/dist/Header/Header.d.ts +21 -0
- package/dist/Header/Header.js +33 -0
- package/dist/HeaderUserInformation/HeaderUserInformation.d.ts +22 -0
- package/dist/HeaderUserInformation/HeaderUserInformation.js +23 -0
- package/dist/ItemBadges/ItemBadges.d.ts +17 -0
- package/dist/ItemBadges/ItemBadges.js +10 -0
- package/dist/ItemFlag/ItemFlagButton.d.ts +9 -0
- package/dist/ItemFlag/ItemFlagButton.js +11 -0
- package/dist/ItemFlag/ItemFlagDialog.d.ts +14 -0
- package/dist/ItemFlag/ItemFlagDialog.js +25 -0
- package/dist/Loader/Loader.d.ts +7 -0
- package/dist/Loader/Loader.js +4 -0
- package/dist/Main/LogoHeader.d.ts +2 -0
- package/dist/Main/LogoHeader.js +5 -0
- package/dist/Main/Main.d.ts +59 -0
- package/dist/Main/Main.js +82 -0
- package/dist/MainMenu/MainMenu.d.ts +10 -0
- package/dist/MainMenu/MainMenu.js +6 -0
- package/dist/MainMenu/MenuItem/MenuItem.d.ts +16 -0
- package/dist/MainMenu/MenuItem/MenuItem.js +16 -0
- package/dist/MainMenu/hooks.d.ts +10 -0
- package/dist/MainMenu/hooks.js +21 -0
- package/dist/Navigation/CurrentItemNavigation.d.ts +15 -0
- package/dist/Navigation/CurrentItemNavigation.js +12 -0
- package/dist/Navigation/ExtraItemsMenu.d.ts +10 -0
- package/dist/Navigation/ExtraItemsMenu.js +24 -0
- package/dist/Navigation/ExtraItemsNavigation.d.ts +11 -0
- package/dist/Navigation/ExtraItemsNavigation.js +11 -0
- package/dist/Navigation/HomeMenu.d.ts +17 -0
- package/dist/Navigation/HomeMenu.js +28 -0
- package/dist/Navigation/ItemMenu.d.ts +16 -0
- package/dist/Navigation/ItemMenu.js +32 -0
- package/dist/Navigation/Navigation.d.ts +26 -0
- package/dist/Navigation/Navigation.js +15 -0
- package/dist/Navigation/ParentsNavigation.d.ts +10 -0
- package/dist/Navigation/ParentsNavigation.js +8 -0
- package/dist/Navigation/common/CenterAlignWrapper.d.ts +3 -0
- package/dist/Navigation/common/CenterAlignWrapper.js +7 -0
- package/dist/Navigation/common/NavigationLink.d.ts +8 -0
- package/dist/Navigation/common/NavigationLink.js +7 -0
- package/dist/Navigation/common/constants.d.ts +1 -0
- package/dist/Navigation/common/constants.js +1 -0
- package/dist/PlatformSwitch/PlatformSwitch.d.ts +57 -0
- package/dist/PlatformSwitch/PlatformSwitch.js +66 -0
- package/dist/PlatformSwitch/hooks.d.ts +30 -0
- package/dist/PlatformSwitch/hooks.js +49 -0
- package/dist/SearchInput/SearchInput.d.ts +20 -0
- package/dist/SearchInput/SearchInput.js +14 -0
- package/dist/Select/Select.d.ts +24 -0
- package/dist/Select/Select.js +7 -0
- package/dist/Sidebar/Sidebar.d.ts +11 -0
- package/dist/Sidebar/Sidebar.js +25 -0
- package/dist/StyledComponents/StyledBaseComponents.d.ts +11 -0
- package/dist/StyledComponents/StyledBaseComponents.js +11 -0
- package/dist/TextDisplay/TextDisplay.d.ts +5 -0
- package/dist/TextDisplay/TextDisplay.js +24 -0
- package/dist/TextDisplay/fixtures.d.ts +3 -0
- package/dist/TextDisplay/fixtures.js +84 -0
- package/dist/TextDisplay/withFlavor.d.ts +8 -0
- package/dist/TextDisplay/withFlavor.js +25 -0
- package/dist/TextEditor/TextEditor.d.ts +16 -0
- package/dist/TextEditor/TextEditor.js +74 -0
- package/dist/ThemeContext/LanguageSelect.d.ts +15 -0
- package/dist/ThemeContext/LanguageSelect.js +19 -0
- package/dist/ThemeContext/ThemeContext.d.ts +22 -0
- package/dist/ThemeContext/ThemeContext.js +31 -0
- package/dist/Thumbnail/Thumbnail.d.ts +28 -0
- package/dist/Thumbnail/Thumbnail.js +27 -0
- package/dist/Tree/Breadcrumbs.d.ts +14 -0
- package/dist/Tree/Breadcrumbs.js +30 -0
- package/dist/Tree/RowMenu.d.ts +12 -0
- package/dist/Tree/RowMenu.js +37 -0
- package/dist/Tree/RowMenus.d.ts +18 -0
- package/dist/Tree/RowMenus.js +7 -0
- package/dist/Tree/types.d.ts +6 -0
- package/dist/Tree/types.js +1 -0
- package/dist/UserSwitch/UserSwitch.d.ts +17 -0
- package/dist/UserSwitch/UserSwitch.js +46 -0
- package/dist/UserSwitch/UserSwitchWrapper.d.ts +37 -0
- package/dist/UserSwitch/UserSwitchWrapper.js +74 -0
- package/dist/appComponents/ErrorFallback.d.ts +57 -0
- package/dist/appComponents/ErrorFallback.js +72 -0
- package/dist/appComponents/QuestionLabel.d.ts +9 -0
- package/dist/appComponents/QuestionLabel.js +4 -0
- package/dist/appComponents/index.d.ts +6 -0
- package/dist/appComponents/index.js +5 -0
- package/dist/appComponents/statusChips/RequiredChip.d.ts +3 -0
- package/dist/appComponents/statusChips/RequiredChip.js +5 -0
- package/dist/appComponents/statusChips/SavedChip.d.ts +3 -0
- package/dist/appComponents/statusChips/SavedChip.js +5 -0
- package/dist/appComponents/statusChips/SubmittedChip.d.ts +3 -0
- package/dist/appComponents/statusChips/SubmittedChip.js +5 -0
- package/dist/appComponents/statusChips/types.d.ts +5 -0
- package/dist/appComponents/statusChips/types.js +1 -0
- package/dist/appComponents/types.d.ts +8 -0
- package/dist/appComponents/types.js +1 -0
- package/dist/apps.d.ts +1 -0
- package/dist/apps.js +1 -0
- package/dist/buttons/BookmarkButton/BookmarkButton.d.ts +24 -0
- package/dist/buttons/BookmarkButton/BookmarkButton.js +24 -0
- package/dist/buttons/Button/Button.d.ts +37 -0
- package/dist/buttons/Button/Button.js +4 -0
- package/dist/buttons/ChatboxButton/ChatboxButton.d.ts +15 -0
- package/dist/buttons/ChatboxButton/ChatboxButton.js +21 -0
- package/dist/buttons/CopyButton/CopyButton.d.ts +13 -0
- package/dist/buttons/CopyButton/CopyButton.js +14 -0
- package/dist/buttons/DeleteButton/DeleteButton.d.ts +12 -0
- package/dist/buttons/DeleteButton/DeleteButton.js +17 -0
- package/dist/buttons/DownloadButton/DownloadButton.d.ts +30 -0
- package/dist/buttons/DownloadButton/DownloadButton.js +20 -0
- package/dist/buttons/EditButton/EditButton.d.ts +13 -0
- package/dist/buttons/EditButton/EditButton.js +17 -0
- package/dist/buttons/LikeButton/LikeButton.d.ts +28 -0
- package/dist/buttons/LikeButton/LikeButton.js +10 -0
- package/dist/buttons/MenuItemButton.d.ts +11 -0
- package/dist/buttons/MenuItemButton.js +12 -0
- package/dist/buttons/MoveButton/MoveButton.d.ts +13 -0
- package/dist/buttons/MoveButton/MoveButton.js +19 -0
- package/dist/buttons/PinButton/PinButton.d.ts +15 -0
- package/dist/buttons/PinButton/PinButton.js +21 -0
- package/dist/buttons/SaveButton/SaveButton.d.ts +24 -0
- package/dist/buttons/SaveButton/SaveButton.js +4 -0
- package/dist/buttons/ShareButton/ShareButton.d.ts +14 -0
- package/dist/buttons/ShareButton/ShareButton.js +17 -0
- package/dist/buttons/hooks.d.ts +5 -0
- package/dist/buttons/hooks.js +14 -0
- package/dist/buttons/index.d.ts +12 -0
- package/dist/buttons/index.js +12 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +12 -0
- package/dist/draggable/DraggableElement.d.ts +11 -0
- package/dist/draggable/DraggableElement.js +42 -0
- package/dist/draggable/DraggingWrapper.d.ts +23 -0
- package/dist/draggable/DraggingWrapper.js +20 -0
- package/dist/draggable/InBetween.d.ts +10 -0
- package/dist/draggable/InBetween.js +34 -0
- package/dist/draggable/types.d.ts +10 -0
- package/dist/draggable/types.js +1 -0
- package/dist/enums/errors.d.ts +3 -0
- package/dist/enums/errors.js +3 -0
- package/dist/hooks/useFullscreen.d.ts +5 -0
- package/dist/hooks/useFullscreen.js +37 -0
- package/dist/hooks/useMobileView.d.ts +4 -0
- package/dist/hooks/useMobileView.js +6 -0
- package/dist/icons/AnalyticsIcon.d.ts +15 -0
- package/dist/icons/AnalyticsIcon.js +7 -0
- package/dist/icons/BuildIcon.d.ts +15 -0
- package/dist/icons/BuildIcon.js +7 -0
- package/dist/icons/EtherpadIcon.d.ts +7 -0
- package/dist/icons/EtherpadIcon.js +7 -0
- package/dist/icons/H5PIcon.d.ts +6 -0
- package/dist/icons/H5PIcon.js +6 -0
- package/dist/icons/ItemIcon.d.ts +23 -0
- package/dist/icons/ItemIcon.js +75 -0
- package/dist/icons/LibraryIcon.d.ts +16 -0
- package/dist/icons/LibraryIcon.js +7 -0
- package/dist/icons/PlayIcon.d.ts +15 -0
- package/dist/icons/PlayIcon.js +7 -0
- package/dist/icons/ResizingIcon.d.ts +2 -0
- package/dist/icons/ResizingIcon.js +21 -0
- package/dist/icons/StyledSVGComponents.d.ts +35 -0
- package/dist/icons/StyledSVGComponents.js +53 -0
- package/dist/icons/index.d.ts +6 -0
- package/dist/icons/index.js +6 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +60 -0
- package/dist/itemLogin/ForbiddenContent.d.ts +20 -0
- package/dist/itemLogin/ForbiddenContent.js +4 -0
- package/dist/itemLogin/ForbiddenText.d.ts +8 -0
- package/dist/itemLogin/ForbiddenText.js +6 -0
- package/dist/itemLogin/ItemLoginScreen.d.ts +26 -0
- package/dist/itemLogin/ItemLoginScreen.js +72 -0
- package/dist/itemLogin/ItemLoginWrapper.d.ts +23 -0
- package/dist/itemLogin/ItemLoginWrapper.js +43 -0
- package/dist/itemLogin/constants.d.ts +1 -0
- package/dist/itemLogin/constants.js +1 -0
- package/dist/items/AppItem.d.ts +60 -0
- package/dist/items/AppItem.js +69 -0
- package/dist/items/DocumentItem.d.ts +19 -0
- package/dist/items/DocumentItem.js +25 -0
- package/dist/items/DownloadButtonFileItem.d.ts +9 -0
- package/dist/items/DownloadButtonFileItem.js +10 -0
- package/dist/items/EtherpadItem.d.ts +26 -0
- package/dist/items/EtherpadItem.js +15 -0
- package/dist/items/FileAudio.d.ts +9 -0
- package/dist/items/FileAudio.js +10 -0
- package/dist/items/FileImage.d.ts +7 -0
- package/dist/items/FileImage.js +10 -0
- package/dist/items/FileItem.d.ts +25 -0
- package/dist/items/FileItem.js +81 -0
- package/dist/items/FilePdf.d.ts +14 -0
- package/dist/items/FilePdf.js +29 -0
- package/dist/items/FileVideo.d.ts +8 -0
- package/dist/items/FileVideo.js +9 -0
- package/dist/items/H5PItem.d.ts +20 -0
- package/dist/items/H5PItem.js +80 -0
- package/dist/items/ItemSkeleton/ItemSkeleton.d.ts +12 -0
- package/dist/items/ItemSkeleton/ItemSkeleton.js +35 -0
- package/dist/items/LinkItem.d.ts +43 -0
- package/dist/items/LinkItem.js +97 -0
- package/dist/items/SizingWrapper.d.ts +6 -0
- package/dist/items/SizingWrapper.js +23 -0
- package/dist/items/appItemHooks.d.ts +27 -0
- package/dist/items/appItemHooks.js +124 -0
- package/dist/items/constants.d.ts +1 -0
- package/dist/items/constants.js +1 -0
- package/dist/items/iframeStyles.d.ts +4 -0
- package/dist/items/iframeStyles.js +5 -0
- package/dist/items/index.d.ts +5 -0
- package/dist/items/index.js +5 -0
- package/dist/items/withCaption.d.ts +19 -0
- package/dist/items/withCaption.js +58 -0
- package/dist/items/withResizing.d.ts +9 -0
- package/dist/items/withResizing.js +42 -0
- package/dist/text-editor.d.ts +2 -0
- package/dist/text-editor.js +2 -0
- package/dist/theme.d.ts +108 -0
- package/dist/theme.js +214 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.js +32 -0
- package/dist/upload/FileDropper/FileDropper.d.ts +50 -0
- package/dist/upload/FileDropper/FileDropper.js +43 -0
- package/dist/upload/UploadFileButton/UploadFileButton.d.ts +35 -0
- package/dist/upload/UploadFileButton/UploadFileButton.js +17 -0
- package/dist/utils/fixtures.d.ts +3 -0
- package/dist/utils/fixtures.js +7 -0
- package/dist/utils/storybook.d.ts +5 -0
- package/dist/utils/storybook.js +5 -0
- package/package.json +172 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AlignmentType, DescriptionPlacementType, DiscriminatedItem } from '@lnco-ai/sdk';
|
|
3
|
+
export declare const getDefaultFileAlignmentSetting: (mimetype?: string) => AlignmentType;
|
|
4
|
+
type WithCaptionItem = {
|
|
5
|
+
description: string | null;
|
|
6
|
+
settings?: {
|
|
7
|
+
descriptionPlacement?: DescriptionPlacementType;
|
|
8
|
+
alignment?: AlignmentType;
|
|
9
|
+
};
|
|
10
|
+
extra?: DiscriminatedItem['extra'];
|
|
11
|
+
};
|
|
12
|
+
type WithCaptionProps<T extends WithCaptionItem> = {
|
|
13
|
+
item: T;
|
|
14
|
+
};
|
|
15
|
+
export declare const CaptionWrapper: <T extends WithCaptionItem>({ item, children, }: WithCaptionProps<T> & {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
}) => JSX.Element;
|
|
18
|
+
export declare function withCaption<T extends WithCaptionItem>({ item, }: WithCaptionProps<T>): (component: JSX.Element) => JSX.Element;
|
|
19
|
+
export default withCaption;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Stack } from '@mui/material';
|
|
3
|
+
import { Alignment, DescriptionPlacement, MimeTypes, getMimetype, } from '@lnco-ai/sdk';
|
|
4
|
+
import TextDisplay from '../TextDisplay/TextDisplay.js';
|
|
5
|
+
export const getDefaultFileAlignmentSetting = (mimetype) => {
|
|
6
|
+
if (!mimetype) {
|
|
7
|
+
return Alignment.Left;
|
|
8
|
+
}
|
|
9
|
+
switch (true) {
|
|
10
|
+
case MimeTypes.isImage(mimetype):
|
|
11
|
+
case MimeTypes.isAudio(mimetype):
|
|
12
|
+
case MimeTypes.isVideo(mimetype):
|
|
13
|
+
case MimeTypes.isPdf(mimetype):
|
|
14
|
+
return Alignment.Center;
|
|
15
|
+
// unknown mimetype is left aligned
|
|
16
|
+
default:
|
|
17
|
+
return Alignment.Left;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const getAlignItemsFromAlignmentSetting = (alignment) => {
|
|
21
|
+
switch (alignment) {
|
|
22
|
+
case Alignment.Right:
|
|
23
|
+
return 'flex-end';
|
|
24
|
+
case Alignment.Left:
|
|
25
|
+
return 'flex-start';
|
|
26
|
+
case Alignment.Center:
|
|
27
|
+
return 'center';
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const normalizeDescription = (value) => {
|
|
31
|
+
// description may be null or undefined, we return empty string
|
|
32
|
+
if (!value) {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
// empty description from quill is a paragraph with an empty line inside,
|
|
36
|
+
// we do not want to display this, so we return empty string
|
|
37
|
+
if (value === '<p><br></p>') {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
export const CaptionWrapper = ({ item, children, }) => {
|
|
43
|
+
const descriptionPlacement = item.settings?.descriptionPlacement ?? 'below';
|
|
44
|
+
const direction = descriptionPlacement === DescriptionPlacement.ABOVE
|
|
45
|
+
? 'column-reverse'
|
|
46
|
+
: 'column';
|
|
47
|
+
const alignment = item.settings?.alignment ??
|
|
48
|
+
getDefaultFileAlignmentSetting(item.extra ? getMimetype(item.extra) : undefined);
|
|
49
|
+
const alignItems = getAlignItemsFromAlignmentSetting(alignment);
|
|
50
|
+
const description = normalizeDescription(item.description);
|
|
51
|
+
return (_jsxs(Stack, { direction: direction, gap: 0.5, alignItems: alignItems, width: '100%', children: [children, _jsx(TextDisplay, { content: description })] }));
|
|
52
|
+
};
|
|
53
|
+
export function withCaption({ item, }) {
|
|
54
|
+
return (component) => {
|
|
55
|
+
return _jsx(CaptionWrapper, { item: item, children: component });
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export default withCaption;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UUID } from '@lnco-ai/sdk';
|
|
2
|
+
export type WithResizingProps = {
|
|
3
|
+
height: string | number;
|
|
4
|
+
component: JSX.Element;
|
|
5
|
+
memberId?: UUID;
|
|
6
|
+
itemId: UUID;
|
|
7
|
+
};
|
|
8
|
+
declare const withResizing: <P extends object>({ height, component, memberId, itemId, }: WithResizingProps) => ((props: P) => JSX.Element);
|
|
9
|
+
export default withResizing;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box } from '@mui/material';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { Rnd } from 'react-rnd';
|
|
5
|
+
import { getIframeResizeHeightCookie, setIframeResizeHeightCookie, } from '@lnco-ai/sdk';
|
|
6
|
+
import { IFRAME_MIN_HEIGHT } from '../constants.js';
|
|
7
|
+
import ResizingIcon from '../icons/ResizingIcon.js';
|
|
8
|
+
const resizeHandleStyles = {
|
|
9
|
+
resizeHandleComponent: {
|
|
10
|
+
height: '24px',
|
|
11
|
+
bottom: '-32px',
|
|
12
|
+
width: '23px',
|
|
13
|
+
marginRight: 'auto',
|
|
14
|
+
marginLeft: 'auto',
|
|
15
|
+
left: '0',
|
|
16
|
+
right: '0',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const withResizing = ({ height, component, memberId, itemId, }) => () => {
|
|
20
|
+
const [variableHeight, setVariableHeight] = useState(getIframeResizeHeightCookie({ memberId, itemId }) ?? height);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
setIframeResizeHeightCookie({ memberId, itemId }, variableHeight);
|
|
23
|
+
}, [variableHeight]);
|
|
24
|
+
return (_jsx(Box, { width: '100%', sx: {
|
|
25
|
+
paddingBottom: '35px',
|
|
26
|
+
WebkitUserSelect: 'none',
|
|
27
|
+
WebkitTouchCallout: 'none',
|
|
28
|
+
MozUserSelect: 'none',
|
|
29
|
+
msUserSelect: 'none',
|
|
30
|
+
userSelect: 'none',
|
|
31
|
+
}, children: _jsx(Rnd, { style: { position: 'relative' }, disableDragging: true, enableResizing: { bottom: true }, default: {
|
|
32
|
+
width: '100%',
|
|
33
|
+
height: variableHeight,
|
|
34
|
+
x: 0,
|
|
35
|
+
y: 0,
|
|
36
|
+
}, minHeight: IFRAME_MIN_HEIGHT, resizeHandleComponent: { bottom: _jsx(ResizingIcon, {}) }, resizeHandleStyles: {
|
|
37
|
+
bottom: resizeHandleStyles.resizeHandleComponent,
|
|
38
|
+
}, onResizeStop: (_e, _direction, ref) => {
|
|
39
|
+
setVariableHeight(ref.style.height);
|
|
40
|
+
}, children: component }) }));
|
|
41
|
+
};
|
|
42
|
+
export default withResizing;
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Direction, Theme } from '@mui/material';
|
|
2
|
+
import { Context } from '@lnco-ai/sdk';
|
|
3
|
+
export declare const PRIMARY_COLOR = "#000000";
|
|
4
|
+
export declare const SECONDARY_COLOR = "#FFFFFF";
|
|
5
|
+
/**
|
|
6
|
+
* Here we explicitly set primary and secondary text colors.
|
|
7
|
+
*
|
|
8
|
+
* These colors do not make use of transparency,
|
|
9
|
+
* as transparent colors do not work well with lucide icons because of overlapping paths.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_TEXT_PRIMARY_COLOR = "#313131";
|
|
12
|
+
export declare const DEFAULT_TEXT_SECONDARY_COLOR = "#71717A";
|
|
13
|
+
export declare const DEFAULT_TEXT_DISABLED_COLOR = "#c0c0c4";
|
|
14
|
+
export declare const DEFAULT_ACTIVE_ACTION_COLOR = "#777578";
|
|
15
|
+
/**
|
|
16
|
+
* Color used as a light version of the primary color for button and icon backgrounds.
|
|
17
|
+
* For example in card thumbnails.
|
|
18
|
+
*/
|
|
19
|
+
export declare const DEFAULT_LIGHT_PRIMARY_COLOR: {
|
|
20
|
+
readonly main: "#ebeaea";
|
|
21
|
+
readonly dark: "#cbcaca";
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Very light red color used as the default background color.
|
|
25
|
+
* Alternative to the pure white default
|
|
26
|
+
*/
|
|
27
|
+
export declare const DEFAULT_BACKGROUND_COLOR = "#fffefe";
|
|
28
|
+
export declare const AccentColors: {
|
|
29
|
+
[K in Context]: string;
|
|
30
|
+
};
|
|
31
|
+
declare module '@mui/material/styles' {
|
|
32
|
+
interface TypographyVariants {
|
|
33
|
+
display: React.CSSProperties;
|
|
34
|
+
label: React.CSSProperties;
|
|
35
|
+
note: React.CSSProperties;
|
|
36
|
+
}
|
|
37
|
+
interface TypographyVariantsOptions {
|
|
38
|
+
display?: React.CSSProperties;
|
|
39
|
+
label?: React.CSSProperties;
|
|
40
|
+
note?: React.CSSProperties;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
declare module '@mui/material/Typography' {
|
|
44
|
+
interface TypographyPropsVariantOverrides {
|
|
45
|
+
display: true;
|
|
46
|
+
label: true;
|
|
47
|
+
note: true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
declare module '@mui/material/styles' {
|
|
51
|
+
interface Palette {
|
|
52
|
+
builder: Palette['primary'];
|
|
53
|
+
player: Palette['primary'];
|
|
54
|
+
analytics: Palette['primary'];
|
|
55
|
+
library: Palette['primary'];
|
|
56
|
+
account: Palette['primary'];
|
|
57
|
+
auth: Palette['primary'];
|
|
58
|
+
}
|
|
59
|
+
interface PaletteOptions {
|
|
60
|
+
builder?: PaletteOptions['primary'];
|
|
61
|
+
player?: PaletteOptions['primary'];
|
|
62
|
+
analytics?: PaletteOptions['primary'];
|
|
63
|
+
library?: PaletteOptions['primary'];
|
|
64
|
+
account?: PaletteOptions['primary'];
|
|
65
|
+
auth?: PaletteOptions['primary'];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
declare module '@mui/material/Button' {
|
|
69
|
+
interface ButtonPropsColorOverrides {
|
|
70
|
+
builder: true;
|
|
71
|
+
player: true;
|
|
72
|
+
analytics: true;
|
|
73
|
+
library: true;
|
|
74
|
+
account: true;
|
|
75
|
+
auth: true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
declare module '@mui/material/IconButton' {
|
|
79
|
+
interface IconButtonPropsColorOverrides {
|
|
80
|
+
builder: true;
|
|
81
|
+
player: true;
|
|
82
|
+
analytics: true;
|
|
83
|
+
library: true;
|
|
84
|
+
account: true;
|
|
85
|
+
auth: true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
declare module '@mui/material/CircularProgress' {
|
|
89
|
+
interface CircularProgressPropsColorOverrides {
|
|
90
|
+
builder: true;
|
|
91
|
+
player: true;
|
|
92
|
+
analytics: true;
|
|
93
|
+
library: true;
|
|
94
|
+
account: true;
|
|
95
|
+
auth: true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
type GraaspThemeOptions = {
|
|
99
|
+
fontFamily?: string;
|
|
100
|
+
direction?: Direction;
|
|
101
|
+
};
|
|
102
|
+
export declare const createGraaspTheme: ({ fontFamily, direction, }: GraaspThemeOptions) => Theme;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated use buildTheme
|
|
105
|
+
*/
|
|
106
|
+
export declare const theme: Theme;
|
|
107
|
+
export declare const buildTheme: (direction?: Direction) => Theme;
|
|
108
|
+
export {};
|
package/dist/theme.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { createTheme, responsiveFontSizes, } from '@mui/material';
|
|
2
|
+
import { Context } from '@lnco-ai/sdk';
|
|
3
|
+
export const PRIMARY_COLOR = '#000000';
|
|
4
|
+
export const SECONDARY_COLOR = '#FFFFFF';
|
|
5
|
+
/**
|
|
6
|
+
* Here we explicitly set primary and secondary text colors.
|
|
7
|
+
*
|
|
8
|
+
* These colors do not make use of transparency,
|
|
9
|
+
* as transparent colors do not work well with lucide icons because of overlapping paths.
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_TEXT_PRIMARY_COLOR = '#313131';
|
|
12
|
+
export const DEFAULT_TEXT_SECONDARY_COLOR = '#71717A';
|
|
13
|
+
export const DEFAULT_TEXT_DISABLED_COLOR = '#c0c0c4';
|
|
14
|
+
export const DEFAULT_ACTIVE_ACTION_COLOR = '#777578';
|
|
15
|
+
/**
|
|
16
|
+
* Color used as a light version of the primary color for button and icon backgrounds.
|
|
17
|
+
* For example in card thumbnails.
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_LIGHT_PRIMARY_COLOR = {
|
|
20
|
+
main: '#ebeaea',
|
|
21
|
+
dark: '#cbcaca',
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Very light red color used as the default background color.
|
|
25
|
+
* Alternative to the pure white default
|
|
26
|
+
*/
|
|
27
|
+
export const DEFAULT_BACKGROUND_COLOR = '#fffefe';
|
|
28
|
+
export const AccentColors = {
|
|
29
|
+
[Context.Builder]: '#a3a3a3',
|
|
30
|
+
[Context.Player]: '#a3a3a3',
|
|
31
|
+
[Context.Analytics]: '#a3a3a3',
|
|
32
|
+
[Context.Account]: '#a3a3a3',
|
|
33
|
+
[Context.Library]: '#a3a3a3',
|
|
34
|
+
[Context.Auth]: PRIMARY_COLOR,
|
|
35
|
+
[Context.Unknown]: '#a3a3a3',
|
|
36
|
+
};
|
|
37
|
+
export const createGraaspTheme = ({ fontFamily, direction = 'ltr', }) => {
|
|
38
|
+
const baseTheme = createTheme({
|
|
39
|
+
direction,
|
|
40
|
+
palette: {
|
|
41
|
+
action: {
|
|
42
|
+
active: DEFAULT_ACTIVE_ACTION_COLOR,
|
|
43
|
+
},
|
|
44
|
+
text: {
|
|
45
|
+
primary: DEFAULT_TEXT_PRIMARY_COLOR,
|
|
46
|
+
secondary: DEFAULT_TEXT_SECONDARY_COLOR,
|
|
47
|
+
disabled: DEFAULT_TEXT_DISABLED_COLOR,
|
|
48
|
+
},
|
|
49
|
+
background: { default: DEFAULT_BACKGROUND_COLOR },
|
|
50
|
+
primary: {
|
|
51
|
+
main: PRIMARY_COLOR,
|
|
52
|
+
},
|
|
53
|
+
secondary: {
|
|
54
|
+
main: SECONDARY_COLOR,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
zIndex: {
|
|
58
|
+
drawer: 100,
|
|
59
|
+
},
|
|
60
|
+
components: {
|
|
61
|
+
MuiCssBaseline: {
|
|
62
|
+
styleOverrides: `
|
|
63
|
+
html {
|
|
64
|
+
scroll-behavior: smooth;
|
|
65
|
+
}
|
|
66
|
+
`,
|
|
67
|
+
},
|
|
68
|
+
MuiAvatar: {
|
|
69
|
+
styleOverrides: {
|
|
70
|
+
root: {
|
|
71
|
+
color: '#bcbcbc',
|
|
72
|
+
backgroundColor: 'white',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
MuiTypography: {
|
|
77
|
+
defaultProps: {
|
|
78
|
+
variantMapping: {
|
|
79
|
+
// Map the new variants to render a <p> by default
|
|
80
|
+
label: 'p',
|
|
81
|
+
note: 'p',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
MuiButton: {
|
|
86
|
+
styleOverrides: {
|
|
87
|
+
root: {
|
|
88
|
+
textTransform: 'capitalize',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
MuiTextField: {
|
|
93
|
+
styleOverrides: {
|
|
94
|
+
root: {
|
|
95
|
+
'& input': {
|
|
96
|
+
backgroundColor: 'white',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
MuiOutlinedInput: {
|
|
102
|
+
// outlined inputs should have the inside white
|
|
103
|
+
styleOverrides: {
|
|
104
|
+
root: {
|
|
105
|
+
backgroundColor: 'white',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
MuiSelect: {
|
|
110
|
+
styleOverrides: {
|
|
111
|
+
root: {
|
|
112
|
+
overflow: 'hidden',
|
|
113
|
+
backgroundColor: 'white',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
MuiTab: {
|
|
118
|
+
styleOverrides: {
|
|
119
|
+
root: {
|
|
120
|
+
textTransform: 'capitalize',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
MuiCard: {
|
|
125
|
+
styleOverrides: {
|
|
126
|
+
root: {
|
|
127
|
+
borderRadius: '8px',
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
typography: {
|
|
133
|
+
fontFamily: fontFamily ?? ['Nunito', 'Roboto', 'sans-serif'].join(','),
|
|
134
|
+
display: {
|
|
135
|
+
fontSize: '4.5rem',
|
|
136
|
+
fontWeight: 800,
|
|
137
|
+
},
|
|
138
|
+
h1: {
|
|
139
|
+
fontSize: '3.2rem',
|
|
140
|
+
fontWeight: 700,
|
|
141
|
+
},
|
|
142
|
+
h2: {
|
|
143
|
+
fontSize: '2rem',
|
|
144
|
+
fontWeight: 700,
|
|
145
|
+
},
|
|
146
|
+
h3: {
|
|
147
|
+
fontSize: '1.75rem',
|
|
148
|
+
fontWeight: 700,
|
|
149
|
+
},
|
|
150
|
+
h4: {
|
|
151
|
+
fontSize: '1.6rem',
|
|
152
|
+
},
|
|
153
|
+
h5: {
|
|
154
|
+
fontSize: '1.1rem',
|
|
155
|
+
fontWeight: 700,
|
|
156
|
+
},
|
|
157
|
+
h6: {
|
|
158
|
+
fontSize: '1.1rem',
|
|
159
|
+
},
|
|
160
|
+
body1: {
|
|
161
|
+
fontSize: '1rem',
|
|
162
|
+
},
|
|
163
|
+
button: {
|
|
164
|
+
fontSize: '1rem',
|
|
165
|
+
},
|
|
166
|
+
label: {
|
|
167
|
+
fontSize: '0.9rem',
|
|
168
|
+
fontWeight: 700,
|
|
169
|
+
},
|
|
170
|
+
note: {
|
|
171
|
+
fontSize: '0.9rem',
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
const augmentedColorTheme = createTheme(baseTheme, {
|
|
176
|
+
palette: Object.fromEntries(Object.entries(AccentColors).map(([platform, color]) => {
|
|
177
|
+
return [
|
|
178
|
+
platform,
|
|
179
|
+
baseTheme.palette.augmentColor({
|
|
180
|
+
color: {
|
|
181
|
+
main: color,
|
|
182
|
+
contrastText: '#fff',
|
|
183
|
+
},
|
|
184
|
+
name: platform,
|
|
185
|
+
}),
|
|
186
|
+
];
|
|
187
|
+
})),
|
|
188
|
+
});
|
|
189
|
+
return responsiveFontSizes(augmentedColorTheme, {
|
|
190
|
+
disableAlign: true,
|
|
191
|
+
factor: 2,
|
|
192
|
+
// allows to also convert non-standard typography styles like "display" that we added
|
|
193
|
+
variants: [
|
|
194
|
+
'display',
|
|
195
|
+
'h1',
|
|
196
|
+
'h2',
|
|
197
|
+
'h3',
|
|
198
|
+
'h4',
|
|
199
|
+
'h5',
|
|
200
|
+
'h6',
|
|
201
|
+
'body1',
|
|
202
|
+
'body2',
|
|
203
|
+
'caption',
|
|
204
|
+
'button',
|
|
205
|
+
'label',
|
|
206
|
+
'note',
|
|
207
|
+
],
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* @deprecated use buildTheme
|
|
212
|
+
*/
|
|
213
|
+
export const theme = createGraaspTheme({});
|
|
214
|
+
export const buildTheme = (direction = 'ltr') => createGraaspTheme({ direction });
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Direction } from '@mui/material';
|
|
2
|
+
import { Context, UnionOfConst } from '@lnco-ai/sdk';
|
|
3
|
+
export declare enum Variant {
|
|
4
|
+
TEXT = "text",
|
|
5
|
+
RECT = "rectangular",
|
|
6
|
+
CIRCLE = "circular"
|
|
7
|
+
}
|
|
8
|
+
export type TooltipPlacement = 'bottom-end' | 'bottom-start' | 'bottom' | 'left-end' | 'left-start' | 'left' | 'right-end' | 'right-start' | 'right' | 'top-end' | 'top-start' | 'top';
|
|
9
|
+
export declare const ColorVariants: {
|
|
10
|
+
readonly Inherit: "inherit";
|
|
11
|
+
readonly Primary: "primary";
|
|
12
|
+
readonly Secondary: "secondary";
|
|
13
|
+
readonly Error: "error";
|
|
14
|
+
readonly Info: "info";
|
|
15
|
+
readonly Success: "success";
|
|
16
|
+
readonly Warning: "warning";
|
|
17
|
+
readonly Builder: "builder";
|
|
18
|
+
readonly Player: "player";
|
|
19
|
+
readonly Library: "library";
|
|
20
|
+
readonly Analytics: "analytics";
|
|
21
|
+
readonly Auth: "auth";
|
|
22
|
+
};
|
|
23
|
+
export type ColorVariantsType = UnionOfConst<typeof ColorVariants>;
|
|
24
|
+
export type IconSizeVariant = 'small' | 'medium' | 'large';
|
|
25
|
+
export declare enum ActionButton {
|
|
26
|
+
ICON = "icon",
|
|
27
|
+
ICON_BUTTON = "iconButton",
|
|
28
|
+
MENU_ITEM = "menuItem"
|
|
29
|
+
}
|
|
30
|
+
export type ActionButtonVariant = ActionButton | `${ActionButton}`;
|
|
31
|
+
export type AllowedContext = Exclude<Context, Context.Unknown>;
|
|
32
|
+
export declare enum CCSharing {
|
|
33
|
+
YES = "yes",
|
|
34
|
+
NO = "no",
|
|
35
|
+
ALIKE = "alike"
|
|
36
|
+
}
|
|
37
|
+
export type CCSharingVariant = CCSharing | `${CCSharing}`;
|
|
38
|
+
export type I18nInstance = {
|
|
39
|
+
language: string;
|
|
40
|
+
t: (s: string) => string;
|
|
41
|
+
dir: (l: string) => Direction;
|
|
42
|
+
changeLanguage: (lang: string) => void;
|
|
43
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export var Variant;
|
|
2
|
+
(function (Variant) {
|
|
3
|
+
Variant["TEXT"] = "text";
|
|
4
|
+
Variant["RECT"] = "rectangular";
|
|
5
|
+
Variant["CIRCLE"] = "circular";
|
|
6
|
+
})(Variant || (Variant = {}));
|
|
7
|
+
export const ColorVariants = {
|
|
8
|
+
Inherit: 'inherit',
|
|
9
|
+
Primary: 'primary',
|
|
10
|
+
Secondary: 'secondary',
|
|
11
|
+
Error: 'error',
|
|
12
|
+
Info: 'info',
|
|
13
|
+
Success: 'success',
|
|
14
|
+
Warning: 'warning',
|
|
15
|
+
Builder: 'builder',
|
|
16
|
+
Player: 'player',
|
|
17
|
+
Library: 'library',
|
|
18
|
+
Analytics: 'analytics',
|
|
19
|
+
Auth: 'auth',
|
|
20
|
+
};
|
|
21
|
+
export var ActionButton;
|
|
22
|
+
(function (ActionButton) {
|
|
23
|
+
ActionButton["ICON"] = "icon";
|
|
24
|
+
ActionButton["ICON_BUTTON"] = "iconButton";
|
|
25
|
+
ActionButton["MENU_ITEM"] = "menuItem";
|
|
26
|
+
})(ActionButton || (ActionButton = {}));
|
|
27
|
+
export var CCSharing;
|
|
28
|
+
(function (CCSharing) {
|
|
29
|
+
CCSharing["YES"] = "yes";
|
|
30
|
+
CCSharing["NO"] = "no";
|
|
31
|
+
CCSharing["ALIKE"] = "alike";
|
|
32
|
+
})(CCSharing || (CCSharing = {}));
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { UploadFileButtonProps } from '../UploadFileButton/UploadFileButton.js';
|
|
2
|
+
export type FileDropperProps = {
|
|
3
|
+
id?: string;
|
|
4
|
+
/**
|
|
5
|
+
* Callback on files dropped
|
|
6
|
+
*/
|
|
7
|
+
onDrop?: (files: File[]) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Callback on files selected
|
|
10
|
+
*/
|
|
11
|
+
onChange: UploadFileButtonProps['onChange'];
|
|
12
|
+
/**
|
|
13
|
+
* Error to show
|
|
14
|
+
*/
|
|
15
|
+
error?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Smaller text to show, such as limits
|
|
18
|
+
*/
|
|
19
|
+
hints?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Text of the browsing button
|
|
22
|
+
*/
|
|
23
|
+
buttonText?: string;
|
|
24
|
+
/**
|
|
25
|
+
* additional buttons to display next to browse files
|
|
26
|
+
*/
|
|
27
|
+
buttons?: JSX.Element;
|
|
28
|
+
/**
|
|
29
|
+
* When true, allows many files to be selected when browsing
|
|
30
|
+
*/
|
|
31
|
+
multiple?: UploadFileButtonProps['multiple'];
|
|
32
|
+
/**
|
|
33
|
+
* Text displayed by default
|
|
34
|
+
*/
|
|
35
|
+
message?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Text displayed on drag enter
|
|
38
|
+
*/
|
|
39
|
+
releaseText?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Whether files are getting uploaded
|
|
42
|
+
*/
|
|
43
|
+
isLoading?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* progress of the upload
|
|
46
|
+
*/
|
|
47
|
+
uploadProgress?: number;
|
|
48
|
+
};
|
|
49
|
+
declare const FileDropper: (args: FileDropperProps) => JSX.Element | null;
|
|
50
|
+
export default FileDropper;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { CloudUploadIcon } from 'lucide-react';
|
|
3
|
+
import { Alert, Box, LinearProgress, Stack, Typography, useTheme, } from '@mui/material';
|
|
4
|
+
import { DndProvider, useDrop } from 'react-dnd';
|
|
5
|
+
import { HTML5Backend, NativeTypes } from 'react-dnd-html5-backend';
|
|
6
|
+
import { DEFAULT_LIGHT_PRIMARY_COLOR } from '../../theme.js';
|
|
7
|
+
import UploadFileButton from '../UploadFileButton/UploadFileButton.js';
|
|
8
|
+
const FileDropperComponent = ({ id, onDrop, onChange, error, hints, buttonText = 'Browse files', buttons, multiple, message = `Drag your files here to upload or`, releaseText = 'Release to drop', uploadProgress, isLoading = false, }) => {
|
|
9
|
+
const theme = useTheme();
|
|
10
|
+
const [{ canDrop, isOver }, drop] = useDrop({
|
|
11
|
+
accept: [NativeTypes.FILE],
|
|
12
|
+
drop: (e) => {
|
|
13
|
+
onDrop?.(e.files);
|
|
14
|
+
},
|
|
15
|
+
canDrop: () => {
|
|
16
|
+
return !isLoading;
|
|
17
|
+
},
|
|
18
|
+
collect: (monitor) => ({
|
|
19
|
+
isOver: monitor.isOver(),
|
|
20
|
+
canDrop: monitor.canDrop(),
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
const isActive = canDrop && isOver;
|
|
24
|
+
let bgColor = DEFAULT_LIGHT_PRIMARY_COLOR.main;
|
|
25
|
+
if (isActive) {
|
|
26
|
+
bgColor = DEFAULT_LIGHT_PRIMARY_COLOR.dark;
|
|
27
|
+
}
|
|
28
|
+
else if (!canDrop && isOver) {
|
|
29
|
+
bgColor = '#bababa';
|
|
30
|
+
}
|
|
31
|
+
return (_jsxs(Stack, { role: 'dropzone', id: id, height: '100%', width: '100%', justifyContent: 'center', alignItems: 'center', bgcolor: error ? '#ffbaba' : bgColor, borderRadius: 5, ref: drop, gap: 2, sx: {
|
|
32
|
+
borderStyle: 'dashed',
|
|
33
|
+
borderWidth: 3,
|
|
34
|
+
borderColor: error ? 'red' : 'lightgrey',
|
|
35
|
+
}, py: 4, boxSizing: 'border-box', children: [_jsx(CloudUploadIcon, { size: 80, color: error ? 'red' : theme.palette.primary.main }), isLoading ? (_jsxs(Box, { width: '100%', px: 5, children: [_jsx(LinearProgress, { variant: uploadProgress ? 'determinate' : 'indeterminate', color: 'primary', value: uploadProgress }), uploadProgress && (_jsxs(Typography, { textAlign: 'center', children: [uploadProgress, "%"] }))] })) : (_jsxs(_Fragment, { children: [_jsx(Typography, { variant: 'label', color: error ? 'error' : 'primary', children: isActive ? releaseText : message }), _jsxs(Stack, { direction: 'row', gap: 2, children: [buttonText && (_jsx(UploadFileButton, { icon: null, text: buttonText, onChange: onChange, size: 'small', multiple: multiple })), buttons] }), hints && _jsx(Typography, { variant: 'caption', children: hints }), error && _jsx(Alert, { severity: 'error', children: error })] }))] }));
|
|
36
|
+
};
|
|
37
|
+
const FileDropper = (args) => {
|
|
38
|
+
return (
|
|
39
|
+
// we need context={window} to use multiple times in the document
|
|
40
|
+
// https://github.com/react-dnd/react-dnd/issues/3257#issuecomment-1239254032
|
|
41
|
+
_jsx(DndProvider, { backend: HTML5Backend, context: window, children: _jsx(FileDropperComponent, { error: args.error, hints: args.hints, onChange: args.onChange, id: args.id, onDrop: args.onDrop, buttonText: args.buttonText, buttons: args.buttons, multiple: args.multiple, isLoading: args.isLoading, uploadProgress: args.uploadProgress, message: args.message }) }));
|
|
42
|
+
};
|
|
43
|
+
export default FileDropper;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ChangeEventHandler } from 'react';
|
|
2
|
+
import { GraaspButtonProps } from '../../buttons/Button/Button.js';
|
|
3
|
+
export type UploadFileButtonProps = {
|
|
4
|
+
id?: string;
|
|
5
|
+
/**
|
|
6
|
+
* callback when files are selected
|
|
7
|
+
*/
|
|
8
|
+
onChange: ChangeEventHandler<HTMLInputElement>;
|
|
9
|
+
/**
|
|
10
|
+
* whether files are uploading
|
|
11
|
+
*/
|
|
12
|
+
isLoading?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* text when loading
|
|
15
|
+
*/
|
|
16
|
+
loadingText?: string;
|
|
17
|
+
/**
|
|
18
|
+
* text when changes have been detected
|
|
19
|
+
*/
|
|
20
|
+
text?: string;
|
|
21
|
+
/**
|
|
22
|
+
* accept prop for browse button
|
|
23
|
+
*/
|
|
24
|
+
accept?: string;
|
|
25
|
+
/**
|
|
26
|
+
* whether multiple files can be selected
|
|
27
|
+
*/
|
|
28
|
+
multiple?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* button icon
|
|
31
|
+
*/
|
|
32
|
+
icon?: JSX.Element | null;
|
|
33
|
+
} & Pick<GraaspButtonProps, 'size' | 'color' | 'variant'>;
|
|
34
|
+
declare const UploadFileButton: ({ id, isLoading, onChange, loadingText, text, variant, accept, multiple, icon, size, color, }: UploadFileButtonProps) => JSX.Element;
|
|
35
|
+
export default UploadFileButton;
|