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