diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 5273109..3523a05 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -15,6 +15,14 @@ const Home: NextPage = () => { <> +
+

48px: h1

+

40px: h2

+

32px: h3

+

24px: h4, header, polaroid, button

+

20px: h5, body

+

16px: h6

+
{/* */} {/* */} @@ -29,8 +37,8 @@ export default Home; const Hero = () => { return ( <> -

Sunrise

-

+

Sunrise

+

Creating software that looks and works great is our specialty at Sunrise. Our team of experts combines artistry and technical know-how to craft solutions that will make your business{" "} diff --git a/tailwind.config.ts b/tailwind.config.ts index 2c5a016..9304036 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -1,5 +1,11 @@ import { type Config } from "tailwindcss"; import { fontFamily } from "tailwindcss/defaultTheme"; +import plugin from "tailwindcss/plugin"; + +interface RecursiveKeyValuePair { + [key: string]: V | RecursiveKeyValuePair; +} +type CSSRuleObject = RecursiveKeyValuePair; export default { content: ["./src/**/*.{js,ts,jsx,tsx}"], @@ -9,6 +15,15 @@ export default { center: true, padding: "1.5rem", }, + fontSize: { + xs: ["0.75rem", { lineHeight: "1rem" }], // 12px 0.75rem + sm: ["1rem", { lineHeight: "1.25rem" }], // 16px 1rem + base: ["1.25rem", { lineHeight: "1.5rem" }], // 20px 1.25rem + lg: ["1.5rem", { lineHeight: "1.75rem" }], // 24px 1.5rem + xl: ["2rem", { lineHeight: "1.75rem" }], // 32px 2rem + "2xl": ["2.5rem", { lineHeight: "2rem" }], // 40px 2.5rem + "3xl": ["3rem", { lineHeight: "2.25rem" }], // 48px 3rem + }, fontFamily: { sans: ["var(--font-jakarta)"], roadster: ["var(--font-roadster)", ...fontFamily.sans], @@ -25,5 +40,41 @@ export default { }, }, }, - plugins: [], + plugins: [ + // Responsive Typography + plugin(function ({ addUtilities, theme }) { + const fontSizes = Object.keys(theme("fontSize")); + + const buildCSS = (fontSize: string): CSSRuleObject => { + const fsIndex = fontSizes.indexOf(fontSize); + + if (fsIndex > 1) { + const desktop = fontSize; + const tablet = fontSizes[fsIndex - 1] ?? fontSize; + const mobile = fontSizes[fsIndex - 2] ?? fontSize; + + return { + "font-size": theme(`fontSize.${mobile}`), + "@screen md": { + "font-size": theme(`fontSize.${tablet}`), + }, + "@screen 2xl": { + "font-size": theme(`fontSize.${desktop}`), + }, + }; + } + + return { "font-size": theme(`fontSize.${fontSize}`) }; + }; + + addUtilities({ + ".text-r-3xl": buildCSS("3xl"), + ".text-r-2xl": buildCSS("2xl"), + ".text-r-xl": buildCSS("xl"), + ".text-r-lg": buildCSS("lg"), + ".text-r-base": buildCSS("base"), + ".text-r-sm": buildCSS("sm"), + }); + }), + ], } satisfies Config;