-
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 #2 from agentlab/issue-1-add-cardcell-and-gridlayout
GH-1 add cardcell and gridlayout
- Loading branch information
Showing
21 changed files
with
2,262 additions
and
2,195 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
|
||
import { uiTypeIs, rankWith, RankedTester } from '../testers'; | ||
import { withStoreToCellProps } from '../util/ContextToProps'; | ||
import { Button } from 'antd'; | ||
|
||
export const AntdButtonCell = (props: any) => { | ||
const options = props.uiOptions; | ||
return ( | ||
<Button size={'small'} style={options.style}> | ||
{options.label} | ||
</Button> | ||
); | ||
}; | ||
|
||
/** | ||
* Default tester for text-based/string controls. | ||
* @type {RankedTester} | ||
*/ | ||
export const antdButtonCellTester: RankedTester = rankWith(2, uiTypeIs('Button')); | ||
|
||
export const AntdButtonCellWithStore = withStoreToCellProps(AntdButtonCell); |
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,47 @@ | ||
/******************************************************************************** | ||
* 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 { rankWith, RankedTester, uiTypeIs } from '../testers'; | ||
import { get } from 'lodash-es'; | ||
|
||
import { ViewElement } from '../models/uischema'; | ||
import { Card } from 'antd'; | ||
import { DispatchCell } from '../DispatchCell'; | ||
import './cell.css'; | ||
|
||
export const AntdCellCardLayout = (props: any) => { | ||
const { viewElement, view, schema, uischema, data, id } = props; | ||
const createCardChilds = () => | ||
viewElement.elements | ||
? viewElement.elements.map((e: ViewElement, idx: number) => { | ||
const newSchema = e.scope ? get(schema, 'properties.' + e.scope.replace(/\//, '.properties.')) : schema; | ||
return ( | ||
<DispatchCell | ||
id={id + String(idx)} | ||
key={id + String(idx)} | ||
view={view} | ||
data={data} | ||
rowData={data} | ||
schema={newSchema || schema} | ||
viewElement={e} | ||
uischema={uischema} | ||
/> | ||
); | ||
}) | ||
: null; | ||
return <Card hoverable>{createCardChilds()}</Card>; | ||
}; | ||
|
||
/** | ||
* Default tester for text-based/string controls. | ||
* @type {RankedTester} | ||
*/ | ||
export const antdCellCardLayoutTester: RankedTester = rankWith(2, uiTypeIs('CardLayout')); |
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,24 @@ | ||
import React from 'react'; | ||
|
||
import { uiTypeIs, rankWith, RankedTester } from '../testers'; | ||
import { withStoreToCellProps } from '../util/ContextToProps'; | ||
import { Image } from 'antd'; | ||
|
||
const template: any = { | ||
'https://www.wildberries.ru/catalog/15570386/detail.aspx': '/img/chart_1.png', | ||
'https://www.wildberries.ru/catalog/15622789/detail.aspx': '/img/chart_2.png', | ||
'https://www.wildberries.ru/catalog/16170086/detail.aspx': '/img/chart_3.png', | ||
'https://www.wildberries.ru/catalog/18247707/detail.aspx': '/img/chart_4.png', | ||
}; | ||
export const AntdCellG2 = (props: any) => { | ||
console.log('PROPS', props); | ||
return <Image src={template[props.data['@id']]} />; | ||
}; | ||
|
||
/** | ||
* Default tester for text-based/string controls. | ||
* @type {RankedTester} | ||
*/ | ||
export const antdCellG2Tester: RankedTester = rankWith(2, uiTypeIs('G2')); | ||
|
||
export const AntdCellG2WithStore = withStoreToCellProps(AntdCellG2); |
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,83 @@ | ||
/******************************************************************************** | ||
* 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 { Row, Col } from 'antd'; | ||
|
||
import { DispatchCell } from '../DispatchCell'; | ||
import { DispatchCellProps } from '../Form'; | ||
import { ViewElement } from '../models/uischema'; | ||
import { rankWith, uiTypeIs, RankedTester } from '../testers'; | ||
import { get } from 'lodash-es'; | ||
|
||
import { Idx } from '../util/layout'; | ||
|
||
export const AntdHorizontalLayoutRenderer: React.FC<DispatchCellProps> = ({ | ||
uischema, | ||
viewElement, | ||
view, | ||
data, | ||
schema, | ||
}) => { | ||
//const layout = viewElement as Layout; | ||
const Render: React.FC<DispatchCellProps & Idx> = ({ | ||
idx, | ||
schema, | ||
uischema, | ||
viewElement, | ||
view, | ||
data, | ||
enabled, | ||
parent, | ||
form, | ||
}) => { | ||
const options = viewElement.options || {}; | ||
//const style: any = options.style; | ||
const span = options.contentSize || !viewElement.elements ? undefined : Math.ceil(24 / viewElement.elements.length); | ||
const newSchema = viewElement.scope | ||
? get(schema, 'properties.' + viewElement.scope.replace(/\//, '.properties.')) | ||
: schema; | ||
return ( | ||
<Col key={idx} span={span}> | ||
<DispatchCell | ||
id={String(idx)} | ||
data={data} | ||
viewElement={viewElement} | ||
view={view} | ||
rowData={data} | ||
schema={newSchema || schema} | ||
uischema={uischema} | ||
enabled={enabled} | ||
parent={parent} | ||
form={form} | ||
/> | ||
</Col> | ||
); | ||
}; | ||
const justify: any = viewElement.options ? viewElement.options.justify : 'center'; | ||
const rowStyle: any = { flexWrap: 'nowrap' }; | ||
if (viewElement.options && viewElement.options.width === 'all-empty-space') rowStyle.width = '100%'; | ||
return ( | ||
<Row justify={justify} style={rowStyle} align={'middle'}> | ||
{(viewElement.elements || []).map((e: ViewElement, idx: number) => ( | ||
<Render | ||
viewElement={e} | ||
schema={schema} | ||
uischema={uischema} | ||
idx={idx} | ||
data={data} | ||
id={String(idx)} | ||
view={view} | ||
/> | ||
))} | ||
</Row> | ||
); | ||
}; | ||
|
||
export const antdHorizontalLayoutTester: RankedTester = rankWith(2, uiTypeIs('CellHorizontalLayout')); |
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,28 @@ | ||
import React from 'react'; | ||
|
||
import { withStoreToCellProps } from '../util/ContextToProps'; | ||
import { Rate } from 'antd'; | ||
|
||
import { uiTypeIs, rankWith, RankedTester } from '../testers'; | ||
|
||
export const AntdCellRateWidget = (props: any /*: EnumCellProps & WithClassname*/) => { | ||
return ( | ||
<React.Fragment> | ||
<Rate | ||
style={{ fontSize: '14px', color: 'rgb(255,140,0)', marginTop: '7px' }} | ||
allowHalf | ||
disabled | ||
defaultValue={props.data} | ||
/> | ||
<span style={{ padding: '4px', fontSize: '12px', fontWeight: 500 }}>{`(${props.data})`}</span> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
/** | ||
* Default tester for enum controls. | ||
* @type {RankedTester} | ||
*/ | ||
export const antdCellRateWidgetTester: RankedTester = rankWith(5, uiTypeIs('Rate')); | ||
|
||
export const AntdCellRateWidgetWithStore = withStoreToCellProps(AntdCellRateWidget); |
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,20 @@ | ||
import React from 'react'; | ||
|
||
import { uiTypeIs, rankWith, RankedTester } from '../testers'; | ||
import { withStoreToCellProps } from '../util/ContextToProps'; | ||
import { Image } from 'antd'; | ||
import { useEffect } from '@storybook/addons'; | ||
import './cell.css'; | ||
|
||
export const AntdImageCell = (props: any) => { | ||
const { data } = props; | ||
return <Image style={{ height: '100%', width: '100%' }} src={data[0]} />; | ||
}; | ||
|
||
/** | ||
* Default tester for text-based/string controls. | ||
* @type {RankedTester} | ||
*/ | ||
export const antdImageCellTester: RankedTester = rankWith(2, uiTypeIs('ImageCell')); | ||
|
||
export const AntdImageCellWithStore = withStoreToCellProps(AntdImageCell); |
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
Oops, something went wrong.