This is a proof of concept heavily
inspired by react-mosaic.
This is currently a research project into what a grid that works nearly identical to VSCode
, which has implemented a great grid style for their tabs/windows.
Not meant to compete with react-mosaic
really as we currently use it fairly heavily in our projects.
To see the current API/props being used for testing, see App.js.
Simply because I wasn't sure how this would be done in the first place and it was a fun challenge. I also use Flow over Typescript so there's the learning curve there to deal with for now, although we are moving to TS at work so....
This is just an ejected create-react-app
so... clone/fork then yarn && yarn start
.
-
No dependencies for most part (
react-dnd
is added and will likely be needed). Dependencies shown inpackage.json
are allcreate-react-app
.styled-components
is currently a dependency but it would be separated easily. Theming with standard react components would be simple.
-
Tree vs Binary Tree Format (fixes react-mosaic#31)
-
Custom constraints per tile and the ability to provide grid-wide constraints by pixels AND percent (height and width).
-
Provides optional context to children for more performant rendering (fixes react-mosaic#79 among other things).
- For example,
isDragging
,height
,width
,position
, and more are planned (with the latter 3 currently implemented) (fixes react-mosaic#69).
- For example,
- Stateful Resizing which is how VSCode works.
- Resizing will move sibling elements further than one step in the tree if needed and if dragged back again the windows return to their original sizes.
- Releasing the resizer will reset the state for the next resize.
- This is customizable with options
stateful
,push
,passive
. More Info - Also planned is ability to resize in corners to modify both width and height simultaneously. Most of the needs to do this efficiently are already complete.
- Utilizes
styled-components
and CSS Variables for extremely simple theming capabilities. Best to just read the defaultTheme comments to see how this works. Makes dynamic styling extremely efficient but is also not technically dependent onstyled-components
. The components exported could be provided by another means if desired.
Providing overrides to the selected themes styling is very simple with
styled-components
!
import { css } from "styled-components/macro";
const CSS_OVERRIDES = css`
--dg-tile-padding: 1px;
--dg-widget-border-radius: 2px;
--dg-widget-content-background: whitesmoke;
`;
<DynamicGrid cssVariables{CSS_OVERRIDES} />
- Tabbed windows opt-in (fixes react-mosaic#50).
- Providing
<DynamicGrid tabbed>
will render widgets with the ability to do tabbing. This is done by providing atabs
,activeTab
, and optionallytitle
property. - May customize the tab render by providing
renderTitle
function which is called if found with the context for thetile
. - If not using
tabbed
, you may still provide thetabs
property. If you also provideactiveTab
it will render the given tab and allows easily providing conditional rendering by modifying that property.- If
tabs
is provided withoutactiveTab
then the first element is rendered by default whentabbed
is false (or not defined).
- If
- Providing
-
Extremely simple to serialize, similar to
react-mosaic
by simplyJSON.stringify(grid)
. -
PERFORMANT - Designed to be extremely performant and provide its dynamic capabilities at a full 60 fps.
react-mosaic
is also quite performant although its biggest failure here is that it can be broken by children inside the grid (for example, atradingview chart
cant be used within a node).
- Drag & Drop (have to learn React DnD still :-P).
- Flow Typing is not finished or really implemented aside from basic structure for it. Won't be hard to get 100% coverage here though as the overall structures are simple.
- Controlled mode in the same way
react-mosaic
provides it. Not sure this is needed with how this is implemented but considering it. Would not be hard in the end to provide.