Last active
June 15, 2020 12:20
-
-
Save tomdye/9599434156ca20e8e3d0b00802b500e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { create, tsx } from '@dojo/framework/core/vdom'; | |
| import theme from '@dojo/framework/core/middleware/theme'; | |
| import icache from '@dojo/framework/core/middleware/icache'; | |
| import drag from '@dojo/framework/core/middleware/drag'; | |
| import * as css from './SplitPane.m.css'; | |
| import { RenderResult } from '@dojo/framework/core/interfaces'; | |
| export interface SplitPaneProperties { | |
| reverse?: boolean; | |
| initialWidth?: number; | |
| } | |
| export interface SplitPaneChildren { | |
| leading: RenderResult; | |
| trailing: RenderResult; | |
| } | |
| const factory = create({ icache, theme, drag }).children<SplitPaneChildren>().properties<SplitPaneProperties>(); | |
| export default factory(function SplitPane({ middleware: { icache, theme, drag }, children, properties }) { | |
| const [{ leading, trailing }] = children(); | |
| const { reverse, initialWidth = 300 } = properties(); | |
| const thumbDrag = drag.get('thumb'); | |
| let width = icache.getOrSet('width', initialWidth); | |
| if (thumbDrag.isDragging) { | |
| width = icache.set('width', width + thumbDrag.delta.x); | |
| } | |
| return ( | |
| <div key='root' classes={[css.root, theme.variant(), reverse && css.reverse]}> | |
| <div classes={css.leading} styles={{ width: `${width}px`}}>{ leading }</div> | |
| <div classes={css.divider}> | |
| <div classes={css.thumb} key='thumb'></div> | |
| </div> | |
| <div classes={css.trailing}>{ trailing }</div> | |
| </div> | |
| ); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment