-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor dockview update logic
- Loading branch information
mathuo
authored and
mathuo
committed
Jun 7, 2021
1 parent
3f93b34
commit ccd8e7f
Showing
14 changed files
with
479 additions
and
259 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
111 changes: 111 additions & 0 deletions
111
packages/dockview-demo/src/stories/gridview/gridview.params.stories.tsx
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,111 @@ | ||
import { | ||
GridviewApi, | ||
GridviewReact, | ||
GridviewReadyEvent, | ||
IGridviewPanelProps, | ||
Orientation, | ||
PanelCollection, | ||
} from 'dockview'; | ||
import * as React from 'react'; | ||
import { Meta } from '@storybook/react'; | ||
|
||
const components: PanelCollection<IGridviewPanelProps<any>> = { | ||
default: (props) => { | ||
return ( | ||
<div style={{ padding: '10px', height: '100%' }}>hello world</div> | ||
); | ||
}, | ||
ticker: (props: IGridviewPanelProps<{ ticker: number }>) => { | ||
return ( | ||
<div style={{ padding: '10px', height: '100%' }}> | ||
{`The current ticker value is ${props.params.ticker}`} | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
export const Params = (props: { | ||
onEvent: (name: string) => void; | ||
theme: string; | ||
hideBorders: boolean; | ||
disableAutoResizing: boolean; | ||
}) => { | ||
const api = React.useRef<GridviewApi>(); | ||
|
||
React.useEffect(() => { | ||
if (!api.current) { | ||
return () => { | ||
// noop | ||
}; | ||
} | ||
|
||
const gridApi = api.current; | ||
|
||
const interval = setInterval(() => { | ||
const panel1 = gridApi.getPanel('panel1'); | ||
|
||
panel1.update({ params: { ticker: Date.now() } }); | ||
}, 1000); | ||
return () => { | ||
clearInterval(interval); | ||
}; | ||
}, [api]); | ||
|
||
const onReady = (event: GridviewReadyEvent) => { | ||
api.current = event.api; | ||
|
||
event.api.onGridEvent((e) => props.onEvent(e.kind)); | ||
|
||
event.api.addPanel({ | ||
id: 'panel1', | ||
component: 'ticker', | ||
params: { | ||
ticker: 0, | ||
}, | ||
}); | ||
event.api.addPanel({ | ||
id: 'panel2', | ||
component: 'default', | ||
}); | ||
event.api.addPanel({ | ||
id: 'panel3', | ||
component: 'default', | ||
}); | ||
}; | ||
|
||
return ( | ||
<GridviewReact | ||
orientation={Orientation.HORIZONTAL} | ||
className={props.theme} | ||
onReady={onReady} | ||
components={components} | ||
hideBorders={props.hideBorders} | ||
disableAutoResizing={props.disableAutoResizing} | ||
/> | ||
); | ||
}; | ||
|
||
export default { | ||
title: 'Library/Gridview/Params', | ||
component: Params, | ||
decorators: [ | ||
(Component) => { | ||
document.body.style.padding = '0px'; | ||
return ( | ||
<div style={{ height: '100vh', fontFamily: 'Arial' }}> | ||
<Component /> | ||
</div> | ||
); | ||
}, | ||
], | ||
args: { theme: 'dockview-theme-light' }, | ||
argTypes: { | ||
theme: { | ||
control: { | ||
type: 'select', | ||
options: ['dockview-theme-dark', 'dockview-theme-light'], | ||
}, | ||
}, | ||
onEvent: { action: 'onEvent' }, | ||
}, | ||
} as Meta; |
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
109 changes: 109 additions & 0 deletions
109
packages/dockview-demo/src/stories/splitview/splitview.params.stories.tsx
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,109 @@ | ||
import { | ||
ISplitviewPanelProps, | ||
Orientation, | ||
PanelCollection, | ||
SplitviewApi, | ||
SplitviewReact, | ||
SplitviewReadyEvent, | ||
} from 'dockview'; | ||
import * as React from 'react'; | ||
import { Meta } from '@storybook/react'; | ||
|
||
const components: PanelCollection<ISplitviewPanelProps<any>> = { | ||
default: (props) => { | ||
return ( | ||
<div style={{ padding: '10px', height: '100%' }}>hello world</div> | ||
); | ||
}, | ||
ticker: (props: ISplitviewPanelProps<{ ticker: number }>) => { | ||
return ( | ||
<div style={{ padding: '10px', height: '100%' }}> | ||
{`The current ticker value is ${props.params.ticker}`} | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
export const Params = (props: { | ||
onEvent: (name: string) => void; | ||
theme: string; | ||
hideBorders: boolean; | ||
disableAutoResizing: boolean; | ||
}) => { | ||
const api = React.useRef<SplitviewApi>(); | ||
|
||
React.useEffect(() => { | ||
if (!api.current) { | ||
return () => { | ||
// noop | ||
}; | ||
} | ||
|
||
const gridApi = api.current; | ||
|
||
const interval = setInterval(() => { | ||
const panel1 = gridApi.getPanel('panel1'); | ||
|
||
panel1.update({ params: { ticker: Date.now() } }); | ||
}, 1000); | ||
return () => { | ||
clearInterval(interval); | ||
}; | ||
}, [api]); | ||
|
||
const onReady = (event: SplitviewReadyEvent) => { | ||
api.current = event.api; | ||
|
||
event.api.addPanel({ | ||
id: 'panel1', | ||
component: 'ticker', | ||
params: { | ||
ticker: 0, | ||
}, | ||
}); | ||
event.api.addPanel({ | ||
id: 'panel2', | ||
component: 'default', | ||
}); | ||
event.api.addPanel({ | ||
id: 'panel3', | ||
component: 'default', | ||
}); | ||
}; | ||
|
||
return ( | ||
<SplitviewReact | ||
orientation={Orientation.HORIZONTAL} | ||
className={props.theme} | ||
onReady={onReady} | ||
components={components} | ||
hideBorders={props.hideBorders} | ||
disableAutoResizing={props.disableAutoResizing} | ||
/> | ||
); | ||
}; | ||
|
||
export default { | ||
title: 'Library/Splitview/Params', | ||
component: Params, | ||
decorators: [ | ||
(Component) => { | ||
document.body.style.padding = '0px'; | ||
return ( | ||
<div style={{ height: '100vh', fontFamily: 'Arial' }}> | ||
<Component /> | ||
</div> | ||
); | ||
}, | ||
], | ||
args: { theme: 'dockview-theme-light' }, | ||
argTypes: { | ||
theme: { | ||
control: { | ||
type: 'select', | ||
options: ['dockview-theme-dark', 'dockview-theme-light'], | ||
}, | ||
}, | ||
onEvent: { action: 'onEvent' }, | ||
}, | ||
} as Meta; |
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
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
Oops, something went wrong.