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)
|
7 | export 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.
|
18 | export function isFilled(obj, SSR = false) {
|
19 | return obj && (hasValue(obj.value) && obj.value !== '' || SSR && hasValue(obj.defaultValue) && obj.defaultValue !== '');
|
20 | }
|
21 |
|
22 | // Determine if an Input is adorned on start.
|
23 | // It's corresponding to the left with LTR.
|
24 | //
|
25 | // @param obj
|
26 | // @returns {boolean} False when no adornments.
|
27 | // True when adorned at the start.
|
28 | export function isAdornedStart(obj) {
|
29 | return obj.startAdornment;
|
30 | } |
\ | No newline at end of file |