Skip to content

Commit fb4eed6

Browse files
committed
hide and show panes
1 parent 8193361 commit fb4eed6

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fiug/layout",
3-
"version": "0.0.16",
3+
"version": "0.1.0",
44
"description": "page layout for browser applications",
55
"main": "dist/layout.js",
66
"exports": {

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ class Layout {
4545
const { tab, pane } = args;
4646
const file = UrlParams(tab.getAttribute("source")).get("file");
4747
this.tabbed.closeTab(pane, tab);
48-
this.onClose({ pane: pane.id, file })
48+
this.onClose({ pane: pane.id, file });
4949
this.onChange();
5050
};
5151
this.closePane = (args) => {
5252
state.closePane(this)(args);
5353
this.onChange();
5454
};
55+
this.hidePane = (args) =>state.hidePane(this)(args);
56+
this.showPane = (args) =>state.showPane(this)(args);
5557

5658
this.dom = dom.createDom(this);
5759
if(!this.dom) return console.error('layout creation failed');

src/removePane.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ const removePaneConfig = ({ layout, pane }) => {
1919

2020
if(paneConfig.fixed)
2121
return { error: "pane is fixed, cannot be closed" }
22-
22+
2323
const parentConfig = getConfigNode(
2424
config,
2525
(node) => node.children && node.children
2626
.find(c => c.id === pane)
2727
);
28-
28+
2929
if(parentConfig.children.length === parentConfig.minChildren)
3030
return { error: "cannot close pane, parent has reached minimum children limit" };
3131
if(!parentConfig)

src/splitting.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ const halfDim = (dim) => {
1515
export const setSize = (container, config) => {
1616
if(config.orient === "column"){
1717
container.style.gridTemplateColumns = config.children
18-
.map(x=>x.width || '1fr')
18+
.map(x => {
19+
if(x.hidden) return '0px';
20+
return x.width || '1fr';
21+
})
1922
.join(' 0px ');
2023
return;
2124
}
2225
container.style.gridTemplateRows = config.children
23-
.map(x=>x.height || '1fr')
26+
.map(x => {
27+
if(x.hidden) return '0px';
28+
return x.height || '1fr';
29+
})
2430
.join(' 0px ');
2531
};
2632

src/state.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,21 @@ export const onResize = (layout) => (sizer, i, x, y) => {
305305
};
306306

307307
export const closePane = removePane;
308+
309+
310+
const setPaneHidden = ({ layout, name, hidden }) => {
311+
const { config, dom } = layout;
312+
if(!config || !dom) return console.log('config and/or dom not found');
313+
const paneConfig = getConfigNode(config, x => x.name === name);
314+
const parentConfig = getConfigNode(
315+
config,
316+
(node) => node.children && node.children
317+
.find(c => c.id === paneConfig.id)
318+
);
319+
const parentDom = document.querySelector('#'+parentConfig.id);
320+
paneConfig.hidden = hidden;
321+
layout.splitting.setSize(parentDom,parentConfig);
322+
layout.onChange();
323+
};
324+
export const hidePane = (layout) => ({ name }) => setPaneHidden({ layout, name, hidden: true });
325+
export const showPane = (layout) => ({ name }) => setPaneHidden({ layout, name, hidden: false });

0 commit comments

Comments
 (0)