diff --git a/README.md b/README.md index 2dbc548..68a0c66 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,21 @@ 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: { ... }, @@ -91,9 +106,16 @@ import { reducer, epics } from '@flipbyte/redux-datatable'; } }, 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: { ... }, @@ -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); @@ -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: { ... }, @@ -159,17 +190,20 @@ 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: { @@ -177,6 +211,10 @@ import { reducer, epics } from '@flipbyte/redux-datatable'; 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: { ... }, @@ -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: { ... }, @@ -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 @@ -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 | @@ -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_** @@ -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_** @@ -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_** @@ -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) diff --git a/demo/src/schema/basic.js b/demo/src/schema/basic.js index 8a56741..2f8da49 100644 --- a/demo/src/schema/basic.js +++ b/demo/src/schema/basic.js @@ -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()); } diff --git a/demo/src/schema/normalized.js b/demo/src/schema/normalized.js index 9bf5414..a2cea06 100644 --- a/demo/src/schema/normalized.js +++ b/demo/src/schema/normalized.js @@ -77,6 +77,12 @@ export default { // // } // // } // }, + // Table: { + // className: 'new-table-class' + // }, + Header: { + className: 'new-header-class' + }, ResultCount: { styles: { display: 'flex', @@ -217,6 +223,7 @@ export default { // styles: {} }, Table: { + className: 'new-table-class', styles: { // table: { // background: '#000', @@ -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()); } diff --git a/package-lock.json b/package-lock.json index c9e7c5a..46cfcfd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@flipbyte/redux-datatable", - "version": "0.7.10", + "version": "0.7.11", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6d9d296..e3e70d6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/Body.js b/src/components/Body.js index 7f6201c..0eaef17 100644 --- a/src/components/Body.js +++ b/src/components/Body.js @@ -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 (
@@ -34,10 +34,10 @@ 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) => ( - { renderCol.bind(this, rowIndex, primaryKey, schema, styles) } + { renderCol.bind(this, rowIndex, primaryKey, schema, styles, colClassName) } ); -const Body = React.forwardRef(({ top: startTop = 0 }, ref) => { +const Body = React.forwardRef(({ top: startTop = 0, config }, ref) => { const { columns, action, @@ -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)); @@ -120,7 +126,7 @@ const Body = React.forwardRef(({ top: startTop = 0 }, ref) => { return ( { range={ range } rowHeight={ rowHeight } > - { renderRow.bind(this, columns, rowHeight, styles, primaryKey, schema) } + { renderRow.bind(this, columns, rowHeight, styles, primaryKey, schema, rowClassName, colClassName) } ); }); diff --git a/src/components/Button.js b/src/components/Button.js index 56a7e2f..d07f20d 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -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 ( diff --git a/src/components/Columns.js b/src/components/Columns.js index b7d1b61..d0b1166 100644 --- a/src/components/Columns.js +++ b/src/components/Columns.js @@ -10,7 +10,11 @@ const Columns = ({ open, toggle, config: { - styles = {} + styles = {}, + className = 'rdt-toolbar-columns', + btnClassName = 'rdt-toolbar-button', + menuClassName = 'rdt-toolbar-menu', + menuItemClassName = 'rdt-toolbar-item', } }) => { const { @@ -20,30 +24,32 @@ const Columns = ({ } = useContext(ConfigContext); const visibleColumnIds = useSelector(getData(({ visibleColumnIds }) => visibleColumnIds)) || []; return ( - - -