Skip to content

Commit 30f109c

Browse files
authored
feat(Form): add size to form
close #127
1 parent 6004434 commit 30f109c

File tree

33 files changed

+6045
-5727
lines changed

33 files changed

+6045
-5727
lines changed

src/components/Badge/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 142 additions & 142 deletions
Large diffs are not rendered by default.

src/components/Button/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 111 additions & 111 deletions
Large diffs are not rendered by default.

src/components/Checkbox/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 224 additions & 224 deletions
Large diffs are not rendered by default.

src/components/Collapse/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 165 additions & 165 deletions
Large diffs are not rendered by default.

src/components/Compact/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 91 additions & 91 deletions
Large diffs are not rendered by default.

src/components/DatePicker/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 433 additions & 433 deletions
Large diffs are not rendered by default.

src/components/Form/Form.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23

34
import { FormWrap } from './style';
45

56
const Form = ({ ...rest }) => {
67
return <FormWrap {...rest} />;
78
};
89

10+
const Size = ['md', 'lg'];
11+
12+
Form.propTypes = {
13+
/**
14+
* 配合表单控件的size使用
15+
*/
16+
size: PropTypes.oneOf(Size)
17+
};
18+
Form.defaultProps = {
19+
size: 'md'
20+
};
21+
22+
Form.Size = Size;
23+
924
export default Form;

src/components/Form/__demo__/form.jsx

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import React from 'react';
22
import Form from 'components/Form';
3-
import Upload from 'components/Upload';
3+
import Radio from 'components/Radio';
4+
import Switch from 'components/Switch';
5+
import Input from 'components/Input';
6+
import Select from 'components/Select';
47

58
// demo start
6-
const { Item } = Form;
9+
const { Item, Size } = Form;
710
const itemLayout = {
811
labelCol: {
912
span: 3
@@ -12,14 +15,43 @@ const itemLayout = {
1215
span: 9
1316
}
1417
};
15-
const Demo = () => (
16-
<Form>
17-
<Item label="上传文件" {...itemLayout}>
18-
<Upload style={{ marginBottom: 5 }} />
19-
<Upload />
20-
</Item>
21-
</Form>
22-
);
18+
class Demo extends React.Component {
19+
constructor(props) {
20+
super(props);
21+
this.state = {
22+
size: 'md'
23+
};
24+
}
25+
render() {
26+
const { size } = this.state;
27+
return (
28+
<div>
29+
<Form className="demo-form">
30+
<Form.Item label="size" {...itemLayout}>
31+
<Radio.Group
32+
value={size}
33+
options={Size.map(value => ({ value }))}
34+
onChange={size => this.setState({ size })}
35+
/>
36+
</Form.Item>
37+
</Form>
38+
<div className="demo-wrap">
39+
<Form size={size}>
40+
<Item label="Input" {...itemLayout}>
41+
<Input size={size} />
42+
</Item>
43+
<Item label="Switch" {...itemLayout}>
44+
<Switch size={size} />
45+
</Item>
46+
<Item label="上传文件" {...itemLayout}>
47+
<Select size={size} options={[{ value: '123' }, { value: '1231' }, { value: '1232' }]} />
48+
</Item>
49+
</Form>
50+
</div>
51+
</div>
52+
);
53+
}
54+
}
2355
// demo end
2456

2557
export default Demo;

0 commit comments

Comments
 (0)