Skip to content

Instantly share code, notes, and snippets.

@bmingles
Last active February 17, 2022 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmingles/dd43907aacf1e7a4af5cd4f0c63d0cd0 to your computer and use it in GitHub Desktop.
Save bmingles/dd43907aacf1e7a4af5cd4f0c63d0cd0 to your computer and use it in GitHub Desktop.
Storybook - Custom Story Sorting
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