Skip to content

Commit aa591c3

Browse files
Controls: Add disableSave parameter
1 parent 1633942 commit aa591c3

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

code/addons/controls/src/ControlsPanel.tsx

+13-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+
disableSave?: 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+
disableSave = false,
55+
} = useParameter<ControlsParameters>(PARAM_KEY, {});
5056
const { path, previewInitialized } = useStorybookState();
5157

5258
// If the story is prepared, then show the args table
@@ -70,6 +76,8 @@ export const ControlsPanel = ({ saveStory, createStory }: ControlsPanelProps) =>
7076
[args, initialArgs]
7177
);
7278

79+
console.log({ disableSave });
80+
7381
return (
7482
<AddonWrapper>
7583
<ArgsTable
@@ -84,9 +92,10 @@ export const ControlsPanel = ({ saveStory, createStory }: ControlsPanelProps) =>
8492
sort={sort}
8593
isLoading={isLoading}
8694
/>
87-
{hasControls && hasUpdatedArgs && global.CONFIG_TYPE === 'DEVELOPMENT' && (
88-
<SaveStory {...{ resetArgs, saveStory, createStory }} />
89-
)}
95+
{hasControls &&
96+
hasUpdatedArgs &&
97+
global.CONFIG_TYPE === 'DEVELOPMENT' &&
98+
disableSave !== true && <SaveStory {...{ resetArgs, saveStory, createStory }} />}
9099
</AddonWrapper>
91100
);
92101
};

docs/essentials/controls.mdx

+14
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ 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 `disableSave` parameter to `true` in the `parameters.controls` parameter in your `.storybook/preview.js` file.
266+
267+
{/* prettier-ignore-start */}
268+
263269
## Configuration
264270

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

0 commit comments

Comments
 (0)