Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Refactor Auto Layout min/max dimension for widgets #24627

Merged
merged 13 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
makes min/max dimensions as params to view component
  • Loading branch information
aswathkk committed Jun 21, 2023
commit 33d657ad065b7e8ec7049520111e18d0c8e91169
14 changes: 10 additions & 4 deletions app/client/src/widgets/ButtonWidget/component/DragContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export type ButtonContainerProps = {
buttonVariant?: ButtonVariant;
disabled?: boolean;
shouldFitContent?: boolean;
maxWidth?: number;
minWidth?: number;
minHeight?: number;
loading?: boolean;
style?: React.CSSProperties;
};
Expand All @@ -47,15 +50,15 @@ const ButtonContainer = styled.div<ButtonContainerProps>`
height: 100%;
}

${({ shouldFitContent }) =>
${({ maxWidth, minHeight, minWidth, shouldFitContent }) =>
shouldFitContent &&
css`
.bp3-button.bp3-fill {
display: flex;
width: auto;
max-width: 352px;
min-width: 112px;
min-height: 32px;
${minWidth ? `min-width: ${minWidth}px;` : ""}
${minHeight ? `min-height: ${minHeight}px;` : ""}
${maxWidth ? `max-width: ${maxWidth}px;` : ""}
}
`}

Expand Down Expand Up @@ -93,6 +96,9 @@ export function DragContainer(props: DragContainerProps) {
buttonVariant={props.buttonVariant}
disabled={props.disabled}
loading={props.loading}
maxWidth={props.maxWidth}
minHeight={props.minHeight}
minWidth={props.minWidth}
onClick={hasOnClick ? props.onClick : undefined}
shouldFitContent={props.shouldFitContent}
style={props.style}
Expand Down
15 changes: 15 additions & 0 deletions app/client/src/widgets/ButtonWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export type ButtonStyleProps = {
iconAlign?: Alignment;
shouldFitContent?: boolean;
placement?: ButtonPlacement;
maxWidth?: number;
minWidth?: number;
minHeight?: number;
};

// To be used in any other part of the app
Expand All @@ -186,6 +189,9 @@ export function BaseButton(props: IButtonProps & ButtonStyleProps) {
iconAlign,
iconName,
loading,
maxWidth,
minHeight,
minWidth,
onClick,
placement,
rightIcon,
Expand All @@ -200,6 +206,9 @@ export function BaseButton(props: IButtonProps & ButtonStyleProps) {
buttonVariant={buttonVariant}
disabled={disabled}
loading={loading}
maxWidth={maxWidth}
minHeight={minHeight}
minWidth={minWidth}
onClick={onClick}
shouldFitContent={props.shouldFitContent}
showInAllModes
Expand Down Expand Up @@ -266,6 +275,9 @@ interface ButtonComponentProps extends ComponentProps {
iconAlign?: Alignment;
placement?: ButtonPlacement;
className?: string;
minWidth?: number;
minHeight?: number;
maxWidth?: number;
}

type RecaptchaV2ComponentPropType = {
Expand Down Expand Up @@ -453,6 +465,9 @@ function ButtonComponent(props: ButtonComponentProps & RecaptchaProps) {
iconAlign={props.iconAlign}
iconName={props.iconName}
loading={props.isLoading}
maxWidth={props.maxWidth}
minHeight={props.minHeight}
minWidth={props.minWidth}
placement={props.placement}
rightIcon={props.rightIcon}
shouldFitContent={props.shouldFitContent}
Expand Down
17 changes: 16 additions & 1 deletion app/client/src/widgets/ButtonWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "components/constants";
import type { ExecutionResult } from "constants/AppsmithActionConstants/ActionConstants";
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
import type { WidgetType } from "constants/WidgetConstants";
import { WIDGET_PADDING, type WidgetType } from "constants/WidgetConstants";
import { ValidationTypes } from "constants/WidgetValidation";
import type { Stylesheet } from "entities/AppTheming";
import React from "react";
Expand Down Expand Up @@ -464,6 +464,21 @@ class ButtonWidget extends BaseWidget<ButtonWidgetProps, ButtonWidgetState> {
isDisabled={isDisabled}
isLoading={this.props.isLoading || this.state.isLoading}
key={this.props.widgetId}
maxWidth={
this.props.maxWidth
? this.props.maxWidth - WIDGET_PADDING * 2
: undefined
}
minHeight={
this.props.minHeight
? this.props.minHeight - WIDGET_PADDING * 2
: undefined
}
minWidth={
this.props.minWidth
? this.props.minWidth - WIDGET_PADDING * 2
: undefined
}
onClick={this.hasOnClickAction() ? this.onButtonClickBound : undefined}
placement={this.props.placement}
recaptchaType={this.props.recaptchaType}
Expand Down
6 changes: 6 additions & 0 deletions app/client/src/widgets/FilePickerWidgetV2/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ function FilePickerComponent(props: FilePickerComponentProps) {
buttonColor={props.buttonColor}
disabled={props.isDisabled}
loading={props.isLoading}
maxWidth={props.maxWidth}
minHeight={props.minHeight}
minWidth={props.minWidth}
onClick={openModal}
shouldFitContent={props.shouldFitContent}
text={computedLabel}
Expand All @@ -42,6 +45,9 @@ export interface FilePickerComponentProps extends ComponentProps {
borderRadius: string;
boxShadow?: string;
shouldFitContent: boolean;
maxWidth?: number;
minWidth?: number;
minHeight?: number;
}

FilePickerComponent.defaultProps = {
Expand Down
20 changes: 19 additions & 1 deletion app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import UpIcon from "assets/icons/ads/up-arrow.svg";
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
import { Colors } from "constants/Colors";
import type { WidgetType } from "constants/WidgetConstants";
import { FILE_SIZE_LIMIT_FOR_BLOBS } from "constants/WidgetConstants";
import {
FILE_SIZE_LIMIT_FOR_BLOBS,
WIDGET_PADDING,
} from "constants/WidgetConstants";
import { ValidationTypes } from "constants/WidgetValidation";
import type { Stylesheet } from "entities/AppTheming";
import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory";
Expand Down Expand Up @@ -834,6 +837,21 @@ class FilePickerWidget extends BaseWidget<
isLoading={this.props.isLoading || this.state.isLoading}
key={this.props.widgetId}
label={this.props.label}
maxWidth={
this.props.maxWidth
? this.props.maxWidth - WIDGET_PADDING * 2
: undefined
}
minHeight={
this.props.minHeight
? this.props.minHeight - WIDGET_PADDING * 2
: undefined
}
minWidth={
this.props.minWidth
? this.props.minWidth - WIDGET_PADDING * 2
: undefined
}
shouldFitContent={this.isAutoLayoutMode}
uppy={this.state.uppy}
widgetId={this.props.widgetId}
Expand Down
15 changes: 15 additions & 0 deletions app/client/src/widgets/MenuButtonWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ export interface PopoverTargetButtonProps {
label?: string;
placement?: ButtonPlacement;
renderMode?: RenderMode;
maxWidth?: number;
minWidth?: number;
minHeight?: number;
}

function PopoverTargetButton(props: PopoverTargetButtonProps) {
Expand All @@ -311,6 +314,9 @@ function PopoverTargetButton(props: PopoverTargetButtonProps) {
iconName,
isDisabled,
label,
maxWidth,
minHeight,
minWidth,
placement,
renderMode,
shouldFitContent,
Expand All @@ -323,6 +329,9 @@ function PopoverTargetButton(props: PopoverTargetButtonProps) {
buttonColor={buttonColor}
buttonVariant={buttonVariant}
disabled={isDisabled}
maxWidth={maxWidth}
minHeight={minHeight}
minWidth={minWidth}
renderMode={renderMode}
shouldFitContent={shouldFitContent}
>
Expand Down Expand Up @@ -354,11 +363,14 @@ function MenuButtonComponent(props: MenuButtonComponentProps) {
isCompact,
isDisabled,
label,
maxWidth,
menuColor,
menuDropDownWidth,
menuItems,
menuItemsSource,
menuVariant,
minHeight,
minWidth,
onItemClicked,
placement,
renderMode,
Expand Down Expand Up @@ -405,6 +417,9 @@ function MenuButtonComponent(props: MenuButtonComponentProps) {
iconName={iconName}
isDisabled={isDisabled}
label={label}
maxWidth={maxWidth}
minHeight={minHeight}
minWidth={minWidth}
placement={placement}
renderMode={renderMode}
shouldFitContent={shouldFitContent}
Expand Down
3 changes: 3 additions & 0 deletions app/client/src/widgets/MenuButtonWidget/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export interface MenuButtonComponentProps {
menuItemsSource: MenuItemsSource;
configureMenuItems: ConfigureMenuItems;
sourceData?: Array<Record<string, unknown>>;
maxWidth?: number;
minWidth?: number;
minHeight?: number;
}

export interface PopoverContentProps {
Expand Down
16 changes: 16 additions & 0 deletions app/client/src/widgets/MenuButtonWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import contentConfig from "./propertyConfig/contentConfig";
import styleConfig from "./propertyConfig/styleConfig";
import { DefaultAutocompleteDefinitions } from "widgets/WidgetUtils";
import type { AutocompletionDefinitions } from "widgets/constants";
import { WIDGET_PADDING } from "constants/WidgetConstants";

class MenuButtonWidget extends BaseWidget<MenuButtonWidgetProps, WidgetState> {
static getPropertyPaneContentConfig() {
Expand Down Expand Up @@ -122,7 +123,22 @@ class MenuButtonWidget extends BaseWidget<MenuButtonWidgetProps, WidgetState> {
<MenuButtonComponent
{...this.props}
getVisibleItems={this.getVisibleItems}
maxWidth={
this.props.maxWidth
? this.props.maxWidth - WIDGET_PADDING * 2
: undefined
}
menuDropDownWidth={menuDropDownWidth}
minHeight={
this.props.minHeight
? this.props.minHeight - WIDGET_PADDING * 2
: undefined
}
minWidth={
this.props.minWidth
? this.props.minWidth - WIDGET_PADDING * 2
: undefined
}
onItemClicked={this.menuItemClickHandler}
renderMode={this.props.renderMode}
shouldFitContent={this.isAutoLayoutMode}
Expand Down