PromucFlow_constructor/app/client/src/utils/layoutPropertiesUtils.ts
Preet Sidhu 46dcf3a8f0
chore: Create layout system structure for Anvil and AnvilFlexComponent. (#27178)
## Description
1. Add new ```appPositioningType``` : ANVIL.
2. Create new code path and folder structure for Anvil layout system.
3. Move common pieces of functionalities between autoLayout and anvil to
anvil folder structure (e.g. ```CanvasResizer```).
4. Create ```AnvilFlexComponent```.
5. Use WDS Flex component in AnvilFlexComponent.
6. Pass min max size props in a data structure that is supported by
container queries in the Flex component.
    e.g. min-width: { base: "120px", "480px": "200px" }
7. Supply the following flex properties (flex-grow flex-shrink
flex-basis) to widgets depending on their ```responsiveBehvaiour```:
    a) Fill: ```flex: 1 1 0%;```
    b) Hug: ```flex: 0 0 auto;```

#### PR fixes following issue(s)
Fixes # (issue number)
1. [#26987](https://github.com/appsmithorg/appsmith/issues/26987)
2. [#26609](https://github.com/appsmithorg/appsmith/issues/26609)
3. [#26611](https://github.com/appsmithorg/appsmith/issues/26611)

#### Type of change
- New feature (non-breaking change which adds functionality)


## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [x] Manual
- [ ] JUnit
- [x] Jest
- [ ] Cypress


## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [x] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

---------

Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
Co-authored-by: Aswath K <aswath.sana@gmail.com>
Co-authored-by: rahulramesha <rahul@appsmith.com>
Co-authored-by: rahulramesha <71900764+rahulramesha@users.noreply.github.com>
2023-10-02 15:41:05 -04:00

196 lines
5.6 KiB
TypeScript

import {
AlignItems,
Alignment,
FlexDirection,
FlexVerticalAlignment,
JustifyContent,
LayoutDirection,
Positioning,
ResponsiveBehavior,
Spacing,
} from "layoutSystems/common/utils/constants";
import { ValidationTypes } from "constants/WidgetValidation";
export interface LayoutProperties {
flexDirection: FlexDirection;
justifyContent: JustifyContent;
alignItems: AlignItems;
}
export const horizontalAlignment: { [key in Alignment]: LayoutProperties } = {
top: {
flexDirection: FlexDirection.Row,
justifyContent: JustifyContent.FlexStart,
alignItems: AlignItems.FlexStart,
},
bottom: {
flexDirection: FlexDirection.Row,
justifyContent: JustifyContent.FlexStart,
alignItems: AlignItems.FlexEnd,
},
left: {
flexDirection: FlexDirection.Row,
justifyContent: JustifyContent.FlexStart,
alignItems: AlignItems.FlexStart,
},
right: {
flexDirection: FlexDirection.RowReverse,
justifyContent: JustifyContent.FlexStart,
alignItems: AlignItems.FlexStart,
},
};
export const verticalAlignment: { [key in Alignment]: LayoutProperties } = {
top: {
flexDirection: FlexDirection.Column,
justifyContent: JustifyContent.FlexStart,
alignItems: AlignItems.Center,
},
bottom: {
flexDirection: FlexDirection.ColumnReverse,
justifyContent: JustifyContent.FlexStart,
alignItems: AlignItems.Center,
},
left: {
flexDirection: FlexDirection.Column,
justifyContent: JustifyContent.FlexStart,
alignItems: AlignItems.FlexStart,
},
right: {
flexDirection: FlexDirection.Column,
justifyContent: JustifyContent.FlexStart,
alignItems: AlignItems.FlexEnd,
},
};
export function getLayoutProperties(
direction: LayoutDirection = LayoutDirection.Horizontal,
alignment: Alignment,
spacing: Spacing,
): LayoutProperties {
let properties: LayoutProperties =
direction === LayoutDirection.Horizontal
? horizontalAlignment[alignment]
: verticalAlignment[alignment];
if (spacing !== Spacing.None) {
properties = {
...properties,
justifyContent:
spacing === Spacing.Equal
? JustifyContent.SpaceEvenly
: JustifyContent.SpaceBetween,
};
}
return properties;
}
export const generateResponsiveBehaviorConfig = (
value: ResponsiveBehavior,
): any => {
return {
helpText: "Widget layout behavior on smaller view port",
propertyName: "responsiveBehavior",
label: "Responsive behavior",
controlType: "DROP_DOWN",
defaultValue: value || ResponsiveBehavior.Hug,
options: [
{ label: "Fill", value: ResponsiveBehavior.Fill },
{ label: "Hug", value: ResponsiveBehavior.Hug },
],
isJSConvertible: false,
isBindProperty: false,
isTriggerProperty: true,
validation: { type: ValidationTypes.TEXT },
};
};
export const generateAlignmentConfig = (
value: Alignment = Alignment.Left,
): any => {
return {
helpText:
"Alignment of children with respect to this parent (applies to Stack positioning)",
propertyName: "alignment",
label: "Alignment",
controlType: "DROP_DOWN",
defaultValue: value,
options: [
{ label: "Top", value: Alignment.Top },
{ label: "Bottom", value: Alignment.Bottom },
{ label: "Left", value: Alignment.Left },
{ label: "Right", value: Alignment.Right },
],
isJSConvertible: true,
isBindProperty: false,
isTriggerProperty: true,
validation: { type: ValidationTypes.TEXT },
hidden: (props: any) => props?.positioning === Positioning.Fixed,
};
};
export const generateSpacingConfig = (value: Spacing = Spacing.None): any => {
return {
helpText: "Spacing between the children (applies to Stack positioning)",
propertyName: "spacing",
label: "Spacing",
controlType: "DROP_DOWN",
defaultValue: value,
options: [
{ label: "None", value: Spacing.None },
{ label: "Equal", value: Spacing.Equal },
{ label: "Space between", value: Spacing.SpaceBetween },
],
isJSConvertible: true,
isBindProperty: false,
isTriggerProperty: true,
validation: { type: ValidationTypes.TEXT },
hidden: (props: any) => props?.positioning === Positioning.Fixed,
};
};
export const generatePositioningConfig = (
value: Positioning = Positioning.Vertical,
): any => {
return {
helpText: "Position styles to be applied to the children",
propertyName: "positioning",
label: "Positioning",
controlType: "DROP_DOWN",
defaultValue: value,
options: [
{ label: "Fixed", value: Positioning.Fixed },
// { label: "Horizontal stack", value: Positioning.Horizontal },
{ label: "Vertical stack", value: Positioning.Vertical },
],
isJSConvertible: false,
isBindProperty: true,
isTriggerProperty: true,
validation: { type: ValidationTypes.TEXT },
};
};
export const generateVerticalAlignmentConfig = (
value: FlexVerticalAlignment = FlexVerticalAlignment.Top,
): any => {
return {
helpText: "Vertical alignment with respect to the siblings in the same row",
propertyName: "flexVerticalAlignment",
label: "Vertical alignment",
controlType: "DROP_DOWN",
defaultValue: value,
options: [
{ label: "Top", value: FlexVerticalAlignment.Top },
{ label: "Center", value: FlexVerticalAlignment.Center },
{ label: "Bottom", value: FlexVerticalAlignment.Bottom },
],
isJSConvertible: false,
isBindProperty: true,
isTriggerProperty: true,
validation: { type: ValidationTypes.TEXT },
};
};
export function getLayoutConfig(alignment: Alignment, spacing: Spacing): any[] {
return [generateAlignmentConfig(alignment), generateSpacingConfig(spacing)];
}