【问题标题】:Is there a way to use custom icon for material ui's pagination有没有办法使用自定义图标进行材质ui的分页
【发布时间】:2020-10-12 04:34:46
【问题描述】:

有没有办法在材质ui中使用自定义图标进行分页?

Material UI Pagination Documentation , CodeSandbox Demo

我想更改默认的左右人字形(用于导航)

有没有办法使用material ui的现有组件来实现这一点?

【问题讨论】:

    标签: css reactjs material-ui


    【解决方案1】:

    你不能直接改变图标,但你可以使用usePagination自定义完整的分页

    <ul className={classes.ul}>
      {items.map(({ page, type, selected, ...item }, index) => {
        let children = null;
    
        if (type === 'start-ellipsis' || type === 'end-ellipsis') {
          children = '…';
        } else if (type === 'page') {
          children = (
            <IconButton  style={{ 
              fontWeight: selected ? 'bold' : undefined, 
             backgroundColor: selected ? 'rgba(0, 0, 0, 0.04)' : 'white',
              width: 50, 
              height:50
            }} {...item}>
              {page}
            </IconButton >
          );
        } else {
          children = (
            <IconButton  {...item}>
              {type === 'previous' ? <FastRewindIcon/> : <FastForwardIcon/>}
            </IconButton >
          );
        }
        return <li key={index} style={{ margin: 'auto 0'}}>{children}</li>;
      })}
    </ul>

    【讨论】:

    • 我能问你我如何操作这些页面吗?我最初只是想在
    • 上放置一个 onClick 事件句柄,例如
  • 你可以像js const { items } = usePagination({ count: 10, onChange: (event,page) =&gt; console.log(page) }); 这样使用usePagiantion中的所有属性
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签