@transferwise/components 46.81.0 → 46.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/i18n/en.json +5 -0
- package/build/i18n/en.json.js +5 -0
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +5 -0
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/main.css +274 -0
- package/build/money/Money.js +5 -2
- package/build/money/Money.js.map +1 -1
- package/build/money/Money.mjs +5 -2
- package/build/money/Money.mjs.map +1 -1
- package/build/styles/main.css +274 -0
- package/build/styles/table/Table.css +274 -0
- package/build/types/money/Money.d.ts +2 -1
- package/build/types/money/Money.d.ts.map +1 -1
- package/build/types/table/Table.d.ts +23 -0
- package/build/types/table/Table.d.ts.map +1 -0
- package/build/types/table/Table.messages.d.ts +24 -0
- package/build/types/table/Table.messages.d.ts.map +1 -0
- package/build/types/table/TableCell.d.ts +40 -0
- package/build/types/table/TableCell.d.ts.map +1 -0
- package/build/types/table/TableHeader.d.ts +13 -0
- package/build/types/table/TableHeader.d.ts.map +1 -0
- package/build/types/table/TableRow.d.ts +17 -0
- package/build/types/table/TableRow.d.ts.map +1 -0
- package/build/types/table/TableStatusText.d.ts +10 -0
- package/build/types/table/TableStatusText.d.ts.map +1 -0
- package/build/types/table/index.d.ts +6 -0
- package/build/types/table/index.d.ts.map +1 -0
- package/build/types/test-utils/index.d.ts +10 -0
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/i18n/en.json +5 -0
- package/src/main.css +274 -0
- package/src/main.less +1 -0
- package/src/money/Money.tsx +9 -2
- package/src/table/Table.css +274 -0
- package/src/table/Table.less +334 -0
- package/src/table/Table.messages.ts +24 -0
- package/src/table/Table.spec.tsx +82 -0
- package/src/table/Table.story.tsx +356 -0
- package/src/table/Table.tsx +167 -0
- package/src/table/TableCell.spec.tsx +298 -0
- package/src/table/TableCell.tsx +149 -0
- package/src/table/TableHeader.spec.tsx +50 -0
- package/src/table/TableHeader.tsx +74 -0
- package/src/table/TableRow.spec.tsx +112 -0
- package/src/table/TableRow.tsx +70 -0
- package/src/table/TableStatusText.spec.tsx +53 -0
- package/src/table/TableStatusText.tsx +40 -0
- package/src/table/index.ts +11 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import TableCell, { TableCellProps } from './TableCell';
|
|
3
|
+
import Chevron from '../chevron';
|
|
4
|
+
import { Position } from '../common';
|
|
5
|
+
import { clsx } from 'clsx';
|
|
6
|
+
|
|
7
|
+
export interface TableRowType {
|
|
8
|
+
cells?: TableCellProps[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface TableRowClickableType extends TableRowType {
|
|
12
|
+
id: number | string; // `id` is mandatory for clickable rows
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TableRowProps {
|
|
16
|
+
rowData?: TableRowType | TableRowClickableType;
|
|
17
|
+
hasSeparator?: boolean;
|
|
18
|
+
children?: React.ReactNode;
|
|
19
|
+
onRowClick?: (rowData: TableRowType | TableRowClickableType) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const TableRow = ({ rowData, hasSeparator = false, children, onRowClick }: TableRowProps) => {
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
<tr
|
|
26
|
+
className={clsx('np-table-row', { 'np-table-row--clickable': !!onRowClick })}
|
|
27
|
+
data-testid="np-table-row"
|
|
28
|
+
role={onRowClick ? 'button' : undefined}
|
|
29
|
+
tabIndex={0}
|
|
30
|
+
onClick={onRowClick && rowData ? () => onRowClick(rowData) : undefined}
|
|
31
|
+
onKeyDown={({ key }) => {
|
|
32
|
+
if (onRowClick && rowData && key === 'Enter') {
|
|
33
|
+
onRowClick(rowData);
|
|
34
|
+
}
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
{rowData?.cells
|
|
38
|
+
? rowData?.cells?.map((item, index) => {
|
|
39
|
+
const itemIndex = item.cell?.text ? item.cell?.text.concat(index.toString()) : index;
|
|
40
|
+
return <TableCell key={itemIndex} {...item} />;
|
|
41
|
+
})
|
|
42
|
+
: children}
|
|
43
|
+
{onRowClick && (
|
|
44
|
+
<TableCell className="np-table-cell--action">
|
|
45
|
+
<div aria-hidden="true">
|
|
46
|
+
<Chevron orientation={Position.RIGHT} />
|
|
47
|
+
</div>
|
|
48
|
+
</TableCell>
|
|
49
|
+
)}
|
|
50
|
+
</tr>
|
|
51
|
+
{hasSeparator && (
|
|
52
|
+
<tr
|
|
53
|
+
aria-hidden="true"
|
|
54
|
+
className="np-table-row np-table-row--separator"
|
|
55
|
+
data-testid="np-table-row--separator"
|
|
56
|
+
>
|
|
57
|
+
<td
|
|
58
|
+
className="np-table-cell np-table-cell--cosmetic"
|
|
59
|
+
colSpan={onRowClick ? Number(rowData?.cells?.length) + 1 : rowData?.cells?.length}
|
|
60
|
+
data-testid="np-table-cell--cosmetic"
|
|
61
|
+
>
|
|
62
|
+
<div className="np-table-cell-separator" data-testid="np-table-cell-separator" />
|
|
63
|
+
</td>
|
|
64
|
+
</tr>
|
|
65
|
+
)}
|
|
66
|
+
</>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default TableRow;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import TableStatusText, { TableStatusTextProps } from './TableStatusText';
|
|
3
|
+
|
|
4
|
+
describe('TableStatusText Component', () => {
|
|
5
|
+
const renderComponent = (props: Partial<TableStatusTextProps> = {}) => {
|
|
6
|
+
const defaultProps: TableStatusTextProps = {
|
|
7
|
+
text: 'Status Text',
|
|
8
|
+
...props,
|
|
9
|
+
};
|
|
10
|
+
return render(<TableStatusText {...defaultProps} />);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
it('renders the text and applies the default class', () => {
|
|
14
|
+
renderComponent();
|
|
15
|
+
expect(screen.getByText('Status Text')).toBeInTheDocument();
|
|
16
|
+
expect(screen.getByText('Status Text')).toHaveClass('np-text-body-default');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('applies the custom class name', () => {
|
|
20
|
+
renderComponent({ className: 'custom-class' });
|
|
21
|
+
expect(screen.getByText('Status Text')).toHaveClass('custom-class');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('applies the default typography class when typography is not provided', () => {
|
|
25
|
+
renderComponent();
|
|
26
|
+
expect(screen.getByText('Status Text')).toHaveClass('np-text-body-default');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('applies the typography class when typography equals `default-bold`', () => {
|
|
30
|
+
renderComponent({ typography: 'default-bold' });
|
|
31
|
+
expect(screen.getByText('Status Text')).toHaveClass('np-text-body-default-bold');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('does not render any icon when status is not provided', () => {
|
|
35
|
+
renderComponent();
|
|
36
|
+
expect(screen.queryByTestId('check-icon')).not.toBeInTheDocument();
|
|
37
|
+
expect(screen.queryByTestId('alert-icon')).not.toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('applies the typography and status classes, renders the error icon when status equals `error`', () => {
|
|
41
|
+
renderComponent({ status: 'error' });
|
|
42
|
+
expect(screen.getByText('Status Text')).toHaveClass('np-text-body-default-bold');
|
|
43
|
+
expect(screen.getByText('Status Text')).toHaveClass('np-table-content--error');
|
|
44
|
+
expect(screen.getByTestId('alert-icon')).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('applies the typography and status classes, renders the success icon when status equals `success`', () => {
|
|
48
|
+
renderComponent({ status: 'success' });
|
|
49
|
+
expect(screen.getByText('Status Text')).toHaveClass('np-text-body-default-bold');
|
|
50
|
+
expect(screen.getByText('Status Text')).toHaveClass('np-table-content--success');
|
|
51
|
+
expect(screen.getByTestId('check-icon')).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AlertCircle, CheckCircle } from '@transferwise/icons';
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import Body from '../body';
|
|
5
|
+
import { Typography } from '../common';
|
|
6
|
+
|
|
7
|
+
export interface TableStatusTextProps {
|
|
8
|
+
text: string | React.ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
status?: 'success' | 'error';
|
|
11
|
+
typography?: 'default' | 'default-bold';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const TableStatusText = ({
|
|
15
|
+
text,
|
|
16
|
+
className,
|
|
17
|
+
status,
|
|
18
|
+
typography = 'default',
|
|
19
|
+
}: TableStatusTextProps) => {
|
|
20
|
+
const typographyType =
|
|
21
|
+
(status ?? typography === 'default-bold')
|
|
22
|
+
? Typography.BODY_DEFAULT_BOLD
|
|
23
|
+
: Typography.BODY_DEFAULT;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Body
|
|
27
|
+
type={typographyType}
|
|
28
|
+
className={clsx(className, {
|
|
29
|
+
'np-table-content--success': status === 'success',
|
|
30
|
+
'np-table-content--error': status === 'error',
|
|
31
|
+
})}
|
|
32
|
+
>
|
|
33
|
+
{text}
|
|
34
|
+
{status === 'success' && <CheckCircle className="tw-icon--status" data-testid="check-icon" />}
|
|
35
|
+
{status === 'error' && <AlertCircle className="tw-icon--status" data-testid="alert-icon" />}
|
|
36
|
+
</Body>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default TableStatusText;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default } from './Table';
|
|
2
|
+
export type { TableProps } from './Table';
|
|
3
|
+
export type { TableRowType, TableRowClickableType } from './TableRow';
|
|
4
|
+
export type { TableHeaderType } from './TableHeader';
|
|
5
|
+
export type {
|
|
6
|
+
TableCellLeading,
|
|
7
|
+
TableCellText,
|
|
8
|
+
TableCellCurrency,
|
|
9
|
+
TableCellStatus,
|
|
10
|
+
TableCellType,
|
|
11
|
+
} from './TableCell';
|