Skip to content

feat(storybook): document data attributes and classes on docs pages - #42

Open
mainframev wants to merge 3 commits into
masterfrom
mainframev/storybook-styling-metadata
Open

mainframev wants to merge 3 commits into
masterfrom
mainframev/storybook-styling-metadata

Conversation

@mainframev

Copy link
Copy Markdown
Owner

Previous Behavior

Docs pages show only the Props table. Slot class names (v9) and data-* attributes (headless) are not documented.

New Behavior

Docs pages render an API Reference with collapsible Props, Data attributes and Classes sections, matching the Fluent Modern Storybook. Family stories get one tab per component, like Props.

  • v9 (root .storybook, public-docsite-v9): Classes from each component's <component>ClassNames export (the convention enforced by the react-conformance component-has-static-classnames-object test).
  • Headless (headless stories, public-docsite-v9-headless): Data attributes from the data-* writes in component hooks, with inferred values, e.g. Button data-icon-position: "before" | "after".

How

  • @fluentui/scripts-storybook adds registerStylingMetadataRule. It registers a webpack pre loader on *.stories.tsx that reads the story's component/subcomponents, statically analyzes their source through the TypeScript compiler (resolved via tsconfig.base.json paths, no build needed) and injects parameters.__generatedStylingMetadata. Extraction problems are emitted as warnings and never fail the build. Port of the Fluent Modern loader.
  • @fluentui/react-storybook-addon renders the sections. Authored parameters.reactStorybookAddon.docs.{dataAttributes,classNames} override generated values; reactStorybookAddon.docs: false opts a story file out.

Known gaps

  • Writes on a local slot variable and attributes written by infrastructure (react-aria, tabster) are not listed. The headless build reports these as warnings (Tooltip/Popover data-arrow, Calendar day attributes).
  • All sections start collapsed, as in Fluent Modern.

Validation

  • scripts-storybook: jest, tsc and eslint pass. The tests cover fixtures and real headless and v9 Button/Accordion sources.
  • react-storybook-addon: jest, eslint and tsc pass for its sources.
  • Checked both docsites locally in storybook dev: v9 Button/Accordion show Props and Classes; headless Button/Accordion show Props and Data attributes.

Add registerStylingMetadataRule, a webpack pre loader that statically
analyzes the components a story documents and injects
parameters.__generatedStylingMetadata: v9 slot class names from the
<component>ClassNames export and headless data-* attributes with their
value domains. Extraction issues are reported as warnings and never
fail the build.
…s and classes

Show Props, Data attributes and Classes as collapsible API Reference
sections on the docs page, matching the Fluent Modern Storybook. Styling
sections render generated metadata, overridable through
parameters.reactStorybookAddon.docs.
v9 Storybooks document slot class names; the headless Storybook and
docsite document data attributes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant