Addon-docs: Extract SetValueButton shared component from control components#34263
Addon-docs: Extract SetValueButton shared component from control components#34263mixelburg wants to merge 7 commits into
Conversation
…components The 'Set X' button pattern (rendered when a control value is undefined) was duplicated verbatim across four control files: Boolean, Number, Text, and Object. The only differences were the button label and the onClick handler. Extract a shared SetValueButton component to eliminate the repetition. As a side effect, Object's button now consistently uses variant='outline' and size='medium', matching the other three controls. Closes storybookjs#34211
📝 WalkthroughWalkthroughReplaces inline control-setter buttons in Boolean, Number, Object, and Text controls with a new exported Changes
Sequence Diagram(s)(Skipped — changes are straightforward UI rendering swaps and a small new helper; no new multi-component control flow requiring a sequence diagram.) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRsThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
JReinhold
left a comment
There was a problem hiding this comment.
Thanks. 🙏 Added a few suggestions.
- Move SetValueButton component directly into helpers.tsx (renamed from .ts) - Replace label prop with children for more idiomatic React composition - Update all consumers (Boolean, Object, Text, Number) to use merged import - Delete separate SetValueButton.tsx file Addresses review feedback from JReinhold on storybookjs#34263
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@code/addons/docs/src/blocks/controls/Text.tsx`:
- Line 8: The relative import of helper symbols getControlId and SetValueButton
in Text.tsx must include the explicit file extension; update the import
statement for './helpers' to include the correct extension that matches the
helpers module (e.g., './helpers.ts' or './helpers.tsx') so the import of
getControlId and SetValueButton uses an explicit extension per repo rules.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 66232d3d-25a0-4bf0-8fec-ca45267b9707
📒 Files selected for processing (5)
code/addons/docs/src/blocks/controls/Boolean.tsxcode/addons/docs/src/blocks/controls/Number.tsxcode/addons/docs/src/blocks/controls/Object.tsxcode/addons/docs/src/blocks/controls/Text.tsxcode/addons/docs/src/blocks/controls/helpers.tsx
✅ Files skipped from review due to trivial changes (1)
- code/addons/docs/src/blocks/controls/Object.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
- code/addons/docs/src/blocks/controls/Number.tsx
- code/addons/docs/src/blocks/controls/Boolean.tsx
| import { styled } from 'storybook/theming'; | ||
|
|
||
| import { getControlId, getControlSetterButtonId } from './helpers'; | ||
| import { getControlId, SetValueButton } from './helpers'; |
There was a problem hiding this comment.
Use explicit extension for this relative import.
Line 8 should include the file extension to match repository import rules.
Suggested fix
-import { getControlId, SetValueButton } from './helpers';
+import { getControlId, SetValueButton } from './helpers.tsx';As per coding guidelines: **/*.{ts,tsx,js,jsx} requires explicit file extensions for relative code imports/exports.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { getControlId, SetValueButton } from './helpers'; | |
| import { getControlId, SetValueButton } from './helpers.tsx'; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@code/addons/docs/src/blocks/controls/Text.tsx` at line 8, The relative import
of helper symbols getControlId and SetValueButton in Text.tsx must include the
explicit file extension; update the import statement for './helpers' to include
the correct extension that matches the helpers module (e.g., './helpers.ts' or
'./helpers.tsx') so the import of getControlId and SetValueButton uses an
explicit extension per repo rules.
Package BenchmarksCommit: No significant changes detected, all good. 👏 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@code/addons/docs/src/blocks/controls/Object.tsx`:
- Line 11: The import statement in Object.tsx uses a bare relative path; update
it to include the explicit file extension per repo rules by importing from the
helpers file with its extension (e.g., replace the current import of
getControlId and SetValueButton from './helpers' with './helpers.ts' or
'./helpers.tsx' as appropriate) so the symbols getControlId and SetValueButton
are resolved with an explicit extension.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: efe2c828-f29b-4106-aa0f-7623bc44f703
📒 Files selected for processing (5)
code/addons/docs/src/blocks/controls/Boolean.tsxcode/addons/docs/src/blocks/controls/Number.tsxcode/addons/docs/src/blocks/controls/Object.tsxcode/addons/docs/src/blocks/controls/Text.tsxcode/addons/docs/src/blocks/controls/helpers.test.ts
✅ Files skipped from review due to trivial changes (1)
- code/addons/docs/src/blocks/controls/helpers.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- code/addons/docs/src/blocks/controls/Boolean.tsx
- code/addons/docs/src/blocks/controls/Number.tsx
| import { styled, useTheme } from 'storybook/theming'; | ||
|
|
||
| import { getControlId, getControlSetterButtonId } from './helpers'; | ||
| import { getControlId, SetValueButton } from './helpers'; |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
Use explicit extension for this relative import.
The import path ./helpers should include the file extension to match repository import rules.
Suggested fix
-import { getControlId, SetValueButton } from './helpers';
+import { getControlId, SetValueButton } from './helpers.tsx';As per coding guidelines: **/*.{ts,tsx,js,jsx} requires "explicit file extensions for relative code imports and exports in TypeScript source, such as './foo.ts' or './bar.tsx'".
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { getControlId, SetValueButton } from './helpers'; | |
| import { getControlId, SetValueButton } from './helpers.tsx'; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@code/addons/docs/src/blocks/controls/Object.tsx` at line 11, The import
statement in Object.tsx uses a bare relative path; update it to include the
explicit file extension per repo rules by importing from the helpers file with
its extension (e.g., replace the current import of getControlId and
SetValueButton from './helpers' with './helpers.ts' or './helpers.tsx' as
appropriate) so the symbols getControlId and SetValueButton are resolved with an
explicit extension.
Summary
The 'Set X' button pattern was duplicated across four control components in
code/addons/docs/src/blocks/controls/. All four shared the sameButtonprops (ariaLabel={false},variant='outline',size='medium') with only theonClickhandler and label text differing.Closes #34211
Changes
SetValueButton.tsx— a small shared component that acceptsname,storyId,label,onClick, anddisabled<SetValueButton />Bonus: Object's button now consistently uses
variant='outline'andsize='medium', matching the other three controls (previously these props were missing from the Object control's button).Impact
Any future change to the button's appearance, accessibility attributes, or sizing now only needs to be made in one place.
Summary by CodeRabbit