## Description Plenty changes related to widgets alignment 1. Paragraph, button, inputs, single checkbox and switch widgets are aligned along the baseline of the text content 2. The icons in the buttons and the single checkbox and switch are now positioned absolutely so as not to affect the height of the components. The height of the components now depends on text content. 3. All unnecessary paddings and borders in the layout have been removed: - Canvas padding: `--outer-spacing-4` - Gap between sections and zones: `--outer-spacing-4` - Zone padding: `--outer-spacing-3` - Gap between widgets: `--outer-spacing-3` 4. In widget selection styles replace `border` with `outline`, since the `outline` one does not take space. 5. Add Changes to the flex-basis calculation method. Now the gap between the zones is taken into account there. 6. Add a lot of small fixes related to the changes described above. https://github.com/appsmithorg/appsmith/assets/11555074/b7c220eb-3e27-4039-9c15-6281bafe8008 Fixes #29364 ## Automation /ok-to-test tags="@tag.Anvil" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!IMPORTANT] > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/8375537665> > Commit: `f85b63c0a49f30b9762379c2f8c3bd38c7a8355f` > Cypress dashboard url: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8375537665&attempt=2" 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 ## Summary by CodeRabbit - **New Features** - Improved handling of CSS variable values in Flex components. - Enhanced styling and layout configurations for a better user experience. - **Bug Fixes** - Fixed label positioning and styling issues in Checkbox and Switch components. - Adjusted padding, margin, and sizing for consistency and alignment. - **Refactor** - Enhanced flex layout handling and space distribution logic for improved layout flexibility. - **Style** - Updated component styles for refined user interface aesthetics. - **Chores** - Updated feature flags and configurations for widgets and components to enable new functionalities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
122 lines
4.4 KiB
TypeScript
122 lines
4.4 KiB
TypeScript
import React, { forwardRef, useMemo } from "react";
|
|
import type { CSSProperties } from "react";
|
|
import { Flex } from "@design-system/widgets";
|
|
import {
|
|
FlexVerticalAlignment,
|
|
ResponsiveBehavior,
|
|
} from "layoutSystems/common/utils/constants";
|
|
import type { FlexProps } from "@design-system/widgets/src/components/Flex/src/types";
|
|
import type { AnvilFlexComponentProps } from "../utils/types";
|
|
import WidgetFactory from "WidgetProvider/factory";
|
|
import type { WidgetProps } from "widgets/BaseWidget";
|
|
import type { WidgetConfigProps } from "WidgetProvider/constants";
|
|
import { getAnvilWidgetDOMId } from "layoutSystems/common/utils/LayoutElementPositionsObserver/utils";
|
|
import { Layers } from "constants/Layers";
|
|
import { noop } from "utils/AppsmithUtils";
|
|
import { convertFlexGrowToFlexBasis } from "../sectionSpaceDistributor/utils/spaceDistributionEditorUtils";
|
|
|
|
const anvilWidgetStyleProps: CSSProperties = {
|
|
position: "relative",
|
|
zIndex: Layers.positionedWidget,
|
|
// add transition ease-in animation when there is a flexgrow value change
|
|
transition: "flex-grow 0.1s ease-in",
|
|
};
|
|
|
|
/**
|
|
* Adds the following functionalities to the widget:
|
|
* 1. Click handler to select the widget and open the property pane.
|
|
* 2. Widget size based on responsiveBehavior:
|
|
* 2a. Hug widgets will stick to the size provided to them. (flex: 0 0 auto;)
|
|
* 2b. Fill widgets will automatically take up all available width in the parent container. (flex: 1 1 0%;)
|
|
* 3. Widgets can optionally have auto width or height which is dictated by the props.
|
|
*
|
|
* Uses Flex component provided by WDS.
|
|
* @param props | AnvilFlexComponentProps
|
|
* @returns Widget
|
|
*/
|
|
export const AnvilFlexComponent = forwardRef(
|
|
(
|
|
{
|
|
children,
|
|
className,
|
|
flexGrow,
|
|
onClick = noop,
|
|
onClickCapture = noop,
|
|
widgetId,
|
|
widgetSize,
|
|
widgetType,
|
|
}: AnvilFlexComponentProps,
|
|
ref: any,
|
|
) => {
|
|
// The `anvil-widget-wrapper` className is necessary for the following features
|
|
// "Vertical Alignment" and "Asymmetric Padding". The code for the same can be found in `src/index.css`
|
|
// Please do not remove this class.
|
|
const _className = `${className} anvil-widget-wrapper`;
|
|
|
|
const widgetConfigProps = useMemo(() => {
|
|
const widgetConfig:
|
|
| (Partial<WidgetProps> & WidgetConfigProps & { type: string })
|
|
| undefined = WidgetFactory.getConfig(widgetType);
|
|
const isFillWidget =
|
|
widgetConfig?.responsiveBehavior === ResponsiveBehavior.Fill;
|
|
const verticalAlignment =
|
|
widgetConfig?.flexVerticalAlignment || FlexVerticalAlignment.Top;
|
|
return { isFillWidget, verticalAlignment };
|
|
}, [widgetType]);
|
|
// Memoize flex props to be passed to the WDS Flex component.
|
|
// If the widget is being resized => update width and height to auto.
|
|
const flexProps: FlexProps = useMemo(() => {
|
|
const { isFillWidget, verticalAlignment } = widgetConfigProps;
|
|
let flexBasis = "auto";
|
|
if (flexGrow) {
|
|
// flexGrow is a widget property present only for zone widgets which represents the number of columns the zone occupies in a section.
|
|
// pls refer to convertFlexGrowToFlexBasis for more details.
|
|
flexBasis = convertFlexGrowToFlexBasis(flexGrow);
|
|
} else if (isFillWidget) {
|
|
flexBasis = "0%";
|
|
}
|
|
const data: FlexProps = {
|
|
alignSelf: verticalAlignment || FlexVerticalAlignment.Top,
|
|
flexGrow: isFillWidget ? 1 : 0,
|
|
flexShrink: isFillWidget ? 1 : 0,
|
|
flexBasis,
|
|
alignItems: "center",
|
|
width: "max-content",
|
|
};
|
|
if (widgetSize) {
|
|
const {
|
|
maxHeight,
|
|
maxWidth,
|
|
minHeight,
|
|
minWidth,
|
|
paddingBottom,
|
|
paddingTop,
|
|
} = widgetSize;
|
|
data.maxHeight = maxHeight;
|
|
data.maxWidth = maxWidth;
|
|
data.minHeight = minHeight;
|
|
data.minWidth = minWidth;
|
|
data.paddingTop = paddingTop;
|
|
data.paddingBottom = paddingBottom;
|
|
}
|
|
return data;
|
|
}, [widgetConfigProps, widgetSize, flexGrow]);
|
|
|
|
// Render the Anvil Flex Component using the Flex component from WDS
|
|
return (
|
|
<Flex
|
|
isInner
|
|
{...flexProps}
|
|
className={_className}
|
|
id={getAnvilWidgetDOMId(widgetId)}
|
|
onClick={onClick}
|
|
onClickCapture={onClickCapture}
|
|
ref={ref}
|
|
style={anvilWidgetStyleProps}
|
|
>
|
|
{children}
|
|
</Flex>
|
|
);
|
|
},
|
|
);
|