refactor : merge Inventory_frontend submodule into frontend/ directory
Merges the full git history of Inventory_frontend into the monorepo under frontend/. Removes the submodule in favor of a unified repo. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
41
frontend/app/utils/events.ts
Normal file
41
frontend/app/utils/events.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Type-safe event handlers for form inputs.
|
||||
* These helpers extract values from DOM events in a way that satisfies TypeScript.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Extract the string value from an input event.
|
||||
*/
|
||||
export const getInputValue = (event: Event): string => {
|
||||
const target = event.target as HTMLInputElement | null
|
||||
return target?.value ?? ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the numeric value from an input event.
|
||||
*/
|
||||
export const getInputNumber = (event: Event): number => {
|
||||
const target = event.target as HTMLInputElement | null
|
||||
const value = target?.value ?? ''
|
||||
const parsed = parseFloat(value)
|
||||
return Number.isNaN(parsed) ? 0 : parsed
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the checked state from a checkbox event.
|
||||
*/
|
||||
export const getCheckboxValue = (event: Event): boolean => {
|
||||
const target = event.target as HTMLInputElement | null
|
||||
return target?.checked ?? false
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract an optional numeric value from an input event (empty string = undefined).
|
||||
*/
|
||||
export const getOptionalNumber = (event: Event): number | undefined => {
|
||||
const target = event.target as HTMLInputElement | null
|
||||
const value = target?.value ?? ''
|
||||
if (value.trim() === '') return undefined
|
||||
const parsed = parseFloat(value)
|
||||
return Number.isNaN(parsed) ? undefined : parsed
|
||||
}
|
||||
Reference in New Issue
Block a user