-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from agentlab/issue-40-refactor-layout-behavio…
…r-and-styles GH-40 Refactor layout behaviour, add PanelLayout, add some layout stories
- Loading branch information
Showing
24 changed files
with
1,777 additions
and
951 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
|
||
import { rankWith, RankedTester, uiTypeIs } from '../testers'; | ||
|
||
function getRandomInt(max: number) { | ||
return Math.floor(Math.random() * max); | ||
} | ||
|
||
const colors = ['#FED6BC', '#FFFADD', '#DEF7FE', '#E7ECFF', '#C3FBD8', '#FDEED9', '#F6FFF8', '#B5F2EA', '#C6D8FF']; | ||
|
||
export const PanelWithText: React.FC<any> = (props) => { | ||
const style = props?.viewKindElement.options?.style; | ||
const value = props?.viewKindElement.options?.value; | ||
return ( | ||
<div style={{ ...style, backgroundColor: colors[getRandomInt(colors.length)] }}> | ||
<pre style={{ verticalAlign: 'center' }}>{value}</pre> | ||
</div> | ||
); | ||
}; | ||
|
||
export const panelWithTextControlTester: RankedTester = rankWith(3, uiTypeIs('aldkg:TextPanel')); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2020 Agentlab and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the GNU General Public License v. 3.0 which is available at | ||
* https://www.gnu.org/licenses/gpl-3.0.html. | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
********************************************************************************/ | ||
import React from 'react'; | ||
import { FormsDispatchProps, FormsDispatch } from '../Form'; | ||
import { rankWith, uiTypeIs, RankedTester } from '../testers'; | ||
import { Idx } from '../util/layout'; | ||
import { withLayoutProps } from '../util/ContextToProps'; | ||
import { renderLayoutElements } from '../util/layout'; | ||
|
||
import { LayoutComponent } from './LayoutComponent'; | ||
|
||
export const PanelLayout: React.FC<LayoutComponent> = ({ | ||
viewKind, | ||
viewKindElement, | ||
viewDescr, | ||
viewDescrElement, | ||
enabled, | ||
visible, | ||
form, | ||
}) => { | ||
const options = viewKindElement.options || {}; | ||
const style = options.style; | ||
const layoutStyle: React.CSSProperties = {}; | ||
const childLayoutStyle: React.CSSProperties = {}; | ||
if (options.flow === 'horizontal') { | ||
layoutStyle.whiteSpace = 'nowrap'; | ||
} | ||
|
||
if (options.flow === 'horizontal' || options.flow === 'wrap') { | ||
childLayoutStyle.display = 'inline-block'; | ||
} | ||
|
||
const Render: React.FC<FormsDispatchProps & Idx> = ({ idx, viewKind, viewKindElement, viewDescr, enabled }) => { | ||
const style = viewKindElement.options?.style; | ||
const newViewKindElement = { ...viewKindElement }; | ||
if (newViewKindElement.options) { | ||
newViewKindElement.options.style = { ...style, ...childLayoutStyle }; | ||
} | ||
return ( | ||
<FormsDispatch | ||
viewKind={viewKind} | ||
viewKindElement={newViewKindElement} | ||
viewDescr={viewDescr} | ||
enabled={enabled} | ||
form={form} | ||
/> | ||
); | ||
}; | ||
return ( | ||
<div style={{ ...style, ...layoutStyle }}> | ||
{renderLayoutElements({ viewKind, viewKindElement, viewDescr, enabled, Render })} | ||
</div> | ||
); | ||
}; | ||
|
||
export const panelLayoutTester: RankedTester = rankWith(2, uiTypeIs('aldkg:PanelLayout')); | ||
export const PanelLayoutWithStore = withLayoutProps(PanelLayout); |
Oops, something went wrong.