Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
黄文鉴 committed Nov 26, 2023
1 parent bda7d7d commit e5a611c
Show file tree
Hide file tree
Showing 20 changed files with 450 additions and 891 deletions.
87 changes: 61 additions & 26 deletions demo/app.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,69 @@
import React, { useState } from 'react';
import React, { useContext, useRef, useState } from 'react';
import { createRoot } from 'react-dom/client';
import { FlexibleWorkbench, IWBConfigData, WBUtil } from '../src';
import { WBContext, Workbench, WBUtil } from '../src';

const LayoutData = {
Normal: WBUtil.createSplit([
WBUtil.createComponent('A'),
WBUtil.createSplit([WBUtil.createComponent('B'), WBUtil.createSplit([WBUtil.createComponent('C'), WBUtil.createComponent('D')])]),
]),
One: WBUtil.createComponent('A'),
Four: WBUtil.createSplit(
[
WBUtil.createComponent('A'),
WBUtil.createComponent('B'),
WBUtil.createSplit(
[WBUtil.createComponent('C'), WBUtil.createComponent('D')],
[{ type: 'fixed', size: 100 }, { type: 'flex' }],
'vertical'
),
],
[{ type: 'fixed', size: 100 }, { type: 'flex' }, { type: 'flex' }]
),
};

const _createComponent = (name: string, color: string) => {
return () => {
const renderCnt = useRef(0);
renderCnt.current++;

const ctx = useContext(WBContext);

return (
<div style={{ width: '100%', height: '100%', background: color }}>
<h3 style={{ marginTop: 0 }}>{name}</h3>
<p>Render Count: {renderCnt.current}</p>
<p>
{ctx.width} x {ctx.height}
</p>
</div>
);
};
};

const components = {
A: _createComponent('A', 'red'),
B: _createComponent('B', 'green'),
C: _createComponent('C', 'blue'),
D: _createComponent('D', 'yellow'),
};

const App = () => {
const [dataName, setDataName] = useState<keyof typeof LayoutData>('Normal');

return (
<div style={{ height: '100vh', width: '100vw', padding: 16, boxSizing: 'border-box' }}>
<FlexibleWorkbench
components={{
A: () => <div style={{ background: 'red' }}>A</div>,
B: () => <div style={{ background: 'green' }}>B</div>,
C: () => <div style={{ background: 'blue' }}>C</div>,
D: () => <div style={{ background: 'yellow' }}>D</div>,
}}
config={{
key: 'root',
layout: WBUtil.createSplit(
[
WBUtil.createComponent('A'),
WBUtil.createSplit(
[WBUtil.createComponent('B'), WBUtil.createSplit([WBUtil.createComponent('C'), WBUtil.createComponent('D')])],
'vertical',
0.5
),
],
'horizontal',
0.5
),
}}
onConfigChange={function (config: IWBConfigData, skipRefresh?: boolean | undefined) {}}
/>
<header style={{ height: 32 }}>
<select value={dataName} onChange={ev => setDataName(ev.target.value as any)}>
{Object.keys(LayoutData).map(key => (
<option key={key} value={key}>
{key}
</option>
))}
</select>
</header>

<Workbench components={components} layout={LayoutData[dataName]} style={{ height: 'calc(100% - 32px)' }} />
</div>
);
};
Expand Down
29 changes: 0 additions & 29 deletions src/FWContext.ts

This file was deleted.

112 changes: 0 additions & 112 deletions src/FlexibleComponent.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions src/FlexibleLayout.tsx

This file was deleted.

112 changes: 0 additions & 112 deletions src/FlexibleSidePanelContainer.tsx

This file was deleted.

Loading

0 comments on commit e5a611c

Please sign in to comment.