@sberdevices/plasma-temple
Version:
SberDevices CanvasApp Templates.
203 lines (161 loc) • 11.1 kB
JavaScript
function _typeof(obj) { "@babel/helpers - typeof"; 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); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AssistantActionConfirmControls = AssistantActionConfirmControls;
exports.AssistantActionConfirmResult = exports.AssistantActionConfirmLabel = exports.AssistantActionConfirmDescription = void 0;
exports.AssistantActionConfirmResults = AssistantActionConfirmResults;
exports.AssistantActionConfirmWrapper = exports.AssistantActionConfirmTitle = void 0;
var _react = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("react"));
var _styledComponents = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("styled-components"));
var _plasmaUi = /*#__PURE__*/require("@sberdevices/plasma-ui");
var _plasmaTokens = /*#__PURE__*/require("@sberdevices/plasma-tokens");
var _utils = /*#__PURE__*/require("@sberdevices/plasma-ui/utils");
var _useFocusOnMount = /*#__PURE__*/require("../../hooks/useFocusOnMount");
var _deviceFamily = /*#__PURE__*/require("../../utils/deviceFamily");
var _excluded = ["children"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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 StyledList = /*#__PURE__*/(0, _styledComponents["default"])(_plasmaUi.Carousel).withConfig({
componentId: "plasma-temple__sc-1oz0z2n-0"
})(["box-sizing:border-box;width:916px;max-height:602px;padding:0 1rem 60px;mask-image:linear-gradient( 180deg,rgba(196,196,196,0.25) 0%,rgba(196,196,196,0.79) 37.25%,#c4c4c4 62.85%,rgba(196,196,196,0.15) 107.29% );user-select:none;outline:none;"]);
var AssistantActionConfirmWrapper = /*#__PURE__*/_styledComponents["default"].div.withConfig({
componentId: "plasma-temple__sc-1oz0z2n-1"
})(["display:flex;flex-direction:column;align-items:center;text-align:center;padding-top:2rem;", ""], /*#__PURE__*/(0, _utils.mediaQuery)('M', 2)( /*#__PURE__*/(0, _styledComponents.css)(["padding-top:1rem;"])));
exports.AssistantActionConfirmWrapper = AssistantActionConfirmWrapper;
var AssistantActionConfirmLabel = /*#__PURE__*/(0, _styledComponents["default"])(_plasmaUi.Body1).withConfig({
componentId: "plasma-temple__sc-1oz0z2n-2"
})(["color:", ";margin-bottom:8px;"], _plasmaTokens.primary);
exports.AssistantActionConfirmLabel = AssistantActionConfirmLabel;
var AssistantActionConfirmTitle = /*#__PURE__*/(0, _styledComponents["default"])(_plasmaUi.Headline1).withConfig({
componentId: "plasma-temple__sc-1oz0z2n-3"
})(["color:", ";margin-bottom:8px;"], _plasmaTokens.primary);
exports.AssistantActionConfirmTitle = AssistantActionConfirmTitle;
var AssistantActionConfirmDescription = /*#__PURE__*/(0, _styledComponents["default"])(_plasmaUi.Footnote1).withConfig({
componentId: "plasma-temple__sc-1oz0z2n-4"
})(["margin-top:2rem;color:", ";"], _plasmaTokens.secondary);
exports.AssistantActionConfirmDescription = AssistantActionConfirmDescription;
var mapDeviceToResult = {
sberBox: _plasmaUi.Headline1,
sberPortal: _plasmaUi.Headline2,
mobile: _plasmaUi.Headline2
};
var AssistantActionConfirmResult = /*#__PURE__*/(0, _styledComponents["default"])(mapDeviceToResult[_deviceFamily.deviceFamily]).withConfig({
componentId: "plasma-temple__sc-1oz0z2n-5"
})(["text-transform:capitalize;"]);
exports.AssistantActionConfirmResult = AssistantActionConfirmResult;
var StyledControlsWrapper = /*#__PURE__*/_styledComponents["default"].div.withConfig({
componentId: "plasma-temple__sc-1oz0z2n-6"
})(["display:flex;flex-direction:row;align-items:center;justify-content:center;margin-top:64px;"]);
var StyledButton = /*#__PURE__*/(0, _styledComponents["default"])(_plasmaUi.Button).withConfig({
componentId: "plasma-temple__sc-1oz0z2n-7"
})(["", " justify-content:center;"], function (_ref) {
var wide = _ref.wide;
if (wide) {
return {
marginTop: '24px',
width: '816px'
};
}
return {
marginLeft: '32px',
'&:first-child': {
marginLeft: 0
}
};
});
function AssistantActionConfirmControls(_ref2) {
var suggests = _ref2.suggests,
onConfirm = _ref2.onConfirm,
onReject = _ref2.onReject,
_ref2$confirmText = _ref2.confirmText,
confirmText = _ref2$confirmText === void 0 ? 'Да, всё верно' : _ref2$confirmText,
_ref2$rejectText = _ref2.rejectText,
rejectText = _ref2$rejectText === void 0 ? 'Нет, ввести другой' : _ref2$rejectText,
confirmDisable = _ref2.confirmDisable;
var mountRef = _react["default"].useRef(null);
(0, _useFocusOnMount.useFocusOnMount)(mountRef, {
delay: 250
});
return /*#__PURE__*/_react["default"].createElement(StyledControlsWrapper, null, /*#__PURE__*/_react["default"].createElement(StyledButton, {
disabled: confirmDisable,
view: "primary",
size: "s",
onClick: function onClick() {
return onConfirm(suggests[0]);
},
ref: !confirmDisable ? mountRef : null
}, confirmText), /*#__PURE__*/_react["default"].createElement(StyledButton, {
view: "secondary",
size: "s",
onClick: onReject,
ref: !confirmDisable ? null : mountRef
}, rejectText));
}
var StyledItem = /*#__PURE__*/(0, _styledComponents["default"])(_plasmaUi.CarouselItem).withConfig({
componentId: "plasma-temple__sc-1oz0z2n-8"
})(["display:inline-flex;"]);
var SelectItem = function SelectItem(_ref3) {
var children = _ref3.children,
props = _objectWithoutProperties(_ref3, _excluded);
return /*#__PURE__*/_react["default"].createElement(StyledItem, props, children);
};
function AssistantActionConfirmResults(_ref4) {
var suggests = _ref4.suggests,
onConfirm = _ref4.onConfirm,
onReject = _ref4.onReject,
labelFormatter = _ref4.labelFormatter;
var _React$useState = _react["default"].useState(0),
_React$useState2 = _slicedToArray(_React$useState, 2),
selectedIndex = _React$useState2[0],
setSelectedIndex = _React$useState2[1];
var mountRef = _react["default"].useRef(null);
var itemsToRender = _react["default"].useMemo(function () {
var list = suggests.map(function (item) {
var _labelFormatter;
return {
label: (_labelFormatter = labelFormatter === null || labelFormatter === void 0 ? void 0 : labelFormatter(item)) !== null && _labelFormatter !== void 0 ? _labelFormatter : String(item),
onClick: function onClick() {
return onConfirm(item);
}
};
});
if (typeof onReject === 'function') {
list.push({
label: 'Ничего не подходит',
onClick: onReject
});
}
return list;
}, [suggests, onConfirm, onReject, labelFormatter]);
(0, _useFocusOnMount.useFocusOnMount)(mountRef, {
delay: 250
});
return /*#__PURE__*/_react["default"].createElement(StyledList, {
axis: "y",
index: selectedIndex
}, itemsToRender.map(function (item, index) {
return /*#__PURE__*/_react["default"].createElement(SelectItem, null, /*#__PURE__*/_react["default"].createElement(StyledButton, {
key: item.label,
wide: true,
view: "secondary",
size: "l",
onClick: item.onClick,
onFocus: function onFocus() {
return setSelectedIndex(index);
},
ref: mountRef.current ? null : mountRef
}, item.label));
}));
}
//# sourceMappingURL=AssistantActionConfirm.js.map
;