Skip to content

Commit

Permalink
storybookを作成
Browse files Browse the repository at this point in the history
- Square
- Board
- Game
  • Loading branch information
YamazakiYusuke committed Jul 10, 2023
1 parent d00b72c commit 22240aa
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 612 deletions.
6 changes: 4 additions & 2 deletions src/components/Board.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Square from './Square';
import '../App.css';

export default function Board({ xIsNext, squares, onPlay }) {
function Board({ xIsNext, squares, onPlay }) {

function handleClick(i) {
if (squares[i] || calculateWinner(squares)) {
Expand Down Expand Up @@ -62,4 +62,6 @@ function calculateWinner(squares) {
}
}
return null;
}
}

export default Board;
4 changes: 3 additions & 1 deletion src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from 'react';
import '../App.css';
import Board from './Board';

export default function Game() {
function Game() {
const [history, setHistory] = useState([Array(9).fill(null)]);
const [currentMove, setCurrentMove] = useState(0);
const xIsNext = currentMove % 2 === 0;
Expand Down Expand Up @@ -43,3 +43,5 @@ export default function Game() {
</div>
);
}

export default Game;
5 changes: 4 additions & 1 deletion src/components/Square.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import '../App.css';
import PropTypes from 'prop-types';

export default function Square({value, onSquareClick}) {
function Square({value, onSquareClick}) {
return (<button className="square" onClick={onSquareClick}>{value}</button>);
}

export default Square;
64 changes: 64 additions & 0 deletions src/stories/Board.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import Board from '../components/Board';

export default {
title: 'Board',
component: Board
}

const Template = args => <Board {...args} />

export const Empty = Template.bind({})
Empty.args = {
xIsNext: true,
squares: Array(9).fill(null),
onplay: () => null
}

export const AllRound = Template.bind({})
AllRound.args = {
xIsNext: true,
squares: Array(9).fill('O'),
onplay: () => null
}

export const AllCross = Template.bind({})
AllCross.args = {
xIsNext: true,
squares: Array(9).fill('X'),
onplay: () => null
}

export const AllTriangle = Template.bind({})
AllTriangle.args = {
xIsNext: true,
squares: Array(9).fill('△'),
onplay: () => null
}

export const RoundAndCross = Template.bind({})
RoundAndCross.args = {
xIsNext: true,
squares: ['X', 'O', 'X', 'X', 'O', 'O', 'O', 'X', 'O',],
onplay: () => null
}

export const RoundAndTriangle = Template.bind({})
RoundAndTriangle.args = {
xIsNext: true,
squares: ['△', 'O', '△', '△', 'O', 'O', 'O', '△', 'O',],
onplay: () => null
}

export const CrossAndTriangle = Template.bind({})
CrossAndTriangle.args = {
xIsNext: true,
squares: ['X', '△', 'X', 'X', '△', '△', '△', 'X', '△',],
onplay: () => null
}

export const RoundAndCrossAndTriangle = Template.bind({})
RoundAndCrossAndTriangle.args = {
xIsNext: true,
squares: ['X', 'O', 'O', '△', 'O', '△', 'X', 'X', '△',],
onplay: () => null
}
50 changes: 0 additions & 50 deletions src/stories/Button.jsx

This file was deleted.

39 changes: 0 additions & 39 deletions src/stories/Button.stories.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/stories/Game.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Game from '../components/Game';
import PropTypes from 'prop-types';

export default {
title: 'Game',
component: Game
}

const Template = args => <Game {...args} />

export const Empty = Template.bind()
Empty.args = {
value: ''
}
59 changes: 0 additions & 59 deletions src/stories/Header.jsx

This file was deleted.

22 changes: 0 additions & 22 deletions src/stories/Header.stories.js

This file was deleted.

Loading

0 comments on commit 22240aa

Please sign in to comment.