@ganpatiinfo/gids-web-dom-reference 11.0.0 → 13.0.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.
Files changed (132) hide show
  1. package/CHANGELOG.md +108 -1
  2. package/dist/components/GidsAdvancedTooltip/GidsAdvancedTooltip.d.ts +8 -0
  3. package/dist/components/GidsAdvancedTooltip/GidsAdvancedTooltip.d.ts.map +1 -0
  4. package/dist/components/GidsAdvancedTooltip/GidsAdvancedTooltip.js +14 -0
  5. package/dist/components/GidsAdvancedTooltip/GidsAdvancedTooltip.js.map +1 -0
  6. package/dist/components/GidsBasicTableBody/GidsBasicTableBody.d.ts +27 -3
  7. package/dist/components/GidsBasicTableBody/GidsBasicTableBody.d.ts.map +1 -1
  8. package/dist/components/GidsBasicTableBody/GidsBasicTableBody.js +22 -3
  9. package/dist/components/GidsBasicTableBody/GidsBasicTableBody.js.map +1 -1
  10. package/dist/components/GidsBasicTableHead/GidsBasicTableHead.d.ts +15 -0
  11. package/dist/components/GidsBasicTableHead/GidsBasicTableHead.d.ts.map +1 -1
  12. package/dist/components/GidsBasicTableHead/GidsBasicTableHead.js +5 -0
  13. package/dist/components/GidsBasicTableHead/GidsBasicTableHead.js.map +1 -1
  14. package/dist/components/GidsBasicTableHeader/GidsBasicTableHeader.d.ts +27 -3
  15. package/dist/components/GidsBasicTableHeader/GidsBasicTableHeader.d.ts.map +1 -1
  16. package/dist/components/GidsBasicTableHeader/GidsBasicTableHeader.js +9 -1
  17. package/dist/components/GidsBasicTableHeader/GidsBasicTableHeader.js.map +1 -1
  18. package/dist/components/GidsBasicTableRow/GidsBasicTableRow.d.ts +23 -3
  19. package/dist/components/GidsBasicTableRow/GidsBasicTableRow.d.ts.map +1 -1
  20. package/dist/components/GidsBasicTableRow/GidsBasicTableRow.js +27 -6
  21. package/dist/components/GidsBasicTableRow/GidsBasicTableRow.js.map +1 -1
  22. package/dist/components/GidsBsTable/GidsBsTable.d.ts +27 -3
  23. package/dist/components/GidsBsTable/GidsBsTable.d.ts.map +1 -1
  24. package/dist/components/GidsBsTable/GidsBsTable.js +36 -14
  25. package/dist/components/GidsBsTable/GidsBsTable.js.map +1 -1
  26. package/dist/components/GidsChartLegendItem/GidsChartLegendItem.d.ts +1 -1
  27. package/dist/components/GidsChartLegendItem/GidsChartLegendItem.d.ts.map +1 -1
  28. package/dist/components/GidsChartLegendItem/GidsChartLegendItem.js +2 -1
  29. package/dist/components/GidsChartLegendItem/GidsChartLegendItem.js.map +1 -1
  30. package/dist/components/GidsColorSwatch/GidsColorSwatch.d.ts +8 -0
  31. package/dist/components/GidsColorSwatch/GidsColorSwatch.d.ts.map +1 -0
  32. package/dist/components/GidsColorSwatch/GidsColorSwatch.js +62 -0
  33. package/dist/components/GidsColorSwatch/GidsColorSwatch.js.map +1 -0
  34. package/dist/components/GidsMatrixTable/GidsMatrixTable.d.ts +12 -0
  35. package/dist/components/GidsMatrixTable/GidsMatrixTable.d.ts.map +1 -0
  36. package/dist/components/GidsMatrixTable/GidsMatrixTable.js +70 -0
  37. package/dist/components/GidsMatrixTable/GidsMatrixTable.js.map +1 -0
  38. package/dist/components/GidsMatrixTableBody/GidsMatrixTableBody.d.ts +12 -0
  39. package/dist/components/GidsMatrixTableBody/GidsMatrixTableBody.d.ts.map +1 -0
  40. package/dist/components/GidsMatrixTableBody/GidsMatrixTableBody.js +70 -0
  41. package/dist/components/GidsMatrixTableBody/GidsMatrixTableBody.js.map +1 -0
  42. package/dist/components/GidsMdTable/GidsMdTable.d.ts +12 -2
  43. package/dist/components/GidsMdTable/GidsMdTable.d.ts.map +1 -1
  44. package/dist/components/GidsMdTable/GidsMdTable.js +3 -0
  45. package/dist/components/GidsMdTable/GidsMdTable.js.map +1 -1
  46. package/dist/components/GidsPagination/GidsPagination.d.ts +10 -0
  47. package/dist/components/GidsPagination/GidsPagination.d.ts.map +1 -1
  48. package/dist/components/GidsPagination/GidsPagination.js +5 -0
  49. package/dist/components/GidsPagination/GidsPagination.js.map +1 -1
  50. package/dist/components/GidsPaginator/GidsPaginator.d.ts +8 -0
  51. package/dist/components/GidsPaginator/GidsPaginator.d.ts.map +1 -0
  52. package/dist/components/GidsPaginator/GidsPaginator.js +154 -0
  53. package/dist/components/GidsPaginator/GidsPaginator.js.map +1 -0
  54. package/dist/components/GidsPaginatorItem/GidsPaginatorItem.d.ts +9 -0
  55. package/dist/components/GidsPaginatorItem/GidsPaginatorItem.d.ts.map +1 -0
  56. package/dist/components/GidsPaginatorItem/GidsPaginatorItem.js +33 -0
  57. package/dist/components/GidsPaginatorItem/GidsPaginatorItem.js.map +1 -0
  58. package/dist/components/GidsTable/GidsTable.d.ts +18 -0
  59. package/dist/components/GidsTable/GidsTable.d.ts.map +1 -0
  60. package/dist/components/GidsTable/GidsTable.js +96 -0
  61. package/dist/components/GidsTable/GidsTable.js.map +1 -0
  62. package/dist/components/GidsTableBody/GidsTableBody.d.ts +13 -0
  63. package/dist/components/GidsTableBody/GidsTableBody.d.ts.map +1 -0
  64. package/dist/components/GidsTableBody/GidsTableBody.js +61 -0
  65. package/dist/components/GidsTableBody/GidsTableBody.js.map +1 -0
  66. package/dist/components/GidsTableCell/GidsTableCell.d.ts +28 -0
  67. package/dist/components/GidsTableCell/GidsTableCell.d.ts.map +1 -0
  68. package/dist/components/GidsTableCell/GidsTableCell.js +146 -0
  69. package/dist/components/GidsTableCell/GidsTableCell.js.map +1 -0
  70. package/dist/components/GidsTableEntry/GidsTableEntry.d.ts +13 -0
  71. package/dist/components/GidsTableEntry/GidsTableEntry.d.ts.map +1 -0
  72. package/dist/components/GidsTableEntry/GidsTableEntry.js +305 -0
  73. package/dist/components/GidsTableEntry/GidsTableEntry.js.map +1 -0
  74. package/dist/components/GidsTableFooter/GidsTableFooter.d.ts +13 -0
  75. package/dist/components/GidsTableFooter/GidsTableFooter.d.ts.map +1 -0
  76. package/dist/components/GidsTableFooter/GidsTableFooter.js +75 -0
  77. package/dist/components/GidsTableFooter/GidsTableFooter.js.map +1 -0
  78. package/dist/components/GidsTableFooterControl/GidsTableFooterControl.d.ts +11 -0
  79. package/dist/components/GidsTableFooterControl/GidsTableFooterControl.d.ts.map +1 -0
  80. package/dist/components/GidsTableFooterControl/GidsTableFooterControl.js +97 -0
  81. package/dist/components/GidsTableFooterControl/GidsTableFooterControl.js.map +1 -0
  82. package/dist/components/GidsTableHeader/GidsTableHeader.d.ts +13 -0
  83. package/dist/components/GidsTableHeader/GidsTableHeader.d.ts.map +1 -0
  84. package/dist/components/GidsTableHeader/GidsTableHeader.js +51 -0
  85. package/dist/components/GidsTableHeader/GidsTableHeader.js.map +1 -0
  86. package/dist/components/GidsTableRow/GidsTableRow.d.ts +13 -0
  87. package/dist/components/GidsTableRow/GidsTableRow.d.ts.map +1 -0
  88. package/dist/components/GidsTableRow/GidsTableRow.js +71 -0
  89. package/dist/components/GidsTableRow/GidsTableRow.js.map +1 -0
  90. package/dist/components/GidsTableToolbar/GidsTableToolbar.d.ts +11 -0
  91. package/dist/components/GidsTableToolbar/GidsTableToolbar.d.ts.map +1 -0
  92. package/dist/components/GidsTableToolbar/GidsTableToolbar.js +92 -0
  93. package/dist/components/GidsTableToolbar/GidsTableToolbar.js.map +1 -0
  94. package/dist/components/_GidsPaginationItem/GidsPaginationItem.d.ts +10 -0
  95. package/dist/components/_GidsPaginationItem/GidsPaginationItem.d.ts.map +1 -1
  96. package/dist/components/_GidsPaginationItem/GidsPaginationItem.js +5 -0
  97. package/dist/components/_GidsPaginationItem/GidsPaginationItem.js.map +1 -1
  98. package/dist/index.d.ts +15 -1
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +15 -1
  101. package/dist/index.js.map +1 -1
  102. package/package.json +4 -4
  103. package/src/components/GidsAdvancedTooltip/GidsAdvancedTooltip.ts +42 -0
  104. package/src/components/GidsBasicTableBody/GidsBasicTableBody.ts +78 -4
  105. package/src/components/GidsBasicTableHead/GidsBasicTableHead.ts +15 -0
  106. package/src/components/GidsBasicTableHeader/GidsBasicTableHeader.ts +69 -12
  107. package/src/components/GidsBasicTableRow/GidsBasicTableRow.ts +73 -6
  108. package/src/components/GidsBsTable/GidsBsTable.ts +101 -18
  109. package/src/components/GidsChartLegendItem/GidsChartLegendItem.ts +2 -0
  110. package/src/components/GidsColorSwatch/GidsColorSwatch.ts +107 -0
  111. package/src/components/GidsMatrixTable/GidsMatrixTable.ts +167 -0
  112. package/src/components/GidsMatrixTableBody/GidsMatrixTableBody.ts +164 -0
  113. package/src/components/GidsMdTable/GidsMdTable.ts +22 -1
  114. package/src/components/GidsPagination/GidsPagination.ts +14 -2
  115. package/src/components/GidsPaginator/GidsPaginator.ts +241 -0
  116. package/src/components/GidsPaginatorItem/GidsPaginatorItem.ts +72 -0
  117. package/src/components/GidsTable/GidsTable.ts +203 -0
  118. package/src/components/GidsTableBody/GidsTableBody.ts +137 -0
  119. package/src/components/GidsTableCell/GidsTableCell.ts +276 -0
  120. package/src/components/GidsTableEntry/GidsTableEntry.ts +515 -0
  121. package/src/components/GidsTableFooter/GidsTableFooter.ts +157 -0
  122. package/src/components/GidsTableFooterControl/GidsTableFooterControl.ts +159 -0
  123. package/src/components/GidsTableHeader/GidsTableHeader.ts +116 -0
  124. package/src/components/GidsTableRow/GidsTableRow.ts +154 -0
  125. package/src/components/GidsTableToolbar/GidsTableToolbar.ts +180 -0
  126. package/src/components/_GidsPaginationItem/GidsPaginationItem.ts +14 -2
  127. package/src/index.ts +15 -1
  128. package/dist/components/GidsBasicTableCell/GidsBasicTableCell.d.ts +0 -8
  129. package/dist/components/GidsBasicTableCell/GidsBasicTableCell.d.ts.map +0 -1
  130. package/dist/components/GidsBasicTableCell/GidsBasicTableCell.js +0 -16
  131. package/dist/components/GidsBasicTableCell/GidsBasicTableCell.js.map +0 -1
  132. package/src/components/GidsBasicTableCell/GidsBasicTableCell.ts +0 -45
@@ -0,0 +1,203 @@
1
+ import {
2
+ GidsTableEntryTypographyStyle,
3
+ GidsTableWebProps,
4
+ GidsTableWebUtils,
5
+ isValidChildren,
6
+ } from '@ganpatiinfo/gids-web-shared';
7
+ import { appendAsChildren, DomChildren } from '../../utils/domUtils';
8
+ import { HtmlInputAttributes } from '../GidsInput/GidsInput';
9
+ import {
10
+ IconAppearance,
11
+ IconName,
12
+ } from '@ganpatiinfo/gids-web-theme-interface';
13
+ import {
14
+ GidsInputStatus,
15
+ GidsTableActionEvent,
16
+ GidsTableToolbarSettings,
17
+ } from '@ganpatiinfo/gids-core-shared';
18
+ import {
19
+ GidsTableToolbarDom,
20
+ GidsTableToolbarDomProps,
21
+ } from '../GidsTableToolbar/GidsTableToolbar';
22
+ import {
23
+ GidsTableHeaderActionBaseEvent,
24
+ GidsTableHeaderDom,
25
+ } from '../GidsTableHeader/GidsTableHeader';
26
+ import {
27
+ GidsTableBodyActionBaseEvent,
28
+ GidsTableBodyDom,
29
+ } from '../GidsTableBody/GidsTableBody';
30
+
31
+ const {
32
+ getGidsTableClassNames,
33
+ getCustomisedTableHeaderEntries,
34
+ getTableBodyBorder,
35
+ } = GidsTableWebUtils;
36
+
37
+ export type GidsTableToolbarBaseSettings = GidsTableToolbarSettings<
38
+ DomChildren,
39
+ Event,
40
+ Element,
41
+ HtmlInputAttributes,
42
+ GidsInputStatus
43
+ > &
44
+ Pick<
45
+ GidsTableToolbarDomProps,
46
+ 'onChange' | 'onInput' | 'onFocus' | 'onBlur' | 'onGidsSearchBarClear'
47
+ >;
48
+
49
+ type GidsTableBaseWebProps = Omit<
50
+ GidsTableWebProps<
51
+ DomChildren,
52
+ GidsTableEntryTypographyStyle,
53
+ IconName,
54
+ IconAppearance,
55
+ DomChildren,
56
+ Event,
57
+ Element,
58
+ HtmlInputAttributes
59
+ >,
60
+ 'toolbarSettings'
61
+ > & {
62
+ toolbarSettings?: GidsTableToolbarBaseSettings;
63
+ };
64
+
65
+ type GidsTableActionBaseEvent = GidsTableActionEvent<
66
+ Event,
67
+ GidsTableEntryTypographyStyle,
68
+ IconName,
69
+ IconAppearance
70
+ >;
71
+
72
+ export interface GidsTableDomProps extends GidsTableBaseWebProps {
73
+ extraClasses?: string;
74
+ onTableAction?: (event: GidsTableActionBaseEvent) => void;
75
+ }
76
+
77
+ export const GidsTableDom = ({
78
+ toolbar,
79
+ toolbarChildren,
80
+ children,
81
+ headerItems,
82
+ bodyContent,
83
+ isHeaderVisible,
84
+ isToolbarVisible,
85
+ bodySettings,
86
+ toolbarSettings,
87
+ headerSettings,
88
+ tableBorders,
89
+ tableBorderRadius,
90
+ tableBodyMaxHeight = 200,
91
+ horizontalScroll = false,
92
+ onTableAction,
93
+ extraClasses,
94
+ }: GidsTableDomProps): HTMLDivElement => {
95
+ const tableDiv = document.createElement('div');
96
+
97
+ tableDiv.className = getGidsTableClassNames(
98
+ { tableBorders, tableBorderRadius },
99
+ extraClasses,
100
+ );
101
+
102
+ /*
103
+ * Toolbar
104
+ */
105
+ if (isValidChildren(toolbar)) {
106
+ appendAsChildren(tableDiv, toolbar);
107
+ } else if (isToolbarVisible) {
108
+ tableDiv.append(
109
+ GidsTableToolbarDom({
110
+ ...toolbarSettings,
111
+ children: toolbarChildren as Element,
112
+ }),
113
+ );
114
+ }
115
+
116
+ /*
117
+ * Scroll container
118
+ */
119
+ const tableScrollContainer = document.createElement('div');
120
+
121
+ tableScrollContainer.className = [
122
+ 'gids-table__scroll-container',
123
+ horizontalScroll ? 'gids-table__scroll-container--horizontal-scroll' : '',
124
+ ]
125
+ .filter(Boolean)
126
+ .join(' ');
127
+
128
+ if (tableBodyMaxHeight) {
129
+ tableScrollContainer.style.maxHeight = `${tableBodyMaxHeight}px`;
130
+ }
131
+
132
+ /*
133
+ * Table
134
+ */
135
+ const table = document.createElement('table');
136
+
137
+ table.className = 'gids-table--main-table';
138
+
139
+ /*
140
+ * Custom children
141
+ */
142
+ if (isValidChildren(children)) {
143
+ appendAsChildren(table, children);
144
+ } else {
145
+ function onActionBtnClick(
146
+ event: GidsTableHeaderActionBaseEvent | GidsTableBodyActionBaseEvent,
147
+ ) {
148
+ if (onTableAction) {
149
+ onTableAction({
150
+ ...event,
151
+ details: {
152
+ ...event.details,
153
+ columnIndex: event?.details?.entryIndex,
154
+ },
155
+ });
156
+ }
157
+ }
158
+
159
+ /*
160
+ * Header
161
+ */
162
+ if (isHeaderVisible && headerItems && headerItems.length > 0) {
163
+ table.append(
164
+ GidsTableHeaderDom({
165
+ ...headerSettings,
166
+ headerItems: getCustomisedTableHeaderEntries({
167
+ headerItems,
168
+ tableBorders,
169
+ }),
170
+ onHeaderAction: onActionBtnClick,
171
+ }),
172
+ );
173
+ }
174
+
175
+ /*
176
+ * Body
177
+ */
178
+ if (bodyContent && bodyContent.length > 0) {
179
+ table.append(
180
+ GidsTableBodyDom({
181
+ bodyBorder: getTableBodyBorder({
182
+ tableBorders,
183
+ }),
184
+ bodyContent,
185
+ bodySettings,
186
+ onBodyAction: onActionBtnClick,
187
+ }),
188
+ );
189
+ }
190
+ }
191
+
192
+ /*
193
+ * Final DOM:
194
+ *
195
+ * tableDiv
196
+ * └── scrollContainer
197
+ * └── table
198
+ */
199
+ tableScrollContainer.appendChild(table);
200
+ tableDiv.appendChild(tableScrollContainer);
201
+
202
+ return tableDiv;
203
+ };
@@ -0,0 +1,137 @@
1
+ import {
2
+ GidsTableBodyWebProps,
3
+ GidsTableBodyWebUtils,
4
+ GidsTableEntryTypographyStyle,
5
+ isValidChildren,
6
+ } from '@ganpatiinfo/gids-web-shared';
7
+ import {
8
+ GidsTableRowActionBaseEvent,
9
+ GidsTableRowDom,
10
+ } from '../GidsTableRow/GidsTableRow';
11
+ import {
12
+ IconAppearance,
13
+ IconName,
14
+ } from '@ganpatiinfo/gids-web-theme-interface';
15
+ import { GidsTableBodyActionEvent } from '@ganpatiinfo/gids-core-shared';
16
+ import { appendAsChildren, DomChildren } from '../../utils/domUtils';
17
+
18
+ const {
19
+ getGidsTableBodyClassNames,
20
+ getConstructedTableBodyContent,
21
+ getTableBodyRowEntryBackgroundColor,
22
+ getTableBodyRowEntryContentColor,
23
+ getTableBodyRowEntryActionsBackgroundColor,
24
+ getTableBodyRowEntryActionsContentColor,
25
+ } = GidsTableBodyWebUtils;
26
+
27
+ type GidsTableBodyBaseWebProps = GidsTableBodyWebProps<
28
+ GidsTableEntryTypographyStyle,
29
+ IconName,
30
+ IconAppearance,
31
+ DomChildren
32
+ >;
33
+ export type GidsTableBodyActionBaseEvent = GidsTableBodyActionEvent<
34
+ Event,
35
+ GidsTableEntryTypographyStyle,
36
+ IconName,
37
+ IconAppearance
38
+ >;
39
+
40
+ export interface GidsTableBodyDomProps extends GidsTableBodyBaseWebProps {
41
+ extraClasses?: string;
42
+ onBodyAction?: (event: GidsTableBodyActionBaseEvent) => void;
43
+ }
44
+
45
+ export const GidsTableBodyDom = ({
46
+ bodySettings,
47
+ bodyContent = [],
48
+ bodyBorder = 'none',
49
+ children,
50
+ onBodyAction,
51
+ extraClasses,
52
+ }: GidsTableBodyDomProps): HTMLElement => {
53
+ const tableBody = document.createElement('tbody');
54
+ tableBody.className = getGidsTableBodyClassNames(extraClasses);
55
+
56
+ if (isValidChildren(children)) {
57
+ appendAsChildren(tableBody, children);
58
+ } else {
59
+ if (bodyContent && bodyContent.length > 0) {
60
+ const constructedTableBodyContent = getConstructedTableBodyContent({
61
+ bodyContent,
62
+ bodyBorder,
63
+ });
64
+
65
+ function onRowActionBtnClick({
66
+ event,
67
+ rowIndex,
68
+ }: {
69
+ event: GidsTableRowActionBaseEvent;
70
+ rowIndex: number;
71
+ }) {
72
+ if (onBodyAction) {
73
+ onBodyAction({
74
+ ...event,
75
+ details: {
76
+ ...event.details,
77
+ rowIndex,
78
+ },
79
+ });
80
+ }
81
+ }
82
+
83
+ constructedTableBodyContent.forEach((constructedBody, indexI) => {
84
+ const constructedBodyRowItems = constructedBody?.rowItems ?? [];
85
+
86
+ const rowBgColor = getTableBodyRowEntryBackgroundColor<
87
+ GidsTableEntryTypographyStyle,
88
+ IconName,
89
+ IconAppearance
90
+ >({
91
+ bodySettings,
92
+ rowIndex: indexI,
93
+ });
94
+ const rowContentColor = getTableBodyRowEntryContentColor<
95
+ GidsTableEntryTypographyStyle,
96
+ IconName,
97
+ IconAppearance
98
+ >({
99
+ bodySettings,
100
+ rowIndex: indexI,
101
+ });
102
+ const rowActionsBgColor = getTableBodyRowEntryActionsBackgroundColor<
103
+ GidsTableEntryTypographyStyle,
104
+ IconName,
105
+ IconAppearance
106
+ >({
107
+ bodySettings,
108
+ rowIndex: indexI,
109
+ });
110
+ const rowActionsContentColor = getTableBodyRowEntryActionsContentColor<
111
+ GidsTableEntryTypographyStyle,
112
+ IconName,
113
+ IconAppearance
114
+ >({
115
+ bodySettings,
116
+ rowIndex: indexI,
117
+ });
118
+
119
+ tableBody.append(
120
+ GidsTableRowDom({
121
+ ...bodySettings,
122
+ actionsBackgroundColor: rowActionsBgColor,
123
+ actionsContentColor: rowActionsContentColor,
124
+ backgroundColor: rowBgColor,
125
+ contentColor: rowContentColor,
126
+ rowType: 'body',
127
+ rows: constructedBodyRowItems,
128
+ onRowAction: (event: GidsTableRowActionBaseEvent) =>
129
+ onRowActionBtnClick({ event, rowIndex: indexI }),
130
+ }),
131
+ );
132
+ });
133
+ }
134
+ }
135
+
136
+ return tableBody;
137
+ };
@@ -0,0 +1,276 @@
1
+ import {
2
+ GidsTableCellTypographyStyle,
3
+ GidsTableCellWebProps,
4
+ GidsTableCellWebUtils,
5
+ } from '@ganpatiinfo/gids-web-shared';
6
+ import { appendAsChildren } from '../../utils/domUtils';
7
+ import {
8
+ IconAppearance,
9
+ IconName,
10
+ } from '@ganpatiinfo/gids-web-theme-interface';
11
+ import { GidsDisplayTagDom } from '../GidsDisplayTag/GidsDisplayTag';
12
+ import { GidsIconDom } from '../GidsIcon/GidsIcon';
13
+ import {
14
+ GetTableCellButtonIconNeedType,
15
+ GidsTableCellActionButtonEvent,
16
+ GidsTableCellActionButtonSharedTypes,
17
+ GidsTableCellCommonUtils,
18
+ GidsTableCellActionButtonPosition,
19
+ } from '@ganpatiinfo/gids-core-shared';
20
+ import { GidsButtonDom } from '../GidsButton/GidsButton';
21
+
22
+ const { getGidsTableCellClassNames, getGidsTableCellLabelTypographyClass } =
23
+ GidsTableCellWebUtils;
24
+ const { isTableCellActionButtonVisible, getTableCellBtnIcon } =
25
+ GidsTableCellCommonUtils;
26
+
27
+ /**
28
+ * @deprecated
29
+ * Use `GidsTableEntry` and its props and functions
30
+ */
31
+ type GidsTableCellBaseWebProps = GidsTableCellWebProps<
32
+ GidsTableCellTypographyStyle,
33
+ IconName,
34
+ IconAppearance
35
+ >;
36
+
37
+ /**
38
+ * @deprecated
39
+ * Use `GidsTableEntry` and its props and functions
40
+ */
41
+ export type GidsTableCellActionButtonBaseEvent = GidsTableCellActionButtonEvent<
42
+ Event,
43
+ GidsTableCellTypographyStyle,
44
+ IconName,
45
+ IconAppearance
46
+ >;
47
+
48
+ /**
49
+ * @deprecated
50
+ * Use `GidsTableEntry` and its props and functions
51
+ */
52
+ export interface GidsTableCellDomProps extends GidsTableCellBaseWebProps {
53
+ extraClasses?: string;
54
+ onClickCellActionBtn?: (event: GidsTableCellActionButtonBaseEvent) => void;
55
+ }
56
+
57
+ /**
58
+ * @deprecated
59
+ * Use `GidsTableEntry` and its props and functions
60
+ */
61
+ export const GidsTableCellDom = ({
62
+ id,
63
+ uniqueKey,
64
+ extraData,
65
+ label,
66
+ cellDataType = 'text',
67
+ displayTags = [],
68
+ width = 'full',
69
+ borderSides = [],
70
+ borderRadiusSides = [],
71
+ appearance = 'none',
72
+ textAlignment = 'center',
73
+ labelTypography = 'label-medium',
74
+ isHeaderCell = false,
75
+ cellPrimaryActionButtons = [],
76
+ cellSecondaryActionButtons = [],
77
+ onClickCellActionBtn,
78
+ extraClasses,
79
+ }: GidsTableCellDomProps): HTMLElement => {
80
+ const cellTag = isHeaderCell ? 'th' : 'td';
81
+ const tableCell = document.createElement(cellTag);
82
+ tableCell.className = getGidsTableCellClassNames(
83
+ { borderSides, borderRadiusSides, appearance, textAlignment, width },
84
+ extraClasses,
85
+ );
86
+
87
+ if (id) {
88
+ tableCell.setAttribute('id', id);
89
+ }
90
+
91
+ if (uniqueKey) {
92
+ tableCell.setAttribute('unique-key', uniqueKey);
93
+ }
94
+
95
+ if (extraData) {
96
+ tableCell.setAttribute('extra-data', JSON.stringify(extraData));
97
+ }
98
+
99
+ function makeCellActionBtnIcon({
100
+ cellActionBtn,
101
+ neededIconType = 'leading',
102
+ }: {
103
+ cellActionBtn?: GidsTableCellActionButtonSharedTypes<
104
+ IconName,
105
+ IconAppearance
106
+ >;
107
+ neededIconType?: GetTableCellButtonIconNeedType;
108
+ }) {
109
+ const tableCellBtnIcon = getTableCellBtnIcon<IconName, IconAppearance>({
110
+ cellActionButton: cellActionBtn,
111
+ neededIconType,
112
+ });
113
+
114
+ return tableCellBtnIcon?.cellIconName &&
115
+ tableCellBtnIcon.cellIconName.toString() !== ''
116
+ ? GidsIconDom({
117
+ name: tableCellBtnIcon.cellIconName,
118
+ size: tableCellBtnIcon.cellIconSize,
119
+ appearance: tableCellBtnIcon.cellIconAppearance,
120
+ })
121
+ : undefined;
122
+ }
123
+
124
+ function onActionBtnClick({
125
+ event,
126
+ actionBtnIndex,
127
+ actionBtnPosition,
128
+ }: {
129
+ event: Event;
130
+ actionBtnIndex: number;
131
+ actionBtnPosition: GidsTableCellActionButtonPosition;
132
+ }) {
133
+ if (onClickCellActionBtn) {
134
+ onClickCellActionBtn({
135
+ originalEvent: event,
136
+ details: {
137
+ appearance,
138
+ cellDataType,
139
+ displayTags,
140
+ label,
141
+ id,
142
+ extraData,
143
+ isHeaderCell,
144
+ uniqueKey,
145
+ actionBtnNumber: `action-btn-${actionBtnIndex + 1}`,
146
+ actionBtnIndex: actionBtnIndex,
147
+ actionBtnPosition: actionBtnPosition ?? 'secondary',
148
+ },
149
+ });
150
+ }
151
+ }
152
+
153
+ function makeCellActionButton({
154
+ cellActionBtn,
155
+ actionBtnIndex,
156
+ actionBtnPosition,
157
+ }: {
158
+ cellActionBtn?: GidsTableCellActionButtonSharedTypes<
159
+ IconName,
160
+ IconAppearance
161
+ >;
162
+ actionBtnIndex: number;
163
+ actionBtnPosition: GidsTableCellActionButtonPosition;
164
+ }) {
165
+ return GidsButtonDom({
166
+ as: 'button',
167
+ appearance: cellActionBtn?.appearance ?? 'default',
168
+ size: cellActionBtn?.size ?? 'md',
169
+ disabled: cellActionBtn?.disabled,
170
+ destructive: cellActionBtn?.destructive,
171
+ positive: cellActionBtn?.positive,
172
+ loading: cellActionBtn?.loading,
173
+ width: cellActionBtn?.width ?? 'intrinsic',
174
+ children: cellActionBtn?.buttonLabel ?? '',
175
+ type: 'button',
176
+ leadingIcon: makeCellActionBtnIcon({
177
+ cellActionBtn,
178
+ neededIconType: 'leading',
179
+ }),
180
+ trailingIcon: makeCellActionBtnIcon({
181
+ cellActionBtn,
182
+ neededIconType: 'trailing',
183
+ }),
184
+ onClick: (event: Event) =>
185
+ onActionBtnClick({ event, actionBtnIndex, actionBtnPosition }),
186
+ });
187
+ }
188
+
189
+ if (cellPrimaryActionButtons && cellPrimaryActionButtons.length > 0) {
190
+ const cellPrimaryActionBtnContainer = document.createElement('div');
191
+ cellPrimaryActionBtnContainer.className =
192
+ 'gids-table-cell__primary-action-btn-container';
193
+
194
+ Array.from({ length: cellPrimaryActionButtons.length }, (_, indexI) => {
195
+ const cellPrimaryActionBtnIndex =
196
+ cellPrimaryActionButtons.length - indexI - 1;
197
+ const cellPrimaryActionBtn =
198
+ cellPrimaryActionButtons[cellPrimaryActionBtnIndex];
199
+ const cellActionBtnVisible = isTableCellActionButtonVisible<
200
+ IconName,
201
+ IconAppearance
202
+ >(cellPrimaryActionBtn);
203
+ if (cellActionBtnVisible) {
204
+ cellPrimaryActionBtnContainer.append(
205
+ makeCellActionButton({
206
+ cellActionBtn: cellPrimaryActionBtn,
207
+ actionBtnIndex: cellPrimaryActionBtnIndex,
208
+ actionBtnPosition: 'primary',
209
+ }),
210
+ );
211
+ }
212
+ });
213
+
214
+ tableCell.appendChild(cellPrimaryActionBtnContainer);
215
+ }
216
+
217
+ if (cellDataType === 'text' && label && label !== '') {
218
+ const labelSpan = document.createElement('span');
219
+ labelSpan.textContent = label;
220
+ labelSpan.className = `${getGidsTableCellLabelTypographyClass(labelTypography)}`;
221
+
222
+ appendAsChildren(tableCell, labelSpan);
223
+ }
224
+
225
+ if (cellDataType === 'display-tag' && displayTags && displayTags.length > 0) {
226
+ const displayTagsContainer = document.createElement('div');
227
+ displayTagsContainer.className = 'gids-table-cell__display-tags-container';
228
+
229
+ displayTags.forEach((displayTag) => {
230
+ displayTagsContainer.append(
231
+ GidsDisplayTagDom({
232
+ label: displayTag?.label ?? '',
233
+ appearance: displayTag?.displayTagAppearance ?? 'subtle',
234
+ size: displayTag?.displayTagSize ?? 'xs',
235
+ icon: displayTag?.displayTagIcon
236
+ ? GidsIconDom({
237
+ name: displayTag.displayTagIcon,
238
+ size: displayTag?.displayTagSize ?? 'xs',
239
+ appearance: displayTag?.displayTagIconAppearance ?? 'regular',
240
+ })
241
+ : undefined,
242
+ color: displayTag?.displayTagColor ?? 'accent-5',
243
+ }),
244
+ );
245
+ });
246
+
247
+ appendAsChildren(tableCell, displayTagsContainer);
248
+ }
249
+
250
+ if (cellSecondaryActionButtons && cellSecondaryActionButtons.length > 0) {
251
+ const cellSecondaryActionBtnContainer = document.createElement('div');
252
+ cellSecondaryActionBtnContainer.className =
253
+ 'gids-table-cell__secondary-action-btn-container';
254
+
255
+ Array.from({ length: cellSecondaryActionButtons.length }, (_, indexJ) => {
256
+ const cellSecondaryActionBtn = cellSecondaryActionButtons[indexJ];
257
+ const cellActionBtnVisible = isTableCellActionButtonVisible<
258
+ IconName,
259
+ IconAppearance
260
+ >(cellSecondaryActionBtn);
261
+ if (cellActionBtnVisible) {
262
+ cellSecondaryActionBtnContainer.append(
263
+ makeCellActionButton({
264
+ cellActionBtn: cellSecondaryActionBtn,
265
+ actionBtnIndex: indexJ,
266
+ actionBtnPosition: 'secondary',
267
+ }),
268
+ );
269
+ }
270
+ });
271
+
272
+ tableCell.appendChild(cellSecondaryActionBtnContainer);
273
+ }
274
+
275
+ return tableCell;
276
+ };