* Resolve a style property into it's component parts, e.g. * * resolveProperties('margin', {margin: 5, marginBottom: 10}) * -> * {top: 5, left: 5, right: 5, bottom: 10} * * If none are set, returns false.
(prefix: string, style: Object)
| 21 | * If none are set, returns false. |
| 22 | */ |
| 23 | function resolveBoxStyle(prefix: string, style: Object): ?Object { |
| 24 | var res = {}; |
| 25 | var subs = ['top', 'left', 'bottom', 'right']; |
| 26 | var set = false; |
| 27 | subs.forEach(sub => { |
| 28 | res[sub] = style[prefix] || 0; |
| 29 | }); |
| 30 | if (style[prefix]) { |
| 31 | set = true; |
| 32 | } |
| 33 | if (style[prefix + 'Vertical']) { |
| 34 | res.top = res.bottom = style[prefix + 'Vertical']; |
| 35 | set = true; |
| 36 | } |
| 37 | if (style[prefix + 'Horizontal']) { |
| 38 | res.left = res.right = style[prefix + 'Horizontal']; |
| 39 | set = true; |
| 40 | } |
| 41 | subs.forEach(sub => { |
| 42 | var val = style[prefix + capFirst(sub)]; |
| 43 | if (val) { |
| 44 | res[sub] = val; |
| 45 | set = true; |
| 46 | } |
| 47 | }); |
| 48 | if (!set) { |
| 49 | return; |
| 50 | } |
| 51 | return res; |
| 52 | } |
| 53 | |
| 54 | function capFirst(text) { |
| 55 | return text[0].toUpperCase() + text.slice(1); |
no test coverage detected
searching dependent graphs…