Skip to content

Commit f728973

Browse files
author
FalkWolsky
committed
Drawer and Modal with title. Fixes #557
1 parent 7e6cf30 commit f728973

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

client/packages/lowcoder/src/comps/hooks/drawerComp.tsx

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AutoHeightControl } from "comps/controls/autoHeightControl";
66
import { BoolControl } from "comps/controls/boolControl";
77
import { StringControl } from "comps/controls/codeControl";
88
import { booleanExposingStateControl } from "comps/controls/codeStateControl";
9-
import { PositionControl, LeftRightControl } from "comps/controls/dropdownControl";
9+
import { PositionControl, LeftRightControl, HorizontalAlignmentControl } from "comps/controls/dropdownControl";
1010
import { closeEvent, eventHandlerControl } from "comps/controls/eventHandlerControl";
1111
import { styleControl } from "comps/controls/styleControl";
1212
import { DrawerStyle } from "comps/controls/styleControlConstants";
@@ -24,6 +24,7 @@ import styled from "styled-components";
2424
import { useUserViewMode } from "util/hooks";
2525
import { isNumeric } from "util/stringUtils";
2626
import { NameConfig, withExposingConfigs } from "../generators/withExposing";
27+
import { title } from "process";
2728

2829
const EventOptions = [closeEvent] as const;
2930

@@ -33,12 +34,23 @@ const DEFAULT_PADDING = 16;
3334
const DrawerWrapper = styled.div`
3435
// Shield the mouse events of the lower layer, the mask can be closed in the edit mode to prevent the lower layer from sliding
3536
pointer-events: auto;
37+
.ant-drawer-header-title {
38+
margin: 0px 20px !important;
39+
font-size: 16px;
40+
}
3641
`;
3742

38-
const ButtonStyle = styled(Button)<{$closePosition?: string}>`
43+
const StyledDrawer = styled(Drawer)<{$titleAlign?: string}>`
44+
.ant-drawer-header-title {
45+
margin: 0px 20px !important;
46+
text-align: ${(props) => props.$titleAlign || "center"};
47+
}
48+
`;
49+
50+
const ButtonStyle = styled(Button)<{$closePosition?: string, $title? :string}>`
3951
position: absolute;
4052
${(props) => props.$closePosition === "right" ? "right: 0;" : "left: 0;"}
41-
top: 0;
53+
top: ${(props) => props.$title !== "" ? "2px" : "0px"};
4254
z-index: 10;
4355
font-weight: 700;
4456
box-shadow: none;
@@ -69,44 +81,15 @@ function transToPxSize(size: string | number) {
6981
return isNumeric(size) ? size + "px" : (size as string);
7082
}
7183

72-
const ClosePlacementOptions = [
73-
{
74-
label: trans("drawer.left"),
75-
value: "left",
76-
},
77-
{
78-
label: trans("drawer.right"),
79-
value: "right",
80-
},
81-
] as const;
82-
83-
const PlacementOptions = [
84-
{
85-
label: trans("drawer.top"),
86-
value: "top",
87-
},
88-
{
89-
label: trans("drawer.right"),
90-
value: "right",
91-
},
92-
{
93-
label: trans("drawer.bottom"),
94-
value: "bottom",
95-
},
96-
{
97-
label: trans("drawer.left"),
98-
value: "left",
99-
},
100-
] as const;
101-
102-
10384
let TmpDrawerComp = (function () {
10485
return new ContainerCompBuilder(
10586
{
10687
visible: booleanExposingStateControl("visible"),
10788
onEvent: eventHandlerControl(EventOptions),
10889
width: StringControl,
10990
height: StringControl,
91+
title: StringControl,
92+
titleAlign: HorizontalAlignmentControl,
11093
autoHeight: AutoHeightControl,
11194
style: styleControl(DrawerStyle),
11295
placement: PositionControl,
@@ -135,7 +118,7 @@ let TmpDrawerComp = (function () {
135118
return (
136119
<BackgroundColorContext.Provider value={props.style.background}>
137120
<DrawerWrapper>
138-
<Drawer
121+
<StyledDrawer
139122
resizable={resizable}
140123
onResizeStop={onResizeStop}
141124
rootStyle={props.visible.value ? { overflow: "auto", pointerEvents: "auto" } : {}}
@@ -149,6 +132,8 @@ let TmpDrawerComp = (function () {
149132
backgroundColor: props.style.background
150133
}
151134
}}
135+
title={props.title}
136+
$titleAlign={props.titleAlign}
152137
closable={false}
153138
placement={props.placement}
154139
open={props.visible.value}
@@ -188,7 +173,7 @@ let TmpDrawerComp = (function () {
188173
hintPlaceholder={HintPlaceHolder}
189174
bgColor={props.style.background}
190175
/>
191-
</Drawer>
176+
</StyledDrawer>
192177
</DrawerWrapper>
193178
</BackgroundColorContext.Provider>
194179
);
@@ -197,6 +182,8 @@ let TmpDrawerComp = (function () {
197182
.setPropertyViewFn((children) => (
198183
<>
199184
<Section name={sectionNames.basic}>
185+
{children.title.propertyView({ label: trans("drawer.title") })}
186+
{children.title.getView() && children.titleAlign.propertyView({ label: trans("drawer.titleAlign"), radioButton: true })}
200187
{children.closePosition.propertyView({ label: trans("drawer.closePosition"), radioButton: true })}
201188
{children.placement.propertyView({ label: trans("drawer.placement"), radioButton: true })}
202189
{["top", "bottom"].includes(children.placement.getView())

client/packages/lowcoder/src/comps/hooks/modalComp.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { StringControl } from "comps/controls/codeControl";
55
import { booleanExposingStateControl } from "comps/controls/codeStateControl";
66
import { eventHandlerControl } from "comps/controls/eventHandlerControl";
77
import { styleControl } from "comps/controls/styleControl";
8+
import { HorizontalAlignmentControl } from "comps/controls/dropdownControl";
89
import { ModalStyle, ModalStyleType } from "comps/controls/styleControlConstants";
910
import { withMethodExposing } from "comps/generators/withMethodExposing";
1011
import { BackgroundColorContext } from "comps/utils/backgroundColorContext";
@@ -47,11 +48,19 @@ const getStyle = (style: ModalStyleType) => {
4748
}
4849
}
4950
.ant-modal-close {
50-
inset-inline-end: 7px !important;
51+
inset-inline-end: 10px !important;
52+
top: 10px;
5153
}
5254
`;
5355
};
5456

57+
const StyledModal = styled(Modal)<{$titleAlign?: string}>`
58+
.ant-modal-title {
59+
margin: 0px 20px !important;
60+
text-align: ${(props) => props.$titleAlign || "center"};
61+
}
62+
`;
63+
5564
const DEFAULT_WIDTH = "60%";
5665
const DEFAULT_HEIGHT = 222;
5766

@@ -91,6 +100,8 @@ let TmpModalComp = (function () {
91100
width: StringControl,
92101
height: StringControl,
93102
autoHeight: AutoHeightControl,
103+
title: StringControl,
104+
titleAlign: HorizontalAlignmentControl,
94105
style: styleControl(ModalStyle),
95106
maskClosable: withDefault(BoolControl, true),
96107
showMask: withDefault(BoolControl, true),
@@ -135,7 +146,7 @@ let TmpModalComp = (function () {
135146
return (
136147
<BackgroundColorContext.Provider value={props.style.background}>
137148
<ModalWrapper>
138-
<Modal
149+
<StyledModal
139150
height={height}
140151
resizeHandles={resizeHandles}
141152
onResizeStop={onResizeStop}
@@ -145,6 +156,8 @@ let TmpModalComp = (function () {
145156
getContainer={() => document.querySelector(`#${CanvasContainerID}`) || document.body}
146157
footer={null}
147158
styles={{body: bodyStyle}}
159+
title={props.title}
160+
$titleAlign={props.titleAlign}
148161
width={width}
149162
onCancel={(e) => {
150163
props.visible.onChange(false);
@@ -166,7 +179,7 @@ let TmpModalComp = (function () {
166179
containerPadding={paddingValues ? [paddingValues[0] ?? 0, paddingValues[1] ?? 0] : [24,24]}
167180
hintPlaceholder={HintPlaceHolder}
168181
/>
169-
</Modal>
182+
</StyledModal>
170183
</ModalWrapper>
171184
</BackgroundColorContext.Provider>
172185
);
@@ -175,6 +188,8 @@ let TmpModalComp = (function () {
175188
.setPropertyViewFn((children) => (
176189
<>
177190
<Section name={sectionNames.basic}>
191+
{children.title.propertyView({ label: trans("drawer.title") })}
192+
{children.title.getView() && children.titleAlign.propertyView({ label: trans("drawer.titleAlign"), radioButton: true })}
178193
{children.autoHeight.getPropertyView()}
179194
{!children.autoHeight.getView() &&
180195
children.height.propertyView({

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,8 +2128,11 @@ export const en = {
21282128
"size": "Size",
21292129
"top": "Top",
21302130
"right": "Right",
2131+
"center": "Center",
21312132
"bottom": "Bottom",
21322133
"left": "Left",
2134+
"title": "Drawer Title",
2135+
"titleAlign": "Title Alignment",
21332136
"widthTooltip": "Pixel or Percentage, e.g. 520, 60%",
21342137
"heightTooltip": "Pixel, e.g. 378",
21352138
"openDrawerDesc": "Open Drawer",

0 commit comments

Comments
 (0)