UNPKG

1.11 kBJavaScriptView Raw
1// Supports determination of isControlled().
2// Controlled input accepts its current value as a prop.
3//
4// @see https://facebook.github.io/react/docs/forms.html#controlled-components
5// @param value
6// @returns {boolean} true if string (including '') or number (including zero)
7export function hasValue(value) {
8 return value != null && !(Array.isArray(value) && value.length === 0);
9} // Determine if field is empty or filled.
10// Response determines if label is presented above field or as placeholder.
11//
12// @param obj
13// @param SSR
14// @returns {boolean} False when not present or empty string.
15// True when any number or string with length.
16
17export function isFilled(obj, SSR = false) {
18 return obj && (hasValue(obj.value) && obj.value !== '' || SSR && hasValue(obj.defaultValue) && obj.defaultValue !== '');
19} // Determine if an Input is adorned on start.
20// It's corresponding to the left with LTR.
21//
22// @param obj
23// @returns {boolean} False when no adornments.
24// True when adorned at the start.
25
26export function isAdornedStart(obj) {
27 return obj.startAdornment;
28}
\No newline at end of file