@storybook/csf 0.0.2--canary.87bc651.0 → 0.0.2--canary.507502b.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +19 -3
- package/dist/index.test.js +20 -0
- package/dist/story.d.ts +9 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Args, InputType } from './story';
|
1
2
|
export declare const sanitize: (string: string) => string;
|
2
3
|
export declare const toId: (kind: string, name?: string | undefined) => string;
|
3
4
|
export declare const storyNameFromExport: (key: string) => string;
|
@@ -15,4 +16,5 @@ export declare const parseKind: (kind: string, { rootSeparator, groupSeparator }
|
|
15
16
|
root: string | null;
|
16
17
|
groups: string[];
|
17
18
|
};
|
19
|
+
export declare const includeConditionalArg: (argType: InputType, args: Args) => boolean;
|
18
20
|
export * from './story';
|
package/dist/index.js
CHANGED
@@ -8,10 +8,11 @@ var _exportNames = {
|
|
8
8
|
toId: true,
|
9
9
|
storyNameFromExport: true,
|
10
10
|
isExportStory: true,
|
11
|
-
parseKind: true
|
11
|
+
parseKind: true,
|
12
|
+
includeConditionalArg: true
|
12
13
|
};
|
13
14
|
exports.isExportStory = isExportStory;
|
14
|
-
exports.parseKind = exports.storyNameFromExport = exports.toId = exports.sanitize = void 0;
|
15
|
+
exports.includeConditionalArg = exports.parseKind = exports.storyNameFromExport = exports.toId = exports.sanitize = void 0;
|
15
16
|
|
16
17
|
var _startCase = _interopRequireDefault(require("lodash/startCase"));
|
17
18
|
|
@@ -125,5 +126,20 @@ var parseKind = function parseKind(kind, _ref2) {
|
|
125
126
|
groups: groups
|
126
127
|
};
|
127
128
|
};
|
129
|
+
/**
|
130
|
+
* Helper function to include/exclude an arg based on the value of other other args
|
131
|
+
* aka "conditional args"
|
132
|
+
*/
|
133
|
+
|
134
|
+
|
135
|
+
exports.parseKind = parseKind;
|
136
|
+
|
137
|
+
var includeConditionalArg = function includeConditionalArg(argType, args) {
|
138
|
+
var addIf = argType.addIf,
|
139
|
+
removeIf = argType.removeIf;
|
140
|
+
if (addIf) return !!args[addIf];
|
141
|
+
if (removeIf) return !args[removeIf];
|
142
|
+
return true;
|
143
|
+
};
|
128
144
|
|
129
|
-
exports.
|
145
|
+
exports.includeConditionalArg = includeConditionalArg;
|
package/dist/index.test.js
CHANGED
@@ -139,4 +139,24 @@ describe('isExportStory', function () {
|
|
139
139
|
excludeStories: /b/
|
140
140
|
})).toBeTruthy();
|
141
141
|
});
|
142
|
+
});
|
143
|
+
describe('includeConditionalArg', function () {
|
144
|
+
it('dynamic values', function () {
|
145
|
+
expect((0, _.includeConditionalArg)({
|
146
|
+
addIf: 'foo'
|
147
|
+
}, {
|
148
|
+
foo: true
|
149
|
+
})).toBe(true);
|
150
|
+
expect((0, _.includeConditionalArg)({
|
151
|
+
addIf: 'bar'
|
152
|
+
}, {})).toBe(false);
|
153
|
+
expect((0, _.includeConditionalArg)({
|
154
|
+
removeIf: 'foo'
|
155
|
+
}, {
|
156
|
+
foo: true
|
157
|
+
})).toBe(false);
|
158
|
+
expect((0, _.includeConditionalArg)({
|
159
|
+
removeIf: 'bar'
|
160
|
+
}, {})).toBe(true);
|
161
|
+
});
|
142
162
|
});
|
package/dist/story.d.ts
CHANGED
@@ -21,6 +21,8 @@ export interface InputType {
|
|
21
21
|
description?: string;
|
22
22
|
defaultValue?: any;
|
23
23
|
type?: SBType | SBScalarType['name'];
|
24
|
+
addIf?: string;
|
25
|
+
removeIf?: string;
|
24
26
|
[key: string]: any;
|
25
27
|
}
|
26
28
|
export interface StrictInputType extends InputType {
|
@@ -85,20 +87,19 @@ export declare type StoryFn<TFramework extends AnyFramework = AnyFramework, TArg
|
|
85
87
|
export declare type DecoratorFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (fn: PartialStoryFn<TFramework, TArgs>, c: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
|
86
88
|
export declare type DecoratorApplicator<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (storyFn: LegacyStoryFn<TFramework, TArgs>, decorators: DecoratorFunction<TFramework, TArgs>[]) => LegacyStoryFn<TFramework, TArgs>;
|
87
89
|
export declare type BaseAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = {
|
88
|
-
decorators?: DecoratorFunction<TFramework,
|
90
|
+
decorators?: DecoratorFunction<TFramework, Args>[];
|
89
91
|
parameters?: Parameters;
|
90
92
|
args?: Partial<TArgs>;
|
91
93
|
argTypes?: Partial<ArgTypes<TArgs>>;
|
92
|
-
loaders?: LoaderFunction<TFramework,
|
93
|
-
render?: ArgsStoryFn<TFramework,
|
94
|
-
play?: PlayFunction<TFramework, TArgs>;
|
94
|
+
loaders?: LoaderFunction<TFramework, Args>[];
|
95
|
+
render?: ArgsStoryFn<TFramework, Args>;
|
95
96
|
};
|
96
97
|
export declare type ProjectAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
|
97
|
-
argsEnhancers?: ArgsEnhancer<TFramework,
|
98
|
-
argTypesEnhancers?: ArgTypesEnhancer<TFramework,
|
98
|
+
argsEnhancers?: ArgsEnhancer<TFramework, Args>[];
|
99
|
+
argTypesEnhancers?: ArgTypesEnhancer<TFramework, Args>[];
|
99
100
|
globals?: Globals;
|
100
101
|
globalTypes?: GlobalTypes;
|
101
|
-
applyDecorators?: DecoratorApplicator<TFramework,
|
102
|
+
applyDecorators?: DecoratorApplicator<TFramework, Args>;
|
102
103
|
};
|
103
104
|
declare type StoryDescriptor = string[] | RegExp;
|
104
105
|
export declare type ComponentAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
|
@@ -112,6 +113,7 @@ export declare type ComponentAnnotations<TFramework extends AnyFramework = AnyFr
|
|
112
113
|
export declare type StoryAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
|
113
114
|
name?: StoryName;
|
114
115
|
storyName?: StoryName;
|
116
|
+
play?: PlayFunction<TFramework, TArgs>;
|
115
117
|
story?: Omit<StoryAnnotations<TFramework, TArgs>, 'story'>;
|
116
118
|
};
|
117
119
|
export declare type LegacyAnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
|