mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Notify): add position prop (#10056)
* feat(Notify): add position prop * chore: update
This commit is contained in:
parent
7b82ce6573
commit
a06f2666a1
@ -8,7 +8,7 @@ import {
|
|||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { Popup } from '../popup';
|
import { Popup } from '../popup';
|
||||||
import { popupSharedProps } from '../popup/shared';
|
import { popupSharedProps } from '../popup/shared';
|
||||||
import type { NotifyType } from './types';
|
import type { NotifyType, NotifyPosition } from './types';
|
||||||
|
|
||||||
const [name, bem] = createNamespace('notify');
|
const [name, bem] = createNamespace('notify');
|
||||||
|
|
||||||
@ -16,6 +16,7 @@ const notifyProps = extend({}, popupSharedProps, {
|
|||||||
type: makeStringProp<NotifyType>('danger'),
|
type: makeStringProp<NotifyType>('danger'),
|
||||||
color: String,
|
color: String,
|
||||||
message: numericProp,
|
message: numericProp,
|
||||||
|
position: makeStringProp<NotifyPosition>('top'),
|
||||||
className: unknownProp,
|
className: unknownProp,
|
||||||
background: String,
|
background: String,
|
||||||
lockScroll: Boolean,
|
lockScroll: Boolean,
|
||||||
@ -42,7 +43,7 @@ export default defineComponent({
|
|||||||
background: props.background,
|
background: props.background,
|
||||||
}}
|
}}
|
||||||
overlay={false}
|
overlay={false}
|
||||||
position="top"
|
position={props.position}
|
||||||
duration={0.2}
|
duration={0.2}
|
||||||
lockScroll={props.lockScroll}
|
lockScroll={props.lockScroll}
|
||||||
onUpdate:show={updateShow}
|
onUpdate:show={updateShow}
|
||||||
|
@ -42,6 +42,11 @@ Notify({
|
|||||||
background: '#ffe1e1',
|
background: '#ffe1e1',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Notify({
|
||||||
|
message: 'Custom Position',
|
||||||
|
position: 'bottom',
|
||||||
|
});
|
||||||
|
|
||||||
Notify({
|
Notify({
|
||||||
message: 'Custom Duration',
|
message: 'Custom Duration',
|
||||||
duration: 1000,
|
duration: 1000,
|
||||||
@ -110,6 +115,7 @@ export default {
|
|||||||
| type | Can be set to `primary` `success` `warning` | _NotifyType_ | `danger` |
|
| type | Can be set to `primary` `success` `warning` | _NotifyType_ | `danger` |
|
||||||
| message | Message | _string_ | - |
|
| message | Message | _string_ | - |
|
||||||
| duration | Duration(ms), won't disappear if value is 0 | _number \| string_ | `3000` |
|
| duration | Duration(ms), won't disappear if value is 0 | _number \| string_ | `3000` |
|
||||||
|
| position `v3.3.8` | Position, can be set to `bottom` | _NotifyPosition_ | `top` |
|
||||||
| color | Message color | _string_ | `white` |
|
| color | Message color | _string_ | `white` |
|
||||||
| background | Background color | _string_ | - |
|
| background | Background color | _string_ | - |
|
||||||
| className | Custom className | _string \| Array \| object_ | - |
|
| className | Custom className | _string \| Array \| object_ | - |
|
||||||
@ -123,7 +129,12 @@ export default {
|
|||||||
The component exports the following type definitions:
|
The component exports the following type definitions:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import type { NotifyType, NotifyProps, NotifyOptions } from 'vant';
|
import type {
|
||||||
|
NotifyType,
|
||||||
|
NotifyProps,
|
||||||
|
NotifyOptions,
|
||||||
|
NotifyPosition,
|
||||||
|
} from 'vant';
|
||||||
```
|
```
|
||||||
|
|
||||||
## Theming
|
## Theming
|
||||||
|
@ -77,7 +77,7 @@ Notify({ type: 'warning', message: '通知内容' });
|
|||||||
|
|
||||||
### 自定义通知
|
### 自定义通知
|
||||||
|
|
||||||
自定义消息通知的颜色和展示时长。
|
自定义消息通知的颜色、位置和展示时长。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
Notify({
|
Notify({
|
||||||
@ -86,6 +86,11 @@ Notify({
|
|||||||
background: '#ffe1e1',
|
background: '#ffe1e1',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Notify({
|
||||||
|
message: '自定义位置',
|
||||||
|
position: 'bottom',
|
||||||
|
});
|
||||||
|
|
||||||
Notify({
|
Notify({
|
||||||
message: '自定义时长',
|
message: '自定义时长',
|
||||||
duration: 1000,
|
duration: 1000,
|
||||||
@ -158,6 +163,7 @@ export default {
|
|||||||
| type | 类型,可选值为 `primary` `success` `warning` | _NotifyType_ | `danger` |
|
| type | 类型,可选值为 `primary` `success` `warning` | _NotifyType_ | `danger` |
|
||||||
| message | 展示文案,支持通过`\n`换行 | _string_ | - |
|
| message | 展示文案,支持通过`\n`换行 | _string_ | - |
|
||||||
| duration | 展示时长(ms),值为 0 时,notify 不会消失 | _number \| string_ | `3000` |
|
| duration | 展示时长(ms),值为 0 时,notify 不会消失 | _number \| string_ | `3000` |
|
||||||
|
| position `v3.3.8` | 弹出位置,可选值为 `bottom` | _NotifyPosition_ | `top` |
|
||||||
| color | 字体颜色 | _string_ | `white` |
|
| color | 字体颜色 | _string_ | `white` |
|
||||||
| background | 背景颜色 | _string_ | - |
|
| background | 背景颜色 | _string_ | - |
|
||||||
| className | 自定义类名 | _string \| Array \| object_ | - |
|
| className | 自定义类名 | _string \| Array \| object_ | - |
|
||||||
@ -171,7 +177,12 @@ export default {
|
|||||||
组件导出以下类型定义:
|
组件导出以下类型定义:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import type { NotifyType, NotifyProps, NotifyOptions } from 'vant';
|
import type {
|
||||||
|
NotifyType,
|
||||||
|
NotifyProps,
|
||||||
|
NotifyOptions,
|
||||||
|
NotifyPosition,
|
||||||
|
} from 'vant';
|
||||||
```
|
```
|
||||||
|
|
||||||
## 主题定制
|
## 主题定制
|
||||||
|
@ -20,6 +20,7 @@ const t = useTranslate({
|
|||||||
customNotify: '自定义配置',
|
customNotify: '自定义配置',
|
||||||
componentCall: '组件调用',
|
componentCall: '组件调用',
|
||||||
customDuration: '自定义时长',
|
customDuration: '自定义时长',
|
||||||
|
customPosition: '自定义位置',
|
||||||
},
|
},
|
||||||
'en-US': {
|
'en-US': {
|
||||||
primary: 'Primary',
|
primary: 'Primary',
|
||||||
@ -32,6 +33,7 @@ const t = useTranslate({
|
|||||||
customNotify: 'Custom Notify',
|
customNotify: 'Custom Notify',
|
||||||
componentCall: 'Component Call',
|
componentCall: 'Component Call',
|
||||||
customDuration: 'Custom Duration',
|
customDuration: 'Custom Duration',
|
||||||
|
customPosition: 'Custom Position',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -56,6 +58,13 @@ const showCustomDuration = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showCustomPosition = () => {
|
||||||
|
Notify({
|
||||||
|
message: t('customPosition'),
|
||||||
|
position: 'bottom',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const showType = (type: NotifyType) => {
|
const showType = (type: NotifyType) => {
|
||||||
Notify({
|
Notify({
|
||||||
message: t('content'),
|
message: t('content'),
|
||||||
@ -85,6 +94,11 @@ const showComponentCall = () => {
|
|||||||
|
|
||||||
<demo-block card :title="t('customNotify')">
|
<demo-block card :title="t('customNotify')">
|
||||||
<van-cell is-link :title="t('customColor')" @click="showCustomColor" />
|
<van-cell is-link :title="t('customColor')" @click="showCustomColor" />
|
||||||
|
<van-cell
|
||||||
|
is-link
|
||||||
|
:title="t('customPosition')"
|
||||||
|
@click="showCustomPosition"
|
||||||
|
/>
|
||||||
<van-cell
|
<van-cell
|
||||||
is-link
|
is-link
|
||||||
:title="t('customDuration')"
|
:title="t('customDuration')"
|
||||||
|
@ -54,6 +54,7 @@ const getDefaultOptions = (): NotifyOptions => ({
|
|||||||
onClick: undefined,
|
onClick: undefined,
|
||||||
onOpened: undefined,
|
onOpened: undefined,
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
|
position: undefined,
|
||||||
className: '',
|
className: '',
|
||||||
lockScroll: false,
|
lockScroll: false,
|
||||||
background: undefined,
|
background: undefined,
|
||||||
|
@ -78,6 +78,18 @@ exports[`should render demo and match snapshot 1`] = `
|
|||||||
<i class="van-badge__wrapper van-icon van-icon-arrow van-cell__right-icon">
|
<i class="van-badge__wrapper van-icon van-icon-arrow van-cell__right-icon">
|
||||||
</i>
|
</i>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="van-cell van-cell--clickable"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
<div class="van-cell__title">
|
||||||
|
<span>
|
||||||
|
Custom Position
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<i class="van-badge__wrapper van-icon van-icon-arrow van-cell__right-icon">
|
||||||
|
</i>
|
||||||
|
</div>
|
||||||
<div class="van-cell van-cell--clickable"
|
<div class="van-cell van-cell--clickable"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
|
@ -20,12 +20,12 @@ test('should add "van-notify--success" class when type is success', async () =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
await later();
|
await later();
|
||||||
const notify = document.querySelector('.van-notify');
|
const notify = document.querySelector('.van-notify') as HTMLElement;
|
||||||
expect(notify.classList.contains('van-notify--success')).toBeTruthy();
|
expect(notify.classList.contains('van-notify--success')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should register component to app', () => {
|
test('should register component to app', () => {
|
||||||
const app = createApp();
|
const app = createApp({});
|
||||||
app.use(Notify);
|
app.use(Notify);
|
||||||
expect(app.component(NotifyComponent.name)).toBeTruthy();
|
expect(app.component(NotifyComponent.name)).toBeTruthy();
|
||||||
});
|
});
|
||||||
@ -63,7 +63,18 @@ test('should call onClick option when clicked', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await later();
|
await later();
|
||||||
const notify = document.querySelector('.van-notify');
|
const notify = document.querySelector('.van-notify') as HTMLElement;
|
||||||
notify.click();
|
notify.click();
|
||||||
expect(onClick).toHaveBeenCalledTimes(1);
|
expect(onClick).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should align to bottom when position option is bottom', async () => {
|
||||||
|
Notify({
|
||||||
|
message: 'test',
|
||||||
|
position: 'bottom',
|
||||||
|
});
|
||||||
|
|
||||||
|
await later();
|
||||||
|
const notify = document.querySelector('.van-notify') as HTMLElement;
|
||||||
|
expect(notify.classList.contains('van-popup--bottom')).toBeTruthy();
|
||||||
|
});
|
@ -4,11 +4,14 @@ export type NotifyMessage = string | number;
|
|||||||
|
|
||||||
export type NotifyType = 'primary' | 'success' | 'danger' | 'warning';
|
export type NotifyType = 'primary' | 'success' | 'danger' | 'warning';
|
||||||
|
|
||||||
|
export type NotifyPosition = 'top' | 'bottom';
|
||||||
|
|
||||||
export type NotifyOptions = {
|
export type NotifyOptions = {
|
||||||
type?: NotifyType;
|
type?: NotifyType;
|
||||||
color?: string;
|
color?: string;
|
||||||
message?: NotifyMessage;
|
message?: NotifyMessage;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
|
position?: NotifyPosition;
|
||||||
className?: unknown;
|
className?: unknown;
|
||||||
background?: string;
|
background?: string;
|
||||||
lockScroll?: boolean;
|
lockScroll?: boolean;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user