ordering.ts 813 B

123456789101112131415161718192021
  1. import type { ICommandSection } from 'ui-patterns/CommandMenu/internal/types'
  2. const DEFAULT_PRIORITY = 10
  3. /**
  4. * Order sections in the command menu by a numbered priority. The lower the
  5. * number, the higher the priority.
  6. *
  7. * Specify the priority when creating or updating the section by passing the
  8. * option `{ sectionMeta: { priority: number } }`.
  9. *
  10. * The priority rankings are roughly as follows:
  11. * 1. Super important, stick to top. Reserved for special cases.
  12. * 2. We want to highlight this and encourage people to use it.
  13. * 3. Easy access for most important features/commands.
  14. */
  15. export function orderCommandSectionsByPriority(sections: Array<ICommandSection>) {
  16. return sections
  17. .slice()
  18. .sort((a, b) => (a.meta?.priority ?? DEFAULT_PRIORITY) - (b.meta?.priority ?? DEFAULT_PRIORITY))
  19. }