2020-09-15 15:01:07 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
const styled = require('styled-components').default;
|
|
|
|
const { space } = require('styled-system');
|
|
|
|
|
|
|
|
export enum ButtonLevel {
|
|
|
|
Primary = 'primary',
|
|
|
|
Secondary = 'secondary',
|
|
|
|
Tertiary = 'tertiary',
|
2021-01-12 14:28:55 +02:00
|
|
|
SidebarSecondary = 'sidebarSecondary',
|
2021-01-20 00:58:09 +02:00
|
|
|
Recommended = 'recommended',
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Props {
|
2020-11-12 21:29:22 +02:00
|
|
|
title?: string;
|
|
|
|
iconName?: string;
|
|
|
|
level?: ButtonLevel;
|
|
|
|
className?: string;
|
2020-11-13 19:09:28 +02:00
|
|
|
onClick?: Function;
|
2020-11-12 21:29:22 +02:00
|
|
|
color?: string;
|
|
|
|
iconAnimation?: string;
|
|
|
|
tooltip?: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
style?: any;
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const StyledTitle = styled.span`
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledButtonBase = styled.button`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
flex-direction: row;
|
2020-11-12 21:13:28 +02:00
|
|
|
height: ${(props: any) => `${props.theme.toolbarHeight}px`};
|
|
|
|
min-height: ${(props: any) => `${props.theme.toolbarHeight}px`};
|
|
|
|
max-height: ${(props: any) => `${props.theme.toolbarHeight}px`};
|
|
|
|
width: ${(props: any) => props.iconOnly ? `${props.theme.toolbarHeight}px` : 'auto'};
|
|
|
|
${(props: any) => props.iconOnly ? `min-width: ${props.theme.toolbarHeight}px;` : ''}
|
|
|
|
${(props: any) => !props.iconOnly ? 'min-width: 100px;' : ''}
|
|
|
|
${(props: any) => props.iconOnly ? `max-width: ${props.theme.toolbarHeight}px;` : ''}
|
2020-09-15 15:01:07 +02:00
|
|
|
box-sizing: border-box;
|
|
|
|
border-radius: 3px;
|
|
|
|
border-style: solid;
|
|
|
|
border-width: 1px;
|
2020-11-12 21:13:28 +02:00
|
|
|
font-size: ${(props: any) => props.theme.fontSize}px;
|
|
|
|
padding: 0 ${(props: any) => props.iconOnly ? 4 : 8}px;
|
2020-09-15 15:01:07 +02:00
|
|
|
justify-content: center;
|
2020-11-12 21:13:28 +02:00
|
|
|
opacity: ${(props: any) => props.disabled ? 0.5 : 1};
|
2020-09-15 15:01:07 +02:00
|
|
|
user-select: none;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledIcon = styled(styled.span(space))`
|
2020-11-12 21:13:28 +02:00
|
|
|
font-size: ${(props: any) => props.theme.toolbarIconSize}px;
|
|
|
|
${(props: any) => props.animation ? `animation: ${props.animation}` : ''};
|
2020-09-15 15:01:07 +02:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledButtonPrimary = styled(StyledButtonBase)`
|
|
|
|
border: none;
|
2020-11-12 21:13:28 +02:00
|
|
|
background-color: ${(props: any) => props.theme.backgroundColor5};
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2020-11-13 19:09:28 +02:00
|
|
|
${(props: any) => props.disabled} {
|
|
|
|
&:hover {
|
|
|
|
background-color: ${(props: any) => props.theme.backgroundColorHover5};
|
|
|
|
}
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2020-11-13 19:09:28 +02:00
|
|
|
&:active {
|
|
|
|
background-color: ${(props: any) => props.theme.backgroundColorActive5};
|
|
|
|
}
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
${StyledIcon} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.color5};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
${StyledTitle} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.color5};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledButtonSecondary = styled(StyledButtonBase)`
|
2020-11-12 21:13:28 +02:00
|
|
|
border: 1px solid ${(props: any) => props.theme.borderColor4};
|
|
|
|
background-color: ${(props: any) => props.theme.backgroundColor4};
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2020-11-13 19:09:28 +02:00
|
|
|
${(props: any) => props.disabled} {
|
|
|
|
&:hover {
|
|
|
|
background-color: ${(props: any) => props.theme.backgroundColorHover4};
|
|
|
|
}
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2020-11-13 19:09:28 +02:00
|
|
|
&:active {
|
|
|
|
background-color: ${(props: any) => props.theme.backgroundColorActive4};
|
|
|
|
}
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
${StyledIcon} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.color4};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
${StyledTitle} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.color4};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledButtonTertiary = styled(StyledButtonBase)`
|
2020-11-12 21:13:28 +02:00
|
|
|
border: 1px solid ${(props: any) => props.theme.color3};
|
|
|
|
background-color: ${(props: any) => props.theme.backgroundColor3};
|
2020-09-15 15:01:07 +02:00
|
|
|
|
|
|
|
&:hover {
|
2020-11-12 21:13:28 +02:00
|
|
|
background-color: ${(props: any) => props.theme.backgroundColorHoverDim3};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
2020-11-12 21:13:28 +02:00
|
|
|
background-color: ${(props: any) => props.theme.backgroundColorActive3};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
${StyledIcon} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.color};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
${StyledTitle} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.color};
|
2020-09-15 15:01:07 +02:00
|
|
|
opacity: 0.9;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2021-01-20 00:58:09 +02:00
|
|
|
const StyledButtonRecommended = styled(StyledButtonBase)`
|
|
|
|
border: 1px solid ${(props: any) => props.theme.borderColor4};
|
|
|
|
background-color: ${(props: any) => props.theme.warningBackgroundColor};
|
|
|
|
|
|
|
|
${StyledIcon} {
|
|
|
|
color: ${(props: any) => props.theme.color};
|
|
|
|
}
|
|
|
|
|
|
|
|
${StyledTitle} {
|
|
|
|
color: ${(props: any) => props.theme.color};
|
|
|
|
opacity: 0.9;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2021-01-12 14:28:55 +02:00
|
|
|
const StyledButtonSidebarSecondary = styled(StyledButtonBase)`
|
2020-09-15 15:01:07 +02:00
|
|
|
background: none;
|
2020-11-12 21:13:28 +02:00
|
|
|
border-color: ${(props: any) => props.theme.color2};
|
|
|
|
color: ${(props: any) => props.theme.color2};
|
2020-09-15 15:01:07 +02:00
|
|
|
|
|
|
|
&:hover {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.colorHover2};
|
|
|
|
border-color: ${(props: any) => props.theme.colorHover2};
|
2020-09-15 15:01:07 +02:00
|
|
|
background: none;
|
|
|
|
|
|
|
|
${StyledTitle} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.colorHover2};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
${StyledIcon} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.colorHover2};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.colorActive2};
|
|
|
|
border-color: ${(props: any) => props.theme.colorActive2};
|
2020-09-15 15:01:07 +02:00
|
|
|
background: none;
|
|
|
|
|
|
|
|
${StyledTitle} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.colorActive2};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
${StyledIcon} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.colorActive2};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
${StyledTitle} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.color2};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
${StyledIcon} {
|
2020-11-12 21:13:28 +02:00
|
|
|
color: ${(props: any) => props.theme.color2};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function buttonClass(level: ButtonLevel) {
|
2020-09-15 15:01:07 +02:00
|
|
|
if (level === ButtonLevel.Primary) return StyledButtonPrimary;
|
|
|
|
if (level === ButtonLevel.Tertiary) return StyledButtonTertiary;
|
2021-01-12 14:28:55 +02:00
|
|
|
if (level === ButtonLevel.SidebarSecondary) return StyledButtonSidebarSecondary;
|
2021-01-20 00:58:09 +02:00
|
|
|
if (level === ButtonLevel.Recommended) return StyledButtonRecommended;
|
2020-09-15 15:01:07 +02:00
|
|
|
return StyledButtonSecondary;
|
|
|
|
}
|
|
|
|
|
2021-01-20 00:58:09 +02:00
|
|
|
function Button(props: Props) {
|
2020-09-15 15:01:07 +02:00
|
|
|
const iconOnly = props.iconName && !props.title;
|
|
|
|
|
|
|
|
const StyledButton = buttonClass(props.level);
|
|
|
|
|
|
|
|
function renderIcon() {
|
|
|
|
if (!props.iconName) return null;
|
|
|
|
return <StyledIcon animation={props.iconAnimation} mr={iconOnly ? '0' : '6px'} color={props.color} className={props.iconName}/>;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderTitle() {
|
|
|
|
if (!props.title) return null;
|
2021-01-23 17:51:19 +02:00
|
|
|
return <StyledTitle color={props.color}>{props.title}</StyledTitle>;
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onClick() {
|
|
|
|
if (props.disabled) return;
|
|
|
|
props.onClick();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StyledButton style={props.style} disabled={props.disabled} title={props.tooltip} className={props.className} iconOnly={iconOnly} onClick={onClick}>
|
|
|
|
{renderIcon()}
|
|
|
|
{renderTitle()}
|
|
|
|
</StyledButton>
|
|
|
|
);
|
|
|
|
}
|
2021-01-20 00:58:09 +02:00
|
|
|
|
|
|
|
export default styled(Button)`${space}`;
|