@enact/sandstone
Version:
Large-screen/TV support library for Enact, containing a variety of UI components.
494 lines (490 loc) • 20.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.WizardPanelsDecorator = exports.WizardPanelsBase = exports.WizardPanels = void 0;
var _handle = _interopRequireWildcard(require("@enact/core/handle"));
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
var _I18nDecorator = require("@enact/i18n/I18nDecorator");
var _SpotlightContainerDecorator = _interopRequireWildcard(require("@enact/spotlight/SpotlightContainerDecorator"));
var _Layout = require("@enact/ui/Layout");
var _Changeable = _interopRequireDefault(require("@enact/ui/Changeable"));
var _ForwardRef = _interopRequireDefault(require("@enact/ui/ForwardRef"));
var _ViewManager = _interopRequireDefault(require("@enact/ui/ViewManager"));
var _IString = _interopRequireDefault(require("ilib/lib/IString"));
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _$L = _interopRequireDefault(require("../internal/$L"));
var _Panels = require("../Panels");
var _Panel = require("../Panels/Panel");
var _Panels2 = require("../internal/Panels");
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _Steps = _interopRequireDefault(require("../Steps"));
var _WizardPanelsModule = _interopRequireDefault(require("./WizardPanels.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["aria-label", "children", "footer", "index", "nextButton", "nextButtonVisibility", "noAnimation", "noSubtitle", "onNextClick", "onPrevClick", "onTransition", "onWillTransition", "prevButton", "prevButtonVisibility", "reverseTransition", "steps", "subtitle", "title", "totalPanels"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(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 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(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(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); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
var DecoratedPanelBase = (0, _Panels2.FloatingLayerIdProvider)(_Panel.PanelBase);
var HeaderContainer = (0, _SpotlightContainerDecorator["default"])(_Panels.Header);
/**
* A WizardPanels that has steps with corresponding panels.
*
* @example
* <WizardPanels>
* <WizardPanels.Panel subtitle="Subtitle" title="Title">
* <Scroller>
* lorem ipsum ...
* </Scroller>
* <footer>
* <Button>OK</Button>
* <Button>Cancel</Button>
* </footer>
* </WizardPanels.Panel>
* </WizardPanels>
*
* @class WizardPanelsBase
* @memberof sandstone/WizardPanels
* @ui
* @public
*/
var WizardPanelsBase = exports.WizardPanelsBase = (0, _kind["default"])({
name: 'WizardPanels',
propTypes: /** @lends sandstone/WizardPanels.WizardPanelsBase.prototype */{
/**
* The "aria-label" for the Panel.
*
* By default, the panel will be labeled by its {@link sandstone/Panels.Header|Header}.
* When `aria-label` is set, it will be used instead to provide an accessibility label for
* the panel.
*
* @type {String}
* @public
*/
'aria-label': _propTypes2["default"].string,
/**
* Obtains a reference to the root node.
*
* @type {Function|Object}
* @public
*/
componentRef: _propTypes["default"].ref,
/**
* The current step.
*
* This is 1-based, not 0-based; as in the first step is `1`. If omitted, this will equal
* the currently selected panel.
*
* @type {Number}
* @public
*/
current: _propTypes2["default"].number,
/**
* Components to be included under the primary content.
*
* Typically, up to 2 buttons may be included.
*
* @type {Element|Element[]}
* @public
*/
footer: _propTypes2["default"].node,
/**
* The currently selected panel.
*
* @type {Number}
* @default 0
* @private
*/
index: _propTypes2["default"].number,
/**
* The button to use in place of the standard next button.
*
* This prop accepts a component (e.g. `Button`), a component instance, or a boolean value.
*
* If `false`, the button will not show. If set to a component, or `true`, the button will
* show. This will override the setting of `nextButtonVisibility`.
*
* Example:
* ```
* nextButton={<Button icon="closex" aria-label="Quit">Close</Button>}
* ```
*
* @type {Boolean|Component}
* @private
*/
nextButton: _propTypes2["default"].oneOfType([_propTypes2["default"].bool, _propTypes["default"].componentOverride]),
/**
* Specifies when and how to show `nextButton` on WizardPanel.
*
* * `'auto'` will display the `nextButton` on every `WizardPanels.Panel` except the last
* * `'always'` will always display the `nextButton`
* * `'never'` will always hide the `nextButton`
*
* Note, children values will override the generalized parent visibility settings. In this
* case, a customized `nextButton` on WizardPanels.Panel will take precedence over the
* `nextButtonVisibility` value.
*
* @type {('auto'|'always'|'never')}
* @default 'auto'
* @public
*/
nextButtonVisibility: _propTypes2["default"].oneOf(['auto', 'always', 'never']),
/**
* Disables panel transitions.
*
* @type {Boolean}
* @public
*/
noAnimation: _propTypes2["default"].bool,
/**
* Omits the steps component.
*
* @type {Boolean}
* @public
*/
noSteps: _propTypes2["default"].bool,
/**
* Omits the subtitle area.
*
* @type {Boolean}
* @default false
* @public
*/
noSubtitle: _propTypes2["default"].bool,
/**
* Called when the index value is changed.
*
* @type {Function}
* @param {Object} event
* @public
*/
onChange: _propTypes2["default"].func,
/**
* Called when the next button is clicked in WizardPanel.
*
* Calling `preventDefault` on the passed event will prevent advancing to the next panel.
*
* @type {Function}
* @public
*/
onNextClick: _propTypes2["default"].func,
/**
* Called when previous button is clicked in WizardPanel.
*
* Calling `preventDefault` on the passed event will prevent navigation to the previous panel.
*
* @type {Function}
* @public
*/
onPrevClick: _propTypes2["default"].func,
/**
* Called when a transition completes.
*
* @type {Function}
*/
onTransition: _propTypes2["default"].func,
/**
* Called before a transition begins.
*
* @type {Function}
*/
onWillTransition: _propTypes2["default"].func,
/**
* The button to use in place of the standard prev button.
*
* This prop accepts a component (e.g. `Button`), a component instance, or a boolean value.
*
* If `false`, the button will not show. If set to a component, or `true`, the button will
* show. This will override the setting of `prevButtonVisibility`.
*
* Example:
* ```
* prevButton={<Button icon="closex" aria-label="Back">Back</Button>}
* ```
*
* @type {Boolean|Component}
* @private
*/
prevButton: _propTypes2["default"].oneOfType([_propTypes2["default"].bool, _propTypes["default"].componentOverride]),
/**
* Specifies when and how to show `prevButton` on WizardPanel.
*
* * `'auto'` will display the `prevButton` on every `WizardPanels.Panel` except the first
* * `'always'` will always display the `prevButton`
* * `'never'` will always hide the `prevButton`
*
* Note, children values will override the generalized parent visibility settings. In this case,
* if user provides a customized `prevButton` on WizardPanels.Panel will take precedence over the `prevButtonVisibility` value.
*
* @type {('auto'|'always'|'never')}
* @default 'auto'
* @public
*/
prevButtonVisibility: _propTypes2["default"].oneOf(['auto', 'always', 'never']),
/**
* Explicitly sets the ViewManager transition direction.
*
* @type {Boolean}
* @private
*/
reverseTransition: _propTypes2["default"].bool,
/**
* The subtitle to display.
*
* If {@link sandstone/WizardPanels.WizardPanelsBase.noSubtitle|noSubtitle} is `true`, this prop is ignored.
*
* @type {String}
* @public
*/
subtitle: _propTypes2["default"].string,
/**
* The title to display.
*
* @type {String}
* @public
*/
title: _propTypes2["default"].string,
/**
* The total number of steps.
*
* If omitted, this will equal the total number of Panels.
*
* @type {Number}
* @public
*/
total: _propTypes2["default"].number,
/**
* The total panels in WizardPanels.
*
* @type {Number}
* @private
*/
totalPanels: _propTypes2["default"].number
},
defaultProps: {
index: 0,
nextButtonVisibility: 'auto',
noSubtitle: false,
prevButtonVisibility: 'auto'
},
styles: {
css: _WizardPanelsModule["default"],
className: 'wizardPanels'
},
handlers: {
onNextClick: (0, _handle["default"])((0, _handle.forwardCustomWithPrevent)('onNextClick'), function (ev, _ref) {
var index = _ref.index,
onChange = _ref.onChange,
totalPanels = _ref.totalPanels;
if (onChange && index !== totalPanels) {
var nextIndex = index < totalPanels - 1 ? index + 1 : index;
onChange({
type: 'onChange',
index: nextIndex
});
}
}),
onPrevClick: (0, _handle["default"])((0, _handle.forwardCustomWithPrevent)('onPrevClick'), function (ev, _ref2) {
var index = _ref2.index,
onChange = _ref2.onChange;
if (onChange && index !== 0) {
var prevIndex = index > 0 ? index - 1 : index;
onChange({
type: 'onChange',
index: prevIndex
});
}
}),
onTransition: function onTransition(ev, _ref3) {
var index = _ref3.index,
_onTransition = _ref3.onTransition;
if (_onTransition) {
_onTransition({
type: 'onTransition',
index: index
});
}
},
onWillTransition: function onWillTransition(ev, _ref4) {
var index = _ref4.index,
_onWillTransition = _ref4.onWillTransition;
if (_onWillTransition) {
_onWillTransition({
type: 'onWillTransition',
index: index
});
}
}
},
computed: {
'aria-label': function ariaLabel(_ref5) {
var label = _ref5['aria-label'],
current = _ref5.current,
index = _ref5.index,
noSteps = _ref5.noSteps,
subtitle = _ref5.subtitle,
title = _ref5.title;
if (label) return label;
var stepNum = typeof current === 'number' && current > 0 ? current : index + 1;
var step = noSteps ? '' : new _IString["default"]((0, _$L["default"])('step {num}')).format({
num: stepNum
}) + ' ';
return "".concat(step).concat(title, " ").concat(subtitle);
},
className: function className(_ref6) {
var noSteps = _ref6.noSteps,
noSubtitle = _ref6.noSubtitle,
styler = _ref6.styler;
return styler.append({
noSteps: noSteps,
noSubtitle: noSubtitle
});
},
steps: function steps(_ref7) {
var current = _ref7.current,
index = _ref7.index,
noSteps = _ref7.noSteps,
total = _ref7.total,
totalPanels = _ref7.totalPanels;
var currentStep = noSteps && 1 || (typeof current === 'number' && current > 0 ? current : index + 1);
var totalSteps = noSteps && 1 || (typeof total === 'number' && total > 0 ? total : totalPanels);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Steps["default"], {
className: _WizardPanelsModule["default"].steps,
current: currentStep,
slot: "slotAbove",
total: totalSteps
});
}
},
render: function render(_ref8) {
var ariaLabel = _ref8['aria-label'],
children = _ref8.children,
footer = _ref8.footer,
index = _ref8.index,
nextButton = _ref8.nextButton,
nextButtonVisibility = _ref8.nextButtonVisibility,
noAnimation = _ref8.noAnimation,
noSubtitle = _ref8.noSubtitle,
onNextClick = _ref8.onNextClick,
onPrevClick = _ref8.onPrevClick,
onTransition = _ref8.onTransition,
onWillTransition = _ref8.onWillTransition,
prevButton = _ref8.prevButton,
prevButtonVisibility = _ref8.prevButtonVisibility,
reverseTransition = _ref8.reverseTransition,
steps = _ref8.steps,
subtitle = _ref8.subtitle,
title = _ref8.title,
totalPanels = _ref8.totalPanels,
rest = _objectWithoutProperties(_ref8, _excluded);
delete rest.current;
delete rest.noSteps;
delete rest.total;
var isPrevButtonVisible = prevButtonVisibility === 'always' || prevButtonVisibility === 'auto' && index !== 0;
var isNextButtonVisible = nextButtonVisibility === 'always' || nextButtonVisibility === 'auto' && index < totalPanels - 1;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(DecoratedPanelBase, _objectSpread(_objectSpread({}, rest), {}, {
header: /*#__PURE__*/(0, _jsxRuntime.jsxs)(HeaderContainer, {
"aria-label": ariaLabel,
arranger: noAnimation ? null : _Panels2.CrossFadeArranger,
centered: true,
css: _WizardPanelsModule["default"],
noCloseButton: true,
noSubtitle: noSubtitle,
subtitle: subtitle,
title: title,
type: "wizard",
children: [steps, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panels2.NavigationButton, {
"aria-label": (0, _$L["default"])('Previous'),
backgroundOpacity: "transparent",
component: prevButton,
focusEffectIconOnly: true,
icon: "arrowlargeleft",
iconFlip: "auto",
minWidth: false,
onClick: onPrevClick,
slot: "slotBefore",
visible: isPrevButtonVisible
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panels2.NavigationButton, {
"aria-label": (0, _$L["default"])('Next'),
backgroundOpacity: "transparent",
component: nextButton,
focusEffectIconOnly: true,
icon: "arrowlargeright",
iconFlip: "auto",
iconPosition: "after",
minWidth: false,
onClick: onNextClick,
slot: "slotAfter",
visible: isNextButtonVisible
})]
}),
panelType: "wizard",
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Layout.Column, {
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
className: _WizardPanelsModule["default"].content,
children: children ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_ViewManager["default"], {
arranger: _Panels2.BasicArranger,
duration: 400,
onTransition: onTransition,
onWillTransition: onWillTransition,
noAnimation: noAnimation,
reverseTransition: reverseTransition,
children: children
}) : null
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
className: _WizardPanelsModule["default"].footer,
component: "footer",
shrink: true,
children: footer
}, index)]
})
}));
}
});
var WizardPanelsDecorator = exports.WizardPanelsDecorator = (0, _compose["default"])((0, _ForwardRef["default"])({
prop: 'componentRef'
}), (0, _Changeable["default"])({
prop: 'index'
}), (0, _Panels2.CancelDecorator)({
cancel: 'onChange',
shouldCancel: (0, _handle["default"])((0, _handle.forwardCustomWithPrevent)('onBack'), (0, _handle.not)((0, _handle.forProp)('noPrevButton', true)))
}), (0, _SpotlightContainerDecorator["default"])({
continue5WayHold: true,
// prefer any spottable within the panel body (content or footer) followed by header
defaultElement: [".".concat(_SpotlightContainerDecorator.spotlightDefaultClass), ".".concat(_WizardPanelsModule["default"].content, " *, .").concat(_WizardPanelsModule["default"].footer, " *"), 'header > *'],
enterTo: 'default-element'
}), (0, _I18nDecorator.I18nContextDecorator)({
rtlProp: 'rtl'
}), _Panels2.PanelsRouter, _Skinnable["default"]);
/**
* A WizardPanels that can step through different panels.
* Expects {@link sandstone/WizardPanels.Panel|WizardPanel} as children.
*
* @class WizardPanels
* @memberof sandstone/WizardPanels
* @extends sandstone/WizardPanels.WizardPanelsBase
* @mixes ui/Changeable.Changeable
* @ui
* @public
*/
var WizardPanels = exports.WizardPanels = WizardPanelsDecorator(WizardPanelsBase);
/**
* Called when the back button is pressed.
*
* If `ev.preventDefault` is called, `WizardPanels` will not process the event further. If it is
* not called, the index of the panel will be decremented unless `noPrevButton` is set.
*
* @name onBack
* @memberof sandstone/WizardPanels.WizardPanels.prototype
* @type {Function}
*/
var _default = exports["default"] = WizardPanels;