Web: Files: Tiles: Added quick buttons, refactoring

This commit is contained in:
Dmitry Kulak 2022-01-18 19:19:56 +03:00
parent 8e62da40a3
commit 6cb00cd777
7 changed files with 143 additions and 57 deletions

View File

@ -122,6 +122,7 @@ export default function withBadges(WrappedComponent) {
isAdmin, isAdmin,
isDesktopClient, isDesktopClient,
sectionWidth, sectionWidth,
viewAs,
} = this.props; } = this.props;
const { fileStatus, access } = item; const { fileStatus, access } = item;
@ -150,6 +151,7 @@ export default function withBadges(WrappedComponent) {
onBadgeClick={this.onBadgeClick} onBadgeClick={this.onBadgeClick}
setConvertDialogVisible={this.setConvertDialogVisible} setConvertDialogVisible={this.setConvertDialogVisible}
onFilesClick={onFilesClick} onFilesClick={onFilesClick}
viewAs={viewAs}
/> />
); );

View File

@ -25,6 +25,7 @@ const Badges = ({
onShowVersionHistory, onShowVersionHistory,
onBadgeClick, onBadgeClick,
setConvertDialogVisible, setConvertDialogVisible,
viewAs,
}) => { }) => {
const { id, locked, fileStatus, version, versionGroup, fileExst } = item; const { id, locked, fileStatus, version, versionGroup, fileExst } = item;
@ -48,9 +49,10 @@ const Badges = ({
const contentNewItems = newItems > 999 ? "999+" : newItems; const contentNewItems = newItems > 999 ? "999+" : newItems;
const tabletViewBadge = const tabletViewBadge =
(sectionWidth > 500 && sectionWidth <= 1024) || isTablet; viewAs !== "tile" &&
((sectionWidth > 500 && sectionWidth <= 1024) || isTablet);
const sizeBadge = tabletViewBadge ? "medium" : "small"; const sizeBadge = viewAs === "tile" || tabletViewBadge ? "medium" : "small";
const lineHeightBadge = tabletViewBadge ? "1.46" : "1.34"; const lineHeightBadge = tabletViewBadge ? "1.46" : "1.34";
@ -97,7 +99,7 @@ const Badges = ({
)} )}
{version > 1 && ( {version > 1 && (
<Badge <Badge
className="badge-version tablet-badge icons-group" className="badge-version badge-version-current tablet-badge icons-group"
backgroundColor="#A3A9AE" backgroundColor="#A3A9AE"
borderRadius="11px" borderRadius="11px"
color="#FFFFFF" color="#FFFFFF"

View File

@ -39,7 +39,8 @@ const QuickButtons = ({
: "/static/images/favorite.react.svg"; : "/static/images/favorite.react.svg";
const tabletViewQuickButton = const tabletViewQuickButton =
(sectionWidth > 500 && sectionWidth <= 1024) || isTablet; viewAs !== "tile" &&
((sectionWidth > 500 && sectionWidth <= 1024) || isTablet);
const sizeQuickButton = tabletViewQuickButton ? "medium" : "small"; const sizeQuickButton = tabletViewQuickButton ? "medium" : "small";
const displayShare = viewAs === "row" && (isMobile || sectionWidth <= 500); const displayShare = viewAs === "row" && (isMobile || sectionWidth <= 500);

View File

@ -11,10 +11,10 @@ import withFileActions from "../../../../../HOCs/withFileActions";
import withContextOptions from "../../../../../HOCs/withContextOptions"; import withContextOptions from "../../../../../HOCs/withContextOptions";
import withQuickButtons from "../../../../../HOCs/withQuickButtons"; import withQuickButtons from "../../../../../HOCs/withQuickButtons";
import ItemIcon from "../../../../../components/ItemIcon"; import ItemIcon from "../../../../../components/ItemIcon";
import withBadges from "../../../../../HOCs/withBadges";
const FilesTile = (props) => { const FileTile = (props) => {
const { const {
t,
item, item,
sectionWidth, sectionWidth,
dragging, dragging,
@ -27,17 +27,15 @@ const FilesTile = (props) => {
value, value,
displayShareButton, displayShareButton,
isPrivacy, isPrivacy,
//sharedButton,
contextOptionsProps, contextOptionsProps,
checkedProps, checkedProps,
//element,
getIcon, getIcon,
onFilesClick, onFilesClick,
onMouseClick, onMouseClick,
showShare,
isActive, isActive,
isEdit, isEdit,
quickButtonsComponent, quickButtonsComponent,
badgesComponent,
} = props; } = props;
const temporaryExtension = const temporaryExtension =
@ -92,6 +90,7 @@ const FilesTile = (props) => {
sectionWidth={sectionWidth} sectionWidth={sectionWidth}
onFilesClick={onFilesClick} onFilesClick={onFilesClick}
/> />
{badgesComponent}
</Tile> </Tile>
</DragAndDrop> </DragAndDrop>
</div> </div>
@ -102,9 +101,11 @@ export default inject(({ formatsStore }) => {
const { getIcon } = formatsStore.iconFormatsStore; const { getIcon } = formatsStore.iconFormatsStore;
return { getIcon }; return { getIcon };
})( })(
withTranslation("Home")( withTranslation(["Home", "VersionBadge"])(
withFileActions( withFileActions(
withContextOptions(withRouter(withQuickButtons(observer(FilesTile)))) withContextOptions(
withRouter(withBadges(withQuickButtons(observer(FileTile))))
)
) )
) )
); );

View File

@ -71,12 +71,7 @@ const SimpleFilesTileContent = styled(TileContent)`
} }
`; `;
const FilesTileContent = ({ const FilesTileContent = ({ item, titleWithoutExt, linkStyles }) => {
item,
titleWithoutExt,
linkStyles,
badgesComponent,
}) => {
const { fileExst, title } = item; const { fileExst, title } = item;
return ( return (
@ -96,8 +91,6 @@ const FilesTileContent = ({
> >
{titleWithoutExt} {titleWithoutExt}
</Link> </Link>
<div className="badges">{badgesComponent}</div>
</SimpleFilesTileContent> </SimpleFilesTileContent>
</> </>
); );

View File

@ -150,7 +150,7 @@ const StyledFileTileTop = styled.div`
.temporary-icon > .injected-svg { .temporary-icon > .injected-svg {
position: absolute; position: absolute;
width: 100%; width: 100%;
top: 25%; bottom: 16px;
} }
`; `;
@ -211,6 +211,105 @@ const StyledOptionButton = styled.div`
} }
`; `;
const badgesPosition = css`
position: absolute;
top: 14px;
left: 16px;
.badges {
display: grid;
grid-template-columns: repeat(3, fit-content(50px));
grid-gap: 20px;
.badge-new-version {
order: 1;
}
.badge-version-current {
order: 2;
}
.is-editing,
.can-convert {
order: 3;
top: 2px;
}
}
`;
const quickButtonsPosition = css`
position: absolute;
right: 20px;
top: 16px;
.badges {
display: grid;
grid-template-rows: repeat(3, 32px);
grid-gap: 4px;
}
`;
const badgeOutlineStyles = ({ top, right, left, width }) => css`
position: relative;
overflow: visible;
&::before {
z-index: -1;
content: "";
position: absolute;
top: ${top};
${right && `right: ${right}`};
${left && `left: ${left}`};
height: 32px;
width: ${width};
border-radius: 4px;
background: white;
}
// this fixes hover
&::after {
content: "";
position: absolute;
top: ${top};
${right && `right: ${right}`};
${left && `left: ${left}`};
height: 32px;
width: ${width};
}
`;
const StyledIcons = styled.div`
${(props) => props.isBadges && badgesPosition}
${(props) => props.isQuickButtons && quickButtonsPosition}
filter: drop-shadow(0px 12px 40px rgba(4, 15, 27, 0.12));
.badge {
${badgeOutlineStyles({
top: "-8px",
left: "-8px",
width: "32px",
})}
svg {
height: 16px;
width: 16px;
}
}
.badge-version {
${badgeOutlineStyles({
top: "-7px",
left: "-9px",
width: "calc(100% + 18px)",
})}
p {
font-size: 11px;
line-height: 16px;
}
}
`;
class Tile extends React.PureComponent { class Tile extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
@ -278,6 +377,7 @@ class Tile extends React.PureComponent {
isActive, isActive,
inProgress, inProgress,
isEdit, isEdit,
contentElement,
} = this.props; } = this.props;
const { isFolder, id, fileExst } = item; const { isFolder, id, fileExst } = item;
@ -291,6 +391,11 @@ class Tile extends React.PureComponent {
"element" "element"
); );
const renderContentElement = Object.prototype.hasOwnProperty.call(
this.props,
"contentElement"
);
const renderContext = const renderContext =
Object.prototype.hasOwnProperty.call(this.props, "contextOptions") && Object.prototype.hasOwnProperty.call(this.props, "contextOptions") &&
contextOptions.length > 0; contextOptions.length > 0;
@ -309,6 +414,9 @@ class Tile extends React.PureComponent {
}; };
const icon = this.getIconFile(); const icon = this.getIconFile();
const FilesTileContent = children[0];
const badges = children[1];
const quickButtons = contentElement;
return ( return (
<StyledTile <StyledTile
@ -355,7 +463,7 @@ class Tile extends React.PureComponent {
<StyledContent <StyledContent
isFolder={(isFolder && !fileExst) || (!fileExst && id === -1)} isFolder={(isFolder && !fileExst) || (!fileExst && id === -1)}
> >
{children} {FilesTileContent}
</StyledContent> </StyledContent>
<StyledOptionButton spacerWidth={contextButtonSpacerWidth}> <StyledOptionButton spacerWidth={contextButtonSpacerWidth}>
{renderContext ? ( {renderContext ? (
@ -379,6 +487,13 @@ class Tile extends React.PureComponent {
<StyledFileTileTop checked={checked} isActive={isActive}> <StyledFileTileTop checked={checked} isActive={isActive}>
{icon} {icon}
</StyledFileTileTop> </StyledFileTileTop>
<StyledIcons isBadges>{badges}</StyledIcons>
{renderContentElement && (
<StyledIcons isQuickButtons>{quickButtons}</StyledIcons>
)}
<StyledFileTileBottom> <StyledFileTileBottom>
{id !== -1 && !isEdit && ( {id !== -1 && !isEdit && (
<> <>
@ -406,7 +521,7 @@ class Tile extends React.PureComponent {
<StyledContent <StyledContent
isFolder={(isFolder && !fileExst) || (!fileExst && id === -1)} isFolder={(isFolder && !fileExst) || (!fileExst && id === -1)}
> >
{children} {FilesTileContent}
</StyledContent> </StyledContent>
<StyledOptionButton spacerWidth={contextButtonSpacerWidth}> <StyledOptionButton spacerWidth={contextButtonSpacerWidth}>
{renderContext ? ( {renderContext ? (
@ -434,7 +549,10 @@ class Tile extends React.PureComponent {
Tile.propTypes = { Tile.propTypes = {
checked: PropTypes.bool, checked: PropTypes.bool,
children: PropTypes.element, children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.element),
PropTypes.element,
]),
className: PropTypes.string, className: PropTypes.string,
contextButtonSpacerWidth: PropTypes.string, contextButtonSpacerWidth: PropTypes.string,
contextOptions: PropTypes.array, contextOptions: PropTypes.array,
@ -447,6 +565,7 @@ Tile.propTypes = {
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
viewAs: PropTypes.string, viewAs: PropTypes.string,
tileContextClick: PropTypes.func, tileContextClick: PropTypes.func,
contentElement: PropTypes.element,
}; };
Tile.defaultProps = { Tile.defaultProps = {

View File

@ -37,33 +37,6 @@ const MainContainer = styled.div`
} }
`; `;
const MainIcons = styled.div`
align-self: center;
white-space: nowrap;
.badges {
margin: 8px;
}
.additional-badges {
position: absolute;
top: 0;
left: 0;
display: flex;
flex-direction: row;
filter: drop-shadow(0px 12px 40px rgba(4, 15, 27, 0.12));
.icons-group {
margin-right: 4px;
background: #ffffff;
border-radius: 4px;
padding: 8px;
height: 16px;
border: none; // removes transparent border on version badge
}
}
`;
const TileContent = (props) => { const TileContent = (props) => {
const { children, id, className, style, onClick } = props; const { children, id, className, style, onClick } = props;
@ -75,14 +48,9 @@ const TileContent = (props) => {
onClick={onClick} onClick={onClick}
> >
<MainContainerWrapper <MainContainerWrapper
mainContainerWidth={ mainContainerWidth={children.props && children.props.containerWidth}
children[0].props && children[0].props.containerWidth
}
> >
<MainContainer className="row-main-container"> <MainContainer className="row-main-container">{children}</MainContainer>
{children[0]}
</MainContainer>
<MainIcons className="main-icons">{children[1]}</MainIcons>
</MainContainerWrapper> </MainContainerWrapper>
</StyledTileContent> </StyledTileContent>
); );