PromucFlow_constructor/app/client/src/components/ads/DialogComponent.tsx

188 lines
5.0 KiB
TypeScript
Raw Normal View History

2021-01-19 06:17:15 +00:00
import React, { ReactNode, useState, useEffect } from "react";
import styled from "styled-components";
import { Dialog, Classes } from "@blueprintjs/core";
import { Colors } from "constants/Colors";
import Icon, { IconName, IconSize } from "./Icon";
2021-01-19 06:17:15 +00:00
const StyledDialog = styled(Dialog)<{
setMaxWidth?: boolean;
width?: string;
maxHeight?: string;
2021-08-18 09:40:31 +00:00
maxWidth?: string;
2021-01-19 06:17:15 +00:00
showHeaderUnderline?: boolean;
}>`
&& {
border-radius: 0;
padding: 24px;
2021-01-19 06:17:15 +00:00
background: ${(props) => props.theme.colors.modal.bg};
${(props) => (props.maxHeight ? `max-height: ${props.maxHeight};` : "")}
width: ${(props) => props.width || "640px"};
${(props) => props.setMaxWidth && `width: 100vh;`}
2021-08-18 09:40:31 +00:00
${(props) => props.maxWidth && `max-width: ${props.maxWidth};`}
2021-01-19 06:17:15 +00:00
& .${Classes.DIALOG_HEADER} {
position: relative;
padding: 0px;
padding-bottom: 0;
2021-01-19 06:17:15 +00:00
background: ${(props) => props.theme.colors.modal.bg};
box-shadow: none;
.${Classes.ICON} {
color: ${(props) => props.theme.colors.modal.iconColor};
}
.${Classes.BUTTON}.${Classes.MINIMAL}:hover {
background-color: ${(props) => props.theme.colors.modal.bg};
}
}
.${Classes.HEADING} {
color: ${(props) => props.theme.colors.modal.headerText};
font-weight: ${(props) => props.theme.typography.h1.fontWeight};
font-size: ${(props) => props.theme.typography.h1.fontSize}px;
line-height: ${(props) => props.theme.typography.h1.lineHeight}px;
letter-spacing: ${(props) => props.theme.typography.h1.letterSpacing};
}
.${Classes.DIALOG_CLOSE_BUTTON} {
color: ${Colors.CHARCOAL};
min-width: 0;
padding: 0;
svg {
fill: ${Colors.CHARCOAL};
width: 24px;
height: 24px;
}
}
2021-01-19 06:17:15 +00:00
${(props) =>
props.showHeaderUnderline
? `
& .${Classes.DIALOG_HEADER}:after {
content: "";
width: calc(100% - 40px);
height: 1px;
position: absolute;
background: white;
left: 50%;
bottom: 0;
transform: translateX(-50%);
background-color: ${props.theme.colors.modal.separator};
}
.${Classes.HEADING} {
margin-bottom: ${props.theme.spaces[7]}px;
}
`
: ""}
& .${Classes.DIALOG_BODY} {
margin: 0;
margin-top: 24px;
2021-01-19 06:17:15 +00:00
overflow: auto;
}
& .${Classes.DIALOG_FOOTER_ACTIONS} {
display: block;
}
}
`;
const HeaderIconWrapper = styled.div<{ bgColor?: string }>`
padding: 5px;
border-radius: 50%;
margin-right: 10px;
background: ${(props) => props.bgColor || props.theme.colors.modal.iconBg};
`;
2021-01-19 06:17:15 +00:00
type DialogComponentProps = {
isOpen?: boolean;
canOutsideClickClose?: boolean;
title?: string;
headerIcon?: {
clickable?: boolean;
name: IconName;
fillColor?: string;
hoverColor?: string;
bgColor?: string;
};
trigger?: ReactNode;
2021-01-19 06:17:15 +00:00
setMaxWidth?: boolean;
children: ReactNode;
width?: string;
maxHeight?: string;
onOpening?: () => void;
2021-08-18 09:40:31 +00:00
onClose?: () => void;
setModalClose?: (close: boolean) => void;
2021-01-19 06:17:15 +00:00
triggerZIndex?: number;
showHeaderUnderline?: boolean;
getHeader?: () => ReactNode;
canEscapeKeyClose?: boolean;
className?: string;
2021-08-18 09:40:31 +00:00
maxWidth?: string;
2021-01-19 06:17:15 +00:00
};
export function DialogComponent(props: DialogComponentProps) {
2021-01-19 06:17:15 +00:00
const [isOpen, setIsOpen] = useState(!!props.isOpen);
2021-08-18 09:40:31 +00:00
const { onClose: onCloseProp, setModalClose } = props;
2021-01-19 06:17:15 +00:00
const onClose = () => {
setModalClose ? setModalClose(false) : null;
2021-01-19 06:17:15 +00:00
setIsOpen(false);
2021-08-18 09:40:31 +00:00
onCloseProp && onCloseProp();
2021-01-19 06:17:15 +00:00
};
useEffect(() => {
setIsOpen(!!props.isOpen);
}, [props.isOpen]);
const getHeader = props.getHeader;
const headerIcon = props.headerIcon ? (
<HeaderIconWrapper bgColor={props.headerIcon.bgColor}>
<Icon
clickable={props.headerIcon?.clickable}
fillColor={props.headerIcon.fillColor}
hoverFillColor={props.headerIcon.hoverColor}
name={props.headerIcon.name}
size={IconSize.XL}
/>
</HeaderIconWrapper>
) : null;
2021-01-19 06:17:15 +00:00
return (
<>
{props.trigger && (
feat: property pane docking (#7361) * add tailwindcss * docked property pane * uncomment a line * make entity explorer as drawer on unpin * remove unused imports * add pin state in reducer * add menu icon in header * fix widget sidebar * fix widgets sidebar * style property pane * update property pane css * update icons in property pane * update property pane header styles * update spacing * fix few ui issues * wip: preview mode * wip:preview mode * remove unused import * comments sidebar in app and edit mode * fix order of import * use selected state for property pane * update scrollbar style * add classes to sidebar and property pane * make widgets editor fluid * make widgets editor fluid and refactor logic * resize the widgets editor if explorer is pinned * add shortcut for preview mode * fix link for tabs in edit mode * zoom in/zoom out for 0.75 * fix chart widget + table widget crashing * allow zooming of canvas * fix weird canvas draw issue + update container for handling zoom * add actions for is panning * allow panning with grab cursor * reset panning + zooming when entering preview mode * add grabbing cursor when grabbing * only prevent default when space key is pressed * dont allow zoom in preview mode * remove unused imports * fix dont allow zoom in preview mode * fix ux of panning on space hit * make fluid as the default app layout * chart spec * fix dropdown_on change spec * fix add widget table and bind spec * remove draggable property pane spec * fix container spec * fix form widget spec * fix jest test * fix the function typo * remove clicking of close button for property pane in cypress tests * remove property pane actions test * fix drag and drop test failing * add cypress selector id to back button in property pane * fix toggle js spec * fix merge conflicts from new design system * editor header * fix product updates styles + widget card * remove all unused imports * fix dynamic layout spec * fix entity explorer tab rename test failing * fix table spec * fix bind tabletextpagination spec * fix js object spec * fix entity explorer rename issue * fix cypress test * fix cypress command wrong commit * fix tab spec * fix property pane copy tests * add zoom header * zoom levels * make property pane sidebar resizable * add multi select property pane * fix widget search bug * update property pane width in state on drag end * fix viewer header * fix editor header * update editor header + remove zooming * update small style * dont allow closing of explorer when resizing * fix jest test * fix dropdown widget jest test * preview test case wip * add entity explorer pinning tests + preview mode tests * add tooltip in layout control + add padding bottom in property pane view * incorporate aakash feedbacks * fix preview mode margin issue * remove panning code * fix cypress failing test * uncomment jest test * remove redundant code * fix maincontainer test * incorporate review feedbacks * incorporate aakash feedbacks * review feedbacks * incorporate review feedbacks * incorporate qa feedbacks * fix dynamic layout spec * updated test based on latest change * dsl updated * Updated dsl * Updated dsl * resize deselects widget issue. * fix canvas height issue * fix typo * incorporate qa feedbacks * incorporate qa feedbacks * incorporate qa feedbacks * update color for setting control for widget name * fix onboarding styles conflicts * Updated tests * fix application overflow issue * updated test method Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io>
2021-11-23 08:01:46 +00:00
<div
className="ads-dialog-trigger"
onClick={() => {
setIsOpen(true);
}}
style={{ zIndex: props.triggerZIndex }}
>
{props.trigger}
feat: property pane docking (#7361) * add tailwindcss * docked property pane * uncomment a line * make entity explorer as drawer on unpin * remove unused imports * add pin state in reducer * add menu icon in header * fix widget sidebar * fix widgets sidebar * style property pane * update property pane css * update icons in property pane * update property pane header styles * update spacing * fix few ui issues * wip: preview mode * wip:preview mode * remove unused import * comments sidebar in app and edit mode * fix order of import * use selected state for property pane * update scrollbar style * add classes to sidebar and property pane * make widgets editor fluid * make widgets editor fluid and refactor logic * resize the widgets editor if explorer is pinned * add shortcut for preview mode * fix link for tabs in edit mode * zoom in/zoom out for 0.75 * fix chart widget + table widget crashing * allow zooming of canvas * fix weird canvas draw issue + update container for handling zoom * add actions for is panning * allow panning with grab cursor * reset panning + zooming when entering preview mode * add grabbing cursor when grabbing * only prevent default when space key is pressed * dont allow zoom in preview mode * remove unused imports * fix dont allow zoom in preview mode * fix ux of panning on space hit * make fluid as the default app layout * chart spec * fix dropdown_on change spec * fix add widget table and bind spec * remove draggable property pane spec * fix container spec * fix form widget spec * fix jest test * fix the function typo * remove clicking of close button for property pane in cypress tests * remove property pane actions test * fix drag and drop test failing * add cypress selector id to back button in property pane * fix toggle js spec * fix merge conflicts from new design system * editor header * fix product updates styles + widget card * remove all unused imports * fix dynamic layout spec * fix entity explorer tab rename test failing * fix table spec * fix bind tabletextpagination spec * fix js object spec * fix entity explorer rename issue * fix cypress test * fix cypress command wrong commit * fix tab spec * fix property pane copy tests * add zoom header * zoom levels * make property pane sidebar resizable * add multi select property pane * fix widget search bug * update property pane width in state on drag end * fix viewer header * fix editor header * update editor header + remove zooming * update small style * dont allow closing of explorer when resizing * fix jest test * fix dropdown widget jest test * preview test case wip * add entity explorer pinning tests + preview mode tests * add tooltip in layout control + add padding bottom in property pane view * incorporate aakash feedbacks * fix preview mode margin issue * remove panning code * fix cypress failing test * uncomment jest test * remove redundant code * fix maincontainer test * incorporate review feedbacks * incorporate aakash feedbacks * review feedbacks * incorporate review feedbacks * incorporate qa feedbacks * fix dynamic layout spec * updated test based on latest change * dsl updated * Updated dsl * Updated dsl * resize deselects widget issue. * fix canvas height issue * fix typo * incorporate qa feedbacks * incorporate qa feedbacks * incorporate qa feedbacks * update color for setting control for widget name * fix onboarding styles conflicts * Updated tests * fix application overflow issue * updated test method Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io>
2021-11-23 08:01:46 +00:00
</div>
)}
2021-01-19 06:17:15 +00:00
<StyledDialog
canEscapeKeyClose={!!props.canEscapeKeyClose}
canOutsideClickClose={!!props.canOutsideClickClose}
className={props.className}
icon={headerIcon}
2021-01-19 06:17:15 +00:00
isOpen={isOpen}
maxHeight={props.maxHeight}
2021-08-18 09:40:31 +00:00
maxWidth={props.maxWidth}
onClose={onClose}
2021-01-19 06:17:15 +00:00
onOpening={props.onOpening}
setMaxWidth={props.setMaxWidth}
2021-01-19 06:17:15 +00:00
showHeaderUnderline={props.showHeaderUnderline}
title={props.title}
width={props.width}
2021-01-19 06:17:15 +00:00
>
{getHeader && getHeader()}
<div className={Classes.DIALOG_BODY}>{props.children}</div>
</StyledDialog>
</>
2021-01-19 06:17:15 +00:00
);
}
2021-01-19 06:17:15 +00:00
export default DialogComponent;