util.ts 596 B

12345678910111213141516171819202122232425262728
  1. // @ts-nocheck
  2. import { isArray } from '@vue/shared'
  3. import type { Option, OptionGroup } from './select.types'
  4. export const flattenOptions = (options: Array<Option | OptionGroup>) => {
  5. const flattened = []
  6. options.forEach((option) => {
  7. if (isArray(option.options)) {
  8. flattened.push({
  9. label: option.label,
  10. isTitle: true,
  11. type: 'Group',
  12. })
  13. option.options.forEach((o: Option) => {
  14. flattened.push(o)
  15. })
  16. flattened.push({
  17. type: 'Group',
  18. })
  19. } else {
  20. flattened.push(option)
  21. }
  22. })
  23. return flattened
  24. }