From 11fd60da81dd78f5fb99bc061078e1b13bbe082a Mon Sep 17 00:00:00 2001 From: LynithDev <61880709+LynithDev@users.noreply.github.com> Date: Mon, 16 Oct 2023 21:23:42 +0200 Subject: Button + Section component, new Icon component + new colors --- apps/website/package.json | 3 +- apps/website/src/components/base/Button.astro | 57 ++++++++++++++++ apps/website/src/components/base/Header.astro | 13 +++- apps/website/src/components/base/Navbar.astro | 4 +- .../src/components/base/NavbarElement.astro | 32 ++++----- apps/website/src/components/base/Section.astro | 17 +++++ .../website/src/components/icons/ChevronDown.astro | 16 ----- apps/website/src/components/icons/Icon.astro | 77 ++++++++++++++++++++++ .../src/components/icons/impl/book-open.svg | 3 + .../src/components/icons/impl/chevron-down.svg | 3 + .../website/src/components/icons/impl/download.svg | 3 + apps/website/src/components/logos/Logo.astro | 4 +- apps/website/src/layouts/Layout.astro | 6 +- apps/website/src/pages/index.astro | 20 ++++-- apps/website/src/styles/global.css | 13 ++++ apps/website/tailwind.config.cjs | 34 ++++++---- pnpm-lock.yaml | 53 +++++++++++++-- 17 files changed, 295 insertions(+), 63 deletions(-) create mode 100644 apps/website/src/components/base/Button.astro create mode 100644 apps/website/src/components/base/Section.astro delete mode 100644 apps/website/src/components/icons/ChevronDown.astro create mode 100644 apps/website/src/components/icons/Icon.astro create mode 100644 apps/website/src/components/icons/impl/book-open.svg create mode 100644 apps/website/src/components/icons/impl/chevron-down.svg create mode 100644 apps/website/src/components/icons/impl/download.svg diff --git a/apps/website/package.json b/apps/website/package.json index 214a306..69ad7e8 100644 --- a/apps/website/package.json +++ b/apps/website/package.json @@ -16,6 +16,7 @@ "devDependencies": { "@polyfrost/config": "workspace:*", "@types/node": "~18.17.19", - "typescript": "^5.2.2" + "typescript": "^5.2.2", + "node-html-parser": "^6.1.10" } } diff --git a/apps/website/src/components/base/Button.astro b/apps/website/src/components/base/Button.astro new file mode 100644 index 0000000..e0787c2 --- /dev/null +++ b/apps/website/src/components/base/Button.astro @@ -0,0 +1,57 @@ +--- +import type { Icons } from "@components/icons/Icon.astro"; +import Icon from "@components/icons/Icon.astro"; +import type { HTMLAttributes } from "astro/types"; + +const styles = { + primary: "bg-blue-500 text-white hover:bg-blue-400 active:bg-blue-600 disabled:bg-blue-800 disabled:text-white-1/4", + secondary: "bg-blue-100 text-blue-500 hover:bg-blue-50 active:bg-blue-200 disabled:bg-blue-50 disabled:text-blue-200", +} + +const sizes = { + sm: "px-4 py-2 text-sm", + md: "px-5 py-2 text-md", + lg: "px-6 py-3 text-lg rounded-2xl" +} + +const iconSize = { + sm: 15, + md: 16, + lg: 24 +} + +interface Props extends HTMLAttributes<"button"> { + style?: keyof typeof styles + size?: keyof typeof sizes + text?: string + iconLeft?: Icons + iconRight?: Icons + href?: string +} + +const { + style = "primary", + size = "md", + text = "", + iconLeft = "", + iconRight = "", + ...rest +} = Astro.props; + +const className = [ + "flex flex-row justify-center items-center text-center focus-visible:ring-offset-4 focus-visible:outline-offset-4", + "rounded-xl font-medium", + styles[style], + sizes[size], + "transition-colors", + rest.class +].join(" "); + +const Element = rest.href ? "a" : "button" as any; +--- + + + {iconLeft && } + {text ? text : } + {iconRight && } + diff --git a/apps/website/src/components/base/Header.astro b/apps/website/src/components/base/Header.astro index 1201798..aea04af 100644 --- a/apps/website/src/components/base/Header.astro +++ b/apps/website/src/components/base/Header.astro @@ -13,14 +13,21 @@ const sizes = { type Headers = "h1" | "h2" | "h3" | "h4" | "h5" | "h6"; interface Props extends HTMLAttributes { - size: keyof typeof sizes; + size?: keyof typeof sizes; + align?: "left" | "center" | "right"; } -const { size, ...attr } = Astro.props; +const { + size = "lg", + align = "left", + ...attr +} = Astro.props; const Element = sizes[size] as any; // Unfortunately gotta do this + +const className = `text-${align}` + (attr.class ? ` ${attr.class}` : ""); --- - + diff --git a/apps/website/src/components/base/Navbar.astro b/apps/website/src/components/base/Navbar.astro index f4f2f49..a3a82fe 100644 --- a/apps/website/src/components/base/Navbar.astro +++ b/apps/website/src/components/base/Navbar.astro @@ -5,7 +5,7 @@ import NavbarElement from "./NavbarElement.astro"; --- -
+
-
\ No newline at end of file +
diff --git a/apps/website/src/components/base/NavbarElement.astro b/apps/website/src/components/base/NavbarElement.astro index 4f82e8b..a7a0768 100644 --- a/apps/website/src/components/base/NavbarElement.astro +++ b/apps/website/src/components/base/NavbarElement.astro @@ -1,11 +1,12 @@ --- -import ChevronDown from "@components/icons/ChevronDown.astro"; +import ChevronDown from "@components/icons/ChevronDown.svg"; import type { LogoType, NavbarElement } from "@webtypes/Config"; import ScreenOverlay from "./ScreenOverlay.astro"; import Header from "./Header.astro"; import Tag from "./Tag.astro"; import Logo from "@components/logos/Logo.astro"; import ScrollbarOverlayContainer from "./ScrollbarOverlayContainer.astro"; +import Icon from "@components/icons/Icon.astro"; interface Props { element: NavbarElement; @@ -25,23 +26,24 @@ const { {element.text && element.text} {element.logo && } - {element.dropdown && } + {element.dropdown && } ) : (

{element.text && element.text} {element.logo && } - {element.dropdown && } + {element.dropdown && }

)} {element.dropdown && ( - - )} - \ No newline at end of file + diff --git a/apps/website/src/components/base/Section.astro b/apps/website/src/components/base/Section.astro new file mode 100644 index 0000000..318056b --- /dev/null +++ b/apps/website/src/components/base/Section.astro @@ -0,0 +1,17 @@ +--- +import type { HTMLAttributes } from "astro/types"; + +interface Props extends HTMLAttributes<"section"> { + maxWidth?: number; +} + +const { + maxWidth = 800, + ...rest +} = Astro.props; +const className = `max-w-[${maxWidth}px] px-3 md:p-0 flex flex-col justify-center items-center h-screen md:h-4/5 md:min-h-[600px] gap-4` + (rest.class ? ` ${rest.class}` : ""); +--- + +
+ +
diff --git a/apps/website/src/components/icons/ChevronDown.astro b/apps/website/src/components/icons/ChevronDown.astro deleted file mode 100644 index 5cb98e4..0000000 --- a/apps/website/src/components/icons/ChevronDown.astro +++ /dev/null @@ -1,16 +0,0 @@ ---- -import type { HTMLAttributes } from 'astro/types'; - -interface Props extends HTMLAttributes<"svg"> { - size?: number; -} - -const { - size = 16, - ...attr -} = Astro.props; ---- - - - - \ No newline at end of file diff --git a/apps/website/src/components/icons/Icon.astro b/apps/website/src/components/icons/Icon.astro new file mode 100644 index 0000000..bf2b362 --- /dev/null +++ b/apps/website/src/components/icons/Icon.astro @@ -0,0 +1,77 @@ +--- +export type Icons = "chevron-down" | "download" | "book-open"; + +import { parse } from 'node-html-parser'; +import type { HTMLAttributes } from "astro/types"; + +interface Props extends HTMLAttributes<"svg"> { + icon: Icons; + size?: number | [number, number]; +} + +async function getSVG(name: string) { + const file = await import(`./impl/${name}.svg?raw` /* @vite-ignore */); + + if (!file) { + throw new Error(`${name} not found`); + } + + const content = parse(file.default); + + const svg = content.querySelector('svg'); + + if (!svg) { + throw new Error(`${name} is not a valid SVG`); + } + + const { attributes, innerHTML } = svg; + + return { + attributes, + innerHTML, + }; +} + +const { + icon, + size, + ...attributes +} = Astro.props as Props; + +let svgAttributes = {}; +let html = ""; + +try { + const sizeAttributes = () => { + if (!size) { + return {}; + } + + if (Array.isArray(size)) { + return { + width: size[0], + height: size[1], + }; + } + + return { + width: size, + height: size, + }; + } + + const { attributes: baseAttributes, innerHTML } = await getSVG(icon); + svgAttributes = { + ...baseAttributes, + ...attributes, + ...sizeAttributes(), + }; + + const colorRegex = /(fill|stroke)=\"([^"]*)\"/g; + html = innerHTML.replaceAll(colorRegex, '$1="currentColor"'); +} catch (err) { + +} +--- + + diff --git a/apps/website/src/components/icons/impl/book-open.svg b/apps/website/src/components/icons/impl/book-open.svg new file mode 100644 index 0000000..37cf696 --- /dev/null +++ b/apps/website/src/components/icons/impl/book-open.svg @@ -0,0 +1,3 @@ + + + diff --git a/apps/website/src/components/icons/impl/chevron-down.svg b/apps/website/src/components/icons/impl/chevron-down.svg new file mode 100644 index 0000000..910a0b5 --- /dev/null +++ b/apps/website/src/components/icons/impl/chevron-down.svg @@ -0,0 +1,3 @@ + + + diff --git a/apps/website/src/components/icons/impl/download.svg b/apps/website/src/components/icons/impl/download.svg new file mode 100644 index 0000000..cd8a6cb --- /dev/null +++ b/apps/website/src/components/icons/impl/download.svg @@ -0,0 +1,3 @@ + + + diff --git a/apps/website/src/components/logos/Logo.astro b/apps/website/src/components/logos/Logo.astro index 0532396..2fd6bea 100644 --- a/apps/website/src/components/logos/Logo.astro +++ b/apps/website/src/components/logos/Logo.astro @@ -10,7 +10,7 @@ export interface Props extends HTMLAttributes<"svg"> { silent?: boolean, } -const { +const { logo, silent = false, size = undefined, @@ -44,7 +44,7 @@ try { svg = svg.replace(/ `${key}="${value}"`).join(" ")}`); } catch (err) { - if (typeof silent != "boolean" || silent == false) console.error(err); + } --- diff --git a/apps/website/src/layouts/Layout.astro b/apps/website/src/layouts/Layout.astro index a648f08..84ec6fe 100644 --- a/apps/website/src/layouts/Layout.astro +++ b/apps/website/src/layouts/Layout.astro @@ -8,7 +8,7 @@ interface Props { favicon?: string; } -const { +const { title = 'Polyfrost', favicon = Favicon } = Astro.props; @@ -32,7 +32,9 @@ const { - +
+ +
diff --git a/apps/website/src/pages/index.astro b/apps/website/src/pages/index.astro index 837f866..6cf0165 100644 --- a/apps/website/src/pages/index.astro +++ b/apps/website/src/pages/index.astro @@ -2,11 +2,23 @@ import Header from "@components/base/Header.astro"; import Layout from "../layouts/Layout.astro"; import Logo from "@components/logos/Logo.astro"; +import Section from "@components/base/Section.astro"; +import Button from "@components/base/Button.astro"; + +import Icon from "@components/icons/Icon.astro"; --- -
- -
Meet OneConfig, the library for everyone.
-
+
+ +
Meet OneConfig, the library designed for everyone.
+
+
+
+
+ +
Meet OneConfig, the library designed for everyone.
+
diff --git a/apps/website/src/styles/global.css b/apps/website/src/styles/global.css index 6520592..79904b7 100644 --- a/apps/website/src/styles/global.css +++ b/apps/website/src/styles/global.css @@ -8,4 +8,17 @@ :focus-visible { @apply outline-none ring ring-blue-500; } + + /* Has to be split because css parser moment */ + ::-moz-selection { + @apply bg-blue-500/20; + } + + ::selection { + @apply bg-blue-500/20; + } + + html, body { + @apply text-[14px] md:text-[16px]; + } } diff --git a/apps/website/tailwind.config.cjs b/apps/website/tailwind.config.cjs index 3cf5259..faa8722 100644 --- a/apps/website/tailwind.config.cjs +++ b/apps/website/tailwind.config.cjs @@ -4,7 +4,13 @@ module.exports = { theme: { colors: { blue: { - 500: 'rgba(31, 101, 214, 1)' + 50: 'rgba(231, 235, 252, 1)', + 100: 'rgba(210, 225, 249, 1)', + 200: 'rgba(189, 215, 249, 1)', + 400: 'rgba(56, 132, 255, 1)', + 500: 'rgba(31, 101, 214, 1)', + 600: 'rgba(9, 84, 165, 1)', + 800: 'rgba(19, 43, 83, 1)' }, gray: { 50: 'rgba(240, 242, 244, 1)', @@ -14,8 +20,7 @@ module.exports = { }, white: { DEFAULT: 'rgba(255, 255, 255, 1)', - secondary: 'rgba(238, 241, 254, 1)', - hover: 'rgba(231, 235, 252, 1)' + "1/4": 'rgba(255, 255, 255, 0.25)' }, black: { DEFAULT: 'rgba(0, 0, 0, 1)' @@ -31,21 +36,24 @@ module.exports = { md: '5px', lg: '8px', xl: '12px', + "2xl": '16px', full: '100vw' }, fontSize: { - 'xs': '12px', - 'sm': '14px', - 'md': '16px', - 'lg': '18px', + // rem starts at 16px on desktop, 14px on tailwind 'sm' and below + 'xs': '0.75rem', // 12px + 'sm': '0.875rem', // 14px + 'md': '1rem', // 16px + 'lg': '1.125rem', // 18px + 'xl': '1.25rem', // 20px - 'header-sm': '24px', - 'header': '28px', - 'header-lg': '32px', + 'header-sm': '1.5rem', // 24px + 'header': '1.75rem', // 28px + 'header-lg': '2rem', // 32px - 'body-sm': '15px', - 'body': '16px', - 'body-lg': '17px' + 'body-sm': '0.938rem', // 15px + 'body': '1rem', // 16px + 'body-lg': '1.063rem' // 17px }, extend: {} }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 458a355..c629d18 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -152,6 +152,9 @@ importers: '@types/node': specifier: ~18.17.19 version: 18.17.19 + node-html-parser: + specifier: ^6.1.10 + version: 6.1.10 typescript: specifier: ^5.2.2 version: 5.2.2 @@ -2474,7 +2477,7 @@ packages: magic-string: 0.27.0 react-docgen-typescript: 2.2.2(typescript@5.2.2) typescript: 5.2.2 - vite: 4.4.11(less@4.2.0)(sass@1.69.3) + vite: 4.4.11 /@jridgewell/gen-mapping@0.3.3: resolution: {integrity: sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==} @@ -3798,7 +3801,7 @@ packages: remark-slug: 6.1.0 rollup: 3.28.1 typescript: 5.2.2 - vite: 4.4.11(less@4.2.0)(sass@1.69.3) + vite: 4.4.11 transitivePeerDependencies: - encoding - supports-color @@ -4151,7 +4154,7 @@ packages: react: 18.2.0 react-docgen: 6.0.0-alpha.3 react-dom: 18.2.0(react@18.2.0) - vite: 4.4.11(less@4.2.0)(sass@1.69.3) + vite: 4.4.11 transitivePeerDependencies: - '@preact/preset-vite' - encoding @@ -4894,7 +4897,7 @@ packages: '@babel/plugin-transform-react-jsx-source': 7.22.5(@babel/core@7.23.2) magic-string: 0.27.0 react-refresh: 0.14.0 - vite: 4.4.11(less@4.2.0)(sass@1.69.3) + vite: 4.4.11 transitivePeerDependencies: - supports-color @@ -6142,6 +6145,16 @@ packages: nth-check: 2.1.1 dev: true + /css-select@5.1.0: + resolution: {integrity: sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==} + dependencies: + boolbase: 1.0.0 + css-what: 6.1.0 + domhandler: 5.0.3 + domutils: 3.1.0 + nth-check: 2.1.1 + dev: true + /css-what@6.1.0: resolution: {integrity: sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==} engines: {node: '>= 6'} @@ -6420,6 +6433,14 @@ packages: entities: 2.2.0 dev: true + /dom-serializer@2.0.0: + resolution: {integrity: sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==} + dependencies: + domelementtype: 2.3.0 + domhandler: 5.0.3 + entities: 4.5.0 + dev: true + /domelementtype@2.3.0: resolution: {integrity: sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==} dev: true @@ -6431,6 +6452,13 @@ packages: domelementtype: 2.3.0 dev: true + /domhandler@5.0.3: + resolution: {integrity: sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==} + engines: {node: '>= 4'} + dependencies: + domelementtype: 2.3.0 + dev: true + /domutils@2.8.0: resolution: {integrity: sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==} dependencies: @@ -6439,6 +6467,14 @@ packages: domhandler: 4.3.1 dev: true + /domutils@3.1.0: + resolution: {integrity: sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==} + dependencies: + dom-serializer: 2.0.0 + domelementtype: 2.3.0 + domhandler: 5.0.3 + dev: true + /dot-case@3.0.4: resolution: {integrity: sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==} dependencies: @@ -9477,6 +9513,13 @@ packages: he: 1.2.0 dev: true + /node-html-parser@6.1.10: + resolution: {integrity: sha512-6/uWdWxjQWQ7tMcFK2wWlrflsQUzh1HsEzlIf2j5+TtzfhT2yUvg3DwZYAmjEHeR3uX74ko7exjHW69J0tOzIg==} + dependencies: + css-select: 5.1.0 + he: 1.2.0 + dev: true + /node-int64@0.4.0: resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==} dev: false @@ -12286,7 +12329,6 @@ packages: rollup: 3.28.1 optionalDependencies: fsevents: 2.3.3 - dev: true /vite@4.4.11(@types/node@18.17.19): resolution: {integrity: sha512-ksNZJlkcU9b0lBwAGZGGaZHCMqHsc8OpgtoYhsQ4/I2v5cnpmmmqe5pM4nv/4Hn6G/2GhTdj0DhZh2e+Er1q5A==} @@ -12359,6 +12401,7 @@ packages: sass: 1.69.3 optionalDependencies: fsevents: 2.3.3 + dev: true /vitefu@0.2.4(vite@4.4.11): resolution: {integrity: sha512-fanAXjSaf9xXtOOeno8wZXIhgia+CZury481LsDaV++lSvcU2R9Ch2bPh3PYFyoHW+w9LqAeYRISVQjUIew14g==} -- cgit