@coreui/react 4.2.3 → 4.3.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.
@@ -1,5 +1,10 @@
1
1
  import React, { TableHTMLAttributes } from 'react';
2
2
  import { Colors } from '../Types';
3
+ import { CTableHeadProps } from './CTableHead';
4
+ import { CTableHeaderCellProps } from './CTableHeaderCell';
5
+ import { CTableDataCellProps } from './CTableDataCell';
6
+ import { CTableRowProps } from './CTableRow';
7
+ import { CTableFootProps } from './CTableFoot';
3
8
  export interface CTableProps extends Omit<TableHTMLAttributes<HTMLTableElement>, 'align'> {
4
9
  /**
5
10
  * Set the vertical aligment.
@@ -20,23 +25,63 @@ export interface CTableProps extends Omit<TableHTMLAttributes<HTMLTableElement>,
20
25
  */
21
26
  borderless?: boolean;
22
27
  /**
23
- * Put the `<caption>` on the top of the table.
28
+ * Put the caption on the top if you set `caption="top"` of the table or set the text of the table caption.
24
29
  */
25
- caption?: 'top';
30
+ caption?: 'top' | string;
31
+ /**
32
+ * Set the text of the table caption and the caption on the top of the table.
33
+ *
34
+ * @since 4.3.0
35
+ */
36
+ captionTop?: string;
26
37
  /**
27
38
  * A string of all className you want applied to the component.
28
39
  */
29
40
  className?: string;
41
+ /**
42
+ * Prop for table columns configuration. If prop is not defined, table will display columns based on the first item keys, omitting keys that begins with underscore (e.g. '_props')
43
+ *
44
+ * In columns prop each array item represents one column. Item might be specified in two ways:
45
+ * String: each item define column name equal to item value.
46
+ * Object: item is object with following keys available as column configuration:
47
+ * - key (required)(String) - define column name equal to item key.
48
+ * - label (String) - define visible label of column. If not defined, label will be generated automatically based on column name, by converting kebab-case and snake_case to individual words and capitalization of each word.
49
+ * - _props (Object) - adds classes to all cels in column, ex. _props: { scope: 'col', className: 'custom-class' },
50
+ * - _style (Object) - adds styles to the column header (useful for defining widths)
51
+ *
52
+ * @since 4.3.0
53
+ */
54
+ columns?: (string | Column)[];
30
55
  /**
31
56
  * Sets the color context of the component to one of CoreUI’s themed colors.
32
57
  *
33
58
  * @type 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string
34
59
  */
35
60
  color?: Colors;
61
+ /**
62
+ * Array of objects or strings, where each element represents one cell in the table footer.
63
+ *
64
+ * Example items:
65
+ * ['FooterCell', 'FooterCell', 'FooterCell']
66
+ * or
67
+ * [{ label: 'FooterCell', _props: { color: 'success' }, ...]
68
+ *
69
+ * @since 4.3.0
70
+ */
71
+ footer?: FooterItem[];
36
72
  /**
37
73
  * Enable a hover state on table rows within a `<CTableBody>`.
38
74
  */
39
75
  hover?: boolean;
76
+ /**
77
+ * Array of objects, where each object represents one item - row in table. Additionally, you can add style classes to each row by passing them by '_props' key and to single cell by '_cellProps'.
78
+ *
79
+ * Example item:
80
+ * { name: 'John' , age: 12, _props: { color: 'success' }, _cellProps: { age: { className: 'fw-bold'}}}
81
+ *
82
+ * @since 4.3.0
83
+ */
84
+ items?: Item[];
40
85
  /**
41
86
  * Make any table responsive across all viewports or pick a maximum breakpoint with which to have a responsive table up to.
42
87
  */
@@ -49,5 +94,39 @@ export interface CTableProps extends Omit<TableHTMLAttributes<HTMLTableElement>,
49
94
  * Add zebra-striping to any table row within the `<CTableBody>`.
50
95
  */
51
96
  striped?: boolean;
97
+ /**
98
+ * Add zebra-striping to any table column.
99
+ *
100
+ * @since 4.3.0
101
+ */
102
+ stripedColumns?: boolean;
103
+ /**
104
+ * Properties that will be passed to the table footer component.
105
+ *
106
+ * @link https://coreui.io/react/docs/components/table/#ctablefoot
107
+ * @since 4.3.0
108
+ */
109
+ tableFootProps?: CTableFootProps;
110
+ /**
111
+ * Properties that will be passed to the table head component.
112
+ *
113
+ * @link https://coreui.io/react/docs/components/table/#ctablehead
114
+ * @since 4.3.0
115
+ */
116
+ tableHeadProps?: CTableHeadProps;
117
+ }
118
+ export interface Column {
119
+ label?: string;
120
+ key: string;
121
+ _style?: any;
122
+ _props?: CTableHeaderCellProps;
123
+ }
124
+ export interface Item {
125
+ [key: string]: number | string | any;
126
+ _props?: CTableRowProps;
127
+ }
128
+ export interface FooterItem {
129
+ label?: string;
130
+ _props?: CTableDataCellProps;
52
131
  }
53
132
  export declare const CTable: React.ForwardRefExoticComponent<CTableProps & React.RefAttributes<HTMLTableElement>>;
@@ -1,6 +1,6 @@
1
- import React, { TdHTMLAttributes } from 'react';
1
+ import React, { TdHTMLAttributes, ThHTMLAttributes } from 'react';
2
2
  import { Colors } from '../Types';
3
- export interface CTableDataCellProps extends Omit<TdHTMLAttributes<HTMLTableDataCellElement>, 'align'> {
3
+ export interface CTableDataCellProps extends Omit<TdHTMLAttributes<HTMLTableCellElement>, 'align'>, Omit<ThHTMLAttributes<HTMLTableCellElement>, 'align'> {
4
4
  /**
5
5
  * Highlight a table row or cell.
6
6
  */
@@ -20,4 +20,4 @@ export interface CTableDataCellProps extends Omit<TdHTMLAttributes<HTMLTableData
20
20
  */
21
21
  color?: Colors;
22
22
  }
23
- export declare const CTableDataCell: React.ForwardRefExoticComponent<CTableDataCellProps & React.RefAttributes<HTMLTableDataCellElement>>;
23
+ export declare const CTableDataCell: React.ForwardRefExoticComponent<CTableDataCellProps & React.RefAttributes<HTMLTableCellElement>>;
@@ -1,6 +1,6 @@
1
1
  import React, { ThHTMLAttributes } from 'react';
2
2
  import { Colors } from '../Types';
3
- export interface CTableHeaderCellProps extends ThHTMLAttributes<HTMLTableHeaderCellElement> {
3
+ export interface CTableHeaderCellProps extends ThHTMLAttributes<HTMLTableCellElement> {
4
4
  /**
5
5
  * A string of all className you want applied to the component.
6
6
  */
@@ -12,4 +12,4 @@ export interface CTableHeaderCellProps extends ThHTMLAttributes<HTMLTableHeaderC
12
12
  */
13
13
  color?: Colors;
14
14
  }
15
- export declare const CTableHeaderCell: React.ForwardRefExoticComponent<CTableHeaderCellProps & React.RefAttributes<HTMLTableHeaderCellElement>>;
15
+ export declare const CTableHeaderCell: React.ForwardRefExoticComponent<CTableHeaderCellProps & React.RefAttributes<HTMLTableCellElement>>;
package/dist/index.es.js CHANGED
@@ -7917,6 +7917,9 @@ var CPopover = function (_a) {
7917
7917
  ],
7918
7918
  placement: placement,
7919
7919
  }), styles = _j.styles, attributes = _j.attributes;
7920
+ useEffect(function () {
7921
+ setVisible(visible);
7922
+ }, [visible]);
7920
7923
  var getTransitionClass = function (state) {
7921
7924
  return state === 'entering'
7922
7925
  ? 'fade'
@@ -8133,65 +8136,50 @@ CSpinner.propTypes = {
8133
8136
  };
8134
8137
  CSpinner.displayName = 'CSpinner';
8135
8138
 
8136
- var CTable = forwardRef(function (_a, ref) {
8139
+ var CTableHead = forwardRef(function (_a, ref) {
8137
8140
  var _b;
8138
- var children = _a.children, align = _a.align, borderColor = _a.borderColor, bordered = _a.bordered, borderless = _a.borderless, caption = _a.caption, className = _a.className, color = _a.color, hover = _a.hover, responsive = _a.responsive, small = _a.small, striped = _a.striped, rest = __rest(_a, ["children", "align", "borderColor", "bordered", "borderless", "caption", "className", "color", "hover", "responsive", "small", "striped"]);
8139
- var _className = classNames('table', (_b = {},
8140
- _b["align-".concat(align)] = align,
8141
- _b["caption-".concat(caption)] = caption,
8142
- _b["border-".concat(borderColor)] = borderColor,
8143
- _b['table-bordered'] = bordered,
8144
- _b['table-borderless'] = borderless,
8141
+ var children = _a.children, className = _a.className, color = _a.color, rest = __rest(_a, ["children", "className", "color"]);
8142
+ var _className = classNames((_b = {},
8145
8143
  _b["table-".concat(color)] = color,
8146
- _b['table-hover'] = hover,
8147
- _b['table-sm'] = small,
8148
- _b['table-striped'] = striped,
8149
8144
  _b), className);
8150
- return responsive ? (React__default.createElement("div", { className: typeof responsive === 'boolean' ? 'table-responsive' : "table-responsive-".concat(responsive) },
8151
- React__default.createElement("table", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children))) : (React__default.createElement("table", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8145
+ return (React__default.createElement("thead", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8152
8146
  });
8153
- CTable.propTypes = {
8154
- align: propTypes.exports.oneOf(['bottom', 'middle', 'top']),
8155
- borderColor: propTypes.exports.string,
8156
- bordered: propTypes.exports.bool,
8157
- borderless: propTypes.exports.bool,
8158
- caption: propTypes.exports.oneOf(['top']),
8147
+ CTableHead.propTypes = {
8159
8148
  children: propTypes.exports.node,
8160
8149
  className: propTypes.exports.string,
8161
8150
  color: colorPropType,
8162
- hover: propTypes.exports.bool,
8163
- responsive: propTypes.exports.oneOfType([
8164
- propTypes.exports.bool,
8165
- propTypes.exports.oneOf(['sm', 'md', 'lg', 'xl', 'xxl']),
8166
- ]),
8167
- small: propTypes.exports.bool,
8168
- striped: propTypes.exports.bool,
8169
8151
  };
8170
- CTable.displayName = 'CTable';
8152
+ CTableHead.displayName = 'CTableHead';
8171
8153
 
8172
- var CTableBody = forwardRef(function (_a, ref) {
8154
+ var CTableHeaderCell = forwardRef(function (_a, ref) {
8173
8155
  var _b;
8174
8156
  var children = _a.children, className = _a.className, color = _a.color, rest = __rest(_a, ["children", "className", "color"]);
8175
8157
  var _className = classNames((_b = {},
8176
8158
  _b["table-".concat(color)] = color,
8177
8159
  _b), className);
8178
- return (React__default.createElement("tbody", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8160
+ return (React__default.createElement("th", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8179
8161
  });
8180
- CTableBody.propTypes = {
8162
+ CTableHeaderCell.propTypes = {
8181
8163
  children: propTypes.exports.node,
8182
8164
  className: propTypes.exports.string,
8183
8165
  color: colorPropType,
8184
8166
  };
8185
- CTableBody.displayName = 'CTableBody';
8167
+ CTableHeaderCell.displayName = 'CTableHeaderCell';
8186
8168
 
8187
- var CTableCaption = forwardRef(function (_a, ref) {
8188
- var children = _a.children, props = __rest(_a, ["children"]);
8189
- return (React__default.createElement("caption", __assign({}, props, { ref: ref }), children));
8169
+ var CTableBody = forwardRef(function (_a, ref) {
8170
+ var _b;
8171
+ var children = _a.children, className = _a.className, color = _a.color, rest = __rest(_a, ["children", "className", "color"]);
8172
+ var _className = classNames((_b = {},
8173
+ _b["table-".concat(color)] = color,
8174
+ _b), className);
8175
+ return (React__default.createElement("tbody", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8190
8176
  });
8191
- CTableCaption.propTypes = {
8177
+ CTableBody.propTypes = {
8192
8178
  children: propTypes.exports.node,
8179
+ className: propTypes.exports.string,
8180
+ color: colorPropType,
8193
8181
  };
8194
- CTableCaption.displayName = 'CTableCaption';
8182
+ CTableBody.displayName = 'CTableBody';
8195
8183
 
8196
8184
  var CTableDataCell = forwardRef(function (_a, ref) {
8197
8185
  var _b;
@@ -8201,7 +8189,8 @@ var CTableDataCell = forwardRef(function (_a, ref) {
8201
8189
  _b['table-active'] = active,
8202
8190
  _b["table-".concat(color)] = color,
8203
8191
  _b), className);
8204
- return (React__default.createElement("td", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8192
+ var Component = rest.scope ? 'th' : 'td';
8193
+ return (React__default.createElement(Component, __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8205
8194
  });
8206
8195
  CTableDataCell.propTypes = {
8207
8196
  active: propTypes.exports.bool,
@@ -8212,69 +8201,126 @@ CTableDataCell.propTypes = {
8212
8201
  };
8213
8202
  CTableDataCell.displayName = 'CTableDataCell';
8214
8203
 
8215
- var CTableFoot = forwardRef(function (_a, ref) {
8204
+ var CTableRow = forwardRef(function (_a, ref) {
8216
8205
  var _b;
8217
- var children = _a.children, className = _a.className, color = _a.color, rest = __rest(_a, ["children", "className", "color"]);
8206
+ var children = _a.children, active = _a.active, align = _a.align, className = _a.className, color = _a.color, rest = __rest(_a, ["children", "active", "align", "className", "color"]);
8218
8207
  var _className = classNames((_b = {},
8208
+ _b["align-".concat(align)] = align,
8209
+ _b['table-active'] = active,
8219
8210
  _b["table-".concat(color)] = color,
8220
8211
  _b), className);
8221
- return (React__default.createElement("tfoot", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8212
+ return (React__default.createElement("tr", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8222
8213
  });
8223
- CTableFoot.propTypes = {
8214
+ CTableRow.propTypes = {
8215
+ active: propTypes.exports.bool,
8216
+ align: propTypes.exports.oneOf(['bottom', 'middle', 'top']),
8224
8217
  children: propTypes.exports.node,
8225
8218
  className: propTypes.exports.string,
8226
8219
  color: colorPropType,
8227
8220
  };
8228
- CTableFoot.displayName = 'CTableFoot';
8221
+ CTableRow.displayName = 'CTableRow';
8229
8222
 
8230
- var CTableHead = forwardRef(function (_a, ref) {
8223
+ var CTableFoot = forwardRef(function (_a, ref) {
8231
8224
  var _b;
8232
8225
  var children = _a.children, className = _a.className, color = _a.color, rest = __rest(_a, ["children", "className", "color"]);
8233
8226
  var _className = classNames((_b = {},
8234
8227
  _b["table-".concat(color)] = color,
8235
8228
  _b), className);
8236
- return (React__default.createElement("thead", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8229
+ return (React__default.createElement("tfoot", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8237
8230
  });
8238
- CTableHead.propTypes = {
8231
+ CTableFoot.propTypes = {
8239
8232
  children: propTypes.exports.node,
8240
8233
  className: propTypes.exports.string,
8241
8234
  color: colorPropType,
8242
8235
  };
8243
- CTableHead.displayName = 'CTableHead';
8236
+ CTableFoot.displayName = 'CTableFoot';
8244
8237
 
8245
- var CTableHeaderCell = forwardRef(function (_a, ref) {
8246
- var _b;
8247
- var children = _a.children, className = _a.className, color = _a.color, rest = __rest(_a, ["children", "className", "color"]);
8248
- var _className = classNames((_b = {},
8249
- _b["table-".concat(color)] = color,
8250
- _b), className);
8251
- return (React__default.createElement("th", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8238
+ var CTableCaption = forwardRef(function (_a, ref) {
8239
+ var children = _a.children, props = __rest(_a, ["children"]);
8240
+ return (React__default.createElement("caption", __assign({}, props, { ref: ref }), children));
8252
8241
  });
8253
- CTableHeaderCell.propTypes = {
8242
+ CTableCaption.propTypes = {
8254
8243
  children: propTypes.exports.node,
8255
- className: propTypes.exports.string,
8256
- color: colorPropType,
8257
8244
  };
8258
- CTableHeaderCell.displayName = 'CTableHeaderCell';
8245
+ CTableCaption.displayName = 'CTableCaption';
8259
8246
 
8260
- var CTableRow = forwardRef(function (_a, ref) {
8247
+ var CTable = forwardRef(function (_a, ref) {
8261
8248
  var _b;
8262
- var children = _a.children, active = _a.active, align = _a.align, className = _a.className, color = _a.color, rest = __rest(_a, ["children", "active", "align", "className", "color"]);
8263
- var _className = classNames((_b = {},
8249
+ var children = _a.children, align = _a.align, borderColor = _a.borderColor, bordered = _a.bordered, borderless = _a.borderless, caption = _a.caption, captionTop = _a.captionTop, className = _a.className, color = _a.color, columns = _a.columns, footer = _a.footer, hover = _a.hover, _c = _a.items, items = _c === void 0 ? [] : _c, responsive = _a.responsive, small = _a.small, striped = _a.striped, stripedColumns = _a.stripedColumns, tableFootProps = _a.tableFootProps, tableHeadProps = _a.tableHeadProps, rest = __rest(_a, ["children", "align", "borderColor", "bordered", "borderless", "caption", "captionTop", "className", "color", "columns", "footer", "hover", "items", "responsive", "small", "striped", "stripedColumns", "tableFootProps", "tableHeadProps"]);
8250
+ var _className = classNames('table', (_b = {},
8264
8251
  _b["align-".concat(align)] = align,
8265
- _b['table-active'] = active,
8252
+ _b["border-".concat(borderColor)] = borderColor,
8253
+ _b["caption-top"] = captionTop || caption === 'top',
8254
+ _b['table-bordered'] = bordered,
8255
+ _b['table-borderless'] = borderless,
8266
8256
  _b["table-".concat(color)] = color,
8257
+ _b['table-hover'] = hover,
8258
+ _b['table-sm'] = small,
8259
+ _b['table-striped'] = striped,
8260
+ _b['table-striped-columns'] = stripedColumns,
8267
8261
  _b), className);
8268
- return (React__default.createElement("tr", __assign({ className: _className ? _className : undefined }, rest, { ref: ref }), children));
8262
+ var rawColumnNames = columns
8263
+ ? columns.map(function (column) {
8264
+ if (typeof column === 'object')
8265
+ return column.key;
8266
+ else
8267
+ return column;
8268
+ })
8269
+ : Object.keys(items[0] || {}).filter(function (el) { return el.charAt(0) !== '_'; });
8270
+ var pretifyName = function (name) {
8271
+ return name
8272
+ .replace(/[-_.]/g, ' ')
8273
+ .replace(/ +/g, ' ')
8274
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
8275
+ .split(' ')
8276
+ .map(function (word) { return word.charAt(0).toUpperCase() + word.slice(1); })
8277
+ .join(' ');
8278
+ };
8279
+ var label = function (column) {
8280
+ return typeof column === 'object'
8281
+ ? column.label !== undefined
8282
+ ? column.label
8283
+ : pretifyName(column.key)
8284
+ : pretifyName(column);
8285
+ };
8286
+ var Table = function () { return (React__default.createElement("table", __assign({ className: _className }, rest, { ref: ref }),
8287
+ ((caption && caption !== 'top') || captionTop) && (React__default.createElement(CTableCaption, null, caption || captionTop)),
8288
+ columns && (React__default.createElement(CTableHead, __assign({}, tableHeadProps),
8289
+ React__default.createElement(CTableRow, null, columns.map(function (column, index) { return (React__default.createElement(CTableHeaderCell, __assign({}, (column._props && __assign({}, column._props)), (column._style && { style: __assign({}, column._style) }), { key: index }), label(column))); })))),
8290
+ items && (React__default.createElement(CTableBody, null, items.map(function (item, index) { return (React__default.createElement(CTableRow, __assign({}, (item._props && __assign({}, item._props)), { key: index }), rawColumnNames.map(function (colName, index) {
8291
+ return item[colName] ? (React__default.createElement(CTableDataCell, __assign({}, (item._cellProps && __assign(__assign({}, (item._cellProps['all'] && __assign({}, item._cellProps['all']))), (item._cellProps[colName] && __assign({}, item._cellProps[colName])))), { key: index }), item[colName])) : null;
8292
+ }))); }))),
8293
+ children,
8294
+ footer && (React__default.createElement(CTableFoot, __assign({}, tableFootProps),
8295
+ React__default.createElement(CTableRow, null, footer.map(function (item, index) { return (React__default.createElement(CTableDataCell, __assign({}, (item._props && __assign({}, item._props)), { key: index }), typeof item === 'object' ? item.label : item)); })))))); };
8296
+ return responsive ? (React__default.createElement("div", { className: typeof responsive === 'boolean' ? 'table-responsive' : "table-responsive-".concat(responsive) },
8297
+ React__default.createElement(Table, null))) : (React__default.createElement(Table, null));
8269
8298
  });
8270
- CTableRow.propTypes = {
8271
- active: propTypes.exports.bool,
8299
+ CTable.propTypes = {
8272
8300
  align: propTypes.exports.oneOf(['bottom', 'middle', 'top']),
8301
+ borderColor: propTypes.exports.string,
8302
+ bordered: propTypes.exports.bool,
8303
+ borderless: propTypes.exports.bool,
8304
+ caption: propTypes.exports.oneOfType([propTypes.exports.string, propTypes.exports.oneOf(['top'])]),
8305
+ captionTop: propTypes.exports.string,
8273
8306
  children: propTypes.exports.node,
8274
8307
  className: propTypes.exports.string,
8275
8308
  color: colorPropType,
8309
+ columns: propTypes.exports.array,
8310
+ footer: propTypes.exports.array,
8311
+ hover: propTypes.exports.bool,
8312
+ items: propTypes.exports.array,
8313
+ responsive: propTypes.exports.oneOfType([
8314
+ propTypes.exports.bool,
8315
+ propTypes.exports.oneOf(['sm', 'md', 'lg', 'xl', 'xxl']),
8316
+ ]),
8317
+ small: propTypes.exports.bool,
8318
+ striped: propTypes.exports.bool,
8319
+ stripedColumns: propTypes.exports.bool,
8320
+ tableFootProps: propTypes.exports.shape(__assign({}, CTableFoot.propTypes)),
8321
+ tableHeadProps: propTypes.exports.shape(__assign({}, CTableHead.propTypes)),
8276
8322
  };
8277
- CTableRow.displayName = 'CTableRow';
8323
+ CTable.displayName = 'CTable';
8278
8324
 
8279
8325
  var CTabContent = forwardRef(function (_a, ref) {
8280
8326
  var children = _a.children, className = _a.className, rest = __rest(_a, ["children", "className"]);