kokopu-react 1.1.0 → 1.4.0
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/CHANGELOG.md +17 -0
- package/README.md +2 -0
- package/dist/lib/ArrowMarkerIcon.js +3 -5
- package/dist/lib/Chessboard.js +25 -32
- package/dist/lib/{impl/ErrorBox.js → ErrorBox.js} +1 -1
- package/dist/lib/TextMarkerIcon.js +11 -10
- package/dist/lib/css/symbol.css +25 -0
- package/dist/lib/i18n.js +35 -0
- package/dist/lib/impl/ArrowTip.js +2 -7
- package/dist/lib/impl/TextSymbol.js +100 -0
- package/dist/lib/impl/util.js +5 -5
- package/dist/lib/index.js +34 -18
- package/dist/lib/markers.js +10 -10
- package/doc_src/{demo/.eslintrc.yml → .eslintrc.yml} +0 -0
- package/doc_src/demo/PageChessboardBase.js +35 -40
- package/doc_src/demo/PageChessboardEdition.js +58 -70
- package/doc_src/demo/PageChessboardMove.js +20 -27
- package/doc_src/demo/PageChessboardSmallScreens.js +15 -16
- package/doc_src/examples/ErrorBox.md +3 -0
- package/doc_src/theming/LogoRenderer.js +50 -0
- package/doc_src/theming/kokopu-react-favicon.png +0 -0
- package/doc_src/theming/kokopu-react-logo.png +0 -0
- package/doc_src/theming/theming.css +29 -0
- package/graphic_test_app/01_marker_icons.js +5 -3
- package/graphic_test_app/04_chessboard_annotations.js +1 -1
- package/graphic_test_app/10_chessboard_play_moves.js +2 -0
- package/graphics/logo-small.svg +14 -0
- package/graphics/logo.svg +26 -0
- package/package.json +23 -21
- package/scripts/test_graphic/docker-compose.yml +1 -1
- package/scripts/test_graphic/webpack-config.js +1 -0
- package/scripts/test_headless.webpack-config.js +1 -0
- package/src/ArrowMarkerIcon.js +1 -1
- package/src/Chessboard.js +15 -15
- package/src/{impl/ErrorBox.js → ErrorBox.js} +1 -1
- package/src/TextMarkerIcon.js +6 -6
- package/src/css/symbol.css +25 -0
- package/src/i18n.js +30 -0
- package/src/impl/ArrowTip.js +2 -6
- package/src/impl/TextSymbol.js +77 -0
- package/src/impl/util.js +1 -1
- package/src/index.js +2 -0
- package/src/markers.js +7 -6
- package/test/1_markers.js +19 -0
- package/test/3_marker_icons_graphic.js +1 -1
- package/test/6_chessboard_play_moves.js +4 -0
- package/test/references/01_marker_icons/10.png +0 -0
- package/test/references/01_marker_icons/9.png +0 -0
- package/test/references/02_chessboard_simple/2.png +0 -0
- package/test/references/02_chessboard_simple/5.png +0 -0
- package/test/references/03_chessboard_flipped/2.png +0 -0
- package/test/references/04_chessboard_annotations/4.png +0 -0
- package/test/references/04_chessboard_annotations/5.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_ambiguous_king_move.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_castling_move_1.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_castling_move_2.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_non_kxr_castling.png +0 -0
|
@@ -25,15 +25,18 @@ import React from 'react';
|
|
|
25
25
|
import { Chessboard } from '../../src/index';
|
|
26
26
|
import { buildComponentDemoCode } from './util';
|
|
27
27
|
|
|
28
|
-
import Box from '@material
|
|
29
|
-
import Button from '@material
|
|
30
|
-
import ButtonGroup from '@material
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import
|
|
28
|
+
import Box from '@mui/material/Box';
|
|
29
|
+
import Button from '@mui/material/Button';
|
|
30
|
+
import ButtonGroup from '@mui/material/ButtonGroup';
|
|
31
|
+
import FormControl from '@mui/material/FormControl';
|
|
32
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
33
|
+
import InputLabel from '@mui/material/InputLabel';
|
|
34
|
+
import MenuItem from '@mui/material/MenuItem';
|
|
35
|
+
import Select from '@mui/material/Select';
|
|
36
|
+
import Slider from '@mui/material/Slider';
|
|
37
|
+
import Stack from '@mui/material/Stack';
|
|
38
|
+
import Switch from '@mui/material/Switch';
|
|
39
|
+
import Typography from '@mui/material/Typography';
|
|
37
40
|
|
|
38
41
|
import './demo.css';
|
|
39
42
|
|
|
@@ -59,17 +62,17 @@ export default class Page extends React.Component {
|
|
|
59
62
|
|
|
60
63
|
render() {
|
|
61
64
|
return (
|
|
62
|
-
<
|
|
65
|
+
<Stack spacing={2} mt={2}>
|
|
63
66
|
{this.renderControls()}
|
|
64
67
|
{this.renderChessboard()}
|
|
65
68
|
{this.renderCode()}
|
|
66
|
-
</
|
|
69
|
+
</Stack>
|
|
67
70
|
);
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
renderControls() {
|
|
71
74
|
return (<>
|
|
72
|
-
<
|
|
75
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
73
76
|
<FormControlLabel label="Flip"
|
|
74
77
|
control={<Switch checked={this.state.flipped} onChange={() => this.set('flipped', !this.state.flipped)} color="primary" />}
|
|
75
78
|
/>
|
|
@@ -79,42 +82,40 @@ export default class Page extends React.Component {
|
|
|
79
82
|
<FormControlLabel label="Show annotations"
|
|
80
83
|
control={<Switch checked={this.state.annotationVisible} onChange={() => this.set('annotationVisible', !this.state.annotationVisible)} color="primary" />}
|
|
81
84
|
/>
|
|
82
|
-
</
|
|
83
|
-
<Box
|
|
85
|
+
</Stack>
|
|
86
|
+
<Box>
|
|
84
87
|
<Typography gutterBottom>Square size</Typography>
|
|
85
88
|
<Slider
|
|
86
89
|
value={this.state.squareSize} onChange={(_, newValue) => this.set('squareSize', newValue)}
|
|
87
90
|
min={Chessboard.minSquareSize()} max={Chessboard.maxSquareSize()} step={1} valueLabelDisplay="on" color="primary"
|
|
88
91
|
/>
|
|
89
92
|
</Box>
|
|
90
|
-
<
|
|
91
|
-
<
|
|
92
|
-
<
|
|
93
|
-
<Select value={this.state.colorset} onChange={evt => this.set('colorset', evt.target.value)}>
|
|
93
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
94
|
+
<FormControl variant="standard">
|
|
95
|
+
<InputLabel id="colorset-label">Colorset</InputLabel>
|
|
96
|
+
<Select labelId="colorset-label" sx={{ width: '8em' }} value={this.state.colorset} onChange={evt => this.set('colorset', evt.target.value)}>
|
|
94
97
|
{Object.keys(Chessboard.colorsets()).sort().map(colorset => <MenuItem key={colorset} value={colorset}>{colorset}</MenuItem>)}
|
|
95
98
|
</Select>
|
|
96
|
-
</
|
|
97
|
-
<
|
|
98
|
-
<
|
|
99
|
-
<Select value={this.state.pieceset} onChange={evt => this.set('pieceset', evt.target.value)}>
|
|
99
|
+
</FormControl>
|
|
100
|
+
<FormControl variant="standard">
|
|
101
|
+
<InputLabel id="pieceset-label">Pieceset</InputLabel>
|
|
102
|
+
<Select labelId="pieceset-label" sx={{ width: '8em' }} value={this.state.pieceset} onChange={evt => this.set('pieceset', evt.target.value)}>
|
|
100
103
|
{Object.keys(Chessboard.piecesets()).sort().map(pieceset => <MenuItem key={pieceset} value={pieceset}>{pieceset}</MenuItem>)}
|
|
101
104
|
</Select>
|
|
102
|
-
</
|
|
103
|
-
<
|
|
104
|
-
<
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
</Box>
|
|
111
|
-
</Box>
|
|
105
|
+
</FormControl>
|
|
106
|
+
<ButtonGroup color="primary" size="small">
|
|
107
|
+
<Button onClick={() => this.set('position', 'empty')}>Clear</Button>
|
|
108
|
+
<Button onClick={() => this.set('position', 'start')}>Reset</Button>
|
|
109
|
+
<Button onClick={() => this.set('position', '8/8/8/8/8/4k3/q7/4K3 b - - 0 1')}>Set FEN</Button>
|
|
110
|
+
<Button onClick={() => this.set('position', 'I\'m an invalid FEN string')}>Set ill-formed FEN</Button>
|
|
111
|
+
</ButtonGroup>
|
|
112
|
+
</Stack>
|
|
112
113
|
</>);
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
renderChessboard() {
|
|
116
117
|
return (
|
|
117
|
-
<Box
|
|
118
|
+
<Box>
|
|
118
119
|
<Chessboard
|
|
119
120
|
position={this.state.position}
|
|
120
121
|
flipped={this.state.flipped}
|
|
@@ -145,13 +146,7 @@ export default class Page extends React.Component {
|
|
|
145
146
|
attributes.push(`coordinateVisible={${this.state.coordinateVisible}}`);
|
|
146
147
|
attributes.push(`colorset="${this.state.colorset}"`);
|
|
147
148
|
attributes.push(`pieceset="${this.state.pieceset}"`);
|
|
148
|
-
return (
|
|
149
|
-
<Box my={2}>
|
|
150
|
-
<pre className="kokopu-demoCode">
|
|
151
|
-
{buildComponentDemoCode('Chessboard', attributes)}
|
|
152
|
-
</pre>
|
|
153
|
-
</Box>
|
|
154
|
-
);
|
|
149
|
+
return <pre className="kokopu-demoCode">{buildComponentDemoCode('Chessboard', attributes)}</pre>;
|
|
155
150
|
}
|
|
156
151
|
|
|
157
152
|
set(attributeName, newValue) {
|
|
@@ -26,18 +26,19 @@ import kokopu from 'kokopu';
|
|
|
26
26
|
import { Chessboard, SquareMarkerIcon, TextMarkerIcon, ArrowMarkerIcon, flattenSquareMarkers, flattenTextMarkers, flattenArrowMarkers } from '../../src/index';
|
|
27
27
|
import { buildComponentDemoCode } from './util';
|
|
28
28
|
|
|
29
|
-
import Box from '@material
|
|
30
|
-
import Button from '@material
|
|
31
|
-
import ButtonGroup from '@material
|
|
32
|
-
import FormControlLabel from '@material
|
|
33
|
-
import MenuItem from '@material
|
|
34
|
-
import Radio from '@material
|
|
35
|
-
import RadioGroup from '@material
|
|
36
|
-
import Select from '@material
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
import
|
|
40
|
-
import
|
|
29
|
+
import Box from '@mui/material/Box';
|
|
30
|
+
import Button from '@mui/material/Button';
|
|
31
|
+
import ButtonGroup from '@mui/material/ButtonGroup';
|
|
32
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
33
|
+
import MenuItem from '@mui/material/MenuItem';
|
|
34
|
+
import Radio from '@mui/material/Radio';
|
|
35
|
+
import RadioGroup from '@mui/material/RadioGroup';
|
|
36
|
+
import Select from '@mui/material/Select';
|
|
37
|
+
import Stack from '@mui/material/Stack';
|
|
38
|
+
import Switch from '@mui/material/Switch';
|
|
39
|
+
import ToggleButton from '@mui/material/ToggleButton';
|
|
40
|
+
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
|
|
41
|
+
import Typography from '@mui/material/Typography';
|
|
41
42
|
|
|
42
43
|
import './demo.css';
|
|
43
44
|
|
|
@@ -68,55 +69,53 @@ export default class Page extends React.Component {
|
|
|
68
69
|
|
|
69
70
|
render() {
|
|
70
71
|
return (
|
|
71
|
-
<
|
|
72
|
+
<Stack spacing={2} mt={2}>
|
|
72
73
|
{this.renderControls()}
|
|
73
74
|
{this.renderChessboard()}
|
|
74
75
|
{this.renderCode()}
|
|
75
|
-
</
|
|
76
|
+
</Stack>
|
|
76
77
|
);
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
renderControls() {
|
|
80
81
|
return (<>
|
|
81
|
-
<
|
|
82
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
82
83
|
<FormControlLabel label="Flip"
|
|
83
84
|
control={<Switch checked={this.state.flipped} onChange={() => this.set('flipped', !this.state.flipped)} color="primary" />}
|
|
84
85
|
/>
|
|
85
86
|
<Button color="primary" size="small" variant="contained" onClick={() => this.handleTurnClicked(kokopu.oppositeColor(this.state.position.turn()))}>
|
|
86
87
|
Change turn
|
|
87
88
|
</Button>
|
|
88
|
-
<
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
</Box>
|
|
95
|
-
<Box my={2}>
|
|
89
|
+
<ButtonGroup color="primary" size="small">
|
|
90
|
+
<Button onClick={() => this.set('position', new kokopu.Position('empty'))}>Clear</Button>
|
|
91
|
+
<Button onClick={() => this.set('position', new kokopu.Position())}>Reset</Button>
|
|
92
|
+
</ButtonGroup>
|
|
93
|
+
</Stack>
|
|
94
|
+
<Box>
|
|
96
95
|
<Typography gutterBottom>
|
|
97
96
|
Edition mode
|
|
98
97
|
</Typography>
|
|
99
98
|
<RadioGroup value={this.state.interactionMode} onChange={evt => this.set('interactionMode', evt.target.value)}>
|
|
100
99
|
<FormControlLabel value="" control={<Radio color="primary" />} label="None" />
|
|
101
|
-
<
|
|
100
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
102
101
|
<FormControlLabel value="addRemovePieces" control={<Radio color="primary" />} label="Add/remove pieces" />
|
|
103
102
|
{this.renderPieceSelector()}
|
|
104
|
-
</
|
|
103
|
+
</Stack>
|
|
105
104
|
<FormControlLabel value="movePieces" control={<Radio color="primary" />} label="Move pieces" />
|
|
106
105
|
<FormControlLabel value="playMoves" control={<Radio color="primary" />} label="Move pieces (obeying chess rules)" />
|
|
107
|
-
<
|
|
106
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
108
107
|
<FormControlLabel value="editSquareMarkers" control={<Radio color="primary" />} label="Edit square annotations" />
|
|
109
108
|
{this.renderMarkerColorSelector('squareMarkerColor', 'editSquareMarkers')}
|
|
110
|
-
</
|
|
111
|
-
<
|
|
109
|
+
</Stack>
|
|
110
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
112
111
|
<FormControlLabel value="editTextMarkers" control={<Radio color="primary" />} label="Edit text annotations" />
|
|
113
112
|
{this.renderMarkerColorSelector('textMarkerColor', 'editTextMarkers')}
|
|
114
113
|
{this.renderTextMarkerSymbolSelector()}
|
|
115
|
-
</
|
|
116
|
-
<
|
|
114
|
+
</Stack>
|
|
115
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
117
116
|
<FormControlLabel value="editArrowMarkers" control={<Radio color="primary" />} label="Edit arrow annotations" />
|
|
118
117
|
{this.renderMarkerColorSelector('arrowMarkerColor', 'editArrowMarkers')}
|
|
119
|
-
</
|
|
118
|
+
</Stack>
|
|
120
119
|
</RadioGroup>
|
|
121
120
|
</Box>
|
|
122
121
|
</>);
|
|
@@ -128,28 +127,24 @@ export default class Page extends React.Component {
|
|
|
128
127
|
}
|
|
129
128
|
let pieceset = Chessboard.piecesets()['cburnett'];
|
|
130
129
|
return (
|
|
131
|
-
<
|
|
132
|
-
<
|
|
133
|
-
<
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
<
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
<ToggleButton value="bp"><img src={pieceset.bp} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
150
|
-
</ToggleButtonGroup>
|
|
151
|
-
</Box>
|
|
152
|
-
</Box>
|
|
130
|
+
<Stack spacing={0.5}>
|
|
131
|
+
<ToggleButtonGroup value={this.state.pieceEditMode} exclusive size="small" onChange={(_, newMode) => this.setIfNonNull('pieceEditMode', newMode)}>
|
|
132
|
+
<ToggleButton value="wk"><img src={pieceset.wk} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
133
|
+
<ToggleButton value="wq"><img src={pieceset.wq} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
134
|
+
<ToggleButton value="wr"><img src={pieceset.wr} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
135
|
+
<ToggleButton value="wb"><img src={pieceset.wb} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
136
|
+
<ToggleButton value="wn"><img src={pieceset.wn} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
137
|
+
<ToggleButton value="wp"><img src={pieceset.wp} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
138
|
+
</ToggleButtonGroup>
|
|
139
|
+
<ToggleButtonGroup value={this.state.pieceEditMode} exclusive size="small" onChange={(_, newMode) => this.setIfNonNull('pieceEditMode', newMode)}>
|
|
140
|
+
<ToggleButton value="bk"><img src={pieceset.bk} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
141
|
+
<ToggleButton value="bq"><img src={pieceset.bq} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
142
|
+
<ToggleButton value="br"><img src={pieceset.br} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
143
|
+
<ToggleButton value="bb"><img src={pieceset.bb} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
144
|
+
<ToggleButton value="bn"><img src={pieceset.bn} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
145
|
+
<ToggleButton value="bp"><img src={pieceset.bp} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
146
|
+
</ToggleButtonGroup>
|
|
147
|
+
</Stack>
|
|
153
148
|
);
|
|
154
149
|
}
|
|
155
150
|
|
|
@@ -157,9 +152,10 @@ export default class Page extends React.Component {
|
|
|
157
152
|
if (this.state.interactionMode !== 'editTextMarkers') {
|
|
158
153
|
return undefined;
|
|
159
154
|
}
|
|
155
|
+
let availableSymbols = [ 'plus', 'times', 'dot', 'circle' ].concat([...'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789']);
|
|
160
156
|
return (
|
|
161
|
-
<Select value={this.state.textMarkerSymbol} onChange={evt => this.set('textMarkerSymbol', evt.target.value)}>
|
|
162
|
-
{
|
|
157
|
+
<Select variant="standard" value={this.state.textMarkerSymbol} onChange={evt => this.set('textMarkerSymbol', evt.target.value)}>
|
|
158
|
+
{availableSymbols.map(mode => <MenuItem key={mode} value={mode}>{mode}</MenuItem>)}
|
|
163
159
|
</Select>
|
|
164
160
|
);
|
|
165
161
|
}
|
|
@@ -170,13 +166,11 @@ export default class Page extends React.Component {
|
|
|
170
166
|
}
|
|
171
167
|
let colorset = Chessboard.colorsets()['original'];
|
|
172
168
|
return (
|
|
173
|
-
<
|
|
174
|
-
<
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
</ToggleButtonGroup>
|
|
179
|
-
</Box>
|
|
169
|
+
<ToggleButtonGroup value={this.state[attributeName]} exclusive size="small" onChange={(_, newColor) => this.setIfNonNull(attributeName, newColor)}>
|
|
170
|
+
<ToggleButton className="kokopu-fixTextTransform" value="g">{this.renderColorButtonLabel(colorset.g)}</ToggleButton>
|
|
171
|
+
<ToggleButton className="kokopu-fixTextTransform" value="r">{this.renderColorButtonLabel(colorset.r)}</ToggleButton>
|
|
172
|
+
<ToggleButton className="kokopu-fixTextTransform" value="y">{this.renderColorButtonLabel(colorset.y)}</ToggleButton>
|
|
173
|
+
</ToggleButtonGroup>
|
|
180
174
|
);
|
|
181
175
|
}
|
|
182
176
|
|
|
@@ -195,7 +189,7 @@ export default class Page extends React.Component {
|
|
|
195
189
|
|
|
196
190
|
renderChessboard() {
|
|
197
191
|
return (
|
|
198
|
-
<Box
|
|
192
|
+
<Box>
|
|
199
193
|
<Chessboard
|
|
200
194
|
position={this.state.position}
|
|
201
195
|
flipped={this.state.flipped}
|
|
@@ -257,13 +251,7 @@ export default class Page extends React.Component {
|
|
|
257
251
|
default:
|
|
258
252
|
break;
|
|
259
253
|
}
|
|
260
|
-
return (
|
|
261
|
-
<Box my={2}>
|
|
262
|
-
<pre className="kokopu-demoCode">
|
|
263
|
-
{buildComponentDemoCode('Chessboard', attributes)}
|
|
264
|
-
</pre>
|
|
265
|
-
</Box>
|
|
266
|
-
);
|
|
254
|
+
return <pre className="kokopu-demoCode">{buildComponentDemoCode('Chessboard', attributes)}</pre>;
|
|
267
255
|
}
|
|
268
256
|
|
|
269
257
|
set(attributeName, newValue) {
|
|
@@ -26,12 +26,13 @@ import kokopu from 'kokopu';
|
|
|
26
26
|
import { Chessboard } from '../../src/index';
|
|
27
27
|
import { buildComponentDemoCode } from './util';
|
|
28
28
|
|
|
29
|
-
import Box from '@material
|
|
30
|
-
import Button from '@material
|
|
31
|
-
import ButtonGroup from '@material
|
|
32
|
-
import FormControlLabel from '@material
|
|
33
|
-
import
|
|
34
|
-
import
|
|
29
|
+
import Box from '@mui/material/Box';
|
|
30
|
+
import Button from '@mui/material/Button';
|
|
31
|
+
import ButtonGroup from '@mui/material/ButtonGroup';
|
|
32
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
33
|
+
import Stack from '@mui/material/Stack';
|
|
34
|
+
import Switch from '@mui/material/Switch';
|
|
35
|
+
import TextField from '@mui/material/TextField';
|
|
35
36
|
|
|
36
37
|
import './demo.css';
|
|
37
38
|
|
|
@@ -56,17 +57,17 @@ export default class Page extends React.Component {
|
|
|
56
57
|
|
|
57
58
|
render() {
|
|
58
59
|
return (
|
|
59
|
-
<
|
|
60
|
+
<Stack spacing={2} mt={2}>
|
|
60
61
|
{this.renderControls()}
|
|
61
62
|
{this.renderChessboard()}
|
|
62
63
|
{this.renderCode()}
|
|
63
|
-
</
|
|
64
|
+
</Stack>
|
|
64
65
|
);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
renderControls() {
|
|
68
69
|
return (<>
|
|
69
|
-
<
|
|
70
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
70
71
|
<FormControlLabel label="Flip"
|
|
71
72
|
control={<Switch checked={this.state.flipped} onChange={() => this.set('flipped', !this.state.flipped)} color="primary" />}
|
|
72
73
|
/>
|
|
@@ -76,23 +77,21 @@ export default class Page extends React.Component {
|
|
|
76
77
|
<FormControlLabel label="Animation" disabled={!this.state.positionAfter}
|
|
77
78
|
control={<Switch checked={this.state.animated} onChange={() => this.set('animated', !this.state.animated)} color="primary" />}
|
|
78
79
|
/>
|
|
79
|
-
</
|
|
80
|
-
<
|
|
81
|
-
<TextField label="Move" value={this.state.editedMove} onChange={evt => this.set('editedMove', evt.target.value)} />
|
|
80
|
+
</Stack>
|
|
81
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
82
|
+
<TextField label="Move" variant="standard" value={this.state.editedMove} onChange={evt => this.set('editedMove', evt.target.value)} />
|
|
82
83
|
<Button color="primary" size="small" variant="contained" onClick={() => this.handlePlayClicked()}>Play</Button>
|
|
83
|
-
<
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
</Box>
|
|
89
|
-
</Box>
|
|
84
|
+
<ButtonGroup color="primary" size="small">
|
|
85
|
+
<Button onClick={() => this.setPosition(new kokopu.Position('empty'))}>Clear</Button>
|
|
86
|
+
<Button onClick={() => this.setPosition(new kokopu.Position())}>Reset</Button>
|
|
87
|
+
</ButtonGroup>
|
|
88
|
+
</Stack>
|
|
90
89
|
</>);
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
renderChessboard() {
|
|
94
93
|
return (
|
|
95
|
-
<Box
|
|
94
|
+
<Box>
|
|
96
95
|
<Chessboard
|
|
97
96
|
position={this.state.position}
|
|
98
97
|
move={this.state.playedMove}
|
|
@@ -115,13 +114,7 @@ export default class Page extends React.Component {
|
|
|
115
114
|
}
|
|
116
115
|
attributes.push(`moveArrowVisible={${this.state.moveArrowVisible}}`);
|
|
117
116
|
attributes.push(`animated={${this.state.animated}}`);
|
|
118
|
-
return (
|
|
119
|
-
<Box my={2}>
|
|
120
|
-
<pre className="kokopu-demoCode">
|
|
121
|
-
{buildComponentDemoCode('Chessboard', attributes)}
|
|
122
|
-
</pre>
|
|
123
|
-
</Box>
|
|
124
|
-
);
|
|
117
|
+
return <pre className="kokopu-demoCode">{buildComponentDemoCode('Chessboard', attributes)}</pre>;
|
|
125
118
|
}
|
|
126
119
|
|
|
127
120
|
set(attributeName, newValue) {
|
|
@@ -25,8 +25,9 @@ import React from 'react';
|
|
|
25
25
|
import { Chessboard } from '../../src/index';
|
|
26
26
|
import { buildComponentDemoCode } from './util';
|
|
27
27
|
|
|
28
|
-
import Box from '@material
|
|
29
|
-
import
|
|
28
|
+
import Box from '@mui/material/Box';
|
|
29
|
+
import Stack from '@mui/material/Stack';
|
|
30
|
+
import Typography from '@mui/material/Typography';
|
|
30
31
|
|
|
31
32
|
import './demo.css';
|
|
32
33
|
|
|
@@ -63,17 +64,17 @@ export default class Page extends React.Component {
|
|
|
63
64
|
|
|
64
65
|
render() {
|
|
65
66
|
return (
|
|
66
|
-
<
|
|
67
|
+
<Stack spacing={2} mt={2}>
|
|
67
68
|
{this.renderControls()}
|
|
68
69
|
{this.renderChessboard()}
|
|
69
70
|
{this.renderCode()}
|
|
70
|
-
</
|
|
71
|
+
</Stack>
|
|
71
72
|
);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
renderControls() {
|
|
75
76
|
return (
|
|
76
|
-
<Box
|
|
77
|
+
<Box>
|
|
77
78
|
<Typography>Resize the browser to see the chessboard adapt its size...</Typography>
|
|
78
79
|
<Typography>{`Current browser width: ${this.state.windowWidth} px`}</Typography>
|
|
79
80
|
</Box>
|
|
@@ -82,7 +83,7 @@ export default class Page extends React.Component {
|
|
|
82
83
|
|
|
83
84
|
renderChessboard() {
|
|
84
85
|
return (
|
|
85
|
-
<Box
|
|
86
|
+
<Box>
|
|
86
87
|
<Chessboard squareSize={this.state.squareSize} smallScreenLimits={this.state.limits} />
|
|
87
88
|
</Box>
|
|
88
89
|
);
|
|
@@ -102,16 +103,14 @@ export default class Page extends React.Component {
|
|
|
102
103
|
attributes.push(`squareSize={${this.state.squareSize}}`);
|
|
103
104
|
attributes.push('smallScreenLimits={limits}');
|
|
104
105
|
return (
|
|
105
|
-
<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
</pre>
|
|
114
|
-
</Box>
|
|
106
|
+
<pre className="kokopu-demoCode">
|
|
107
|
+
{
|
|
108
|
+
'let limits = [\n' +
|
|
109
|
+
limits.join('') +
|
|
110
|
+
'];\n' +
|
|
111
|
+
buildComponentDemoCode('Chessboard', attributes)
|
|
112
|
+
}
|
|
113
|
+
</pre>
|
|
115
114
|
);
|
|
116
115
|
}
|
|
117
116
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
* *
|
|
3
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
+
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
|
+
* *
|
|
6
|
+
* This program is free software: you can redistribute it and/or *
|
|
7
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
8
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
9
|
+
* the License, or (at your option) any later version. *
|
|
10
|
+
* *
|
|
11
|
+
* This program is distributed in the hope that it will be useful, *
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
14
|
+
* GNU Lesser General Public License for more details. *
|
|
15
|
+
* *
|
|
16
|
+
* You should have received a copy of the GNU Lesser General *
|
|
17
|
+
* Public License along with this program. If not, see *
|
|
18
|
+
* <http://www.gnu.org/licenses/>. *
|
|
19
|
+
* *
|
|
20
|
+
******************************************************************************/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
import React from 'react';
|
|
24
|
+
import Styled from 'react-styleguidist/lib/client/rsg-components/Styled';
|
|
25
|
+
|
|
26
|
+
import logo from './kokopu-react-logo.png';
|
|
27
|
+
|
|
28
|
+
import './theming.css';
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const styles = ({ color, fontFamily, fontSize }) => ({
|
|
32
|
+
logo: {
|
|
33
|
+
color: color.base,
|
|
34
|
+
margin: 0,
|
|
35
|
+
fontFamily: fontFamily.base,
|
|
36
|
+
fontSize: fontSize.h4,
|
|
37
|
+
fontWeight: 'normal',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function LogoRenderer({ classes, children }) {
|
|
42
|
+
return (<>
|
|
43
|
+
<div className="kokopu-logo">
|
|
44
|
+
<img src={logo} />
|
|
45
|
+
</div>
|
|
46
|
+
<h1 className={classes.logo}>{children}</h1>
|
|
47
|
+
</>);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default Styled(styles)(LogoRenderer);
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
* *
|
|
3
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
+
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
|
+
* *
|
|
6
|
+
* This program is free software: you can redistribute it and/or *
|
|
7
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
8
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
9
|
+
* the License, or (at your option) any later version. *
|
|
10
|
+
* *
|
|
11
|
+
* This program is distributed in the hope that it will be useful, *
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
14
|
+
* GNU Lesser General Public License for more details. *
|
|
15
|
+
* *
|
|
16
|
+
* You should have received a copy of the GNU Lesser General *
|
|
17
|
+
* Public License along with this program. If not, see *
|
|
18
|
+
* <http://www.gnu.org/licenses/>. *
|
|
19
|
+
* *
|
|
20
|
+
******************************************************************************/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
.kokopu-logo {
|
|
24
|
+
text-align: center;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
footer {
|
|
28
|
+
display: none !important;
|
|
29
|
+
}
|
|
@@ -27,11 +27,13 @@ import { SquareMarkerIcon, TextMarkerIcon, ArrowMarkerIcon } from '../src/index'
|
|
|
27
27
|
testApp([ /* eslint-disable react/jsx-key */
|
|
28
28
|
<SquareMarkerIcon size={40} />,
|
|
29
29
|
<SquareMarkerIcon size={45} color="green" />,
|
|
30
|
-
<div style={{ color: 'purple' }}
|
|
30
|
+
<div style={{ color: 'purple' }}><SquareMarkerIcon size={31} /></div>,
|
|
31
31
|
<TextMarkerIcon size={41} symbol="A" />,
|
|
32
32
|
<TextMarkerIcon size={29} symbol="b" color="#0ff" />,
|
|
33
|
-
<div style={{ color: 'red' }}
|
|
33
|
+
<div style={{ color: 'red' }}><TextMarkerIcon size={53} symbol="5" /></div>,
|
|
34
34
|
<ArrowMarkerIcon size={40} />,
|
|
35
35
|
<ArrowMarkerIcon size={24} color="#888" />,
|
|
36
|
-
<div style={{ color: '#f70' }}
|
|
36
|
+
<div style={{ color: '#f70' }}><ArrowMarkerIcon size={48} /></div>,
|
|
37
|
+
<TextMarkerIcon size={47} symbol="dot" color="#00f" />,
|
|
38
|
+
<div style={{ color: 'pink' }}><TextMarkerIcon size={48} symbol="circle" /></div>,
|
|
37
39
|
]); /* eslint-enable react/jsx-key */
|
|
@@ -34,7 +34,7 @@ let textMarkers2 = { g3: { symbol: 'H', color: 'r' }, g5: { symbol: 'M', color:
|
|
|
34
34
|
|
|
35
35
|
let squareMarkers3 = { b5: 'r', e4: 'g', h5: 'y' };
|
|
36
36
|
let arrowMarkers3 = { d1h5: 'g', a5f4: 'r', c7c3: 'y', g7g7: 'g' };
|
|
37
|
-
let textMarkers3 = 'G5c6';
|
|
37
|
+
let textMarkers3 = 'G5c6,R(plus)a1,G(times)b1,R(dot)a2,Y(circle)b2';
|
|
38
38
|
|
|
39
39
|
testApp([ /* eslint-disable react/jsx-key */
|
|
40
40
|
<Chessboard squareMarkers={squareMarkers1} arrowMarkers={arrowMarkers1} textMarkers={textMarkers1} flipped={false} coordinateVisible={true} />,
|
|
@@ -34,4 +34,6 @@ testApp([ /* eslint-disable react/jsx-key */
|
|
|
34
34
|
flipped position="rnbqk2r/ppp2ppp/3p1n2/2b1p3/4P3/2NP1N2/PPP2PPP/R1BQKB1R w KQkq - 0 1" move="Bg5" animated={false} />,
|
|
35
35
|
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed}
|
|
36
36
|
position="rnbq1bnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQ - 0 1" />,
|
|
37
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed}
|
|
38
|
+
position="chess960:1r3k1r/pppppppp/8/8/8/8/PPPPPPPP/1R3K1R w BHbh - 0 1" />,
|
|
37
39
|
]); /* eslint-enable react/jsx-key */
|