UNPKG

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