Last active
February 17, 2022 22:24
-
-
Save bmingles/dd43907aacf1e7a4af5cd4f0c63d0cd0 to your computer and use it in GitHub Desktop.
Storybook - Custom Story Sorting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const parameters = { | |
actions: { argTypesRegex: '^on[A-Z].*' }, | |
options: { | |
storySort, | |
}, | |
} | |
/** Force example stories to sort last */ | |
function forceExampleLast(id) { | |
return (id.startsWith('example-') ? '' : '_') + id | |
} | |
function storySort(a, b) { | |
// within category, just use default sort | |
if (a[1].kind === b[1].kind) { | |
return 0 | |
} | |
const aId = forceExampleLast(a[1].id) | |
const bId = forceExampleLast(b[1].id) | |
return aId.localeCompare(bId, { numeric: true }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment