Skip to content

Commit bd23748

Browse files
committed
[Feat]: #2021 add disabled property for nav
1 parent 6741bf5 commit bd23748

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ const Item = styled.div<{
6767
$padding: string;
6868
$textTransform:string;
6969
$textDecoration:string;
70+
$disabled?: boolean;
7071
}>`
7172
height: 30px;
7273
line-height: 30px;
7374
padding: ${(props) => props.$padding ? props.$padding : '0 16px'};
74-
color: ${(props) => (props.$active ? props.$activeColor : props.$color)};
75+
color: ${(props) => props.$disabled ? `${props.$color}80` : (props.$active ? props.$activeColor : props.$color)};
7576
font-weight: ${(props) => (props.$textWeight ? props.$textWeight : 500)};
7677
font-family:${(props) => (props.$fontFamily ? props.$fontFamily : 'sans-serif')};
7778
font-style:${(props) => (props.$fontStyle ? props.$fontStyle : 'normal')};
@@ -81,8 +82,8 @@ const Item = styled.div<{
8182
margin:${(props) => props.$margin ? props.$margin : '0px'};
8283
8384
&:hover {
84-
color: ${(props) => props.$activeColor};
85-
cursor: pointer;
85+
color: ${(props) => props.$disabled ? (props.$active ? props.$activeColor : props.$color) : props.$activeColor};
86+
cursor: ${(props) => props.$disabled ? 'not-allowed' : 'pointer'};
8687
}
8788
8889
.anticon {
@@ -166,6 +167,7 @@ const NavCompBase = new UICompBuilder(childrenMap, (props) => {
166167
const label = view?.label;
167168
const active = !!view?.active;
168169
const onEvent = view?.onEvent;
170+
const disabled = !!view?.disabled;
169171
const subItems = isCompItem ? view?.items : [];
170172

171173
const subMenuItems: Array<{ key: string; label: string }> = [];
@@ -199,7 +201,8 @@ const NavCompBase = new UICompBuilder(childrenMap, (props) => {
199201
$textTransform={props.style.textTransform}
200202
$textDecoration={props.style.textDecoration}
201203
$margin={props.style.margin}
202-
onClick={() => onEvent && onEvent("click")}
204+
$disabled={disabled}
205+
onClick={() => { if (!disabled && onEvent) onEvent("click"); }}
203206
>
204207
{label}
205208
{Array.isArray(subItems) && subItems.length > 0 && <DownOutlined />}
@@ -209,6 +212,7 @@ const NavCompBase = new UICompBuilder(childrenMap, (props) => {
209212
const subMenu = (
210213
<StyledMenu
211214
onClick={(e) => {
215+
if (disabled) return;
212216
const subItem = subItems[Number(e.key)];
213217
const onSubEvent = subItem?.getView()?.onEvent;
214218
onSubEvent && onSubEvent("click");
@@ -221,6 +225,7 @@ const NavCompBase = new UICompBuilder(childrenMap, (props) => {
221225
<Dropdown
222226
key={idx}
223227
popupRender={() => subMenu}
228+
disabled={disabled}
224229
>
225230
{item}
226231
</Dropdown>
@@ -320,6 +325,7 @@ function createNavItemsControl() {
320325
{
321326
label: StringControl,
322327
hidden: BoolCodeControl,
328+
disabled: BoolCodeControl,
323329
active: BoolCodeControl,
324330
onEvent: eventHandlerControl([clickEvent]),
325331
},
@@ -330,7 +336,8 @@ function createNavItemsControl() {
330336
{children.label.propertyView({ label: trans("label"), placeholder: "{{item}}" })}
331337
{children.active.propertyView({ label: trans("navItemComp.active") })}
332338
{children.hidden.propertyView({ label: trans("hidden") })}
333-
{children.onEvent.propertyView({ inline: true })}
339+
{children.disabled.propertyView({ label: trans("disabled") })}
340+
{children.onEvent.getPropertyView()}
334341
</>
335342
))
336343
.build();

client/packages/lowcoder/src/comps/comps/navComp/navItemComp.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { clickEvent, eventHandlerControl } from "comps/controls/eventHandlerCont
33
import { list } from "comps/generators/list";
44
import { parseChildrenFromValueAndChildrenMap, ToViewReturn } from "comps/generators/multi";
55
import { withDefault } from "comps/generators/simpleGenerators";
6-
import { hiddenPropertyView } from "comps/utils/propertyUtils";
6+
import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUtils";
77
import { trans } from "i18n";
88
import _ from "lodash";
99
import { fromRecord, MultiBaseComp, Node, RecordNode, RecordNodeToValue } from "lowcoder-core";
@@ -14,6 +14,7 @@ const events = [clickEvent];
1414
const childrenMap = {
1515
label: StringControl,
1616
hidden: BoolCodeControl,
17+
disabled: BoolCodeControl,
1718
active: BoolCodeControl,
1819
onEvent: withDefault(eventHandlerControl(events), [
1920
{
@@ -29,6 +30,7 @@ const childrenMap = {
2930
type ChildrenType = {
3031
label: InstanceType<typeof StringControl>;
3132
hidden: InstanceType<typeof BoolCodeControl>;
33+
disabled: InstanceType<typeof BoolCodeControl>;
3234
active: InstanceType<typeof BoolCodeControl>;
3335
onEvent: InstanceType<ReturnType<typeof eventHandlerControl>>;
3436
items: InstanceType<ReturnType<typeof navListComp>>;
@@ -43,6 +45,7 @@ export class NavItemComp extends MultiBaseComp<ChildrenType> {
4345
return (
4446
<>
4547
{this.children.label.propertyView({ label: trans("label") })}
48+
{disabledPropertyView(this.children)}
4649
{hiddenPropertyView(this.children)}
4750
{this.children.active.propertyView({ label: trans("navItemComp.active") })}
4851
{this.children.onEvent.propertyView({ inline: true })}
@@ -69,6 +72,7 @@ export class NavItemComp extends MultiBaseComp<ChildrenType> {
6972
return fromRecord({
7073
label: this.children.label.exposingNode(),
7174
hidden: this.children.hidden.exposingNode(),
75+
disabled: this.children.disabled.exposingNode(),
7276
active: this.children.active.exposingNode(),
7377
items: this.children.items.exposingNode(),
7478
});
@@ -78,6 +82,7 @@ export class NavItemComp extends MultiBaseComp<ChildrenType> {
7882
type NavItemExposing = {
7983
label: Node<string>;
8084
hidden: Node<boolean>;
85+
disabled: Node<boolean>;
8186
active: Node<boolean>;
8287
items: Node<RecordNodeToValue<NavItemExposing>[]>;
8388
};

0 commit comments

Comments
 (0)