@popsure/dirty-swan 0.54.3 → 0.54.4

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.
Files changed (65) hide show
  1. package/dist/cjs/index.js +74 -71
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/lib/components/table/components/TableCell/BaseCell/BaseCell.d.ts +5 -5
  4. package/dist/cjs/lib/components/table/components/TableCell/BaseCell/BaseCell.stories.d.ts +7 -7
  5. package/dist/cjs/lib/components/table/components/TableCell/ButtonCell/ButtonCell.d.ts +3 -3
  6. package/dist/cjs/lib/components/table/components/TableCell/ButtonCell/ButtonCell.stories.d.ts +4 -4
  7. package/dist/cjs/lib/components/table/components/TableCell/CTACell/CTACell.d.ts +4 -3
  8. package/dist/cjs/lib/components/table/components/TableCell/CTACell/CTACell.stories.d.ts +5 -4
  9. package/dist/cjs/lib/components/table/types.d.ts +12 -4
  10. package/dist/esm/TableSection-f6d0028e.js +80 -0
  11. package/dist/esm/TableSection-f6d0028e.js.map +1 -0
  12. package/dist/esm/components/table/Table.js +8 -13
  13. package/dist/esm/components/table/Table.js.map +1 -1
  14. package/dist/esm/components/table/Table.stories.js +61 -35
  15. package/dist/esm/components/table/Table.stories.js.map +1 -1
  16. package/dist/esm/components/table/Table.test.js +3 -6
  17. package/dist/esm/components/table/Table.test.js.map +1 -1
  18. package/dist/esm/components/table/components/TableCell/BaseCell/BaseCell.js +3 -3
  19. package/dist/esm/components/table/components/TableCell/BaseCell/BaseCell.js.map +1 -1
  20. package/dist/esm/components/table/components/TableCell/BaseCell/BaseCell.stories.js +7 -7
  21. package/dist/esm/components/table/components/TableCell/BaseCell/BaseCell.stories.js.map +1 -1
  22. package/dist/esm/components/table/components/TableCell/ButtonCell/ButtonCell.js +6 -6
  23. package/dist/esm/components/table/components/TableCell/ButtonCell/ButtonCell.js.map +1 -1
  24. package/dist/esm/components/table/components/TableCell/ButtonCell/ButtonCell.stories.js +4 -4
  25. package/dist/esm/components/table/components/TableCell/ButtonCell/ButtonCell.stories.js.map +1 -1
  26. package/dist/esm/components/table/components/TableCell/CTACell/CTACell.js +3 -3
  27. package/dist/esm/components/table/components/TableCell/CTACell/CTACell.js.map +1 -1
  28. package/dist/esm/components/table/components/TableCell/CTACell/CTACell.stories.js +5 -4
  29. package/dist/esm/components/table/components/TableCell/CTACell/CTACell.stories.js.map +1 -1
  30. package/dist/esm/components/table/components/TableCell/TableCell.js +5 -2
  31. package/dist/esm/components/table/components/TableCell/TableCell.js.map +1 -1
  32. package/dist/esm/components/table/components/TableCell/TableCell.test.js +3 -5
  33. package/dist/esm/components/table/components/TableCell/TableCell.test.js.map +1 -1
  34. package/dist/esm/components/table/components/TableContents/TableContents.js +1 -1
  35. package/dist/esm/components/table/components/TableContents/TableContents.test.js +5 -5
  36. package/dist/esm/components/table/components/TableContents/TableContents.test.js.map +1 -1
  37. package/dist/esm/components/table/components/TableSection/TableSection.js +7 -75
  38. package/dist/esm/components/table/components/TableSection/TableSection.js.map +1 -1
  39. package/dist/esm/components/table/components/TableSection/TableSection.test.js +3 -3
  40. package/dist/esm/components/table/components/TableSection/TableSection.test.js.map +1 -1
  41. package/dist/esm/index.js +1 -1
  42. package/dist/esm/lib/components/table/components/TableCell/BaseCell/BaseCell.d.ts +5 -5
  43. package/dist/esm/lib/components/table/components/TableCell/BaseCell/BaseCell.stories.d.ts +7 -7
  44. package/dist/esm/lib/components/table/components/TableCell/ButtonCell/ButtonCell.d.ts +3 -3
  45. package/dist/esm/lib/components/table/components/TableCell/ButtonCell/ButtonCell.stories.d.ts +4 -4
  46. package/dist/esm/lib/components/table/components/TableCell/CTACell/CTACell.d.ts +4 -3
  47. package/dist/esm/lib/components/table/components/TableCell/CTACell/CTACell.stories.d.ts +5 -4
  48. package/dist/esm/lib/components/table/types.d.ts +12 -4
  49. package/package.json +1 -1
  50. package/src/lib/components/table/Table.stories.tsx +61 -35
  51. package/src/lib/components/table/Table.test.tsx +2 -5
  52. package/src/lib/components/table/Table.tsx +7 -14
  53. package/src/lib/components/table/components/TableCell/BaseCell/BaseCell.stories.tsx +11 -11
  54. package/src/lib/components/table/components/TableCell/BaseCell/BaseCell.tsx +17 -19
  55. package/src/lib/components/table/components/TableCell/ButtonCell/ButtonCell.module.scss +2 -2
  56. package/src/lib/components/table/components/TableCell/ButtonCell/ButtonCell.stories.tsx +13 -13
  57. package/src/lib/components/table/components/TableCell/ButtonCell/ButtonCell.tsx +8 -8
  58. package/src/lib/components/table/components/TableCell/CTACell/CTACell.stories.tsx +9 -6
  59. package/src/lib/components/table/components/TableCell/CTACell/CTACell.tsx +9 -7
  60. package/src/lib/components/table/components/TableCell/TableCell.test.tsx +8 -7
  61. package/src/lib/components/table/components/TableCell/TableCell.tsx +5 -1
  62. package/src/lib/components/table/components/TableContents/TableContents.test.tsx +4 -4
  63. package/src/lib/components/table/components/TableSection/TableSection.test.tsx +2 -2
  64. package/src/lib/components/table/components/TableSection/TableSection.tsx +64 -65
  65. package/src/lib/components/table/types.ts +11 -4
@@ -5,58 +5,58 @@ const story = {
5
5
  component: ButtonCell,
6
6
  argTypes: {},
7
7
  args: {
8
+ buttonCaption: 'Premium',
9
+ price: '€277/mo',
8
10
  isSelected: false,
9
- content: 'Premium',
10
- subContent: '€277/mo',
11
11
  disabled: false,
12
12
  },
13
13
  };
14
14
 
15
15
  export const ButtonCellStory = ({
16
16
  isSelected,
17
- content,
18
- subContent,
17
+ buttonCaption,
18
+ price,
19
19
  disabled,
20
20
  }: React.ComponentProps<typeof ButtonCell>) => (
21
21
  <div className="p48 d-flex fd-column gap16 bg-white">
22
22
  <ButtonCell
23
- content={content}
24
- subContent={subContent}
23
+ buttonCaption={buttonCaption}
24
+ price={price}
25
25
  isSelected={isSelected}
26
26
  disabled={disabled}
27
27
  onClick={() => {}}
28
28
  />
29
29
 
30
30
  <ButtonCell
31
- content={content}
32
- subContent={subContent}
31
+ buttonCaption={buttonCaption}
32
+ price={price}
33
33
  isSelected
34
34
  disabled={disabled}
35
35
  onClick={() => {}}
36
36
  />
37
37
 
38
38
  <ButtonCell
39
- content={content}
40
- subContent={subContent}
39
+ buttonCaption={buttonCaption}
40
+ price={price}
41
41
  disabled
42
42
  onClick={() => {}}
43
43
  />
44
44
 
45
45
  <ButtonCell
46
- content={content}
46
+ buttonCaption={buttonCaption}
47
47
  isSelected={isSelected}
48
48
  disabled={disabled}
49
49
  onClick={() => {}}
50
50
  />
51
51
 
52
52
  <ButtonCell
53
- content={content}
53
+ buttonCaption={buttonCaption}
54
54
  isSelected
55
55
  disabled={disabled}
56
56
  onClick={() => {}}
57
57
  />
58
58
 
59
- <ButtonCell content={content} disabled onClick={() => {}} />
59
+ <ButtonCell buttonCaption={buttonCaption} disabled onClick={() => {}} />
60
60
  </div>
61
61
  );
62
62
 
@@ -5,18 +5,18 @@ import { Button } from '../../../../button';
5
5
  import { ReactNode } from 'react';
6
6
 
7
7
  export type ButtonCellProps = {
8
- content?: ReactNode;
8
+ buttonCaption: ReactNode;
9
9
  disabled?: boolean;
10
10
  isSelected?: boolean;
11
11
  onClick: () => void;
12
- subContent?: ReactNode;
12
+ price?: ReactNode;
13
13
  };
14
14
 
15
15
  export const ButtonCell = ({
16
16
  isSelected,
17
17
  onClick,
18
- content,
19
- subContent,
18
+ buttonCaption,
19
+ price,
20
20
  disabled,
21
21
  }: ButtonCellProps) => {
22
22
  return (
@@ -24,16 +24,16 @@ export const ButtonCell = ({
24
24
  <Button
25
25
  className={classNames('w100 wmx5 d-flex fd-column', styles.buttonCell, {
26
26
  [styles.selected]: isSelected,
27
- [styles.withoutSubContent]: !subContent,
28
- [styles.withSubContent]: !!subContent,
27
+ [styles.withoutPrice]: !price,
28
+ [styles.withPrice]: !!price,
29
29
  })}
30
30
  variant="filledWhite"
31
31
  type="submit"
32
32
  onClick={onClick}
33
33
  disabled={disabled}
34
34
  >
35
- {content}
36
- {subContent && <span className="p-p tc-purple-500">{subContent}</span>}
35
+ {buttonCaption}
36
+ {price && <span className="p-p tc-purple-500">{price}</span>}
37
37
  </Button>
38
38
  </div>
39
39
  );
@@ -5,23 +5,26 @@ const story = {
5
5
  component: CTACell,
6
6
  argTypes: {},
7
7
  args: {
8
- content: 'Premium',
9
- subContent: '€277',
8
+ title: 'Premium',
9
+ price: '€277',
10
+ buttonCaption: 'Get covered',
10
11
  grey: false,
11
12
  narrow: false,
12
13
  },
13
14
  };
14
15
 
15
16
  export const CTACellStory = ({
16
- content,
17
- subContent,
17
+ title,
18
+ price,
19
+ buttonCaption,
18
20
  grey,
19
21
  narrow,
20
22
  }: React.ComponentProps<typeof CTACell>) => (
21
23
  <div className="p48 d-flex fd-column gap16 bg-white">
22
24
  <CTACell
23
- content={content}
24
- subContent={subContent}
25
+ title={title}
26
+ price={price}
27
+ buttonCaption={buttonCaption}
25
28
  href=""
26
29
  grey={grey}
27
30
  narrow={narrow}
@@ -2,8 +2,9 @@ import classNames from 'classnames';
2
2
  import { ReactNode } from 'react';
3
3
 
4
4
  export type CTACellProps = {
5
- content?: ReactNode;
6
- subContent?: ReactNode;
5
+ title: ReactNode;
6
+ price?: ReactNode;
7
+ buttonCaption?: ReactNode;
7
8
  grey?: boolean;
8
9
  narrow?: boolean;
9
10
  href: string;
@@ -11,17 +12,18 @@ export type CTACellProps = {
11
12
  import styles from './CTACell.module.scss';
12
13
 
13
14
  export const CTACell = ({
14
- content,
15
- subContent,
15
+ title,
16
+ price,
16
17
  grey,
17
18
  narrow,
18
19
  href,
20
+ buttonCaption,
19
21
  }: CTACellProps) => {
20
22
  return (
21
23
  <div className="wmn3 ta-center">
22
24
  <p className="p-h3">
23
- {content}
24
- {subContent && <span className="tc-purple-500"> {subContent}</span>}
25
+ {title}
26
+ {price && <span className="tc-purple-500"> {price}</span>}
25
27
  </p>
26
28
  <a
27
29
  className={classNames('mt16', {
@@ -33,7 +35,7 @@ export const CTACell = ({
33
35
  target="_blank"
34
36
  rel="noopener noreferrer"
35
37
  >
36
- Get covered
38
+ {buttonCaption}
37
39
  </a>
38
40
  </div>
39
41
  );
@@ -3,17 +3,18 @@ import { TableCell, TableCellProps } from './TableCell';
3
3
 
4
4
  const openModal = jest.fn();
5
5
 
6
- const setup = ({ isNavigation, ...rest }: TableCellProps = {}) => render(
7
- isNavigation
8
- ? <TableCell {...rest} isNavigation />
9
- : (
6
+ const setup = ({ isNavigation, ...rest }: TableCellProps = {}) =>
7
+ render(
8
+ isNavigation ? (
9
+ <TableCell {...rest} isNavigation />
10
+ ) : (
10
11
  <table>
11
12
  <tbody>
12
13
  <tr>
13
14
  <TableCell {...rest} />
14
15
  </tr>
15
16
  </tbody>
16
- </table>
17
+ </table>
17
18
  )
18
19
  );
19
20
 
@@ -58,7 +59,7 @@ describe('TableCell', () => {
58
59
  });
59
60
 
60
61
  it('renders the component with text', () => {
61
- setup({ content: "Sample text" });
62
+ setup({ text: 'Sample text' });
62
63
 
63
64
  expect(screen.getByText('Sample text')).toBeInTheDocument();
64
65
  });
@@ -76,7 +77,7 @@ describe('TableCell', () => {
76
77
  });
77
78
 
78
79
  it('calls openModal when info button is clicked', () => {
79
- setup({ modalContent: "Additional information", openModal });
80
+ setup({ modalContent: 'Additional information', openModal });
80
81
 
81
82
  // Click info button
82
83
  screen.getByTestId('ds-table-info-button').click();
@@ -48,7 +48,11 @@ const TableCell = ({
48
48
  {!cellProps.type && (
49
49
  <BaseCell
50
50
  {...cellProps}
51
- contentFontVariant={isTopLeftCell ? 'BIG_WITH_UNDERLINE' : 'NORMAL'}
51
+ fontVariant={
52
+ isTopLeftCell
53
+ ? 'BIG_WITH_UNDERLINE'
54
+ : cellProps.fontVariant ?? 'NORMAL'
55
+ }
52
56
  />
53
57
  )}
54
58
  {cellProps.type === 'CTA' && <CTACell {...cellProps} />}
@@ -4,8 +4,8 @@ import { TableContents, TableContentsProps } from './TableContents';
4
4
  const mockData: TableContentsProps['tableData'] = [
5
5
  {
6
6
  rows: [
7
- [{ content: 'Item 1.1.1' }, { content: 'Item 1.1.2' }],
8
- [{ content: 'Item 1.2.1' }, { content: 'Item 1.2.2' }],
7
+ [{ text: 'Item 1.1.1' }, { text: 'Item 1.1.2' }],
8
+ [{ text: 'Item 1.2.1' }, { text: 'Item 1.2.2' }],
9
9
  ],
10
10
  },
11
11
  {
@@ -13,8 +13,8 @@ const mockData: TableContentsProps['tableData'] = [
13
13
  title: 'Section 2',
14
14
  },
15
15
  rows: [
16
- [{ content: 'Item 2.1.1' }, { content: 'Item 2.1.2' }],
17
- [{ content: 'Item 2.2.1' }, { content: 'Item 2.2.2' }],
16
+ [{ text: 'Item 2.1.1' }, { text: 'Item 2.1.2' }],
17
+ [{ text: 'Item 2.2.1' }, { text: 'Item 2.2.2' }],
18
18
  ],
19
19
  },
20
20
  ];
@@ -2,8 +2,8 @@ import { render, screen } from '../../../../util/testUtils';
2
2
  import { TableSection, TableSectionProps } from './TableSection';
3
3
 
4
4
  const tableCellRows: TableSectionProps['tableCellRows'] = [
5
- [{ content: 'Cell 1.1' }, { content: 'Cell 1.2' }, { content: 'Cell 1.3' }],
6
- [{ content: 'Cell 2.1' }, { content: 'Cell 2.2' }, { content: 'Cell 2.3' }],
5
+ [{ text: 'Cell 1.1' }, { text: 'Cell 1.2' }, { text: 'Cell 1.3' }],
6
+ [{ text: 'Cell 2.1' }, { text: 'Cell 2.2' }, { text: 'Cell 2.3' }],
7
7
  ];
8
8
 
9
9
  const mockTitle = 'Test Table';
@@ -2,9 +2,13 @@ import classNames from 'classnames';
2
2
 
3
3
  import styles from './TableSection.module.scss';
4
4
  import { TableCell, TableCellProps } from '../TableCell/TableCell';
5
- import React, { ReactNode, useCallback } from 'react';
6
- import { ModalData, ModalFunction, TableCellRowData } from '../../types';
7
- import { Alignment } from '../TableCell/BaseCell/BaseCell';
5
+ import { ReactNode, useCallback } from 'react';
6
+ import {
7
+ isBaseCell,
8
+ ModalData,
9
+ ModalFunction,
10
+ TableCellRowData,
11
+ } from '../../types';
8
12
 
9
13
  export interface TableSectionProps {
10
14
  className?: string;
@@ -25,22 +29,32 @@ const TableSection = ({
25
29
  }: TableSectionProps) => {
26
30
  const headerRow = tableCellRows?.[0];
27
31
 
28
- const getColumnContentByKey = useCallback(
29
- (key: number) => tableCellRows?.[0]?.[key]?.content || '',
30
- [tableCellRows]
31
- );
32
-
33
- const handleOpenModal = ({
34
- cellIndex,
35
- body,
36
- title,
37
- }: ModalData & {
38
- cellIndex: number;
39
- }) =>
40
- openModal?.({
41
- body,
42
- title: title || getColumnContentByKey(cellIndex),
43
- });
32
+ const getModalTitleFromColumnHeader = (cellIndex: number) => {
33
+ const firstCellInColumn = tableCellRows?.[0]?.[cellIndex];
34
+ let titleFromColumn;
35
+
36
+ switch (firstCellInColumn.type) {
37
+ case 'BUTTON':
38
+ titleFromColumn = firstCellInColumn.buttonCaption;
39
+ break;
40
+ case 'CTA':
41
+ titleFromColumn = firstCellInColumn.title;
42
+ break;
43
+ case undefined:
44
+ titleFromColumn = firstCellInColumn.text || '';
45
+ break;
46
+ }
47
+
48
+ return titleFromColumn;
49
+ };
50
+
51
+ const getModalTitleFromRowHeader = (currentRow: TableCellRowData) => {
52
+ const firstCellInRow = currentRow?.[0];
53
+ const titleFromRow =
54
+ (isBaseCell(firstCellInRow) && firstCellInRow.text) || '';
55
+
56
+ return titleFromRow;
57
+ };
44
58
 
45
59
  return (
46
60
  <table
@@ -52,35 +66,26 @@ const TableSection = ({
52
66
  {headerRow && (
53
67
  <thead className={hideHeader ? 'sr-only' : ''}>
54
68
  <tr>
55
- {headerRow.map((tableCellProps, cellIndex) => {
69
+ {headerRow.map((tableCellData, cellIndex) => {
56
70
  const isFirstCellInRow = cellIndex === 0;
57
71
 
58
- const isBaseCell = !tableCellProps.type;
59
-
60
- let openModal;
61
- let align: Alignment = 'left';
62
-
63
- if (isBaseCell) {
64
- openModal = (body: ReactNode) =>
65
- handleOpenModal({
66
- cellIndex,
67
- body,
68
- title: tableCellProps?.content,
69
- });
70
- align = isFirstCellInRow ? 'left' : 'center';
71
- }
72
-
73
72
  return (
74
73
  <TableCell
75
74
  key={cellIndex}
76
75
  isHeader
77
76
  isFirstCellInRow={isFirstCellInRow}
78
77
  isTopLeftCell={isFirstCellInRow}
79
- {...tableCellProps}
80
- {...(isBaseCell
78
+ {...tableCellData}
79
+ {...(isBaseCell(tableCellData)
81
80
  ? {
82
- openModal,
83
- align,
81
+ openModal: (body: ReactNode) =>
82
+ openModal?.({
83
+ body,
84
+ title:
85
+ tableCellData.text ||
86
+ getModalTitleFromColumnHeader(cellIndex),
87
+ }),
88
+ align: isFirstCellInRow ? 'left' : 'center',
84
89
  }
85
90
  : {})}
86
91
  />
@@ -97,40 +102,34 @@ const TableSection = ({
97
102
  return (
98
103
  rowIndex > 0 && (
99
104
  <tr key={rowIndex} className={styles.tr}>
100
- {row.map((tableCellProps, cellIndex) => {
105
+ {row.map((tableCellData, cellIndex) => {
101
106
  const key = `${rowIndex}-${cellIndex}`;
102
107
  const isFirstCellInRow = cellIndex === 0;
103
108
 
104
- const onCelInfoClick = (body: ReactNode) =>
105
- handleOpenModal({
106
- cellIndex,
107
- body,
108
- title: isFirstCellInRow
109
- ? tableCellProps.content
110
- : undefined,
111
- });
112
-
113
- let openModal;
114
- let align: Alignment = 'left';
115
-
116
- const isBaseCell = !tableCellProps.type;
117
-
118
- if (isBaseCell) {
119
- openModal = onCelInfoClick;
120
- align = isFirstCellInRow ? 'left' : 'center';
121
- }
122
-
123
109
  return (
124
110
  <TableCell
125
- {...(isBaseCell
111
+ isFirstCellInRow={isFirstCellInRow}
112
+ key={key}
113
+ {...tableCellData}
114
+ {...(isBaseCell(tableCellData)
126
115
  ? {
127
- openModal,
128
- align,
116
+ openModal: (body: ReactNode) => {
117
+ const titleFromRow =
118
+ getModalTitleFromRowHeader(row);
119
+ const titleFromColumnOrRow =
120
+ getModalTitleFromColumnHeader(cellIndex) ||
121
+ getModalTitleFromRowHeader(row);
122
+
123
+ return openModal?.({
124
+ body,
125
+ title: isFirstCellInRow
126
+ ? titleFromRow
127
+ : titleFromColumnOrRow,
128
+ });
129
+ },
130
+ align: isFirstCellInRow ? 'left' : 'center',
129
131
  }
130
132
  : {})}
131
- isFirstCellInRow={isFirstCellInRow}
132
- key={key}
133
- {...tableCellProps}
134
133
  />
135
134
  );
136
135
  })}
@@ -3,10 +3,17 @@ import { BaseCellProps } from './components/TableCell/BaseCell/BaseCell';
3
3
  import { CTACellProps } from './components/TableCell/CTACell/CTACell';
4
4
  import { ButtonCellProps } from './components/TableCell/ButtonCell/ButtonCell';
5
5
 
6
- export type TableCellData =
7
- | (BaseCellProps & { type?: undefined })
8
- | (CTACellProps & { type: 'CTA' })
9
- | (ButtonCellProps & { type: 'BUTTON' });
6
+ type BaseCellData = BaseCellProps & { type?: undefined; cellId?: string };
7
+ type CTACellData = CTACellProps & { type: 'CTA'; cellId?: string };
8
+ type ButtonCellData = ButtonCellProps & { type: 'BUTTON'; cellId?: string };
9
+
10
+ export type TableCellData = BaseCellData | CTACellData | ButtonCellData;
11
+
12
+ export const isBaseCell = (
13
+ tableCellData: TableCellData
14
+ ): tableCellData is BaseCellData => {
15
+ return !tableCellData.type;
16
+ };
10
17
 
11
18
  export type TableSectionType = {
12
19
  title?: string;