Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storybook): implement argTypeEnhancers for improved Slot API docs rendering #33838

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

Hotell
Copy link
Contributor

@Hotell Hotell commented Feb 13, 2025

Previous Behavior

image

New Behavior

image

Leverages Storybook Arg enhancer hook to tweak ouput as needed without any changes necessary in v9 codebase ( not affecting consumers of v9 )

Related Issue(s)

@Hotell Hotell changed the title Sb/implement arg type enhancers for slot feat(storybook): implement argTypeEnhancers for nice UX for Slot API rendering Feb 13, 2025
Copy link

github-actions bot commented Feb 13, 2025

📊 Bundle size report

✅ No changes found

@fabricteam
Copy link
Collaborator

🕵 FluentUIV0 No visual regressions between this PR and main

Copy link

Pull request demo site: URL

@Hotell Hotell changed the title feat(storybook): implement argTypeEnhancers for nice UX for Slot API rendering feat(storybook): implement argTypeEnhancers for improved Slot API docs rendering Feb 13, 2025
const styles = useStyles();

const { component } = withSlotEnhancer(story);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task:

  • verify that this doesn't mutate story object as we don't wanna do that to prevent any unwanted side effects

@@ -219,7 +256,7 @@ export const FluentDocsPage = () => {
{videos && <VideoPreviews videos={videos} />}
</div>
<RenderPrimaryStory primaryStory={primaryStory} skipPrimaryStory={skipPrimaryStory} />
<RenderArgsTable primaryStory={primaryStory} hideArgsTable={hideArgsTable} />
<RenderArgsTable story={primaryStory} hideArgsTable={hideArgsTable} argTypes={primaryStoryContext.argTypes} />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these argTypes are properly transformed via preview enhance in preview.js although we cannot use them it seems

Task:

  • revert this argTypes prop change

@Hotell
Copy link
Contributor Author

Hotell commented Feb 14, 2025

@carlamntn please see comments and Task to follow-up/finish this PR

ty

@carlamntn carlamntn marked this pull request as ready for review February 27, 2025 09:50
@carlamntn carlamntn requested a review from a team as a code owner February 27, 2025 09:50
@carlamntn carlamntn requested review from a team as code owners February 27, 2025 09:50
@carlamntn carlamntn marked this pull request as draft February 27, 2025 10:15
all <code>aria-*</code> and <code>data-*</code> attributes, can be applied as native props on this
component.
</span>
{story.argTypes.as && story.argTypes.as?.type?.name === 'enum' && (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have here a repetition already - time to encapsulate this into separate component

Task:

  • create a local component with following API usage:
<AdditionalApiDocs>
 custom content
</AdditionalApiDocs>
  • render these components with extra info conditionaly
const hasArgAsProp = story.argTypes.as && story.argTypes.as?.type?.name === 'enum';
const hasArgSlotProp =  ???;

return 
{ hasArgAsProp ? <AdditionalApiDocs>
 custom content
</AdditionalApiDocs>: null }

{ hasArgSlotProp ? <AdditionalApiDocs>
 custom content
</AdditionalApiDocs>: null }

const RenderArgsTable = ({ hideArgsTable, primaryStory }: { primaryStory: PrimaryStory; hideArgsTable: boolean }) => {
const slotRegex = /as\?:\s*"([^"]+)"/;

function withSlotEnhancer(story: PreparedStory) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task:

  • tweak this function to get info if Slot was set

We can leverage this logic to flag if Slot was found and set.

Later on, this flag can be used as part of the API of this function to be leveraged later in conditional rendering of additional info component.

@carlamntn carlamntn marked this pull request as ready for review March 3, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[docs]: improve Storybook prop table for Slot<T> type
5 participants