Skip to content

Commit

Permalink
Merge pull request #19492 from storybookjs/deprecate/argType-defaultV…
Browse files Browse the repository at this point in the history
…alue

remove the defaultValue feature for argTypes
  • Loading branch information
ndelangen authored Jan 14, 2023
2 parents ef7b7df + d2b773f commit e886dd4
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 87 deletions.
60 changes: 1 addition & 59 deletions code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

import { global } from '@storybook/global';
import { expect } from '@jest/globals';
import type {
Renderer,
ArgsEnhancer,
PlayFunctionContext,
SBObjectType,
SBScalarType,
} from '@storybook/types';
import type { Renderer, ArgsEnhancer, PlayFunctionContext, SBScalarType } from '@storybook/types';
import { addons, HooksContext } from '../../addons';

import { NO_TARGET_NAME } from '../args';
Expand All @@ -32,20 +26,6 @@ const moduleExport = {};
const stringType: SBScalarType = { name: 'string' };
const numberType: SBScalarType = { name: 'number' };
const booleanType: SBScalarType = { name: 'boolean' };
const complexType: SBObjectType = {
name: 'object',
value: {
complex: {
name: 'object',
value: {
object: {
name: 'array',
value: { name: 'string' },
},
},
},
},
};

beforeEach(() => {
global.FEATURES = { breakingChangesV7: true };
Expand Down Expand Up @@ -195,44 +175,6 @@ describe('prepareStory', () => {
expect(initialArgs).toEqual({});
});

it('are initialized to argTypes[x].defaultValue if unset', () => {
const { initialArgs } = prepareStory(
{
id,
name,
args: {
arg2: 3,
arg4: 'foo',
arg7: false,
},
argTypes: {
arg1: { name: 'arg1', type: stringType, defaultValue: 'arg1' },
arg2: { name: 'arg2', type: numberType, defaultValue: 2 },
arg3: {
name: 'arg3',
type: complexType,
defaultValue: { complex: { object: ['type'] } },
},
arg4: { name: 'arg4', type: stringType },
arg5: { name: 'arg5', type: stringType },
arg6: { name: 'arg6', type: numberType, defaultValue: 0 }, // See https://github.com/storybookjs/storybook/issues/12767 }
},
moduleExport,
},
{ id, title },
{ render: () => {} }
);

expect(initialArgs).toEqual({
arg1: 'arg1',
arg2: 3,
arg3: { complex: { object: ['type'] } },
arg4: 'foo',
arg6: 0,
arg7: false,
});
});

describe('argsEnhancers', () => {
it('are applied in the right order', () => {
const run: number[] = [];
Expand Down
21 changes: 1 addition & 20 deletions code/lib/preview-api/src/modules/store/csf/prepareStory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { dedent } from 'ts-dedent';
import deprecate from 'util-deprecate';
import { global } from '@storybook/global';

import type {
Expand Down Expand Up @@ -28,15 +26,6 @@ import { applyHooks } from '../../addons';
import { combineParameters } from '../parameters';
import { defaultDecorateStory } from '../decorators';
import { groupArgsByTarget, NO_TARGET_NAME } from '../args';
import { getValuesFromArgTypes } from './getValuesFromArgTypes';

const argTypeDefaultValueWarning = deprecate(
() => {},
dedent`
\`argType.defaultValue\` is deprecated and will be removed in Storybook 7.0.
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#no-longer-inferring-default-values-of-args`
);

// Combine all the metadata about a story (both direct and inherited from the component/global scope)
// into a "renderable" story function, with all decorators applied, parameters passed as context etc
Expand Down Expand Up @@ -234,15 +223,7 @@ function preparePartialAnnotations<TRenderer extends Renderer>(
contextForEnhancers.argTypes
);

// Add argTypes[X].defaultValue to initial args (note this deprecated)
// We need to do this *after* the argTypesEnhancers as they may add defaultValues
const defaultArgs = getValuesFromArgTypes(contextForEnhancers.argTypes);

if (Object.keys(defaultArgs).length > 0) {
argTypeDefaultValueWarning();
}

const initialArgsBeforeEnhancers = { ...defaultArgs, ...passedArgs };
const initialArgsBeforeEnhancers = { ...passedArgs };

contextForEnhancers.initialArgs = argsEnhancers.reduce(
(accumulatedArgs: Args, enhancer) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ exports[`Renders CSF2Secondary story 1`] = `
<div>
<button
class="storybook-button storybook-button--medium storybook-button--secondary"
label="Button"
type="button"
>
Children coming from story args!
Expand All @@ -32,7 +31,6 @@ exports[`Renders CSF2StoryWithParamsAndDecorator story 1`] = `
<div>
<button
class="storybook-button storybook-button--medium storybook-button--secondary"
label="Button"
type="button"
>
foo
Expand All @@ -46,7 +44,6 @@ exports[`Renders CSF3Button story 1`] = `
<div>
<button
class="storybook-button storybook-button--medium storybook-button--secondary"
label="Button"
type="button"
>
foo
Expand All @@ -66,7 +63,6 @@ exports[`Renders CSF3ButtonWithRender story 1`] = `
</p>
<button
class="storybook-button storybook-button--medium storybook-button--secondary"
label="Button"
type="button"
>
foo
Expand All @@ -91,7 +87,6 @@ exports[`Renders CSF3Primary story 1`] = `
<div>
<button
class="storybook-button storybook-button--large storybook-button--primary"
label="Button"
type="button"
>
foo
Expand Down
1 change: 0 additions & 1 deletion code/renderers/react/src/__test__/internals.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const { CSF2StoryWithParamsAndDecorator } = composeStories(stories);
test('returns composed args including default values from argtypes', () => {
expect(CSF2StoryWithParamsAndDecorator.args).toEqual({
...stories.CSF2StoryWithParamsAndDecorator.args,
label: stories.default.argTypes!.label!.defaultValue,
});
});

Expand Down
3 changes: 1 addition & 2 deletions code/renderers/vue3/template/stories/OverrideArgs.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ export default {
type: 'select',
options: Object.keys(icons),
},
defaultValue: 'Primary',
},
},
render: (args) => {
// Individual properties can be overridden by spreading the args
// and the replacing the key-values that need to be updated
args = { ...args, icon: icons[args.icon] }; // eslint-disable-line no-param-reassign
args = { ...args, icon: icons[args.icon || 'Primary'] }; // eslint-disable-line no-param-reassign
return {
// Components used in your story `template` are defined in the `components` object
components: { OverrideArgs },
Expand Down

0 comments on commit e886dd4

Please sign in to comment.