dragbar component

pull/1840/head
bunsenstraat 3 years ago
parent 123afca2f2
commit 2bd2a91944
  1. 4
      apps/remix-ide/src/app.tsx
  2. 4
      apps/remix-ide/src/walkthroughService.js
  3. 26
      libs/remix-ui/app/src/lib/remix-app/dragbar/dragbar.css
  4. 43
      libs/remix-ui/app/src/lib/remix-app/dragbar/dragbar.tsx
  5. 1
      libs/remix-ui/app/src/lib/remix-app/modals/matomo.tsx
  6. 12
      libs/remix-ui/app/src/lib/remix-app/remix-app.tsx
  7. 25
      libs/remix-ui/app/src/lib/remix-app/style/remix-app.css

@ -8,7 +8,9 @@ appComponent.run()
function App () { function App () {
return <> return <>
<RemixApp app={appComponent}></RemixApp> <React.StrictMode>
<RemixApp app={appComponent}></RemixApp>
</React.StrictMode>
</> </>
} }

@ -15,14 +15,12 @@ export class WalkthroughService extends Plugin {
super(profile) super(profile)
appManager.event.on('activate', (plugin) => { appManager.event.on('activate', (plugin) => {
if (plugin.name === 'udapp' && !showMatamo) { if (plugin.name === 'udapp' && !showMatamo) {
console.log('start')
this.start() this.start()
} }
}) })
} }
start () { start () {
console.log('start')
if (!localStorage.getItem('hadTour_initial')) { if (!localStorage.getItem('hadTour_initial')) {
introJs().setOptions({ introJs().setOptions({
steps: [{ steps: [{
@ -63,8 +61,6 @@ export class WalkthroughService extends Plugin {
} }
}).start() }).start()
localStorage.setItem('hadTour_initial', true) localStorage.setItem('hadTour_initial', true)
} else {
console.log('had walkthrough')
} }
} }
} }

@ -0,0 +1,26 @@
/* dragbar UI */
.dragbar {
display : block;
height : 100%;
position : absolute;
left: 0px;
top: 0px;
width: 0.3em;
z-index: 9999;
}
.overlay {
position: absolute;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
display: block;
z-index: 9998;
}
.dragbar:hover, .dragbar.ondrag{
background-color: var(--secondary);
cursor:col-resize;
}

@ -1,36 +1,53 @@
import React, { useState } from 'react' import React, { useEffect, useState } from 'react'
import Draggable from 'react-draggable' import Draggable from 'react-draggable'
import './dragbar.css'
interface IRemixDragBarUi { interface IRemixDragBarUi {
refObject: React.MutableRefObject<any>; refObject: React.MutableRefObject<any>;
setHideStatus: (hide: boolean) => void; setHideStatus: (hide: boolean) => void;
hidden: boolean
minWidth: number
} }
const DragBar = (props: IRemixDragBarUi) => { const DragBar = (props: IRemixDragBarUi) => {
const [dragState, setDragState] = useState<boolean>(false) const [dragState, setDragState] = useState<boolean>(false)
const [dragBarPos, setDragBarPos] = useState<number>(0) const [dragBarPosX, setDragBarPosX] = useState<number>(0)
const [offset, setOffSet] = useState<number>(0)
const nodeRef = React.useRef(null) // fix for strictmode
useEffect(() => {
// arbitrary time out to wait the the UI to be completely done
setTimeout(() => {
setOffSet(props.refObject.current.offsetLeft)
setDragBarPosX(offset + props.refObject.current.offsetWidth)
}, 1000)
}, [])
useEffect(() => {
setDragBarPosX(offset + (props.hidden ? 0 : props.refObject.current.offsetWidth))
}, [props.hidden, offset])
function stopDrag (e: MouseEvent, data: any) { function stopDrag (e: MouseEvent, data: any) {
console.log(data)
setDragState(false) setDragState(false)
props.refObject.current.style.width = (320 + data.x) + 'px' if (data.x < props.minWidth) {
console.log(props.refObject.current.offsetWidth) setDragBarPosX(offset)
if ((320 + data.x) < 250) {
props.setHideStatus(true) props.setHideStatus(true)
setDragBarPos(41 - 360)
} else { } else {
props.refObject.current.style.width = (data.x - offset) + 'px'
props.setHideStatus(false) props.setHideStatus(false)
setDragBarPos(props.refObject.current.offsetWidth - 320) setDragBarPosX(offset + props.refObject.current.offsetWidth)
} }
} }
function startDrag (e: MouseEvent, data: any) { function startDrag () {
console.log('start')
setDragState(true) setDragState(true)
} }
return <Draggable position={{ x: dragBarPos, y: 0 }} onStart={startDrag} onStop={stopDrag} axis="x"> return <>
<div className={`dragbar ${dragState ? 'ondrag' : ''}`}></div> <div className={`overlay ${dragState ? '' : 'd-none'}`} ></div>
</Draggable> <Draggable nodeRef={nodeRef} position={{ x: dragBarPosX, y: 0 }} onStart={startDrag} onStop={stopDrag} axis="x">
<div ref={nodeRef} className={`dragbar ${dragState ? 'ondrag' : ''}`}></div>
</Draggable>
</>
} }
export default DragBar export default DragBar

@ -20,7 +20,6 @@ const MatomoDialog = (props) => {
setVisible(false) setVisible(false)
} }
const hideModal = async () => { const hideModal = async () => {
console.log('handle hide')
setVisible(false) setVisible(false)
} }
const handleModalOkClick = async () => { const handleModalOkClick = async () => {

@ -5,7 +5,6 @@ import RemixSplashScreen from './modals/splashscreen'
import MatomoDialog from './modals/matomo' import MatomoDialog from './modals/matomo'
import AlertModal from './modals/alert' import AlertModal from './modals/alert'
import AppContext from './context/context' import AppContext from './context/context'
import Draggable from 'react-draggable'
import DragBar from './dragbar/dragbar' import DragBar from './dragbar/dragbar'
interface IRemixAppUi { interface IRemixAppUi {
app: any app: any
@ -13,17 +12,13 @@ interface IRemixAppUi {
const RemixApp = (props: IRemixAppUi) => { const RemixApp = (props: IRemixAppUi) => {
const [appReady, setAppReady] = useState<boolean>(false) const [appReady, setAppReady] = useState<boolean>(false)
const [dragState, setDragState] = useState<boolean>(false)
const [hideSidePanel, setHideSidePanel] = useState<boolean>(false) const [hideSidePanel, setHideSidePanel] = useState<boolean>(false)
const [dragBarPos, setDragBarPos] = useState<number>(0)
const sidePanelRef = useRef(null) const sidePanelRef = useRef(null)
const mainPanelRef = useRef(null) const mainPanelRef = useRef(null)
const iconPanelRef = useRef(null) const iconPanelRef = useRef(null)
const hiddenPanelRef = useRef(null) const hiddenPanelRef = useRef(null)
const resizePanelRef = useRef(null)
useEffect(() => { useEffect(() => {
console.log('mounting app')
if (sidePanelRef.current) { if (sidePanelRef.current) {
if (props.app.sidePanel) { if (props.app.sidePanel) {
sidePanelRef.current.appendChild(props.app.sidePanel.render()) sidePanelRef.current.appendChild(props.app.sidePanel.render())
@ -52,20 +47,17 @@ const RemixApp = (props: IRemixAppUi) => {
}) })
} }
if (props.app) { if (props.app) {
console.log('app', props.app)
activateApp() activateApp()
} }
}, []) }, [])
function setListeners () { function setListeners () {
props.app.sidePanel.events.on('toggle', () => { props.app.sidePanel.events.on('toggle', () => {
console.log('toggle')
setHideSidePanel(prev => { setHideSidePanel(prev => {
return !prev return !prev
}) })
}) })
props.app.sidePanel.events.on('showing', () => { props.app.sidePanel.events.on('showing', () => {
console.log('showing')
setHideSidePanel(false) setHideSidePanel(false)
}) })
} }
@ -73,7 +65,6 @@ const RemixApp = (props: IRemixAppUi) => {
const components = { const components = {
iconPanel: <div ref={iconPanelRef} id="icon-panel" data-id="remixIdeIconPanel" className="iconpanel bg-light"></div>, iconPanel: <div ref={iconPanelRef} id="icon-panel" data-id="remixIdeIconPanel" className="iconpanel bg-light"></div>,
sidePanel: <div ref={sidePanelRef} id="side-panel" data-id="remixIdeSidePanel" className={`sidepanel border-right border-left ${hideSidePanel ? 'd-none' : ''}`}></div>, sidePanel: <div ref={sidePanelRef} id="side-panel" data-id="remixIdeSidePanel" className={`sidepanel border-right border-left ${hideSidePanel ? 'd-none' : ''}`}></div>,
resizePanel: <div ref={resizePanelRef} id="resize-panel" data-id="remixIdeResizePanel"></div>,
mainPanel: <div ref={mainPanelRef} id="main-panel" data-id="remixIdeMainPanel" className='mainpanel'></div>, mainPanel: <div ref={mainPanelRef} id="main-panel" data-id="remixIdeMainPanel" className='mainpanel'></div>,
hiddenPanel: <div ref={hiddenPanelRef}></div> hiddenPanel: <div ref={hiddenPanelRef}></div>
} }
@ -87,12 +78,11 @@ const RemixApp = (props: IRemixAppUi) => {
<div className={`remixIDE ${appReady ? '' : 'd-none'}`} data-id="remixIDE"> <div className={`remixIDE ${appReady ? '' : 'd-none'}`} data-id="remixIDE">
{components.iconPanel} {components.iconPanel}
{components.sidePanel} {components.sidePanel}
<DragBar refObject={sidePanelRef} setHideStatus={setHideSidePanel}></DragBar> <DragBar minWidth={250} refObject={sidePanelRef} hidden={hideSidePanel} setHideStatus={setHideSidePanel}></DragBar>
{components.mainPanel} {components.mainPanel}
</div> </div>
{components.hiddenPanel} {components.hiddenPanel}
<div className={`overlay ${dragState ? '' : 'd-none'}`} ></div>
</AppContext.Provider> </AppContext.Provider>
) )

@ -68,29 +68,4 @@ pre {
.splash { .splash {
text-align: center; text-align: center;
}
.dragbar {
display : block;
height : 100%;
position : absolute;
left: 367px;
top: 0px;
width: 0.3em;
z-index: 9999;
}
.overlay {
position: absolute;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
display: block;
z-index: 9998;
}
.dragbar:hover, .dragbar.ondrag{
background-color: var(--secondary);
cursor:col-resize;
} }
Loading…
Cancel
Save