Skip to content

Commit

Permalink
Merge pull request #285 from komarovalexander/dev
Browse files Browse the repository at this point in the history
Add noDataCell childComponent
  • Loading branch information
komarovalexander authored Feb 14, 2023
2 parents c0ce850 + c3fe92f commit a592cce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ka-table",
"version": "7.10.1",
"version": "7.11.0",
"license": "MIT",
"repository": "github:komarovalexander/ka-table",
"homepage": "https://komarovalexander.github.io/ka-table/#/overview",
Expand Down
19 changes: 19 additions & 0 deletions src/lib/Components/NoDataRow/NoDataRow.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import Enzyme, { mount } from 'enzyme';

import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import { INoDataRowProps } from '../../props';
import NoDataRow from './NoDataRow';
import React from 'react';
import ReactDOM from 'react-dom';

Enzyme.configure({ adapter: new Adapter() });

const props: INoDataRowProps = {
childComponents: {},
columns: [],
Expand All @@ -14,3 +19,17 @@ it('renders without crashing', () => {
ReactDOM.render(<NoDataRow {...props} />, div);
ReactDOM.unmountComponentAtNode(div);
});

it('custom colspan for cell', () => {
const wrapper = mount(<NoDataRow {...props} childComponents={{
noDataCell: {
elementAttributes: () => ({
colSpan: 100
})
}
}}/>, {
attachTo: document.createElement('tbody')
});
expect(wrapper.find('.ka-no-data-cell').exists()).toBeTruthy();
expect(wrapper.find('.ka-no-data-cell').prop('colSpan')).toBe(100);
});
10 changes: 6 additions & 4 deletions src/lib/Components/NoDataRow/NoDataRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';

import { INoDataRowProps } from '../../props';
import React from 'react';
import { getElementCustomization } from '../../Utils/ComponentUtils';

const NoDataRow: React.FunctionComponent<INoDataRowProps> = (props) => {
Expand All @@ -12,10 +11,13 @@ const NoDataRow: React.FunctionComponent<INoDataRowProps> = (props) => {
const { elementAttributes, content } = getElementCustomization({
className: 'ka-tr ka-no-data-row'
}, props, childComponents.noDataRow);
const { elementAttributes: cellElementAttributes, content: cellContent } = getElementCustomization({
className: 'ka-no-data-cell'
}, props, childComponents.noDataCell);
return (
<tr {...elementAttributes}>
<td className='ka-no-data-cell' colSpan={columns.length + groupColumnsCount}>
{content}
<td colSpan={columns.length + groupColumnsCount} {...cellElementAttributes}>
{content || cellContent}
</td>
</tr>
);
Expand Down
1 change: 1 addition & 0 deletions src/lib/Models/ChildComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class ChildComponents {
public headRow?: ChildComponent<IHeadRowProps>;
public loading?: ChildComponent<ILoadingProps>;
public noDataRow?: ChildComponent<INoDataRowProps>;
public noDataCell?: ChildComponent<INoDataRowProps>;
public paging?: ChildComponent<IPagingProps>;
public pagingIndex?: ChildComponent<IPagingIndexProps>;
public pagingPages?: ChildComponent<IPagingProps>;
Expand Down

0 comments on commit a592cce

Please sign in to comment.