(core) New Grist Forms styling and field options

Summary:
 - New styling for forms.
 - New field options for various field types (spinner, checkbox, radio buttons, alignment, sort).
 - Improved alignment of form fields in columns.
 - Support for additional select input keyboard shortcuts (Enter and Backspace).
 - Prevent submitting form on Enter if an input has focus.
 - Fix for changing form field type causing the field to disappear.

Test Plan: Browser tests.

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D4223
This commit is contained in:
George Gevoian
2024-04-10 23:50:30 -07:00
parent 661f1c1804
commit 86062a8c28
35 changed files with 2037 additions and 716 deletions

View File

@@ -175,6 +175,21 @@ export async function firstDefined<T>(...list: Array<() => Promise<T>>): Promise
return undefined;
}
/**
* Returns the number repesentation of `value`, or `defaultVal` if it cannot
* be represented as a valid number.
*/
export function numberOrDefault<T>(value: unknown, defaultVal: T): number | T {
if (typeof value === 'number') {
return !Number.isNaN(value) ? value : defaultVal;
} else if (typeof value === 'string') {
const maybeNumber = Number.parseFloat(value);
return !Number.isNaN(maybeNumber) ? maybeNumber : defaultVal;
} else {
return defaultVal;
}
}
/**
* Parses json and returns the result, or returns defaultVal if parsing fails.
*/