Skip to content

Commit 8e8349f

Browse files
committed
feat: strip \n
1 parent e033266 commit 8e8349f

File tree

5 files changed

+134
-17
lines changed

5 files changed

+134
-17
lines changed

__tests__/basic.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ const reactMarkdownProps = require('../src');
22

33
describe('Basic test', () => {
44
test('test development', () => {
5-
65
console.log(reactMarkdownProps('__tests__/components/index.js'));
7-
86
// expect(true).toBe(true);
97
});
108
});

__tests__/components/index2.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import React, { Component } from 'react';
2+
import ReactDOM from 'react-dom';
3+
import PropTypes from 'prop-types';
4+
import classNames from 'classnames';
5+
import noop from '@feizheng/noop';
6+
import objectAssign from 'object-assign';
7+
import { Form, Button } from 'antd';
8+
9+
const CLASS_NAME = 'react-ant-form';
10+
export default Form.create()(
11+
class ReactAntForm extends Component {
12+
static displayName = CLASS_NAME;
13+
static version = '__VERSION__';
14+
static propTypes = {
15+
/**
16+
* The extended className for component.
17+
*/
18+
className: PropTypes.string,
19+
/**
20+
* Default fileds value object.
21+
*/
22+
fieldsValue: PropTypes.object,
23+
/**
24+
* Form schema.
25+
*/
26+
items: PropTypes.array,
27+
/**
28+
* The onSubmit event.
29+
*/
30+
onSubmit: PropTypes.func,
31+
/**
32+
* When component did mount.
33+
*/
34+
onLoad: PropTypes.func,
35+
/**
36+
* The formLayout for antd.Form.
37+
*/
38+
formLayout: PropTypes.object,
39+
/**
40+
* The submit label.
41+
*/
42+
submitLabel: PropTypes.string,
43+
/**
44+
* The submit props.
45+
*/
46+
submitProps: PropTypes.object
47+
};
48+
49+
static defaultProps = {
50+
fieldsValue: {},
51+
items: [],
52+
onSubmit: noop,
53+
onLoad: noop,
54+
formLayout: {
55+
labelCol: { span: 6 },
56+
wrapperCol: { span: 16 }
57+
},
58+
submitLabel: ' ',
59+
submitProps: {
60+
type: 'primary',
61+
htmlType: 'submit',
62+
children: 'Save'
63+
}
64+
};
65+
66+
componentDidMount() {
67+
const { onLoad, fieldsValue, form } = this.props;
68+
const { getFieldDecorator, setFields } = form;
69+
objectAssign(this, { $form: form });
70+
setFields(fieldsValue);
71+
onLoad({
72+
target: {
73+
sender: this,
74+
value: this.props
75+
}
76+
});
77+
}
78+
79+
handleSubmit = (inEvent) => {
80+
inEvent.preventDefault();
81+
const { onSubmit, form } = this.props;
82+
form.validateFields((err, values) => {
83+
if (!err) {
84+
onSubmit(values);
85+
}
86+
});
87+
};
88+
89+
render() {
90+
const { className, items, formLayout, submitLabel, submitProps } = this.props;
91+
const { getFieldDecorator } = this.props.form;
92+
93+
return (
94+
<Form
95+
data-component={CLASS_NAME}
96+
className={classNames(CLASS_NAME, className)}
97+
onSubmit={this.handleSubmit}>
98+
{items.map((item, index) => {
99+
return (
100+
<Form.Item
101+
className="react-ant-form-field"
102+
{...formLayout}
103+
key={index}
104+
label={item.label}>
105+
{getFieldDecorator(item.field, {
106+
rules: item.rules
107+
})(<item.component {...item.props} />)}
108+
</Form.Item>
109+
);
110+
})}
111+
<Form.Item
112+
{...formLayout}
113+
className="react-ant-form-submit"
114+
label={submitLabel}
115+
colon={false}>
116+
<Button {...submitProps} />
117+
</Form.Item>
118+
</Form>
119+
);
120+
}
121+
}
122+
);

dist/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*!
22
* name: @feizheng/react-markdown-props
33
* url: https://github.com/afeiship/react-markdown-props
4-
* version: 1.1.0
4+
* version: 1.2.0
55
* license: MIT
66
*/
77

8-
var reactDocs=require("react-docgen"),fs=require("fs"),json2md=require("json2md"),prettier=require("prettier");require("@feizheng/next-js-core2"),module.exports=function(e,r){var t=fs.readFileSync(e),a=reactDocs.parse(t),n=[];nx.forIn(a.props,function(e,r){n.push([e,r.type.name,nx.get(r,"defaultValue.value")||"-",r.description])});var o=json2md({table:{headers:["Name","Type","Default","Description"],rows:n}});return prettier.format(o,{parser:"markdown"})};
8+
var reactDocs=require("react-docgen"),fs=require("fs"),json2md=require("json2md"),prettier=require("prettier");require("@feizheng/next-js-core2"),module.exports=function(e,r){var t=fs.readFileSync(e),n=reactDocs.parse(t),a=[];nx.forIn(n.props,function(e,r){var t=nx.get(r,"defaultValue.value","-");t.includes("\n")&&(t="-"),a.push([e,r.type.name,t,r.description])});var s=json2md({table:{headers:["Name","Type","Default","Description"],rows:a}});return prettier.format(s,{parser:"markdown"})};

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@feizheng/react-markdown-props",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Generate markdown properties string.",
55
"homepage": "https://github.com/afeiship/react-markdown-props",
66
"author": {
@@ -14,23 +14,23 @@
1414
"main": "dist/index.js",
1515
"license": "MIT",
1616
"devDependencies": {
17-
"@feizheng/next-nice-comments": "^1.0.0",
17+
"@feizheng/next-nice-comments": "^1.0.1",
1818
"del": "^5.1.0",
1919
"gulp": "^4.0.2",
20-
"gulp-header": "^2.0.7",
21-
"gulp-load-plugins": "^2.0.1",
20+
"gulp-header": "^2.0.9",
21+
"gulp-load-plugins": "^2.0.2",
2222
"gulp-size": "^3.0.0",
2323
"gulp-uglify": "^3.0.2",
24-
"jest": "^24.8.0",
24+
"jest": "^25.1.0",
2525
"react": "^16.12.0"
2626
},
2727
"publishConfig": {
2828
"registry": "https://registry.npmjs.org/"
2929
},
3030
"dependencies": {
31-
"@feizheng/next-js-core2": "^2.4.0",
31+
"@feizheng/next-js-core2": "^2.4.1",
3232
"json2md": "^1.6.5",
3333
"prettier": "^1.19.1",
34-
"react-docgen": "^5.1.0"
34+
"react-docgen": "^5.2.1"
3535
}
3636
}

src/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ module.exports = function(inFilePath, inOptions) {
1111
var rows = [];
1212

1313
nx.forIn(info.props, function(key, value) {
14-
rows.push([
15-
key,
16-
value.type.name,
17-
nx.get(value, 'defaultValue.value') || '-',
18-
value.description
19-
]);
14+
var _value = nx.get(value, 'defaultValue.value', '-');
15+
_value.includes('\n') && (_value = '-');
16+
rows.push([key, value.type.name, _value, value.description]);
2017
});
2118

2219
var mdstring = json2md({

0 commit comments

Comments
 (0)