Compare commits

...

3 Commits

Author SHA1 Message Date
neverland
9d55f2d6b8
docs(Navbar): update clickable description (#11110) 2022-10-03 21:47:42 +08:00
哭你几哇
ea0ba1fcf1
feat(nav-bar): add clickable prop to nav-bar component (#11048)
* feat: add clickable prop to nav-bar

* test(nav-bar): add clickable prop test case
2022-10-03 21:43:32 +08:00
neverland
9f2eb92172
feat(Loading): add icon slot (#11109)
* feat(Loading): add icon slot

* chore: update snapshot
2022-10-03 21:36:02 +08:00
10 changed files with 115 additions and 11 deletions

View File

@ -43,6 +43,15 @@ export default defineComponent({
extend({ color: props.color }, getSizeStyle(props.size))
);
const renderIcon = () => {
const DefaultIcon = props.type === 'spinner' ? SpinIcon : CircularIcon;
return (
<span class={bem('spinner', props.type)} style={spinnerStyle.value}>
{slots.icon ? slots.icon() : DefaultIcon}
</span>
);
};
const renderText = () => {
if (slots.default) {
return (
@ -67,9 +76,7 @@ export default defineComponent({
aria-live="polite"
aria-busy={true}
>
<span class={bem('spinner', type)} style={spinnerStyle.value}>
{type === 'spinner' ? SpinIcon : CircularIcon}
</span>
{renderIcon()}
{renderText()}
</div>
);

View File

@ -66,6 +66,19 @@ use `color` or `text-color` to change text color.
<van-loading text-color="#0094ff" />
```
### Custom Icon
Use `icon` slot to custom icon.
```html
<van-loading vertical>
<template #icon>
<van-icon name="star-o" size="30" />
</template>
Loading...
</van-loading>
```
## API
### Props
@ -81,9 +94,10 @@ use `color` or `text-color` to change text color.
### Slots
| Name | Description |
| ------- | ------------ |
| default | Loading text |
| Name | Description |
| ------- | ------------------- |
| default | Loading text |
| icon | Custom loading icon |
### Types

View File

@ -76,6 +76,19 @@ app.use(Loading);
<van-loading text-color="#0094ff" />
```
### 自定义图标
通过 `icon` 插槽可以自定义加载图标。
```html
<van-loading vertical>
<template #icon>
<van-icon name="star-o" size="30" />
</template>
加载中...
</van-loading>
```
## API
### Props
@ -91,9 +104,10 @@ app.use(Loading);
### Slots
| 名称 | 说明 |
| ------- | -------- |
| default | 加载文案 |
| 名称 | 说明 |
| ------- | -------------- |
| default | 加载文案 |
| icon | 自定义加载图标 |
### 类型定义

View File

@ -1,4 +1,5 @@
<script setup lang="ts">
import VanIcon from '../../icon';
import VanLoading from '..';
import { useTranslate } from '../../../docs/site';
@ -10,6 +11,7 @@ const t = useTranslate({
color: '自定义颜色',
vertical: '垂直排列',
textColor: '自定义文本颜色',
customIcon: '自定义图标',
},
'en-US': {
type: 'Type',
@ -18,6 +20,7 @@ const t = useTranslate({
color: 'Color',
vertical: 'Vertical',
textColor: 'Text Color',
customIcon: 'Custom Icon',
},
});
</script>
@ -58,6 +61,15 @@ const t = useTranslate({
{{ t('loading') }}
</van-loading>
</demo-block>
<demo-block :title="t('customIcon')">
<van-loading vertical>
<template #icon>
<van-icon name="star-o" size="30" />
</template>
{{ t('loading') }}
</van-loading>
</demo-block>
</template>
<style lang="less">

View File

@ -257,4 +257,20 @@ exports[`should render demo and match snapshot 1`] = `
</span>
</div>
</div>
<div>
<div class="van-loading van-loading--circular van-loading--vertical"
aria-live="polite"
aria-busy="true"
>
<span class="van-loading__spinner van-loading__spinner--circular">
<i class="van-badge__wrapper van-icon van-icon-star-o"
style="font-size: 30px;"
>
</i>
</span>
<span class="van-loading__text">
Loading...
</span>
</div>
</div>
`;

View File

@ -33,6 +33,7 @@ export const navBarProps = {
leftArrow: Boolean,
placeholder: Boolean,
safeAreaInsetTop: Boolean,
clickable: truthProp,
};
export type NavBarProps = ExtractPropTypes<typeof navBarProps>;
@ -92,7 +93,7 @@ export default defineComponent({
<div class={bem('content')}>
{hasLeft && (
<div
class={[bem('left'), HAPTICS_FEEDBACK]}
class={[bem('left'), props.clickable ? HAPTICS_FEEDBACK : '']}
onClick={onClickLeft}
>
{renderLeft()}
@ -103,7 +104,7 @@ export default defineComponent({
</div>
{hasRight && (
<div
class={[bem('right'), HAPTICS_FEEDBACK]}
class={[bem('right'), props.clickable ? HAPTICS_FEEDBACK : '']}
onClick={onClickRight}
>
{renderRight()}

View File

@ -99,6 +99,7 @@ export default {
| placeholder | Whether to generate a placeholder element when fixed | _boolean_ | `false` |
| z-index | Z-index | _number \| string_ | `1` |
| safe-area-inset-top | Whether to enable top safe area adaptation | _boolean_ | `false` |
| clickable | Whether to show click feedback when the left or right content is clicked | _boolean_ | `true` |
### Slots

View File

@ -107,6 +107,7 @@ export default {
| placeholder | 固定在顶部时,是否在标签位置生成一个等高的占位元素 | _boolean_ | `false` |
| z-index | 导航栏 z-index | _number \| string_ | `1` |
| safe-area-inset-top | 是否开启[顶部安全区适配](#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei) | _boolean_ | `false` |
| clickable | 是否开启两侧按钮的点击反馈 | _boolean_ | `true` |
### Slots

View File

@ -25,6 +25,18 @@ exports[`should render placeholder element when using placeholder prop 1`] = `
</div>
`;
exports[`should render slots correctly when set clickable to false 1`] = `
<div class="van-nav-bar__left">
Custom Left
</div>
`;
exports[`should render slots correctly when set clickable to false 2`] = `
<div class="van-nav-bar__right">
Custom Right
</div>
`;
exports[`should render title slot correctly 1`] = `
<div class="van-nav-bar__title van-ellipsis">
Custom Title

View File

@ -1,4 +1,5 @@
import { NavBar } from '..';
import { HAPTICS_FEEDBACK } from '../../utils';
import { mount, mockGetBoundingClientRect, later } from '../../../test';
test('should render left slot correctly', () => {
@ -9,6 +10,9 @@ test('should render left slot correctly', () => {
});
expect(wrapper.find('.van-nav-bar__left').html()).toMatchSnapshot();
expect(
wrapper.find('.van-nav-bar__left').classes(HAPTICS_FEEDBACK)
).toBeTruthy();
});
test('should render left slot correctly', () => {
@ -19,6 +23,9 @@ test('should render left slot correctly', () => {
});
expect(wrapper.find('.van-nav-bar__right').html()).toMatchSnapshot();
expect(
wrapper.find('.van-nav-bar__right').classes(HAPTICS_FEEDBACK)
).toBeTruthy();
});
test('should render title slot correctly', () => {
@ -85,3 +92,22 @@ test('should change z-index when using z-index prop', () => {
});
expect(wrapper.style.zIndex).toEqual('100');
});
test('should render slots correctly when set clickable to false', () => {
const wrapper = mount(NavBar, {
slots: {
left: () => 'Custom Left',
right: () => 'Custom Right',
},
props: {
clickable: false,
},
});
const leftDom = wrapper.find('.van-nav-bar__left');
const rightDom = wrapper.find('.van-nav-bar__right');
expect(leftDom.html()).toMatchSnapshot();
expect(rightDom.html()).toMatchSnapshot();
expect(leftDom.classes(HAPTICS_FEEDBACK)).toBeFalsy();
expect(rightDom.classes(HAPTICS_FEEDBACK)).toBeFalsy();
});