@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
1 lines • 1.77 kB
Source Map (JSON)
{"version":3,"file":"get-cascader-columns.cjs","names":[],"sources":["../../../src/components/Cascader/get-cascader-columns.ts"],"sourcesContent":["import type { CascaderOption } from './Cascader';\n\nexport function cascaderOptionHasChildren(option: CascaderOption): boolean {\n return Array.isArray(option.children) && option.children.length > 0;\n}\n\nexport function findCascaderOption(\n options: CascaderOption[],\n value: string\n): CascaderOption | undefined {\n return options.find((option) => option.value === value);\n}\n\nexport function getCascaderColumns(\n data: CascaderOption[],\n activePath: string[]\n): CascaderOption[][] {\n const columns: CascaderOption[][] = [data];\n let level = data;\n\n for (let index = 0; index < activePath.length; index += 1) {\n const node = findCascaderOption(level, activePath[index]);\n\n if (!node) {\n break;\n }\n\n const isLast = index === activePath.length - 1;\n\n if (Array.isArray(node.children) && node.children.length > 0) {\n if (!isLast) {\n columns.push(node.children);\n level = node.children;\n }\n // The deepest highlighted option is intentionally not expanded\n } else {\n break;\n }\n }\n\n return columns;\n}\n"],"mappings":";;AAEA,SAAgB,0BAA0B,QAAiC;CACzE,OAAO,MAAM,QAAQ,OAAO,QAAQ,KAAK,OAAO,SAAS,SAAS;AACpE;AAEA,SAAgB,mBACd,SACA,OAC4B;CAC5B,OAAO,QAAQ,MAAM,WAAW,OAAO,UAAU,KAAK;AACxD;AAEA,SAAgB,mBACd,MACA,YACoB;CACpB,MAAM,UAA8B,CAAC,IAAI;CACzC,IAAI,QAAQ;CAEZ,KAAK,IAAI,QAAQ,GAAG,QAAQ,WAAW,QAAQ,SAAS,GAAG;EACzD,MAAM,OAAO,mBAAmB,OAAO,WAAW,MAAM;EAExD,IAAI,CAAC,MACH;EAGF,MAAM,SAAS,UAAU,WAAW,SAAS;EAE7C,IAAI,MAAM,QAAQ,KAAK,QAAQ,KAAK,KAAK,SAAS,SAAS;OACrD,CAAC,QAAQ;IACX,QAAQ,KAAK,KAAK,QAAQ;IAC1B,QAAQ,KAAK;GACf;SAGA;CAEJ;CAEA,OAAO;AACT"}