react-justified-layout-ts 1.1.4 → 1.1.5
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.
- package/package.json +5 -2
- package/dist/TSJustifiedLayout.d.ts +0 -14
- package/dist/TSJustifiedLayout.d.ts.map +0 -1
- package/dist/TSJustifiedLayout.js +0 -114
- package/dist/stories/Button.d.ts +0 -29
- package/dist/stories/Button.js +0 -28
- package/dist/stories/Button.stories.js +0 -54
- package/dist/stories/Header.d.ts +0 -13
- package/dist/stories/Header.js +0 -27
- package/dist/stories/Header.stories.js +0 -29
- package/dist/stories/Page.d.ts +0 -3
- package/dist/stories/Page.js +0 -44
- package/dist/stories/Page.stories.d.ts +0 -13
- package/dist/stories/Page.stories.js +0 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-justified-layout-ts",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "A component based off Flickr's justified layout that is compatible with Typescript",
|
|
5
5
|
"main": "./dist/TSJustifiedLayout.js",
|
|
6
6
|
"types": "./dist/TSJustifiedLayout.d.ts",
|
|
@@ -40,5 +40,8 @@
|
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "^18.2.0"
|
|
42
42
|
},
|
|
43
|
-
"repository":
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/Alan19/react-justified-layout-ts.git"
|
|
46
|
+
}
|
|
44
47
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
type ElementDimensions = number;
|
|
3
|
-
export interface TSJustifiedLayoutProps {
|
|
4
|
-
layoutItems: ElementDimensions[];
|
|
5
|
-
itemSpacing?: number;
|
|
6
|
-
rowSpacing?: number;
|
|
7
|
-
targetRowHeight?: number;
|
|
8
|
-
targetRowHeightTolerance?: number;
|
|
9
|
-
width: number;
|
|
10
|
-
children: any[];
|
|
11
|
-
showWidows?: boolean;
|
|
12
|
-
}
|
|
13
|
-
declare function TSJustifiedLayout({ children, layoutItems, itemSpacing, rowSpacing, showWidows, targetRowHeight, targetRowHeightTolerance, width }: TSJustifiedLayoutProps): React.JSX.Element;
|
|
14
|
-
export { TSJustifiedLayout };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TSJustifiedLayout.d.ts","sourceRoot":"","sources":["../src/components/TSJustifiedLayout/TSJustifiedLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,MAAM,WAAW,sBAAsB;IACnC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;CAIxB;AAED,iBAAS,iBAAiB,CAAC,EACW,QAAQ,EACR,MAAM,EACN,WAAgB,EAChB,UAAe,EACf,UAAiB,EACjB,eAAqB,EACrB,wBAA8B,EAC9B,KAAK,EACR,EAAE,sBAAsB,qBA4G1D;AAED,OAAO,EAAC,iBAAiB,EAAC,CAAA"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.TSJustifiedLayout = void 0;
|
|
27
|
-
const react_1 = __importStar(require("react"));
|
|
28
|
-
function TSJustifiedLayout({ children, layoutItems, itemSpacing = 10, rowSpacing = 10, showWidows = true, targetRowHeight = 320, targetRowHeightTolerance = .25, width }) {
|
|
29
|
-
const minAspectRatio = width / targetRowHeight * (1 - targetRowHeightTolerance);
|
|
30
|
-
const maxAspectRatio = width / targetRowHeight * (1 + targetRowHeightTolerance);
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param value The new aspect ratio to be checked
|
|
34
|
-
* @return If the buffer can accept the new value
|
|
35
|
-
* */
|
|
36
|
-
function addItem(value) {
|
|
37
|
-
const newItems = rowBuffer.concat(value);
|
|
38
|
-
const newAspectRatio = newItems.map(dimensions => dimensions).reduce((previousValue, currentValue) => previousValue + currentValue, 0);
|
|
39
|
-
const rowWidthWithoutSpacing = width - (newItems.length - 1) * itemSpacing;
|
|
40
|
-
const targetAspectRatio = rowWidthWithoutSpacing / targetRowHeight;
|
|
41
|
-
// Row still has space
|
|
42
|
-
if (newAspectRatio < minAspectRatio) {
|
|
43
|
-
rowBuffer.push(value);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
// Row ran out of space, and the new item is larger than the max aspect ratio for the row
|
|
47
|
-
else if (newAspectRatio > maxAspectRatio) {
|
|
48
|
-
// Always accept if it's just 1 item
|
|
49
|
-
if (rowBuffer.length === 0) {
|
|
50
|
-
rowBuffer.push(value);
|
|
51
|
-
rows.push({ items: rowBuffer, height: rowWidthWithoutSpacing / newAspectRatio });
|
|
52
|
-
rowBuffer = [];
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
// Calculate width/aspect ratio for row before adding new item
|
|
57
|
-
const previousRowWidthWithoutSpacing = width - (rowBuffer.length - 1) * itemSpacing;
|
|
58
|
-
const previousAspectRatio = rowBuffer.map(dimensions => dimensions).reduce((previousValue, currentValue) => previousValue + currentValue, 0);
|
|
59
|
-
const previousTargetAspectRatio = previousRowWidthWithoutSpacing / targetRowHeight;
|
|
60
|
-
// If the new aspect ratio is farther from the target after the insert, then push row buffer and insert new item into the next row
|
|
61
|
-
if (Math.abs(newAspectRatio - targetAspectRatio) > Math.abs(previousAspectRatio - previousTargetAspectRatio)) {
|
|
62
|
-
rows.push({ items: rowBuffer, height: previousRowWidthWithoutSpacing / previousAspectRatio });
|
|
63
|
-
rowBuffer = [];
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
// If the new aspect ratio is closer to the target aspect ratio, then insert item and push row buffer
|
|
67
|
-
else {
|
|
68
|
-
rowBuffer.push(value);
|
|
69
|
-
rows.push({ items: rowBuffer, height: rowWidthWithoutSpacing / newAspectRatio });
|
|
70
|
-
rowBuffer = [];
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// New aspect ratio is within aspect ratio tolerance, so we finish off the row
|
|
77
|
-
rowBuffer.push(value);
|
|
78
|
-
rows.push({ items: rowBuffer, height: rowWidthWithoutSpacing / newAspectRatio });
|
|
79
|
-
rowBuffer = [];
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const rows = [];
|
|
84
|
-
let rowBuffer = [];
|
|
85
|
-
layoutItems.forEach((value) => {
|
|
86
|
-
const isItemSuccessfullyAdded = addItem(value);
|
|
87
|
-
if (!isItemSuccessfullyAdded) {
|
|
88
|
-
addItem(value);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
// Handle leftover content
|
|
92
|
-
if (showWidows) {
|
|
93
|
-
rows.push({ items: rowBuffer, height: rows.length === 0 ? targetRowHeight : rows[rows.length - 1].height });
|
|
94
|
-
}
|
|
95
|
-
let childNodeCounter = -1;
|
|
96
|
-
/**
|
|
97
|
-
* Clone the children element, and inject the height of the element as a prop
|
|
98
|
-
* @param height The height that the element should be
|
|
99
|
-
*/
|
|
100
|
-
function renderChildren(height) {
|
|
101
|
-
childNodeCounter++;
|
|
102
|
-
return (0, react_1.cloneElement)(children[childNodeCounter], Object.assign(Object.assign({}, children[childNodeCounter].props), { style: Object.assign(Object.assign({}, children[childNodeCounter].props.style), { height: height }) }));
|
|
103
|
-
}
|
|
104
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
105
|
-
react_1.default.createElement("div", { style: { width: "100%" } }, rows.map(value => {
|
|
106
|
-
return react_1.default.createElement("div", { style: {
|
|
107
|
-
display: "flex",
|
|
108
|
-
flexDirection: "row",
|
|
109
|
-
gap: itemSpacing,
|
|
110
|
-
marginBottom: rowSpacing
|
|
111
|
-
} }, value.items.map(() => react_1.default.createElement("div", { style: { height: value.height } }, renderChildren(value.height))));
|
|
112
|
-
}))));
|
|
113
|
-
}
|
|
114
|
-
exports.TSJustifiedLayout = TSJustifiedLayout;
|
package/dist/stories/Button.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import './button.css';
|
|
3
|
-
interface ButtonProps {
|
|
4
|
-
/**
|
|
5
|
-
* Is this the principal call to action on the page?
|
|
6
|
-
*/
|
|
7
|
-
primary?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* What background color to use
|
|
10
|
-
*/
|
|
11
|
-
backgroundColor?: string;
|
|
12
|
-
/**
|
|
13
|
-
* How large should the button be?
|
|
14
|
-
*/
|
|
15
|
-
size?: 'small' | 'medium' | 'large';
|
|
16
|
-
/**
|
|
17
|
-
* Button contents
|
|
18
|
-
*/
|
|
19
|
-
label: string;
|
|
20
|
-
/**
|
|
21
|
-
* Optional click handler
|
|
22
|
-
*/
|
|
23
|
-
onClick?: () => void;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Primary UI component for user interaction
|
|
27
|
-
*/
|
|
28
|
-
export declare const Button: ({ primary, size, backgroundColor, label, ...props }: ButtonProps) => React.JSX.Element;
|
|
29
|
-
export {};
|
package/dist/stories/Button.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Button = void 0;
|
|
18
|
-
const react_1 = __importDefault(require("react"));
|
|
19
|
-
require("./button.css");
|
|
20
|
-
/**
|
|
21
|
-
* Primary UI component for user interaction
|
|
22
|
-
*/
|
|
23
|
-
const Button = (_a) => {
|
|
24
|
-
var { primary = false, size = 'medium', backgroundColor, label } = _a, props = __rest(_a, ["primary", "size", "backgroundColor", "label"]);
|
|
25
|
-
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
26
|
-
return (react_1.default.createElement("button", Object.assign({ type: "button", className: ['storybook-button', `storybook-button--${size}`, mode].join(' '), style: { backgroundColor } }, props), label));
|
|
27
|
-
};
|
|
28
|
-
exports.Button = Button;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Warning = exports.Small = exports.Large = exports.Secondary = exports.Primary = void 0;
|
|
4
|
-
const test_1 = require("@storybook/test");
|
|
5
|
-
const Button_1 = require("./Button");
|
|
6
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
7
|
-
const meta = {
|
|
8
|
-
title: 'Example/Button',
|
|
9
|
-
component: Button_1.Button,
|
|
10
|
-
parameters: {
|
|
11
|
-
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
12
|
-
layout: 'centered',
|
|
13
|
-
},
|
|
14
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
15
|
-
tags: ['autodocs'],
|
|
16
|
-
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
|
17
|
-
argTypes: {
|
|
18
|
-
backgroundColor: { control: 'color' },
|
|
19
|
-
},
|
|
20
|
-
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
|
21
|
-
args: { onClick: (0, test_1.fn)() },
|
|
22
|
-
};
|
|
23
|
-
exports.default = meta;
|
|
24
|
-
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
25
|
-
exports.Primary = {
|
|
26
|
-
args: {
|
|
27
|
-
primary: true,
|
|
28
|
-
label: 'Button',
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
exports.Secondary = {
|
|
32
|
-
args: {
|
|
33
|
-
label: 'Button',
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
exports.Large = {
|
|
37
|
-
args: {
|
|
38
|
-
size: 'large',
|
|
39
|
-
label: 'Button',
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
exports.Small = {
|
|
43
|
-
args: {
|
|
44
|
-
size: 'small',
|
|
45
|
-
label: 'Button',
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
exports.Warning = {
|
|
49
|
-
args: {
|
|
50
|
-
primary: true,
|
|
51
|
-
label: 'Delete now',
|
|
52
|
-
backgroundColor: 'red',
|
|
53
|
-
}
|
|
54
|
-
};
|
package/dist/stories/Header.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import './header.css';
|
|
3
|
-
type User = {
|
|
4
|
-
name: string;
|
|
5
|
-
};
|
|
6
|
-
interface HeaderProps {
|
|
7
|
-
user?: User;
|
|
8
|
-
onLogin?: () => void;
|
|
9
|
-
onLogout?: () => void;
|
|
10
|
-
onCreateAccount?: () => void;
|
|
11
|
-
}
|
|
12
|
-
export declare const Header: ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => React.JSX.Element;
|
|
13
|
-
export {};
|
package/dist/stories/Header.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Header = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const Button_1 = require("./Button");
|
|
9
|
-
require("./header.css");
|
|
10
|
-
const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (react_1.default.createElement("header", null,
|
|
11
|
-
react_1.default.createElement("div", { className: "storybook-header" },
|
|
12
|
-
react_1.default.createElement("div", null,
|
|
13
|
-
react_1.default.createElement("svg", { width: "32", height: "32", viewBox: "0 0 32 32", xmlns: "http://www.w3.org/2000/svg" },
|
|
14
|
-
react_1.default.createElement("g", { fill: "none", fillRule: "evenodd" },
|
|
15
|
-
react_1.default.createElement("path", { d: "M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z", fill: "#FFF" }),
|
|
16
|
-
react_1.default.createElement("path", { d: "M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z", fill: "#555AB9" }),
|
|
17
|
-
react_1.default.createElement("path", { d: "M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z", fill: "#91BAF8" }))),
|
|
18
|
-
react_1.default.createElement("h1", null, "Acme")),
|
|
19
|
-
react_1.default.createElement("div", null, user ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
20
|
-
react_1.default.createElement("span", { className: "welcome" },
|
|
21
|
-
"Welcome, ",
|
|
22
|
-
react_1.default.createElement("b", null, user.name),
|
|
23
|
-
"!"),
|
|
24
|
-
react_1.default.createElement(Button_1.Button, { size: "small", onClick: onLogout, label: "Log out" }))) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
25
|
-
react_1.default.createElement(Button_1.Button, { size: "small", onClick: onLogin, label: "Log in" }),
|
|
26
|
-
react_1.default.createElement(Button_1.Button, { primary: true, size: "small", onClick: onCreateAccount, label: "Sign up" })))))));
|
|
27
|
-
exports.Header = Header;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LoggedOut = exports.LoggedIn = void 0;
|
|
4
|
-
const test_1 = require("@storybook/test");
|
|
5
|
-
const Header_1 = require("./Header");
|
|
6
|
-
const meta = {
|
|
7
|
-
title: 'Example/Header',
|
|
8
|
-
component: Header_1.Header,
|
|
9
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
10
|
-
tags: ['autodocs'],
|
|
11
|
-
parameters: {
|
|
12
|
-
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
|
13
|
-
layout: 'fullscreen',
|
|
14
|
-
},
|
|
15
|
-
args: {
|
|
16
|
-
onLogin: (0, test_1.fn)(),
|
|
17
|
-
onLogout: (0, test_1.fn)(),
|
|
18
|
-
onCreateAccount: (0, test_1.fn)(),
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
exports.default = meta;
|
|
22
|
-
exports.LoggedIn = {
|
|
23
|
-
args: {
|
|
24
|
-
user: {
|
|
25
|
-
name: 'Jane Doe',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
exports.LoggedOut = {};
|
package/dist/stories/Page.d.ts
DELETED
package/dist/stories/Page.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Page = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const Header_1 = require("./Header");
|
|
9
|
-
require("./page.css");
|
|
10
|
-
const Page = () => {
|
|
11
|
-
const [user, setUser] = react_1.default.useState();
|
|
12
|
-
return (react_1.default.createElement("article", null,
|
|
13
|
-
react_1.default.createElement(Header_1.Header, { user: user, onLogin: () => setUser({ name: 'Jane Doe' }), onLogout: () => setUser(undefined), onCreateAccount: () => setUser({ name: 'Jane Doe' }) }),
|
|
14
|
-
react_1.default.createElement("section", { className: "storybook-page" },
|
|
15
|
-
react_1.default.createElement("h2", null, "Pages in Storybook"),
|
|
16
|
-
react_1.default.createElement("p", null,
|
|
17
|
-
"We recommend building UIs with a",
|
|
18
|
-
' ',
|
|
19
|
-
react_1.default.createElement("a", { href: "https://componentdriven.org", target: "_blank", rel: "noopener noreferrer" },
|
|
20
|
-
react_1.default.createElement("strong", null, "component-driven")),
|
|
21
|
-
' ',
|
|
22
|
-
"process starting with atomic components and ending with pages."),
|
|
23
|
-
react_1.default.createElement("p", null, "Render pages with mock data. This makes it easy to build and review page states without needing to navigate to them in your app. Here are some handy patterns for managing page data in Storybook:"),
|
|
24
|
-
react_1.default.createElement("ul", null,
|
|
25
|
-
react_1.default.createElement("li", null, "Use a higher-level connected component. Storybook helps you compose such data from the \"args\" of child component stories"),
|
|
26
|
-
react_1.default.createElement("li", null, "Assemble data in the page component from your services. You can mock these services out using Storybook.")),
|
|
27
|
-
react_1.default.createElement("p", null,
|
|
28
|
-
"Get a guided tutorial on component-driven development at",
|
|
29
|
-
' ',
|
|
30
|
-
react_1.default.createElement("a", { href: "https://storybook.js.org/tutorials/", target: "_blank", rel: "noopener noreferrer" }, "Storybook tutorials"),
|
|
31
|
-
". Read more in the",
|
|
32
|
-
' ',
|
|
33
|
-
react_1.default.createElement("a", { href: "https://storybook.js.org/docs", target: "_blank", rel: "noopener noreferrer" }, "docs"),
|
|
34
|
-
"."),
|
|
35
|
-
react_1.default.createElement("div", { className: "tip-wrapper" },
|
|
36
|
-
react_1.default.createElement("span", { className: "tip" }, "Tip"),
|
|
37
|
-
" Adjust the width of the canvas with the",
|
|
38
|
-
' ',
|
|
39
|
-
react_1.default.createElement("svg", { width: "10", height: "10", viewBox: "0 0 12 12", xmlns: "http://www.w3.org/2000/svg" },
|
|
40
|
-
react_1.default.createElement("g", { fill: "none", fillRule: "evenodd" },
|
|
41
|
-
react_1.default.createElement("path", { d: "M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z", id: "a", fill: "#999" }))),
|
|
42
|
-
"Viewports addon in the toolbar"))));
|
|
43
|
-
};
|
|
44
|
-
exports.Page = Page;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import type { StoryObj } from '@storybook/react';
|
|
3
|
-
declare const meta: {
|
|
4
|
-
title: string;
|
|
5
|
-
component: import("react").FC<{}>;
|
|
6
|
-
parameters: {
|
|
7
|
-
layout: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export default meta;
|
|
11
|
-
type Story = StoryObj<typeof meta>;
|
|
12
|
-
export declare const LoggedOut: Story;
|
|
13
|
-
export declare const LoggedIn: Story;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.LoggedIn = exports.LoggedOut = void 0;
|
|
13
|
-
const test_1 = require("@storybook/test");
|
|
14
|
-
const Page_1 = require("./Page");
|
|
15
|
-
const meta = {
|
|
16
|
-
title: 'Example/Page',
|
|
17
|
-
component: Page_1.Page,
|
|
18
|
-
parameters: {
|
|
19
|
-
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
|
20
|
-
layout: 'fullscreen',
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
exports.default = meta;
|
|
24
|
-
exports.LoggedOut = {};
|
|
25
|
-
// More on interaction testing: https://storybook.js.org/docs/writing-tests/interaction-testing
|
|
26
|
-
exports.LoggedIn = {
|
|
27
|
-
play: ({ canvasElement }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
const canvas = (0, test_1.within)(canvasElement);
|
|
29
|
-
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
|
30
|
-
yield (0, test_1.expect)(loginButton).toBeInTheDocument();
|
|
31
|
-
yield test_1.userEvent.click(loginButton);
|
|
32
|
-
yield (0, test_1.expect)(loginButton).not.toBeInTheDocument();
|
|
33
|
-
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
|
34
|
-
yield (0, test_1.expect)(logoutButton).toBeInTheDocument();
|
|
35
|
-
}),
|
|
36
|
-
};
|