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,
|
|
|
|
|
ButtonBoxShadow,
|
|
|
|
|
ButtonVariant,
|
2021-09-27 06:30:04 +00:00
|
|
|
ButtonVariantTypes,
|
2021-09-23 15:14:24 +00:00
|
|
|
} from "components/constants";
|
|
|
|
|
import { IconName } from "@blueprintjs/icons";
|
|
|
|
|
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;
|
|
|
|
|
borderRadius?: ButtonBorderRadius;
|
|
|
|
|
boxShadow?: ButtonBoxShadow;
|
|
|
|
|
boxShadowColor?: string;
|
|
|
|
|
iconName?: IconName;
|
|
|
|
|
iconAlign?: Alignment;
|
|
|
|
|
}
|
2021-07-13 08:05:09 +00:00
|
|
|
|
|
|
|
|
class MenuButtonWidget extends BaseWidget<MenuButtonWidgetProps, WidgetState> {
|
|
|
|
|
static getPropertyPaneConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "label",
|
|
|
|
|
helpText: "Sets the label of a menu",
|
|
|
|
|
label: "Label",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
2021-09-20 10:43:44 +00:00
|
|
|
placeholderText: "Open",
|
2021-07-13 08:05:09 +00:00
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-07-13 08:05:09 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText: "Menu items",
|
|
|
|
|
propertyName: "menuItems",
|
|
|
|
|
controlType: "MENU_ITEMS",
|
2021-09-20 10:43:44 +00:00
|
|
|
label: "Menu Items",
|
2021-07-13 08:05:09 +00:00
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
panelConfig: {
|
|
|
|
|
editableTitle: true,
|
|
|
|
|
titlePropertyName: "label",
|
|
|
|
|
panelIdPropertyName: "id",
|
|
|
|
|
updateHook: (
|
|
|
|
|
props: any,
|
|
|
|
|
propertyPath: string,
|
|
|
|
|
propertyValue: string,
|
|
|
|
|
) => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
propertyPath,
|
|
|
|
|
propertyValue,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "label",
|
|
|
|
|
helpText: "Sets the label of a menu item",
|
|
|
|
|
label: "Label",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
2021-09-20 10:43:44 +00:00
|
|
|
placeholderText: "Download",
|
2021-07-13 08:05:09 +00:00
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-07-13 08:05:09 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "backgroundColor",
|
|
|
|
|
helpText: "Sets the background color of a menu item",
|
|
|
|
|
label: "Background 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: "isDisabled",
|
|
|
|
|
helpText: "Disables input to the widget",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
2021-07-13 08:05:09 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
2021-07-13 08:05:09 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Icon Options",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconName",
|
|
|
|
|
label: "Icon",
|
|
|
|
|
helpText: "Sets the icon to be used for a menu item",
|
|
|
|
|
controlType: "ICON_SELECT",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-07-13 08:05:09 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconColor",
|
|
|
|
|
helpText: "Sets the icon color of a menu item",
|
|
|
|
|
label: "Icon color",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconAlign",
|
|
|
|
|
label: "Icon alignment",
|
|
|
|
|
helpText: "Sets the icon alignment of a menu item",
|
|
|
|
|
controlType: "ICON_ALIGN",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-07-13 08:05:09 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
2021-11-26 09:32:04 +00:00
|
|
|
sectionName: "Events",
|
2021-07-13 08:05:09 +00:00
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
helpText:
|
|
|
|
|
"Triggers an action when the menu item is clicked",
|
|
|
|
|
propertyName: "onClick",
|
|
|
|
|
label: "onClick",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-09-20 10:43:44 +00:00
|
|
|
{
|
|
|
|
|
propertyName: "isDisabled",
|
|
|
|
|
helpText: "Disables input to the widget",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
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 },
|
|
|
|
|
},
|
2021-07-13 08:05:09 +00:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
2021-08-24 05:37:16 +00:00
|
|
|
sectionName: "Styles",
|
2021-07-13 08:05:09 +00:00
|
|
|
children: [
|
2021-08-24 05:37:16 +00:00
|
|
|
{
|
|
|
|
|
propertyName: "menuColor",
|
2021-09-23 15:14:24 +00:00
|
|
|
helpText: "Sets the style of the Menu button",
|
2021-08-24 05:37:16 +00:00
|
|
|
label: "Menu Color",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "menuVariant",
|
|
|
|
|
label: "Menu Variant",
|
|
|
|
|
controlType: "DROP_DOWN",
|
|
|
|
|
helpText: "Sets the variant of the menu button",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
2021-09-23 15:14:24 +00:00
|
|
|
label: "Primary",
|
2021-10-12 08:04:51 +00:00
|
|
|
value: ButtonVariantTypes.PRIMARY,
|
2021-08-24 05:37:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
2021-09-23 15:14:24 +00:00
|
|
|
label: "Secondary",
|
2021-10-12 08:04:51 +00:00
|
|
|
value: ButtonVariantTypes.SECONDARY,
|
2021-08-24 05:37:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
2021-09-23 15:14:24 +00:00
|
|
|
label: "Tertiary",
|
2021-10-12 08:04:51 +00:00
|
|
|
value: ButtonVariantTypes.TERTIARY,
|
2021-08-24 05:37:16 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isJSConvertible: true,
|
2021-09-27 06:30:04 +00:00
|
|
|
isBindProperty: true,
|
2021-08-24 05:37:16 +00:00
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
2021-10-12 08:04:51 +00:00
|
|
|
allowedValues: [
|
|
|
|
|
ButtonVariantTypes.PRIMARY,
|
|
|
|
|
ButtonVariantTypes.SECONDARY,
|
|
|
|
|
ButtonVariantTypes.TERTIARY,
|
|
|
|
|
],
|
|
|
|
|
default: ButtonVariantTypes.PRIMARY,
|
2021-08-24 05:37:16 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "borderRadius",
|
|
|
|
|
label: "Border Radius",
|
|
|
|
|
helpText:
|
|
|
|
|
"Rounds the corners of the icon button's outer border edge",
|
|
|
|
|
controlType: "BUTTON_BORDER_RADIUS_OPTIONS",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
allowedValues: ["CIRCLE", "SHARP", "ROUNDED"],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "boxShadow",
|
|
|
|
|
label: "Box Shadow",
|
|
|
|
|
helpText:
|
|
|
|
|
"Enables you to cast a drop shadow from the frame of the widget",
|
|
|
|
|
controlType: "BOX_SHADOW_OPTIONS",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
allowedValues: [
|
|
|
|
|
"NONE",
|
|
|
|
|
"VARIANT1",
|
|
|
|
|
"VARIANT2",
|
|
|
|
|
"VARIANT3",
|
|
|
|
|
"VARIANT4",
|
|
|
|
|
"VARIANT5",
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-07-13 08:05:09 +00:00
|
|
|
},
|
|
|
|
|
{
|
2021-08-24 05:37:16 +00:00
|
|
|
propertyName: "boxShadowColor",
|
|
|
|
|
helpText: "Sets the shadow color of the widget",
|
|
|
|
|
label: "Shadow Color",
|
2021-07-13 08:05:09 +00:00
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
2021-08-24 05:37:16 +00:00
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
regex: /^(?![<|{{]).+/,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
},
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
},
|
2021-07-13 08:05:09 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconAlign",
|
2021-08-24 05:37:16 +00:00
|
|
|
label: "Icon Alignment",
|
|
|
|
|
helpText: "Sets the icon alignment of the menu button",
|
2021-07-13 08:05:09 +00:00
|
|
|
controlType: "ICON_ALIGN",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
2021-08-24 05:37:16 +00:00
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
allowedValues: ["center", "left", "right"],
|
|
|
|
|
},
|
|
|
|
|
},
|
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() {
|
|
|
|
|
return (
|
|
|
|
|
<MenuButtonComponent
|
|
|
|
|
{...this.props}
|
|
|
|
|
onItemClicked={this.menuItemClickHandler}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|