@salesforce/design-system-react
Version:
Salesforce Lightning Design System for React
157 lines (119 loc) • 6.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _constants = require("../../../utilities/constants");
var _icon = _interopRequireDefault(require("../../icon"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// ### Display Name
var displayName = _constants.PROGRESS_INDICATOR_STEP_VERTICAL; // ### Prop Types
var propTypes = {
/**
* **Assistive text for accessibility**
* This object is merged with the default props object on every render.
* * `completedStep`: Label for a completed step. The default is `Completed Step`
* * `disabledStep`: Label for disabled step. The default is `Disabled Step`
* * `errorStep`: Label for a step with an error. The default is `Error Step`
* * `percentage`: Label for Progress Bar. The default is `Progress: [this.props.value]%`. You will need to calculate the percentage yourself if changing this string.
* * `step`: Label for a step. It will be typically followed by the number of the step such as "Step 1".
*/
assistiveText: _propTypes.default.shape({
completedStep: _propTypes.default.string,
disabledStep: _propTypes.default.string,
percentage: _propTypes.default.string,
step: _propTypes.default.string
}),
/**
* Id for Steps, ranging in [0, steps.length).
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
/**
* Index of step. Used for id's if no step ID exists
*/
index: _propTypes.default.number,
/**
* Determines if the step has been completed
*/
isCompleted: _propTypes.default.bool,
/**
* Determines if the step has been disabled
*/
isDisabled: _propTypes.default.bool,
/**
* Determines if the step contains an error
*/
isError: _propTypes.default.bool,
/**
* Determines if the step is currently selected (active)
*/
isSelected: _propTypes.default.bool,
/**
* Step object. This is passed into event callbacks.
*/
step: _propTypes.default.object
};
/**
* StepVertical renders a step icon and its step label if applied
*/
var StepVertical =
/*#__PURE__*/
function (_React$Component) {
_inherits(StepVertical, _React$Component);
function StepVertical() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, StepVertical);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(StepVertical)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_this), "stepIcon", function (renderIcon) {
var icon = renderIcon ? _react.default.createElement(_icon.default, {
category: "utility",
size: "x-small",
name: _this.props.isError ? 'error' : 'success'
}) : null;
return _react.default.createElement("span", {
className: (0, _classnames.default)('slds-progress__marker', {
'slds-progress__marker_icon': renderIcon
})
}, icon);
});
return _this;
}
_createClass(StepVertical, [{
key: "render",
value: function render() {
var renderIcon = this.props.isCompleted || this.props.isError;
return _react.default.createElement("li", {
className: (0, _classnames.default)('slds-progress__item', {
'slds-is-completed': this.props.isCompleted,
'slds-is-active': this.props.isSelected && !this.props.isError,
'slds-has-error': this.props.isError
})
}, this.stepIcon(renderIcon), _react.default.createElement("div", {
id: "progress-indicator-vertical-label-".concat(this.props.step.id || this.props.index),
className: "slds-progress__item_content slds-grid slds-grid_align-spread"
}, this.props.step.label));
}
}]);
return StepVertical;
}(_react.default.Component);
StepVertical.propTypes = propTypes;
StepVertical.displayName = displayName;
var _default = StepVertical; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime
exports.default = _default;