Skip to content

Commit

Permalink
Controls: Add disableSave parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Jul 29, 2024
1 parent 1633942 commit aa591c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
17 changes: 13 additions & 4 deletions code/addons/controls/src/ControlsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface ControlsParameters {
sort?: SortType;
expanded?: boolean;
presetColors?: PresetColor[];
disableSave?: boolean;
}

interface ControlsPanelProps {
Expand All @@ -46,7 +47,12 @@ export const ControlsPanel = ({ saveStory, createStory }: ControlsPanelProps) =>
const [args, updateArgs, resetArgs, initialArgs] = useArgs();
const [globals] = useGlobals();
const rows = useArgTypes();
const { expanded, sort, presetColors } = useParameter<ControlsParameters>(PARAM_KEY, {});
const {
expanded,
sort,
presetColors,
disableSave = false,
} = useParameter<ControlsParameters>(PARAM_KEY, {});
const { path, previewInitialized } = useStorybookState();

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

console.log({ disableSave });

return (
<AddonWrapper>
<ArgsTable
Expand All @@ -84,9 +92,10 @@ export const ControlsPanel = ({ saveStory, createStory }: ControlsPanelProps) =>
sort={sort}
isLoading={isLoading}
/>
{hasControls && hasUpdatedArgs && global.CONFIG_TYPE === 'DEVELOPMENT' && (
<SaveStory {...{ resetArgs, saveStory, createStory }} />
)}
{hasControls &&
hasUpdatedArgs &&
global.CONFIG_TYPE === 'DEVELOPMENT' &&
disableSave !== true && <SaveStory {...{ resetArgs, saveStory, createStory }} />}
</AddonWrapper>
);
};
14 changes: 14 additions & 0 deletions docs/essentials/controls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ You can also update a control's value, then save the changes to the story. The s

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

### Disable creating and editing of stories

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.

{/* prettier-ignore-start */}

## Configuration

The Controls addon can be configured in two ways:
Expand Down Expand Up @@ -484,3 +490,11 @@ Specifies how the controls are sorted.
* **none**: Unsorted, displayed in the same order the arg types are processed in
* **alpha**: Sorted alphabetically, by the arg type's name
* **requiredFirst**: Same as `alpha`, with any required arg types displayed first

#### `disableSave`

Type: `boolean`

Default: `false`

Disable the ability to create or edit stories from the Controls panel.

0 comments on commit aa591c3

Please sign in to comment.