2019-10-21 15:12:45 +00:00
|
|
|
import React from "react";
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
import { AnchorButton, IButtonProps, MaybeElement } from "@blueprintjs/core";
|
2019-10-21 15:12:45 +00:00
|
|
|
import styled, { css } from "styled-components";
|
2019-10-31 05:28:11 +00:00
|
|
|
import { TextComponentProps } from "./TextComponent";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { ButtonStyle } from "widgets/ButtonWidget";
|
|
|
|
|
import { Theme } from "constants/DefaultTheme";
|
2019-11-28 07:08:39 +00:00
|
|
|
import _ from "lodash";
|
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;
|
|
|
|
|
&&:hover,
|
|
|
|
|
&&:focus {
|
|
|
|
|
${ButtonColorStyles};
|
|
|
|
|
background-color: ${props => {
|
|
|
|
|
if (!props.filled) return props.theme.colors.secondaryDarker;
|
2019-11-28 07:08:39 +00:00
|
|
|
if (props.accent !== "secondary") {
|
|
|
|
|
return props.theme.colors[`${props.accent}Darker`];
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
}};
|
|
|
|
|
border-color: ${props => {
|
|
|
|
|
if (!props.filled) return;
|
2019-11-28 07:08:39 +00:00
|
|
|
if (props.accent !== "secondary") {
|
|
|
|
|
return props.theme.colors[`${props.accent}Darker`];
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
&&:active {
|
|
|
|
|
${ButtonColorStyles};
|
|
|
|
|
background-color: ${props => {
|
|
|
|
|
if (!props.filled) return props.theme.colors.secondaryDarkest;
|
2019-11-28 07:08:39 +00:00
|
|
|
if (props.accent !== "secondary") {
|
|
|
|
|
return props.theme.colors[`${props.accent}Darkest`];
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
}};
|
|
|
|
|
border-color: ${props => {
|
|
|
|
|
if (!props.filled) return;
|
2019-11-28 07:08:39 +00:00
|
|
|
if (props.accent !== "secondary") {
|
|
|
|
|
return props.theme.colors[`${props.accent}Darkest`];
|
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,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface ButtonContainerProps extends TextComponentProps {
|
|
|
|
|
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-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
|
|
|
|
|
icon={props.icon}
|
|
|
|
|
text={props.text}
|
|
|
|
|
filled={props.buttonStyle === "PRIMARY_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;
|