@storybook/csf 0.0.2--canary.d38f8f1.0 → 0.0.2--canary.4566f4d.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,9 +19,10 @@ var testValue = function testValue(cond, value) {
19
19
  var _ref = cond,
20
20
  exists = _ref.exists,
21
21
  eq = _ref.eq,
22
- neq = _ref.neq;
22
+ neq = _ref.neq,
23
+ truthy = _ref.truthy;
23
24
 
24
- if (count([exists, eq, neq]) > 1) {
25
+ if (count([exists, eq, neq, truthy]) > 1) {
25
26
  throw new Error("Invalid conditional test ".concat(JSON.stringify({
26
27
  exists: exists,
27
28
  eq: eq,
@@ -37,9 +38,13 @@ var testValue = function testValue(cond, value) {
37
38
  return !(0, _isEqual["default"])(value, neq);
38
39
  }
39
40
 
40
- var shouldExist = typeof exists !== 'undefined' ? exists : true;
41
- var valueExists = typeof value !== 'undefined';
42
- return shouldExist ? valueExists : !valueExists;
41
+ if (typeof exists !== 'undefined') {
42
+ var valueExists = typeof value !== 'undefined';
43
+ return exists ? valueExists : !valueExists;
44
+ }
45
+
46
+ var shouldBeTruthy = typeof truthy === 'undefined' ? true : truthy;
47
+ return shouldBeTruthy ? !!value : !value;
43
48
  };
44
49
  /**
45
50
  * Helper function to include/exclude an arg based on the value of other other args
@@ -4,14 +4,32 @@ var _includeConditionalArg = require("./includeConditionalArg");
4
4
 
5
5
  /* eslint-disable @typescript-eslint/ban-ts-ignore */
6
6
  describe('testValue', function () {
7
+ describe('truthy', function () {
8
+ it.each([['implicit true', {}, true, true], ['implicit truthy', {}, 1, true], ['implicit falsey', {}, 0, false], ['truthy true', {
9
+ truthy: true
10
+ }, true, true], ['truthy truthy', {
11
+ truthy: true
12
+ }, 1, true], ['truthy falsey', {
13
+ truthy: true
14
+ }, 0, false], ['falsey true', {
15
+ truthy: false
16
+ }, true, false], ['falsey truthy', {
17
+ truthy: false
18
+ }, 1, false], ['falsey falsey', {
19
+ truthy: false
20
+ }, 0, true]])('%s', function (_name, cond, value, expected) {
21
+ // @ts-ignore
22
+ expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
23
+ });
24
+ });
7
25
  describe('exists', function () {
8
- it.each([['implicit exist true', {}, 1, true], ['implicit exist false', {}, undefined, false], ['explicit exist', {
26
+ it.each([['exist', {
9
27
  exists: true
10
- }, 1, true], ['explicit exist false', {
28
+ }, 1, true], ['exist false', {
11
29
  exists: true
12
- }, undefined, false], ['explicit nexist', {
30
+ }, undefined, false], ['nexist', {
13
31
  exists: false
14
- }, undefined, true], ['explicit nexist false', {
32
+ }, undefined, true], ['nexist false', {
15
33
  exists: false
16
34
  }, 1, false]])('%s', function (_name, cond, value, expected) {
17
35
  // @ts-ignore
@@ -114,25 +132,39 @@ describe('includeConditionalArg', function () {
114
132
  });
115
133
  });
116
134
  describe('args', function () {
117
- describe('exists', function () {
118
- it.each([['implicit exist true', {
135
+ describe('implicit', function () {
136
+ it.each([['implicit true', {
119
137
  "if": {
120
138
  arg: 'a'
121
139
  }
122
140
  }, {
123
141
  a: 1
124
- }, {}, true], ['implicit exist false', {
142
+ }, {}, true], ['truthy true', {
125
143
  "if": {
126
- arg: 'a'
144
+ arg: 'a',
145
+ truthy: true
146
+ }
147
+ }, {
148
+ a: 0
149
+ }, {}, false], ['truthy false', {
150
+ "if": {
151
+ arg: 'a',
152
+ truthy: false
127
153
  }
128
- }, {}, {}, false], ['explicit exist', {
154
+ }, {}, {}, true]])('%s', function (_name, argType, args, globals, expected) {
155
+ // @ts-ignore
156
+ expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
157
+ });
158
+ });
159
+ describe('exists', function () {
160
+ it.each([['exist', {
129
161
  "if": {
130
162
  arg: 'a',
131
163
  exists: true
132
164
  }
133
165
  }, {
134
166
  a: 1
135
- }, {}, true], ['explicit exist false', {
167
+ }, {}, true], ['exist false', {
136
168
  "if": {
137
169
  arg: 'a',
138
170
  exists: true
@@ -188,18 +220,49 @@ describe('includeConditionalArg', function () {
188
220
  });
189
221
  });
190
222
  describe('globals', function () {
191
- describe('exists', function () {
192
- it.each([// name, argType, args, globals, expected
193
- ['implicit exist true', {
223
+ describe('truthy', function () {
224
+ it.each([['implicit true', {
194
225
  "if": {
195
226
  global: 'a'
196
227
  }
197
228
  }, {}, {
198
229
  a: 1
199
- }, true], ['implicit exist false', {
230
+ }, true], ['implicit undefined', {
200
231
  "if": {
201
232
  global: 'a'
202
233
  }
234
+ }, {}, {}, false], ['truthy true', {
235
+ "if": {
236
+ global: 'a',
237
+ truthy: true
238
+ }
239
+ }, {}, {
240
+ a: 0
241
+ }, false], ['truthy false', {
242
+ "if": {
243
+ global: 'a',
244
+ truthy: false
245
+ }
246
+ }, {}, {
247
+ a: 0
248
+ }, true]])('%s', function (_name, argType, args, globals, expected) {
249
+ // @ts-ignore
250
+ expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
251
+ });
252
+ });
253
+ describe('exists', function () {
254
+ it.each([['implicit exist true', {
255
+ "if": {
256
+ global: 'a',
257
+ exists: true
258
+ }
259
+ }, {}, {
260
+ a: 1
261
+ }, true], ['implicit exist false', {
262
+ "if": {
263
+ global: 'a',
264
+ exists: true
265
+ }
203
266
  }, {
204
267
  a: 1
205
268
  }, {}, false]])('%s', function (_name, argType, args, globals, expected) {
package/dist/story.d.ts CHANGED
@@ -17,7 +17,9 @@ export declare type Parameters = {
17
17
  [name: string]: any;
18
18
  };
19
19
  declare type ConditionalTest = {
20
- exists?: boolean;
20
+ truthy?: boolean;
21
+ } | {
22
+ exists: boolean;
21
23
  } | {
22
24
  eq: any;
23
25
  } | {
@@ -104,7 +106,7 @@ export declare type BaseAnnotations<TFramework extends AnyFramework = AnyFramewo
104
106
  args?: Partial<TArgs>;
105
107
  argTypes?: Partial<ArgTypes<TArgs>>;
106
108
  loaders?: LoaderFunction<TFramework, Args>[];
107
- render?: ArgsStoryFn<TFramework, Args>;
109
+ render?: ArgsStoryFn<TFramework, TArgs>;
108
110
  };
109
111
  export declare type ProjectAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
110
112
  argsEnhancers?: ArgsEnhancer<TFramework, Args>[];
@@ -116,7 +116,7 @@ CSF2Story.args = {
116
116
  a: 1
117
117
  };
118
118
  var CSF3Story = {
119
- render: function render() {
119
+ render: function render(args) {
120
120
  return 'Named Story';
121
121
  },
122
122
  name: 'Another name for story',
@@ -138,7 +138,7 @@ var CSF3Story = {
138
138
  }
139
139
  };
140
140
  var CSF3StoryStrict = {
141
- render: function render() {
141
+ render: function render(args) {
142
142
  return 'Named Story';
143
143
  },
144
144
  name: 'Another name for story',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/csf",
3
- "version": "0.0.2--canary.d38f8f1.0",
3
+ "version": "0.0.2--canary.4566f4d.0",
4
4
  "description": "Component Story Format (CSF) utilities",
5
5
  "keywords": [
6
6
  "storybook",
@@ -38,7 +38,10 @@
38
38
  },
39
39
  "prettier": "@storybook/linter-config/prettier.config",
40
40
  "jest": {
41
- "testEnvironment": "node"
41
+ "testEnvironment": "node",
42
+ "roots": [
43
+ "<rootDir>/src"
44
+ ]
42
45
  },
43
46
  "dependencies": {
44
47
  "lodash": "^4.17.15"