generated from wrappid/wrappid-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(global): ✨ added layout selection
now we can select any layout from right side menu and we can see those layout in left side Ref: #54
- Loading branch information
Showing
12 changed files
with
192 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
app/components/page-builder/content-components/ContentComp.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/components/page-builder/content-components/DefaultCanvasViewer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
CoreBox, CoreClasses, | ||
LayoutManager | ||
} from "@wrappid/core"; | ||
import { useSelector } from "react-redux"; | ||
|
||
export default function DefaultCanvasViewer() { | ||
const selectedLayout = useSelector((state) => state.testBuilderReducer?.selectedLayout); | ||
const layoutName = selectedLayout || "BlankLayout"; | ||
|
||
return ( | ||
<> | ||
<CoreBox | ||
styleClasses={[CoreClasses.BG.BG_DOT_GRID_1, CoreClasses.HEIGHT.VH_75, CoreClasses.OVERFLOW.OVERFLOW_AUTO, CoreClasses.PADDING.P2]}> | ||
|
||
<CoreBox | ||
styleClasses={[CoreClasses.BG.BG_GREY_100, CoreClasses.PADDING.P1, CoreClasses.SHADOW.NORMAL, CoreClasses.OVERFLOW.OVERFLOW_AUTO]} | ||
> | ||
<LayoutManager key={layoutName + "-VIEW-MODE"} layoutName={layoutName} viewMode={true} /> | ||
</CoreBox> | ||
</CoreBox> | ||
|
||
{/* ↑↓ */} | ||
</> | ||
); | ||
} |
28 changes: 28 additions & 0 deletions
28
app/components/page-builder/content-components/JsonCanvasViewer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from "react"; | ||
|
||
import { CoreBox, CoreClasses } from "@wrappid/core"; | ||
import { useSelector } from "react-redux"; | ||
|
||
export default function JsonCanvasViewer() { | ||
const selectedLayout = useSelector((state) => state.testBuilderReducer?.selectedLayout); | ||
const layoutName = selectedLayout || "BlankLayout"; | ||
|
||
const [pageJson, setPageJson] = React.useState({ layout: layoutName }); | ||
|
||
// Update pageJson when layout changes | ||
React.useEffect(() => { | ||
if (layoutName) { | ||
setPageJson((prevPageJson) => ({ | ||
...prevPageJson, | ||
layout: layoutName, // Replace the layout with the new selected layout | ||
})); | ||
} | ||
}, [layoutName]); | ||
return ( | ||
<> | ||
<CoreBox component="pre" styleClasses={[CoreClasses.HEIGHT.VH_75, CoreClasses.OVERFLOW.OVERFLOW_AUTO, CoreClasses.PADDING.P2]}> | ||
{JSON.stringify(pageJson, null, 2)} | ||
</CoreBox> | ||
</> | ||
); | ||
} |
32 changes: 0 additions & 32 deletions
32
app/components/page-builder/content-components/PageMetaInput.js
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
app/components/page-builder/content-components/RenderLayoutViewerCanvas.js
This file was deleted.
Oops, something went wrong.
66 changes: 50 additions & 16 deletions
66
app/components/page-builder/content-components/ViewerOption.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,63 @@ | ||
import React from "react"; | ||
|
||
import { CoreBox, CoreClasses, CoreTab, CoreTabs } from "@wrappid/core"; | ||
|
||
import DefaultCanvasViewer from "./DefaultCanvasViewer"; | ||
import JsonCanvasViewer from "./JsonCanvasViewer"; | ||
|
||
function CoreTabPanel(props) { | ||
const { children, value, index, ...other } = props; | ||
|
||
return ( | ||
<CoreBox | ||
role="tabpanel" | ||
hidden={value !== index} | ||
id={`simple-tabpanel-${index}`} | ||
aria-labelledby={`simple-tab-${index}`} | ||
{...other} | ||
> | ||
{value === index && <CoreBox>{children}</CoreBox>} | ||
</CoreBox> | ||
); | ||
} | ||
|
||
function a11yProps(index) { | ||
return { | ||
"aria-controls": `simple-tabpanel-${index}`, | ||
id : `simple-tab-${index}`, | ||
}; | ||
} | ||
|
||
export default function ViewerOption() { | ||
const [value, setValue] = React.useState("one"); | ||
const [value, setValue] = React.useState(0); | ||
|
||
const handleChange = (event, newValue) => { | ||
setValue(newValue); | ||
}; | ||
|
||
return ( | ||
<CoreBox styleClasses={[CoreClasses.WIDTH.W_100, CoreClasses.MARGIN.MB2]}> | ||
<CoreTabs | ||
value={value} | ||
onChange={handleChange} | ||
aria-label="wrapped label tabs example" | ||
> | ||
<CoreTab | ||
value="one" | ||
label="Default" | ||
/> | ||
|
||
<CoreTab value="two" label="JSON" /> | ||
|
||
<CoreTab value="three" label="Code" /> | ||
</CoreTabs> | ||
<CoreBox styleClasses={[CoreClasses.WIDTH.W_100]}> | ||
<CoreBox styleClasses={[CoreClasses.BORDER.BORDER_BOTTOM, CoreClasses.BORDER.BORDER_GREY_300]}> | ||
<CoreTabs value={value} onChange={handleChange} aria-label="basic tabs example"> | ||
<CoreTab label="Default" {...a11yProps(0)} /> | ||
|
||
<CoreTab label="JSON" {...a11yProps(1)} /> | ||
|
||
<CoreTab label="Code" {...a11yProps(2)} /> | ||
</CoreTabs> | ||
</CoreBox> | ||
|
||
<CoreTabPanel value={value} index={0}> | ||
<DefaultCanvasViewer/> | ||
</CoreTabPanel> | ||
|
||
<CoreTabPanel value={value} index={1}> | ||
<JsonCanvasViewer /> | ||
</CoreTabPanel> | ||
|
||
<CoreTabPanel value={value} index={2}> | ||
Not developted yet | ||
</CoreTabPanel> | ||
</CoreBox> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
app/components/page-builder/right-drawer-components/LayoutSelector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from "react"; | ||
|
||
import { ComponentRegistryContext, CoreMenu } from "@wrappid/core"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
import { selectLayout } from "../../../actions/test.action"; | ||
|
||
export default function LayoutSelector() { | ||
const componentRegistry = React.useContext(ComponentRegistryContext); | ||
const dispatch = useDispatch(); | ||
|
||
const layoutComponentRegistry = Object.fromEntries(Object.entries(componentRegistry).filter((value) => { | ||
return value[1].layout === true; | ||
})); | ||
|
||
const prepareLayoutMenu = (layoutComponentRegistry) => { | ||
return Object.entries(layoutComponentRegistry)?.map(([layoutName]) => ({ | ||
Children: layoutName, | ||
id : layoutName, | ||
label : layoutName, | ||
name : layoutName?.trim(), | ||
type : "layoutName", | ||
})); | ||
}; | ||
|
||
// Handle menu selection and dispatch the action | ||
const handleMenuSelect = (selectedItem) => { | ||
const selectedLayoutName = selectedItem?.name; // Get the layout name | ||
|
||
if (selectedLayoutName) { | ||
dispatch(selectLayout(selectedLayoutName)); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<CoreMenu | ||
multiLevel={true} | ||
menu={prepareLayoutMenu(layoutComponentRegistry)} | ||
open={true} | ||
displayIcon={true} | ||
OnMenuClick={handleMenuSelect} | ||
/> | ||
</> | ||
); | ||
} |
7 changes: 5 additions & 2 deletions
7
app/components/page-builder/right-drawer-components/RightDrawerComp.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export const ReducersRegistry = {}; | ||
import testBuilderReducer from "./reducers/testBuilder.reducer"; | ||
|
||
export const ReducersRegistry = { testBuilderReducer: testBuilderReducer }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { SELECT_LAYOUT } from "../types/test.types"; | ||
|
||
const initialState = { | ||
error : false, | ||
message : "This is a test module.", | ||
selectedLayout: null, | ||
success : false | ||
}; | ||
|
||
const testBuilderReducer = (state = initialState, action) => { | ||
switch (action.type) { | ||
|
||
case SELECT_LAYOUT: | ||
return { | ||
...state, | ||
selectedLayout: action.payload // Store the selected layout | ||
}; | ||
|
||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default testBuilderReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const TEST_SUCCESS = "TEST_SUCCESS"; | ||
export const TEST_FAILURE = "TEST_FAILURE"; | ||
export const RESET_TEST = "RESET_TEST"; | ||
export const RESET_TEST = "RESET_TEST"; | ||
export const SELECT_LAYOUT = "SELECT_LAYOUT"; |