Skip to content
This repository was archived by the owner on Feb 4, 2024. It is now read-only.

Commit 7a07078

Browse files
authored
Merge pull request #396 from samuel-gomez/refactor/table-custom
refactor(table): update table custom with table toolkit
2 parents 5ba8d05 + d04a018 commit 7a07078

37 files changed

+295
-447
lines changed

src/Layout/Layout.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.af-main {
2+
padding: 1rem;
3+
min-height: calc(100vh - (calc(var(--fullheaderHeight) + var(--footerHeight))));
4+
background: $color-gray-2;
5+
}
6+
7+
@include media-breakpoint-down(sm) {
8+
.af-main {
9+
padding: 0;
10+
}
11+
}

src/Layout/Layout.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ComponentPropsWithoutRef, ReactNode } from 'react';
2-
import withClassNameModifier from 'shared/hoc/WithClassNameModifier';
2+
import withClassNameModifier, { TwithClassNameModifier } from 'shared/hoc/WithClassNameModifier';
33
import Header from 'Layout/Header';
44
import Footer from 'Layout/Footer';
55
import TitleBar from 'Layout/TitleBar';
@@ -22,7 +22,7 @@ export type TLayout = {
2222
propsTitle?: ComponentPropsWithoutRef<typeof TitleBar>;
2323
propsFooter?: ComponentPropsWithoutRef<typeof Footer>;
2424
propsA11yMenu?: ComponentPropsWithoutRef<typeof A11yMenu>;
25-
};
25+
} & TwithClassNameModifier;
2626

2727
export type TLayoutPage = TLayout & {
2828
titleBar?: string;
@@ -37,8 +37,6 @@ const disabledDefault = {
3737
a11yMenu: false,
3838
};
3939

40-
const DEFAULT_CLASSNAME = 'af-main';
41-
4240
const Layout = withClassNameModifier(
4341
({ className, children, propsHeader, propsMenu, propsTitle, propsFooter, propsA11yMenu, fullScreen, disabled = disabledDefault }: TLayout) => (
4442
<>
@@ -52,7 +50,7 @@ const Layout = withClassNameModifier(
5250
{!disabled.footer && <Footer {...propsFooter} fullScreen={fullScreen} />}
5351
</>
5452
),
55-
DEFAULT_CLASSNAME,
53+
{ defaultClassName: 'af-main' },
5654
);
5755

5856
export default Layout;
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import { Alert } from '@axa-fr/react-toolkit-all';
22
import Modal from '@axa-fr/react-toolkit-modal-default';
33
import { ModalCommonHeader, ModalCommonBody, ModalCommonFooter, TReturnUseToggleModal } from 'shared/components/ModalCommon';
4-
import withClassNameModifier from 'shared/hoc/WithClassNameModifier';
4+
import withClassNameModifier, { TwithClassNameModifier } from 'shared/hoc/WithClassNameModifier';
55

66
/**
77
* NOTE: Ce composant est un snippet, il n'est pas utilisé dans la démo
88
*/
99

1010
type TModalConfirm = Pick<TReturnUseToggleModal, 'isOpen' | 'onCancel'> & {
1111
className?: string;
12-
};
13-
14-
const DEFAULT_CLASSNAME = 'af-modal';
12+
} & TwithClassNameModifier;
1513

1614
const ModalConfirm = withClassNameModifier(
1715
({ className, isOpen, onCancel }: TModalConfirm) => (
@@ -24,7 +22,7 @@ const ModalConfirm = withClassNameModifier(
2422
<ModalCommonFooter cancelLabel="Annuler" onCancel={onCancel} onSubmit={onCancel} confirmLabel="Valider" confirmClassModifier="" />
2523
</Modal>
2624
),
27-
DEFAULT_CLASSNAME,
25+
{ defaultClassName: 'af-modal' },
2826
);
2927

3028
export default ModalConfirm;

src/pages/Demos/Table/Table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const INITIAL_STATE = {
1919
classModifier: '',
2020
className: 'af-table',
2121
headers: [
22-
{ label: 'Prénomlll', id: 'firstname' },
22+
{ label: 'Prénom', id: 'firstname' },
2323
{
2424
label: `<span><strong>Nom</strong>
2525
<i className="glyphicon glyphicon-ok"></i></span>`,

src/shared/components/LiveCode/LiveCode.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import vsDark from 'prism-react-renderer/themes/vsDark';
22
import React from 'react';
33
import { LiveProviderProps, LiveProvider, LiveError, LivePreview } from 'react-live';
44
import * as reactTookitAll from '@axa-fr/react-toolkit-all';
5-
import withClassNameModifier from 'shared/hoc/WithClassNameModifier';
5+
import withClassNameModifier, { TwithClassNameModifier } from 'shared/hoc/WithClassNameModifier';
66
import { TReturnUseToggleModal } from '../ModalCommon';
77
import TabsLiveCode from './TabsLiveCode';
88
import Accessibility from './Accessibility';
@@ -23,7 +23,7 @@ type TLiveCode = {
2323
hideCode?: boolean;
2424
hideAccessibility?: boolean;
2525
hideReadme?: boolean;
26-
};
26+
} & TwithClassNameModifier;
2727

2828
const styleLivePreviewDefault = { background: 'white', padding: '2rem', width: '100%' } as const;
2929
const ariaLabel = 'af-accessibility' as const;
@@ -53,7 +53,7 @@ const LiveCode = withClassNameModifier(
5353
</TabsLiveCode>
5454
</article>
5555
),
56-
'af-livecode',
56+
{ defaultClassName: 'af-livecode' },
5757
);
5858

5959
export default LiveCode;
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ReactNode } from 'react';
2+
import { default as TableTk } from '@axa-fr/react-toolkit-table';
23
import Line from './Line';
34

45
export type Tcol = {
@@ -7,13 +8,14 @@ export type Tcol = {
78
children?: ReactNode;
89
classModifier?: string;
910
};
11+
1012
export type TCols = {
1113
[k: string]: Tcol;
1214
};
1315

1416
type TItems = {
1517
key: string;
16-
modifier?: string;
18+
classModifier?: string;
1719
cols: TCols;
1820
};
1921

@@ -24,12 +26,12 @@ export type TBody = {
2426
};
2527

2628
const Body = ({ items = [], children, ariaLabel = 'table-body' }: TBody) => (
27-
<tbody className="af-table__body" aria-label={ariaLabel}>
28-
{items.map(({ key, modifier, cols }) => (
29-
<Line key={key} modifier={modifier} cols={Object.entries({ ...cols })} />
29+
<TableTk.Body aria-label={ariaLabel}>
30+
{items.map(({ key, classModifier, cols }) => (
31+
<Line key={key} classModifier={classModifier} cols={Object.entries({ ...cols })} />
3032
))}
3133
{children}
32-
</tbody>
34+
</TableTk.Body>
3335
);
3436

3537
export default Body;
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import type { Tcol } from '../Body';
2-
import Line from './Line';
2+
import Line, { TLine } from './Line';
33

4-
export type TLineContainer = {
5-
className?: string;
6-
modifier?: string;
4+
export type TLineContainer = Omit<TLine, 'columns'> & {
75
LineCmpt?: typeof Line;
86
cols: [string, Tcol][];
97
};
108

11-
const LineContainer = ({ className, modifier = '', LineCmpt = Line, cols }: TLineContainer) => {
9+
const LineContainer = ({ LineCmpt = Line, cols, ...restLineProps }: TLineContainer) => {
1210
const columns = cols.map(([keyCol, value]) => ({
1311
keyCol,
1412
...value,
1513
}));
16-
return <LineCmpt className={className} modifier={modifier} columns={columns} />;
14+
return <LineCmpt {...restLineProps} columns={columns} />;
1715
};
1816

1917
export default LineContainer;
Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,21 @@
1-
import { ReactNode } from 'react';
2-
import withClassNameModifier from 'shared/hoc/WithClassNameModifier';
1+
import { ComponentPropsWithoutRef } from 'react';
2+
import { default as TableTk } from '@axa-fr/react-toolkit-table';
33
import Td, { TTdContainer } from './Td';
44

5-
type TTr = {
6-
className?: string;
7-
children: ReactNode;
8-
};
9-
const DEFAULT_CLASSNAME = 'af-table__tr';
10-
11-
const Tr = withClassNameModifier(
12-
({ className, children, ...rest }: TTr) => (
13-
<tr className={className} aria-label="table-body-line" {...rest}>
14-
{children}
15-
</tr>
16-
),
17-
DEFAULT_CLASSNAME,
18-
);
19-
20-
export type TLine = {
21-
className?: string;
5+
export type TLine = ComponentPropsWithoutRef<typeof TableTk.Tr> & {
226
columns: (TTdContainer & { keyCol: string })[];
23-
modifier?: string;
24-
children?: ReactNode;
7+
ariaLabel?: string;
258
};
269

27-
const Line = ({ className, columns = [], modifier = '', children }: TLine) => (
28-
<Tr classModifier={modifier} className={className}>
10+
const Line = ({ className, columns = [], classModifier = '', children, ariaLabel = 'table-body-line' }: TLine) => (
11+
<TableTk.Tr classModifier={classModifier} className={className} aria-label={ariaLabel}>
2912
<>
3013
{columns.map(({ keyCol, ...restTd }) => (
3114
<Td key={keyCol} {...restTd} />
3215
))}
3316
{children}
3417
</>
35-
</Tr>
18+
</TableTk.Tr>
3619
);
3720

3821
export default Line;

src/shared/components/Table/Body/Line/Td/Td.container.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import { ReactNode } from 'react';
2-
import withClassNameModifier from 'shared/hoc/WithClassNameModifier';
2+
import HelpHover, { THelpInfo } from 'shared/components/HelpInfo';
3+
import { default as TableTk } from '@axa-fr/react-toolkit-table';
34

4-
export type TTd = {
5-
className?: string;
5+
export type TTdContainer = Omit<THelpInfo, 'children'> & {
66
children?: ReactNode;
7+
label?: ReactNode;
8+
classModifier?: string;
9+
hover?: ReactNode;
10+
TdCmpt?: typeof TableTk.Td;
11+
HelpHoverCmpt?: typeof HelpHover;
712
};
813

9-
const DEFAULT_CLASSNAME = 'af-table__cell';
10-
11-
const Td = withClassNameModifier(
12-
({ className, children, ...rest }: TTd) => (
13-
<td {...rest} className={className}>
14+
const TdContainer = ({ children, label, hover, classModifier, TdCmpt = TableTk.Td, HelpHoverCmpt = HelpHover }: TTdContainer) => (
15+
<TdCmpt classModifier={classModifier}>
16+
<HelpHoverCmpt content={hover} classModifier="content">
17+
{label}
1418
{children}
15-
</td>
16-
),
17-
DEFAULT_CLASSNAME,
19+
</HelpHoverCmpt>
20+
</TdCmpt>
1821
);
1922

20-
export default Td;
23+
export default TdContainer;

0 commit comments

Comments
 (0)