Skip to content

Commit

Permalink
feat: add useIsMobile hook, isMobile prop, enhance ui style
Browse files Browse the repository at this point in the history
  • Loading branch information
luigibarbato committed Oct 17, 2023
1 parent fee3fbd commit 8bd3f16
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/Feeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface FeedsProps {

export const Feeds = (props: FeedsProps) => {
return (
<div className="md:columns-2 lg:columns-3 columns-1 gap-8 px-8 mb-10 container">
<div className="md:columns-2 lg:columns-3 columns-1 gap-8 px-8 mb-10 mt-10 container">
{props.feeds.map((feed) => (
<div
key={feed.link}
Expand Down
4 changes: 2 additions & 2 deletions components/SearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const SearchForm: FunctionComponent<SearchFormProps> = ({ onSubmitted }) => {
></path>
</svg>
</div>
<div className="flex justify-center items-center text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<div className="flex justify-center items-center text-gray-900 bg-gray-50 rounded-lg border border-gray-300 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white ">
<input
type="search"
value={query}
Expand All @@ -52,7 +52,7 @@ const SearchForm: FunctionComponent<SearchFormProps> = ({ onSubmitted }) => {
></input>
<button
type="submit"
className="text-white mr-2 md:h-auto w-2/4 md:w-1/2 bg-black hover:bg-black focus:ring-4 focus:outline-none font-medium rounded-lg text-sm md:text-sm p-2 md:px-4 md:py-2 dark:bg-black dark:hover:bg-black dark:focus:ring-black "
className="text-white mr-2 md:h-auto w-2/4 md:w-1/2 bg-black hover:bg-black focus:outline-none font-medium rounded-lg text-sm md:text-sm p-2 md:px-4 md:py-2 dark:bg-black dark:hover:bg-black dark:focus:ring-black"
>
Search
</button>
Expand Down
7 changes: 6 additions & 1 deletion components/layouts/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import { useRouter } from "next/router";
interface LayoutProps {
children: React.ReactNode;
hideSearchBar?: boolean;
hideTagLine?: boolean;
isMobile: boolean;
}

const Layout: FunctionComponent<LayoutProps> = ({
children,
hideSearchBar,
hideTagLine,
isMobile,
}) => {
const router = useRouter();

Expand Down Expand Up @@ -47,7 +52,7 @@ const Layout: FunctionComponent<LayoutProps> = ({
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
<div className="flex flex-col h-screen ">
<Header hideTagline={hideSearchBar} />
<Header hideTagline={hideTagLine || isMobile} />
{!hideSearchBar && <SearchForm onSubmitted={onSubmitted} />}
<hr />
<main className="m-auto overflow-y-scroll md:overflow-y-visible">
Expand Down
22 changes: 22 additions & 0 deletions hooks/useismobile.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect, useState } from "react";

const useIsMobile = () => {
const [isMobile, setIsMobile] = useState(false);

useEffect(() => {
const handleResize = () => {
setIsMobile(
window.matchMedia("only screen and (max-width: 912px)").matches,
);
};

window.addEventListener("resize", handleResize);
handleResize(); // Chiamare la funzione quando il componente viene montato

return () => window.removeEventListener("resize", handleResize);
}, []);

return isMobile;
};

export default useIsMobile;
13 changes: 11 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ import "../styles/globals.css";
import { Analytics } from "@vercel/analytics/react";
import type { AppProps } from "next/app";
import Layout from "../components/layouts/Layout";
import { SWRConfig } from "swr";
import useIsMobile from "../hooks/useismobile.hook";

interface PageProps {
hideSearchBar?: boolean;
hideTagLine?: boolean;
isMobile: boolean;
}

function MyApp({ Component, pageProps }: AppProps<PageProps>) {
const isMobile = useIsMobile();

return (
<Layout hideSearchBar={pageProps.hideSearchBar}>
<Layout
hideSearchBar={pageProps.hideSearchBar}
hideTagLine={pageProps.hideTagLine}
isMobile={isMobile}
>
<Component {...pageProps} />
<Analytics />
</Layout>
Expand Down
38 changes: 38 additions & 0 deletions styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,43 @@ input:-webkit-autofill:active {
-webkit-box-shadow: 0 0 0 100px rgb(249 250 251 / var(--tw-bg-opacity)) inset !important;
}

input[type="search"]::-webkit-search-cancel-button {
-webkit-appearance: none;
height: 1em;
width: 1em;
border-radius: 50%;
background: black;
color: white;
font-size: 1em;
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
}

@media only screen and (max-width: 768px) {
input[type="search"]::-webkit-search-cancel-button {
margin-right: 1em;
}
}

input[type="search"]:after::-webkit-search-cancel-button {
opacity: 1;
color: white;
pointer-events: all;
}

input[type="search"]:focus::-webkit-search-cancel-button {
opacity: 1;
color: white;
cursor: pointer;
pointer-events: all;
}

input[type="search"].dark::-webkit-search-cancel-button {
filter: invert(1);
}

.article {
padding: 16px 24px;
position: relative;
Expand Down Expand Up @@ -81,6 +118,7 @@ input:-webkit-autofill:active {
.text-summarize {
overflow: hidden;
display: -webkit-box;
text-overflow: "...";
-webkit-box-orient: vertical;
-webkit-line-clamp: 10;
}
Expand Down

0 comments on commit 8bd3f16

Please sign in to comment.