@@ -17,6 +17,70 @@ const onUpdateSection = debounce((section) => store.dispatch(updateSection(secti
1717
1818type IControlProps = Pick < ISTKProps , "options" | "styles" > ;
1919
20+ export const SectionManager = ( { options } : IControlProps ) => {
21+ const sections = useSelector ( ( state : any ) => state . editor . sections ) ;
22+ return (
23+ < div className = "grid gap-4" >
24+ < div className = "flex flex-col gap-2" >
25+ < h4 className = "font-bold leading-none pb-1" > Manage Sections</ h4 >
26+ < hr />
27+ < span className = "hover:text-gray-500 cursor-pointer transition-all duration-medium" onClick = { onAddSection } >
28+ + Add Section
29+ </ span >
30+ < hr />
31+ </ div >
32+ < div className = "flex flex-col gap-4" >
33+ { sections . map (
34+ ( section , index ) =>
35+ section . id !== "0" && (
36+ < div key = { `category-${ section . id } ` } className = "flex justify-start items-center gap-4" >
37+ < input
38+ defaultValue = { section . color }
39+ type = "color"
40+ className = "flex-shrink-0 w-6 h-6 p-0 bg-white rounded-color-input"
41+ onChange = { ( e ) => onUpdateSection ( { ...section , color : e . target . value } ) }
42+ />
43+ < input
44+ defaultValue = { section . stroke }
45+ type = "color"
46+ className = "flex-shrink-0 w-6 h-6 p-0 bg-white rounded-color-input"
47+ onChange = { ( e ) => onUpdateSection ( { ...section , stroke : e . target . value } ) }
48+ />
49+ < Input
50+ defaultValue = { section . name }
51+ className = "h-8"
52+ onChange = { ( e ) => onUpdateSection ( { ...section , name : e . target . value } ) }
53+ />
54+ < Percent
55+ size = { 22 }
56+ className = { twMerge (
57+ "flex-shrink-0 cursor-pointer transition-all duration-medium " ,
58+ section ?. freeSeating ? "text-blue-600 hover:text-blue-500" : "hover:text-gray-500"
59+ ) }
60+ onClick = { ( ) =>
61+ section ?. freeSeating
62+ ? onUpdateSection ( { ...section , freeSeating : false } )
63+ : onUpdateSection ( { ...section , freeSeating : true } )
64+ }
65+ />
66+ { ! options ?. disableSectionDelete && (
67+ < Trash2
68+ size = { 22 }
69+ className = { twMerge (
70+ "hover:text-gray-500 flex-shrink-0 cursor-pointer transition-all duration-medium" ,
71+ index === 0 && "opacity-0 pointer-events-none"
72+ ) }
73+ onClick = { ( ) => onDeleteSection ( section . id ) }
74+ />
75+ ) }
76+ </ div >
77+ )
78+ ) }
79+ </ div >
80+ </ div >
81+ ) ;
82+ } ;
83+
2084const SectionSelector = ( { firstElement, selectedElementIds, options } : IControlProps & Record < string , any > ) => {
2185 const sections = useSelector ( ( state : any ) => state . editor . sections ) ;
2286 return (
@@ -30,67 +94,7 @@ const SectionSelector = ({ firstElement, selectedElementIds, options }: IControl
3094 </ Caption >
3195 </ PopoverTrigger >
3296 < PopoverContent className = "bg-white w-80 py-4 mr-4" >
33- < div className = "grid gap-4" >
34- < div className = "flex flex-col gap-2" >
35- < h4 className = "font-bold leading-none pb-1" > Manage Sections</ h4 >
36- < hr />
37- < span
38- className = "hover:text-gray-500 cursor-pointer transition-all duration-medium"
39- onClick = { onAddSection }
40- >
41- + Add Section
42- </ span >
43- < hr />
44- </ div >
45- < div className = "flex flex-col gap-4" >
46- { sections . map (
47- ( section , index ) =>
48- section . id !== "0" && (
49- < div key = { `category-${ section . id } ` } className = "flex justify-start items-center gap-4" >
50- < input
51- defaultValue = { section . color }
52- type = "color"
53- className = "flex-shrink-0 w-6 h-6 p-0 bg-white rounded-color-input"
54- onChange = { ( e ) => onUpdateSection ( { ...section , color : e . target . value } ) }
55- />
56- < input
57- defaultValue = { section . stroke }
58- type = "color"
59- className = "flex-shrink-0 w-6 h-6 p-0 bg-white rounded-color-input"
60- onChange = { ( e ) => onUpdateSection ( { ...section , stroke : e . target . value } ) }
61- />
62- < Input
63- defaultValue = { section . name }
64- className = "h-8"
65- onChange = { ( e ) => onUpdateSection ( { ...section , name : e . target . value } ) }
66- />
67- < Percent
68- size = { 22 }
69- className = { twMerge (
70- "flex-shrink-0 cursor-pointer transition-all duration-medium " ,
71- section ?. freeSeating ? "text-blue-600 hover:text-blue-500" : "hover:text-gray-500"
72- ) }
73- onClick = { ( ) =>
74- section ?. freeSeating
75- ? onUpdateSection ( { ...section , freeSeating : false } )
76- : onUpdateSection ( { ...section , freeSeating : true } )
77- }
78- />
79- { ! options ?. disableSectionDelete && (
80- < Trash2
81- size = { 22 }
82- className = { twMerge (
83- "hover:text-gray-500 flex-shrink-0 cursor-pointer transition-all duration-medium" ,
84- index === 0 && "opacity-0 pointer-events-none"
85- ) }
86- onClick = { ( ) => onDeleteSection ( section . id ) }
87- />
88- ) }
89- </ div >
90- )
91- ) }
92- </ div >
93- </ div >
97+ < SectionManager options = { options } />
9498 </ PopoverContent >
9599 </ Popover >
96100 </ div >
0 commit comments