Skip to content

Commit d9a49a7

Browse files
Merge pull request #988 from MenamAfzal/feature/add-event-handler
Event handler added
2 parents ace9e1e + 23767c4 commit d9a49a7

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

client/packages/lowcoder/src/comps/comps/layout/mobileTabLayout.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
3030
import { AlignCenter } from "lowcoder-design";
3131
import { AlignLeft } from "lowcoder-design";
3232
import { AlignRight } from "lowcoder-design";
33+
import { LayoutActionComp } from "./layoutActionComp";
34+
import { clickEvent, eventHandlerControl } from "@lowcoder-ee/index.sdk";
3335

3436
const TabBar = React.lazy(() => import("antd-mobile/es/components/tab-bar"));
3537
const TabBarItem = React.lazy(() =>
3638
import("antd-mobile/es/components/tab-bar/tab-bar").then((module) => ({
3739
default: module.TabBarItem,
3840
}))
3941
);
42+
const EventOptions = [clickEvent] as const;
4043

4144
const AppViewContainer = styled.div`
4245
position: absolute;
@@ -171,6 +174,7 @@ type JsonItemNode = {
171174
}
172175

173176
type TabBarProps = {
177+
onEvent:any;
174178
tabs: Array<{
175179
title: string;
176180
icon?: React.ReactNode;
@@ -224,6 +228,7 @@ function TabBarView(props: TabBarProps & {
224228
<StyledTabBar
225229
onChange={(key: string) => {
226230
if (key) {
231+
props.onEvent('click')
227232
props.onChange(key);
228233
}
229234
}}
@@ -250,6 +255,7 @@ const TabOptionComp = (function () {
250255
return new MultiCompBuilder(
251256
{
252257
app: AppSelectComp,
258+
action: LayoutActionComp,
253259
label: StringControl,
254260
icon: IconControl,
255261
hidden: BoolCodeControl,
@@ -261,12 +267,16 @@ const TabOptionComp = (function () {
261267
.setPropertyViewFn((children, dispatch) => {
262268
return (
263269
<>
264-
{children.app.propertyView({})}
270+
{children.action.propertyView({
271+
onAppChange: (label:any) => {
272+
label && children.label.dispatchChangeValueAction(label);
273+
},
274+
})}
265275
{children.label.propertyView({ label: trans("label") })}
266276
{hiddenPropertyView(children)}
267277
{children.icon.propertyView({
268-
label: trans("icon"),
269-
tooltip: trans("aggregation.iconTooltip"),
278+
label: trans('icon'),
279+
tooltip: trans('aggregation.iconTooltip'),
270280
})}
271281
</>
272282
);
@@ -276,8 +286,9 @@ const TabOptionComp = (function () {
276286

277287
let MobileTabLayoutTmp = (function () {
278288
const childrenMap = {
289+
onEvent: eventHandlerControl(EventOptions),
279290
dataOptionType: dropdownControl(DataOptionType, DataOption.Manual),
280-
jsonItems: jsonControl<JsonItemNode[]>(convertTreeData, mobileNavJsonMenuItems),
291+
jsonItems: jsonControl<JsonItemNode[]>(convertTreeData, mobileNavJsonMenuItems),
281292
tabs: manualOptionsControl(TabOptionComp, {
282293
initOptions: [
283294
{
@@ -328,6 +339,9 @@ let MobileTabLayoutTmp = (function () {
328339
})
329340
}
330341
</Section>
342+
<Section name={trans("eventHandler.eventHandlers")}>
343+
{ children.onEvent.getPropertyView() }
344+
</Section>
331345
<Section name={sectionNames.layout}>
332346
{children.backgroundImage.propertyView({
333347
label: `Background Image`,
@@ -385,6 +399,7 @@ MobileTabLayoutTmp = withViewFn(MobileTabLayoutTmp, (comp) => {
385399
const verticalAlignment = comp.children.verticalAlignment.getView();
386400
const showSeparator = comp.children.showSeparator.getView();
387401
const bgColor = (useContext(ThemeContext)?.theme || defaultTheme).canvas;
402+
const onEvent = comp.children.onEvent.getView();
388403

389404
useEffect(() => {
390405
comp.children.jsonTabs.dispatchChangeValueAction({
@@ -428,6 +443,7 @@ MobileTabLayoutTmp = withViewFn(MobileTabLayoutTmp, (comp) => {
428443

429444
const tabBarView = (
430445
<TabBarView
446+
onEvent={onEvent}
431447
tabs={tabViews.map((tab, index) => ({
432448
key: index,
433449
title: tab.children.label.getView(),

client/packages/lowcoder/src/comps/comps/layout/navLayout.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ import {
4040
jsonMenuItems,
4141
menuItemStyleOptions
4242
} from "./navLayoutConstants";
43+
import { clickEvent, eventHandlerControl } from "@lowcoder-ee/index.sdk";
4344

4445
const { Header } = Layout;
4546

4647
const DEFAULT_WIDTH = 240;
4748
type MenuItemStyleOptionValue = "normal" | "hover" | "active";
49+
const EventOptions = [clickEvent] as const;
4850

4951
const StyledSide = styled(LayoutSider)`
5052
max-height: calc(100vh - ${TopHeaderHeight});
@@ -183,6 +185,7 @@ function convertTreeData(data: any) {
183185

184186
let NavTmpLayout = (function () {
185187
const childrenMap = {
188+
onEvent: eventHandlerControl(EventOptions),
186189
dataOptionType: dropdownControl(DataOptionType, DataOption.Manual),
187190
items: withDefault(LayoutMenuItemListComp, [
188191
{
@@ -221,6 +224,9 @@ let NavTmpLayout = (function () {
221224
})
222225
}
223226
</Section>
227+
<Section name={trans("eventHandler.eventHandlers")}>
228+
{ children.onEvent.getPropertyView() }
229+
</Section>
224230
<Section name={sectionNames.layout}>
225231
{ children.width.propertyView({
226232
label: trans("navLayout.width"),
@@ -282,7 +288,8 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
282288
const backgroundImage = comp.children.backgroundImage.getView();
283289
const jsonItems = comp.children.jsonItems.getView();
284290
const dataOptionType = comp.children.dataOptionType.getView();
285-
291+
const onEvent = comp.children.onEvent.getView();
292+
286293
// filter out hidden. unauthorised items filtered by server
287294
const filterItem = useCallback((item: LayoutMenuItemComp): boolean => {
288295
return !item.children.hidden.getView();
@@ -319,7 +326,8 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
319326
return generateItemKeyRecord(items)
320327
}, [dataOptionType, jsonItems, items, generateItemKeyRecord]);
321328

322-
const onMenuItemClick = useCallback(({key}: {key: string}) => {
329+
const onMenuItemClick = useCallback(({ key }: { key: string }) => {
330+
onEvent('click')
323331
const itemComp = itemKeyRecord[key]
324332

325333
const url = [

client/packages/lowcoder/src/comps/comps/textComp.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import { PaddingControl } from "../controls/paddingControl";
2020

2121
import React, { useContext } from "react";
2222
import { EditorContext } from "comps/editorState";
23+
import { clickEvent, eventHandlerControl } from "../controls/eventHandlerControl";
24+
25+
const EventOptions = [clickEvent] as const;
2326

2427
const getStyle = (style: TextStyleType) => {
2528
return css`
@@ -126,6 +129,7 @@ let TextTmpComp = (function () {
126129
"text",
127130
trans("textShow.text", { name: "{{currentUser.name}}" })
128131
),
132+
onEvent: eventHandlerControl(EventOptions),
129133
autoHeight: AutoHeightControl,
130134
type: dropdownControl(typeOptions, "markdown"),
131135
horizontalAlignment: alignWithJustifyControl(),
@@ -148,6 +152,7 @@ let TextTmpComp = (function () {
148152
textAlign: props.horizontalAlignment,
149153
rotate: props.style.rotation
150154
}}
155+
onClick={() => props.onEvent("click")}
151156
>
152157
{props.type === "markdown" ? <TacoMarkDown>{value}</TacoMarkDown> : value}
153158
</TextContainer>
@@ -168,6 +173,7 @@ let TextTmpComp = (function () {
168173
{["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && (
169174
<Section name={sectionNames.interaction}>
170175
{hiddenPropertyView(children)}
176+
{children.onEvent.getPropertyView()}
171177
</Section>
172178
)}
173179

0 commit comments

Comments
 (0)