I have all Storybook stories nested under a “Docs” header. Every component gets a README mdx file, then as many stories as necessary. I would like for the README to always appear first in the navigation, then stories can be sorted as they are naturally.
This is my desired sort:
Docs
│
├─ Button
│ │
│ ├─ README
│ ├─ Button Story One
│ ├─ Button Story Two
│ └─ Button Story One
│
└─ Grid
│
├─ README
│
├─ Column
│ │
│ ├─ README
│ ├─ Column Story One
│ ├─ Column Story Two
│ └─ Column Story Three
│
└─ Row
│
├─ README
├─ Row Story One
├─ Row Story Two
└─ Row Story Three
You’ll notice there are 3 levels, but depending on the complexity of the component there may be as many as 4 levels, each with a README.
Is this custom sorting possible? If so, how?
This is the recommended sorting algorithm:
return a[1].kind === b[1].kind ? 0 : a[1].id.localeCompare(b[1].id, undefined, { numeric: true });
Where a[1] and b[1] are objects with the following structure:
{
"id": "docs-grid-column-examples--default-story",
"kind": "Docs/Grid/Column/Examples",
"name": "default",
"story": "default"
}