From 0945a94b6ef7608ac3767af8dfe45c0fdeeb0a44 Mon Sep 17 00:00:00 2001 From: Xavier Balloy Date: Tue, 12 May 2020 10:01:56 +0200 Subject: [PATCH] feat(react-toolkit-table): allow to customize labels of Items --- packages/table/src/Items/Items.spec.tsx | 22 +++++- packages/table/src/Items/Items.tsx | 20 ++++- .../Items/__snapshots__/Items.spec.tsx.snap | 79 ++++++++++++++++++- .../packages/table/src/Items/Items.stories.js | 8 +- 4 files changed, 120 insertions(+), 9 deletions(-) diff --git a/packages/table/src/Items/Items.spec.tsx b/packages/table/src/Items/Items.spec.tsx index f00dec771..8b00bc3d2 100644 --- a/packages/table/src/Items/Items.spec.tsx +++ b/packages/table/src/Items/Items.spec.tsx @@ -4,7 +4,7 @@ import { create } from 'react-test-renderer'; import Items from './Items'; describe('Table.Items', () => { - it('renders correctly', () => { + it('renders correctly with default values', () => { const handleOnChangeMock = jest.fn(); handleOnChangeMock.mockImplementationOnce(() => 'My mock is called'); @@ -20,6 +20,24 @@ describe('Table.Items', () => { expect(component).toMatchSnapshot(); }); + it('renders correctly with custom values', () => { + const handleOnChangeMock = jest.fn(); + handleOnChangeMock.mockImplementationOnce(() => 'My mock is called'); + + const component = create( + + ); + + expect(component).toMatchSnapshot(); + }); + test('handleChange when value updated', () => { const handleOnChangeMock = jest.fn(); handleOnChangeMock.mockImplementationOnce(() => 'My mock is called'); @@ -32,6 +50,8 @@ describe('Table.Items', () => { onChange={handleOnChangeMock} items={[5, 10, 25, 50, 100]} id="itemid" + displayLabel="show" + elementsLabel="elements" /> ); diff --git a/packages/table/src/Items/Items.tsx b/packages/table/src/Items/Items.tsx index 5e71a7485..5d63d71c2 100644 --- a/packages/table/src/Items/Items.tsx +++ b/packages/table/src/Items/Items.tsx @@ -7,7 +7,7 @@ import { withClassModifier, WithOnChangeEvent, OnChangeCustomEvent, - compose + compose, } from '@axa-fr/react-toolkit-core'; export type ItemsComponentProps = Pick< @@ -18,6 +18,8 @@ export type ItemsComponentProps = Pick< id: string; numberItems?: number; items?: number[]; + displayLabel?: React.ReactNode; + elementsLabel?: React.ReactNode; }; const DEFAULT_CLASSNAME = 'af-paging__form'; @@ -25,6 +27,8 @@ const defaultProps: Partial = { numberItems: 10, items: [5, 10, 25, 50, 100], id: null, + displayLabel: 'Afficher', + elementsLabel: 'éléments', }; class Items extends React.PureComponent { @@ -42,7 +46,15 @@ class Items extends React.PureComponent { } render() { - const { numberItems, className, items, id } = this.props; + const { + className, + displayLabel, + elementsLabel, + id, + items, + numberItems, + } = this.props; + const content = items.map(item => (