UNPKG

1.41 kBJavaScriptView Raw
1/* eslint-disable camelcase */
2
3function getPadding(vertical, top, bottom) {
4 const isTopDefined = typeof top === 'number';
5 const isBottomDefined = typeof bottom === 'number';
6 const isVerticalDefined = typeof vertical === 'number';
7
8 if (isTopDefined && isBottomDefined) {
9 return top + bottom;
10 }
11
12 if (isTopDefined && isVerticalDefined) {
13 return top + vertical;
14 }
15
16 if (isTopDefined) {
17 return top;
18 }
19
20 if (isBottomDefined && isVerticalDefined) {
21 return bottom + vertical;
22 }
23
24 if (isBottomDefined) {
25 return bottom;
26 }
27
28 if (isVerticalDefined) {
29 return 2 * vertical;
30 }
31
32 return 0;
33}
34
35export default function getInputHeight({
36 font: {
37 input: {
38 lineHeight,
39 lineHeight_small,
40 },
41 },
42 spacing: {
43 inputPadding,
44 displayTextPaddingVertical,
45 displayTextPaddingTop,
46 displayTextPaddingBottom,
47 displayTextPaddingVertical_small,
48 displayTextPaddingTop_small,
49 displayTextPaddingBottom_small,
50 },
51}, small) {
52 const calcLineHeight = small ? lineHeight_small : lineHeight;
53
54 const padding = small
55 ? getPadding(
56 displayTextPaddingVertical_small,
57 displayTextPaddingTop_small,
58 displayTextPaddingBottom_small,
59 )
60 : getPadding(
61 displayTextPaddingVertical,
62 displayTextPaddingTop,
63 displayTextPaddingBottom,
64 );
65
66 return parseInt(calcLineHeight, 10) + (2 * inputPadding) + padding;
67}