@coreui/react 4.2.2 → 4.3.1

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 (34) hide show
  1. package/README.md +113 -9
  2. package/dist/components/button/CButton.d.ts +1 -1
  3. package/dist/components/dropdown/CDropdownItem.d.ts +1 -1
  4. package/dist/components/form/CFormTextarea.d.ts +2 -2
  5. package/dist/components/link/CLink.d.ts +1 -1
  6. package/dist/components/list-group/CListGroupItem.d.ts +1 -1
  7. package/dist/components/nav/CNavLink.d.ts +1 -1
  8. package/dist/components/table/CTable.d.ts +83 -4
  9. package/dist/components/table/CTableDataCell.d.ts +8 -4
  10. package/dist/components/table/CTableHeaderCell.d.ts +2 -2
  11. package/dist/components/table/CTableResponsiveWrapper.d.ts +9 -0
  12. package/dist/components/table/CTableRow.d.ts +1 -1
  13. package/dist/index.es.js +139 -72
  14. package/dist/index.es.js.map +1 -1
  15. package/dist/index.js +139 -72
  16. package/dist/index.js.map +1 -1
  17. package/package.json +12 -12
  18. package/src/components/alert/__tests__/__snapshots__/CAlert.spec.tsx.snap +1 -0
  19. package/src/components/button/__tests__/__snapshots__/CButtonClose.spec.tsx.snap +2 -0
  20. package/src/components/close-button/__tests__/__snapshots__/CCloseButton.spec.tsx.snap +2 -0
  21. package/src/components/form/CFormTextarea.tsx +2 -2
  22. package/src/components/form/__tests__/CFormTextarea.spec.tsx +1 -0
  23. package/src/components/form/__tests__/__snapshots__/CFormTextarea.spec.tsx.snap +1 -0
  24. package/src/components/modal/__tests__/__snapshots__/CModalHeader.spec.tsx.snap +2 -0
  25. package/src/components/popover/CPopover.tsx +5 -0
  26. package/src/components/table/CTable.tsx +184 -18
  27. package/src/components/table/CTableDataCell.tsx +13 -6
  28. package/src/components/table/CTableHeaderCell.tsx +2 -2
  29. package/src/components/table/CTableResponsiveWrapper.tsx +39 -0
  30. package/src/components/table/CTableRow.tsx +1 -1
  31. package/src/components/table/__tests__/CTable.spec.tsx +45 -0
  32. package/src/components/table/__tests__/__snapshots__/CTable.spec.tsx.snap +86 -2
  33. package/src/components/toast/CToast.tsx +1 -1
  34. package/src/components/toast/__tests__/__snapshots__/CToast.spec.tsx.snap +0 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreui/react",
3
- "version": "4.2.2",
3
+ "version": "4.3.1",
4
4
  "description": "UI Components Library for React.js",
5
5
  "keywords": [
6
6
  "react",
@@ -36,24 +36,24 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@popperjs/core": "^2.11.5",
39
- "@rollup/plugin-commonjs": "^22.0.0",
39
+ "@rollup/plugin-commonjs": "^22.0.1",
40
40
  "@rollup/plugin-node-resolve": "^13.3.0",
41
- "@rollup/plugin-typescript": "^8.3.1",
41
+ "@rollup/plugin-typescript": "^8.3.4",
42
42
  "@testing-library/jest-dom": "^5.16.4",
43
- "@testing-library/react": "^13.2.0",
44
- "@types/react": "18.0.9",
45
- "@types/react-dom": "^18.0.4",
46
- "@types/react-transition-group": "^4.4.4",
43
+ "@testing-library/react": "^13.3.0",
44
+ "@types/react": "18.0.15",
45
+ "@types/react-dom": "^18.0.6",
46
+ "@types/react-transition-group": "^4.4.5",
47
47
  "classnames": "^2.3.1",
48
48
  "prop-types": "^15.8.1",
49
- "react": "^18.1.0",
50
- "react-dom": "^18.1.0",
49
+ "react": "^18.2.0",
50
+ "react-dom": "^18.2.0",
51
51
  "react-popper": "^2.2.5",
52
- "react-transition-group": "^4.4.2",
53
- "rollup": "^2.74.1",
52
+ "react-transition-group": "^4.4.5",
53
+ "rollup": "^2.77.2",
54
54
  "rollup-plugin-peer-deps-external": "^2.2.4",
55
55
  "tslib": "^2.4.0",
56
- "typescript": "^4.6.4"
56
+ "typescript": "^4.7.4"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "react": ">=17",
@@ -10,6 +10,7 @@ exports[`CAlert customize 1`] = `
10
10
  <button
11
11
  aria-label="Close"
12
12
  class="btn btn-close"
13
+ type="button"
13
14
  />
14
15
  </div>
15
16
  </div>
@@ -6,6 +6,7 @@ exports[`CCloseButton customize 1`] = `
6
6
  aria-label="Close"
7
7
  class="btn btn-close btn-close-white bazinga"
8
8
  disabled=""
9
+ type="button"
9
10
  >
10
11
  Test
11
12
  </button>
@@ -17,6 +18,7 @@ exports[`loads and displays CCloseButton component 1`] = `
17
18
  <button
18
19
  aria-label="Close"
19
20
  class="btn btn-close"
21
+ type="button"
20
22
  >
21
23
  Test
22
24
  </button>
@@ -6,6 +6,7 @@ exports[`CCloseButton customize 1`] = `
6
6
  aria-label="Close"
7
7
  class="btn btn-close btn-close-white bazinga"
8
8
  disabled=""
9
+ type="button"
9
10
  />
10
11
  </div>
11
12
  `;
@@ -15,6 +16,7 @@ exports[`loads and displays CCloseButton component 1`] = `
15
16
  <button
16
17
  aria-label="Close"
17
18
  class="btn btn-close"
19
+ type="button"
18
20
  />
19
21
  </div>
20
22
  `;
@@ -1,4 +1,4 @@
1
- import React, { ChangeEventHandler, forwardRef, InputHTMLAttributes } from 'react'
1
+ import React, { ChangeEventHandler, forwardRef, TextareaHTMLAttributes } from 'react'
2
2
 
3
3
  import classNames from 'classnames'
4
4
  import PropTypes from 'prop-types'
@@ -7,7 +7,7 @@ import { CFormControlWrapper, CFormControlWrapperProps } from './CFormControlWra
7
7
 
8
8
  export interface CFormTextareaProps
9
9
  extends CFormControlWrapperProps,
10
- InputHTMLAttributes<HTMLTextAreaElement> {
10
+ TextareaHTMLAttributes<HTMLTextAreaElement> {
11
11
  /**
12
12
  * A string of all className you want applied to the component.
13
13
  */
@@ -19,6 +19,7 @@ test('CFormTextarea customize', async () => {
19
19
  readOnly={true}
20
20
  valid={true}
21
21
  defaultValue="Some value"
22
+ rows={2}
22
23
  />,
23
24
  )
24
25
  expect(container).toMatchSnapshot()
@@ -6,6 +6,7 @@ exports[`CFormTextarea customize 1`] = `
6
6
  class="form-control-plaintext is-invalid is-valid bazinga"
7
7
  disabled=""
8
8
  readonly=""
9
+ rows="2"
9
10
  >
10
11
  Some value
11
12
  </textarea>
@@ -9,6 +9,7 @@ exports[`CModalHeader customize 1`] = `
9
9
  <button
10
10
  aria-label="Close"
11
11
  class="btn btn-close"
12
+ type="button"
12
13
  />
13
14
  </div>
14
15
  </div>
@@ -23,6 +24,7 @@ exports[`loads and displays CModalHeader component 1`] = `
23
24
  <button
24
25
  aria-label="Close"
25
26
  class="btn btn-close"
27
+ type="button"
26
28
  />
27
29
  </div>
28
30
  </div>
@@ -7,6 +7,7 @@ import { usePopper } from 'react-popper'
7
7
  import { Transition } from 'react-transition-group'
8
8
 
9
9
  import { Triggers, triggerPropType } from '../Types'
10
+ import { useEffect } from 'react'
10
11
 
11
12
  export interface CPopoverProps {
12
13
  // TODO: find solution to not use any
@@ -78,6 +79,10 @@ export const CPopover: FC<CPopoverProps> = ({
78
79
  placement: placement,
79
80
  })
80
81
 
82
+ useEffect(() => {
83
+ setVisible(visible)
84
+ }, [visible])
85
+
81
86
  const getTransitionClass = (state: string) => {
82
87
  return state === 'entering'
83
88
  ? 'fade'
@@ -3,12 +3,20 @@ import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
5
  import { Colors, colorPropType } from '../Types'
6
+ import { CTableHead, CTableHeadProps } from './CTableHead'
7
+ import { CTableHeaderCell, CTableHeaderCellProps } from './CTableHeaderCell'
8
+ import { CTableBody } from './CTableBody'
9
+ import { CTableDataCell, CTableDataCellProps } from './CTableDataCell'
10
+ import { CTableRow, CTableRowProps } from './CTableRow'
11
+ import { CTableFoot, CTableFootProps } from './CTableFoot'
12
+ import { CTableCaption } from './CTableCaption'
13
+ import { CTableResponsiveWrapper } from './CTableResponsiveWrapper'
6
14
 
7
- export interface CTableProps extends TableHTMLAttributes<HTMLTableElement> {
15
+ export interface CTableProps extends Omit<TableHTMLAttributes<HTMLTableElement>, 'align'> {
8
16
  /**
9
17
  * Set the vertical aligment.
10
18
  */
11
- align?: 'bottom' | 'middle' | 'top'
19
+ align?: 'bottom' | 'middle' | 'top' | string
12
20
  /**
13
21
  * Sets the border color of the component to one of CoreUI’s themed colors.
14
22
  *
@@ -24,23 +32,63 @@ export interface CTableProps extends TableHTMLAttributes<HTMLTableElement> {
24
32
  */
25
33
  borderless?: boolean
26
34
  /**
27
- * Put the `<caption>` on the top of the table.
35
+ * Put the caption on the top if you set `caption="top"` of the table or set the text of the table caption.
28
36
  */
29
- caption?: 'top'
37
+ caption?: 'top' | string
38
+ /**
39
+ * Set the text of the table caption and the caption on the top of the table.
40
+ *
41
+ * @since 4.3.0
42
+ */
43
+ captionTop?: string
30
44
  /**
31
45
  * A string of all className you want applied to the component.
32
46
  */
33
47
  className?: string
48
+ /**
49
+ * 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')
50
+ *
51
+ * In columns prop each array item represents one column. Item might be specified in two ways:
52
+ * String: each item define column name equal to item value.
53
+ * Object: item is object with following keys available as column configuration:
54
+ * - key (required)(String) - define column name equal to item key.
55
+ * - 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.
56
+ * - _props (Object) - adds classes to all cels in column, ex. _props: { scope: 'col', className: 'custom-class' },
57
+ * - _style (Object) - adds styles to the column header (useful for defining widths)
58
+ *
59
+ * @since 4.3.0
60
+ */
61
+ columns?: (string | Column)[]
34
62
  /**
35
63
  * Sets the color context of the component to one of CoreUI’s themed colors.
36
64
  *
37
65
  * @type 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string
38
66
  */
39
67
  color?: Colors
68
+ /**
69
+ * Array of objects or strings, where each element represents one cell in the table footer.
70
+ *
71
+ * Example items:
72
+ * ['FooterCell', 'FooterCell', 'FooterCell']
73
+ * or
74
+ * [{ label: 'FooterCell', _props: { color: 'success' }, ...]
75
+ *
76
+ * @since 4.3.0
77
+ */
78
+ footer?: FooterItem[]
40
79
  /**
41
80
  * Enable a hover state on table rows within a `<CTableBody>`.
42
81
  */
43
82
  hover?: boolean
83
+ /**
84
+ * 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'.
85
+ *
86
+ * Example item:
87
+ * { name: 'John' , age: 12, _props: { color: 'success' }, _cellProps: { age: { className: 'fw-bold'}}}
88
+ *
89
+ * @since 4.3.0
90
+ */
91
+ items?: Item[]
44
92
  /**
45
93
  * Make any table responsive across all viewports or pick a maximum breakpoint with which to have a responsive table up to.
46
94
  */
@@ -53,6 +101,43 @@ export interface CTableProps extends TableHTMLAttributes<HTMLTableElement> {
53
101
  * Add zebra-striping to any table row within the `<CTableBody>`.
54
102
  */
55
103
  striped?: boolean
104
+ /**
105
+ * Add zebra-striping to any table column.
106
+ *
107
+ * @since 4.3.0
108
+ */
109
+ stripedColumns?: boolean
110
+ /**
111
+ * Properties that will be passed to the table footer component.
112
+ *
113
+ * @link https://coreui.io/react/docs/components/table/#ctablefoot
114
+ * @since 4.3.0
115
+ */
116
+ tableFootProps?: CTableFootProps
117
+ /**
118
+ * Properties that will be passed to the table head component.
119
+ *
120
+ * @link https://coreui.io/react/docs/components/table/#ctablehead
121
+ * @since 4.3.0
122
+ */
123
+ tableHeadProps?: CTableHeadProps
124
+ }
125
+
126
+ export interface Column {
127
+ label?: string
128
+ key: string
129
+ _style?: any
130
+ _props?: CTableHeaderCellProps
131
+ }
132
+
133
+ export interface Item {
134
+ [key: string]: number | string | any
135
+ _props?: CTableRowProps
136
+ }
137
+
138
+ export interface FooterItem {
139
+ label?: string
140
+ _props?: CTableDataCellProps
56
141
  }
57
142
 
58
143
  export const CTable = forwardRef<HTMLTableElement, CTableProps>(
@@ -64,12 +149,19 @@ export const CTable = forwardRef<HTMLTableElement, CTableProps>(
64
149
  bordered,
65
150
  borderless,
66
151
  caption,
152
+ captionTop,
67
153
  className,
68
154
  color,
155
+ columns,
156
+ footer,
69
157
  hover,
158
+ items = [],
70
159
  responsive,
71
160
  small,
72
161
  striped,
162
+ stripedColumns,
163
+ tableFootProps,
164
+ tableHeadProps,
73
165
  ...rest
74
166
  },
75
167
  ref,
@@ -78,32 +170,99 @@ export const CTable = forwardRef<HTMLTableElement, CTableProps>(
78
170
  'table',
79
171
  {
80
172
  [`align-${align}`]: align,
81
- [`caption-${caption}`]: caption,
82
173
  [`border-${borderColor}`]: borderColor,
174
+ [`caption-top`]: captionTop || caption === 'top',
83
175
  'table-bordered': bordered,
84
176
  'table-borderless': borderless,
85
177
  [`table-${color}`]: color,
86
178
  'table-hover': hover,
87
179
  'table-sm': small,
88
180
  'table-striped': striped,
181
+ 'table-striped-columns': stripedColumns,
89
182
  },
90
183
  className,
91
184
  )
92
185
 
93
- return responsive ? (
94
- <div
95
- className={
96
- typeof responsive === 'boolean' ? 'table-responsive' : `table-responsive-${responsive}`
97
- }
98
- >
99
- <table className={_className ? _className : undefined} {...rest} ref={ref}>
186
+ const rawColumnNames = columns
187
+ ? columns.map((column: Column) => {
188
+ if (typeof column === 'object') return column.key
189
+ else return column
190
+ })
191
+ : Object.keys(items[0] || {}).filter((el) => el.charAt(0) !== '_')
192
+
193
+ const pretifyName = (name: string) => {
194
+ return name
195
+ .replace(/[-_.]/g, ' ')
196
+ .replace(/ +/g, ' ')
197
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
198
+ .split(' ')
199
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
200
+ .join(' ')
201
+ }
202
+
203
+ const label = (column: Column | string) =>
204
+ typeof column === 'object'
205
+ ? column.label !== undefined
206
+ ? column.label
207
+ : pretifyName(column.key)
208
+ : pretifyName(column)
209
+
210
+ return (
211
+ <CTableResponsiveWrapper responsive={responsive}>
212
+ <table className={_className} {...rest} ref={ref}>
213
+ {((caption && caption !== 'top') || captionTop) && (
214
+ <CTableCaption>{caption || captionTop}</CTableCaption>
215
+ )}
216
+ {columns && (
217
+ <CTableHead {...tableHeadProps}>
218
+ <CTableRow>
219
+ {columns.map((column: Column, index: number) => (
220
+ <CTableHeaderCell
221
+ {...(column._props && { ...column._props })}
222
+ {...(column._style && { style: { ...column._style } })}
223
+ key={index}
224
+ >
225
+ {label(column)}
226
+ </CTableHeaderCell>
227
+ ))}
228
+ </CTableRow>
229
+ </CTableHead>
230
+ )}
231
+ {items && (
232
+ <CTableBody>
233
+ {items.map((item: Item, index: number) => (
234
+ <CTableRow {...(item._props && { ...item._props })} key={index}>
235
+ {rawColumnNames.map((colName: string, index: number) => {
236
+ return item[colName] ? (
237
+ <CTableDataCell
238
+ {...(item._cellProps && {
239
+ ...(item._cellProps['all'] && { ...item._cellProps['all'] }),
240
+ ...(item._cellProps[colName] && { ...item._cellProps[colName] }),
241
+ })}
242
+ key={index}
243
+ >
244
+ {item[colName]}
245
+ </CTableDataCell>
246
+ ) : null
247
+ })}
248
+ </CTableRow>
249
+ ))}
250
+ </CTableBody>
251
+ )}
100
252
  {children}
253
+ {footer && (
254
+ <CTableFoot {...tableFootProps}>
255
+ <CTableRow>
256
+ {footer.map((item: FooterItem, index: number) => (
257
+ <CTableDataCell {...(item._props && { ...item._props })} key={index}>
258
+ {typeof item === 'object' ? item.label : item}
259
+ </CTableDataCell>
260
+ ))}
261
+ </CTableRow>
262
+ </CTableFoot>
263
+ )}
101
264
  </table>
102
- </div>
103
- ) : (
104
- <table className={_className ? _className : undefined} {...rest} ref={ref}>
105
- {children}
106
- </table>
265
+ </CTableResponsiveWrapper>
107
266
  )
108
267
  },
109
268
  )
@@ -113,17 +272,24 @@ CTable.propTypes = {
113
272
  borderColor: PropTypes.string,
114
273
  bordered: PropTypes.bool,
115
274
  borderless: PropTypes.bool,
116
- caption: PropTypes.oneOf(['top']),
275
+ caption: PropTypes.oneOfType([PropTypes.string, PropTypes.oneOf(['top'])]),
276
+ captionTop: PropTypes.string,
117
277
  children: PropTypes.node,
118
278
  className: PropTypes.string,
119
279
  color: colorPropType,
280
+ columns: PropTypes.array,
281
+ footer: PropTypes.array,
120
282
  hover: PropTypes.bool,
283
+ items: PropTypes.array,
121
284
  responsive: PropTypes.oneOfType([
122
285
  PropTypes.bool,
123
286
  PropTypes.oneOf<'sm' | 'md' | 'lg' | 'xl' | 'xxl'>(['sm', 'md', 'lg', 'xl', 'xxl']),
124
287
  ]),
125
288
  small: PropTypes.bool,
126
289
  striped: PropTypes.bool,
290
+ stripedColumns: PropTypes.bool,
291
+ tableFootProps: PropTypes.shape({ ...CTableFoot.propTypes }),
292
+ tableHeadProps: PropTypes.shape({ ...CTableHead.propTypes }),
127
293
  }
128
294
 
129
295
  CTable.displayName = 'CTable'
@@ -1,11 +1,12 @@
1
- import React, { forwardRef, TdHTMLAttributes } from 'react'
1
+ import React, { forwardRef, TdHTMLAttributes, ThHTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
5
  import { Colors, colorPropType } from '../Types'
6
6
 
7
7
  export interface CTableDataCellProps
8
- extends Omit<TdHTMLAttributes<HTMLTableDataCellElement>, 'align'> {
8
+ extends Omit<TdHTMLAttributes<HTMLTableCellElement>, 'align'>,
9
+ Omit<ThHTMLAttributes<HTMLTableCellElement>, 'align'> {
9
10
  /**
10
11
  * Highlight a table row or cell.
11
12
  */
@@ -13,7 +14,7 @@ export interface CTableDataCellProps
13
14
  /**
14
15
  * Set the vertical aligment.
15
16
  */
16
- align?: 'bottom' | 'middle' | 'top'
17
+ align?: 'bottom' | 'middle' | 'top' | string
17
18
  /**
18
19
  * A string of all className you want applied to the component.
19
20
  */
@@ -24,9 +25,13 @@ export interface CTableDataCellProps
24
25
  * @type 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string
25
26
  */
26
27
  color?: Colors
28
+ /**
29
+ * @ignore
30
+ */
31
+ colSpan?: number
27
32
  }
28
33
 
29
- export const CTableDataCell = forwardRef<HTMLTableDataCellElement, CTableDataCellProps>(
34
+ export const CTableDataCell = forwardRef<HTMLTableCellElement, CTableDataCellProps>(
30
35
  ({ children, active, align, className, color, ...rest }, ref) => {
31
36
  const _className = classNames(
32
37
  {
@@ -37,10 +42,12 @@ export const CTableDataCell = forwardRef<HTMLTableDataCellElement, CTableDataCel
37
42
  className,
38
43
  )
39
44
 
45
+ const Component = rest.scope ? 'th' : 'td'
46
+
40
47
  return (
41
- <td className={_className ? _className : undefined} {...rest} ref={ref}>
48
+ <Component className={_className ? _className : undefined} {...rest} ref={ref}>
42
49
  {children}
43
- </td>
50
+ </Component>
44
51
  )
45
52
  },
46
53
  )
@@ -4,7 +4,7 @@ import classNames from 'classnames'
4
4
 
5
5
  import { Colors, colorPropType } from '../Types'
6
6
 
7
- export interface CTableHeaderCellProps extends ThHTMLAttributes<HTMLTableHeaderCellElement> {
7
+ export interface CTableHeaderCellProps extends ThHTMLAttributes<HTMLTableCellElement> {
8
8
  /**
9
9
  * A string of all className you want applied to the component.
10
10
  */
@@ -17,7 +17,7 @@ export interface CTableHeaderCellProps extends ThHTMLAttributes<HTMLTableHeaderC
17
17
  color?: Colors
18
18
  }
19
19
 
20
- export const CTableHeaderCell = forwardRef<HTMLTableHeaderCellElement, CTableHeaderCellProps>(
20
+ export const CTableHeaderCell = forwardRef<HTMLTableCellElement, CTableHeaderCellProps>(
21
21
  ({ children, className, color, ...rest }, ref) => {
22
22
  const _className = classNames(
23
23
  {
@@ -0,0 +1,39 @@
1
+ import React, { FC, HTMLAttributes } from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ export interface CTableResponsiveWrapperProps extends HTMLAttributes<HTMLDivElement> {
5
+ children: any
6
+ /**
7
+ * Make any table responsive across all viewports or pick a maximum breakpoint with which to have a responsive table up to.
8
+ */
9
+ responsive?: boolean | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'
10
+ }
11
+
12
+ export const CTableResponsiveWrapper: FC<CTableResponsiveWrapperProps> = ({
13
+ children,
14
+ responsive,
15
+ ...rest
16
+ }) => {
17
+ return responsive ? (
18
+ <div
19
+ className={
20
+ typeof responsive === 'boolean' ? 'table-responsive' : `table-responsive-${responsive}`
21
+ }
22
+ {...rest}
23
+ >
24
+ {children}
25
+ </div>
26
+ ) : (
27
+ children
28
+ )
29
+ }
30
+
31
+ CTableResponsiveWrapper.propTypes = {
32
+ children: PropTypes.any,
33
+ responsive: PropTypes.oneOfType([
34
+ PropTypes.bool,
35
+ PropTypes.oneOf<'sm' | 'md' | 'lg' | 'xl' | 'xxl'>(['sm', 'md', 'lg', 'xl', 'xxl']),
36
+ ]),
37
+ }
38
+
39
+ CTableResponsiveWrapper.displayName = 'CTableResponsiveWrapper'
@@ -12,7 +12,7 @@ export interface CTableRowProps extends HTMLAttributes<HTMLTableRowElement> {
12
12
  /**
13
13
  * Set the vertical aligment.
14
14
  */
15
- align?: 'bottom' | 'middle' | 'top'
15
+ align?: 'bottom' | 'middle' | 'top' | string
16
16
  /**
17
17
  * A string of all className you want applied to the component.
18
18
  */
@@ -17,6 +17,51 @@ test('loads and displays CTable component', async () => {
17
17
  expect(container).toMatchSnapshot()
18
18
  })
19
19
 
20
+ test('loads and displays CTable component - new way', async () => {
21
+ const columns = [
22
+ {
23
+ key: 'id',
24
+ label: '#',
25
+ _props: { scope: 'col' },
26
+ },
27
+ 'class',
28
+ {
29
+ key: 'heading_1',
30
+ label: 'Heading',
31
+ _props: { scope: 'col' },
32
+ },
33
+ {
34
+ key: 'heading_2',
35
+ label: 'Heading',
36
+ _props: { scope: 'col' },
37
+ },
38
+ ]
39
+ const items = [
40
+ {
41
+ id: 1,
42
+ class: 'Mark',
43
+ heading_1: 'Otto',
44
+ heading_2: '@mdo',
45
+ _cellProps: { id: { scope: 'row' } },
46
+ },
47
+ {
48
+ id: 2,
49
+ class: 'Jacob',
50
+ heading_1: 'Thornton',
51
+ heading_2: '@fat',
52
+ _cellProps: { id: { scope: 'row' } },
53
+ },
54
+ {
55
+ id: 3,
56
+ class: 'Larry the Bird',
57
+ heading_2: '@twitter',
58
+ _cellProps: { id: { scope: 'row' }, class: { colSpan: 2 } },
59
+ },
60
+ ]
61
+ const { container } = render(<CTable columns={columns} items={items} />)
62
+ expect(container).toMatchSnapshot()
63
+ })
64
+
20
65
  test('CTable customize', async () => {
21
66
  const { container } = render(
22
67
  <CTable