Skip to content
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
109 changes: 89 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,38 @@ import { reducer, epics } from '@flipbyte/redux-datatable';
['Limiter', 'Spacer', 'ResultCount', 'Spacer', 'Pages'],
],
components: {
Header: {
rowClassName: 'your custom class names',
colClassName: 'your custom class names',
className: 'your custom class names',
},
Body: {
rowClassName: 'your custom class names',
colClassName: 'your custom class names',
className: 'your custom class names',
},
Filters: {
rowClassName: 'your custom class names',
colClassName: 'your custom class names',
className: 'your custom class names',
},
Loader: {
styles: {
mask: { ... },
spinner: { ... }
}
},
ResultCount: {
className: 'your custom class names',
styles: { ... }
},
Pages: {
firstClassName: 'your custom class names',
lastClassName: 'your custom class names',
nextClassName: 'your custom class names',
prevClassName: 'your custom class names',
pageNumberClassName: 'your custom class names',
activeClassName: 'your custom class names',
styles: {
first: { ... },
last: { ... },
Expand All @@ -109,6 +131,11 @@ import { reducer, epics } from '@flipbyte/redux-datatable';
hide: 'Hide editable',
save: 'Save',
},
classNames: {
show: 'your custom class names',
hide: 'your custom class names',
save: 'your custom class names',
},
save: ( config ) => ( dispatch, getState ) => {
const tableState = getState()[config.reducerName][config.name];
console.log('toolbar save click with modified data', config, tableState.modified);
Expand All @@ -127,6 +154,10 @@ import { reducer, epics } from '@flipbyte/redux-datatable';
name: 'actions',
label: 'Actions',
id: 'dropdown',
className: 'your custom class names',
btnClassName: 'your custom class names',
menuClassName: 'your custom class names',
menuItemClassName: 'your custom class names',
styles: {
button: { ... },
dropdownMenu: { ... },
Expand Down Expand Up @@ -159,24 +190,31 @@ import { reducer, epics } from '@flipbyte/redux-datatable';
SimpleButton: {
type: 'button',
label: 'Simple Button',
className: 'your custom class names',
thunk: ( config ) => ( dispatch, getState ) => { ... },
styles: { ... }
},
ResetFilters: {
type: 'reset-filters',
label: 'Reset Filters',
className: 'your custom class names',
styles: { ... }
},
Print: {
type: 'print',
label: 'Print Table',
className: 'your custom class names',
styles: { ... }
},
Columns: {
name: 'columns',
type: 'columns',
label: 'Columns',
visible: true,
className: 'your custom class names',
btnClassName: 'your custom class names',
menuClassName: 'your custom class names',
menuItemClassName: 'your custom class names',
styles: {
button: { ... },
dropdownMenu: { ... },
Expand All @@ -187,9 +225,12 @@ import { reducer, epics } from '@flipbyte/redux-datatable';
type: 'limiter',
options: [10, 20, 50, 200, 2000, 0],
default: 200,
className: 'your custom class names',
selectClassName: 'your custom class names',
styles: { ... }
},
Table: {
className: 'your custom class names',
styles: {
table: { ... },
thead: { ... },
Expand Down Expand Up @@ -359,11 +400,12 @@ Note: Check the [example](https://github.com/flipbyte/redux-datatable/blob/maste

**_Common Properties_**

| Key | Type | Required | Default | Description |
| -------- | -------- | -------- | ------- | -------------------------------------------------------------------------------------------------- |
| styles | object | false | {} | styled-component styles object or key-value pairs with values being styled-component styles object |
| renderer | function | false | - | returns a react component |
| type | string | true | - | the type of the object |
| Key | Type | Required | Default | Description |
| --------- | -------- | -------- | ------- | -------------------------------------------------------------------------------------------------- |
| styles | object | false | {} | styled-component styles object or key-value pairs with values being styled-component styles object |
| renderer | function | false | - | returns a react component |
| type | string | true | - | the type of the object |
| className | string | true | varies | html class names for top-level html element in the component |

##### Loader

Expand All @@ -382,6 +424,17 @@ No unique properties

##### Pages

**_Properties_**

| Key | Type | Required | Default | Description |
| ------------------- | ------ | -------- | ------------ | ---------------- |
| firstClassName | string | false | rdt-pg-first | html class names |
| lastClassName | string | false | rdt-pg-last | html class names |
| prevClassName | string | false | rdt-pg-prev | html class names |
| nextClassName | string | false | rdt-pg-next | html class names |
| pageNumberClassName | string | false | rdt-pg-num | html class names |
| activeClassName | string | false | active | html class names |

**_Styles object properties_**

| Key | Type | Required | Default | Description |
Expand All @@ -398,10 +451,19 @@ Toggles the table between editable and non-editable and shows a save button when

**_Properties_**

| Key | Type | Required | Default | Description |
| ------ | -------- | -------- | ----------- | ----------------------------------------------- |
| labels | object | false | check below | check below |
| save | function | false | - | ( config ) => ( dispatch, getState ) => { ... } |
| Key | Type | Required | Default | Description |
| ---------- | -------- | -------- | ----------- | ----------------------------------------------- |
| labels | object | false | check below | check below |
| save | function | false | - | ( config ) => ( dispatch, getState ) => { ... } |
| classNames | object | false | check below | check below |

**_classNames object properties_**

| Key | Type | Required | Default | Description |
| ---- | ------ | -------- | ---------------------- | ---------------- |
| show | string | false | rdt-toolbar-button | html class names |
| hide | string | false | rdt-toolbar-button | html class names |
| save | string | false | Sardt-toolbar-buttonve | html class names |

**_Labels object properties_**

Expand All @@ -423,10 +485,13 @@ Toggles the table between editable and non-editable and shows a save button when

**_Properties_**

| Key | Type | Required | Default | Description |
| ------- | ------ | -------- | ------- | ------------------------------------- |
| options | array | required | \[] | array of actions objects |
| label | string | required | - | Label for the actions dropdown button |
| Key | Type | Required | Default | Description |
| ----------------- | ------ | -------- | ------------------ | ------------------------------------- |
| options | array | true | \[] | array of actions objects |
| label | string | true | - | Label for the actions dropdown button |
| btnClassName | string | false | rdt-toolbar-button | html class names |
| menuClassName | string | false | rdt-toolbar-menu | html class names |
| menuItemClassName | string | false | rdt-toolbar-item | html class names |

**_Actions object properties_**

Expand Down Expand Up @@ -477,9 +542,12 @@ Shows the columns toggling dropdown.

**_Properties_**

| Key | Type | Required | Default | Description |
| ----- | ------ | -------- | ------- | ------------------------------------- |
| label | string | required | - | Label for the actions dropdown button |
| Key | Type | Required | Default | Description |
| ----------------- | ------ | -------- | ------------------ | ------------------------------------- |
| label | string | required | - | Label for the actions dropdown button |
| btnClassName | string | false | rdt-toolbar-button | html class names |
| menuClassName | string | false | rdt-toolbar-menu | html class names |
| menuItemClassName | string | false | rdt-toolbar-item | html class names |

**_Styles object properties_**

Expand All @@ -491,10 +559,11 @@ Shows the columns toggling dropdown.

##### Limiter (type: limiter)

| Key | Type | Required | Default | Description |
| ------- | ------- | -------- | ------- | --------------------------------------------------------------------- |
| options | array | required | \[] | array of limiter counts |
| default | integer | required | \[] | default limiter option (should be a value in the options array above) |
| Key | Type | Required | Default | Description |
| --------------- | ------- | -------- | ------------------ | --------------------------------------------------------------------- |
| options | array | required | \[] | array of limiter counts |
| default | integer | required | \[] | default limiter option (should be a value in the options array above) |
| selectClassName | string | false | rdt-limiter-select | html class names |

##### Table (type: table)

Expand Down
2 changes: 1 addition & 1 deletion demo/src/schema/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export default {
type: 'action',
name: 'edit',
label: 'Edit',
htmlClass: 'btn btn-secondary',
className: 'btn btn-secondary',
thunk: ( config ) => ( dispatch, getState ) => {
console.log('edit', config, getState());
}
Expand Down
9 changes: 8 additions & 1 deletion demo/src/schema/normalized.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export default {
// // }
// // }
// },
// Table: {
// className: 'new-table-class'
// },
Header: {
className: 'new-header-class'
},
ResultCount: {
styles: {
display: 'flex',
Expand Down Expand Up @@ -217,6 +223,7 @@ export default {
// styles: {}
},
Table: {
className: 'new-table-class',
styles: {
// table: {
// background: '#000',
Expand Down Expand Up @@ -344,7 +351,7 @@ export default {
type: 'action',
name: 'edit',
label: 'Edit',
htmlClass: 'btn btn-secondary',
className: 'btn btn-secondary',
thunk: ( config ) => ( dispatch, getState ) => {
console.log('edit', config, getState());
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flipbyte/redux-datatable",
"version": "0.7.10",
"version": "0.7.11",
"description": "React-Redux data table",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
22 changes: 14 additions & 8 deletions src/components/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { createSelector } from 'reselect';
const addElementResizeEventListener = require('element-resize-event');
const removeElementResizeEventListener = require('element-resize-event').unbind;

const renderCol = (rowIndex, primaryKey, schema, styles, column, index) => {
const renderCol = (rowIndex, primaryKey, schema, styles, colClassName, column, index) => {
const { textAlign, name, type } = column;
const ColRenderer = getRenderer(column, Renderers);
return (
<Td
key={ index }
colIndex={ index }
className={ `rdt-table-col ${name} ${type}` }
className={ `${colClassName} ${name} ${type}` }
styles={ getStyles(styles.td, 'body') }
>
<Div className="rdt-table-col-inner">
Expand All @@ -34,22 +34,22 @@ const renderCol = (rowIndex, primaryKey, schema, styles, column, index) => {
);
};

const renderRow = (columns, rowHeight, styles, primaryKey, schema, rowIndex, top) => (
const renderRow = (columns, rowHeight, styles, primaryKey, schema, rowClassName, colClassName, rowIndex, top) => (
<Tr
key={ rowIndex }
className="rdt-table-row"
className={ rowClassName }
position="absolute"
top={ top }
columns={ columns }
height={ rowHeight }
even={ rowIndex % 2 === 0 }
styles={ getStyles(styles.tr, 'body') }
>
{ renderCol.bind(this, rowIndex, primaryKey, schema, styles) }
{ renderCol.bind(this, rowIndex, primaryKey, schema, styles, colClassName) }
</Tr>
);

const Body = React.forwardRef(({ top: startTop = 0 }, ref) => {
const Body = React.forwardRef(({ top: startTop = 0, config }, ref) => {
const {
columns,
action,
Expand All @@ -68,6 +68,12 @@ const Body = React.forwardRef(({ top: startTop = 0 }, ref) => {
}
} = useContext(ConfigContext);

const {
className = 'table-body',
rowClassName = 'rdt-table-row',
colClassName = 'rdt-table-col'
} = config;

const itemCount = useSelector(getData(tableData => (tableData.items || []).length));
const isPrinting = useSelector(getData(tableData => !!tableData.isPrinting));

Expand Down Expand Up @@ -120,7 +126,7 @@ const Body = React.forwardRef(({ top: startTop = 0 }, ref) => {

return (
<Tbody
className="table-body"
className={ className }
styles={ getStyles(styles, 'tbody') }
ref={ ref }
isPrinting={ isPrinting }
Expand All @@ -130,7 +136,7 @@ const Body = React.forwardRef(({ top: startTop = 0 }, ref) => {
range={ range }
rowHeight={ rowHeight }
>
{ renderRow.bind(this, columns, rowHeight, styles, primaryKey, schema) }
{ renderRow.bind(this, columns, rowHeight, styles, primaryKey, schema, rowClassName, colClassName) }
</Tbody>
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import ConfigContext from '../context';

const Button = ({ config }) => {
const { thunk } = useContext(ConfigContext);
const { thunk: cb, label, name, styles = {} } = config;
const { thunk: cb, label, name, styles = {}, className = 'rdt-toolbar-btn' } = config;
return (
<StyledButton
className={ `rdt-toolbar-btn ${name || ''}` }
className={ className }
onClick={ cb && thunk.bind(this, cb, config) }
styles={ styles }
>
Expand Down
Loading