2021-11-11 06:41:05 +00:00
|
|
|
import React from "react";
|
2022-02-24 08:21:45 +00:00
|
|
|
import { sortBy, uniqueId } from "lodash";
|
2021-12-08 13:11:13 +00:00
|
|
|
import {
|
|
|
|
|
Alignment,
|
|
|
|
|
Icon,
|
|
|
|
|
Menu,
|
|
|
|
|
MenuItem,
|
|
|
|
|
Classes as CoreClass,
|
|
|
|
|
} from "@blueprintjs/core";
|
2021-11-11 06:41:05 +00:00
|
|
|
import { Classes, Popover2 } from "@blueprintjs/popover2";
|
|
|
|
|
import { IconName } from "@blueprintjs/icons";
|
|
|
|
|
import tinycolor from "tinycolor2";
|
|
|
|
|
import { darkenActive, darkenHover } from "constants/DefaultTheme";
|
|
|
|
|
import {
|
|
|
|
|
ButtonBoxShadow,
|
|
|
|
|
ButtonBoxShadowTypes,
|
|
|
|
|
ButtonBorderRadius,
|
|
|
|
|
ButtonBorderRadiusTypes,
|
|
|
|
|
ButtonStyleType,
|
|
|
|
|
ButtonVariant,
|
|
|
|
|
ButtonVariantTypes,
|
2021-12-08 13:11:13 +00:00
|
|
|
ButtonPlacement,
|
2021-11-11 06:41:05 +00:00
|
|
|
} from "components/constants";
|
|
|
|
|
import { ThemeProp } from "components/ads/common";
|
|
|
|
|
import styled, { createGlobalStyle } from "styled-components";
|
|
|
|
|
import { Colors } from "constants/Colors";
|
|
|
|
|
import {
|
|
|
|
|
getCustomBackgroundColor,
|
|
|
|
|
getCustomBorderColor,
|
|
|
|
|
getCustomTextColor,
|
2021-12-08 13:11:13 +00:00
|
|
|
getCustomJustifyContent,
|
2022-02-24 08:21:45 +00:00
|
|
|
WidgetContainerDiff,
|
2021-11-11 06:41:05 +00:00
|
|
|
} from "widgets/WidgetUtils";
|
2022-03-13 17:21:04 +00:00
|
|
|
import { RenderMode } from "constants/WidgetConstants";
|
|
|
|
|
import { DragContainer } from "widgets/ButtonWidget/component/DragContainer";
|
|
|
|
|
import { buttonHoverActiveStyles } from "../../ButtonWidget/component/utils";
|
2021-11-11 06:41:05 +00:00
|
|
|
|
|
|
|
|
interface WrapperStyleProps {
|
|
|
|
|
isHorizontal: boolean;
|
|
|
|
|
borderRadius?: ButtonBorderRadius;
|
|
|
|
|
boxShadow?: ButtonBoxShadow;
|
|
|
|
|
boxShadowColor?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ButtonGroupWrapper = styled.div<ThemeProp & WrapperStyleProps>`
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
position: relative;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: stretch;
|
|
|
|
|
align-items: stretch;
|
|
|
|
|
overflow: hidden;
|
2021-12-02 08:45:46 +00:00
|
|
|
|
2021-11-11 06:41:05 +00:00
|
|
|
${(props) =>
|
|
|
|
|
props.isHorizontal ? "flex-direction: row" : "flex-direction: column"};
|
|
|
|
|
|
|
|
|
|
border-radius: ${({ borderRadius }) =>
|
|
|
|
|
borderRadius === ButtonBorderRadiusTypes.ROUNDED
|
|
|
|
|
? "8px"
|
|
|
|
|
: borderRadius === ButtonBorderRadiusTypes.CIRCLE
|
|
|
|
|
? "32px"
|
|
|
|
|
: "0px"};
|
|
|
|
|
|
|
|
|
|
box-shadow: ${({ boxShadow, boxShadowColor, theme }) =>
|
|
|
|
|
boxShadow === ButtonBoxShadowTypes.VARIANT1
|
|
|
|
|
? `0px 0px 4px 3px ${boxShadowColor ||
|
|
|
|
|
theme.colors.button.boxShadow.default.variant1}`
|
|
|
|
|
: boxShadow === ButtonBoxShadowTypes.VARIANT2
|
|
|
|
|
? `3px 3px 4px ${boxShadowColor ||
|
|
|
|
|
theme.colors.button.boxShadow.default.variant2}`
|
|
|
|
|
: boxShadow === ButtonBoxShadowTypes.VARIANT3
|
|
|
|
|
? `0px 1px 3px ${boxShadowColor ||
|
|
|
|
|
theme.colors.button.boxShadow.default.variant3}`
|
|
|
|
|
: boxShadow === ButtonBoxShadowTypes.VARIANT4
|
|
|
|
|
? `2px 2px 0px ${boxShadowColor ||
|
|
|
|
|
theme.colors.button.boxShadow.default.variant4}`
|
|
|
|
|
: boxShadow === ButtonBoxShadowTypes.VARIANT5
|
|
|
|
|
? `-2px -2px 0px ${boxShadowColor ||
|
|
|
|
|
theme.colors.button.boxShadow.default.variant5}`
|
|
|
|
|
: "none"} !important;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const MenuButtonWrapper = styled.div`
|
|
|
|
|
flex: 1 1 auto;
|
|
|
|
|
|
2022-03-13 17:21:04 +00:00
|
|
|
& > .${Classes.POPOVER2_TARGET} > button {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-11 06:41:05 +00:00
|
|
|
& > .${Classes.POPOVER2_TARGET} {
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2022-02-24 08:21:45 +00:00
|
|
|
const PopoverStyles = createGlobalStyle<{
|
|
|
|
|
parentWidth: number;
|
|
|
|
|
menuDropDownWidth: number;
|
|
|
|
|
id: string;
|
|
|
|
|
}>`
|
2021-11-11 06:41:05 +00:00
|
|
|
.menu-button-popover > .${Classes.POPOVER2_CONTENT} {
|
|
|
|
|
background: none;
|
|
|
|
|
}
|
2022-02-24 08:21:45 +00:00
|
|
|
${({ id, menuDropDownWidth, parentWidth }) => `
|
|
|
|
|
.menu-button-width-${id} {
|
|
|
|
|
|
|
|
|
|
max-width: ${
|
|
|
|
|
menuDropDownWidth > parentWidth
|
|
|
|
|
? `${menuDropDownWidth}px`
|
|
|
|
|
: `${parentWidth}px`
|
|
|
|
|
} !important;
|
|
|
|
|
min-width: ${
|
|
|
|
|
parentWidth > menuDropDownWidth ? parentWidth : menuDropDownWidth
|
|
|
|
|
}px !important;
|
|
|
|
|
}
|
|
|
|
|
`}
|
2021-11-11 06:41:05 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
interface ButtonStyleProps {
|
|
|
|
|
isHorizontal: boolean;
|
|
|
|
|
borderRadius?: ButtonBorderRadius;
|
|
|
|
|
borderRadOnStart: boolean;
|
|
|
|
|
borderRadOnEnd: boolean;
|
|
|
|
|
buttonVariant?: ButtonVariant; // solid | outline | ghost
|
|
|
|
|
buttonColor?: string;
|
|
|
|
|
iconAlign?: string;
|
2021-12-08 13:11:13 +00:00
|
|
|
placement?: ButtonPlacement;
|
2021-11-11 06:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-13 17:21:04 +00:00
|
|
|
/*
|
|
|
|
|
Don't use buttonHoverActiveStyles in a nested function it won't work -
|
|
|
|
|
|
|
|
|
|
const buttonHoverActiveStyles = css ``
|
|
|
|
|
|
|
|
|
|
const Button = styled.button`
|
|
|
|
|
// won't work
|
|
|
|
|
${({ buttonColor, theme }) => {
|
|
|
|
|
&:hover, &:active {
|
|
|
|
|
${buttonHoverActiveStyles}
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
// will work
|
|
|
|
|
&:hover, &:active {
|
|
|
|
|
${buttonHoverActiveStyles}
|
|
|
|
|
}`
|
|
|
|
|
*/
|
|
|
|
|
|
2021-11-11 06:41:05 +00:00
|
|
|
const StyledButton = styled.button<ThemeProp & ButtonStyleProps>`
|
|
|
|
|
flex: 1 1 auto;
|
|
|
|
|
display: flex;
|
2021-12-08 13:11:13 +00:00
|
|
|
justify-content: stretch;
|
2021-11-11 06:41:05 +00:00
|
|
|
align-items: center;
|
2021-12-08 13:11:13 +00:00
|
|
|
padding: 0px 10px;
|
2021-11-11 06:41:05 +00:00
|
|
|
|
2022-03-13 17:21:04 +00:00
|
|
|
&:hover,
|
|
|
|
|
&:active {
|
|
|
|
|
${buttonHoverActiveStyles}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-11 06:41:05 +00:00
|
|
|
${({
|
|
|
|
|
borderRadius,
|
|
|
|
|
borderRadOnEnd,
|
|
|
|
|
borderRadOnStart,
|
|
|
|
|
buttonColor,
|
|
|
|
|
buttonVariant,
|
2021-12-14 07:55:30 +00:00
|
|
|
iconAlign,
|
2021-11-11 06:41:05 +00:00
|
|
|
isHorizontal,
|
|
|
|
|
theme,
|
|
|
|
|
}) => `
|
|
|
|
|
& {
|
|
|
|
|
background: ${
|
|
|
|
|
getCustomBackgroundColor(buttonVariant, buttonColor) !== "none"
|
|
|
|
|
? getCustomBackgroundColor(buttonVariant, buttonColor)
|
|
|
|
|
: buttonVariant === ButtonVariantTypes.PRIMARY
|
|
|
|
|
? theme.colors.button.primary.primary.bgColor
|
|
|
|
|
: "none"
|
|
|
|
|
} !important;
|
2021-12-14 07:55:30 +00:00
|
|
|
flex-direction : ${iconAlign === "right" ? "row-reverse" : "row"};
|
|
|
|
|
.bp3-icon {
|
|
|
|
|
${iconAlign === "right" ? "margin-left: 10px" : "margin-right: 10px"};
|
|
|
|
|
}
|
2021-11-11 06:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
border: ${
|
|
|
|
|
getCustomBorderColor(buttonVariant, buttonColor) !== "none"
|
|
|
|
|
? `1px solid ${getCustomBorderColor(buttonVariant, buttonColor)}`
|
|
|
|
|
: buttonVariant === ButtonVariantTypes.SECONDARY
|
|
|
|
|
? `1px solid ${theme.colors.button.primary.secondary.borderColor}`
|
|
|
|
|
: "none"
|
|
|
|
|
} ${buttonVariant === ButtonVariantTypes.PRIMARY ? "" : "!important"};
|
|
|
|
|
|
|
|
|
|
${
|
|
|
|
|
isHorizontal
|
|
|
|
|
? buttonVariant === ButtonVariantTypes.PRIMARY
|
|
|
|
|
? borderRadOnEnd
|
|
|
|
|
? ""
|
|
|
|
|
: `
|
|
|
|
|
border-right: 1px solid ${getCustomTextColor(theme, buttonColor)};
|
|
|
|
|
`
|
|
|
|
|
: ""
|
|
|
|
|
: buttonVariant === ButtonVariantTypes.PRIMARY
|
|
|
|
|
? borderRadOnEnd
|
|
|
|
|
? ""
|
|
|
|
|
: `
|
|
|
|
|
border-bottom: 1px solid ${getCustomTextColor(theme, buttonColor)};
|
|
|
|
|
`
|
|
|
|
|
: ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
border-radius: ${
|
|
|
|
|
borderRadius === ButtonBorderRadiusTypes.ROUNDED
|
|
|
|
|
? borderRadOnStart // first button
|
|
|
|
|
? isHorizontal
|
|
|
|
|
? "8px 0px 0px 8px"
|
|
|
|
|
: "8px 8px 0px 0px"
|
|
|
|
|
: borderRadOnEnd // last button
|
|
|
|
|
? isHorizontal
|
|
|
|
|
? "0px 8px 8px 0px"
|
|
|
|
|
: "0px 0px 8px 8px"
|
|
|
|
|
: "0px"
|
|
|
|
|
: borderRadius === ButtonBorderRadiusTypes.CIRCLE
|
|
|
|
|
? borderRadOnStart // first button
|
|
|
|
|
? isHorizontal
|
|
|
|
|
? "32px 0px 0px 32px"
|
|
|
|
|
: "32px 32px 0px 0px"
|
|
|
|
|
: borderRadOnEnd // last button
|
|
|
|
|
? isHorizontal
|
|
|
|
|
? "0px 32px 32px 0px"
|
|
|
|
|
: "0px 0px 32px 32px"
|
|
|
|
|
: "0px"
|
|
|
|
|
: "0px"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
& span {
|
|
|
|
|
color: ${
|
|
|
|
|
buttonVariant === ButtonVariantTypes.PRIMARY
|
|
|
|
|
? getCustomTextColor(theme, buttonColor)
|
|
|
|
|
: getCustomBackgroundColor(ButtonVariantTypes.PRIMARY, buttonColor)
|
|
|
|
|
} !important;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-13 17:21:04 +00:00
|
|
|
&:disabled {
|
|
|
|
|
cursor: not-allowed;
|
|
|
|
|
border: 1px solid ${Colors.ALTO2} !important;
|
|
|
|
|
background: ${theme.colors.button.disabled.bgColor} !important;
|
|
|
|
|
span {
|
|
|
|
|
color: ${theme.colors.button.disabled.textColor} !important;
|
2021-11-11 06:41:05 +00:00
|
|
|
}
|
2022-03-13 17:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
2021-11-11 06:41:05 +00:00
|
|
|
`}
|
|
|
|
|
`;
|
|
|
|
|
|
2021-12-08 13:11:13 +00:00
|
|
|
const StyledButtonContent = styled.div<{
|
|
|
|
|
iconAlign: string;
|
|
|
|
|
placement?: ButtonPlacement;
|
|
|
|
|
}>`
|
|
|
|
|
flex: 1;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: ${({ placement }) => getCustomJustifyContent(placement)};
|
|
|
|
|
flex-direction: ${({ iconAlign }) =>
|
|
|
|
|
iconAlign === Alignment.RIGHT ? "row-reverse" : "row"};
|
2021-11-11 06:41:05 +00:00
|
|
|
& .bp3-icon {
|
|
|
|
|
${({ iconAlign }) =>
|
|
|
|
|
iconAlign === "right" ? "margin-left: 10px" : "margin-right: 10px"};
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export interface BaseStyleProps {
|
|
|
|
|
backgroundColor?: string;
|
|
|
|
|
borderRadius?: ButtonBorderRadius;
|
|
|
|
|
boxShadow?: ButtonBoxShadow;
|
|
|
|
|
boxShadowColor?: string;
|
|
|
|
|
buttonColor?: string;
|
|
|
|
|
buttonStyle?: ButtonStyleType;
|
|
|
|
|
buttonVariant?: ButtonVariant;
|
|
|
|
|
textColor?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BaseMenuItem = styled(MenuItem)<ThemeProp & BaseStyleProps>`
|
|
|
|
|
padding: 8px 10px !important;
|
|
|
|
|
${({ backgroundColor, theme }) =>
|
|
|
|
|
backgroundColor
|
|
|
|
|
? `
|
|
|
|
|
background-color: ${backgroundColor} !important;
|
|
|
|
|
&:hover {
|
|
|
|
|
background-color: ${darkenHover(backgroundColor)} !important;
|
|
|
|
|
}
|
|
|
|
|
&:active {
|
|
|
|
|
background-color: ${darkenActive(backgroundColor)} !important;
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
: `
|
|
|
|
|
background: none !important
|
|
|
|
|
&:hover {
|
|
|
|
|
background-color: ${tinycolor(
|
|
|
|
|
theme.colors.button.primary.primary.textColor,
|
|
|
|
|
)
|
|
|
|
|
.darken()
|
|
|
|
|
.toString()} !important;
|
|
|
|
|
}
|
|
|
|
|
&:active {
|
|
|
|
|
background-color: ${tinycolor(
|
|
|
|
|
theme.colors.button.primary.primary.textColor,
|
|
|
|
|
)
|
|
|
|
|
.darken()
|
|
|
|
|
.toString()} !important;
|
|
|
|
|
}
|
|
|
|
|
`}
|
|
|
|
|
${({ textColor }) =>
|
|
|
|
|
textColor &&
|
|
|
|
|
`
|
|
|
|
|
color: ${textColor} !important;
|
|
|
|
|
`}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledMenu = styled(Menu)`
|
|
|
|
|
padding: 0;
|
2022-02-24 08:21:45 +00:00
|
|
|
min-width: 0px;
|
2021-11-11 06:41:05 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
interface PopoverContentProps {
|
|
|
|
|
menuItems: Record<
|
|
|
|
|
string,
|
|
|
|
|
{
|
|
|
|
|
widgetId: string;
|
|
|
|
|
id: string;
|
|
|
|
|
index: number;
|
|
|
|
|
isVisible?: boolean;
|
|
|
|
|
isDisabled?: boolean;
|
|
|
|
|
label?: string;
|
|
|
|
|
backgroundColor?: string;
|
|
|
|
|
textColor?: string;
|
|
|
|
|
iconName?: IconName;
|
|
|
|
|
iconColor?: string;
|
|
|
|
|
iconAlign?: Alignment;
|
|
|
|
|
onClick?: string;
|
|
|
|
|
}
|
|
|
|
|
>;
|
2022-03-13 17:21:04 +00:00
|
|
|
onItemClicked: (onClick: string | undefined) => void;
|
2021-11-11 06:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function PopoverContent(props: PopoverContentProps) {
|
|
|
|
|
const { menuItems, onItemClicked } = props;
|
|
|
|
|
|
|
|
|
|
let items = Object.keys(menuItems)
|
|
|
|
|
.map((itemKey) => menuItems[itemKey])
|
|
|
|
|
.filter((item) => item.isVisible === true);
|
|
|
|
|
// sort btns by index
|
|
|
|
|
items = sortBy(items, ["index"]);
|
|
|
|
|
|
|
|
|
|
const listItems = items.map((menuItem) => {
|
|
|
|
|
const {
|
|
|
|
|
backgroundColor,
|
|
|
|
|
iconAlign,
|
|
|
|
|
iconColor,
|
|
|
|
|
iconName,
|
|
|
|
|
id,
|
|
|
|
|
isDisabled,
|
|
|
|
|
label,
|
|
|
|
|
onClick,
|
|
|
|
|
textColor,
|
|
|
|
|
} = menuItem;
|
|
|
|
|
if (iconAlign === Alignment.RIGHT) {
|
|
|
|
|
return (
|
|
|
|
|
<BaseMenuItem
|
|
|
|
|
backgroundColor={backgroundColor}
|
|
|
|
|
disabled={isDisabled}
|
|
|
|
|
key={id}
|
|
|
|
|
labelElement={<Icon color={iconColor} icon={iconName} />}
|
2022-03-13 17:21:04 +00:00
|
|
|
onClick={() => onItemClicked(onClick)}
|
2021-11-11 06:41:05 +00:00
|
|
|
text={label}
|
|
|
|
|
textColor={textColor}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<BaseMenuItem
|
|
|
|
|
backgroundColor={backgroundColor}
|
|
|
|
|
disabled={isDisabled}
|
|
|
|
|
icon={<Icon color={iconColor} icon={iconName} />}
|
|
|
|
|
key={id}
|
2022-03-13 17:21:04 +00:00
|
|
|
onClick={() => onItemClicked(onClick)}
|
2021-11-11 06:41:05 +00:00
|
|
|
text={label}
|
|
|
|
|
textColor={textColor}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return <StyledMenu>{listItems}</StyledMenu>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ButtonGroupComponent extends React.Component<ButtonGroupComponentProps> {
|
2022-03-13 17:21:04 +00:00
|
|
|
onButtonClick = (onClick?: string) => {
|
2021-11-11 06:41:05 +00:00
|
|
|
this.props.buttonClickHandler(onClick);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render = () => {
|
2022-02-24 08:21:45 +00:00
|
|
|
const {
|
|
|
|
|
buttonVariant,
|
|
|
|
|
groupButtons,
|
|
|
|
|
isDisabled,
|
|
|
|
|
menuDropDownWidth,
|
|
|
|
|
orientation,
|
|
|
|
|
width,
|
|
|
|
|
} = this.props;
|
2021-11-11 06:41:05 +00:00
|
|
|
const isHorizontal = orientation === "horizontal";
|
|
|
|
|
|
|
|
|
|
let items = Object.keys(groupButtons)
|
|
|
|
|
.map((itemKey) => groupButtons[itemKey])
|
|
|
|
|
.filter((item) => item.isVisible === true);
|
|
|
|
|
// sort btns by index
|
|
|
|
|
items = sortBy(items, ["index"]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ButtonGroupWrapper
|
|
|
|
|
borderRadius={this.props.borderRadius}
|
|
|
|
|
boxShadow={this.props.boxShadow}
|
|
|
|
|
boxShadowColor={this.props.boxShadowColor}
|
|
|
|
|
className="t--buttongroup-widget"
|
|
|
|
|
isHorizontal={isHorizontal}
|
|
|
|
|
>
|
|
|
|
|
{items.map((button) => {
|
|
|
|
|
const borderRadOnStart = button.index === 0;
|
|
|
|
|
const borderRadOnEnd = button.index === items.length - 1;
|
|
|
|
|
const isButtonDisabled = button.isDisabled || isDisabled;
|
|
|
|
|
|
|
|
|
|
if (button.buttonType === "MENU" && !isButtonDisabled) {
|
|
|
|
|
const { menuItems } = button;
|
2022-02-24 08:21:45 +00:00
|
|
|
const id = uniqueId();
|
2021-11-11 06:41:05 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<MenuButtonWrapper key={button.id}>
|
2022-02-24 08:21:45 +00:00
|
|
|
<PopoverStyles
|
|
|
|
|
id={id}
|
|
|
|
|
menuDropDownWidth={menuDropDownWidth}
|
|
|
|
|
parentWidth={width - WidgetContainerDiff}
|
|
|
|
|
/>
|
2021-11-11 06:41:05 +00:00
|
|
|
<Popover2
|
|
|
|
|
content={
|
|
|
|
|
<PopoverContent
|
|
|
|
|
menuItems={menuItems || {}}
|
|
|
|
|
onItemClicked={this.onButtonClick}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
disabled={button.isDisabled}
|
|
|
|
|
fill
|
|
|
|
|
minimal
|
|
|
|
|
placement="bottom-end"
|
2022-02-24 08:21:45 +00:00
|
|
|
popoverClassName={`menu-button-popover menu-button-width-${id}`}
|
2021-11-11 06:41:05 +00:00
|
|
|
>
|
2022-03-13 17:21:04 +00:00
|
|
|
<DragContainer
|
2021-11-11 06:41:05 +00:00
|
|
|
buttonColor={button.buttonColor}
|
|
|
|
|
buttonVariant={buttonVariant}
|
2022-03-13 17:21:04 +00:00
|
|
|
disabled={isButtonDisabled}
|
|
|
|
|
renderMode={this.props.renderMode}
|
2021-11-11 06:41:05 +00:00
|
|
|
>
|
2022-03-13 17:21:04 +00:00
|
|
|
<StyledButton
|
|
|
|
|
borderRadOnEnd={borderRadOnEnd}
|
|
|
|
|
borderRadOnStart={borderRadOnStart}
|
|
|
|
|
borderRadius={this.props.borderRadius}
|
|
|
|
|
buttonColor={button.buttonColor}
|
|
|
|
|
buttonVariant={buttonVariant}
|
|
|
|
|
disabled={isButtonDisabled}
|
|
|
|
|
iconAlign={button.iconAlign}
|
|
|
|
|
isHorizontal={isHorizontal}
|
|
|
|
|
key={button.id}
|
2021-12-08 13:11:13 +00:00
|
|
|
>
|
2022-03-13 17:21:04 +00:00
|
|
|
<StyledButtonContent
|
|
|
|
|
iconAlign={button.iconAlign || "left"}
|
|
|
|
|
placement={button.placement}
|
|
|
|
|
>
|
|
|
|
|
{button.iconName && <Icon icon={button.iconName} />}
|
|
|
|
|
{!!button.label && (
|
|
|
|
|
<span className={CoreClass.BUTTON_TEXT}>
|
|
|
|
|
{button.label}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</StyledButtonContent>
|
|
|
|
|
</StyledButton>
|
|
|
|
|
</DragContainer>
|
2021-11-11 06:41:05 +00:00
|
|
|
</Popover2>
|
|
|
|
|
</MenuButtonWrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
2022-03-13 17:21:04 +00:00
|
|
|
<DragContainer
|
2021-11-11 06:41:05 +00:00
|
|
|
buttonColor={button.buttonColor}
|
|
|
|
|
buttonVariant={buttonVariant}
|
2022-03-13 17:21:04 +00:00
|
|
|
disabled={isButtonDisabled}
|
2021-11-11 06:41:05 +00:00
|
|
|
key={button.id}
|
2022-03-13 17:21:04 +00:00
|
|
|
onClick={() => {
|
|
|
|
|
if (isButtonDisabled) return;
|
|
|
|
|
this.onButtonClick(button.onClick);
|
|
|
|
|
}}
|
|
|
|
|
renderMode={this.props.renderMode}
|
|
|
|
|
style={{ flex: "1 1 auto" }}
|
2021-11-11 06:41:05 +00:00
|
|
|
>
|
2022-03-13 17:21:04 +00:00
|
|
|
<StyledButton
|
|
|
|
|
borderRadOnEnd={borderRadOnEnd}
|
|
|
|
|
borderRadOnStart={borderRadOnStart}
|
|
|
|
|
borderRadius={this.props.borderRadius}
|
|
|
|
|
buttonColor={button.buttonColor}
|
|
|
|
|
buttonVariant={buttonVariant}
|
|
|
|
|
disabled={isButtonDisabled}
|
|
|
|
|
iconAlign={button.iconAlign}
|
|
|
|
|
isHorizontal={isHorizontal}
|
|
|
|
|
onClick={() => this.onButtonClick(button.onClick)}
|
2021-12-08 13:11:13 +00:00
|
|
|
>
|
2022-03-13 17:21:04 +00:00
|
|
|
<StyledButtonContent
|
|
|
|
|
iconAlign={button.iconAlign || "left"}
|
|
|
|
|
placement={button.placement}
|
|
|
|
|
>
|
|
|
|
|
{button.iconName && <Icon icon={button.iconName} />}
|
|
|
|
|
{!!button.label && (
|
|
|
|
|
<span className={CoreClass.BUTTON_TEXT}>
|
|
|
|
|
{button.label}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</StyledButtonContent>
|
|
|
|
|
</StyledButton>
|
|
|
|
|
</DragContainer>
|
2021-11-11 06:41:05 +00:00
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</ButtonGroupWrapper>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface GroupButtonProps {
|
|
|
|
|
widgetId: string;
|
|
|
|
|
id: string;
|
|
|
|
|
index: number;
|
|
|
|
|
isVisible?: boolean;
|
|
|
|
|
isDisabled?: boolean;
|
|
|
|
|
label?: string;
|
|
|
|
|
buttonType?: string;
|
|
|
|
|
buttonColor?: string;
|
|
|
|
|
iconName?: IconName;
|
|
|
|
|
iconAlign?: Alignment;
|
2021-12-08 13:11:13 +00:00
|
|
|
placement?: ButtonPlacement;
|
2021-11-11 06:41:05 +00:00
|
|
|
onClick?: string;
|
|
|
|
|
menuItems: Record<
|
|
|
|
|
string,
|
|
|
|
|
{
|
|
|
|
|
widgetId: string;
|
|
|
|
|
id: string;
|
|
|
|
|
index: number;
|
|
|
|
|
isVisible?: boolean;
|
|
|
|
|
isDisabled?: boolean;
|
|
|
|
|
label?: string;
|
|
|
|
|
backgroundColor?: string;
|
|
|
|
|
textColor?: string;
|
|
|
|
|
iconName?: IconName;
|
|
|
|
|
iconColor?: string;
|
|
|
|
|
iconAlign?: Alignment;
|
|
|
|
|
onClick?: string;
|
|
|
|
|
}
|
|
|
|
|
>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ButtonGroupComponentProps {
|
|
|
|
|
borderRadius?: ButtonBorderRadius;
|
|
|
|
|
boxShadow?: ButtonBoxShadow;
|
|
|
|
|
boxShadowColor?: string;
|
|
|
|
|
buttonVariant: ButtonVariant;
|
|
|
|
|
buttonClickHandler: (onClick: string | undefined) => void;
|
|
|
|
|
groupButtons: Record<string, GroupButtonProps>;
|
2022-03-13 17:21:04 +00:00
|
|
|
isDisabled: boolean;
|
2022-02-24 08:21:45 +00:00
|
|
|
menuDropDownWidth: number;
|
2022-03-13 17:21:04 +00:00
|
|
|
orientation: string;
|
|
|
|
|
renderMode: RenderMode;
|
|
|
|
|
width: number;
|
2021-11-11 06:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ButtonGroupComponent;
|