UNPKG

2.14 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = position;
5var _directionalProperty = _interopRequireDefault(require("../helpers/directionalProperty"));
6function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
7function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
8var positionMap = ['absolute', 'fixed', 'relative', 'static', 'sticky'];
9
10/**
11 * Shorthand accepts up to five values, including null to skip a value, and maps them to their respective directions. The first value can optionally be a position keyword.
12 * @example
13 * // Styles as object usage
14 * const styles = {
15 * ...position('12px', '24px', '36px', '48px')
16 * }
17 *
18 * // styled-components usage
19 * const div = styled.div`
20 * ${position('12px', '24px', '36px', '48px')}
21 * `
22 *
23 * // CSS as JS Output
24 *
25 * div {
26 * 'top': '12px',
27 * 'right': '24px',
28 * 'bottom': '36px',
29 * 'left': '48px'
30 * }
31 *
32 * // Styles as object usage
33 * const styles = {
34 * ...position('absolute', '12px', '24px', '36px', '48px')
35 * }
36 *
37 * // styled-components usage
38 * const div = styled.div`
39 * ${position('absolute', '12px', '24px', '36px', '48px')}
40 * `
41 *
42 * // CSS as JS Output
43 *
44 * div {
45 * 'position': 'absolute',
46 * 'top': '12px',
47 * 'right': '24px',
48 * 'bottom': '36px',
49 * 'left': '48px'
50 * }
51 */
52function position(firstValue) {
53 for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
54 values[_key - 1] = arguments[_key];
55 }
56 if (positionMap.indexOf(firstValue) >= 0 && firstValue) {
57 return _extends({}, _directionalProperty["default"].apply(void 0, [''].concat(values)), {
58 position: firstValue
59 });
60 } else {
61 return _directionalProperty["default"].apply(void 0, ['', firstValue].concat(values));
62 }
63}
64module.exports = exports.default;
\No newline at end of file