UNPKG

@procraft/widget-order

Version:

Order widget for landing

154 lines 6.28 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Subscriptions = void 0; const react_1 = __importStar(require("react")); // import ReactDecliner from 'react-decliner' const RadioGroup_1 = require("../../components/RadioGroup"); const Typography_1 = __importDefault(require("../../components/Typography")); const styles_1 = require("./styles"); /** * Подписки */ const Subscriptions = (_a) => { // const subscriptions = useMemo(() => item.subscriptions, [item.subscriptions]) var { item } = _a, // subscription, // onChangeSubscription, other = __rest(_a, ["item"]); const [subscriptionIndex] = (0, react_1.useState)(0); item; const onChangeIndex = (0, react_1.useCallback)((value) => { value; // value && subscriptionIndexSetter(parseInt(value)) // const item = // (value && subscriptions && subscriptions[parseInt(value)]) || null // onChangeSubscription(item) }, []); return (0, react_1.useMemo)(() => { /** * Если нет ни одной подписки, ничего не выводим */ // if (!subscriptions?.length) { // return null // } // let subscriptionIndex = // subscription && subscriptions // ? subscriptions.findIndex( // (n) => // n.period.unit === subscription.period.unit && // n.period.amount === subscription.period.amount // ) // : undefined // /** // * Если не найден элемент, то указываем нулевой индекс, чтобы вывести первый элемент // */ // if (subscriptionIndex === undefined || subscriptionIndex === -1) { // subscriptionIndex = 0 // } const items = []; // subscriptions.forEach((n, index) => { // // const checked = subscriptionIndex === index // const periodAmount = n.period.amount // if (!periodAmount) { // return null // } // let one = '' // let two = '' // let many = '' // switch (n.period.unit) { // case TimeUnit.DAYS: // one = 'день' // two = 'дня' // many = 'дней' // break // case TimeUnit.HOURS: // one = 'час' // two = 'часа' // many = 'часов' // break // case TimeUnit.MINUTES: // one = 'минута' // two = 'минуты' // many = 'минут' // break // case TimeUnit.MONTHS: // one = 'месяц' // two = 'месяца' // many = 'месяцев' // break // case TimeUnit.WEEKS: // one = 'неделя' // two = 'недели' // many = 'недель' // break // } // // return ( // // <div key={index}> // // <input type="radio" checked={checked} onChange={onChange} /> // // {periodAmount === 1 ? '' : periodAmount + ' '} // // <ReactDecliner num={periodAmount} one={one} two={two} many={many} /> // // </div> // // ) // items.push({ // uid: index, // label: ( // <> // <Typography // variant="grey-sm" // component="label" // className="altItemText" // > // {periodAmount === 1 ? '' : periodAmount + ' '} // <ReactDecliner // num={periodAmount} // one={one} // two={two} // many={many} // /> // </Typography> // </> // ), // }) // }) const dates = (react_1.default.createElement(RadioGroup_1.RadioGroup, { items: items, value: subscriptionIndex, onChangeIndex: onChangeIndex })); return (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement(styles_1.SubscriptionsStyled, Object.assign({ variant: "white" }, other), react_1.default.createElement(Typography_1.default, { className: "subscriptions--title" }, "\u0421\u0440\u043E\u043A\u0438 \u043F\u043E\u0434\u043F\u0438\u0441\u043A\u0438"), dates))); }, [onChangeIndex, other, subscriptionIndex]); }; exports.Subscriptions = Subscriptions; //# sourceMappingURL=index.js.map