javascript - 如何自定义 react-show-more 或 less 文本到 Material-UI 图标
问题描述
我正在使用 react 在我的 spfx webpart 中使用 react 显示更多文本控制器。我需要用我的 webpart 中的 ExpandMore 和 ExpandLess 材料 ui 图标替换 showMore 和 showLess 字符串链接。有什么方法吗?
<ShowMoreText
/* Default options */
lines={2}
more="Show More"
less="Show less"
anchorClass=""
onClick={this.executeOnClick}
expanded={false}
>
{item["description"]}
</ShowMoreText>
解决方案
方法
将直接传递<Icon />
给相关的道具可以正常工作。
<ShowMoreText
more={<ExpandMore />}
less={<ExpandLess />}
...
/>
演示
资源
import React, { useState } from "react";
import "./styles.css";
import ShowMoreText from "react-show-more-text";
import ExpandLess from "@material-ui/icons/ExpandLess";
import ExpandMore from "@material-ui/icons/ExpandMore";
export default function App() {
const [expand, setExpand] = useState(false);
const onClick = () => {
setExpand(!expand);
};
const text = "12313131313131311";
return (
<div className="App">
<ShowMoreText
lines={2}
more={<ExpandMore />}
less={<ExpandLess />}
onClick={onClick}
expanded={expand}
width={30}
>
{text}
</ShowMoreText>
</div>
);
}
推荐阅读
- python - Python将图像转换为棕褐色
- elasticsearch - 有没有办法使用发布请求将数据存储在logstash中?
- mongodb - DMS 不理解来自 MongoDB 的架构更改
- javascript - TestCafe 跳过点击步骤
- selenium - 一种在驱动程序初始化中阻止 cookie 的方法(EDGE、SAFARI)
- java - Spring Data JPA 查找最近的日期
- javascript - 我可以在 Angular 9 应用程序中使用查询选择器吗
- amazon-web-services - Amazon Web Services (AWS) 的 AWS CloudFormation 模板文件无法创建 EC2 实例
- flutter - Flutter pub get failed with (1; The system cannot find path specified)
- python - Python中从R3到R15的地图图像