Theme
Primary Color
Lesson 21

Show and Hide Content

محتوى الدرس

src/App.jsx
import "./App.css";
import CourseCard from "./components/CourseCard";
import Header from "./components/layout/Header";
import Footer from "./components/layout/Footer";

function App() {
  return (
    <>
      <Header />
      <main>
        <div className="courses" id="courses">
          <CourseCard title="HTML" lessons={30} price={15} isSpecial={true} />
          <CourseCard title="CSS" lessons={50} price={25} challenges="Yes" isSpecial={true} />
          <CourseCard title="JS" lessons={60} challenges="Yes" />
          <CourseCard title="Reactjs" challenges="Yes" />
        </div>
      </main>
      <Footer />
    </>
  );
}

export default App;
src/components/CourseCard.jsx
import "./course-card.css";

function CourseCard({ title, lessons, price = 0, challenges, isSpecial = false, children }) {
  console.log(challenges);
  return (
    <div className="course-card">
      <p>Course Name Is: {title}</p>
      <p>{lessons === undefined ? "No Lessons" : `Lesssons Count: ${lessons}`}</p>
      <p>Price Is: {price === 0 ? "Free" : `${price} EGP`}</p>
      <p>{challenges === "Yes" ? "Has Challenges" : "No Challenges"}</p>
      {/* {isSpecial ? <span>Special Course</span> : null} */}
      {isSpecial && <span>Special Course</span>}
      {children}
    </div>
  );
}

export default CourseCard;
src/components/course-card.css
.course-card {
  min-width: 0;
  padding: 28px;
  background-color: white;
  border: 1px solid #e2e8f0;
  border-top: 4px solid #2563eb;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgb(15 23 42 / 5%);
  transition: box-shadow 0.2s;
  position: relative;
}
.course-card:hover {
  box-shadow: 0 12px 32px rgb(15 23 42 / 12%);
}
.course-card p {
  margin: 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.course-card p:first-child {
  margin-bottom: 20px;
  color: #0f172a;
  font-size: 22px;
  font-weight: bold;
}
.course-card p:nth-child(2) {
  padding-bottom: 20px;
  color: #64748b;
  border-bottom: 1px solid #e2e8f0;
}
.course-card p:last-child {
  padding-top: 20px;
  color: #1d4ed8;
  font-size: 20px;
  font-weight: bold;
}
.course-card .special {
  position: absolute;
  right: 10px;
  top: 10px;
  background-color: #F44336;
  color: wheat;
  font-weight: bold;
  padding: 4px 5px 5px;
  border-radius: 6px;
  font-size: 12px;
}