[new feature] Loading: add text-size prop

This commit is contained in:
陈嘉涵
2019-04-30 17:47:41 +08:00
parent cd0720954c
commit 0a7ca2fb6e
11 changed files with 53 additions and 18 deletions

View File

@@ -35,7 +35,8 @@ Vue.use(Loading);
|------|------|------|------|
| color | Loading color | `String` | `#c9c9c9` | |
| type | Can be set to `spinner` | `String` | `circular` |
| size | Size | `String` | `30px` |
| size | Icon size | `String` | `30px` |
| text-size | Text font size | `String | Number` | `14px` |
### Slot

View File

@@ -1,4 +1,4 @@
import { use } from '../utils';
import { use, suffixPx } from '../utils';
import { inherit } from '../utils/functional';
// Types
@@ -6,9 +6,10 @@ import { CreateElement, RenderContext } from 'vue/types';
import { DefaultSlots } from '../utils/use/sfc';
export type LoadingProps = {
size?: string;
type: string;
size?: string;
color: string;
textSize?: string | number;
};
const [sfc, bem] = use('loading');
@@ -41,19 +42,34 @@ function Loading(
</svg>
);
function Text() {
if (slots.default) {
const style = props.textSize && {
fontSize: suffixPx(props.textSize)
};
return (
<span class={bem('text')} style={style}>
{slots.default()}
</span>
);
}
}
return (
<div class={bem([type])} {...inherit(ctx, true)}>
<span class={bem('spinner', type)} style={style}>
{Spin}
{Circular}
</span>
{slots.default && <span class={bem('text')}>{slots.default()}</span>}
{Text()}
</div>
);
}
Loading.props = {
size: String,
textSize: [String, Number],
type: {
type: String,
default: 'circular'

View File

@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`text-size prop 1`] = `<div class="van-loading van-loading--circular"><span class="van-loading__spinner van-loading__spinner--circular" style="color: rgb(201, 201, 201);"><svg viewBox="25 25 50 50" class="van-loading__circular"><circle cx="50" cy="50" r="20" fill="none"></circle></svg></span><span class="van-loading__text" style="font-size: 20px;">Text</span></div>`;

View File

@@ -0,0 +1,15 @@
import { mount } from '../../../test/utils';
import Loading from '..';
test('text-size prop', () => {
const wrapper = mount(Loading, {
propsData: {
textSize: 20
},
scopedSlots: {
default: () => 'Text'
}
});
expect(wrapper).toMatchSnapshot();
});

View File

@@ -35,7 +35,8 @@ Vue.use(Loading);
|------|------|------|------|------|
| color | 颜色 | `String` | `#c9c9c9` | - |
| type | 类型,可选值为 `spinner` | `String` | `circular` | - |
| size | 大小 | `String` | `30px` | - |
| size | 加载图标大小 | `String` | `30px` | - |
| text-size | 文字大小 | `String | Number` | `14px` | 2.0.0 |
### Slot