Skip to content

Commit 2bcb92a

Browse files
kanban drag/edit header on hover + fixed styles not applying
1 parent 615379a commit 2bcb92a

File tree

2 files changed

+103
-39
lines changed

2 files changed

+103
-39
lines changed

lowcoder-comp-kanban/src/kanbanCompView.tsx

Lines changed: 98 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,25 @@ registerLicense(
2626
"ORg4AjUWIQA/Gnt2UFhhQlJBfV5AQmBIYVp/TGpJfl96cVxMZVVBJAtUQF1hTX5Vd0ViX3pfdXRRR2VY"
2727
);
2828

29-
const Wrapper = styled.div<{}>`
29+
const Wrapper = styled.div<{
30+
$bgColor?: string;
31+
}>`
3032
position: relative;
3133
height: 100%;
3234
width: 100%;
35+
overflow: hidden;
36+
${(props) => props.$bgColor && `background: ${props.$bgColor};`}
3337
`;
3438

3539
const LayoutContainer = styled.div<{
3640
$bgColor?: string;
3741
$autoHeight?: boolean;
3842
$overflow?: string;
3943
$radius?: string;
44+
$padding?: string;
4045
}>`
4146
height: ${(props: any) => (props.$autoHeight ? "auto" : "100%")};
42-
width:"100%";
47+
width: 100%;
4348
4449
overflow: auto;
4550
${(props: any) =>
@@ -52,43 +57,67 @@ const LayoutContainer = styled.div<{
5257
padding-top: 24px !important;
5358
}
5459
55-
.e-card {
56-
overflow: visible;
57-
}
58-
`;
59-
60-
const StyledEditIcon = styled(TextEditIcon)`
61-
g g {
62-
fill: #ffffff;
63-
}
64-
`;
65-
66-
const StyledDragIcon = styled(DragIcon)`
67-
g g {
68-
fill: #ffffff;
69-
}
60+
${(props) => props.$padding && `
61+
.e-kanban .e-kanban-content .e-content-row .e-content-cells .e-card-wrapper .e-card {
62+
.card-template {
63+
.e-card-header {
64+
padding-left: 0;
65+
padding-right: 0;
66+
}
67+
.e-card-content {
68+
padding-left: 0;
69+
padding-right: 0;
70+
}
71+
.e-card-custom-footer {
72+
padding-left: 0;
73+
padding-right: 0;
74+
}
75+
}
76+
}
77+
`}
7078
`;
7179

7280
const CardActions = styled.div`
7381
display: flex;
82+
justify-content: space-between;
7483
position: absolute;
75-
top: -20px;
84+
top: 0;
7685
right: 0;
86+
width: 100%;
7787
line-height: 16px;
78-
font-size: 12px;
79-
background: #3377ff;
80-
color: white;
81-
border-top-left-radius: 3px;
82-
border-top-right-radius: 3px;
88+
font-size: 14px;
89+
padding: 12px 0px;
90+
box-shadow: 0 2px 6px 2px rgba(0, 0, 0, 0.15), 0 1px 2px 0 rgba(0, 0, 0, 0.3);
91+
background: #f5f5f7;
92+
align-items: center;
93+
z-index: 999;
8394
8495
.editAction {
85-
padding: 2px 6px;
86-
border-right: 1px solid white;
96+
padding: 2px 8px;
8797
cursor: pointer;
98+
color: #3377ff;
99+
font-weight: 500;
88100
}
89101
90102
.dragAction {
103+
font-weight: bold;
91104
padding: 2px 6px;
105+
display: flex;
106+
align-items: center;
107+
flex: 1;
108+
min-width: 0;
109+
110+
svg {
111+
min-width: 20px;
112+
height: 20px;
113+
}
114+
115+
span {
116+
width: 100%;
117+
white-space: nowrap;
118+
text-overflow: ellipsis;
119+
overflow: hidden;
120+
}
92121
}
93122
`;
94123

@@ -158,43 +187,64 @@ const CardTemplate = React.memo((props: {
158187

159188
if (props.isEditorStateAvailable && props.cardViewOption === 'custom') {
160189
return (
161-
<Wrapper>
190+
<Wrapper
191+
$bgColor={props.cardContentStyles.backgroundColor}
192+
onMouseEnter={() => setHover(true)}
193+
onMouseLeave={() => setHover(false)}
194+
>
195+
{hover && (
196+
<CardActions>
197+
<div className="dragAction">
198+
<DragIcon />
199+
<span>{props.data.label}</span>
200+
</div>
201+
<div
202+
className="editAction"
203+
onClick={props.onEdit}
204+
>
205+
<span>Edit</span>
206+
</div>
207+
</CardActions>
208+
)}
162209
<div
163210
className={'card-template'}
164211
onClick={() => {
165212
props.onClick();
166213
}}
167214
style={{
168-
backgroundColor: props.cardContentStyles.backgroundColor,
169215
borderRadius: props.cardContentStyles.radius,
170216
borderWidth: props.cardContentStyles.borderWidth,
171217
border: props.cardContentStyles.border,
218+
padding: props.cardContentStyles.padding,
219+
margin: props.cardContentStyles.margin,
220+
fontSize: props.cardContentStyles.textSize,
221+
overflow: 'hidden',
172222
}}
173223
>
174-
{template}
224+
{template}
175225
</div>
176226
</Wrapper>
177227
);
178228
}
179229

180230
return (
181231
<Wrapper
232+
$bgColor={props.cardContentStyles.backgroundColor}
182233
onMouseEnter={() => setHover(true)}
183234
onMouseLeave={() => setHover(false)}
184235
>
185236
{hover && (
186237
<CardActions>
238+
<div className="dragAction">
239+
<DragIcon />
240+
<span>{props.data.label}</span>
241+
</div>
187242
<div
188243
className="editAction"
189244
onClick={props.onEdit}
190245
>
191-
<StyledEditIcon />
192246
<span>Edit</span>
193247
</div>
194-
<div className="dragAction">
195-
<StyledDragIcon />
196-
<span>Drag</span>
197-
</div>
198248
</CardActions>
199249
)}
200250
<div
@@ -203,10 +253,13 @@ const CardTemplate = React.memo((props: {
203253
props.onClick();
204254
}}
205255
style={{
206-
backgroundColor: props.cardContentStyles.backgroundColor,
207256
borderRadius: props.cardContentStyles.radius,
208257
borderWidth: props.cardContentStyles.borderWidth,
209258
border: props.cardContentStyles.border,
259+
padding: props.cardContentStyles.padding,
260+
margin: props.cardContentStyles.margin,
261+
fontSize: props.cardContentStyles.textSize,
262+
overflow: 'hidden',
210263
}}
211264
>
212265
<div className="e-card-header">
@@ -227,10 +280,6 @@ const CardTemplate = React.memo((props: {
227280
className="e-text"
228281
style={{
229282
fontSize: props.cardContentStyles.textSize,
230-
color: props.cardContentStyles.text,
231-
padding: props.cardContentStyles.padding,
232-
margin: props.cardContentStyles.margin,
233-
borderWidth: props.cardContentStyles.borderWidth,
234283
}}
235284
>
236285
{props.data.summary}
@@ -279,6 +328,8 @@ export const KanbanCompView = React.memo((props: Props) => {
279328
const isEditorStateAvailable = useMemo(() => Boolean(editorState), [ editorState ]);
280329
const cardView = useMemo(() => comp.children.cardView.children.cardView.toJsonValue(), [comp.children.cardView]);
281330
const cardModal = useMemo(() => childrenProps.cardView.cardModalView, [childrenProps.cardView.cardModalView] )
331+
const onEventVal = useMemo(() => comp?.toJsonValue()?.onEvent, [comp]);
332+
282333
const updateDataMap = useCallback(() => {
283334
const mapData: Record<string, number> = {};
284335
childrenProps.data?.forEach((item: any, index: number) => {
@@ -445,6 +496,10 @@ export const KanbanCompView = React.memo((props: Props) => {
445496
childrenProps.onEvent("cardClick");
446497
}}
447498
onEdit={() => {
499+
if (onEventVal && onEventVal.some((e: any) => e.name === 'onEdit')) {
500+
childrenProps.onEvent('onEdit');
501+
return;
502+
}
448503
handleOnEdit(childrenProps.data[cardIndex]);
449504
}}
450505
/>
@@ -458,6 +513,7 @@ export const KanbanCompView = React.memo((props: Props) => {
458513
JSON.stringify(childrenProps.cardHeaderStyles),
459514
JSON.stringify(childrenProps.cardContentStyles),
460515
JSON.stringify(childrenProps.tagStyles),
516+
onEventVal,
461517
]);
462518

463519
const renderKanbanComp = useMemo(() => {
@@ -471,7 +527,9 @@ export const KanbanCompView = React.memo((props: Props) => {
471527
overflow="scroll"
472528
hideScrollbar={!childrenProps.scrollbars}
473529
>
474-
<LayoutContainer>
530+
<LayoutContainer
531+
$padding={childrenProps.cardContentStyles.padding}
532+
>
475533
{Boolean(Object.keys(dataMap).length) && (
476534
<KanbanComponent
477535
id="kanban"
@@ -489,6 +547,7 @@ export const KanbanCompView = React.memo((props: Props) => {
489547
cardSettings={{
490548
headerField: 'label',
491549
template: cardTemplate,
550+
selectionType: 'Single',
492551
}}
493552
cardRendered={(args: CardRenderedEventArgs) => {
494553
return cardRendered({

lowcoder-comp-kanban/src/kanbanTypes.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ const childrenMap = {
138138
value: "cardClick",
139139
description: "Triggers on card click",
140140
},
141+
{
142+
label: "onEdit",
143+
value: "onEdit",
144+
description: "Customize edit action",
145+
},
141146
] as const),
142147
cardContentStyles: styleControl(CompStyles),
143148
statusOptions: jsonControl(toJSONObjectArray, dataSource.statusOptions),

0 commit comments

Comments
 (0)