mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] Loading: add text-size prop
This commit is contained in:
parent
cd0720954c
commit
0a7ca2fb6e
@ -54,6 +54,7 @@
|
|||||||
## Loading
|
## Loading
|
||||||
|
|
||||||
- 新增`default`插槽
|
- 新增`default`插槽
|
||||||
|
- 新增`text-size`属性
|
||||||
|
|
||||||
## NoticeBar
|
## NoticeBar
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ export default {
|
|||||||
|------|------|------|
|
|------|------|------|
|
||||||
| change | 当绑定值变化时触发的事件 | 当前组件的值 |
|
| change | 当绑定值变化时触发的事件 | 当前组件的值 |
|
||||||
|
|
||||||
### Checkbox Slots
|
### Checkbox Slot
|
||||||
|
|
||||||
| 名称 | 说明 | slot-scope |
|
| 名称 | 说明 | slot-scope |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
import Cell from '../cell';
|
import Cell from '../cell';
|
||||||
import { cellProps } from '../cell/shared';
|
import { cellProps } from '../cell/shared';
|
||||||
import { use, isObj, isDef, isIOS } from '../utils';
|
|
||||||
import { getRootScrollTop } from '../utils/scroll';
|
import { getRootScrollTop } from '../utils/scroll';
|
||||||
import { isNumber } from '../utils/validate/number';
|
import { use, isObj, isDef, isIOS, suffixPx } from '../utils';
|
||||||
|
|
||||||
const [sfc, bem] = use('field');
|
const [sfc, bem] = use('field');
|
||||||
|
|
||||||
@ -66,8 +65,7 @@ export default sfc({
|
|||||||
labelStyle() {
|
labelStyle() {
|
||||||
const { labelWidth } = this;
|
const { labelWidth } = this;
|
||||||
if (labelWidth) {
|
if (labelWidth) {
|
||||||
const width = isNumber(String(labelWidth)) ? `${labelWidth}px` : labelWidth;
|
return { width: suffixPx(labelWidth) };
|
||||||
return { width };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -35,7 +35,8 @@ Vue.use(Loading);
|
|||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| color | Loading color | `String` | `#c9c9c9` | |
|
| color | Loading color | `String` | `#c9c9c9` | |
|
||||||
| type | Can be set to `spinner` | `String` | `circular` |
|
| 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
|
### Slot
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { use } from '../utils';
|
import { use, suffixPx } from '../utils';
|
||||||
import { inherit } from '../utils/functional';
|
import { inherit } from '../utils/functional';
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
@ -6,9 +6,10 @@ import { CreateElement, RenderContext } from 'vue/types';
|
|||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/use/sfc';
|
||||||
|
|
||||||
export type LoadingProps = {
|
export type LoadingProps = {
|
||||||
size?: string;
|
|
||||||
type: string;
|
type: string;
|
||||||
|
size?: string;
|
||||||
color: string;
|
color: string;
|
||||||
|
textSize?: string | number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const [sfc, bem] = use('loading');
|
const [sfc, bem] = use('loading');
|
||||||
@ -41,19 +42,34 @@ function Loading(
|
|||||||
</svg>
|
</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 (
|
return (
|
||||||
<div class={bem([type])} {...inherit(ctx, true)}>
|
<div class={bem([type])} {...inherit(ctx, true)}>
|
||||||
<span class={bem('spinner', type)} style={style}>
|
<span class={bem('spinner', type)} style={style}>
|
||||||
{Spin}
|
{Spin}
|
||||||
{Circular}
|
{Circular}
|
||||||
</span>
|
</span>
|
||||||
{slots.default && <span class={bem('text')}>{slots.default()}</span>}
|
{Text()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading.props = {
|
Loading.props = {
|
||||||
size: String,
|
size: String,
|
||||||
|
textSize: [String, Number],
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'circular'
|
default: 'circular'
|
||||||
|
3
packages/loading/test/__snapshots__/index.spec.js.snap
Normal file
3
packages/loading/test/__snapshots__/index.spec.js.snap
Normal 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>`;
|
15
packages/loading/test/index.spec.js
Normal file
15
packages/loading/test/index.spec.js
Normal 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();
|
||||||
|
});
|
@ -35,7 +35,8 @@ Vue.use(Loading);
|
|||||||
|------|------|------|------|------|
|
|------|------|------|------|------|
|
||||||
| color | 颜色 | `String` | `#c9c9c9` | - |
|
| color | 颜色 | `String` | `#c9c9c9` | - |
|
||||||
| type | 类型,可选值为 `spinner` | `String` | `circular` | - |
|
| type | 类型,可选值为 `spinner` | `String` | `circular` | - |
|
||||||
| size | 大小 | `String` | `30px` | - |
|
| size | 加载图标大小 | `String` | `30px` | - |
|
||||||
|
| text-size | 文字大小 | `String | Number` | `14px` | 2.0.0 |
|
||||||
|
|
||||||
### Slot
|
### Slot
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ export default {
|
|||||||
|------|------|------|
|
|------|------|------|
|
||||||
| change | 当绑定值变化时触发的事件 | 当前选中项的 name |
|
| change | 当绑定值变化时触发的事件 | 当前选中项的 name |
|
||||||
|
|
||||||
### Radio Slots
|
### Radio Slot
|
||||||
|
|
||||||
| 名称 | 说明 | slot-scope |
|
| 名称 | 说明 | slot-scope |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { use } from '../utils';
|
import { use, suffixPx } from '../utils';
|
||||||
import { inherit } from '../utils/functional';
|
import { inherit } from '../utils/functional';
|
||||||
import { isNumber } from '../utils/validate/number';
|
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
@ -22,11 +21,6 @@ const [sfc, bem] = use('skeleton');
|
|||||||
const DEFAULT_ROW_WIDTH = '100%';
|
const DEFAULT_ROW_WIDTH = '100%';
|
||||||
const DEFAULT_LAST_ROW_WIDTH = '60%';
|
const DEFAULT_LAST_ROW_WIDTH = '60%';
|
||||||
|
|
||||||
function suffixPx(value: string | number): string {
|
|
||||||
value = String(value);
|
|
||||||
return isNumber(value) ? `${value}px` : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Skeleton(
|
function Skeleton(
|
||||||
h: CreateElement,
|
h: CreateElement,
|
||||||
props: SkeletonProps,
|
props: SkeletonProps,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
import { isNumber } from './validate/number';
|
||||||
|
|
||||||
export { use } from './use';
|
export { use } from './use';
|
||||||
|
|
||||||
@ -48,3 +49,8 @@ export function range(num: number, min: number, max: number): number {
|
|||||||
export function isInDocument(element: HTMLElement): boolean {
|
export function isInDocument(element: HTMLElement): boolean {
|
||||||
return document.body.contains(element);
|
return document.body.contains(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function suffixPx(value: string | number): string {
|
||||||
|
value = String(value);
|
||||||
|
return isNumber(value) ? `${value}px` : value;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user