Skip to content

Commit 856762c

Browse files
Merge pull request #28734 from storybookjs/valentin/disable-save-from-controls
Controls: Add disableSave parameter
2 parents 1633942 + 7452e1e commit 856762c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

code/addons/controls/src/ControlsPanel.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface ControlsParameters {
3434
sort?: SortType;
3535
expanded?: boolean;
3636
presetColors?: PresetColor[];
37+
disableSaveFromUI?: boolean;
3738
}
3839

3940
interface ControlsPanelProps {
@@ -46,7 +47,12 @@ export const ControlsPanel = ({ saveStory, createStory }: ControlsPanelProps) =>
4647
const [args, updateArgs, resetArgs, initialArgs] = useArgs();
4748
const [globals] = useGlobals();
4849
const rows = useArgTypes();
49-
const { expanded, sort, presetColors } = useParameter<ControlsParameters>(PARAM_KEY, {});
50+
const {
51+
expanded,
52+
sort,
53+
presetColors,
54+
disableSaveFromUI = false,
55+
} = useParameter<ControlsParameters>(PARAM_KEY, {});
5056
const { path, previewInitialized } = useStorybookState();
5157

5258
// If the story is prepared, then show the args table
@@ -84,9 +90,10 @@ export const ControlsPanel = ({ saveStory, createStory }: ControlsPanelProps) =>
8490
sort={sort}
8591
isLoading={isLoading}
8692
/>
87-
{hasControls && hasUpdatedArgs && global.CONFIG_TYPE === 'DEVELOPMENT' && (
88-
<SaveStory {...{ resetArgs, saveStory, createStory }} />
89-
)}
93+
{hasControls &&
94+
hasUpdatedArgs &&
95+
global.CONFIG_TYPE === 'DEVELOPMENT' &&
96+
disableSaveFromUI !== true && <SaveStory {...{ resetArgs, saveStory, createStory }} />}
9097
</AddonWrapper>
9198
);
9299
};

docs/essentials/controls.mdx

+12
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ You can also update a control's value, then save the changes to the story. The s
260260

261261
<Video src="../_assets/get-started/edit-story-from-controls-optimized.mp4" />
262262

263+
### Disable creating and editing of stories
264+
265+
If you don't want to allow the creation or editing of stories from the Controls panel, you can disable this feature by setting the `disableSaveFromUI` parameter to `true` in the `parameters.controls` parameter in your `.storybook/preview.js` file.
266+
263267
## Configuration
264268

265269
The Controls addon can be configured in two ways:
@@ -484,3 +488,11 @@ Specifies how the controls are sorted.
484488
* **none**: Unsorted, displayed in the same order the arg types are processed in
485489
* **alpha**: Sorted alphabetically, by the arg type's name
486490
* **requiredFirst**: Same as `alpha`, with any required arg types displayed first
491+
492+
#### `disableSaveFromUI`
493+
494+
Type: `boolean`
495+
496+
Default: `false`
497+
498+
Disable the ability to create or edit stories from the Controls panel.

0 commit comments

Comments
 (0)