borderRadius.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = borderRadius;
  4. var _capitalizeString = _interopRequireDefault(require("../internalHelpers/_capitalizeString"));
  5. var _errors = _interopRequireDefault(require("../internalHelpers/_errors"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  7. /**
  8. * Shorthand that accepts a value for side and a value for radius and applies the radius value to both corners of the side.
  9. * @example
  10. * // Styles as object usage
  11. * const styles = {
  12. * ...borderRadius('top', '5px')
  13. * }
  14. *
  15. * // styled-components usage
  16. * const div = styled.div`
  17. * ${borderRadius('top', '5px')}
  18. * `
  19. *
  20. * // CSS as JS Output
  21. *
  22. * div {
  23. * 'borderTopRightRadius': '5px',
  24. * 'borderTopLeftRadius': '5px',
  25. * }
  26. */
  27. function borderRadius(side, radius) {
  28. var uppercaseSide = (0, _capitalizeString["default"])(side);
  29. if (!radius && radius !== 0) {
  30. throw new _errors["default"](62);
  31. }
  32. if (uppercaseSide === 'Top' || uppercaseSide === 'Bottom') {
  33. var _ref;
  34. return _ref = {}, _ref["border" + uppercaseSide + "RightRadius"] = radius, _ref["border" + uppercaseSide + "LeftRadius"] = radius, _ref;
  35. }
  36. if (uppercaseSide === 'Left' || uppercaseSide === 'Right') {
  37. var _ref2;
  38. return _ref2 = {}, _ref2["borderTop" + uppercaseSide + "Radius"] = radius, _ref2["borderBottom" + uppercaseSide + "Radius"] = radius, _ref2;
  39. }
  40. throw new _errors["default"](63);
  41. }
  42. module.exports = exports.default;