From e65acd8723fec9c3a1f2a26752ab186ad2a439b1 Mon Sep 17 00:00:00 2001 From: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Tue, 19 Dec 2023 06:59:05 -0500 Subject: [PATCH] feat: carousel and components --- restaurant/src/components/carousel.js | 32 ++++++++++++++++++- .../src/{menu.js => components/navbar.js} | 0 restaurant/src/index.js | 20 ++++++++---- restaurant/src/style.css | 2 +- 4 files changed, 45 insertions(+), 9 deletions(-) rename restaurant/src/{menu.js => components/navbar.js} (100%) diff --git a/restaurant/src/components/carousel.js b/restaurant/src/components/carousel.js index 89b6c13..7ce9a41 100644 --- a/restaurant/src/components/carousel.js +++ b/restaurant/src/components/carousel.js @@ -2,6 +2,31 @@ class Carousel { constructor(items) { this.items = items; }; + + carouselDiv = document.createElement('div'); + createComponent() { + this.carouselDiv.classList.add(['carousel']); + + this.items.forEach(element => { + let div = document.createElement('div'); + div.classList.add(['carousel-item']); + + let heading = document.createElement('h1'); + let desc = document.createElement('p'); + let link = document.createElement('a'); + + heading.textContent = element.heading; + desc.textContent = element.desc; + link.textContent = element.link; + + div.appendChild(heading); + div.appendChild(desc); + div.appendChild(link); + + this.carouselDiv.appendChild(div); + }); + return this.carouselDiv; + }; }; @@ -41,4 +66,9 @@ let carouselItems = [ } ] -carouselItems.forEach(e => new Items(e)); +let items = carouselItems.map(e => new Items(e.heading, e.desc, e.link)); +let carousel = new Carousel(items); + +export { carousel }; + + diff --git a/restaurant/src/menu.js b/restaurant/src/components/navbar.js similarity index 100% rename from restaurant/src/menu.js rename to restaurant/src/components/navbar.js diff --git a/restaurant/src/index.js b/restaurant/src/index.js index eaeb99c..99c6036 100644 --- a/restaurant/src/index.js +++ b/restaurant/src/index.js @@ -1,11 +1,16 @@ -import { menuBar } from "./menu"; +import { carousel } from "./components/carousel" +import { menuBar as navbar } from "./components/navbar"; import './style.css' -function navbar(){ - const element = document.createElement('div'); - let menu = new menuBar(); +function nav(){ + const element = document.createElement('header'); + const brandName = document.createElement('h1'); + let menu = new navbar(); - element.classList.add(['container']); + brandName.style.textAlign = 'center'; + brandName.textContent = 'This Wondrous Coffee'; + + element.appendChild(brandName); element.appendChild(menu); return element; @@ -20,5 +25,6 @@ function content(data) { return content; } - -document.body.appendChild(navbar()); +let carouselComponent = carousel.createComponent(); +document.body.appendChild(nav()); +document.body.appendChild(carouselComponent); diff --git a/restaurant/src/style.css b/restaurant/src/style.css index 0131322..f7ff5dd 100644 --- a/restaurant/src/style.css +++ b/restaurant/src/style.css @@ -13,7 +13,7 @@ .navbar { display: grid; - grid-template-columns: 150px 150px 150px; + grid-template-columns: repeat(3, 100px); gap: 15px; }