Skip to content

Commit

Permalink
feat: implement sticky header and sticky fixed menu
Browse files Browse the repository at this point in the history
  • Loading branch information
zerinoid committed Jul 7, 2023
1 parent 129cfd8 commit 3384840
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/components/layouts/primary/PrimaryLayout.module.css
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.main {}
.main {
position: relative;
}
38 changes: 24 additions & 14 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const Home: NextPageWithLayout = () => {
});
const [isFilterOpen, setIsFilterOpen] = useState<boolean>(false);
const [searchText, setSearchText] = useState<string>('');
const icon = isFilterOpen ? faXmark : faBars;
const projects = galleryData.projects;

const handleSearchTextChange = (text: string) => {
Expand Down Expand Up @@ -81,32 +80,43 @@ const Home: NextPageWithLayout = () => {

return (
<>
<div className={styles.header}>
<button
className="md:hidden"
onClick={() => setIsFilterOpen(isOpen => !isOpen)}
>
<FontAwesomeIcon icon={faBars} size="xl" />
</button>
<p>Search and filter</p>
</div>
<div
className={styles.slidingMenu}
style={{ left: isFilterOpen ? '0' : '-100%' }}
>
<button
className="absolute top-2 right-2"
onClick={() => setIsFilterOpen(isOpen => !isOpen)}
>
<FontAwesomeIcon icon={faXmark} size="xl" />
</button>
<Filter
searchText={searchText}
handleSearchTextChange={handleSearchTextChange}
handleCheckboxChange={handleCheckboxChange}
filtersState={filters}
/>
</div>
<section className={styles.container}>
<button
className="fixed top-2 left-2 z-10 md:hidden"
onClick={() => setIsFilterOpen(isOpen => !isOpen)}
>
<FontAwesomeIcon icon={icon} size="xl" />
</button>
<section className={styles.main}>
<Gallery projects={filteredItems} />
<div className={styles.fixedMenu}>
<Filter
searchText={searchText}
handleSearchTextChange={handleSearchTextChange}
handleCheckboxChange={handleCheckboxChange}
filtersState={filters}
/>
<div className={styles.fixedContainer}>
<Filter
searchText={searchText}
handleSearchTextChange={handleSearchTextChange}
handleCheckboxChange={handleCheckboxChange}
filtersState={filters}
/>
</div>
</div>
</section>
</>
Expand Down
27 changes: 25 additions & 2 deletions src/styles/Home.module.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
.container {
.header {
position: sticky;
display: flex;
justify-content: space-around;
align-items: center;
top: 0;
height: 40px;
border-bottom: 1px solid grey;
background-color: white;
z-index: 200;
}

.header p {
text-transform: uppercase;
}

.main {
display: grid;
grid-template-columns: 1fr;
min-height: 100vh;
padding: 4rem 0;

@media screen(md) {
grid-template-columns: 8fr 4fr;
Expand All @@ -16,6 +31,7 @@
left: -100%;
overflow-y: auto;
transition: all 2s cubic-bezier(0.16, 1, 0.3, 1);
z-index: 300;

@media screen(md) {
display: none;
Expand All @@ -24,12 +40,19 @@

.fixedMenu {
display: none;
border-left: 1px solid grey;
z-index: 100;

@media screen(md) {
display: block;
}
}

.fixedContainer {
top: 40px;
position: sticky;
}

@media (prefers-color-scheme: dark) {

.card,
Expand Down

0 comments on commit 3384840

Please sign in to comment.