UNPKG

1.96 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
7var box = require('@spark-web/box');
8var divider = require('@spark-web/divider');
9var ts = require('@spark-web/utils/ts');
10var react = require('react');
11var theme = require('@spark-web/theme');
12var jsxRuntime = require('react/jsx-runtime');
13
14var alignLookup = {
15 left: 'start',
16 center: 'center',
17 right: 'end',
18 stretch: 'stretch'
19};
20var alignToAlignItems = theme.createResponsiveMapFn(alignLookup);
21
22var _excluded = ["align", "children", "data", "dividers"];
23var Stack = ts.forwardRefWithAs(function (_ref, forwardedRef) {
24 var _ref$align = _ref.align,
25 align = _ref$align === void 0 ? 'stretch' : _ref$align,
26 children = _ref.children,
27 data = _ref.data,
28 dividers = _ref.dividers,
29 props = _objectWithoutProperties(_ref, _excluded);
30
31 var alignItems = alignToAlignItems(align);
32
33 var rootProps = _objectSpread({
34 ref: forwardedRef,
35 alignItems: alignItems,
36 data: data,
37 display: 'flex',
38 flexDirection: 'column'
39 }, props); // bail early w/o dividers to avoid unnecessary map
40
41
42 if (!dividers) {
43 return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, rootProps), {}, {
44 children: children
45 }));
46 } // map over children to insert dividers
47 // remove falsy values before mapping, keeps the index in sync
48
49
50 var childArray = react.Children.toArray(children);
51 return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, rootProps), {}, {
52 children: childArray.map(function (child, idx) {
53 return /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
54 children: [dividers && idx ? /*#__PURE__*/jsxRuntime.jsx(divider.Divider, {}) : null, child]
55 }, child.key || idx);
56 })
57 }));
58});
59
60exports.Stack = Stack;