@storybook/csf 0.0.2--canary.68887a1.0 → 0.0.2--canary.789b78e.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -30,7 +30,7 @@ export const emoji = () => <Button>😀😎👍💯</Button>;
30
30
 
31
31
  ### Who uses CSF?
32
32
 
33
- **Tools:** [Storybook](https://storybook.js.org), [WebComponents.dev](https://webcomponents.dev), [RedwoodJS](https://redwoodjs.com/), [UXPin](https://www.uxpin.com/)
33
+ **Tools:** [Storybook](https://storybook.js.org), [WebComponents.dev](https://webcomponents.dev), [Components.studio](https://components.studio), [RedwoodJS](https://redwoodjs.com/), [UXPin](https://www.uxpin.com/)
34
34
 
35
35
  **Compatible with:** [Jest](https://jestjs.io/), [Enzyme](https://enzymejs.github.io/enzyme), [Testing Library](https://testing-library.com), [Cypress](https://www.cypress.io/), [Playwright](https://playwright.dev/), [Mocha](https://mochajs.org), etc.
36
36
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { Args, InputType } from './story';
1
2
  export declare const sanitize: (string: string) => string;
2
- export declare const toId: (kind: string, name: string) => string;
3
+ export declare const toId: (kind: string, name?: string | undefined) => string;
3
4
  export declare const storyNameFromExport: (key: string) => string;
4
5
  declare type StoryDescriptor = string[] | RegExp;
5
6
  export interface IncludeExcludeOptions {
@@ -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
 
@@ -69,7 +70,7 @@ var sanitizeSafe = function sanitizeSafe(string, part) {
69
70
 
70
71
 
71
72
  var toId = function toId(kind, name) {
72
- return "".concat(sanitizeSafe(kind, 'kind'), "--").concat(sanitizeSafe(name, 'name'));
73
+ return "".concat(sanitizeSafe(kind, 'kind')).concat(name ? "--".concat(sanitizeSafe(name, 'name')) : '');
73
74
  };
74
75
  /**
75
76
  * Transform a CSF named export into a readable story name
@@ -126,4 +127,23 @@ var parseKind = function parseKind(kind, _ref2) {
126
127
  };
127
128
  };
128
129
 
129
- exports.parseKind = parseKind;
130
+ exports.parseKind = parseKind;
131
+
132
+ var includeHelper = function includeHelper(includeIf, args) {
133
+ return typeof includeIf === 'string' && includeIf.length > 0 ? !!args[includeIf] : !!includeIf;
134
+ };
135
+ /**
136
+ * Helper function to include/exclude an arg based on the value of other other args
137
+ * aka "conditional args"
138
+ */
139
+
140
+
141
+ var includeConditionalArg = function includeConditionalArg(argType, args) {
142
+ var includeIf = argType.includeIf,
143
+ excludeIf = argType.excludeIf;
144
+ if (typeof includeIf !== 'undefined') return includeHelper(includeIf, args);
145
+ if (typeof excludeIf !== 'undefined') return !includeHelper(excludeIf, args);
146
+ return true;
147
+ };
148
+
149
+ exports.includeConditionalArg = includeConditionalArg;
@@ -15,8 +15,9 @@ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(
15
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
16
 
17
17
  describe('toId', function () {
18
- [// name, kind, story, output
19
- ['handles simple cases', 'kind', 'story', 'kind--story'], ['handles basic substitution', 'a b$c?d😀e', '1-2:3', 'a-b-c-d😀e--1-2-3'], ['handles runs of non-url chars', 'a?&*b', 'story', 'a-b--story'], ['removes non-url chars from start and end', '?ab-', 'story', 'ab--story'], ['downcases', 'KIND', 'STORY', 'kind--story'], ['non-latin', 'Кнопки', 'нормальный', 'кнопки--нормальный'], ['korean', 'kind', '바보 (babo)', 'kind--바보-babo'], ['all punctuation', 'kind', 'unicorns,’–—―′¿`"<>()!.!!!{}[]%^&$*#&', 'kind--unicorns']].forEach(function (_ref) {
18
+ var testCases = [// name, kind, story, output
19
+ ['handles simple cases', 'kind', 'story', 'kind--story'], ['handles kind without story', 'kind', undefined, 'kind'], ['handles basic substitution', 'a b$c?d😀e', '1-2:3', 'a-b-c-d😀e--1-2-3'], ['handles runs of non-url chars', 'a?&*b', 'story', 'a-b--story'], ['removes non-url chars from start and end', '?ab-', 'story', 'ab--story'], ['downcases', 'KIND', 'STORY', 'kind--story'], ['non-latin', 'Кнопки', 'нормальный', 'кнопки--нормальный'], ['korean', 'kind', '바보 (babo)', 'kind--바보-babo'], ['all punctuation', 'kind', 'unicorns,’–—―′¿`"<>()!.!!!{}[]%^&$*#&', 'kind--unicorns']];
20
+ testCases.forEach(function (_ref) {
20
21
  var _ref2 = _slicedToArray(_ref, 4),
21
22
  name = _ref2[0],
22
23
  kind = _ref2[1],
@@ -42,10 +43,10 @@ describe('toId', function () {
42
43
  return (0, _.toId)('kind', '?');
43
44
  }).toThrow("Invalid name '?', must include alphanumeric characters");
44
45
  });
45
- it('does not allow empty story', function () {
46
+ it('allows empty story', function () {
46
47
  expect(function () {
47
48
  return (0, _.toId)('kind', '');
48
- }).toThrow("Invalid name '', must include alphanumeric characters");
49
+ }).not.toThrow();
49
50
  });
50
51
  });
51
52
  describe('storyNameFromExport', function () {
@@ -0,0 +1,75 @@
1
+ export declare enum PropertyTypes {
2
+ TEXT = "text",
3
+ NUMBER = "number",
4
+ BOOLEAN = "boolean",
5
+ OPTIONS = "options",
6
+ DATE = "date",
7
+ COLOR = "color",
8
+ BUTTON = "button",
9
+ OBJECT = "object",
10
+ ARRAY = "array",
11
+ FILES = "files"
12
+ }
13
+ export interface StoryPropertyBase<T> {
14
+ type: PropertyTypes;
15
+ label?: string;
16
+ value?: T;
17
+ hideLabel?: boolean;
18
+ hidden?: boolean;
19
+ groupId?: string;
20
+ order?: number;
21
+ }
22
+ export interface StoryPropertyText extends StoryPropertyBase<string> {
23
+ type: PropertyTypes.TEXT;
24
+ placeholder?: string;
25
+ maxRows?: number;
26
+ }
27
+ export interface StoryPropertyBoolean extends StoryPropertyBase<boolean> {
28
+ type: PropertyTypes.BOOLEAN;
29
+ }
30
+ export interface StoryPropertyColor extends StoryPropertyBase<string> {
31
+ type: PropertyTypes.COLOR;
32
+ }
33
+ export interface StoryPropertyDate extends StoryPropertyBase<Date> {
34
+ type: PropertyTypes.DATE;
35
+ datePicker?: boolean;
36
+ timePicker?: boolean;
37
+ }
38
+ export interface StoryPropertyFiles extends StoryPropertyBase<string[]> {
39
+ type: PropertyTypes.FILES;
40
+ accept?: string;
41
+ }
42
+ export interface StoryPropertyArray extends StoryPropertyBase<string[]> {
43
+ type: PropertyTypes.ARRAY;
44
+ separator?: string;
45
+ }
46
+ export interface StoryPropertyObject extends StoryPropertyBase<object> {
47
+ type: PropertyTypes.OBJECT;
48
+ }
49
+ export interface StoryPropertyButton extends StoryPropertyBase<void> {
50
+ type: PropertyTypes.BUTTON;
51
+ onClick?: (prop: StoryPropertyButton) => void;
52
+ }
53
+ export declare type OptionsValueType<T = unknown> = T | string | number | string[] | number[] | {
54
+ label: string;
55
+ value: any;
56
+ };
57
+ export declare type OptionsListType<T = unknown> = {
58
+ [key: string]: T;
59
+ } | OptionsValueType<T>[];
60
+ export interface StoryPropertyOptions<T = unknown> extends StoryPropertyBase<OptionsValueType<T>> {
61
+ type: PropertyTypes.OPTIONS;
62
+ options: OptionsListType<T>;
63
+ display?: 'select' | 'multi-select' | 'radio' | 'inline-radio' | 'check' | 'inline-check';
64
+ }
65
+ export interface StoryPropertyNumber extends StoryPropertyBase<number> {
66
+ type: PropertyTypes.NUMBER;
67
+ range?: boolean;
68
+ min?: number;
69
+ max?: number;
70
+ step?: number;
71
+ }
72
+ export declare type StoryProperty = StoryPropertyText | StoryPropertyBoolean | StoryPropertyColor | StoryPropertyDate | StoryPropertyObject | StoryPropertyButton | StoryPropertyOptions | StoryPropertyNumber | StoryPropertyArray | StoryPropertyFiles;
73
+ export interface StoryProperties {
74
+ [name: string]: StoryProperty;
75
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PropertyTypes = void 0;
7
+
8
+ /**
9
+ * Property field types
10
+ * examples are provided for the different types:
11
+ *
12
+ */
13
+ var PropertyTypes;
14
+ exports.PropertyTypes = PropertyTypes;
15
+
16
+ (function (PropertyTypes) {
17
+ PropertyTypes["TEXT"] = "text";
18
+ PropertyTypes["NUMBER"] = "number";
19
+ PropertyTypes["BOOLEAN"] = "boolean";
20
+ PropertyTypes["OPTIONS"] = "options";
21
+ PropertyTypes["DATE"] = "date";
22
+ PropertyTypes["COLOR"] = "color";
23
+ PropertyTypes["BUTTON"] = "button";
24
+ PropertyTypes["OBJECT"] = "object";
25
+ PropertyTypes["ARRAY"] = "array";
26
+ PropertyTypes["FILES"] = "files";
27
+ })(PropertyTypes || (exports.PropertyTypes = PropertyTypes = {}));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ var _ = require(".");
4
+
5
+ describe('properties', function () {
6
+ it('type PropertyTypes.TEXT', function () {
7
+ expect(function () {
8
+ var prop = {
9
+ type: _.PropertyTypes.TEXT
10
+ };
11
+ return prop.type === 'text';
12
+ }).toBeTruthy();
13
+ });
14
+ });
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
+ includeIf?: boolean | string;
25
+ excludeIf?: boolean | string;
24
26
  [key: string]: any;
25
27
  }
26
28
  export interface StrictInputType extends InputType {
@@ -71,15 +73,13 @@ export declare type StoryContextForLoaders<TFramework extends AnyFramework = Any
71
73
  viewMode: ViewMode;
72
74
  originalStoryFn: StoryFn<TFramework>;
73
75
  };
74
- export declare type LoaderFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (c: StoryContextForLoaders<TFramework, TArgs>) => Promise<Record<string, any>>;
76
+ export declare type LoaderFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContextForLoaders<TFramework, TArgs>) => Promise<Record<string, any>>;
75
77
  export declare type StoryContext<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContextForLoaders<TFramework, TArgs> & {
76
78
  loaded: Record<string, any>;
77
- };
78
- export declare type StoryContextForPlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContext<TFramework, TArgs> & {
79
79
  abortSignal: AbortSignal;
80
- canvas?: HTMLElement;
80
+ canvasElement: HTMLElement;
81
81
  };
82
- export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = () => Promise<void> | void;
82
+ export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => Promise<void> | void;
83
83
  export declare type PartialStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (update?: StoryContextUpdate<TArgs>) => TFramework['storyResult'];
84
84
  export declare type LegacyStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
85
85
  export declare type ArgsStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (args: TArgs, context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
@@ -87,20 +87,19 @@ export declare type StoryFn<TFramework extends AnyFramework = AnyFramework, TArg
87
87
  export declare type DecoratorFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (fn: PartialStoryFn<TFramework, TArgs>, c: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
88
88
  export declare type DecoratorApplicator<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (storyFn: LegacyStoryFn<TFramework, TArgs>, decorators: DecoratorFunction<TFramework, TArgs>[]) => LegacyStoryFn<TFramework, TArgs>;
89
89
  export declare type BaseAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = {
90
- decorators?: DecoratorFunction<TFramework, TArgs>[];
90
+ decorators?: DecoratorFunction<TFramework, Args>[];
91
91
  parameters?: Parameters;
92
92
  args?: Partial<TArgs>;
93
93
  argTypes?: Partial<ArgTypes<TArgs>>;
94
- loaders?: LoaderFunction<TFramework, TArgs>[];
95
- render?: ArgsStoryFn<TFramework, TArgs>;
96
- play?: PlayFunction<TFramework, TArgs>;
94
+ loaders?: LoaderFunction<TFramework, Args>[];
95
+ render?: ArgsStoryFn<TFramework, Args>;
97
96
  };
98
97
  export declare type ProjectAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
99
- argsEnhancers?: ArgsEnhancer<TFramework, TArgs>[];
100
- argTypesEnhancers?: ArgTypesEnhancer<TFramework, TArgs>[];
98
+ argsEnhancers?: ArgsEnhancer<TFramework, Args>[];
99
+ argTypesEnhancers?: ArgTypesEnhancer<TFramework, Args>[];
101
100
  globals?: Globals;
102
101
  globalTypes?: GlobalTypes;
103
- applyDecorators?: DecoratorApplicator<TFramework, TArgs>;
102
+ applyDecorators?: DecoratorApplicator<TFramework, Args>;
104
103
  };
105
104
  declare type StoryDescriptor = string[] | RegExp;
106
105
  export declare type ComponentAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
@@ -114,9 +113,10 @@ export declare type ComponentAnnotations<TFramework extends AnyFramework = AnyFr
114
113
  export declare type StoryAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
115
114
  name?: StoryName;
116
115
  storyName?: StoryName;
116
+ play?: PlayFunction<TFramework, TArgs>;
117
117
  story?: Omit<StoryAnnotations<TFramework, TArgs>, 'story'>;
118
118
  };
119
- declare type LegacyAnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
119
+ export declare type LegacyAnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
120
120
  export declare type LegacyStoryAnnotationsOrFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = LegacyAnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>;
121
- declare type AnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = ArgsStoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
121
+ export declare type AnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = ArgsStoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
122
122
  export declare type StoryAnnotationsOrFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = AnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/csf",
3
- "version": "0.0.2--canary.68887a1.0",
3
+ "version": "0.0.2--canary.789b78e.0",
4
4
  "description": "Component Story Format (CSF) utilities",
5
5
  "keywords": [
6
6
  "storybook",