| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import { Input, View } from "@tarojs/components";
- import './Inputs.scss'
- import { useEffect, useState } from "react";
- import { ColorType } from "@/context/themes/color";
- import { IconClear } from "../basic/Icons";
- interface CustomInputProps {
- placeholder?: string;
- value: string;
- onChange: (value: string) => void;
- onConfirm: Function,
- openType?: string;
- disabled?: boolean;
- isSecure?: boolean;
- autoFocus?: boolean;
- onBlur?: Function;
- onFocus?: Function;
- }
- export default function Component({
- placeholder,
- value,
- onChange,
- onConfirm,
- openType,
- disabled,
- isSecure,
- autoFocus,
- onBlur,
- onFocus
- }: CustomInputProps) {
- const [inputValue, setInputValue] = useState(value ? value : '');
- const [isFocus, setIsFocus] = useState(false)
- const handleInputChange = (e: any) => {
- const newValue = e.target.value;
- setInputValue(newValue);
- onChange(newValue);
- };
- useEffect(() => {
- setInputValue(value ? value : '')
- }, [value])
- function clear() {
- setInputValue('')
- onChange('')
- }
- if (process.env.TARO_ENV=='rn'){
- const TextInput = require('react-native').TextInput
- return (
- <View className="input_bg">
- <TextInput className={isFocus ? "input input_focus" : "input"}
- // style={{backgroundColor:'red'}}
- placeholder={placeholder ? placeholder : ''}
- value={inputValue}
- password={isSecure ? true : false}
- type={openType == 'nickname' ? 'nickname' : isSecure ? 'safe-password' : 'text'}
- // type={openType?openType:'text'}
- onInput={handleInputChange}
- placeholderStyle='color:#ffffff66'
- // onConfirm={() => onConfirm()}
- focus={autoFocus}
- confirmType="done"
- selectionColor={global.fastColor ? global.fastColor : ColorType.fast}
- disabled={disabled ? disabled : false}
- onFocus={() => {
- setIsFocus(true)
- if (onFocus)
- onFocus()
- }}
- onBlur={() => {
- setIsFocus(false)
- if (onBlur)
- onBlur()
- }}
- />
- {
- inputValue.length > 0 && <View className="clear_bg" onClick={clear}>
- <IconClear />
- </View>
- }
- </View>
- )
- }
- return (
- <View className="input_bg">
- <Input className={isFocus ? "input input_focus" : "input"}
- // style={{backgroundColor:'red'}}
- placeholder={placeholder ? placeholder : ''}
- value={inputValue}
- password={isSecure ? true : false}
- type={openType == 'nickname' ? 'nickname' : isSecure ? 'safe-password' : 'text'}
- // type={openType?openType:'text'}
- onInput={handleInputChange}
- placeholderStyle='color:#ffffff66'
- // onConfirm={() => onConfirm()}
- focus={autoFocus}
- confirmType="done"
- selectionColor={global.fastColor ? global.fastColor : ColorType.fast}
- disabled={disabled ? disabled : false}
- onFocus={() => {
- setIsFocus(true)
- if (onFocus)
- onFocus()
- }}
- onBlur={() => {
- setIsFocus(false)
- if (onBlur)
- onBlur()
- }}
- />
- {
- inputValue.length > 0 && <View className="clear_bg" onClick={clear}>
- <IconClear />
- </View>
- }
- </View>
- )
- }
|