npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ophiuchus/number-keyboard

v1.0.2

Published

### 介绍

Downloads

3

Readme

NumberKeyboard 数字键盘

介绍

虚拟数字键盘,可以配合密码输入框组件或自定义的输入框组件使用。

引入

import Vue from 'vue';
import NumberKeyboard from '@ophiuchus/number-keyboard';

Vue.use(NumberKeyboard);

代码演示

默认样式

数字键盘提供了 inputdeleteblur 事件,分别对应输入内容、删除内容和失去焦点的动作。

<sf-cell @touchstart.native.stop="show = true">弹出默认键盘</sf-cell>
<sf-number-keyboard
  :show="show"
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>
import Toast  from '@ophiuchus/toast';

export default {
  data() {
    return {
      show: true,
    };
  },
  methods: {
    onInput(value) {
      Toast(value);
    },
    onDelete() {
      Toast('删除');
    },
  },
};

点击键盘以外的区域时,键盘会自动收起,通过阻止元素上的 touchstart 事件冒泡可以避免键盘收起。

带右侧栏的键盘

将 theme 属性设置为 custom 来展示键盘的右侧栏,常用于输入金额的场景。

<sf-number-keyboard
  :show="show"
  theme="custom"
  extra-key="."
  close-button-text="完成"
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>

身份证号键盘

通过 extra-key 属性可以设置左下角按键内容,比如需要输入身份证号时,可以将 extra-key 设置为 X

<sf-cell plain type="primary" @touchstart.native.stop="show = true">
  弹出身份证号键盘
</sf-cell>
<sf-number-keyboard
  :show="show"
  extra-key="X"
  close-button-text="完成"
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>

键盘标题

通过 title 属性可以设置键盘标题。

<sf-cell plain type="info" @touchstart.native.stop="show = true">
  弹出带标题的键盘
</sf-cell>
<sf-number-keyboard
  :show="show"
  title="键盘标题"
  extra-key="."
  close-button-text="完成"
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>

配置多个按键

当 theme 为 custom 时,支持以数组的形式配置两个 extra-key

<sf-cell plain type="primary" @touchstart.native.stop="show = true">
  弹出配置多个按键的键盘
</sf-cell>
<sf-number-keyboard
  :show="show"
  :extra-key="['00', '.']"
  close-button-text="完成"
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>

随机数字键盘

通过 random-key-order 属性可以随机排序数字键盘,常用于安全等级较高的场景。

<sf-cell @touchstart.native.stop="show = true">
  弹出配置随机数字的键盘
</sf-cell>
<sf-number-keyboard
  :show="show"
  random-key-order
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>

双向绑定

可以通过 v-model 绑定键盘当前输入值。

<sf-field
  readonly
  clickable
  :value="value"
  @touchstart.native.stop="show = true"
/>
<sf-number-keyboard
  v-model="value"
  :show="show"
  :maxlength="6"
  @blur="show = false"
/>
export default {
  data() {
    return {
      show: false,
      value: '',
    };
  },
};

API

Props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model (value) | 当前输入值 | string | - | | show | 是否显示键盘 | boolean | - | | title | 键盘标题 | string | - | | theme | 样式风格,可选值为 custom | string | default | | maxlength | 输入值最大长度 | number | string | - | | transition | 是否开启过场动画 | boolean | true | | z-index | 键盘 z-index 层级 | number | string | 100 | | extra-key | 底部额外按键的内容 | string | string[] | '' | | close-button-text | 关闭按钮文字,空则不展示 | string | - | | delete-button-text | 删除按钮文字,空则展示删除图标 | string | - | | close-button-loading | 是否将关闭按钮设置为加载中状态,仅在 theme="custom" 时有效 | boolean | false | | show-delete-key | 是否展示删除图标 | boolean | true | | hide-on-click-outside | 点击外部时是否收起键盘 | boolean | true | | get-container | 指定挂载的节点,用法示例 | string | () => Element | - | | safe-area-inset-bottom | 是否开启底部安全区适配 | boolean | true | | random-key-order | 是否将通过随机顺序展示按键 | boolean | false |

Events

| 事件名 | 说明 | 回调参数 | | ------ | ------------------------------ | ------------- | | input | 点击按键时触发 | key: 按键内容 | | delete | 点击删除键时触发 | - | | close | 点击关闭按钮时触发 | - | | blur | 点击关闭按钮或非键盘区域时触发 | - | | show | 键盘完全弹出时触发 | - | | hide | 键盘完全收起时触发 | - |

Slots

| 名称 | 说明 | | ---------- | -------------------- | | delete | 自定义删除按键内容 | | extra-key | 自定义左下角按键内容 | | title-left | 自定义标题栏左侧内容 |

样式变量

组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制

| 名称 | 默认值 | 描述 | | ------------------------------------------ | ------------------ | ---- | | @number-keyboard-background-color | @gray-2 | - | | @number-keyboard-key-height | 48px | - | | @number-keyboard-key-font-size | 28px | - | | @number-keyboard-key-active-color | @gray-3 | - | | @number-keyboard-delete-font-size | @font-size-lg | - | | @number-keyboard-title-color | @gray-7 | - | | @number-keyboard-title-height | 34px | - | | @number-keyboard-title-font-size | @font-size-lg | - | | @number-keyboard-close-padding | 0 @padding-md | - | | @number-keyboard-close-color | @text-link-color | - | | @number-keyboard-close-font-size | @font-size-md | - | | @number-keyboard-button-text-color | @white | - | | @number-keyboard-button-background-color | @blue | - | | @number-keyboard-cursor-color | @text-color | - | | @number-keyboard-cursor-width | 1px | - | | @number-keyboard-cursor-height | 40% | - | | @number-keyboard-cursor-animation-duration | 1s | - | | @number-keyboard-z-index | 100 | - |

常见问题

在桌面端无法操作组件?

参见桌面端适配