UNPKG

2.62 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5exports.__esModule = true;
6exports["default"] = exports.ListIcon = exports.ListItem = void 0;
7
8var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
10var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
12var _core = require("@emotion/core");
13
14var _react = require("react");
15
16var _Box = _interopRequireDefault(require("../Box"));
17
18var _Icon = _interopRequireDefault(require("../Icon"));
19
20var _PseudoBox = _interopRequireDefault(require("../PseudoBox"));
21
22var _utils = require("../utils");
23
24/** @jsx jsx */
25var List = (0, _react.forwardRef)(function (_ref, ref) {
26 var _ref$styleType = _ref.styleType,
27 styleType = _ref$styleType === void 0 ? "none" : _ref$styleType,
28 _ref$stylePos = _ref.stylePos,
29 stylePos = _ref$stylePos === void 0 ? "inside" : _ref$stylePos,
30 spacing = _ref.spacing,
31 children = _ref.children,
32 props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, ["styleType", "stylePos", "spacing", "children"]);
33 var validChildren = (0, _utils.cleanChildren)(children);
34 return (0, _core.jsx)(_Box["default"], (0, _extends2["default"])({
35 ref: ref,
36 as: "ul",
37 listStyleType: styleType,
38 listStylePosition: stylePos
39 }, props), validChildren.map(function (child, index) {
40 var isLast = index + 1 === _react.Children.count(children);
41
42 if (isLast) {
43 return child;
44 }
45
46 return (0, _react.cloneElement)(child, {
47 spacing: spacing
48 });
49 }));
50});
51List.displayName = "List";
52var ListItem = (0, _react.forwardRef)(function (_ref2, ref) {
53 var spacing = _ref2.spacing,
54 props = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, ["spacing"]);
55 return (0, _core.jsx)(_PseudoBox["default"], (0, _extends2["default"])({
56 ref: ref,
57 as: "li",
58 mb: spacing
59 }, props));
60});
61exports.ListItem = ListItem;
62ListItem.diplayName = "ListItem";
63
64var ListIcon = function ListIcon(_ref3) {
65 var icon = _ref3.icon,
66 props = (0, _objectWithoutPropertiesLoose2["default"])(_ref3, ["icon"]);
67
68 if (typeof icon === "string") {
69 return (0, _core.jsx)(_Icon["default"], (0, _extends2["default"])({
70 name: icon,
71 mr: 2
72 }, props));
73 }
74
75 return (0, _core.jsx)(_Box["default"], (0, _extends2["default"])({
76 as: icon,
77 d: "inline",
78 focusable: "false",
79 size: "1em",
80 color: "currentColor",
81 mr: 2
82 }, props));
83};
84
85exports.ListIcon = ListIcon;
86var _default = List;
87exports["default"] = _default;
\No newline at end of file