(setting: Setting, options: TextSettingOptions)
| 186 | * Helper for configuring a text input setting (works with SettingGroup.addSetting) |
| 187 | */ |
| 188 | export function configureTextSetting(setting: Setting, options: TextSettingOptions): Setting { |
| 189 | return setting |
| 190 | .setName(options.name) |
| 191 | .setDesc(options.desc) |
| 192 | .addText((text) => { |
| 193 | text.setValue(options.getValue()); |
| 194 | |
| 195 | // Use debounced onChange if debounceMs is specified |
| 196 | const handleChange = (value: string) => { |
| 197 | runAsyncSettingCallback(() => options.setValue(value)); |
| 198 | }; |
| 199 | if (options.debounceMs && options.debounceMs > 0) { |
| 200 | const debouncedSetValue = debounce(handleChange, options.debounceMs); |
| 201 | text.onChange(debouncedSetValue); |
| 202 | } else { |
| 203 | text.onChange(handleChange); |
| 204 | } |
| 205 | |
| 206 | if (options.placeholder) { |
| 207 | text.setPlaceholder(options.placeholder); |
| 208 | } |
| 209 | |
| 210 | if (options.ariaLabel) { |
| 211 | text.inputEl.setAttribute("aria-label", options.ariaLabel); |
| 212 | } |
| 213 | |
| 214 | // Apply consistent styling |
| 215 | text.inputEl.addClass("settings-view__input"); |
| 216 | |
| 217 | return text; |
| 218 | }); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Helper for creating standard text input settings |
no test coverage detected