Skip to content

Commit 3e9e4d6

Browse files
refactor(docs): extract ControlsTables component from render helper
Replace renderControlsTables with a ControlsTables FC so table rendering follows the same component pattern as the rest of the Controls block. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 176296f commit 3e9e4d6

1 file changed

Lines changed: 33 additions & 32 deletions

File tree

code/addons/docs/src/blocks/blocks/Controls.tsx

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ type ControlsInteractiveState = {
4242
resetArgs: ReturnType<typeof useArgs>[2];
4343
};
4444

45+
type ControlsTablesProps = ControlsInteractiveState & {
46+
mainName?: string;
47+
mainRows: StrictArgTypes;
48+
subcomponentRows: Record<string, StrictArgTypes>;
49+
include?: PropDescriptor;
50+
exclude?: PropDescriptor;
51+
sort?: SortType;
52+
storyId: string;
53+
};
54+
4555
function getControlsFilterProps(story: PreparedStory, props: ControlsProps): ControlsParameters {
4656
const controlsParameters = story.parameters.docs?.controls || ({} as ControlsParameters);
4757

@@ -66,7 +76,7 @@ function useControlsInteractiveState(
6676
return { controlsId, args, globals, updateArgs, resetArgs };
6777
}
6878

69-
function renderControlsTables({
79+
const ControlsTables: FC<ControlsTablesProps> = ({
7080
mainName = 'Story',
7181
mainRows,
7282
subcomponentRows,
@@ -79,20 +89,7 @@ function renderControlsTables({
7989
globals,
8090
updateArgs,
8191
resetArgs,
82-
}: {
83-
mainName?: string;
84-
mainRows: StrictArgTypes;
85-
subcomponentRows: Record<string, StrictArgTypes>;
86-
include?: PropDescriptor;
87-
exclude?: PropDescriptor;
88-
sort?: SortType;
89-
storyId: string;
90-
controlsId: string;
91-
args: Args;
92-
globals: Globals;
93-
updateArgs: ControlsInteractiveState['updateArgs'];
94-
resetArgs: ControlsInteractiveState['resetArgs'];
95-
}) {
92+
}) => {
9693
const filteredMainRows = filterArgTypes(mainRows, include, exclude);
9794

9895
if (Object.keys(subcomponentRows).length === 0) {
@@ -139,7 +136,7 @@ function renderControlsTables({
139136
controlsId={controlsId}
140137
/>
141138
);
142-
}
139+
};
143140

144141
const LegacyControls: FC<ControlsStoryProps> = ({ story, context, ...props }) => {
145142
const { parameters, argTypes, component, subcomponents } = story;
@@ -150,14 +147,16 @@ const LegacyControls: FC<ControlsStoryProps> = ({ story, context, ...props }) =>
150147
return null;
151148
}
152149

153-
return renderControlsTables({
154-
mainName: getComponentName(component) || 'Story',
155-
mainRows: argTypes,
156-
subcomponentRows: extractSubcomponentArgTypes(subcomponents, parameters),
157-
...filterProps,
158-
storyId: story.id,
159-
...interactiveState,
160-
});
150+
return (
151+
<ControlsTables
152+
mainName={getComponentName(component) || 'Story'}
153+
mainRows={argTypes}
154+
subcomponentRows={extractSubcomponentArgTypes(subcomponents, parameters)}
155+
{...filterProps}
156+
storyId={story.id}
157+
{...interactiveState}
158+
/>
159+
);
161160
};
162161

163162
const DocgenServiceControls: FC<ControlsStoryProps> = ({ story, context, ...props }) => {
@@ -176,14 +175,16 @@ const DocgenServiceControls: FC<ControlsStoryProps> = ({ story, context, ...prop
176175
return null;
177176
}
178177

179-
return renderControlsTables({
180-
mainName: getComponentName(component) ?? serviceRows.serviceComponentName,
181-
mainRows: serviceRows.mainRows,
182-
subcomponentRows: serviceRows.subcomponentRows,
183-
...filterProps,
184-
storyId: story.id,
185-
...interactiveState,
186-
});
178+
return (
179+
<ControlsTables
180+
mainName={getComponentName(component) ?? serviceRows.serviceComponentName}
181+
mainRows={serviceRows.mainRows}
182+
subcomponentRows={serviceRows.subcomponentRows}
183+
{...filterProps}
184+
storyId={story.id}
185+
{...interactiveState}
186+
/>
187+
);
187188
};
188189

189190
const ControlsImpl: FC<ControlsProps> = (props) => {

0 commit comments

Comments
 (0)