2019-10-21 15:12:45 +00:00
|
|
|
import React from "react";
|
2020-02-12 08:23:50 +00:00
|
|
|
import {
|
|
|
|
|
AnchorButton,
|
|
|
|
|
IButtonProps,
|
|
|
|
|
MaybeElement,
|
|
|
|
|
IconName,
|
|
|
|
|
} from "@blueprintjs/core";
|
2019-10-21 15:12:45 +00:00
|
|
|
import styled, { css } from "styled-components";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { ButtonStyle } from "widgets/ButtonWidget";
|
2020-01-15 04:49:36 +00:00
|
|
|
import { Theme, darkenHover, darkenActive } from "constants/DefaultTheme";
|
2019-11-28 07:08:39 +00:00
|
|
|
import _ from "lodash";
|
2020-01-03 13:40:31 +00:00
|
|
|
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
2019-10-21 15:12:45 +00:00
|
|
|
|
2019-11-13 07:34:59 +00:00
|
|
|
const getButtonColorStyles = (props: { theme: Theme } & ButtonStyleProps) => {
|
|
|
|
|
if (props.filled) return props.theme.colors.textOnDarkBG;
|
2019-11-28 07:08:39 +00:00
|
|
|
if (props.accent) {
|
|
|
|
|
if (props.accent === "secondary") {
|
2019-11-13 07:34:59 +00:00
|
|
|
return props.theme.colors.OXFORD_BLUE;
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
2019-11-28 07:08:39 +00:00
|
|
|
return props.theme.colors[props.accent];
|
2019-11-13 07:34:59 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const ButtonColorStyles = css<ButtonStyleProps>`
|
|
|
|
|
color: ${getButtonColorStyles};
|
|
|
|
|
svg {
|
|
|
|
|
fill: ${getButtonColorStyles};
|
|
|
|
|
}
|
2019-10-21 15:12:45 +00:00
|
|
|
`;
|
|
|
|
|
|
2019-11-28 07:08:39 +00:00
|
|
|
const ButtonWrapper = styled((props: ButtonStyleProps & IButtonProps) => (
|
|
|
|
|
<AnchorButton {..._.omit(props, ["accent", "filled"])} />
|
|
|
|
|
))<ButtonStyleProps>`
|
2019-10-21 15:12:45 +00:00
|
|
|
&& {
|
|
|
|
|
${ButtonColorStyles};
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
transition: background-color 0.2s;
|
|
|
|
|
background-color: ${props =>
|
2019-11-28 07:08:39 +00:00
|
|
|
props.filled && props.accent && props.theme.colors[props.accent]};
|
2019-10-21 15:12:45 +00:00
|
|
|
border: 1px solid
|
|
|
|
|
${props =>
|
2019-11-28 07:08:39 +00:00
|
|
|
props.accent
|
|
|
|
|
? props.theme.colors[props.accent]
|
2019-10-21 15:12:45 +00:00
|
|
|
: props.theme.colors.secondary};
|
|
|
|
|
border-radius: 4px;
|
2019-11-14 09:01:23 +00:00
|
|
|
font-weight: ${props => props.theme.fontWeights[2]};
|
|
|
|
|
font-family: "DM Sans";
|
2019-10-21 15:12:45 +00:00
|
|
|
outline: none;
|
2020-01-17 12:34:58 +00:00
|
|
|
&.bp3-button {
|
|
|
|
|
min-height: auto;
|
|
|
|
|
padding: 0px 10px;
|
|
|
|
|
}
|
2020-01-14 09:48:01 +00:00
|
|
|
&& .bp3-button-text {
|
2020-01-20 08:07:00 +00:00
|
|
|
max-width: 99%;
|
2020-01-17 12:34:58 +00:00
|
|
|
max-height: 100%;
|
2020-01-14 09:48:01 +00:00
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
2019-10-21 15:12:45 +00:00
|
|
|
&&:hover,
|
|
|
|
|
&&:focus {
|
|
|
|
|
${ButtonColorStyles};
|
|
|
|
|
background-color: ${props => {
|
|
|
|
|
if (!props.filled) return props.theme.colors.secondaryDarker;
|
2020-01-15 04:49:36 +00:00
|
|
|
if (props.accent !== "secondary" && props.accent) {
|
|
|
|
|
return darkenHover(props.theme.colors[props.accent]);
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
}};
|
|
|
|
|
border-color: ${props => {
|
|
|
|
|
if (!props.filled) return;
|
2020-01-15 04:49:36 +00:00
|
|
|
if (props.accent !== "secondary" && props.accent) {
|
|
|
|
|
return darkenHover(props.theme.colors[props.accent]);
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
&&:active {
|
|
|
|
|
${ButtonColorStyles};
|
|
|
|
|
background-color: ${props => {
|
|
|
|
|
if (!props.filled) return props.theme.colors.secondaryDarkest;
|
2020-01-15 04:49:36 +00:00
|
|
|
if (props.accent !== "secondary" && props.accent) {
|
|
|
|
|
return darkenActive(props.theme.colors[props.accent]);
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
}};
|
|
|
|
|
border-color: ${props => {
|
|
|
|
|
if (!props.filled) return;
|
2020-01-15 04:49:36 +00:00
|
|
|
if (props.accent !== "secondary" && props.accent) {
|
|
|
|
|
return darkenActive(props.theme.colors[props.accent]);
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
}};
|
|
|
|
|
}
|
2019-11-25 09:15:11 +00:00
|
|
|
&&.bp3-disabled {
|
|
|
|
|
background-color: #d0d7dd;
|
|
|
|
|
border: none;
|
|
|
|
|
}
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
`;
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
export type ButtonStyleName = "primary" | "secondary" | "error";
|
2019-10-21 15:12:45 +00:00
|
|
|
|
|
|
|
|
type ButtonStyleProps = {
|
2019-11-28 07:08:39 +00:00
|
|
|
accent?: ButtonStyleName;
|
2019-10-21 15:12:45 +00:00
|
|
|
filled?: boolean;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// To be used in any other part of the app
|
|
|
|
|
export const BaseButton = (props: IButtonProps & ButtonStyleProps) => {
|
|
|
|
|
return <ButtonWrapper {...props} />;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BaseButton.defaultProps = {
|
2019-11-28 07:08:39 +00:00
|
|
|
accent: "secondary",
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
disabled: false,
|
2019-10-21 15:12:45 +00:00
|
|
|
text: "Button Text",
|
|
|
|
|
minimal: true,
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-03 13:40:31 +00:00
|
|
|
interface ButtonContainerProps extends ComponentProps {
|
|
|
|
|
text?: string;
|
2019-10-21 15:12:45 +00:00
|
|
|
icon?: MaybeElement;
|
|
|
|
|
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
disabled?: boolean;
|
2019-10-31 05:28:11 +00:00
|
|
|
buttonStyle?: ButtonStyle;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2020-02-12 08:23:50 +00:00
|
|
|
rightIcon?: IconName | MaybeElement;
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-31 05:28:11 +00:00
|
|
|
const mapButtonStyleToStyleName = (buttonStyle?: ButtonStyle) => {
|
|
|
|
|
switch (buttonStyle) {
|
|
|
|
|
case "PRIMARY_BUTTON":
|
|
|
|
|
return "primary";
|
|
|
|
|
case "SECONDARY_BUTTON":
|
|
|
|
|
return "secondary";
|
|
|
|
|
case "DANGER_BUTTON":
|
|
|
|
|
return "error";
|
|
|
|
|
default:
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-21 15:12:45 +00:00
|
|
|
// To be used with the canvas
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
const ButtonContainer = (props: ButtonContainerProps & ButtonStyleProps) => {
|
2019-10-21 15:12:45 +00:00
|
|
|
return (
|
2019-11-13 07:00:25 +00:00
|
|
|
<BaseButton
|
2019-12-03 04:41:10 +00:00
|
|
|
className={props.isLoading ? "bp3-skeleton" : ""}
|
2019-11-13 07:00:25 +00:00
|
|
|
icon={props.icon}
|
2020-02-12 08:23:50 +00:00
|
|
|
rightIcon={props.rightIcon}
|
2019-11-13 07:00:25 +00:00
|
|
|
text={props.text}
|
2020-01-14 09:48:01 +00:00
|
|
|
filled={props.buttonStyle !== "SECONDARY_BUTTON"}
|
2019-11-28 07:08:39 +00:00
|
|
|
accent={mapButtonStyleToStyleName(props.buttonStyle)}
|
2019-11-13 07:00:25 +00:00
|
|
|
onClick={props.onClick}
|
|
|
|
|
disabled={props.disabled}
|
|
|
|
|
/>
|
2019-10-21 15:12:45 +00:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ButtonContainer;
|