priteshjha4u / react-jspanel4 Goto Github PK
View Code? Open in Web Editor NEWThis app shows jsPanel4 Integration with React JS
This app shows jsPanel4 Integration with React JS
First of all thanks for this repo. I'm sure it will be of help ...
Just one thing: the modal example is not a jsPanel. Since jsPanel offers the use as modal a well I would appreciate it a lot if you could consider changing your example to use a jsPanel modal.
Thanks again and best regards,
Stefan
Hello, my name is Lucas im trying to put the JS panels to work on mey porject but still get litle issues on integration. I make in my project a bigger context using JSpanels... Is a hook function, thats give all other components the 2 functions nedded. There are 2 issues... I cant make work JSpanels in modal, also, i cant remove the closed panels from state because the recived state is null, i assume that it'n have recived yet when script pass by onbeforeclose or onclosed function... It works proprely it other cases... I post here my code take a look i think you gonna like the integration i made.
Here context file that hold the create Js component function ans serve all other components...
import React, { Suspense, createContext, useState, useContext } from "react";
import AuthContext from "./auth";
import CreatePortal from "../components/CreatePortal";
// jspanels needed importion
import "jspanel4/es6module/jspanel.css";
import { jsPanel } from "jspanel4/es6module/jspanel";
import "jspanel4/es6module/extensions/modal/jspanel.modal";
import "jspanel4/es6module/extensions/layout/jspanel.layout";
const JsPanelsContext = createContext({});
export function JsPanelsProvider({ children }) {
const { signed } = useContext(AuthContext);
const [panels, setPanels] = useState({});
const storedData = jsPanel.layout.save({
selector: ".jsPanel-standard",
storagename: "mypanels",
});
function createCustomJsPanel(action, comp, custom, modal = false) {
const appPanels = panels;
const currentpanel = panels[action];
// check if its already mounted, bring it to front
if (currentpanel) {
console.log(panels);
console.log(panels[action]);
return panels[action]["panel"].front(() => {
panels[action]["panel"].resize({
height: "auto",
});
panels[action]["panel"].reposition("center-top 0 5%");
});
}
const options = {
...custom,
// animateIn: 'jsPanelFadeIn',
// animateOut: 'jsPanelFadeOut',
position: "center-top 0 5%",
headerTitle: action,
headerLogo:
"<span class='fa fa-spinner fa-spin' style='margin-left:8px;'></span>",
onbeforeclose: () => {
// remove closed jsPanel and its mounted component from state
console.log(action);
console.log("current panel:" + panels[action]);
if (action) {
const paneljson = jsPanel.layout.getAll();
console.log("axei:" + JSON.stringify(paneljson));
delete appPanels[action];
setPanels({ ...appPanels });
return true;
}
},
callback: (panel) => {
panel.resize({
height: "auto",
});
const maxHeight = window.innerHeight;
panel.content.style.maxHeight = `${maxHeight}px`;
panel.content.style.maxWidth = `${window.innerWidth - 20}px`;
panel.options.data = { [action]: { comp } };
jsPanel.layout.save();
},
};
// create jsPanel
const panel = modal
? jsPanel.modal.create(options)
: jsPanel.create(options);
// save panel and compponent (this will be mounted later inside panel body) reference inside state
const savedpanelsjson = jsPanel.layout.getAll();
setPanels({ ...panels, [action]: { comp, panel } });
}
function renderJsPanlesInsidePortal() {
return Object.keys(panels).map((action) => {
const jsPanel = panels[action].panel;
const Comp = panels[action].comp;
const node = document.getElementById(`${jsPanel.id}-node`);
let counter = 0;
if (!Comp) return null;
return (
<CreatePortal rootNode={node} key={jsPanel.id}>
{Array.isArray(Comp) ? (
Comp.map((C) => (
<Suspense
key={`${jsPanel.id}-${counter++}`}
fallback={<div className="alert alert-info">Loading...</div>}
>
<C jsPanel={jsPanel} />
</Suspense>
))
) : (
<Suspense
fallback={<div className="alert alert-info">Loading...</div>}
>
<Comp jsPanel={jsPanel} />
</Suspense>
)}
</CreatePortal>
);
});
}
const jsPanels = Object.keys(panels);
return (
<JsPanelsContext.Provider
value={{
panels,
jsPanels,
renderJsPanlesInsidePortal,
createCustomJsPanel,
}}
>
{children}
</JsPanelsContext.Provider>
);
}
export default JsPanelsContext;
console logs show me that the function onbeforeclose or anyother function inside the options does'nt recieve the correct state, instead, in options from state recieve only a empty array. I need help... because with no state calling i cant find one way to make the correct delete of panel on state... If function recieve a empty array , defining a new state on that funcion delete the entire panel state. And this does't work propely. The bug occours on deleting the first opened panels, with other second panels opened making to close all others. The panels closes and on click on close apears this error:
That componet was build by you @priteshjha4u so i dont see a way to change it... if you can help-me please... i changed your buttons behavior becouse i already have my menus and i will only use the functions structure... The CreatePortal original file is intact. Is very useful to render other of my components inside the Jspanel created...
This an example on Menu that call the function...
import React, { lazy, useContext } from "react";
import { Menubar } from "primereact/menubar";
// import { useHistory } from "react-router-dom";
import { AiOutlineUserAdd } from "react-icons/ai";
import { FiInfo } from "react-icons/fi";
import AuthContext from "../../../contexts/auth";
import JsPanelsContext from "../../../contexts/jspanels";
//jspanelcustomoptions
import CustomOptionsforSingin from "../../../components/SingIn/jsPanelSingin";
import CustomOptionsforIntro from "../../../components/Intro/jsPanelIntro";
import CustomOptionsforLogin from "../../../components/Loginpanel/jsPanelLogin";
//jspanelcustomoptions
//jspanel
import Createpanel from "../../../utils/CreateJspanels";
//jspanel lazy loaded
const Login = lazy(() => import("../../../components/Loginpanel"));
const SingIn = lazy(() => import("../../../components/SingIn"));
const Intro = lazy(() => import("../../../components/Intro"));
//jspanel lazy loaded
export default function Menu() {
const { signed } = useContext(AuthContext);
const {
jsPanels,
renderJsPanlesInsidePortal,
createCustomJsPanel,
} = useContext(JsPanelsContext);
// const history = useHistory();
const items = [
{
label: "Log in",
icon: "fas fa-pen-square",
command: (event) => {
createCustomJsPanel(
"Log in to your account",
Login,
CustomOptionsforLogin,
false
);
},
},
{
label: "Register",
icon: "fas fa-pen-square",
command: (event) => {
createCustomJsPanel("Register", SingIn, CustomOptionsforSingin, false);
},
},
{
label: "Contact us",
icon: "pi pi-fw pi-comments",
items: [
{
label: "Chat",
icon: "pi pi-fw pi-comment",
command: (event) => {
Createpanel.createchatpanel();
},
},
],
},
{
label: "Projects",
icon: "pi pi-fw pi-desktop",
items: [
{
label: "Edit",
icon: "pi pi-fw pi-pencil",
items: [
{
label: "Save",
icon: "pi pi-fw pi-calendar-plus",
},
{
label: "Delete",
icon: "pi pi-fw pi-calendar-minus",
},
],
},
{
label: "Archieve",
icon: "pi pi-fw pi-calendar-times",
items: [
{
label: "Remove",
icon: "pi pi-fw pi-calendar-minus",
},
],
},
],
},
{
label: "Information",
icon: "fas fa-info",
command: (event) => {
createCustomJsPanel("Information", Intro, CustomOptionsforIntro, false);
},
},
];
return (
<div>
<Menubar model={items}></Menubar>
{jsPanels.length > 0 && renderJsPanlesInsidePortal()}
</div>
);
}
Thaks for you work on first integration on Jspanels @priteshjha4u and @Flyer53 for this awesome work on Jspnanels. JS will chnage the world... I hope you can helpme there is no way i found here to load these state corectely... I'm trying too use the display extension to save data... and instead of use state to not reload already open modals... Ok thanks alll by waith for answer...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.