## Description > [!TIP] To update the explorer widgets and icons to match the new Anvil design system **How** 1. Update all the icons and thumbnails svg for widgets in the explorer 2. Update the WidgetCard component to implement the new design 3. Test functionality of widgets manually Fixes #32330 ## Automation /ok-to-test tags="@tag.Visual, @tag.MainContainer, @tag.Widget" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!IMPORTANT] > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/8598999945> > Commit: `47cf5a8e0e14e986da31e02ba8f630fd27ce310f` > Cypress dashboard url: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8598999945&attempt=1" target="_blank">Click here!</a> > All cypress tests have passed 🎉🎉🎉 <!-- end of auto-generated comment: Cypress test results --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new `UIEntityCard` component for representing widgets in the editor sidebar with enhanced drag-and-drop functionality and improved visual layout including widget details. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
500 lines
14 KiB
TypeScript
500 lines
14 KiB
TypeScript
import { LabelPosition } from "components/constants";
|
|
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
|
|
import { ValidationTypes } from "constants/WidgetValidation";
|
|
import type { SetterConfig, Stylesheet } from "entities/AppTheming";
|
|
import React from "react";
|
|
import { isAutoLayout } from "layoutSystems/autolayout/utils/flexWidgetUtils";
|
|
import type { DerivedPropertiesMap } from "WidgetProvider/factory";
|
|
import { AlignWidgetTypes } from "WidgetProvider/constants";
|
|
import {
|
|
isAutoHeightEnabledForWidget,
|
|
DefaultAutocompleteDefinitions,
|
|
} from "widgets/WidgetUtils";
|
|
import type { WidgetProps, WidgetState } from "../../BaseWidget";
|
|
import BaseWidget from "../../BaseWidget";
|
|
import CheckboxComponent from "../component";
|
|
import type {
|
|
AnvilConfig,
|
|
AutocompletionDefinitions,
|
|
} from "WidgetProvider/constants";
|
|
import { FILL_WIDGET_MIN_WIDTH } from "constants/minWidthConstants";
|
|
import { ResponsiveBehavior } from "layoutSystems/common/utils/constants";
|
|
import type {
|
|
SnipingModeProperty,
|
|
PropertyUpdates,
|
|
} from "WidgetProvider/constants";
|
|
|
|
import IconSVG from "../icon.svg";
|
|
import ThumbnailSVG from "../thumbnail.svg";
|
|
import { WIDGET_TAGS } from "constants/WidgetConstants";
|
|
|
|
class CheckboxWidget extends BaseWidget<CheckboxWidgetProps, WidgetState> {
|
|
static type = "CHECKBOX_WIDGET";
|
|
|
|
static getConfig() {
|
|
return {
|
|
name: "Checkbox",
|
|
iconSVG: IconSVG,
|
|
thumbnailSVG: ThumbnailSVG,
|
|
tags: [WIDGET_TAGS.TOGGLES],
|
|
needsMeta: true,
|
|
searchTags: ["boolean"],
|
|
};
|
|
}
|
|
|
|
static getFeatures() {
|
|
return {
|
|
dynamicHeight: {
|
|
sectionIndex: 2,
|
|
active: true,
|
|
},
|
|
};
|
|
}
|
|
|
|
static getDefaults() {
|
|
return {
|
|
rows: 4,
|
|
columns: 12,
|
|
label: "Label",
|
|
defaultCheckedState: true,
|
|
widgetName: "Checkbox",
|
|
version: 1,
|
|
alignWidget: AlignWidgetTypes.LEFT,
|
|
labelPosition: LabelPosition.Left,
|
|
isDisabled: false,
|
|
isRequired: false,
|
|
animateLoading: true,
|
|
responsiveBehavior: ResponsiveBehavior.Fill,
|
|
minWidth: FILL_WIDGET_MIN_WIDTH,
|
|
};
|
|
}
|
|
|
|
static getMethods() {
|
|
return {
|
|
getSnipingModeUpdates: (
|
|
propValueMap: SnipingModeProperty,
|
|
): PropertyUpdates[] => {
|
|
return [
|
|
{
|
|
propertyPath: "defaultCheckedState",
|
|
propertyValue: propValueMap.data,
|
|
isDynamicPropertyPath: true,
|
|
},
|
|
];
|
|
},
|
|
};
|
|
}
|
|
|
|
static getAutoLayoutConfig() {
|
|
return {
|
|
disabledPropsDefaults: {
|
|
labelTextSize: "0.875rem",
|
|
},
|
|
widgetSize: [
|
|
{
|
|
viewportMinWidth: 0,
|
|
configuration: () => {
|
|
return {
|
|
minWidth: "120px",
|
|
minHeight: "40px",
|
|
};
|
|
},
|
|
},
|
|
],
|
|
disableResizeHandles: {
|
|
vertical: true,
|
|
},
|
|
};
|
|
}
|
|
|
|
static getAnvilConfig(): AnvilConfig | null {
|
|
return {
|
|
isLargeWidget: false,
|
|
widgetSize: {
|
|
maxHeight: {},
|
|
maxWidth: {},
|
|
minHeight: { base: "40px" },
|
|
minWidth: { base: "120px" },
|
|
},
|
|
};
|
|
}
|
|
|
|
static getAutocompleteDefinitions(): AutocompletionDefinitions {
|
|
return {
|
|
"!doc":
|
|
"Checkbox is a simple UI widget you can use when you want users to make a binary choice",
|
|
"!url": "https://docs.appsmith.com/widget-reference/checkbox",
|
|
isVisible: DefaultAutocompleteDefinitions.isVisible,
|
|
isChecked: "bool",
|
|
isDisabled: "bool",
|
|
};
|
|
}
|
|
|
|
static getPropertyPaneContentConfig() {
|
|
return [
|
|
{
|
|
sectionName: "Label",
|
|
children: [
|
|
{
|
|
propertyName: "label",
|
|
label: "Text",
|
|
controlType: "INPUT_TEXT",
|
|
helpText: "Displays a label next to the widget",
|
|
placeholderText: "I agree to the T&C",
|
|
isBindProperty: true,
|
|
isTriggerProperty: false,
|
|
validation: { type: ValidationTypes.TEXT },
|
|
},
|
|
{
|
|
helpText: "Sets the label position of the widget",
|
|
propertyName: "labelPosition",
|
|
label: "Position",
|
|
controlType: "ICON_TABS",
|
|
fullWidth: true,
|
|
options: [
|
|
{ label: "Left", value: LabelPosition.Left },
|
|
{ label: "Right", value: LabelPosition.Right },
|
|
],
|
|
defaultValue: LabelPosition.Left,
|
|
isBindProperty: false,
|
|
isTriggerProperty: false,
|
|
validation: { type: ValidationTypes.TEXT },
|
|
},
|
|
{
|
|
propertyName: "alignWidget",
|
|
helpText: "Sets the alignment of the widget",
|
|
label: "Alignment",
|
|
controlType: "LABEL_ALIGNMENT_OPTIONS",
|
|
isBindProperty: true,
|
|
isTriggerProperty: false,
|
|
fullWidth: false,
|
|
options: [
|
|
{
|
|
startIcon: "align-left",
|
|
value: AlignWidgetTypes.LEFT,
|
|
},
|
|
{
|
|
startIcon: "align-right",
|
|
value: AlignWidgetTypes.RIGHT,
|
|
},
|
|
],
|
|
validation: { type: ValidationTypes.TEXT },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
sectionName: "Validations",
|
|
children: [
|
|
{
|
|
propertyName: "isRequired",
|
|
label: "Required",
|
|
helpText: "Makes input to the widget mandatory",
|
|
controlType: "SWITCH",
|
|
isJSConvertible: true,
|
|
isBindProperty: true,
|
|
isTriggerProperty: false,
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
sectionName: "General",
|
|
children: [
|
|
{
|
|
propertyName: "defaultCheckedState",
|
|
label: "Default state",
|
|
helpText: "Sets the default checked state of the widget",
|
|
controlType: "SWITCH",
|
|
isJSConvertible: true,
|
|
isBindProperty: true,
|
|
isTriggerProperty: false,
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
},
|
|
{
|
|
propertyName: "isVisible",
|
|
label: "Visible",
|
|
helpText: "Controls the visibility of the widget",
|
|
controlType: "SWITCH",
|
|
isJSConvertible: true,
|
|
isBindProperty: true,
|
|
isTriggerProperty: false,
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
},
|
|
{
|
|
propertyName: "isDisabled",
|
|
label: "Disabled",
|
|
controlType: "SWITCH",
|
|
helpText: "Disables input to this widget",
|
|
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 },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
sectionName: "Events",
|
|
children: [
|
|
{
|
|
helpText: "when the check state is changed",
|
|
propertyName: "onCheckChange",
|
|
label: "onCheckChange",
|
|
controlType: "ACTION_SELECTOR",
|
|
isJSConvertible: true,
|
|
isBindProperty: true,
|
|
isTriggerProperty: true,
|
|
},
|
|
],
|
|
},
|
|
];
|
|
}
|
|
|
|
static getPropertyPaneStyleConfig() {
|
|
return [
|
|
{
|
|
sectionName: "Label styles",
|
|
children: [
|
|
{
|
|
propertyName: "labelTextColor",
|
|
label: "Font color",
|
|
helpText: "Control the color of the label associated",
|
|
controlType: "COLOR_PICKER",
|
|
isJSConvertible: true,
|
|
isBindProperty: true,
|
|
isTriggerProperty: false,
|
|
validation: {
|
|
type: ValidationTypes.TEXT,
|
|
params: {
|
|
regex: /^(?![<|{{]).+/,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
propertyName: "labelTextSize",
|
|
label: "Font size",
|
|
helpText: "Control the font size of the label associated",
|
|
controlType: "DROP_DOWN",
|
|
defaultValue: "0.875rem",
|
|
hidden: isAutoLayout,
|
|
options: [
|
|
{
|
|
label: "S",
|
|
value: "0.875rem",
|
|
subText: "0.875rem",
|
|
},
|
|
{
|
|
label: "M",
|
|
value: "1rem",
|
|
subText: "1rem",
|
|
},
|
|
{
|
|
label: "L",
|
|
value: "1.25rem",
|
|
subText: "1.25rem",
|
|
},
|
|
{
|
|
label: "XL",
|
|
value: "1.875rem",
|
|
subText: "1.875rem",
|
|
},
|
|
{
|
|
label: "XXL",
|
|
value: "3rem",
|
|
subText: "3rem",
|
|
},
|
|
{
|
|
label: "3XL",
|
|
value: "3.75rem",
|
|
subText: "3.75rem",
|
|
},
|
|
],
|
|
isJSConvertible: true,
|
|
isBindProperty: true,
|
|
isTriggerProperty: false,
|
|
validation: { type: ValidationTypes.TEXT },
|
|
},
|
|
{
|
|
propertyName: "labelStyle",
|
|
label: "Emphasis",
|
|
helpText: "Control if the label should be bold or italics",
|
|
controlType: "BUTTON_GROUP",
|
|
options: [
|
|
{
|
|
icon: "text-bold",
|
|
value: "BOLD",
|
|
},
|
|
{
|
|
icon: "text-italic",
|
|
value: "ITALIC",
|
|
},
|
|
],
|
|
isJSConvertible: true,
|
|
isBindProperty: true,
|
|
isTriggerProperty: false,
|
|
validation: { type: ValidationTypes.TEXT },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
sectionName: "Color",
|
|
children: [
|
|
{
|
|
propertyName: "accentColor",
|
|
helpText: "Sets the checked state color of the checkbox",
|
|
label: "Accent 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 },
|
|
},
|
|
],
|
|
},
|
|
];
|
|
}
|
|
|
|
static getDefaultPropertiesMap(): Record<string, string> {
|
|
return {
|
|
isChecked: "defaultCheckedState",
|
|
};
|
|
}
|
|
|
|
static getDerivedPropertiesMap(): DerivedPropertiesMap {
|
|
return {
|
|
value: `{{!!this.isChecked}}`,
|
|
isValid: `{{ this.isRequired ? !!this.isChecked : true }}`,
|
|
};
|
|
}
|
|
|
|
static getMetaPropertiesMap(): Record<string, any> {
|
|
return {
|
|
isChecked: undefined,
|
|
isDirty: false,
|
|
};
|
|
}
|
|
|
|
static getStylesheetConfig(): Stylesheet {
|
|
return {
|
|
accentColor: "{{appsmith.theme.colors.primaryColor}}",
|
|
borderRadius: "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
|
};
|
|
}
|
|
|
|
componentDidUpdate(prevProps: CheckboxWidgetProps) {
|
|
if (
|
|
this.props.defaultCheckedState !== prevProps.defaultCheckedState &&
|
|
this.props.isDirty
|
|
) {
|
|
this.props.updateWidgetMetaProperty("isDirty", false);
|
|
}
|
|
}
|
|
|
|
static getSetterConfig(): SetterConfig {
|
|
return {
|
|
__setters: {
|
|
setVisibility: {
|
|
path: "isVisible",
|
|
type: "boolean",
|
|
},
|
|
setDisabled: {
|
|
path: "isDisabled",
|
|
type: "boolean",
|
|
},
|
|
setRequired: {
|
|
path: "isRequired",
|
|
type: "boolean",
|
|
},
|
|
setValue: {
|
|
path: "defaultCheckedState",
|
|
type: "boolean",
|
|
accessor: "isChecked",
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
getWidgetView() {
|
|
return (
|
|
<CheckboxComponent
|
|
accentColor={this.props.accentColor}
|
|
alignWidget={this.props.alignWidget}
|
|
borderRadius={this.props.borderRadius}
|
|
isChecked={!!this.props.isChecked}
|
|
isDisabled={this.props.isDisabled}
|
|
isDynamicHeightEnabled={isAutoHeightEnabledForWidget(this.props)}
|
|
isLabelInline={this.isAutoLayoutMode}
|
|
isLoading={this.props.isLoading}
|
|
isRequired={this.props.isRequired}
|
|
key={this.props.widgetId}
|
|
label={this.props.label}
|
|
labelPosition={this.props.labelPosition}
|
|
labelStyle={this.props.labelStyle}
|
|
labelTextColor={this.props.labelTextColor}
|
|
labelTextSize={this.props.labelTextSize}
|
|
minHeight={this.props.minHeight}
|
|
onCheckChange={this.onCheckChange}
|
|
widgetId={this.props.widgetId}
|
|
/>
|
|
);
|
|
}
|
|
|
|
onCheckChange = (isChecked: boolean) => {
|
|
if (!this.props.isDirty) {
|
|
this.props.updateWidgetMetaProperty("isDirty", true);
|
|
}
|
|
|
|
this.props.updateWidgetMetaProperty("isChecked", isChecked, {
|
|
triggerPropertyName: "onCheckChange",
|
|
dynamicString: this.props.onCheckChange,
|
|
event: {
|
|
type: EventType.ON_CHECK_CHANGE,
|
|
},
|
|
});
|
|
};
|
|
}
|
|
|
|
export interface CheckboxWidgetProps extends WidgetProps {
|
|
label: string;
|
|
defaultCheckedState: boolean;
|
|
isChecked?: boolean;
|
|
isDisabled?: boolean;
|
|
onCheckChange?: string;
|
|
isRequired?: boolean;
|
|
accentColor: string;
|
|
borderRadius: string;
|
|
alignWidget: AlignWidgetTypes;
|
|
labelPosition: LabelPosition;
|
|
labelTextColor?: string;
|
|
labelTextSize?: string;
|
|
labelStyle?: string;
|
|
}
|
|
|
|
export default CheckboxWidget;
|