Skip to content

Feat: margin padding #278

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

Merged
merged 6 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions client/packages/lowcoder-design/src/icons/icon-compress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions client/packages/lowcoder-design/src/icons/icon-expand.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions client/packages/lowcoder-design/src/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,6 @@ export { ReactComponent as CalendarDeleteIcon } from "icons/icon-calendar-delete
export { ReactComponent as TableCheckedIcon } from "icons/icon-table-checked.svg";
export { ReactComponent as TableUnCheckedIcon } from "icons/icon-table-boolean-false.svg";
export { ReactComponent as FileFolderIcon } from "icons/icon-editor-folder.svg";
export { ReactComponent as ExpandIcon } from "icons/icon-expand.svg";
export { ReactComponent as CompressIcon } from "icons/icon-compress.svg"
export { ReactComponent as TableCellsIcon } from "icons/icon-table-cells.svg" // Added By Aqib Mirza
8 changes: 8 additions & 0 deletions client/packages/lowcoder/src/api/commonSettingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface ThemeDetail {
primarySurface: string; // comp bg-color
borderRadius: string;
chart?: string;
margin?: string;
padding?: string;
gridColumns?: string; //Added By Aqib Mirza
}

Expand All @@ -61,6 +63,10 @@ export function getThemeDetailName(key: keyof ThemeDetail) {
return trans("themeDetail.primarySurface");
case "borderRadius":
return trans("themeDetail.borderRadius");
case "margin":
return trans("style.margin");
case "padding":
return trans("style.padding");
//Added By Aqib Mirza
case "gridColumns":
return trans("themeDetail.gridColumns");
Expand All @@ -75,6 +81,8 @@ export function isThemeColorKey(key: string) {
case "textLight":
case "canvas":
case "primarySurface":
case "margin":
case "padding":
case "gridColumns": //Added By Aqib Mirza
return true;
}
Expand Down
88 changes: 86 additions & 2 deletions client/packages/lowcoder/src/components/ColorPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import _ from "lodash";
import { useEffect, useState } from "react";
import { ConfigItem, Radius, GridColumns } from "../pages/setting/theme/styledComponents";
import { ConfigItem, Radius, Margin, Padding, GridColumns } from "../pages/setting/theme/styledComponents";
import { isValidColor, toHex } from "components/colorSelect/colorUtils";
import { ColorSelect } from "components/colorSelect";
import { TacoInput } from "components/tacoInput";
import { TableCellsIcon as GridIcon } from "lowcoder-design"; //Added By Aqib Mirza

import { ExpandIcon, CompressIcon } from "lowcoder-design";

export type configChangeParams = {
colorKey: string;
color?: string;
radius?: string;
chart?: string;
margin?: string;
padding?: string;
gridColumns?: string; //Added By Aqib Mirza
};

Expand All @@ -23,6 +27,8 @@ type ColorConfigProps = {
radius?: string;
configChange: (params: configChangeParams) => void;
showVarName?: boolean;
margin?: string;
padding?: string;
gridColumns?: string; //Added By Aqib Mirza
};

Expand All @@ -35,12 +41,16 @@ export default function ColorPicker(props: ColorConfigProps) {
radius: defaultRadius,
configChange,
showVarName = true,
margin: defaultMargin,
padding: defaultPadding,
gridColumns: defaultGridColumns, //Added By Aqib Mirza
} = props;
const configChangeWithDebounce = _.debounce(configChange, 0);
const [color, setColor] = useState(defaultColor);
const [radius, setRadius] = useState(defaultRadius);

const [margin, setMargin] = useState(defaultMargin);
const [padding, setPadding] = useState(defaultPadding);
const [gridColumns, setGridColumns] = useState(defaultGridColumns); //Added By Aqib Mirza

const varName = `(${colorKey})`;
Expand Down Expand Up @@ -69,6 +79,35 @@ export default function ColorPicker(props: ColorConfigProps) {
configChange({ colorKey, radius: result });
};

const marginInputBlur = (margin: string) => {
let result = "";
if (!margin || Number(margin) === 0) {
result = "0";
} else if (/^[0-9]+$/.test(margin)) {
result = Number(margin) + "px";
} else if (/^[0-9]+(px|%)$/.test(margin)) {
result = margin;
} else {
result = "3px";
}
setMargin(result);
configChange({ colorKey, margin: result });
};
const paddingInputBlur = (padding: string) => {
let result = "";
if (!padding || Number(padding) === 0) {
result = "0";
} else if (/^[0-9]+$/.test(padding)) {
result = Number(padding) + "px";
} else if (/^[0-9]+(px|%)$/.test(padding)) {
result = padding;
} else {
result = "3px";
}
setPadding(result);
configChange({ colorKey, padding: result });
};

//Added By Aqib Mirza

const gridColumnsInputBlur = (gridColumns: string) => {
Expand Down Expand Up @@ -99,6 +138,13 @@ export default function ColorPicker(props: ColorConfigProps) {
setRadius(defaultRadius);
}, [defaultRadius]);

useEffect(() => {
setMargin(defaultMargin);
}, [defaultMargin]);

useEffect(() => {
setPadding(defaultPadding);
}, [defaultPadding]);
// Added By Aqib Mirza
useEffect(() => {
setGridColumns(defaultGridColumns);
Expand All @@ -113,7 +159,9 @@ export default function ColorPicker(props: ColorConfigProps) {
</div>
<div className="desc">{desc}</div>
</div>
{colorKey !== "borderRadius" &&
{colorKey !== "borderRadius" &&
colorKey !== "margin" &&
colorKey !== "padding" &&
colorKey !== "gridColumns" && (
<div className="config-input">
<ColorSelect
Expand Down Expand Up @@ -147,6 +195,42 @@ export default function ColorPicker(props: ColorConfigProps) {
/>
</div>
)}
{colorKey === "margin" && (
<div className="config-input">
<Margin margin={defaultMargin || "3px"}>
<div>
<ExpandIcon title="" />
</div>
</Margin>
<TacoInput
value={margin}
onChange={(e) => setMargin(e.target.value)}
onBlur={(e) => marginInputBlur(e.target.value)}
onKeyUp={(e) =>
e.nativeEvent.key === "Enter" &&
marginInputBlur(e.currentTarget.value)
}
/>
</div>
)}
{colorKey === "padding" && (
<div className="config-input">
<Padding padding={defaultPadding || "3px"}>
<div>
<CompressIcon title="" />
</div>
</Padding>
<TacoInput
value={padding}
onChange={(e) => setPadding(e.target.value)}
onBlur={(e) => paddingInputBlur(e.target.value)}
onKeyUp={(e) =>
e.nativeEvent.key === "Enter" &&
paddingInputBlur(e.currentTarget.value)
}
/>
</div>
)}
{colorKey === "gridColumns" && (
<div className="config-input">
<GridColumns gridColumns={defaultGridColumns || "24"}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ export function getButtonStyle(buttonStyle: ButtonStyleType) {
const activeColor = genActiveColor(buttonStyle.background);
return css`
border-radius: ${buttonStyle.radius};
margin: ${buttonStyle.margin};
padding: ${buttonStyle.padding};
&:not(:disabled) {
// click animation color
--antd-wave-shadow-color: ${buttonStyle.border};
border-color: ${buttonStyle.border};
color: ${buttonStyle.text};
background-color: ${buttonStyle.background};
border-radius: ${buttonStyle.radius};
margin: ${buttonStyle.margin};
padding: ${buttonStyle.padding};

:hover,
:focus {
Expand All @@ -37,12 +41,14 @@ export function getButtonStyle(buttonStyle: ButtonStyleType) {
: buttonStyle.border};
}
}

`;
}

export const Button100 = styled(Button)<{ $buttonStyle?: ButtonStyleType }>`
${(props) => props.$buttonStyle && getButtonStyle(props.$buttonStyle)}
width: 100%;
width: -webkit-fill-available;
height: auto;
display: inline-flex;
justify-content: center;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,30 @@ const DropdownButton = styled(Dropdown.Button)`

const LeftButtonWrapper = styled.div<{ $buttonStyle: ButtonStyleType }>`
width: calc(100% - 32px);

${(props) => `margin: ${props.$buttonStyle.margin};`}
margin-right: 0;
.ant-btn {
${(props) => getButtonStyle(props.$buttonStyle)}
margin: 0 !important;
height: 100%;
&.ant-btn-default {
margin: 0 !important;
${(props) => `border-radius: ${props.$buttonStyle.radius} 0 0 ${props.$buttonStyle.radius};`}
}
width: 100%;
}
`;

const RightButtonWrapper = styled.div<{ $buttonStyle: ButtonStyleType }>`
width: 32px;
// width: 32px;
${(props) => `margin: ${props.$buttonStyle.margin};`}
margin-left: -1px;

.ant-btn {
${(props) => getButtonStyle(props.$buttonStyle)}
margin: 0 !important;
height: 100%;
&.ant-btn-default {
margin: 0 !important;
${(props) => `border-radius: 0 ${props.$buttonStyle.radius} ${props.$buttonStyle.radius} 0;`}
}
width: 100%;
Expand All @@ -69,6 +76,7 @@ const DropdownTmpComp = (function () {
.map((option, index) => ({
title: option.label,
label: option.label,
style: {padding: props.style.padding},
key: option.label + " - " + index,
disabled: option.disabled,
icon: hasIcon && <span>{option.prefixIcon}</span>,
Expand All @@ -83,6 +91,7 @@ const DropdownTmpComp = (function () {

return (
<ButtonCompWrapper disabled={props.disabled}>
{console.log("props,", props)}
{props.onlyMenu ? (
<Dropdown disabled={props.disabled} overlay={menu}>
<Button100 $buttonStyle={props.style} disabled={props.disabled}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { hasIcon } from "comps/utils";
import { RefControl } from "comps/controls/refControl";

const Link = styled(Button)<{ $style: LinkStyleType }>`
${(props) => `color: ${props.$style.text};`}
${(props) => `color: ${props.$style.text};margin: ${props.$style.margin}; padding: ${props.$style.padding};`}
&.ant-btn {
display: inline-flex;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const disabledTime = (min: string, max: string) => {
export const getStyle = (style: DateTimeStyleType) => {
return css`
border-radius: ${style.radius};

padding: ${style.padding};
&:not(.ant-picker-disabled) {
border-color: ${style.border};
background-color: ${style.background};
Expand Down
13 changes: 12 additions & 1 deletion client/packages/lowcoder/src/comps/comps/dividerComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Section, sectionNames } from "lowcoder-design";
import _ from "lodash";
import styled from "styled-components";
import { styleControl } from "comps/controls/styleControl";
import { DividerStyle, DividerStyleType } from "comps/controls/styleControlConstants";
import { DividerStyle, DividerStyleType, heightCalculator, widthCalculator } from "comps/controls/styleControlConstants";
import { migrateOldData } from "comps/generators/simpleGenerators";
import { hiddenPropertyView } from "comps/utils/propertyUtils";
import { trans } from "i18n";
Expand All @@ -22,6 +22,17 @@ const StyledDivider = styled(Divider)<IProps>`
display: flex;
align-items: center;
}
min-width: 0;
width: ${(props) => {
return widthCalculator(props.$style.margin);
}};
min-height: ${(props) => {
return heightCalculator(props.$style.margin);
}};
margin: ${(props) => {
return props.$style.margin;
}};
padding: ${(props) => props.$style.padding};
border-top: 1px ${(props) => (props.dashed ? "dashed" : "solid")} ${(props) => props.$style.color};

&.ant-divider-horizontal.ant-divider-with-text {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { darkenColor } from "components/colorSelect/colorUtils";
import { Section, sectionNames } from "components/Section";
import { IconControl } from "comps/controls/iconControl";
import { styleControl } from "comps/controls/styleControl";
import { FileStyle, FileStyleType } from "comps/controls/styleControlConstants";
import { FileStyle, FileStyleType, heightCalculator, widthCalculator } from "comps/controls/styleControlConstants";
import { withMethodExposing } from "comps/generators/withMethodExposing";
import { hasIcon } from "comps/utils";
import { getComponentDocUrl } from "comps/utils/compDocUtil";
Expand Down Expand Up @@ -133,6 +133,10 @@ const getStyle = (style: FileStyleType) => {
return css`
.ant-btn {
border-radius: ${style.radius};
margin: ${style.margin};
padding: ${style.padding};
width: ${widthCalculator(style.margin)};
height: ${heightCalculator(style.margin)};
}

.ant-btn:not(:disabled) {
Expand Down
7 changes: 6 additions & 1 deletion client/packages/lowcoder/src/comps/comps/fileViewerComp.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { styleControl } from "comps/controls/styleControl";
import { FileViewerStyle, FileViewerStyleType } from "comps/controls/styleControlConstants";
import { FileViewerStyle, FileViewerStyleType, heightCalculator, widthCalculator } from "comps/controls/styleControlConstants";
import { isEmpty } from "lodash";
import { useState } from "react";
import { DocumentViewer } from "react-documents";
Expand All @@ -13,6 +13,11 @@ import { trans } from "i18n";

const getStyle = (style: FileViewerStyleType) => {
return css`
width: ${widthCalculator(style.margin)};
height: ${heightCalculator(style.margin)};
margin: ${style.margin};
padding: ${style.padding};

overflow: hidden;
background-color: ${style.background};
border: 1px solid ${style.border};
Expand Down
7 changes: 5 additions & 2 deletions client/packages/lowcoder/src/comps/comps/imageComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useEffect, useRef, useState } from "react";
import _ from "lodash";
import ReactResizeDetector from "react-resize-detector";
import { styleControl } from "comps/controls/styleControl";
import { ImageStyle, ImageStyleType } from "comps/controls/styleControlConstants";
import { ImageStyle, ImageStyleType, heightCalculator, widthCalculator } from "comps/controls/styleControlConstants";
import { hiddenPropertyView } from "comps/utils/propertyUtils";
import { trans } from "i18n";
import { AutoHeightControl } from "comps/controls/autoHeightControl";
Expand All @@ -23,7 +23,6 @@ const Container = styled.div<{ $style: ImageStyleType | undefined }>`
display: flex;
align-items: center;
justify-content: center;

.ant-image,
img {
width: 100%;
Expand All @@ -43,6 +42,10 @@ const getStyle = (style: ImageStyleType) => {
img {
border: 1px solid ${style.border};
border-radius: ${style.radius};
margin: ${style.margin};
padding: ${style.padding};
max-width: ${widthCalculator(style.margin)};
max-height: ${heightCalculator(style.margin)};
}

.ant-image-mask {
Expand Down
Loading