MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / configureNumberSetting

Function configureNumberSetting

src/settings/components/settingHelpers.ts:268–313  ·  view source on GitHub ↗
(setting: Setting, options: NumberSettingOptions)

Source from the content-addressed store, hash-verified

266 * Helper for configuring a number input setting (works with SettingGroup.addSetting)
267 */
268export function configureNumberSetting(setting: Setting, options: NumberSettingOptions): Setting {
269 const setValue = options.debounceMs
270 ? debounce((value: number) => {
271 runAsyncSettingCallback(() => options.setValue(value));
272 }, options.debounceMs)
273 : (value: number) => {
274 runAsyncSettingCallback(() => options.setValue(value));
275 };
276
277 return setting
278 .setName(options.name)
279 .setDesc(options.desc)
280 .addText((text) => {
281 text.setValue(options.getValue().toString()).onChange((value) => {
282 const num = parseInt(value);
283 if (!isNaN(num)) {
284 if (options.min !== undefined && num < options.min) return;
285 if (options.max !== undefined && num > options.max) return;
286 setValue(num);
287 }
288 });
289
290 text.inputEl.type = "number";
291
292 if (options.placeholder) {
293 text.setPlaceholder(options.placeholder);
294 }
295
296 if (options.min !== undefined) {
297 text.inputEl.setAttribute("min", options.min.toString());
298 }
299
300 if (options.max !== undefined) {
301 text.inputEl.setAttribute("max", options.max.toString());
302 }
303
304 if (options.ariaLabel) {
305 text.inputEl.setAttribute("aria-label", options.ariaLabel);
306 }
307
308 // Apply consistent styling
309 text.inputEl.addClass("settings-view__input");
310
311 return text;
312 });
313}
314
315/**
316 * Helper for creating standard number input settings

Callers 4

renderIntegrationsTabFunction · 0.90
renderFeaturesTabFunction · 0.90
renderAppearanceTabFunction · 0.90
createNumberSettingFunction · 0.85

Calls 11

runAsyncSettingCallbackFunction · 0.85
setDescMethod · 0.80
setPlaceholderMethod · 0.80
debounceFunction · 0.70
setValueMethod · 0.65
toStringMethod · 0.65
addClassMethod · 0.65
addTextMethod · 0.45
setNameMethod · 0.45
onChangeMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected