Replies: 4 comments 6 replies
-
Nice idea! A few thoughts:
I had to read this three times, but I think I understand now. 😅 I agree with this: "If you're overriding DocsStory, you are responsible for all the direct children to be your custom implementation too." To make this easier, could the implementation of this feature expose the custom implementation (which falls back to the default) to be able to use? e.g. function CustomDocsStory({ blocks }) {
const { Description } = blocks
return (
// Bunch of other stuff
<Description />
)
} Or make it a hook: import { useBlocks } from '@storybook/blocks'
function CustomDocsStory() {
const { Description } = useBlocks
return (
// Bunch of other stuff
<Description />
)
}
I also prefer this API (option 2).
Unless we feel strongly that we will be adding such options in the future, I prefer keeping Btw, related to my suggestion above, could the implementation change to: parameters: {
docs: {
page: ({ blocks }) => {
const { Title, Subtitle, Description, Primary, Controls, Stories } = blocks
return (
<Title />
// ...
)
}
}
} Where |
Beta Was this translation helpful? Give feedback.
-
@JReinhold did you think about using |
Beta Was this translation helpful? Give feedback.
-
Nice feature and excellent writeup. Seems like you're leaning towards I'm also concerned with growing our surface area and constraining ourselves in unknown ways. But I can live with it. |
Beta Was this translation helpful? Give feedback.
-
Hi, I'd like to follow up on this RFC based on this Twitter exchange. I documented my use case here (- hide all I proposed a solution that matches this RFC and basically used the same API as "Proposed API 1.". (This seemed more natural to me as it matches how you override MDX components.) But I'd also be happy to support in contributing to "Proposed API 2.". For the time being I'd keep |
Beta Was this translation helpful? Give feedback.
-
Status: in-review; championed by @JReinhold
Summary
This RFC is a proposal to make it possible to override individual blocks in the autodocs page, without having to override and re-implement the whole page. Blocks will be overridable via parameters, similar to how the docs page and container is overridable today.
Problem Statement
Sometimes users want to override just a portion of the autodocs page, but overall keep the same content. Examples include:
To eg. change the Description today, the user has to go through a somewhat cumbersome process:
parameters.docs.page
- most likely inpreview.js
Non-goals
DocsStory
it's direct childDescription
, we shouldn't try to get the customDescription
to work. If you're overridingDocsStory
, you are responsible for all the direct children to be your custom implementation too. (Although non-direct descendants likeStories
->Description
should work)Implementation
Similar to how you can override the default docs page and container at
parameters.docs.page
andparameters.docs.container
, I propose a solution that allows you to override the individual blocks in an autodocs via parameters.So if you wanted to have a custom description, you would only override that, and not the full tree of the docs page:
The following blocks would be valid to override:
Proposed API
I can come up with 2 different APIs for this:
Possible property names (we should choose one):
blocks
components
- We already use this today to override MDX components (unsupported)templates
- if you're writing them with MDX, this might match the mental modeloverrides
- similar to MDX2 APII feel this API is more closely aligned with our existing API, and I'm leaning towards this. A minor thing to consider here is that
parameters.docs.description.component
is already a property, so we wouldn't be able to usecomponent
as a prop name there.Docs Page and Container overrides
Irregardless of which API we choose, we need to decide what to do abut the existing functionality for overriding the Docs page and container at
parameters.docs.page|container
, as it wouldn't be consistent with overriding the other blocks. There are multiple possibilities here as well:parameters.docs.page
as-is.parameters.docs.blocks.page
orparameters.docs.page.block
The current API is problematic if we want to support adding options to the docs page/container at some point in the future. Eg. you can't at support for
parameters.docs.page.rightAligned
becauseparameters.docs.page
is already supposed to be a function.Prior Art
As mentioned it's already possible to override the docs page and container, implemented here: https://github.com/storybookjs/storybook/blob/next/code/ui/blocks/src/blocks/Docs.tsx
See https://storybook.js.org/docs/react/writing-docs/autodocs
This is similar to what fwoosh supports https://fwoo.sh/docs/Theming-Introduction#component-overrides
Deliverables
Not planned yet.
Risks
Unresolved Questions
Alternatives considered / Abandoned Ideas
No response
Beta Was this translation helpful? Give feedback.
All reactions