NumberKeyboard 数字键盘

import {
  TaNumberKeyboard,
  TaInput,
  TaCell,
  TaGroup,
  NumberKeyboardOnDelete,
  NumberKeyboardOnClose,
  showToast,
  NumberKeyboardType
} from '@/index'
import { useState } from 'react'

interface ShowArgs {
  title?: string
  type?: NumberKeyboardType
  customKey?: string | string[]
  closeEvent?: boolean
  confirmEvent?: boolean
}

export default function ExpNumberKeyboard() {
  const [visible1, setVisible1] = useState(false)
  const [visible2, setVisible2] = useState(false)
  const [inputValue, setInputValue] = useState('')

  const [title, setTitle] = useState<string>()
  const [customKey, setCustomKey] = useState<string | string[]>()
  const [type, setType] = useState<NumberKeyboardType>()

  function onShow(args: ShowArgs) {
    setTitle(args.title)
    setCustomKey(args.customKey)
    setType(args.type)

    setVisible1(true)
  }

  const onInput = (value: string) => {
    showToast(value)
  }

  const onChange = (value: string) => {
    console.log('change', value)
    showToast(`本次输入值为:${value}`)
  }

  const onDelete: NumberKeyboardOnDelete = res => {
    console.log('delete', res)
    showToast('删除')
  }

  const onClose: NumberKeyboardOnClose = res => {
    console.log('close', res)
  }

  return (
    <>
      <TaGroup title="基础键盘">
        <TaCell label="默认键盘" isLink onClick={() => onShow({})}></TaCell>
        <TaCell
          label="带小数点(customKey='.'"
          isLink
          onClick={() => onShow({ customKey: '.' })}
        ></TaCell>
        <TaCell
          label="身份证(customKey='X'"
          isLink
          onClick={() => onShow({ customKey: 'X' })}
        ></TaCell>
      </TaGroup>
      <TaGroup title="带右侧栏键盘">
        <TaCell
          label="默认键盘"
          isLink
          onClick={() => onShow({ type: 'rightColumn' })}
        ></TaCell>
        <TaCell
          label="1个自定义值(customKey=['.'])"
          isLink
          onClick={() => onShow({ type: 'rightColumn', customKey: '.' })}
        ></TaCell>
        <TaCell
          label="2个自定义值(customKey=['00', '.'])"
          isLink
          onClick={() =>
            onShow({ type: 'rightColumn', customKey: ['00', '.'] })
          }
        ></TaCell>
      </TaGroup>
      <TaGroup title="其他">
        <TaCell
          label="设置标题"
          isLink
          onClick={() => onShow({ title: '键盘标题' })}
        ></TaCell>
        <TaCell label="数据绑定" isLink onClick={() => setVisible2(true)}>
          <TaInput value={inputValue} readonly />
        </TaCell>
      </TaGroup>
      <TaNumberKeyboard
        visible={visible1}
        title={title}
        customKey={customKey}
        type={type}
        onUpdateVisible={v => setVisible1(v)}
        onChange={onChange}
        onClose={onClose}
        onDelete={onDelete}
        onInput={onInput}
      />
      <TaNumberKeyboard
        visible={visible2}
        value={inputValue}
        onUpdateVisible={v => setVisible2(v)}
      />
    </>
  )
}

Import

import { TaNumberKeyboard } from 'tantalum-ui-mobile-react'

具体的引入方式可以参考引入组件

Import Type

组件导出的类型定义:

import type {
  NumberKeyboardOnDelete,
  NumberKeyboardOnClose,
  NumberKeyboardType,
  VisibleState,
  PopupOnVisibleStateChange
} from 'tantalum-ui-mobile-react'

Props

属性类型默认值必填说明
visiblebooleanfalse是否显示
titlestring标题,不设置则不展示标题栏
valuestring当前输入值
typestring'default'键盘模式,可选'default', 'rightColumn'
customKeystring | string[]'rightColumn' 模式下最多支持添加 2 个,'default' 模式下最多支持添加 1 个

Events

事件描述回调函数参数TypeScript 函数
onInput点击按键时触发key: string
onDelete点击删除键时触发payload: { deleteKey: string }NumberKeyboardOnDelete
onChange键盘收回时触发value: string
onClose键盘收回时触发payload: { source: 'confirm' | 'blur' }NumberKeyboardOnClose
onVisibleStateChange展示隐藏时触发payload: { state: VisibleState }PopupOnVisibleStateChange
onUpdateVisible展示隐藏时触发visible: boolean 是否显示

VisibleState 值说明

说明备注
show展示时触发
shown展示且动画结束后触发
hide隐藏时触发可能携带其他参数 cancel, maskClick, closeClick 等
hidden隐藏且动画结束后触发可能携带其他参数 cancel, maskClick, closeClick 等