11import { NameConfig , NameConfigHidden , withExposingConfigs } from "comps/generators/withExposing" ;
2+ import { MultiCompBuilder } from "comps/generators/multi" ;
23import { UICompBuilder , withDefault } from "comps/generators" ;
34import { Section , sectionNames } from "lowcoder-design" ;
45import styled from "styled-components" ;
56import { clickEvent , eventHandlerControl } from "comps/controls/eventHandlerControl" ;
6- import { StringControl } from "comps/controls/codeControl" ;
7+ import { BoolCodeControl , StringControl } from "comps/controls/codeControl" ;
78import { alignWithJustifyControl } from "comps/controls/alignControl" ;
89import { navListComp } from "./navItemComp" ;
910import { menuPropertyView } from "./components/MenuItemList" ;
@@ -22,6 +23,8 @@ import { trans } from "i18n";
2223
2324import { useContext } from "react" ;
2425import { EditorContext } from "comps/editorState" ;
26+ import { controlItem } from "lowcoder-design" ;
27+ import { createNavItemsControl } from "./components/NavItemsControl" ;
2528
2629type IProps = {
2730 $justify : boolean ;
@@ -63,11 +66,12 @@ const Item = styled.div<{
6366 $padding : string ;
6467 $textTransform :string ;
6568 $textDecoration :string ;
69+ $disabled ?: boolean ;
6670} > `
6771 height: 30px;
6872 line-height: 30px;
6973 padding: ${ ( props ) => props . $padding ? props . $padding : '0 16px' } ;
70- color: ${ ( props ) => ( props . $active ? props . $activeColor : props . $color ) } ;
74+ color: ${ ( props ) => props . $disabled ? ` ${ props . $color } 80` : ( props . $active ? props . $activeColor : props . $color ) } ;
7175 font-weight: ${ ( props ) => ( props . $textWeight ? props . $textWeight : 500 ) } ;
7276 font-family:${ ( props ) => ( props . $fontFamily ? props . $fontFamily : 'sans-serif' ) } ;
7377 font-style:${ ( props ) => ( props . $fontStyle ? props . $fontStyle : 'normal' ) } ;
@@ -77,8 +81,8 @@ const Item = styled.div<{
7781 margin:${ ( props ) => props . $margin ? props . $margin : '0px' } ;
7882
7983 &:hover {
80- color: ${ ( props ) => props . $activeColor } ;
81- cursor: pointer;
84+ color: ${ ( props ) => props . $disabled ? ( props . $active ? props . $activeColor : props . $color ) : props . $ activeColor} ;
85+ cursor: ${ ( props ) => props . $disabled ? 'not-allowed' : ' pointer' } ;
8286 }
8387
8488 .anticon {
@@ -131,41 +135,74 @@ function fixOldStyleData(oldData: any) {
131135 return oldData ;
132136}
133137
138+ function fixOldItemsData ( oldData : any ) {
139+ if ( Array . isArray ( oldData ) ) {
140+ return {
141+ optionType : "manual" ,
142+ manual : oldData ,
143+ } ;
144+ }
145+ if ( oldData && ! oldData . optionType && Array . isArray ( oldData . manual ) ) {
146+ return {
147+ optionType : "manual" ,
148+ manual : oldData . manual ,
149+ } ;
150+ }
151+ return oldData ;
152+ }
153+
134154const childrenMap = {
135155 logoUrl : StringControl ,
136156 logoEvent : withDefault ( eventHandlerControl ( logoEventHandlers ) , [ { name : "click" } ] ) ,
137157 horizontalAlignment : alignWithJustifyControl ( ) ,
138158 style : migrateOldData ( styleControl ( NavigationStyle , 'style' ) , fixOldStyleData ) ,
139159 animationStyle : styleControl ( AnimationStyle , 'animationStyle' ) ,
140- items : withDefault ( navListComp ( ) , [
141- {
142- label : trans ( "menuItem" ) + " 1" ,
143- } ,
144- ] ) ,
160+ items : withDefault ( migrateOldData ( createNavItemsControl ( ) , fixOldItemsData ) , {
161+ optionType : "manual" ,
162+ manual : [
163+ {
164+ label : trans ( "menuItem" ) + " 1" ,
165+ } ,
166+ ] ,
167+ } ) ,
145168} ;
146169
147170const NavCompBase = new UICompBuilder ( childrenMap , ( props ) => {
148171 const data = props . items ;
149172 const items = (
150173 < >
151- { data . map ( ( menuItem , idx ) => {
152- const { hidden, label, items, active, onEvent } = menuItem . getView ( ) ;
174+ { data . map ( ( menuItem : any , idx : number ) => {
175+ const isCompItem = typeof menuItem ?. getView === "function" ;
176+ const view = isCompItem ? menuItem . getView ( ) : menuItem ;
177+ const hidden = ! ! view ?. hidden ;
153178 if ( hidden ) {
154179 return null ;
155180 }
156- const subMenuItems : Array < { key : string ; label : string } > = [ ] ;
181+
182+ const label = view ?. label ;
183+ const active = ! ! view ?. active ;
184+ const onEvent = view ?. onEvent ;
185+ const disabled = ! ! view ?. disabled ;
186+ const subItems = isCompItem ? view ?. items : [ ] ;
187+
188+ const subMenuItems : Array < { key : string ; label : any ; disabled ?: boolean } > = [ ] ;
157189 const subMenuSelectedKeys : Array < string > = [ ] ;
158- items . forEach ( ( subItem , originalIndex ) => {
159- if ( subItem . children . hidden . getView ( ) ) {
160- return ;
161- }
162- const key = originalIndex + "" ;
163- subItem . children . active . getView ( ) && subMenuSelectedKeys . push ( key ) ;
164- subMenuItems . push ( {
165- key : key ,
166- label : subItem . children . label . getView ( ) ,
190+
191+ if ( Array . isArray ( subItems ) ) {
192+ subItems . forEach ( ( subItem : any , originalIndex : number ) => {
193+ if ( subItem . children . hidden . getView ( ) ) {
194+ return ;
195+ }
196+ const key = originalIndex + "" ;
197+ subItem . children . active . getView ( ) && subMenuSelectedKeys . push ( key ) ;
198+ subMenuItems . push ( {
199+ key : key ,
200+ label : subItem . children . label . getView ( ) ,
201+ disabled : ! ! subItem . children . disabled . getView ( ) ,
202+ } ) ;
167203 } ) ;
168- } ) ;
204+ }
205+
169206 const item = (
170207 < Item
171208 key = { idx }
@@ -180,18 +217,23 @@ const NavCompBase = new UICompBuilder(childrenMap, (props) => {
180217 $textTransform = { props . style . textTransform }
181218 $textDecoration = { props . style . textDecoration }
182219 $margin = { props . style . margin }
183- onClick = { ( ) => onEvent ( "click" ) }
220+ $disabled = { disabled }
221+ onClick = { ( ) => { if ( ! disabled && onEvent ) onEvent ( "click" ) ; } }
184222 >
185223 { label }
186- { items . length > 0 && < DownOutlined /> }
224+ { Array . isArray ( subItems ) && subItems . length > 0 && < DownOutlined /> }
187225 </ Item >
188226 ) ;
189227 if ( subMenuItems . length > 0 ) {
190228 const subMenu = (
191229 < StyledMenu
192230 onClick = { ( e ) => {
193- const { onEvent : onSubEvent } = items [ Number ( e . key ) ] ?. getView ( ) ;
194- onSubEvent ( "click" ) ;
231+ if ( disabled ) return ;
232+ const subItem = subItems [ Number ( e . key ) ] ;
233+ const isSubDisabled = ! ! subItem ?. children ?. disabled ?. getView ?.( ) ;
234+ if ( isSubDisabled ) return ;
235+ const onSubEvent = subItem ?. getView ( ) ?. onEvent ;
236+ onSubEvent && onSubEvent ( "click" ) ;
195237 } }
196238 selectedKeys = { subMenuSelectedKeys }
197239 items = { subMenuItems }
@@ -201,6 +243,7 @@ const NavCompBase = new UICompBuilder(childrenMap, (props) => {
201243 < Dropdown
202244 key = { idx }
203245 popupRender = { ( ) => subMenu }
246+ disabled = { disabled }
204247 >
205248 { item }
206249 </ Dropdown >
@@ -237,7 +280,7 @@ const NavCompBase = new UICompBuilder(childrenMap, (props) => {
237280 return (
238281 < >
239282 < Section name = { sectionNames . basic } >
240- { menuPropertyView ( children . items ) }
283+ { children . items . propertyView ( ) }
241284 </ Section >
242285
243286 { ( useContext ( EditorContext ) . editorModeStatus === "logic" || useContext ( EditorContext ) . editorModeStatus === "both" ) && (
0 commit comments