UNPKG

@codinglane/dropdown

Version:
51 lines (50 loc) 3.59 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Group = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const Atoms = __importStar(require("../../../../atoms")); const Group = (_a) => { var { id, grouped, selected, favorize, onOptionClick, onFavorize } = _a, props = __rest(_a, ["id", "grouped", "selected", "favorize", "onOptionClick", "onFavorize"]); return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: grouped.map((group, index) => { var _a, _b, _c; return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'dropdown-grouping', "data-testid": (_a = props['data-testid']) === null || _a === void 0 ? void 0 : _a.concat(group.name) }, { children: !group.isParent ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Atoms.Label, { label: group.name, "data-testid": (_b = props['data-testid']) === null || _b === void 0 ? void 0 : _b.concat('-label').concat(group.name) }), group.options.map((option) => { var _a; return ((0, jsx_runtime_1.jsx)(Atoms.Option, { className: 'group-option', onClick: onOptionClick, id: id === null || id === void 0 ? void 0 : id.concat('option').concat(option.value), selected: selected, option: option, favorites: favorize, isFavorite: option.favorite, onFavorize: onFavorize, "data-testid": (_a = props['data-testid']) === null || _a === void 0 ? void 0 : _a.concat('-group-option').concat(option.value) }, option.value)); })] })) : ((0, jsx_runtime_1.jsx)(exports.Group, { grouped: group.options, onOptionClick: onOptionClick, onFavorize: onFavorize, id: id === null || id === void 0 ? void 0 : id.concat('option'.concat(group.name)), favorize: favorize, selected: selected, "data-testid": (_c = props['data-testid']) === null || _c === void 0 ? void 0 : _c.concat(group.name) }, group.name)) }), group.name.concat(`-${index}`))); }) })); }; exports.Group = Group;