Bin*_*cob 4 html javascript css reactjs material-ui
我正在使用 React 在我的 spfx Web 部件中使用 React 显示更多文本控制器。我需要在我的 web 部件中将 showMore 和 showLess 字符串链接替换为 ExpandMore 和 ExpandLess 材料 ui 图标。有什么方法可以做到这一点吗?
<ShowMoreText
/* Default options */
lines={2}
more="Show More"
less="Show less"
anchorClass=""
onClick={this.executeOnClick}
expanded={false}
>
{item["description"]}
</ShowMoreText>
Run Code Online (Sandbox Code Playgroud)
直接传递<Icon />给相关的道具就可以了。
<ShowMoreText
more={<ExpandMore />}
less={<ExpandLess />}
...
/>
Run Code Online (Sandbox Code Playgroud)
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>
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8743 次 |
| 最近记录: |