Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Commit 1434dc1

Browse files
committed
chore: update example project dependencies and code
1 parent 17d0575 commit 1434dc1

14 files changed

+2810
-2263
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import '@storybook/addon-actions/register';
2-
import '@storybook/addon-links/register';
1+
import "@storybook/addon-actions/register";
2+
import "@storybook/addon-links/register";

examples/storybook/.storybook/config.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
1-
import React from "react";
2-
import { addDecorator, configure } from "@storybook/react";
1+
import { configure } from "@storybook/react";
32

4-
addDecorator(story => (
5-
<React.Fragment>
6-
<style dangerouslySetInnerHTML={{__html: `
7-
html {
8-
box-sizing: border-box;
9-
}
10-
11-
*, *:before, *:after {
12-
box-sizing: inherit;
13-
}
14-
`}}/>
15-
{story()}
16-
</React.Fragment>
17-
))
18-
19-
// automatically import all files ending in *.stories.js
3+
// automatically import all files ending in *.stories.tsx
204
const req = require.context("../src/components", true, /.stories.tsx$/);
215
function loadStories() {
226
req.keys().forEach(filename => req(filename));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<style>
2+
html {
3+
box-sizing: border-box;
4+
}
5+
6+
*,
7+
*:before,
8+
*:after {
9+
box-sizing: inherit;
10+
}
11+
</style>

examples/storybook/.storybook/webpack.config.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
const path = require("path");
22

3-
/**
4-
* To extend the default Storybook 3 config, it is necessary to import it from
5-
* the @storybook/react package. Storybook 4 provides the default config as the
6-
* third parameter to this module's exported function.
7-
*/
8-
// const genDefaultConfig = require("@storybook/react/dist/server/config/defaults/webpack.config.js");
9-
10-
module.exports = (baseConfig, env, config /* Storybook 4 default config */) => {
11-
// Storybook 3 default config
12-
// const config = genDefaultConfig(baseConfig);
13-
3+
module.exports = (baseConfig, env, config) => {
144
config.module.rules.push({
155
test: /\.tsx?$/,
166
include: path.resolve(__dirname, "../src"),
@@ -20,24 +10,6 @@ module.exports = (baseConfig, env, config /* Storybook 4 default config */) => {
2010
],
2111
});
2212

23-
// Just enabling CSS modules here
24-
config.module.rules = config.module.rules
25-
.filter(r => r.test.toString() !== "/\\.css$/")
26-
.concat({
27-
test: /\.css$/,
28-
use: [
29-
{
30-
loader: require.resolve("style-loader"),
31-
},
32-
{
33-
loader: require.resolve("css-loader"),
34-
options: {
35-
modules: true,
36-
},
37-
},
38-
],
39-
});
40-
4113
config.resolve.extensions.push(".ts", ".tsx");
4214

4315
return config;

examples/storybook/package.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@
44
"version": "1.0.0",
55
"main": "index.js",
66
"license": "MIT",
7+
"scripts": {
8+
"storybook": "start-storybook -p 6006",
9+
"build-storybook": "build-storybook"
10+
},
711
"dependencies": {
812
"react": "^16.5.2",
913
"react-dom": "^16.5.2"
1014
},
11-
"scripts": {
12-
"storybook": "start-storybook -p 6006",
13-
"build-storybook": "build-storybook",
14-
"clean": "rimraf storybook-static"
15-
},
1615
"devDependencies": {
17-
"@storybook/addon-actions": "4.0.0-alpha.2",
18-
"@storybook/addon-info": "4.0.0-alpha.2",
19-
"@storybook/addon-links": "4.0.0-alpha.2",
20-
"@storybook/addons": "4.0.0-alpha.2",
21-
"@storybook/react": "4.0.0-alpha.2",
16+
"@babel/core": "^7.2.2",
17+
"@storybook/addon-actions": "4.1.11",
18+
"@storybook/addon-info": "4.1.11",
19+
"@storybook/addon-links": "4.1.11",
20+
"@storybook/addons": "4.1.11",
21+
"@storybook/react": "4.1.11",
2222
"@types/react": "^16.4.14",
2323
"@types/storybook__addon-actions": "^3.0.3",
2424
"@types/storybook__addon-info": "^3.4.2",
25-
"@types/storybook__react": "^3.0.8",
26-
"babel-core": "^6.26.3",
27-
"babel-runtime": "^6.26.0",
28-
"react-docgen-typescript-loader": "^2.0.3",
29-
"rimraf": "^2.6.2",
25+
"@types/storybook__react": "^4.0.1",
26+
"babel-loader": "^8.0.5",
27+
"react-docgen-typescript-loader": "^3.0.1",
3028
"ts-loader": "^5.1.1",
3129
"typescript": "^3.0.3"
3230
}

examples/storybook/src/components/TicTacToeCell/TicTacToeCell.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.button {
1+
.ttt-cell {
22
display: block;
33
width: 100%;
44
height: 100%;
@@ -11,6 +11,6 @@
1111
cursor: pointer;
1212
}
1313

14-
.disabled {
14+
.ttt-cell--hidden {
1515
cursor: inherit;
1616
}

examples/storybook/src/components/TicTacToeCell/TicTacToeCell.stories.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ import { TicTacToeCell } from "./TicTacToeCell";
66

77
const stories = storiesOf("Components", module);
88

9-
stories.add(
10-
"TicTacToeCell",
11-
withInfo({ inline: true })(() => (
12-
<div style={styles.container}>
13-
<div style={styles.firstCellContainer}>
14-
<TicTacToeCell
15-
value="X"
16-
position={{ x: 0, y: 0 }}
17-
onClick={action("onClick")}
18-
/>
19-
</div>
20-
<div style={styles.cellContainer}>
21-
<TicTacToeCell
22-
value=" "
23-
position={{ x: 0, y: 1 }}
24-
onClick={action("onClick")}
25-
/>
26-
</div>
9+
stories.addDecorator(withInfo);
10+
stories.addParameters({ info: { inline: true } });
11+
12+
stories.add("TicTacToeCell", () => (
13+
<div style={styles.container}>
14+
<div style={styles.firstCellContainer}>
15+
<TicTacToeCell
16+
value="X"
17+
position={{ x: 0, y: 0 }}
18+
onClick={action("onClick")}
19+
/>
20+
</div>
21+
<div style={styles.cellContainer}>
22+
<TicTacToeCell
23+
value=" "
24+
position={{ x: 0, y: 1 }}
25+
onClick={action("onClick")}
26+
/>
2727
</div>
28-
)),
29-
);
28+
</div>
29+
));
3030

3131
const styles: { [key: string]: CSSProperties } = {
3232
container: {

examples/storybook/src/components/TicTacToeCell/TicTacToeCell.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from "react";
2-
import * as styles from "./TicTacToeCell.css";
2+
import "./TicTacToeCell.css";
33

4-
interface Props {
4+
export interface TicTacToeCellProps {
55
/**
66
* Value to display, either empty (" ") or "X" / "O".
77
*
@@ -20,7 +20,7 @@ interface Props {
2020
* TicTacToe game cell. Displays a clickable button when the value is " ",
2121
* otherwise displays "X" or "O".
2222
*/
23-
export class TicTacToeCell extends Component<Props> {
23+
export class TicTacToeCell extends Component<TicTacToeCellProps> {
2424
handleClick = () => {
2525
const {
2626
position: { x, y },
@@ -34,7 +34,7 @@ export class TicTacToeCell extends Component<Props> {
3434
render() {
3535
const { value = " " } = this.props;
3636
const disabled = value !== " ";
37-
const classes = `${styles.button} ${disabled ? styles.disabled : ""}`;
37+
const classes = `ttt-cell ${disabled ? "ttt-cell--hidden" : ""}`;
3838

3939
return (
4040
<button
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { TicTacToeCell as default } from "./TicTacToeCell";
1+
export { TicTacToeCell as default, TicTacToeCellProps } from "./TicTacToeCell";
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
.container {
1+
.ttt-game-board {
22
position: relative;
33
padding-bottom: 100%;
44
background-color: rgb(72, 78, 104);
55
}
66

7-
.innerContainer {
7+
.ttt-game-board__content {
88
display: flex;
99
flex-wrap: wrap;
1010
position: absolute;
@@ -13,17 +13,17 @@
1313
padding: 8px;
1414
}
1515

16-
.cell {
16+
.ttt-game-board__cell {
1717
width: calc(100% / 3);
1818
padding: 8px;
1919
border: 2px transparent;
2020
}
2121

22-
.cell:nth-child(3n - 2),
23-
.cell:nth-child(3n - 1) {
24-
border-right-color: #FFC153;
22+
.ttt-game-board__cell:nth-child(3n - 2),
23+
.ttt-game-board__cell:nth-child(3n - 1) {
24+
border-right-color: #ffc153;
2525
}
2626

27-
.cell:nth-child(-n + 6) {
28-
border-bottom-color: #FFC153;
27+
.ttt-game-board__cell:nth-child(-n + 6) {
28+
border-bottom-color: #ffc153;
2929
}
Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
1-
import React, { SFC, ReactElement } from "react";
1+
import React, { FC } from "react";
22
import { storiesOf } from "@storybook/react";
33
import { withInfo } from "@storybook/addon-info";
44
import { TicTacToeGameBoard } from "./TicTacToeGameBoard";
5-
import TicTacToeCell from "../TicTacToeCell";
5+
import TicTacToeCell, { TicTacToeCellProps } from "../TicTacToeCell";
66

77
const stories = storiesOf("Components", module);
88

9-
stories.add(
10-
"TicTacToeGameBoard",
11-
withInfo({ inline: true })(() => (
12-
<div style={{ display: "flex" }}>
13-
<div style={{ width: 300, marginRight: 20 }}>
14-
<TicTacToeGameBoard cells={placeholderCells} />
15-
</div>
16-
<div style={{ width: 300 }}>
17-
<TicTacToeGameBoard cells={gameCells} lineStyle="dashed" />
18-
</div>
9+
stories.addDecorator(withInfo);
10+
stories.addParameters({ info: { inline: true } });
11+
12+
stories.add("TicTacToeGameBoard", () => (
13+
<div style={{ display: "flex" }}>
14+
<div style={{ width: 300, marginRight: 20 }}>
15+
<TicTacToeGameBoard cells={placeholderCells} />
1916
</div>
20-
)),
21-
);
17+
<div style={{ width: 300 }}>
18+
<TicTacToeGameBoard cells={gameCells} lineStyle="dashed" />
19+
</div>
20+
</div>
21+
));
2222

23-
const PlaceholderCell: SFC<object> = () => (
23+
const PlaceholderCell: FC = () => (
2424
<p style={{ margin: 0, color: "#eee" }}>Cell</p>
2525
);
2626

27-
const placeholderCells: ReactElement<any>[] = [];
28-
for (let i = 0; i < 9; i += 1) {
29-
placeholderCells.push(<PlaceholderCell key={i} />);
30-
}
27+
const placeholderCells = Array.from({ length: 9 }, (_, index) => (
28+
<PlaceholderCell key={index} />
29+
));
3130

32-
const gameCells: ReactElement<any>[] = [];
33-
const gameCellValues = "XOX O O X";
34-
for (let y = 0; y < 3; y += 1) {
35-
for (let x = 0; x < 3; x += 1) {
36-
gameCells.push(
37-
<TicTacToeCell
38-
key={`${x}${y}`}
39-
value={gameCellValues.charAt(y * 3 + x) as any}
40-
position={{ x, y }}
41-
/>,
42-
);
43-
}
44-
}
31+
const gameCellValues = "XOX O O X".split("") as TicTacToeCellProps["value"][];
32+
const gameCells = Array.from(gameCellValues, (char, index) => (
33+
<TicTacToeCell
34+
key={index}
35+
value={char}
36+
position={{ x: index % 3, y: index / 3 }}
37+
/>
38+
));

examples/storybook/src/components/TicTacToeGameBoard/TicTacToeGameBoard.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { ReactElement, SFC } from "react";
2-
import * as styles from "./TicTacToeGameBoard.css";
1+
import React, { ReactElement, FC } from "react";
2+
import "./TicTacToeGameBoard.css";
33

44
interface Props {
55
/**
@@ -10,7 +10,7 @@ interface Props {
1010
/**
1111
* Line style to use when dividing game cells.
1212
*
13-
* @default solid
13+
* @default "solid"
1414
*/
1515
lineStyle?: "solid" | "dashed";
1616
}
@@ -20,16 +20,16 @@ interface Props {
2020
* It requires that 9 elements be provided. The game board maintains a 1:1 size
2121
* ratio.
2222
*/
23-
export const TicTacToeGameBoard: SFC<Props> = props => {
23+
export const TicTacToeGameBoard: FC<Props> = props => {
2424
const { cells, lineStyle = "solid", ...rest } = props;
2525

2626
return (
27-
<div className={styles.container} {...rest}>
28-
<div className={styles.innerContainer}>
27+
<div className="ttt-game-board" {...rest}>
28+
<div className="ttt-game-board__content">
2929
{cells.map((cell, index) => (
3030
<div
3131
key={index}
32-
className={styles.cell}
32+
className="ttt-game-board__cell"
3333
style={{ borderStyle: lineStyle }}
3434
>
3535
{cell}

examples/storybook/src/css.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)