UNPKG

gg-editor

Version:

A visual graph editor based on G6 and React

75 lines (60 loc) 1.48 kB
import React from 'react'; import { Card, Form, Input } from 'antd'; import { withPropsAPI } from '@src'; const { Item } = Form; const inlineFormItemLayout = { labelCol: { sm: { span: 6 }, }, wrapperCol: { sm: { span: 18 }, }, }; class NodeDetail extends React.Component { handleSubmit = (e) => { e.preventDefault(); const { form, propsAPI } = this.props; const { getSelected, executeCommand, update } = propsAPI; form.validateFieldsAndScroll((err, values) => { if (err) { return; } const item = getSelected()[0]; if (!item) { return; } executeCommand(() => { update(item, { ...values, }); }); }); } render() { const { form, propsAPI } = this.props; const { getFieldDecorator } = form; const { getSelected } = propsAPI; const item = getSelected()[0]; if (!item) { return null; } const { label } = item.getModel(); return ( <Card type="inner" title="节点属性" bordered={false}> <Form onSubmit={this.handleSubmit}> <Item label="标签" {...inlineFormItemLayout} > { getFieldDecorator('label', { initialValue: label, })(<Input onBlur={this.handleSubmit} />) } </Item> </Form> </Card> ); } } export default Form.create()(withPropsAPI(NodeDetail));