baseui
Version:
A React Component library implementing the Base design language
61 lines (59 loc) • 3.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _overrides = require("../helpers/overrides");
var _styledComponents = require("./styled-components");
var _constants = require("./constants");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _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); } /*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
function ProgressSteps({
overrides = {},
current,
alwaysShowDescription = false,
orientation = _constants.ORIENTATION.vertical,
children
}) {
const [Root, rootProps] = (0, _overrides.getOverrides)(overrides.Root, _styledComponents.StyledProgressSteps);
const numChildren = React.Children.count(children);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const modifiedChildren = React.Children.map(children, (child, index) => {
if (!child) return;
const childOverrides = child.props.overrides || {};
const areOtherStepsActive = React.Children.toArray(children).some(child => child?.props?.isActive);
const isActive = child.props?.isActive ?? (index === current && !areOtherStepsActive);
const isCompleted = child.props.isCompleted ?? (typeof current === 'number' && index < current);
const isCurrent = child.props.isCurrent ?? index === current;
const isRightBeforeActive = children && children[index + 1] && (children[index + 1].props?.isActive ?? (typeof current === 'number' && index === current - 1));
return /*#__PURE__*/React.cloneElement(child, {
isLast: index === numChildren - 1,
isCompleted,
isCurrent,
isActive,
isRightBeforeActive,
alwaysShowDescription: child.props.alwaysShowDescription === undefined ? alwaysShowDescription : child.props.alwaysShowDescription,
step: index + 1,
orientation,
overrides: {
...overrides,
Root: overrides.StepRoot,
...childOverrides
}
});
});
return /*#__PURE__*/React.createElement(Root, _extends({
"data-baseweb": "progress-steps",
$orientation: orientation
}, rootProps), modifiedChildren);
}
ProgressSteps.defaultProps = {
current: 0
};
var _default = exports.default = ProgressSteps;