@enact/ui
Version:
A collection of simplified unstyled cross-platform UI components for Enact
229 lines (225 loc) • 9.89 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.ProgressBarDecorator = exports.ProgressBarBase = exports.ProgressBar = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
var _clamp = _interopRequireDefault(require("ramda/src/clamp"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _validators = require("../internal/validators");
var _ForwardRef = _interopRequireDefault(require("../ForwardRef"));
var _ProgressBarModule = _interopRequireDefault(require("./ProgressBar.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "componentRef", "css"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
* A basic progress bar component that can display the progress of something in a horizontal,
* vertical, or radial bar format.
*
* A secondary independent progress indicator can be displayed, to indicate
* an additional degree of information, often used as a background loading progress.
*
* @module ui/ProgressBar
* @exports ProgressBar
* @exports ProgressBarBase
* @exports ProgressBarDecorator
*/
var progressToProportion = function progressToProportion(value) {
return (0, _clamp["default"])(0, 1, value);
};
var calcBarStyle = function calcBarStyle(prop, anchor) {
var value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : anchor;
var startProp = arguments.length > 3 ? arguments[3] : undefined;
var endProp = arguments.length > 4 ? arguments[4] : undefined;
var start = Math.min(anchor, value);
var end = Math.max(anchor, value) - start;
if (process.env.NODE_ENV !== "production") {
(0, _validators.validateRange)(start, 0, 1, 'ProgressBar', prop, 'min', 'max');
(0, _validators.validateRange)(end, 0, 1, 'ProgressBar', prop, 'min', 'max');
}
return _defineProperty(_defineProperty({}, startProp, progressToProportion(start)), endProp, progressToProportion(end));
};
/**
* An unstyled progress bar component that can be customized by a theme or application.
*
* @class ProgressBarBase
* @memberof ui/ProgressBar
* @ui
* @public
*/
var ProgressBarBase = exports.ProgressBarBase = (0, _kind["default"])({
name: 'ui:ProgressBar',
propTypes: /** @lends ui/ProgressBar.ProgressBarBase.prototype */{
/**
* The proportion of the loaded portion of the progress bar.
*
* * Valid values are between `0` and `1`.
*
* @type {Number}
* @default 0
* @public
*/
backgroundProgress: _propTypes2["default"].number,
/**
* The contents to be displayed with progress bar.
*
* @type {Node}
* @public
*/
children: _propTypes2["default"].node,
/**
* Called with a reference to the root component.
*
* When using {@link ui/ProgressBar.ProgressBar}, the `ref` prop is forwarded to this
* component as `componentRef`.
*
* @type {Object|Function}
* @public
*/
componentRef: _propTypes["default"].ref,
/**
* Customizes the component by mapping the supplied collection of CSS class names to the
* corresponding internal elements and states of this component.
*
* The following classes are supported:
*
* * `progressBar` - The root component class
* * `bar` - The background node (the empty part of the progressBar)
* * `fill` - The foreground of the progress bar (`progress`)
* * `load` - The `backgroundProgress` node
* * `horizontal` - Applied when `orientation` is `'horizontal'`
* * `vertical` - Applied when `orientation` is `'vertical'`
* * `radial` - Applied when `orientation` is `'radial'`
*
* @type {Object}
* @public
*/
css: _propTypes2["default"].object,
/**
* Sets the orientation of the slider.
*
* Allowed values include:
*
* * `'horizontal'` - A left and right orientation
* * `'vertical'` - An up and down orientation
* * `'radial'` - A circular orientation
*
* @type {String}
* @default 'horizontal'
* @public
*/
orientation: _propTypes2["default"].string,
/**
* The proportion of the filled portion of the progress bar.
*
* * Valid values are between `0` and `1`.
*
* @type {Number}
* @default 0
* @public
*/
progress: _propTypes2["default"].number,
/**
* Sets the point, as a proportion between 0 and 1, from which the progress bar is filled.
*
* Applies to both the progress bar's `value` and `backgroundProgress`. In both cases,
* setting the value of `progressAnchor` will cause the progress bar to fill from that point
* down, when `value` or `backgroundProgress` is proportionally less than the anchor, or up,
* when `value` or `backgroundProgress` is proportionally greater than the anchor, rather
* than always from the start of the progress bar.
*
* @type {Number}
* @default 0
* @public
*/
progressAnchor: _propTypes2["default"].number
},
defaultProps: {
backgroundProgress: 0,
orientation: 'horizontal',
progress: 0,
progressAnchor: 0
},
styles: {
css: _ProgressBarModule["default"],
className: 'progressBar',
publicClassNames: true
},
computed: {
className: function className(_ref2) {
var backgroundProgress = _ref2.backgroundProgress,
orientation = _ref2.orientation,
progress = _ref2.progress,
styler = _ref2.styler;
return styler.append(orientation, {
fillOverHalf: progress > 0.5,
loadOverHalf: backgroundProgress > 0.5
});
},
style: function style(_ref3) {
var backgroundProgress = _ref3.backgroundProgress,
progress = _ref3.progress,
progressAnchor = _ref3.progressAnchor,
_style = _ref3.style;
return _objectSpread(_objectSpread(_objectSpread({}, _style), {}, {
'--ui-progressbar-proportion-anchor': progressAnchor
}, calcBarStyle('backgroundProgress', progressAnchor, backgroundProgress, '--ui-progressbar-proportion-start-background', '--ui-progressbar-proportion-end-background')), calcBarStyle('progress', progressAnchor, progress, '--ui-progressbar-proportion-start', '--ui-progressbar-proportion-end'));
}
},
render: function render(_ref4) {
var children = _ref4.children,
componentRef = _ref4.componentRef,
css = _ref4.css,
rest = _objectWithoutProperties(_ref4, _excluded);
delete rest.backgroundProgress;
delete rest.orientation;
delete rest.progress;
delete rest.progressAnchor;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({
role: "progressbar"
}, rest), {}, {
ref: componentRef,
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
className: css.bar,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: css.load
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: css.fill
})]
}), children]
}));
}
});
/**
* A higher-order component that adds behavior to
* {@link ui/ProgressBar.ProgressBarBase|ProgressBar}.
*
* @hoc
* @memberof ui/ProgressBar
* @mixes ui/ForwardRef.ForwardRef
* @public
*/
var ProgressBarDecorator = exports.ProgressBarDecorator = (0, _compose["default"])((0, _ForwardRef["default"])({
prop: 'componentRef'
}));
/**
* An unstyled progress bar component that can be customized by a theme or application.
*
* @class ProgressBar
* @memberof ui/ProgressBar
* @extends ui/ProgressBar.ProgressBarBase
* @mixes ui/ProgressBar.ProgressBarDecorator
* @omit componentRef
* @ui
* @public
*/
var ProgressBar = exports.ProgressBar = ProgressBarDecorator(ProgressBarBase);
var _default = exports["default"] = ProgressBar;
;