WesselBBD / Grad-WebLevelUp

Our 3rd level up involving web technologies
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Created vanilla component using function #21

Closed fabio-sv closed 2 years ago

fabio-sv commented 2 years ago

Vanilla Star Rating Component

Example output

Stars using Vanilla

What it creates

<section class="star-box">
    <img src="star.svg" />
    <img src="star.svg" />
    <img src="star.svg" />
    <img src="star.svg" />
    <img src="star.svg" />
</section>

Using the Component

import { createStars } from "./components/stars.js";

const starRating = createStars(3); // will create 5 stars, 3 of which are highlighted
const elem = document.getElementById("ceiling-fans-card");

elem.appendChild(starRating);
// There we go, stars on the card
Personally, really enjoyed making it this way, was pretty easy to do, and don't have to worry about building out html and it is pure vanilla