UNPKG

1.98 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = border;
5var _capitalizeString = _interopRequireDefault(require("../internalHelpers/_capitalizeString"));
6function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
7var sideMap = ['top', 'right', 'bottom', 'left'];
8
9/**
10 * Shorthand for the border property that splits out individual properties for use with tools like Fela and Styletron. A side keyword can optionally be passed to target only one side's border properties.
11 *
12 * @example
13 * // Styles as object usage
14 * const styles = {
15 * ...border('1px', 'solid', 'red')
16 * }
17 *
18 * // styled-components usage
19 * const div = styled.div`
20 * ${border('1px', 'solid', 'red')}
21 * `
22 *
23 * // CSS as JS Output
24 *
25 * div {
26 * 'borderColor': 'red',
27 * 'borderStyle': 'solid',
28 * 'borderWidth': `1px`,
29 * }
30 *
31 * // Styles as object usage
32 * const styles = {
33 * ...border('top', '1px', 'solid', 'red')
34 * }
35 *
36 * // styled-components usage
37 * const div = styled.div`
38 * ${border('top', '1px', 'solid', 'red')}
39 * `
40 *
41 * // CSS as JS Output
42 *
43 * div {
44 * 'borderTopColor': 'red',
45 * 'borderTopStyle': 'solid',
46 * 'borderTopWidth': `1px`,
47 * }
48 */
49
50function border(sideKeyword) {
51 for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
52 values[_key - 1] = arguments[_key];
53 }
54 if (typeof sideKeyword === 'string' && sideMap.indexOf(sideKeyword) >= 0) {
55 var _ref;
56 return _ref = {}, _ref["border" + (0, _capitalizeString["default"])(sideKeyword) + "Width"] = values[0], _ref["border" + (0, _capitalizeString["default"])(sideKeyword) + "Style"] = values[1], _ref["border" + (0, _capitalizeString["default"])(sideKeyword) + "Color"] = values[2], _ref;
57 } else {
58 values.unshift(sideKeyword);
59 return {
60 borderWidth: values[0],
61 borderStyle: values[1],
62 borderColor: values[2]
63 };
64 }
65}
66module.exports = exports.default;
\No newline at end of file