2022-03-13 17:21:04 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { ButtonVariant } from "components/constants";
|
|
|
|
|
import { RenderMode, RenderModes } from "constants/WidgetConstants";
|
|
|
|
|
import { buttonHoverActiveStyles } from "./utils";
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
We have this Bug in Firefox where we are unable to drag
|
|
|
|
|
buttons - https://bugzilla.mozilla.org/show_bug.cgi?id=568313
|
|
|
|
|
|
|
|
|
|
We found a solution here - https://stackoverflow.com/a/43888410
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
We are adding a wrapper in Canvas mode to the Button and once
|
|
|
|
|
we deploy it we remove the wrapper altogether.
|
2022-05-03 05:25:31 +00:00
|
|
|
Because we are adding a wrapper we also need to duplicate any
|
2022-03-13 17:21:04 +00:00
|
|
|
:hover, :active & :focus styles and pass onClick to the wrapper.
|
2022-05-03 05:25:31 +00:00
|
|
|
We could have checked for firefox browser using window.navigator
|
2022-03-13 17:21:04 +00:00
|
|
|
but we wanted our widget to be pure and have similar experience
|
|
|
|
|
in all the Browsers.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-04-04 10:42:51 +00:00
|
|
|
/*
|
|
|
|
|
For the Button Widget we don't remove the DragContainer
|
|
|
|
|
because of the Tooltip issue -
|
|
|
|
|
https://github.com/appsmithorg/appsmith/pull/12372
|
|
|
|
|
For this reason we pass the showInAllModes prop.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-03-13 17:21:04 +00:00
|
|
|
export type ButtonContainerProps = {
|
|
|
|
|
buttonColor?: string;
|
|
|
|
|
buttonVariant?: ButtonVariant;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
loading?: boolean;
|
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const ButtonContainer = styled.div<ButtonContainerProps>`
|
|
|
|
|
cursor: ${({ disabled }) => (disabled ? "not-allowed" : "pointer")};
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
|
|
& > button {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
position: relative;
|
|
|
|
|
&:after {
|
|
|
|
|
content: "";
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
position: absolute;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&:hover > button,
|
|
|
|
|
&:active > button {
|
|
|
|
|
${buttonHoverActiveStyles}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
type DragContainerProps = ButtonContainerProps & {
|
|
|
|
|
children?: React.ReactNode;
|
|
|
|
|
onClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
|
|
|
|
renderMode?: RenderMode;
|
2022-04-04 07:13:04 +00:00
|
|
|
showInAllModes?: boolean;
|
2022-03-13 17:21:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function DragContainer(props: DragContainerProps) {
|
2022-04-04 07:13:04 +00:00
|
|
|
if (props.renderMode === RenderModes.CANVAS || props.showInAllModes) {
|
2022-03-13 17:21:04 +00:00
|
|
|
return (
|
|
|
|
|
<ButtonContainer
|
|
|
|
|
buttonColor={props.buttonColor}
|
|
|
|
|
buttonVariant={props.buttonVariant}
|
|
|
|
|
disabled={props.disabled}
|
|
|
|
|
loading={props.loading}
|
2022-03-18 09:29:34 +00:00
|
|
|
onClick={(event) => {
|
|
|
|
|
if (props.disabled) return;
|
2022-05-03 05:25:31 +00:00
|
|
|
if (props.loading) return;
|
2022-03-18 09:29:34 +00:00
|
|
|
if (props.onClick) {
|
|
|
|
|
props.onClick(event);
|
|
|
|
|
}
|
|
|
|
|
}}
|
2022-03-13 17:21:04 +00:00
|
|
|
style={props.style}
|
|
|
|
|
>
|
|
|
|
|
{props.children}
|
|
|
|
|
</ButtonContainer>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
|
|
|
return <>{props.children}</>;
|
|
|
|
|
}
|