1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * Declare the type of input box 18 * @since 7 19 */ 20declare enum InputType { 21 /** 22 * Basic input mode. 23 * @since 7 24 */ 25 Normal, 26 27 /** 28 * Pure digital input mode. 29 * @since 7 30 */ 31 Number, 32 33 /** 34 * Phone number entry mode. 35 * @since 9 36 */ 37 PhoneNumber, 38 39 /** 40 * E-mail address input mode. 41 * @since 7 42 */ 43 Email, 44 45 /** 46 * Password entry mode. 47 * @since 7 48 */ 49 Password, 50} 51 52/** 53 * Declare the type of soft keyboard. 54 * @since 7 55 */ 56declare enum EnterKeyType { 57 /** 58 * Go. 59 * @since 7 60 */ 61 Go, 62 63 /** 64 * Search. 65 * @since 7 66 */ 67 Search, 68 69 /** 70 * Send. 71 * @since 7 72 */ 73 Send, 74 75 /** 76 * Next. 77 * @since 7 78 */ 79 Next, 80 81 /** 82 * Done. 83 * @since 7 84 */ 85 Done, 86} 87 88/** 89 * Provides the method of switching the cursor position. 90 * @since 8 91 */ 92declare class TextInputController { 93 /** 94 * constructor. 95 * @since 8 96 */ 97 constructor(); 98 /** 99 * Called when the position of the insertion cursor is set. 100 * @since 8 101 */ 102 caretPosition(value: number): void; 103} 104 105/** 106 * Defines the options of TextInput. 107 * @since 7 108 */ 109declare interface TextInputOptions { 110 /** 111 * The place holder text string. 112 * @since 7 113 */ 114 placeholder?: ResourceStr; 115 116 /** 117 * Sets the current value of TextArea. 118 * @since 7 119 */ 120 text?: ResourceStr; 121 122 /** 123 * Called when the position of the insertion cursor is set. 124 * @since 8 125 */ 126 controller?: TextInputController; 127} 128 129/** 130 * Text input style. 131 * @since 9 132 */ 133declare enum TextInputStyle { 134 /** 135 * Text input default style. 136 * @since 9 137 */ 138 Default, 139 140 /** 141 * Text input inline style. 142 * @since 9 143 */ 144 Inline 145} 146 147/** 148 * Provides a single-line text input component interface. 149 * @since 7 150 */ 151interface TextInputInterface { 152 /** 153 * Called when writing a single line of text. 154 * @since 7 155 */ 156 (value?: TextInputOptions): TextInputAttribute; 157} 158 159/** 160 * Defines the TextInput attribute functions. 161 * @since 7 162 */ 163declare class TextInputAttribute extends CommonMethod<TextInputAttribute> { 164 /** 165 * Called when the input type is set. 166 * @since 7 167 */ 168 type(value: InputType): TextInputAttribute; 169 170 /** 171 * Called when the color of the placeholder is set. 172 * @since 7 173 */ 174 placeholderColor(value: ResourceColor): TextInputAttribute; 175 176 /** 177 * Called when the font property of the placeholder is set. 178 * @since 7 179 */ 180 placeholderFont(value?: Font): TextInputAttribute; 181 182 /** 183 * Called when the type of soft keyboard input button is set. 184 * @since 7 185 */ 186 enterKeyType(value: EnterKeyType): TextInputAttribute; 187 188 /** 189 * Called when the color of the insertion cursor is set. 190 * @since 7 191 */ 192 caretColor(value: ResourceColor): TextInputAttribute; 193 194 /** 195 * Called when judging whether the text editing change finished. 196 * @since 7 197 * @deprecated since 8 198 * @useinstead onEditChange 199 */ 200 onEditChanged(callback: (isEditing: boolean) => void): TextInputAttribute; 201 202 /** 203 * Called when judging whether the text editing change finished. 204 * @since 8 205 */ 206 onEditChange(callback: (isEditing: boolean) => void): TextInputAttribute; 207 208 /** 209 * Called when submitted. 210 * @since 7 211 */ 212 onSubmit(callback: (enterKey: EnterKeyType) => void): TextInputAttribute; 213 214 /** 215 * Called when the input of the input box changes. 216 * @since 7 217 */ 218 onChange(callback: (value: string) => void): TextInputAttribute; 219 220 /** 221 * Called when the input of maximum text length is set. 222 * @since 7 223 */ 224 maxLength(value: number): TextInputAttribute; 225 226 /** 227 * Called when the font color is set. 228 * @since 7 229 */ 230 fontColor(value: ResourceColor): TextInputAttribute; 231 232 /** 233 * Called when the font size is set. 234 * @since 7 235 */ 236 fontSize(value: Length): TextInputAttribute; 237 238 /** 239 * Called when the font style of a font is set. 240 * @since 7 241 */ 242 fontStyle(value: FontStyle): TextInputAttribute; 243 244 /** 245 * Called when the font weight is set. 246 * @since 7 247 */ 248 fontWeight(value: number | FontWeight | string): TextInputAttribute; 249 250 /** 251 * Called when the font list of text is set. 252 * @since 7 253 */ 254 fontFamily(value: ResourceStr): TextInputAttribute; 255 256 /** 257 * Called when the inputFilter of text is set. 258 * @since 8 259 */ 260 inputFilter(value: ResourceStr, error?: (value: string) => void): TextInputAttribute; 261 262 /** 263 * Called when using the Clipboard menu 264 * @since 8 265 */ 266 onCopy(callback: (value: string) => void): TextInputAttribute; 267 268 /** 269 * Called when using the Clipboard menu 270 * @since 8 271 */ 272 onCut(callback: (value: string) => void): TextInputAttribute; 273 274 /** 275 * Called when using the Clipboard menu 276 * @since 8 277 */ 278 onPaste(callback: (value: string) => void): TextInputAttribute; 279 280 /** 281 * Called when the copy option is set. 282 * @since 9 283 */ 284 copyOption(value: CopyOptions): TextInputAttribute; 285 286 /** 287 * Called when the password show/hide icon is set. 288 * @since 9 289 */ 290 showPasswordIcon(value: boolean): TextInputAttribute; 291 292 /** 293 * Called when the text align is set. 294 * @since 9 295 */ 296 textAlign(value: TextAlign): TextInputAttribute; 297 298 /** 299 * Text input style 300 * @since 9 301 */ 302 style(value: TextInputStyle): TextInputAttribute; 303} 304 305/** 306 * Defines TextInput Component. 307 * @since 7 308 */ 309declare const TextInput: TextInputInterface; 310 311/** 312 * Defines TextInput Component instance. 313 * @since 7 314 */ 315declare const TextInputInstance: TextInputAttribute; 316