@storybook/csf 0.0.2--canary.6aca495.0 → 0.0.2--canary.87bc651.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.test.js +5 -4
- package/dist/properties.d.ts +75 -0
- package/dist/properties.js +27 -0
- package/dist/properties.test.d.ts +1 -0
- package/dist/properties.test.js +14 -0
- package/dist/story.d.ts +3 -5
- package/package.json +1 -1
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,5 @@
|
|
1
1
|
export declare const sanitize: (string: string) => string;
|
2
|
-
export declare const toId: (kind: string, name
|
2
|
+
export declare const toId: (kind: string, name?: string | undefined) => string;
|
3
3
|
export declare const storyNameFromExport: (key: string) => string;
|
4
4
|
declare type StoryDescriptor = string[] | RegExp;
|
5
5
|
export interface IncludeExcludeOptions {
|
package/dist/index.js
CHANGED
@@ -69,7 +69,7 @@ var sanitizeSafe = function sanitizeSafe(string, part) {
|
|
69
69
|
|
70
70
|
|
71
71
|
var toId = function toId(kind, name) {
|
72
|
-
return "".concat(sanitizeSafe(kind, 'kind')
|
72
|
+
return "".concat(sanitizeSafe(kind, 'kind')).concat(name ? "--".concat(sanitizeSafe(name, 'name')) : '');
|
73
73
|
};
|
74
74
|
/**
|
75
75
|
* Transform a CSF named export into a readable story name
|
package/dist/index.test.js
CHANGED
@@ -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']]
|
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('
|
46
|
+
it('allows empty story', function () {
|
46
47
|
expect(function () {
|
47
48
|
return (0, _.toId)('kind', '');
|
48
|
-
}).toThrow(
|
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
@@ -71,15 +71,13 @@ export declare type StoryContextForLoaders<TFramework extends AnyFramework = Any
|
|
71
71
|
viewMode: ViewMode;
|
72
72
|
originalStoryFn: StoryFn<TFramework>;
|
73
73
|
};
|
74
|
-
export declare type LoaderFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (
|
74
|
+
export declare type LoaderFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContextForLoaders<TFramework, TArgs>) => Promise<Record<string, any>>;
|
75
75
|
export declare type StoryContext<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContextForLoaders<TFramework, TArgs> & {
|
76
76
|
loaded: Record<string, any>;
|
77
|
-
};
|
78
|
-
export declare type StoryContextForPlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContext<TFramework, TArgs> & {
|
79
77
|
abortSignal: AbortSignal;
|
80
|
-
|
78
|
+
canvasElement: HTMLElement;
|
81
79
|
};
|
82
|
-
export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = () => Promise<void> | void;
|
80
|
+
export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => Promise<void> | void;
|
83
81
|
export declare type PartialStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (update?: StoryContextUpdate<TArgs>) => TFramework['storyResult'];
|
84
82
|
export declare type LegacyStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
|
85
83
|
export declare type ArgsStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (args: TArgs, context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
|