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 * Password entry mode. 29 * @since 7 30 */ 31 Number, 32 33 /** 34 * E-mail address input mode. 35 * @since 7 36 */ 37 Email, 38 39 /** 40 * Pure digital input mode. 41 * @since 7 42 */ 43 Password, 44} 45 46/** 47 * Declare the type of soft keyboard. 48 * @since 7 49 */ 50declare enum EnterKeyType { 51 /** 52 * Go. 53 * @since 7 54 */ 55 Go, 56 57 /** 58 * Search. 59 * @since 7 60 */ 61 Search, 62 63 /** 64 * Send. 65 * @since 7 66 */ 67 Send, 68 69 /** 70 * Next. 71 * @since 7 72 */ 73 Next, 74 75 /** 76 * Done. 77 * @since 7 78 */ 79 Done, 80} 81 82/** 83 * Provides the method of switching the cursor position. 84 * @since 8 85 */ 86declare class TextInputController { 87 /** 88 * constructor. 89 * @since 8 90 */ 91 constructor(); 92 /** 93 * Called when the position of the insertion cursor is set. 94 * @since 8 95 */ 96 caretPosition(value: number): void; 97} 98 99/** 100 * Defines the options of TextInput. 101 * @since 7 102 */ 103declare interface TextInputOptions { 104 /** 105 * The place holder text string. 106 * @since 7 107 */ 108 placeholder?: ResourceStr; 109 110 /** 111 * Sets the current value of TextArea. 112 * @since 7 113 */ 114 text?: ResourceStr; 115 116 /** 117 * Called when the position of the insertion cursor is set. 118 * @since 8 119 */ 120 controller?: TextInputController; 121} 122 123/** 124 * Provides a single-line text input component interface. 125 * @since 7 126 */ 127interface TextInputInterface { 128 /** 129 * Called when writing a single line of text. 130 * @since 7 131 */ 132 (value?: TextInputOptions): TextInputAttribute; 133} 134 135/** 136 * Defines the TextInput attribute functions. 137 * @since 7 138 */ 139declare class TextInputAttribute extends CommonMethod<TextInputAttribute> { 140 /** 141 * Called when the input type is set. 142 * @since 7 143 */ 144 type(value: InputType): TextInputAttribute; 145 146 /** 147 * Called when the color of the placeholder is set. 148 * @since 7 149 */ 150 placeholderColor(value: ResourceColor): TextInputAttribute; 151 152 /** 153 * Called when the font property of the placeholder is set. 154 * @since 7 155 */ 156 placeholderFont(value?: Font): TextInputAttribute; 157 158 /** 159 * Called when the type of soft keyboard input button is set. 160 * @since 7 161 */ 162 enterKeyType(value: EnterKeyType): TextInputAttribute; 163 164 /** 165 * Called when the color of the insertion cursor is set. 166 * @since 7 167 */ 168 caretColor(value: ResourceColor): TextInputAttribute; 169 170 /** 171 * Called when judging whether the text editing change finished. 172 * @since 7 173 * @deprecated since 8 174 */ 175 onEditChanged(callback: (isEditing: boolean) => void): TextInputAttribute; 176 177 /** 178 * Called when judging whether the text editing change finished. 179 * @since 8 180 */ 181 onEditChange(callback: (isEditing: boolean) => void): TextInputAttribute; 182 183 /** 184 * Called when submitted. 185 * @since 7 186 */ 187 onSubmit(callback: (enterKey: EnterKeyType) => void): TextInputAttribute; 188 189 /** 190 * Called when the input of the input box changes. 191 * @since 7 192 */ 193 onChange(callback: (value: string) => void): TextInputAttribute; 194 195 /** 196 * Called when the input of maximum text length is set. 197 * @since 7 198 */ 199 maxLength(value: number): TextInputAttribute; 200 201 /** 202 * Called when the font color is set. 203 * @since 7 204 */ 205 fontColor(value: ResourceColor): TextInputAttribute; 206 207 /** 208 * Called when the font size is set. 209 * @since 7 210 */ 211 fontSize(value: Length): TextInputAttribute; 212 213 /** 214 * Called when the font style of a font is set. 215 * @since 7 216 */ 217 fontStyle(value: FontStyle): TextInputAttribute; 218 219 /** 220 * Called when the font weight is set. 221 * @since 7 222 */ 223 fontWeight(value: number | FontWeight | string): TextInputAttribute; 224 225 /** 226 * Called when the font list of text is set. 227 * @since 7 228 */ 229 fontFamily(value: ResourceStr): TextInputAttribute; 230 231 /** 232 * Called when the inputFilter of text is set. 233 * @since 8 234 */ 235 inputFilter(value: ResourceStr, error?: (value: string) => void): TextInputAttribute; 236 237 /** 238 * Called when using the Clipboard menu 239 * @since 8 240 */ 241 onCopy(callback: (value: string) => void): TextInputAttribute; 242 243 /** 244 * Called when using the Clipboard menu 245 * @since 8 246 */ 247 onCut(callback: (value: string) => void): TextInputAttribute; 248 249 /** 250 * Called when using the Clipboard menu 251 * @since 8 252 */ 253 onPaste(callback: (value: string) => void): TextInputAttribute; 254} 255 256declare const TextInput: TextInputInterface; 257declare const TextInputInstance: TextInputAttribute; 258