2021-09-09 15:10:22 +00:00
|
|
|
import React from "react";
|
2021-07-13 08:05:09 +00:00
|
|
|
|
2021-09-23 15:14:24 +00:00
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "widgets/BaseWidget";
|
2021-07-13 08:05:09 +00:00
|
|
|
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
|
2021-09-09 15:10:22 +00:00
|
|
|
import MenuButtonComponent from "../component";
|
|
|
|
|
import { ValidationTypes } from "constants/WidgetValidation";
|
|
|
|
|
import { Alignment } from "@blueprintjs/core";
|
2021-09-23 15:14:24 +00:00
|
|
|
import {
|
|
|
|
|
ButtonBorderRadius,
|
|
|
|
|
ButtonVariant,
|
2021-09-27 06:30:04 +00:00
|
|
|
ButtonVariantTypes,
|
2021-12-08 13:11:13 +00:00
|
|
|
ButtonPlacementTypes,
|
|
|
|
|
ButtonPlacement,
|
2021-09-23 15:14:24 +00:00
|
|
|
} from "components/constants";
|
|
|
|
|
import { IconName } from "@blueprintjs/icons";
|
2021-11-30 10:38:46 +00:00
|
|
|
import { MinimumPopupRows } from "widgets/constants";
|
2021-09-23 15:14:24 +00:00
|
|
|
export interface MenuButtonWidgetProps extends WidgetProps {
|
|
|
|
|
label?: string;
|
|
|
|
|
isDisabled?: boolean;
|
|
|
|
|
isVisible?: boolean;
|
|
|
|
|
isCompact?: boolean;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
>;
|
|
|
|
|
menuVariant?: ButtonVariant;
|
|
|
|
|
menuColor?: string;
|
2022-05-04 09:45:57 +00:00
|
|
|
borderRadius: ButtonBorderRadius;
|
|
|
|
|
boxShadow?: string;
|
2021-09-23 15:14:24 +00:00
|
|
|
iconName?: IconName;
|
|
|
|
|
iconAlign?: Alignment;
|
2021-12-08 13:11:13 +00:00
|
|
|
placement?: ButtonPlacement;
|
2021-09-23 15:14:24 +00:00
|
|
|
}
|
2021-07-13 08:05:09 +00:00
|
|
|
|
|
|
|
|
class MenuButtonWidget extends BaseWidget<MenuButtonWidgetProps, WidgetState> {
|
2022-08-15 08:05:46 +00:00
|
|
|
static getPropertyPaneContentConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Basic",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "label",
|
|
|
|
|
helpText: "Sets the label of a menu",
|
|
|
|
|
label: "Label",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
placeholderText: "Open",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText: "Menu items",
|
|
|
|
|
propertyName: "menuItems",
|
|
|
|
|
controlType: "MENU_ITEMS",
|
|
|
|
|
label: "Menu Items",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
panelConfig: {
|
|
|
|
|
editableTitle: true,
|
|
|
|
|
titlePropertyName: "label",
|
|
|
|
|
panelIdPropertyName: "id",
|
|
|
|
|
updateHook: (
|
|
|
|
|
props: any,
|
|
|
|
|
propertyPath: string,
|
|
|
|
|
propertyValue: string,
|
|
|
|
|
) => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
propertyPath,
|
|
|
|
|
propertyValue,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
contentChildren: [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Basic",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "label",
|
|
|
|
|
helpText: "Sets the label of a menu item",
|
|
|
|
|
label: "Label",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
placeholderText: "Download",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText:
|
|
|
|
|
"Triggers an action when the menu item is clicked",
|
|
|
|
|
propertyName: "onClick",
|
|
|
|
|
label: "onClick",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isDisabled",
|
|
|
|
|
helpText: "Disables input to the widget",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
styleChildren: [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Icon",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconName",
|
|
|
|
|
label: "Icon",
|
|
|
|
|
helpText: "Sets the icon to be used for a menu item",
|
|
|
|
|
controlType: "ICON_SELECT",
|
2022-10-26 09:45:30 +00:00
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconAlign",
|
|
|
|
|
label: "Position",
|
|
|
|
|
helpText: "Sets the icon alignment of a menu item",
|
|
|
|
|
controlType: "ICON_TABS",
|
2022-10-20 14:06:32 +00:00
|
|
|
fullWidth: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
icon: "VERTICAL_LEFT",
|
|
|
|
|
value: "left",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
icon: "VERTICAL_RIGHT",
|
|
|
|
|
value: "right",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Color",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconColor",
|
|
|
|
|
helpText: "Sets the icon color of a menu item",
|
|
|
|
|
label: "Icon color",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "textColor",
|
|
|
|
|
helpText: "Sets the text color of a menu item",
|
|
|
|
|
label: "Text color",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "backgroundColor",
|
|
|
|
|
helpText: "Sets the background color of a menu item",
|
|
|
|
|
label: "Background color",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isDisabled",
|
|
|
|
|
helpText: "Disables input to the widget",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "animateLoading",
|
|
|
|
|
label: "Animate Loading",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
helpText: "Controls the loading of the widget",
|
|
|
|
|
defaultValue: true,
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isCompact",
|
|
|
|
|
helpText: "Decides if menu items will consume lesser space",
|
|
|
|
|
label: "Compact",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getPropertyPaneStyleConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "menuVariant",
|
|
|
|
|
label: "Button Variant",
|
2022-10-20 14:06:32 +00:00
|
|
|
controlType: "ICON_TABS",
|
|
|
|
|
fullWidth: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
helpText: "Sets the variant of the menu button",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "Primary",
|
|
|
|
|
value: ButtonVariantTypes.PRIMARY,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Secondary",
|
|
|
|
|
value: ButtonVariantTypes.SECONDARY,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Tertiary",
|
|
|
|
|
value: ButtonVariantTypes.TERTIARY,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
allowedValues: [
|
|
|
|
|
ButtonVariantTypes.PRIMARY,
|
|
|
|
|
ButtonVariantTypes.SECONDARY,
|
|
|
|
|
ButtonVariantTypes.TERTIARY,
|
|
|
|
|
],
|
|
|
|
|
default: ButtonVariantTypes.PRIMARY,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Icon",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconName",
|
|
|
|
|
label: "Icon",
|
|
|
|
|
helpText: "Sets the icon to be used for the menu button",
|
|
|
|
|
controlType: "ICON_SELECT",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
updateHook: (
|
|
|
|
|
props: MenuButtonWidgetProps,
|
|
|
|
|
propertyPath: string,
|
|
|
|
|
propertyValue: string,
|
|
|
|
|
) => {
|
|
|
|
|
const propertiesToUpdate = [{ propertyPath, propertyValue }];
|
|
|
|
|
if (!props.iconAlign) {
|
|
|
|
|
propertiesToUpdate.push({
|
|
|
|
|
propertyPath: "iconAlign",
|
|
|
|
|
propertyValue: Alignment.LEFT,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return propertiesToUpdate;
|
|
|
|
|
},
|
|
|
|
|
dependencies: ["iconAlign"],
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconAlign",
|
|
|
|
|
label: "Position",
|
|
|
|
|
helpText: "Sets the icon alignment of the menu button",
|
|
|
|
|
controlType: "ICON_TABS",
|
2022-10-20 14:06:32 +00:00
|
|
|
fullWidth: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
icon: "VERTICAL_LEFT",
|
|
|
|
|
value: "left",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
icon: "VERTICAL_RIGHT",
|
|
|
|
|
value: "right",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
allowedValues: ["center", "left", "right"],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "placement",
|
|
|
|
|
label: "Placement",
|
2022-10-20 14:06:32 +00:00
|
|
|
controlType: "ICON_TABS",
|
|
|
|
|
fullWidth: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
helpText: "Sets the space between items",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "Start",
|
|
|
|
|
value: ButtonPlacementTypes.START,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Between",
|
|
|
|
|
value: ButtonPlacementTypes.BETWEEN,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Center",
|
|
|
|
|
value: ButtonPlacementTypes.CENTER,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
defaultValue: ButtonPlacementTypes.CENTER,
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
allowedValues: [
|
|
|
|
|
ButtonPlacementTypes.START,
|
|
|
|
|
ButtonPlacementTypes.BETWEEN,
|
|
|
|
|
ButtonPlacementTypes.CENTER,
|
|
|
|
|
],
|
|
|
|
|
default: ButtonPlacementTypes.CENTER,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Color",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "menuColor",
|
|
|
|
|
helpText: "Sets the style of the Menu button",
|
|
|
|
|
label: "Button Color",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Border and Shadow",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "borderRadius",
|
|
|
|
|
label: "Border Radius",
|
|
|
|
|
helpText:
|
|
|
|
|
"Rounds the corners of the icon button's outer border edge",
|
|
|
|
|
controlType: "BORDER_RADIUS_OPTIONS",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "boxShadow",
|
|
|
|
|
label: "Box Shadow",
|
|
|
|
|
helpText:
|
|
|
|
|
"Enables you to cast a drop shadow from the frame of the widget",
|
|
|
|
|
controlType: "BOX_SHADOW_OPTIONS",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-13 08:05:09 +00:00
|
|
|
menuItemClickHandler = (onClick: string | undefined) => {
|
|
|
|
|
if (onClick) {
|
|
|
|
|
super.executeAction({
|
|
|
|
|
triggerPropertyName: "onClick",
|
|
|
|
|
dynamicString: onClick,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_CLICK,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getPageView() {
|
2021-11-30 10:38:46 +00:00
|
|
|
const { componentWidth } = this.getComponentDimensions();
|
|
|
|
|
const menuDropDownWidth = MinimumPopupRows * this.props.parentColumnSpace;
|
|
|
|
|
|
2021-07-13 08:05:09 +00:00
|
|
|
return (
|
|
|
|
|
<MenuButtonComponent
|
|
|
|
|
{...this.props}
|
2021-11-30 10:38:46 +00:00
|
|
|
menuDropDownWidth={menuDropDownWidth}
|
2021-07-13 08:05:09 +00:00
|
|
|
onItemClicked={this.menuItemClickHandler}
|
2022-03-13 17:21:04 +00:00
|
|
|
renderMode={this.props.renderMode}
|
2021-11-30 10:38:46 +00:00
|
|
|
width={componentWidth}
|
2021-07-13 08:05:09 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
static getWidgetType() {
|
|
|
|
|
return "MENU_BUTTON_WIDGET";
|
2021-07-13 08:05:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default MenuButtonWidget;
|