⚒️ Preparate boilerplate v2 - Typescript + React 18.

This commit is contained in:
pheralb
2022-06-03 11:53:50 +01:00
parent 48e648a04b
commit b21f464108
46 changed files with 1374 additions and 12586 deletions
-8
View File
@@ -1,8 +0,0 @@
import Error from 'components/error';
import React from 'react';
const Error404 = () => {
return <Error />;
};
export default Error404;
-78
View File
@@ -1,78 +0,0 @@
// 🖤 Next Head ->
import Head from "next/head";
// 🌿 Chakra UI ->
import { ChakraProvider, Container, useColorModeValue } from "@chakra-ui/react";
// ➡️ Nextjs Progressbar ->
import NextNProgress from "nextjs-progressbar";
// 📦 Components ->
import Sidebar from "components/sidebar";
import Layout from "components/layout";
import Footer from "components/sidebar/by";
// 💙 Global CSS ->
import "styles/globals.css";
// 🎨 Theme ->
import theme from "styles/theme";
// 🐢 Animations ->
import Transitions from "animations/transitions";
import { Toaster } from "react-hot-toast";
function MyApp({ Component, pageProps, router }) {
const progress = useColorModeValue("#7B7B7B", "#D4D4D4");
return (
<>
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>SVGL - Beautiful SVG vector logos</title>
<meta property="og:title" content="SVGL - Beautiful SVG vector logos" />
<meta
property="og:description"
content="Beautiful SVG logos. Free and open source."
/>
<meta property="og:type" content="website" />
<meta property="og:url" content="https://svgl.vercel.app/" />
<meta
property="og:image"
content="https://svgl.vercel.app/images/banner.png"
/>
<meta name="twitter:site" content="@pheralb_" />
<meta
property="twitter:title"
content="SVGL - Beautiful SVG vector logos"
/>
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:creator" content="@pheralb" />
<meta
property="twitter:description"
content="Beautiful SVG logos. Free and open source."
/>
<meta
name="twitter:image"
content="https://svgl.vercel.app/images/banner.png"
/>
<meta name="keywords" content="svg,vector,logo,logos,download" />
<meta content="#16161a" name="theme-color" />
<link rel="icon" href="/icons/icon.ico" />
</Head>
<ChakraProvider theme={theme}>
<Sidebar>
<NextNProgress color={progress}/>
<Layout>
<Transitions key={router.route}>
<Component {...pageProps} />
</Transitions>
</Layout>
</Sidebar>
</ChakraProvider>
<Toaster position="bottom-center" reverseOrder={false} />
</>
);
}
export default MyApp;
+8
View File
@@ -0,0 +1,8 @@
import '../styles/globals.css'
import type { AppProps } from 'next/app'
function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
export default MyApp
-22
View File
@@ -1,22 +0,0 @@
import { ColorModeScript } from "@chakra-ui/react";
import NextDocument, { Html, Head, Main, NextScript } from "next/document";
import theme from "styles/theme";
export default class Document extends NextDocument {
render() {
return (
<Html>
<Head>
<link rel="manifest" href="/manifest.json" />
<link rel="apple-touch-icon" href="/icons/icon-512x512.png"></link>
<meta name="theme-color" content="#36558F" />
</Head>
<body>
<ColorModeScript initialColorMode={theme.config.initialColorMode} />
<Main />
<NextScript />
</body>
</Html>
);
}
}
-38
View File
@@ -1,38 +0,0 @@
import React from "react";
import { Box, Flex, Button, Text, Icon } from "@chakra-ui/react";
import { IoHome, IoWarning } from "react-icons/io5";
import Link from "next/link";
import Show from "animations/show";
const Offline = () => {
return (
<>
<Show delay="0">
<Box px={{ base: 4, lg: 20 }} py={{ base: "3", md: "24" }}>
<Flex align="center" justify="center" direction="column" w="full">
<Icon name="error" boxSize="80px" mb="3" as={IoWarning} />
<Text fontSize="40px" mb="2">
Oh no!
</Text>
<Text fontSize="20px" mb="3">
No internet connection
</Text>
<Link href="/" passHref>
<Button
leftIcon={<IoHome />}
borderWidth="1px"
variant="outline"
fontWeight="light"
mb="4"
>
Refresh
</Button>
</Link>
</Flex>
</Box>
</Show>
</>
);
};
export default Offline;
-6
View File
@@ -1,6 +0,0 @@
import db from "data/svgs";
// 📦 Show all content ->
export default function handler(req, res) {
res.status(200).json(db);
}
-13
View File
@@ -1,13 +0,0 @@
import db from "data/svgs";
// 📦 Show categories ->
export default function handler(req, res) {
try {
const categories = db
.map((item) => item.category)
.filter((category, index, self) => self.indexOf(category) === index);
return res.status(200).json(categories);
} catch (err) {
res.status(400).json({ message: err });
}
}
+13
View File
@@ -0,0 +1,13 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
type Data = {
name: string
}
export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
res.status(200).json({ name: 'John Doe' })
}
-32
View File
@@ -1,32 +0,0 @@
import db from "data/svgs";
export default function handler(req, res) {
const { id, q, c } = req.query;
// 🔎 Search by id (ex: ?id=1) ->
if (id) {
const item = db.find((item) => item.id === +id);
return res.status(200).json(item);
}
// 🔎 Search by query (ex: ?q=d) ->
if (q) {
const results = db.filter((product) => {
const { title } = product;
return title.toLowerCase().includes(q.toLowerCase());
});
return res.status(200).json(results);
}
// 🔎 Search by category (ex: ?c=library) ->
if (c) {
const results = db.filter((product) => {
const { category } = product;
return category.toLowerCase().includes(c.toLowerCase());
});
return res.status(200).json(results);
}
// ✖ Error ->
res.status(400).json({ info: 'Error: api query not found.' });
}
-116
View File
@@ -1,116 +0,0 @@
import React from "react";
import Head from "next/head";
import download from "downloadjs";
import { Box, Button, Flex, HStack, Link, Text } from "@chakra-ui/react";
import Show from "animations/show";
import Grid from "components/grid";
import DesignCard from "components/card/design";
import { RiFontSize, RiPaletteLine } from "react-icons/ri";
import { IoMdImages } from "react-icons/io";
import { HiOutlineExternalLink } from "react-icons/hi";
import { IoCloudDownloadOutline } from "react-icons/io5";
import CardImage from "components/card/image";
const Design = () => {
const downloadSvg = (url) => {
download(url);
};
return (
<>
<Head>
<title>Design - SVGL</title>
</Head>
<Box mt="6">
<Box w="full" border="solid 1px transparent">
<Show>
<Text
as="h1"
fontSize={{ base: "25px", sm: "35px", md: "5xl", lg: "6xl" }}
letterSpacing="tight"
lineHeight="short"
fontWeight="extrabold"
mb="3"
>
Design
</Text>
</Show>
<Show delay={0.3}>
<Box mt={{ base: 4, md: 5 }}>
<Grid>
<DesignCard title="Fonts" icon={RiFontSize}>
<HStack spacing={2}>
<Link
href="https://fonts.google.com/specimen/Poppins"
isExternal
>
Poppins
</Link>
<HiOutlineExternalLink size="20px" />
</HStack>
</DesignCard>
<DesignCard title="Colors" icon={RiPaletteLine}>
<Flex color="white">
<Box bg="lightDark.900" p="2">
<Text fontSize="15px">#16161a</Text>
</Box>
<Box bg="light.100" p="2">
<Text fontSize="15px" color="black">
#f9f9f9
</Text>
</Box>
<Box bg="#6748E6" p="2">
<Text fontSize="15px" color="white">
#6748E6
</Text>
</Box>
</Flex>
</DesignCard>
</Grid>
<Box mt="4">
<DesignCard title="Images" icon={IoMdImages}>
<HStack spacing={3}>
<CardImage title="Banner" image="/images/banner.png">
<Button
w={{ base: "100%", md: "auto" }}
leftIcon={<IoCloudDownloadOutline />}
variant="primary"
fontWeight="light"
mt="2"
onClick={() =>
downloadSvg(
"https://svgl.vercel.app/images/banner.png"
)
}
>
Download
</Button>
</CardImage>
<CardImage title="Logo" image="/images/logo.png">
<Button
w={{ base: "100%", md: "auto" }}
leftIcon={<IoCloudDownloadOutline />}
variant="primary"
fontWeight="light"
mt="2"
onClick={() =>
downloadSvg(
"https://svgl.vercel.app/images/logo.png"
)
}
>
Download
</Button>
</CardImage>
</HStack>
</DesignCard>
</Box>
</Box>
</Show>
</Box>
</Box>
</>
);
};
export default Design;
-19
View File
@@ -1,19 +0,0 @@
import { chakra, Box } from "@chakra-ui/react";
import Search from "components/search";
import Items from "components/items/all";
import Loader from "animations/loader";
export default function Index() {
return (
<>
<Box mt="6">
<Box w="full" border="solid 1px transparent">
<Search />
<Box mt={{ base: 4, md: 8 }}>
<Items />
</Box>
</Box>
</Box>
</>
);
}
+72
View File
@@ -0,0 +1,72 @@
import type { NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'
const Home: NextPage = () => {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
<p className={styles.description}>
Get started by editing{' '}
<code className={styles.code}>pages/index.tsx</code>
</p>
<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h2>Documentation &rarr;</h2>
<p>Find in-depth information about Next.js features and API.</p>
</a>
<a href="https://nextjs.org/learn" className={styles.card}>
<h2>Learn &rarr;</h2>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
<a
href="https://github.com/vercel/next.js/tree/canary/examples"
className={styles.card}
>
<h2>Examples &rarr;</h2>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
>
<h2>Deploy &rarr;</h2>
<p>
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
</main>
<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<span className={styles.logo}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
</footer>
</div>
)
}
export default Home
-134
View File
@@ -1,134 +0,0 @@
import Head from "next/head";
import {
chakra,
Box,
Flex,
SimpleGrid,
Button,
Image,
Center,
Link,
useColorModeValue,
} from "@chakra-ui/react";
import { useRouter } from "next/router";
import useSWR from "swr";
import Error from "components/error";
import { IoArrowBackOutline, IoCloudDownloadOutline } from "react-icons/io5";
import { BiLinkExternal } from "react-icons/bi";
import Show from "animations/show";
import Loader from "animations/loader";
import confetti from "canvas-confetti";
import download from "downloadjs";
import NextLink from 'next/link';
const fetcher = async (url) => {
const res = await fetch(url);
const data = await res.json();
if (res.status !== 200) {
throw new Error(data.message);
}
return data;
};
export default function Icon() {
const { query } = useRouter();
const { data, error } = useSWR(
() => query.id && `/api/search?id=${query.id}`,
fetcher
);
const bgImage = useColorModeValue("transparent", "#E9E9E9");
const borderRds = useColorModeValue("0", "15px");
if (error) return <Error />;
if (!data) return <Loader />;
const downloadSvg = (url) => {
confetti({
particleCount: 200,
startVelocity: 30,
spread: 300,
gravity: 1.2,
origin: { y: 0 },
});
download(url);
};
return (
<>
<Head>
<title>{data.title} - SVGL</title>
</Head>
<Show delay="0">
<NextLink href="/" passHref>
<Button
leftIcon={<IoArrowBackOutline />}
fontWeight="light"
variant="ghost"
mb="4"
>
Continue discovering
</Button>
</NextLink>
<SimpleGrid columns={{ base: 1, md: 1, lg: 2 }} spacing={0}>
<Box py={{ base: "10", md: "24" }}>
<Center>
<Image
src={data.href}
alt={data.title}
w={{ base: "30%", md: "20%", lg: "30%" }}
fit="cover"
loading="lazy"
bg={bgImage}
borderRadius={borderRds}
p="1"
/>
</Center>
</Box>
<Flex
direction="column"
alignItems="start"
justifyContent="center"
px={{ base: 4, lg: 4 }}
py={{ base: "3", md: "0", lg: "10" }}
>
<chakra.h1
mb={3}
fontSize={{ base: "4xl", md: "4xl", lg: "5xl" }}
fontWeight="semibold"
lineHeight="shorter"
>
{data.title}
</chakra.h1>
<Flex direction={{ base: "column", md: "row" }} w="100%" mt="2">
<Button
w={{ base: "100%", md: "auto" }}
mb={{ base: "2", md: "0" }}
leftIcon={<IoCloudDownloadOutline />}
variant="primary"
fontWeight="light"
mr="2"
onClick={() => downloadSvg(data.href)}
>
Download .svg
</Button>
<Link
href={data.url}
style={{ textDecoration: "none" }}
isExternal
>
<Button
w={{ base: "100%", md: "auto" }}
fontWeight="light"
borderWidth="1px"
rightIcon={<BiLinkExternal />}
>
{data.title} website
</Button>
</Link>
</Flex>
</Flex>
</SimpleGrid>
</Show>
</>
);
}