Skip to content

Commit bdd1ba9

Browse files
authored
Merge branch 'master' into master
2 parents 241bb58 + 91a8cb2 commit bdd1ba9

File tree

15 files changed

+100
-92
lines changed

15 files changed

+100
-92
lines changed

README.md

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
[![Coverage Status](https://coveralls.io/repos/github/nadbm/react-datasheet/badge.svg)](https://coveralls.io/github/nadbm/react-datasheet)
44
# React-Datasheet
55
A simple react component to create a spreadsheet.
6-
Demo here: https://nadbm.github.io/react-datasheet/
7-
Examples are located in https://github.com/nadbm/react-datasheet/tree/master/docs/src/examples
86

7+
Demo here: https://nadbm.github.io/react-datasheet/
98

10-
Current features
9+
Examples are located in https://github.com/nadbm/react-datasheet/tree/master/docs/src/examples
1110

11+
Current features:
1212
* Select cells, copy-paste cells
1313
* Navigation using keyboard keys
1414
* Deletion using keyboard keys
@@ -19,10 +19,10 @@ Current features
1919
## Installation
2020

2121
Install from npm:
22-
```javascript
22+
```bash
2323
$ npm install react-datasheet --save
2424
```
25-
Import in your project
25+
Import in your project:
2626

2727
```javascript
2828
import ReactDataSheet from 'react-datasheet';
@@ -73,39 +73,36 @@ class App extends React.Component {
7373
There are two values that each cell shows. The first is via ```valueRenderer``` and the second is via ```dataRenderer```. When a cell is in *edit mode*, it will show the value returned from ```dataRenderer```. It needs to return a string as this value is set in an input field.
7474

7575
```jsx
76-
const grid = [
77-
[{value: 5, expr: '1 + 4'}, {value: 6, expr: '6'}],
78-
[{value: 5, expr: '1 + 4'}, {value: 5, expr: '1 + 4'}]
79-
]
80-
const onChange = (cell, i, j, newValue) => console.log("New expression :" + newValue)
81-
<ReactDataSheet
82-
data={grid}
83-
valueRenderer={(cell) => cell.value}
84-
dataRenderer={(cell) => cell.expr}
85-
onChange={}
86-
/>
87-
)
88-
}
89-
}
76+
const grid = [
77+
[{value: 5, expr: '1 + 4'}, {value: 6, expr: '6'}],
78+
[{value: 5, expr: '1 + 4'}, {value: 5, expr: '1 + 4'}]
79+
]
80+
const onChange = (cell, i, j, newValue) => console.log("New expression :" + newValue)
81+
<ReactDataSheet
82+
data={grid}
83+
valueRenderer={(cell) => cell.value}
84+
dataRenderer={(cell) => cell.expr}
85+
onChange={}
86+
/>
9087
```
9188

9289
### Cells with underlying component
9390

9491
```jsx
95-
const grid = [
96-
[{
97-
value: 5,
98-
component: (
99-
<button onClick={() => console.log("clicked")}}>
100-
Rendered
101-
</button>
102-
)
103-
}]
104-
]
105-
<ReactDataSheet
106-
data={grid}
107-
valueRenderer={(cell) => cell.value}
108-
/>
92+
const grid = [
93+
[{
94+
value: 5,
95+
component: (
96+
<button onClick={() => console.log("clicked")}}>
97+
Rendered
98+
</button>
99+
)
100+
}]
101+
]
102+
<ReactDataSheet
103+
data={grid}
104+
valueRenderer={(cell) => cell.value}
105+
/>
109106
```
110107
This renders a single cell with the value 5. Once in edit mode, the button will appear.
111108

@@ -117,6 +114,7 @@ data | Array | Array of rows and each row should contain the cell objects to dis
117114
valueRenderer | func | Method to render the value of the cell `function(cell)`. This is visible by default
118115
dataRenderer | func | Method to render the underlying value of the cell `function(cell)`. This data is visible once in edit mode.
119116
onChange | func | onChange handler: `function(cell, i, j, newValue) {}`
117+
onPaste | func | onPaste handler: `function(array) {}` If set, the function will be called with an array of rows. Each row has an array of objects containing the cell and raw pasted value. If the pasted value cannot be matched with a cell, the cell value will be undefined
120118

121119
## Cell Options
122120

@@ -126,8 +124,8 @@ Option | Type | Default | Description
126124
:--- | :--- | :--- | :--
127125
readOnly | Bool | false | Cell will never go in edit mode
128126
key | String | undefined | By default, each cell is given the key of col number and row number. This would override that key
129-
className | String | undefined | Additional class names for cells.
127+
className | String | undefined | Additional class names for cells.
130128
component | ReactElement | undefined | Insert a react element or JSX to this field. This will render on edit mode
131-
forceComponent | bool | false | Renders whats in component at all times, even when not in edit mode
129+
forceComponent | bool | false | Renders what's in component at all times, even when not in edit mode
132130
colSpan | number | 1 | The colSpan of the cell's td element
133131
rowSpan | number | 1 | The rowSpan of the cell's td element

docs/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "react-datasheet",
2+
"name": "react-datasheet-example",
33
"version": "0.1.0",
44
"private": true,
55
"homepage": "http://nadbm.github.io/react-datasheet",
@@ -9,13 +9,16 @@
99
"dependencies": {
1010
"mathjs": "^3.10.0",
1111
"react": "^15.4.2",
12+
"react-datasheet": "^1.2.3",
1213
"react-dom": "^15.4.2",
1314
"react-select": "^1.0.0-rc.3"
1415
},
1516
"scripts": {
1617
"start": "react-scripts start",
1718
"build": "react-scripts build",
1819
"test": "react-scripts test --env=jsdom",
19-
"eject": "react-scripts eject"
20+
"eject": "react-scripts eject",
21+
"predeploy": "npm run build",
22+
"deploy": "gh-pages -d build"
2023
}
2124
}

docs/public/favicon.ico

-23.1 KB
Binary file not shown.

docs/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
work correctly both with client-side routing and a non-root public URL.
1616
Learn how to configure a non-root public URL by running `npm run build`.
1717
-->
18-
<title>React App</title>
18+
<title>React Datasheet Component</title>
1919
</head>
2020
<body>
2121

docs/src/examples/BasicSheet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from 'lodash'
2-
import Datasheet from '../../../lib';
2+
import Datasheet from 'react-datasheet';
33
import React from 'react';
44

55
export default class BasicSheet extends React.Component {

docs/src/examples/ComponentSheet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import Select from 'react-select'
33
import _ from 'lodash'
4-
import Datasheet from '../../../lib';
4+
import Datasheet from 'react-datasheet';
55

66
export default class ComponentSheet extends React.Component {
77
constructor (props) {

docs/src/examples/MathSheet.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import _ from 'lodash'
3-
import Datasheet from '../../../lib';
3+
import Datasheet from 'react-datasheet';
44
import mathjs from 'mathjs';
55

66

@@ -79,7 +79,7 @@ export default class MathSheet extends React.Component {
7979
}
8080

8181
cellUpdate(state, changeCell, expr) {
82-
const scope = _.mapValues(state, (val) => isNaN(val.value) ? 0 : parseInt(val.value))
82+
const scope = _.mapValues(state, (val) => isNaN(val.value) ? 0 : parseFloat(val.value))
8383
const updatedCell = _.assign({}, changeCell, this.computeExpr(changeCell.key, expr, scope))
8484
state[changeCell.key] = updatedCell
8585

docs/src/index.css

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ body {
5050
}
5151

5252
.container {
53-
width: 600px;
53+
max-width: 600px;
5454
margin: auto;
5555
}
5656
table.data-grid {
@@ -74,15 +74,17 @@ table.data-grid {
7474
.sheet-container {
7575
display: block;
7676
padding: 5px;
77-
box-shadow: 0px 0px 2px #CCC;
77+
78+
box-shadow: 2px 4px 6px #CCC;
7879
margin: auto;
7980
width: 500px;
8081
margin-top: 20px;
81-
transition: box-shadow 0.2s ease-in;
82+
transition: box-shadow 0.5s ease-in;
8283
}
8384
.sheet-container:hover {
84-
transition: box-shadow 0.5s ease-in;
85-
box-shadow: 2px 4px 6px #CCC;
85+
transition: box-shadow 0.2s ease-in;
86+
87+
box-shadow: 0px 0px 2px #CCC;
8688
}
8789
.sheet-container table.data-grid tr td.cell:not(.selected){
8890
border: 1px solid #ececec;

docs/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import App from './App';
3+
import App from './app';
44
import './index.css';
55

66
ReactDOM.render(

lib/DataSheet.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,30 +140,28 @@ var DataSheet = function (_PureComponent) {
140140
value: function handlePaste(e) {
141141
var _this2 = this;
142142

143-
var pasteData = e.clipboardData.getData('text/plain').split('\n').map(function (row) {
143+
this.dgDom.removeEventListener('paste', this.handlePaste);
144+
145+
var start = this.state.start;
146+
var pastedMap = [];
147+
var pasteData = e.clipboardData.getData('text/plain').split(/\n|\r/).map(function (row) {
144148
return row.split('\t');
145149
});
146-
var columnMaps = [];
147-
var start = this.state.start;
148150

149151
pasteData.map(function (row, i) {
150-
var rowMap = [];
152+
var rowData = [];
151153
row.map(function (pastedData, j) {
152154
var cell = _this2.props.data[start.i + i] && _this2.props.data[start.i + i][start.j + j];
153-
rowMap.push({ cell: cell, data: pastedData });
155+
rowData.push({ cell: cell, data: pastedData });
154156
if (cell && !cell.readOnly && !_this2.props.onPaste) {
155157
_this2.onChange(start.i + i, start.j + j, pastedData);
156158
}
157159
});
158-
columnMaps.push(rowMap);
160+
pastedMap.push(rowData);
159161
});
160162

161-
if (this.props.onPaste) {
162-
this.props.onPaste(columnMaps);
163-
}
164-
;
163+
this.props.onPaste && this.props.onPaste(pastedMap);
165164
this.setState(this.defaultState);
166-
this.dgDom.removeEventListener('paste', this.handlePaste);
167165
}
168166
}, {
169167
key: 'handleKeyboardCellMovement',

0 commit comments

Comments
 (0)