Skip to content

Commit

Permalink
feat: add logic-diagram to Next and AntD (TBD) (#1158)
Browse files Browse the repository at this point in the history
* feat: add next-logic-diagram

* fix: use scss variable instead of literal color string
  • Loading branch information
soulwu authored Feb 23, 2021
1 parent 43972ba commit 5626d97
Show file tree
Hide file tree
Showing 8 changed files with 578 additions and 5 deletions.
127 changes: 127 additions & 0 deletions packages/next/docs/components/LogicDiagram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# LogicDiagram

## Markup Schema 案例

```jsx
import React from 'react'
import {
Switch,
Input,
Select,
LogicDiagram,
FormItem,
FormButtonGroup,
Submit,
} from '@formily/next'
import { createForm, onFieldChange } from '@formily/core'
import { FormProvider, createSchemaField } from '@formily/react'

const SchemaField = createSchemaField({
components: {
Switch,
Input,
Select,
LogicDiagram,
FormItem,
},
})

const form = createForm({
values: {
editable: true,
logic: {
relation: 'OR',
rule: [
{ field: 'field1', operator: 'EQ', value: '123' },
{
relation: 'AND',
rule: [
{ field: 'field2', operator: 'NEQ', value: '456' },
{ field: 'field2', operator: 'NEQ', value: '654' },
],
},
{ field: 'field3', operator: 'EQ', value: '789' },
],
},
},
effects: () => {
onFieldChange('editable', ['value'], (field) => {
field.query('logic').take((target) => {
target.editable = !!field.value
})
})
},
})

export default () => (
<FormProvider form={form}>
<SchemaField>
<SchemaField.Boolean
name="editable"
title="可编辑"
x-decorator="FormItem"
x-component="Switch"
/>
<SchemaField.Object
name="logic"
title="条件表达式"
x-decorator="FormItem"
x-component="LogicDiagram"
>
<SchemaField.Void x-component="LogicDiagram.Relation">
<SchemaField.String
name="relation"
x-decorator="FormItem"
x-component="Select"
enum={[
{ label: '', value: 'OR' },
{ label: '', value: 'AND' },
]}
/>
</SchemaField.Void>
<SchemaField.Object name="rule" x-component="LogicDiagram.Rule">
<SchemaField.String
name="field"
x-decorator="FormItem"
x-component="Select"
enum={[
{ label: '字段一', value: 'field1' },
{ label: '字段二', value: 'field2' },
{ label: '字段三', value: 'field3' },
]}
required
/>
<SchemaField.String
name="operator"
x-decorator="FormItem"
x-component="Select"
enum={[
{ label: '等于', value: 'EQ' },
{ label: '不等于', value: 'NEQ' },
]}
required
/>
<SchemaField.String
name="value"
x-decorator="FormItem"
x-component="Input"
required
/>
</SchemaField.Object>
<SchemaField.Void x-component="LogicDiagram.AddRule" name="addRule" />
<SchemaField.Void
x-component="LogicDiagram.AddRuleGroup"
name="addRuleGroup"
/>
<SchemaField.Void
x-component="LogicDiagram.RemoveRule"
name="removeRule"
/>
</SchemaField.Object>
</SchemaField>
<FormButtonGroup>
<Submit onSubmit={console.log}>提交</Submit>
</FormButtonGroup>
</FormProvider>
)
```
1 change: 1 addition & 0 deletions packages/next/docs/components/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- FormDialog
- FormDrawer
- Editable
- LogicDiagram
- 阅读态组件
- PreviewText
- 主题定制能力
Expand Down
9 changes: 5 additions & 4 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@
"build:docs": "dumi build"
},
"peerDependencies": {
"@alifd/next": "^1.19.0",
"@types/react": ">=16.8.0 || >=17.0.0",
"@types/react-dom": ">=16.8.0 || >=17.0.0",
"@alifd/next": "^1.19.0",
"mobx": "^6.0.3",
"react": ">=16.8.0 || >=17.0.0",
"react-dom": ">=16.8.0"
},
"devDependencies": {
"dumi": "^1.1.0-rc.8",
"@umijs/plugin-sass": "^1.1.1"
"@umijs/plugin-sass": "^1.1.1",
"dumi": "^1.1.0-rc.8"
},
"dependencies": {
"@ant-design/icons": "^4.0.0",
"@formily/json-schema": "^2.0.0-beta.3",
"@formily/core": "^2.0.0-beta.3",
"@formily/json-schema": "^2.0.0-beta.3",
"@formily/react": "^2.0.0-beta.3",
"@formily/react-logic-diagram": "^2.0.0-beta.3",
"@formily/shared": "^2.0.0-beta.3",
"classnames": "^2.2.6",
"react-sortable-hoc": "^1.11.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export * from './upload'
export * from './preview-text'
export * from './submit'
export * from './reset'
export * from './editable'
export * from './editable'
export * from './logic-diagram'
Loading

0 comments on commit 5626d97

Please sign in to comment.