demo.tsx 9.1 KB
Newer Older
V
vickyYe 已提交
1
import React, { useState } from 'react'
Y
yewenwen 已提交
2
import { Input } from './input'
V
vickyYe 已提交
3 4
import { useTranslate } from '../../sites/assets/locale'
import Button from '@/packages/button'
Y
yewenwen 已提交
5

V
vickyYe 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
interface Idata {
  val1: string
  text: string
  password: string
  number: string
  digit: string
  tel: string
  readonly: string
  disabled: string
  showIcon: string
  required: string
  error1: string
  error2: string
  buttonVal: string
  format1: string
  format2: string
  textarea: string
  align1: string
  align2: string
  noBorder1: string
  noBorder2: string
  event: string
}
Y
yewenwen 已提交
29
const InputDemo = () => {
V
vickyYe 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  const [translated] = useTranslate({
    'zh-CN': {
      basic: '基本用法',
      title1: '自定义类型',
      title2: '禁用和只读',
      title3: '显示图标',
      title4: '错误提示',
      title5: '插入按钮',
      title6: '格式化输入内容',
      title7: '显示字数统计',
      title8: '对齐方式',
      title9: '无边框',
      title10: '点击事件',
      text: '文本',
      password: '密码',
      number: '数字',
      digit: '整数',
      tel: '手机号',
      readonly: '只读',
      disabled: '禁用',
      icon: '显示图标',
      clear: '显示清除图标',
      required: '必填项',
      error: '输入内容标红',
      errorBottom: '底部错误提示文案',
      code: '短信验证码',
      codeplaceholder: '请输入短信验证码',
      sendCode: '发送验证码',
      message: '留言',
      noBorder: '无边框',
      click: '点击',
      placeholder1: '在输入时执行格式化',
62
      text1: '校验文本中无数字',
V
vickyYe 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
      placeholder2: '在失焦时执行格式化',
      placeholder3: '请输入留言',
      placeholder4: '文本内容对齐',
      placeholder5: '输入框内容对齐',
    },
    'en-US': {
      basic: 'Basic Usage',
      title1: 'Custom Type',
      title2: 'Readonly And Disabled',
      title3: 'Show Icon',
      title4: 'Error Info',
      title5: 'Insert Button',
      title6: 'Format Value',
      title7: 'Show Word Limit',
      title8: 'Input Align',
      title9: 'No Border',
      title10: 'Click Event',
      text: 'Text',
      password: 'Password',
      number: 'Number',
      digit: 'Digit',
      tel: 'Tel',
      readonly: 'Readonly',
      disabled: 'Disabled',
      icon: 'Show Icon',
      clear: 'Show Clear Icon',
      required: 'Required',
      error: 'Error',
      errorBottom: 'Error Message',
      code: 'Code',
      codeplaceholder: 'Please enter code',
      sendCode: 'Send',
      message: 'Message',
      noBorder: 'No Border',
      click: 'Click',
      placeholder1: 'Format On Change',
99
      text1: 'Check no digits',
V
vickyYe 已提交
100 101 102 103 104 105
      placeholder2: 'Format On Blur',
      placeholder3: 'Message',
      placeholder4: 'Label Align',
      placeholder5: 'Input Align',
    },
  })
106
  const [value, UpdateValue] = useState('')
V
vickyYe 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
  const [state, setState] = useState({
    val1: '',
    text: '',
    password: '',
    number: '',
    digit: '',
    tel: '',
    readonly: '',
    disabled: '',
    showIcon: '',
    required: '',
    error1: '',
    error2: '',
    buttonVal: '',
    format1: '',
    format2: '',
    textarea: '',
    align1: '',
    align2: '',
    noBorder1: '',
    noBorder2: '',
    event: '',
    clear: '',
  })

132
  const change = (value: string | number, event: Event) => {
V
vickyYe 已提交
133
    console.log('change: ', value)
Y
yewenwen 已提交
134
  }
V
vickyYe 已提交
135
  const focus = (value: string | number, event: Event) => {
Y
yewenwen 已提交
136 137
    console.log('focus:', value, event)
  }
V
vickyYe 已提交
138
  const blur = (value: string | number, event: Event) => {
Y
yewenwen 已提交
139 140
    console.log('blur:', value, event)
  }
V
vickyYe 已提交
141 142 143 144 145 146 147 148
  const clear = (value: string | number, event: Event) => {
    console.log('clear:', value, event)
  }
  const click = (value: string | number) => {
    console.log('click:', value)
  }
  const clickInput = (value: string | number) => {
    console.log('clickInput:', value)
Y
yewenwen 已提交
149
  }
V
vickyYe 已提交
150 151 152 153 154 155 156 157
  const clickLeftIcon = (value: string | number) => {
    console.log('clickLeftIcon:', value)
  }
  const clickRightIcon = (value: string | number) => {
    console.log('clickRightIcon:', value)
  }
  const formatter = (value: string) => value.replace(/\d/g, '')

Y
yewenwen 已提交
158 159
  return (
    <>
V
vickyYe 已提交
160 161
      <div className="demo" style={{ paddingBottom: '20px' }}>
        <h2>{translated.basic}</h2>
O
oasis-cloud 已提交
162
        <Input
163
          name="text"
V
vickyYe 已提交
164 165
          label={translated.text}
          placeholder={translated.text}
166
          defaultValue={value}
167
          onChange={(val) => {
168 169 170
            console.log('change value:', val)
            UpdateValue(val)
          }}
V
vickyYe 已提交
171 172 173
        />
        <h2>{translated.title1}</h2>
        <Input
174
          name="text"
V
vickyYe 已提交
175 176
          label={translated.text}
          placeholder={translated.text}
177
          defaultValue={state.val1}
V
vickyYe 已提交
178 179
        />
        <Input
180
          name="password"
V
vickyYe 已提交
181 182 183 184 185 186
          label={translated.password}
          placeholder={translated.password}
          defaultValue={state.password}
          type="password"
        />
        <Input
187
          name="number"
V
vickyYe 已提交
188 189 190 191 192 193
          label={translated.number}
          placeholder={translated.number}
          defaultValue={state.number}
          type="number"
        />
        <Input
194
          name="digit"
V
vickyYe 已提交
195 196 197 198 199 200
          label={translated.digit}
          placeholder={translated.digit}
          defaultValue={state.digit}
          type="digit"
        />
        <Input
201
          name="tel"
V
vickyYe 已提交
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
          label={translated.tel}
          placeholder={translated.tel}
          defaultValue={state.tel}
          type="tel"
        />
        <h2>{translated.title2}</h2>
        <Input
          label={translated.text}
          placeholder={translated.readonly}
          defaultValue={state.readonly}
          readonly
        />
        <Input
          label={translated.text}
          placeholder={translated.disabled}
          defaultValue={state.disabled}
          disabled
        />
        <h2>{translated.title3}</h2>
        <Input
          label={translated.text}
          placeholder={translated.icon}
          defaultValue={state.showIcon}
          leftIcon="dongdong"
          rightIcon="ask2"
O
oasis-cloud 已提交
227 228
        />
        <Input
V
vickyYe 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
          label={translated.text}
          placeholder={translated.clear}
          defaultValue={state.clear}
          clearable
          clearSize="14"
        />
        <h2>{translated.title4}</h2>
        <Input
          label={translated.text}
          placeholder={translated.required}
          defaultValue={state.required}
          required
        />
        <Input
          label={translated.text}
          placeholder={translated.error}
          defaultValue={state.error1}
          error
        />
        <Input
          label={translated.text}
          placeholder={translated.errorBottom}
          defaultValue={state.error2}
          errorMessage={translated.errorBottom}
        />
        <h2>{translated.title5}</h2>
        <Input
          label={translated.code}
          placeholder={translated.codeplaceholder}
          defaultValue={state.buttonVal}
          clearable
          center
261 262 263 264 265
          slotButton={
            <Button size="small" type="primary">
              {translated.sendCode}
            </Button>
          }
V
vickyYe 已提交
266
        />
267 268 269 270 271 272
        <h2>
          {translated.title6}
          <span style={{ fontSize: '12px', paddingLeft: '10px' }}>
            ({translated.text1})
          </span>
        </h2>
V
vickyYe 已提交
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
        <Input
          label={translated.text}
          placeholder={translated.placeholder1}
          defaultValue={state.format1}
          formatter={formatter}
        />
        <Input
          label={translated.text}
          placeholder={translated.placeholder2}
          defaultValue={state.format2}
          formatter={formatter}
          formatTrigger="onBlur"
        />
        <h2>{translated.title7}</h2>
        <Input
          label={translated.message}
          placeholder={translated.message}
          defaultValue={state.textarea}
          type="textarea"
          showWordLimit
          rows="2"
          maxlength="50"
        />
        <h2>{translated.title8}</h2>
        <Input
          label={translated.text}
          placeholder={translated.placeholder4}
          defaultValue={state.align1}
          labelAlign="right"
        />
        <Input
          label={translated.text}
          placeholder={translated.placeholder5}
          defaultValue={state.align2}
          inputAlign="right"
        />
        <h2>{translated.title9}</h2>
        <Input
          label={translated.noBorder}
          placeholder={translated.noBorder}
          defaultValue={state.noBorder1}
          border={false}
        />
        <Input
          label={translated.noBorder}
          placeholder={translated.noBorder}
          defaultValue={state.noBorder2}
          border={false}
        />
        <h2>{translated.title10}</h2>
        <Input
          label={translated.click}
          placeholder={translated.click}
          defaultValue={state.event}
          leftIcon="dongdong"
          rightIcon="ask2"
          clearable
330 331 332 333 334 335 336 337
          onChange={change}
          onFocus={focus}
          onBlur={blur}
          onClear={clear}
          onClick={click}
          onClickInput={clickInput}
          onClickLeftIcon={clickLeftIcon}
          onClickRightIcon={clickRightIcon}
O
oasis-cloud 已提交
338
        />
Y
yewenwen 已提交
339 340 341 342 343 344
      </div>
    </>
  )
}

export default InputDemo