Frontend Page - Configure MenuConfig: Difference between revisions
Jump to navigation
Jump to search
(→OnDrag) |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 28: | Line 28: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== OnDrag == | == OnDrag == | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
const dragStartRowIndex = useRef(null); | const dragStartRowIndex = useRef(null); | ||
Line 44: | Line 41: | ||
dragable | dragable | ||
onDragStart={(e) => { | onDragStart={(e) => { | ||
dragStartRowIndex.current = rowIndex; //set value when clicked element | |||
dragPassRowIndex.current = null; | dragPassRowIndex.current = null; //set null when departed original position | ||
setdragnamerow("row"); | setdragnamerow("row"); | ||
}} | }} | ||
onDragEnter={(e) => { | onDragEnter={(e) => { | ||
if (dragnamerow === "row") { | |||
dragPassRowIndex.current = rowIndex; | dragPassRowIndex.current = rowIndex;// change value when passed others element | ||
setDragPassRowIndexState(rowIndex); | setDragPassRowIndexState(rowIndex); | ||
} | } | ||
Line 62: | Line 59: | ||
* onDragEnter : when you passed element | * onDragEnter : when you passed element | ||
* onDragEnd : when you released holding | * onDragEnd : when you released holding | ||
* set variable by useRef : | * set variable by useRef : for save data immediately | ||
* set variable by useState : // | * set variable by useState : for Re-render | ||
== DragDrop == | |||
Under Construction | |||
<syntaxhighlight lang="json"> | |||
<CellTabButton | |||
id={"menuelement" + menuElementIndex} | |||
type="button" | |||
name="menuelement" | |||
dragdrop={( | |||
dragPassMenuElementIndexState === menuElementIndex //set state of index | |||
&& dragPassMenuElements.current === menuElements //switch element in array | |||
)} | |||
> | |||
//... | |||
</CellTabButton> | |||
</syntaxhighlight> | |||
== menuElements recursion == | == menuElements recursion == |
Latest revision as of 01:57, 26 June 2023
Overview
Frontend page for creating and editing MenuConfigs
Repository
visibleObj Object
let visibleObj = {
visibleRowIndex: 0, // row index we have open on page
visibleRenameRowIndex: 0, // row index currently renaming
rows:[
{
menuElements: [
{
show: false, // whether the menuElement settings are expanded
menuText
menuElements: [ // if menuElement is elementType menu, will have child menuElements
],
},
// ..
]
},
// ..
]
}
OnDrag
const dragStartRowIndex = useRef(null);
const dragPassRowIndex = useRef(null);
const [dragnamerow, setdragnamerow] = useState(null);
const [dragPassRowIndexState, setDragPassRowIndexState] = useState(null);
<div
dragable
onDragStart={(e) => {
dragStartRowIndex.current = rowIndex; //set value when clicked element
dragPassRowIndex.current = null; //set null when departed original position
setdragnamerow("row");
}}
onDragEnter={(e) => {
if (dragnamerow === "row") {
dragPassRowIndex.current = rowIndex;// change value when passed others element
setDragPassRowIndexState(rowIndex);
}
}}
onDragEnd={moveRows}
>
{"text"}
</div>
- onDragStart : when you started to click element
- onDragEnter : when you passed element
- onDragEnd : when you released holding
- set variable by useRef : for save data immediately
- set variable by useState : for Re-render
DragDrop
Under Construction
<CellTabButton
id={"menuelement" + menuElementIndex}
type="button"
name="menuelement"
dragdrop={(
dragPassMenuElementIndexState === menuElementIndex //set state of index
&& dragPassMenuElements.current === menuElements //switch element in array
)}
>
//...
</CellTabButton>
- Menu elements are nested to any level
- Structure of rows and menuElements in visible object matches structure of menuConfig/menuConfigSetting