Keyboard虚拟键盘 - 图1

Keyboard 虚拟键盘

Keyboard 平铺键盘

  1. import { Cell, Select, Keyboard } from 'zarm';
  2. class Demo extends React.Component {
  3. state = {
  4. type: 'number',
  5. };
  6. render() {
  7. return (
  8. <>
  9. <Cell title="键盘类型">
  10. <Select
  11. value={this.state.type}
  12. dataSource={[
  13. { value: 'number', label: '数字键盘' },
  14. { value: 'price', label: '金额键盘' },
  15. { value: 'idcard', label: '身份证键盘' },
  16. ]}
  17. onOk={(selected) => {
  18. this.setState({
  19. type: selected.map(item => item.value)[0],
  20. });
  21. }}
  22. />
  23. </Cell>
  24. <Keyboard type={this.state.type} onKeyClick={(key) => console.log(key)} />
  25. </>
  26. )
  27. }
  28. }
  29. ReactDOM.render(<Demo />, mountNode);

KeyboardPicker 键盘触发器

  1. import { Cell, Button, KeyboardPicker, Input } from 'zarm';
  2. class Demo extends React.Component {
  3. state = {
  4. visible: false,
  5. value: '',
  6. };
  7. toggle() {
  8. this.setState({ visible: !this.state.visible });
  9. }
  10. onKeyClick(key) {
  11. console.log(key);
  12. if (['close', 'ok'].indexOf(key) > -1) {
  13. this.toggle();
  14. return;
  15. }
  16. const value = this.state.value;
  17. const newValue = (key === 'delete')
  18. ? value.slice(0, value.length - 1)
  19. : value + key;
  20. if (newValue !== value) {
  21. this.setState({ value: newValue });
  22. }
  23. }
  24. render() {
  25. const { visible } = this.state;
  26. return (
  27. <>
  28. <Cell
  29. description={
  30. <Button size="xs" onClick={() => this.toggle()}>{visible ? '关闭' : '开启'}</Button>
  31. }
  32. >
  33. 拾取器触发方式
  34. </Cell>
  35. <KeyboardPicker
  36. visible={visible}
  37. onKeyClick={(key) => this.onKeyClick(key)}
  38. />
  39. </>
  40. )
  41. }
  42. }
  43. ReactDOM.render(<Demo />, mountNode);

API

属性类型默认值说明
typestring'number'键盘类型,可选值 numberpriceidcard
onKeyClick(key?: string) => void-点击按键时触发的回调函数

仅 KeyboardPicker 支持的属性

属性类型默认值说明
visiblebooleanfalse是否展示
destroybooleantrue弹层关闭后是否移除节点