Skip to content

Commit

Permalink
Added flexbox head, body, footer.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwicho38 committed Feb 18, 2024
1 parent 2804405 commit bd02526
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 30 deletions.
4 changes: 1 addition & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
<script src="javascript/components/main-component.js" defer></script>
</head>

<body class="flex flex-col h-screen">

<body class="root">
<main-component>

</main-component>
</body>

Expand Down
15 changes: 15 additions & 0 deletions public/javascript/components/body-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class BodyComponent extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
const template = document.createElement('template');
template.innerHTML = `
<style>
@import "../../stylesheets/body-component.css";
</style>
<h1>Hello</h1>
`;
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
}
customElements.define('body-component', BodyComponent);
18 changes: 10 additions & 8 deletions public/javascript/components/footer-component.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@

class FooterComponent extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
const template = document.createElement('template');
template.innerHTML = `
constructor() {
super();
this.attachShadow({ mode: 'open' });
const template = document.createElement('template');
template.innerHTML = `
<head>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@^2.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<style>
@import "../../stylesheets/footer-component.css"
</style>
<footer class="flex justify-center items-center bg-gray-700 text-white p-4">
<p>© 2024 My Website. All rights reserved.</p>
</footer>
`;
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
}
customElements.define('footer-component', FooterComponent);
20 changes: 11 additions & 9 deletions public/javascript/components/header-component.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@

class HeaderComponent extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
const template = document.createElement('template');
template.innerHTML = `
constructor() {
super();
this.attachShadow({ mode: 'open' });
const template = document.createElement('template');
template.innerHTML = `
<head>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@^2.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<header class="flex justify-center items-center bg-blue-500 text-white p-4">
<style>
@import "../../stylesheets/header-component.css"
</style>
<header class="justify-center items-center bg-blue-500 text-white p-4">
<h1>Welcome to My Website</h1>
</header>
`;
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
}
customElements.define('header-component', HeaderComponent);
18 changes: 10 additions & 8 deletions public/javascript/components/main-component.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

class MainComponent extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
const template = document.createElement('template');
template.innerHTML = `
constructor() {
super();
this.attachShadow({ mode: 'open' });
const template = document.createElement('template');
template.innerHTML = `
<style>
@import "../../stylesheets/main-component.css";
</style>
<header-component></header-component>
<body-component></body-component>
<footer-component></footer-component>
`;
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
}
customElements.define('main-component', MainComponent);
4 changes: 2 additions & 2 deletions public/javascript/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
})

/**
* Scrool with ofset on links with a class name .scrollto
* Scroll with ofset on links with a class name .scrollto
*/
on('click', '.scrollto', function(e) {
if (select(this.hash)) {
Expand Down Expand Up @@ -255,4 +255,4 @@
})
});

})()
})()
6 changes: 6 additions & 0 deletions public/stylesheets/body-component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:host {
flex: 1 1 auto;
/* Grow to fill available space */
overflow-y: auto;
/* Add scroll if content overflows */
}
3 changes: 3 additions & 0 deletions public/stylesheets/footer-component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {
flex: 0 1 auto;
}
3 changes: 3 additions & 0 deletions public/stylesheets/header-component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {
flex: 0 1 auto;
}
6 changes: 6 additions & 0 deletions public/stylesheets/main-component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:host {
display: flex;
flex-direction: column;
height: 100vh;
/* Full viewport height */
}
6 changes: 6 additions & 0 deletions public/stylesheets/theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* theme.css */
:root {
--background-color: #333;
--text-color: #fff;
--padding: 10px;
}

0 comments on commit bd02526

Please sign in to comment.