css react-data-table-component如何设置复选框的样式?大复选框变小

yshpjwxd  于 2023-07-01  发布在  React
关注(0)|答案(2)|浏览(123)

我在我的项目中使用react-data-table-component来创建一个数据表。
但是,复选框看起来太大。
在检查文档后,我发现了这个页面-Overidding Styling Using css-in-js with customStyles,以及这个示例:

  1. // Internally, customStyles will deep merges your customStyles with the default styling.
  2. const customStyles = {
  3. rows: {
  4. style: {
  5. minHeight: '72px', // override the row height
  6. },
  7. },
  8. headCells: {
  9. style: {
  10. paddingLeft: '8px', // override the cell padding for head cells
  11. paddingRight: '8px',
  12. },
  13. },
  14. cells: {
  15. style: {
  16. paddingLeft: '8px', // override the cell padding for data cells
  17. paddingRight: '8px',
  18. },
  19. },
  20. };

上面没有提到复选框样式,所以我尝试这样做:

  1. const customStyles = {
  2. checkbox: {
  3. style: {
  4. maxHeight: '18px',
  5. maxWidth: '18px',
  6. },
  7. },
  8. };

不幸的是,复选框仍然很大。
我该如何解决这个问题,使复选框的大小与屏幕截图中的示例中显示的大小相同?
截图。

taor4pac

taor4pac1#

我是如何解决它的:
1.创建一个Checkbox组件,如下所示:

  1. const Checkbox = React.forwardRef(({ onClick, ...rest }, ref) =>
  2. {
  3. return(
  4. <>
  5. <div className="form-check pb-5" style={{ backgroundColor: '' }}>
  6. <input
  7. type="checkbox"
  8. className="form-check-input"
  9. style={{ height: '20px', width: '20px' }}
  10. ref={ref}
  11. onClick={ onClick }
  12. {...rest}
  13. />
  14. <label className="form-check-label" id="booty-check" />
  15. </div>
  16. </>
  17. )
  18. })

1.将Checkbox组件添加到DataTable,如下所示:

  1. <DataTable
  2. title="Products"
  3. columns={columns}
  4. data={ data }
  5. subHeader
  6. subHeaderComponent={subHeaderComponentMemo}
  7. onRowClicked={ handleRowClicked }
  8. selectableRows
  9. selectableRowsComponent={Checkbox} // Pass the Checkbox component only
  10. responsive
  11. persistTableHead
  12. />
展开查看全部
fcy6dtqo

fcy6dtqo2#

this is not working
Unexpected Application Error! Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. at createFiberFromTypeAndProps (http://localhost:3000/static/js/bundle.js:206785:21) at createFiberFromElement (http://localhost:3000/static/js/bundle.js:206806:19) at reconcileSingleElement (http://localhost:3000/static/js/bundle.js:195897:27) at reconcileChildFibers (http://localhost:3000/static/js/bundle.js:195947:39) at reconcileChildren (http://localhost:3000/static/js/bundle.js:198889:32) at updateFunctionComponent (http://localhost:3000/static/js/bundle.js:199279:7) at updateSimpleMemoComponent (http://localhost:3000/static/js/bundle.js:199116:14) at updateMemoComponent (http://localhost:3000/static/js/bundle.js:198989:18) at beginWork (http://localhost:3000/static/js/bundle.js:201019:20) at beginWork$1 (http://localhost:3000/static/js/bundle.js:205917:18)

相关问题