UNPKG

1.19 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}
10
11// Determine if field is empty or filled.
12// Response determines if label is presented above field or as placeholder.
13//
14// @param obj
15// @param SSR
16// @returns {boolean} False when not present or empty string.
17// True when any number or string with length.
18export function isFilled(obj) {
19 var SSR = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
20 return obj && (hasValue(obj.value) && obj.value !== '' || SSR && hasValue(obj.defaultValue) && obj.defaultValue !== '');
21}
22
23// Determine if an Input is adorned on start.
24// It's corresponding to the left with LTR.
25//
26// @param obj
27// @returns {boolean} False when no adornments.
28// True when adorned at the start.
29export function isAdornedStart(obj) {
30 return obj.startAdornment;
31}
\No newline at end of file