UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 2.12 kB
{"version":3,"file":"get-parsed-combobox-data.cjs","names":[],"sources":["../../../../src/components/Combobox/get-parsed-combobox-data/get-parsed-combobox-data.ts"],"sourcesContent":["import { Primitive } from '../../../core';\nimport {\n ComboboxData,\n ComboboxGenericData,\n ComboboxGenericItem,\n ComboboxItem,\n ComboboxItemGroup,\n ComboboxParsedItem,\n ComboboxParsedItemGroup,\n} from '../Combobox.types';\n\nfunction parseItem<Value extends Primitive = string>(\n item:\n | Primitive\n | ComboboxItem<Value>\n | ComboboxGenericItem<Value>\n | ComboboxItemGroup<Value | ComboboxGenericItem<Value> | ComboboxItem<Value>>\n): ComboboxItem<Value> | ComboboxParsedItemGroup<Value> {\n if (typeof item === 'string') {\n return { value: item as Value, label: item };\n }\n\n if (typeof item === 'object' && 'value' in item && !('label' in item)) {\n return { value: item.value, label: `${item.value}`, disabled: item.disabled };\n }\n\n if (typeof item === 'object' && 'group' in item) {\n return {\n group: item.group,\n items: item.items.map((i) => parseItem<Value>(i) as ComboboxItem<Value>),\n };\n }\n\n if (typeof item === 'number' || typeof item === 'bigint' || typeof item === 'boolean') {\n return { value: item as Value, label: `${item}` };\n }\n\n return item;\n}\n\nexport function getParsedComboboxData<Value extends Primitive = string>(\n data: ComboboxData<Value> | ComboboxGenericData<Value> | undefined\n): ComboboxParsedItem<Value>[] {\n if (!data) {\n return [];\n }\n\n return data.map((item) => parseItem<Value>(item));\n}\n"],"mappings":";;AAWA,SAAS,UACP,MAKsD;AACtD,KAAI,OAAO,SAAS,SAClB,QAAO;EAAE,OAAO;EAAe,OAAO;EAAM;AAG9C,KAAI,OAAO,SAAS,YAAY,WAAW,QAAQ,EAAE,WAAW,MAC9D,QAAO;EAAE,OAAO,KAAK;EAAO,OAAO,GAAG,KAAK;EAAS,UAAU,KAAK;EAAU;AAG/E,KAAI,OAAO,SAAS,YAAY,WAAW,KACzC,QAAO;EACL,OAAO,KAAK;EACZ,OAAO,KAAK,MAAM,KAAK,MAAM,UAAiB,EAAE,CAAwB;EACzE;AAGH,KAAI,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY,OAAO,SAAS,UAC1E,QAAO;EAAE,OAAO;EAAe,OAAO,GAAG;EAAQ;AAGnD,QAAO;;AAGT,SAAgB,sBACd,MAC6B;AAC7B,KAAI,CAAC,KACH,QAAO,EAAE;AAGX,QAAO,KAAK,KAAK,SAAS,UAAiB,KAAK,CAAC"}