Skip to content

Adding Shapes Component #854

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 27 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
10d27dc
initial shape component
freddysundowner Apr 18, 2024
840678f
Merge branch 'dev' of https://github.com/lowcoder-org/lowcoder into f…
freddysundowner Apr 18, 2024
6842c4f
merged from dev
freddysundowner Apr 18, 2024
cd3d37f
initial shape component
freddysundowner Apr 18, 2024
06d6458
selecting active shape
freddysundowner Apr 19, 2024
c0325fe
selecting active shape
freddysundowner Apr 19, 2024
7e190ed
aa
freddysundowner Apr 24, 2024
cd4f98b
fixed shape width and height, added default icon selection
freddysundowner Apr 27, 2024
a78fbe1
added icons lables
freddysundowner May 6, 2024
4ac855d
added grid too shapes comp and lables to shapes lists
freddysundowner May 6, 2024
acda8fe
referencing forked coolshapes package
freddysundowner May 6, 2024
e1a49c4
added grid too shapes comp and lables to shapes lists
freddysundowner May 6, 2024
578899e
initial shape component
freddysundowner Apr 18, 2024
e9d4aa4
initial shape component
freddysundowner Apr 18, 2024
be62b7d
selecting active shape
freddysundowner Apr 19, 2024
ebc66fe
selecting active shape
freddysundowner Apr 19, 2024
b07fee5
aa
freddysundowner Apr 24, 2024
b19c9bc
fixed shape width and height, added default icon selection
freddysundowner Apr 27, 2024
e5e1e2a
added icons lables
freddysundowner May 6, 2024
9e2f907
added grid too shapes comp and lables to shapes lists
freddysundowner May 6, 2024
bcd1211
referencing forked coolshapes package
freddysundowner May 6, 2024
5665218
added grid too shapes comp and lables to shapes lists
freddysundowner May 6, 2024
9143dd5
lazy load shapes comp
raheeliftikhar5 May 9, 2024
7dab708
removed console
raheeliftikhar5 May 9, 2024
307668c
Merge branch 'feat-ShapeComp' of https://github.com/lowcoder-org/lowc…
freddysundowner May 9, 2024
84ba449
fixed drag items to shape comp
freddysundowner May 10, 2024
b156fc0
Merge branch 'dev' into feat-ShapeComp
FalkWolsky May 11, 2024
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
487 changes: 487 additions & 0 deletions client/packages/lowcoder-design/src/components/shapeSelect/index.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const en = {
advanced: "Advanced",
validation: "Validation",
layout: "Layout",
labelStyle:"Label Style",
labelStyle: "Label Style",
style: "Style",
meetings: "Meeting Settings",
data: "Data",
Expand Down Expand Up @@ -54,6 +54,10 @@ export const en = {
title: "Select icon",
searchPlaceholder: "Search icon",
},
shapeSelect: {
title: "Select shape",
searchPlaceholder: "Search shape",
},
eventHandler: {
advanced: "Advanced",
},
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder-design/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export * from "./components/tacoInput";
export * from "./components/tacoPagination";
export * from "./components/toolTip";
export * from "./components/video";
export * from "./components/shapeSelect";

export * from "./icons";

Expand Down
3 changes: 2 additions & 1 deletion client/packages/lowcoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"buffer": "^6.0.3",
"clsx": "^2.0.0",
"cnchar": "^3.2.4",
"coolshapes-react": "lowcoder-org/coolshapes-react",
"copy-to-clipboard": "^3.3.3",
"core-js": "^3.25.2",
"echarts": "^5.4.3",
Expand Down Expand Up @@ -129,4 +130,4 @@
"vite-plugin-svgr": "^2.2.2",
"vite-tsconfig-paths": "^3.6.0"
}
}
}
159 changes: 159 additions & 0 deletions client/packages/lowcoder/src/comps/comps/shapeComp/shapeComp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { CompParams } from "lowcoder-core";
import { ToDataType } from "comps/generators/multi";
import {
NameConfigHidden,
withExposingConfigs,
} from "comps/generators/withExposing";
import { NameGenerator } from "comps/utils/nameGenerator";
import { Section, sectionNames } from "lowcoder-design";
import { oldContainerParamsToNew } from "../containerBase";
import { toSimpleContainerData } from "../containerBase/simpleContainerComp";
import { ShapeTriContainer } from "./shapeTriContainer";
import { ShapeControl } from "comps/controls/shapeControl";
import { withDefault } from "../../generators";
import {
ContainerChildren,
ContainerCompBuilder,
} from "../triContainerComp/triContainerCompBuilder";
import {
disabledPropertyView,
hiddenPropertyView,
} from "comps/utils/propertyUtils";
import { trans } from "i18n";
import { BoolCodeControl } from "comps/controls/codeControl";
import { DisabledContext } from "comps/generators/uiCompBuilder";
import React, { useContext, useEffect, useState } from "react";
import { EditorContext } from "comps/editorState";

export const ContainerBaseComp = (function () {
const childrenMap = {
disabled: BoolCodeControl,
icon: withDefault(ShapeControl, ""),
};
return new ContainerCompBuilder(childrenMap, (props, dispatch) => {


return (
<DisabledContext.Provider value={props.disabled}>
<ShapeTriContainer {...props} />
</DisabledContext.Provider>
);
})
.setPropertyViewFn((children) => {
return (
<>
<Section name={sectionNames.basic}>
{children.icon.propertyView({
label: trans("iconComp.icon"),
IconType: "All",
})}
</Section>
{(useContext(EditorContext).editorModeStatus === "logic" ||
useContext(EditorContext).editorModeStatus === "both") && (
<Section name={sectionNames.interaction}>
{disabledPropertyView(children)}
{hiddenPropertyView(children)}
</Section>
)}

{(useContext(EditorContext).editorModeStatus === "layout" ||
useContext(EditorContext).editorModeStatus === "both") && (
<>
<Section name={sectionNames.layout}>
{children.container.getPropertyView()}
</Section>
<Section name={sectionNames.style}>
{children.container.stylePropertyView()}
</Section>
{children.container.children.showHeader.getView() && (
<Section name={"Header Style"}>
{children.container.headerStylePropertyView()}
</Section>
)}
{children.container.children.showBody.getView() && (
<Section name={"Body Style"}>
{children.container.bodyStylePropertyView()}
</Section>
)}
{children.container.children.showFooter.getView() && (
<Section name={"Footer Style"}>
{children.container.footerStylePropertyView()}
</Section>
)}
</>
)}
</>
);
})
.build();
})();

// Compatible with old data
function convertOldContainerParams(params: CompParams<any>) {
// convert older params to old params
let tempParams = oldContainerParamsToNew(params);

if (tempParams.value) {
const container = tempParams.value.container;
// old params
if (
container &&
(container.hasOwnProperty("layout") || container.hasOwnProperty("items"))
) {
const autoHeight = tempParams.value.autoHeight;
const scrollbars = tempParams.value.scrollbars;
return {
...tempParams,
value: {
container: {
showHeader: true,
body: { 0: { view: container } },
showBody: true,
showFooter: false,
autoHeight: autoHeight,
scrollbars: scrollbars,
},
},
};
}
}
return tempParams;
}

class ContainerTmpComp extends ContainerBaseComp {
constructor(params: CompParams<any>) {
super(convertOldContainerParams(params));
}
}

export const ShapeComp = withExposingConfigs(ContainerTmpComp, [NameConfigHidden]);

type ContainerDataType = ToDataType<ContainerChildren<{}>>;

export function defaultContainerData(
compName: string,
nameGenerator: NameGenerator
): ContainerDataType {
return {
container: {
header: toSimpleContainerData([
{
item: {
compType: "text",
name: nameGenerator.genItemName("containerTitle"),
comp: {
text: "### " + trans("container.title"),
},
},
layoutItem: {
i: "",
h: 5,
w: 24,
x: 0,
y: 0,
},
},
]),
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { ContainerStyleType } from "comps/controls/styleControlConstants";
import { EditorContext } from "comps/editorState";
import { BackgroundColorContext } from "comps/utils/backgroundColorContext";
import { HintPlaceHolder, ScrollBar } from "lowcoder-design";
import { ReactNode, useContext, useEffect, useState } from "react";
import styled, { css } from "styled-components";
import { checkIsMobile } from "util/commonUtils";
import {
gridItemCompToGridItems,
InnerGrid,
} from "../containerComp/containerView";
import { TriContainerViewProps } from "../triContainerComp/triContainerCompBuilder";
import { Coolshape } from "coolshapes-react";

const getStyle = (style: ContainerStyleType) => {
return css`
border-color: ${style.border};
border-width: ${style.borderWidth};
border-radius: ${style.radius};
overflow: hidden;
padding: ${style.padding};
${style.background && `background-color: ${style.background};`}
${style.backgroundImage && `background-image: ${style.backgroundImage};`}
${style.backgroundImageRepeat &&
`background-repeat: ${style.backgroundImageRepeat};`}
${style.backgroundImageSize &&
`background-size: ${style.backgroundImageSize};`}
${style.backgroundImagePosition &&
`background-position: ${style.backgroundImagePosition};`}
${style.backgroundImageOrigin &&
`background-origin: ${style.backgroundImageOrigin};`}
`;
};

const Wrapper = styled.div<{ $style: ContainerStyleType }>`
display: flex;
flex-flow: column;
height: 100%;
border: 1px solid #d7d9e0;
border-radius: 4px;
${(props) => props.$style && getStyle(props.$style)}
`;

const BodyInnerGrid = styled(InnerGrid)<{
$showBorder: boolean;
$backgroundColor: string;
$borderColor: string;
$borderWidth: string;
$backgroundImage: string;
$backgroundImageRepeat: string;
$backgroundImageSize: string;
$backgroundImagePosition: string;
$backgroundImageOrigin: string;
}>`
border-top: ${(props) =>
`${props.$showBorder ? props.$borderWidth : 0} solid ${props.$borderColor}`};
flex: 1;
${(props) =>
props.$backgroundColor && `background-color: ${props.$backgroundColor};`}
border-radius: 0;
${(props) =>
props.$backgroundImage && `background-image: ${props.$backgroundImage};`}
${(props) =>
props.$backgroundImageRepeat &&
`background-repeat: ${props.$backgroundImageRepeat};`}
${(props) =>
props.$backgroundImageSize &&
`background-size: ${props.$backgroundImageSize};`}
${(props) =>
props.$backgroundImagePosition &&
`background-position: ${props.$backgroundImagePosition};`}
${(props) =>
props.$backgroundImageOrigin &&
`background-origin: ${props.$backgroundImageOrigin};`}
`;

export type TriContainerProps = TriContainerViewProps & {
hintPlaceholder?: ReactNode;
icon: any;
};

export function ShapeTriContainer(props: TriContainerProps) {
const { container, icon } = props;
const { showHeader, showFooter } = container;
// When the header and footer are not displayed, the body must be displayed
const showBody = container.showBody || (!showHeader && !showFooter);
const scrollbars = container.scrollbars;

const { items: headerItems, ...otherHeaderProps } = container.header;
const { items: bodyItems, ...otherBodyProps } =
container.body["0"].children.view.getView();
const { items: footerItems, ...otherFooterProps } = container.footer;
const { style, headerStyle, bodyStyle, footerStyle } = container;

const editorState = useContext(EditorContext);
const maxWidth = editorState.getAppSettings().maxWidth;
const isMobile = checkIsMobile(maxWidth);
const paddingWidth = isMobile ? 8 : 0;

let [shape, setShape] = useState({ value: "star", index: 0 });
useEffect(() => {
if (icon.props?.value) {
let shapeDetails = icon.props?.value;
setShape({
index: parseInt(shapeDetails?.split("_")[0]),
value: shapeDetails?.split("_")[1],
});
}
}, [icon.props]);

return (
<div style={{ padding: style.margin, height: "100%" }}>
<Wrapper $style={style}>
<BackgroundColorContext.Provider value={bodyStyle.background}>
<ScrollBar
style={{
height: container.autoHeight ? "auto" : "100%",
margin: "0px",
padding: "0px",
}}
hideScrollbar={!scrollbars}
>
<div style={{ position: "relative", height: "100%" }}>
<Coolshape
type={shape?.value as any}
index={shape.index}
styles={{
position: "absolute",
top: "0",
left: "50%",
transform: "translateX(-50%)",
}}
/>
<BodyInnerGrid
$showBorder={false}
{...otherBodyProps}
items={gridItemCompToGridItems(bodyItems)}
autoHeight={container.autoHeight}
emptyRows={14}
minHeight={"142px"}
hintPlaceholder={props.hintPlaceholder ?? HintPlaceHolder}
$backgroundColor={bodyStyle?.background || "transparent"}
$borderColor={style?.border}
$borderWidth={style?.borderWidth}
$backgroundImage={bodyStyle?.backgroundImage}
$backgroundImageRepeat={bodyStyle?.backgroundImageRepeat}
$backgroundImageSize={bodyStyle?.backgroundImageSize}
$backgroundImagePosition={bodyStyle?.backgroundImagePosition}
$backgroundImageOrigin={bodyStyle?.backgroundImageOrigin}
style={{
zIndex: 999,
}}
/>
</div>
</ScrollBar>
</BackgroundColorContext.Provider>
</Wrapper>
</div>
);
}
Loading
Loading