Skip to content

Commit

Permalink
feat(Form): support size to control margin between FormItems, close #499
Browse files Browse the repository at this point in the history
  • Loading branch information
Javey committed Jul 6, 2020
1 parent 442bc4c commit ad14a3f
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 14 deletions.
12 changes: 10 additions & 2 deletions components/form/demos/layout.md
Expand Up @@ -3,22 +3,29 @@ title: 表单布局
order: 5
---

通过`layout`指定表单布局:`horizontal`, `vertical`, `inline`
通过`layout`指定表单布局:`horizontal`, `vertical`, `inline`,还可以通过`size`控制`FormItem`的间距

```vdt
import {Form, FormItem} from 'kpc/components/form';
import {Input} from 'kpc/components/input';
import {Select, Option} from 'kpc/components/select';
import {ButtonGroup, Button} from 'kpc/components/button';
<Form layout={{ self.get('layout') }}>
<Form layout={{ self.get('layout') }} size={{ self.get('size') }}>
<FormItem label="Layout">
<ButtonGroup checkType="radio" v-model="layout">
<Button value="horizontal">horizontal</Button>
<Button value="vertical">vertical</Button>
<Button value="inline">inline</Button>
</ButtonGroup>
</FormItem>
<FormItem label="Size">
<ButtonGroup checkType="radio" v-model="size">
<Button value="default">default</Button>
<Button value="small">small</Button>
<Button value="mini">mini</Button>
</ButtonGroup>
</FormItem>
<FormItem label="Input" model="model.input" rules={{ {required: true} }}>
<Input v-model="model.input" />
</FormItem>
Expand Down Expand Up @@ -48,6 +55,7 @@ export default class extends Intact {
checkbox: [],
},
layout: 'horizontal',
size: 'default',
};
}
}
Expand Down
6 changes: 4 additions & 2 deletions components/form/form.js
Expand Up @@ -5,9 +5,9 @@ import '../../styles/kpc.styl';
import './index.styl';

export default class Form extends Intact {
static methods = methods;
static methods = methods;

static messages = messages;
static messages = messages;

static classNames = classNames;

Expand All @@ -22,6 +22,7 @@ export default class Form extends Intact {
labelWidth: [String, Number],
layout: ['horizontal', 'vertical', 'inline'],
starOnRequired: Boolean,
size: ['default', 'small', 'mini'],
};

static events = {
Expand All @@ -35,6 +36,7 @@ export default class Form extends Intact {
labelWidth: undefined,
layout: 'horizontal',
starOnRequired: false,
size: 'default',
}
}

Expand Down
3 changes: 2 additions & 1 deletion components/form/form.vdt
@@ -1,11 +1,12 @@
import {getRestProps} from '../utils';

const {children, className, layout} = self.get();
const {children, className, layout, size} = self.get();

const classNameObj = {
'k-form': true,
[className]: className,
[`k-${layout}`]: layout,
[`k-${size}`]: size !== 'default',
};

<form {{ ...getRestProps(self) }} class={{ classNameObj }}
Expand Down
1 change: 1 addition & 0 deletions components/form/index.md
Expand Up @@ -29,6 +29,7 @@ sidebar: doc
| isDirty | 组件是否被污染,组件只有被污染后,才会进行表单验证 | `Boolean` | `false` |
| force | 如果组件被污染,让`FormItem`更新时,强制验证。你也可以配合`isDirty`属性,指定强制验证的时机 [#6][1]`force`的意思是:在组件的`update`生命周期函数中去调用`validate`验证`FormItem`;默认情况下组件会`watch` `rules`以及`model`,只有在它们变化时才验证 | `Boolean` | `false` |
| fluid | `FormItem`的宽度默认是被子元素撑开的,添加该属性可以渲染`100%`的宽度 | `Boolean` | `false` |
| size | 控制`FormItem`的间距 | `"default"` &#124; `"small"` &#124; `"mini"` | `"default"` |

# 扩展点

Expand Down
9 changes: 8 additions & 1 deletion components/form/index.styl
Expand Up @@ -93,6 +93,13 @@
text-align left
line-height inherit
margin-bottom $form-item-vertical-label-margin-bottom

// size
for size in small mini
&.k-{size}
.k-form-item
margin lookup('$form-' + size + '-item-margin')
&.k-inline
.k-form-item
margin-right lookup('$form-' + size + '-item-inline-margin-right')

requireTheme('form')
8 changes: 7 additions & 1 deletion components/form/variables.styl
Expand Up @@ -18,5 +18,11 @@ $form-item-invalid-border := 1px solid $danger-color
$form-item-append-padding := 0 unit(10 / $rem, rem)

// layout
$form-item-inline-margin-right := unit(16 / $rem, rem)
$form-item-inline-margin-right := unit(15 / $rem, rem)
$form-item-vertical-label-margin-bottom := unit(8 / $rem, rem)

// size
$form-small-item-margin := 0 0 unit(15 / $rem, rem) 0
$form-small-item-inline-margin-right := unit(10 / $rem, rem)
$form-mini-item-margin := 0 0 unit(10 / $rem, rem) 0
$form-mini-item-inline-margin-right := unit(5 / $rem, rem)
1 change: 1 addition & 0 deletions components/input/demos/textarea.md
Expand Up @@ -11,6 +11,7 @@ import Input from 'kpc/components/input';
<div>
<Input type="textarea" placeholder="please enter" />
<br />
<br />
<Input type="textarea" rows="5" placeholder="please enter" />
</div>
```
1 change: 1 addition & 0 deletions components/input/index.styl
Expand Up @@ -146,6 +146,7 @@
padding $input-textarea-padding
height auto
line-height 1.5
vertical-align top

// fake dom for get value's width
.k-fake
Expand Down
14 changes: 7 additions & 7 deletions components/tooltip/index.spec.js
Expand Up @@ -13,13 +13,13 @@ import {mount, unmount, dispatchEvent, getElement, wait} from 'test/utils';
describe('Tooltip', () => {
let instance;

// afterEach((done) => {
// if (instance) {
// unmount(instance);
// instance = null;
// }
// setTimeout(done, 500);
// });
afterEach((done) => {
if (instance) {
unmount(instance);
instance = null;
}
setTimeout(done, 500);
});

it('should show and hide content correctly', async () => {
instance = mount(BasicDemo);
Expand Down
10 changes: 10 additions & 0 deletions styles/themes/ksyun/index.styl
Expand Up @@ -338,4 +338,14 @@ $colorpicker-small-padding := 2px
$colorpicker-mini-width := 40px
$colorpicker-mini-padding = 1px

/**
* form
*/
$form-item-margin := 0 0 24px 0
$form-item-inline-margin-right := 16px
$form-small-item-margin := 0 0 16px 0
$form-small-item-inline-margin-right := 12px
$form-mini-item-margin := 0 0 8px 0
$form-mini-item-inline-margin-right := 8px

@require('../default.styl')

0 comments on commit ad14a3f

Please sign in to comment.