You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
// Supports determination of isControlled().
|
|
// Controlled input accepts its current value as a prop.
|
|
//
|
|
// @see https://facebook.github.io/react/docs/forms.html#controlled-components
|
|
// @param value
|
|
// @returns {boolean} true if string (including '') or number (including zero)
|
|
export function hasValue(value) {
|
|
return value != null && !(Array.isArray(value) && value.length === 0);
|
|
}
|
|
|
|
// Determine if field is empty or filled.
|
|
// Response determines if label is presented above field or as placeholder.
|
|
//
|
|
// @param obj
|
|
// @param SSR
|
|
// @returns {boolean} False when not present or empty string.
|
|
// True when any number or string with length.
|
|
export function isFilled(obj, SSR = false) {
|
|
return obj && (hasValue(obj.value) && obj.value !== '' || SSR && hasValue(obj.defaultValue) && obj.defaultValue !== '');
|
|
}
|
|
|
|
// Determine if an Input is adorned on start.
|
|
// It's corresponding to the left with LTR.
|
|
//
|
|
// @param obj
|
|
// @returns {boolean} False when no adornments.
|
|
// True when adorned at the start.
|
|
export function isAdornedStart(obj) {
|
|
return obj.startAdornment;
|
|
} |