# @wines/toptips

> The toptips @wines

Latest version **2.0.0** (published 2025-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @wines/toptips
pnpm add @wines/toptips
yarn add @wines/toptips
bun add @wines/toptips
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-04-01 |
| First published | 2021-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=16.0.0 |
| Dependencies | 3 |
| Unpacked size | 24 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tianyingchun |

## Links

- npm: https://www.npmjs.com/package/@wines/toptips
- Repository: https://gitlab.itcjf.com/wines/toptips
- npm.io page: https://npm.io/package/@wines/toptips

## Dependencies (3)

- [@wines/core](https://npm.io/package/@wines/core.md) 2.0.0
- [@wines/styles](https://npm.io/package/@wines/styles.md) 2.0.0
- [@wines/animation-group](https://npm.io/package/@wines/animation-group.md) 2.0.0

## Recent versions

- 2.0.0 (latest) — 2025-04-01
- 2.0.0-next.7 (next) — 2025-04-01
- 2.0.0-next.6 — 2025-03-06
- 2.0.0-next.5 — 2025-03-05
- 2.0.0-next.4 — 2025-03-05
- 2.0.0-next.3 — 2025-03-04
- 2.0.0-next.2 — 2025-02-28
- 2.0.0-next.1 — 2025-02-27
- 2.0.0-next.0 — 2025-02-27
- 1.5.1 — 2023-03-07
- 1.5.0 — 2022-11-22
- 1.4.0 — 2022-02-23
- 1.3.5 — 2021-12-03
- 1.3.4 — 2021-09-26
- 1.3.2 — 2021-09-24
- … 2 more at https://npm.io/package/@wines/toptips/versions

## README

# `@wines/toptips`

# Toptips 顶部提示

用于展现简短的提示信息，在窗口顶部显示。

## 使用指南

### 在 page.json 中引入组件

```json
{
  "navigationBarTitleText": "Toptips",
  "usingComponents": {
    "wux-button": "@wines/button",
    "wux-toptips": "@wines/toptips"
  }
}
```

### 示例

```xml
<wux-toptips id="wux-toptips" />
<view class="page">
	<view class="page__hd">
		<view class="page__title">Toptips</view>
		<view class="page__desc">顶部提示</view>
	</view>
	<view class="page__bd page__bd_spacing">
		<wux-button block type="light" bind:click="showToptips1">Show</wux-button>
		<wux-button block type="light" bind:click="showToptips2">Success</wux-button>
		<wux-button block type="light" bind:click="showToptips3">Info</wux-button>
		<wux-button block type="light" bind:click="showToptips4">Warn</wux-button>
		<wux-button block type="light" bind:click="showToptips5">Error</wux-button>
		<wux-button block type="light" bind:click="showToptips6">Use return value to close</wux-button>
		<wux-button block type="light" bind:click="showToptips7">
			Use promise to know when closed
		</wux-button>
	</view>
</view>

```

```ts
import './index.less';
import { $wuxToptips } from '@wines/toptips';
import { PageData, PageCustom } from '@wines/core';

Page<PageData, PageCustom>({
  showToptips1() {
    $wuxToptips().show({
      icon: 'cancel',
      hidden: false,
      text: 'Toptips Title',
      duration: 3000,
      success() {
        /** */
      },
    });
  },
  showToptips2() {
    $wuxToptips().success({
      hidden: false,
      text: 'Toptips Title',
      duration: 3000,
      success() {
        /** */
      },
    });
  },
  showToptips3() {
    $wuxToptips().info({
      hidden: false,
      text: 'Toptips Title',
      duration: 3000,
      success() {
        /** */
      },
    });
  },
  showToptips4() {
    $wuxToptips().warn({
      hidden: false,
      text: 'Toptips Title',
      duration: 3000,
      success() {
        /** */
      },
    });
  },
  showToptips5() {
    $wuxToptips().error({
      hidden: false,
      text: 'Toptips Title',
      duration: 3000,
      success() {
        /** */
      },
    });
  },
  showToptips6() {
    if (this.timeout) clearTimeout(this.timeout);
    const hide = $wuxToptips().show({
      icon: 'cancel',
      hidden: false,
      text: 'Toptips Title',
      duration: 3000,
    });

    this.timeout = setTimeout(() => {
      hide();
    }, 1000);
  },
  showToptips7() {
    const hide = $wuxToptips().show({
      icon: 'cancel',
      hidden: false,
      text: 'Toptips Title',
      duration: 3000,
    });

    // hide.promise.then(() => console.log('success'))
    hide.then(() => console.log('success'));
  },
});
```

## API

| 参数               | 类型       | 描述                                                                    | 默认值                   |
| ------------------ | ---------- | ----------------------------------------------------------------------- | ------------------------ |
| options            | `object`   | 配置项                                                                  | -                        |
| options.prefixCls  | `string`   | 自定义类名前缀                                                          | wux-toptips              |
| options.classNames | `any`      | 过渡的类名，更多内置过渡效果请参考 [AnimationGroup](animation-group.md) | wux-animate--slideInDown |
| options.icon       | `string`   | 图标类型                                                                | cancel                   |
| options.hidden     | `boolean`  | 是否隐藏图标                                                            | false                    |
| options.text       | `string`   | 报错文本                                                                | -                        |
| options.duration   | `number`   | 多少毫秒后消失                                                          | 3000                     |
| options.success    | `function` | 消失后的回调函数                                                        | -                        |

### Toptips.method

- Toptips.show
- Toptips.success
- Toptips.info
- Toptips.warn
- Toptips.error

> 以上函数调用后，会返回一个引用，可以通过该引用手动关闭组件

```
const hide = Toptips.show()
hide()

// 返回值支持 promise 接口，可以通过 then/promise.then 方法在关闭后运行 callback
hide.then(callback)
hide.promise.then(callback)
```

---
_Source: https://npm.io/package/@wines/toptips · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
