Skip to content
This repository was archived by the owner on Oct 24, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"printWidth" : 100,
"singleQuote" : true,
"bracketSpacing" : false,
"arrowParens": "always"
"singleQuote" : true
}
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = (api) => {
module.exports = api => {
api.cache(true);

return {
Expand Down
24 changes: 17 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default class Grid extends React.Component {

bindEventHandlers(props, prevProps) {
Object.keys(props)
.filter((key) => /on[A-Z][a-zA-Z]+/.test(key))
.forEach((key) => {
.filter(key => /on[A-Z][a-zA-Z]+/.test(key))
.forEach(key => {
const eventName = key[2].toLowerCase() + key.slice(3);
// For <Grid onFocus={condition ? onFocus1 : onFocus2} />
if (prevProps && prevProps[key] !== props[key]) {
Expand All @@ -35,21 +35,31 @@ export default class Grid extends React.Component {
}

componentDidMount() {
const {
frozenColumnCount: frozenCount = 0,
columnOptions: columnOptionsProp = {}
} = this.props;

const columnOptions = {
...columnOptionsProp,
frozenCount
};

this.gridInst = new TuiGrid({
el: this.rootEl.current,
...this.props
...this.props,
columnOptions
});

this.bindEventHandlers(this.props);
}

shouldComponentUpdate(nextProps) {
const {oneTimeBindingProps = []} = this.props;
const { oneTimeBindingProps = [] } = this.props;
const reactiveProps = Object.keys(reactivePropSetterMap).filter(
(propName) => oneTimeBindingProps.indexOf(propName) === -1
propName => oneTimeBindingProps.indexOf(propName) === -1
);

reactiveProps.forEach((propName) => {
reactiveProps.forEach(propName => {
const currentValue = this.props[propName];
const nextValue = nextProps[propName];
if (currentValue !== nextValue) {
Expand Down
34 changes: 18 additions & 16 deletions stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import React, {useCallback} from 'react';
import React, { useCallback } from 'react';
import XHRMock from 'xhr-mock';
import {storiesOf} from '@storybook/react';
import { storiesOf } from '@storybook/react';
import Grid from '../src/index';
import TuiGrid from 'tui-grid';
import {actions} from '@storybook/addon-actions';
import {withKnobs, number, radios, button, object, array} from '@storybook/addon-knobs';
import {data} from './dummy-data';
import { actions } from '@storybook/addon-actions';
import { withKnobs, number, radios, button, object, array } from '@storybook/addon-knobs';
import { data } from './dummy-data';
import 'tui-grid/dist/tui-grid.css';
import 'tui-pagination/dist/tui-pagination.css';

const columns = [
{header: 'Name', name: 'name'},
{header: 'Artist', name: 'artist'},
{header: 'Type', name: 'type', editor: 'text'},
{header: 'Release', name: 'release', editor: 'text'},
{header: 'Genre', name: 'genre', editor: 'text'}
{ header: 'Name', name: 'name' },
{ header: 'Artist', name: 'artist' },
{ header: 'Type', name: 'type', editor: 'text' },
{ header: 'Release', name: 'release', editor: 'text' },
{ header: 'Genre', name: 'genre', editor: 'text' }
];

const stories = storiesOf('Toast UI Grid', module).addDecorator(withKnobs);

stories.add('Normal', () => <Grid columns={columns} data={data} header={{height: 60}} />);
stories.add('Normal', () => <Grid columns={columns} data={data} header={{ height: 60 }} />);

stories.add('Set Language', () => {
const options = {
Expand Down Expand Up @@ -85,7 +85,7 @@ stories.add('Using Method', () => {
}

handleClickAppend = () => {
this.grid.appendRow({}, {at: 0});
this.grid.appendRow({}, { at: 0 });
};

handleClickSort = () => {
Expand Down Expand Up @@ -204,15 +204,17 @@ stories.add('dataSource', () => {
withCredentials: false,
initialRequest: true,
api: {
readData: {url: 'api/readData', method: 'GET'}
readData: { url: 'api/readData', method: 'GET' }
}
};

return <Grid columns={columns} pagination={true} data={dataSource} pageOptions={{perPage: 3}} />;
return (
<Grid columns={columns} pagination={true} data={dataSource} pageOptions={{ perPage: 3 }} />
);
});

stories.add('hook', () => {
const condition = radios('condition', {true: 'true', false: 'false'}, 'true');
const condition = radios('condition', { true: 'true', false: 'false' }, 'true');
const ReactComponent = () => {
const onClick = useCallback(() => {
console.log('condition:', condition);
Expand All @@ -225,7 +227,7 @@ stories.add('hook', () => {
});

stories.add('change event based on condition', () => {
const condition = radios('condition', {true: 'true', false: 'false'}, 'true');
const condition = radios('condition', { true: 'true', false: 'false' }, 'true');

return (
<Grid
Expand Down