Skip to content

Commit ea9f504

Browse files
showMore/less
- added button in the style of description itself to show more and less of description which is more than 100 letter - changed styling line-clamp-3 to line-clamp-11 because old styling was limiting description display functionality eventhough toggling use state works fine - chose line-clamp-11 because the biggest description in project in 10 line , so just chosed on line more, - line clamp am talking about is in Errorcard.jsx line number 56 //for future// - line-clamp should be increased if description not fits in 11 line
1 parent cea6986 commit ea9f504

2 files changed

Lines changed: 33 additions & 22 deletions

File tree

src/components/Error/Error.jsx

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,34 @@ import ErrorCard from "./ErrorCard";
33
import { errors } from "../../data/error.json";
44

55
const Error = ({ search, type }) => {
6-
const [error, setError] = useState([])
7-
useEffect(() => {
8-
setError(errors)
9-
}, [])
10-
11-
const filteredError = error.filter((error) => {
12-
return ((error.title.toLowerCase().includes(search.toLowerCase()) || (error.description.toLowerCase().includes(search.toLowerCase())) || (error.type.toLowerCase().includes(search.toLowerCase()))))
13-
})
14-
15-
const filteredErrorByType = filteredError.filter((error) => {
16-
return (error.type.toLowerCase().includes(type.toLowerCase()))
17-
})
18-
6+
const [error, setError] = useState([]);
7+
useEffect(() => {
8+
setError(errors);
9+
}, []);
1910

11+
const filteredError = error.filter((error) => {
2012
return (
21-
<section className="mx-4 md:w-5/6 my-12 grid grid-cols-12 justify-center gap-8 md:mx-auto">
22-
{
23-
(filteredErrorByType.length === 0 ? <h1 className="text-center text-2xl text-gray-500">No Error Found</h1> : filteredErrorByType.map((error, idx) => (
24-
<ErrorCard key={idx} error={error} />
25-
)))
26-
}
27-
</section>
13+
error.title.toLowerCase().includes(search.toLowerCase()) ||
14+
error.description.toLowerCase().includes(search.toLowerCase()) ||
15+
error.type.toLowerCase().includes(search.toLowerCase())
2816
);
17+
});
18+
19+
const filteredErrorByType = filteredError.filter((error) => {
20+
return error.type.toLowerCase().includes(type.toLowerCase());
21+
});
22+
23+
return (
24+
<section className="mx-4 md:w-5/6 my-12 grid grid-cols-12 justify-center gap-8 md:mx-auto">
25+
{filteredErrorByType.length === 0 ? (
26+
<h1 className="text-center text-2xl text-gray-500">No Error Found</h1>
27+
) : (
28+
filteredErrorByType.map((error, idx) => (
29+
<ErrorCard key={idx} error={error} />
30+
))
31+
)}
32+
</section>
33+
);
2934
};
3035

3136
export default Error;

src/components/Error/ErrorCard.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import ErrorSolutions from "./ErrorSolutions";
44
import ErrorType from "./ErrorType";
55

66
function ErrorCard({ error }) {
7+
78
const [showSolution, setShowSolution] = useState(false);
89
const [errorTypeColor, setErrorTypeColor] = useState('#7e1aa5');
10+
const [readMore,setReadMore]=useState(false);
911
useEffect(() => {
1012
if (error.type == "add") {
1113
return setErrorTypeColor("#4024e0");
@@ -50,9 +52,13 @@ function ErrorCard({ error }) {
5052
{showSolution ? (
5153
<ErrorSolutions solutions={error.solutions} />
5254
) : (
53-
<p className="text-sm text-gray line-clamp-3 leading-relaxed">
54-
{error.description}
55+
<div className="h-fit">
56+
<p className="text-sm text-gray line-clamp-11 leading-relaxed">
57+
{readMore ? error.description : error.description.substring(0,100)}
58+
{error.description.length > 100 ?<button onClick={()=>{setReadMore(!readMore)}}>{readMore ? '...show less': '...show more'} </button>:''}
5559
</p>
60+
61+
</div>
5662
)}
5763

5864
<button

0 commit comments

Comments
 (0)